debug.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2001-2012 Ben Sapp
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_debug_h)
00024 #define octave_debug_h 1
00025 
00026 #include <map>
00027 #include <set>
00028 #include "ov.h"
00029 #include "dRowVector.h"
00030 
00031 class octave_value_list;
00032 class octave_user_code;
00033 
00034 // Interface to breakpoints,.
00035 
00036 class
00037 OCTINTERP_API
00038 bp_table
00039 {
00040 private:
00041 
00042   bp_table (void) : bp_set () { }
00043 
00044   ~bp_table (void) { }
00045 
00046 public:
00047 
00048   typedef std::map<int, int> intmap;
00049 
00050   typedef intmap::const_iterator const_intmap_iterator;
00051   typedef intmap::iterator intmap_iterator;
00052 
00053   typedef std::map <std::string, intmap> fname_line_map;
00054 
00055   typedef fname_line_map::const_iterator const_fname_line_map_iterator;
00056   typedef fname_line_map::iterator fname_line_map_iterator;
00057 
00058   static bool instance_ok (void);
00059 
00060   // Add a breakpoint at the nearest executable line.
00061   static intmap add_breakpoint (const std::string& fname = "",
00062                                 const intmap& lines = intmap ())
00063   {
00064     return instance_ok ()
00065       ? instance->do_add_breakpoint (fname, lines) : intmap ();
00066   }
00067 
00068   // Remove a breakpoint from a line in file.
00069   static int remove_breakpoint (const std::string& fname = "",
00070                                 const intmap& lines = intmap ())
00071   {
00072     return instance_ok ()
00073       ? instance->do_remove_breakpoint (fname, lines) : 0;
00074   }
00075 
00076   // Remove all the breakpoints in a specified file.
00077   static intmap remove_all_breakpoints_in_file (const std::string& fname,
00078                                                 bool silent = false)
00079   {
00080     return instance_ok ()
00081       ? instance->do_remove_all_breakpoints_in_file (fname, silent) : intmap ();
00082   }
00083 
00084   // Remove all the breakpoints registered with octave.
00085   static void remove_all_breakpoints (void)
00086   {
00087     if (instance_ok ())
00088       instance->do_remove_all_breakpoints ();
00089   }
00090 
00091   // Return all breakpoints.  Each element of the map is a vector
00092   // containing the breakpoints corresponding to a given function name.
00093   static fname_line_map
00094   get_breakpoint_list (const octave_value_list& fname_list)
00095   {
00096     return instance_ok ()
00097       ? instance->do_get_breakpoint_list (fname_list) : fname_line_map ();
00098   }
00099 
00100   static bool
00101   have_breakpoints (void)
00102   {
00103     return instance_ok () ? instance->do_have_breakpoints () : 0;
00104   }
00105 
00106 private:
00107 
00108   typedef std::set<std::string>::const_iterator const_bp_set_iterator;
00109   typedef std::set<std::string>::iterator bp_set_iterator;
00110 
00111   // Set of function names containing at least one breakpoint.
00112   std::set<std::string> bp_set;
00113 
00114   static bp_table *instance;
00115 
00116   static void cleanup_instance (void) { delete instance; instance = 0; }
00117 
00118   intmap do_add_breakpoint (const std::string& fname, const intmap& lines);
00119 
00120   int do_remove_breakpoint (const std::string&, const intmap& lines);
00121 
00122   intmap do_remove_all_breakpoints_in_file (const std::string& fname,
00123                                             bool silent);
00124 
00125   void do_remove_all_breakpoints (void);
00126 
00127   fname_line_map do_get_breakpoint_list (const octave_value_list& fname_list);
00128 
00129   bool do_have_breakpoints (void) { return (! bp_set.empty ()); }
00130 };
00131 
00132 std::string get_file_line (const std::string& fname, size_t line);
00133 
00134 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines