GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
debug.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2001-2017 Ben Sapp
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_debug_h)
24 #define octave_debug_h 1
25 
26 #include "octave-config.h"
27 
28 #include <map>
29 #include <set>
30 #include "ov.h"
31 #include "dRowVector.h"
32 
33 class octave_value_list;
34 class octave_user_code;
35 static std::string bp_empty_string ("");
36 
37 struct
38 bp_type
39 {
40  int line;
42 
43  bp_type (int l, const std::string& c) : line (l), cond (c) { }
44 };
45 
46 // Interface to breakpoints.
47 class
50 {
51 private:
52 
53  bp_table (void) : bp_set () { }
54 
55  ~bp_table (void) { }
56 
57 public:
58 
59  // mapping from (FIXME: arbitrary index??) to line number of breakpoint
60  typedef std::map<int, int> intmap;
61 
62  typedef intmap::const_iterator const_intmap_iterator;
63  typedef intmap::iterator intmap_iterator;
64 
65  typedef std::map <std::string, intmap> fname_line_map;
66 
67  typedef fname_line_map::const_iterator const_fname_line_map_iterator;
68  typedef fname_line_map::iterator fname_line_map_iterator;
69 
70  typedef std::map <std::string, std::list<bp_type> > fname_bp_map;
71  typedef fname_bp_map::const_iterator const_fname_bp_map_iterator;
72  typedef fname_bp_map::iterator fname_bp_map_iterator;
73 
74  static bool instance_ok (void);
75 
76  // Add a breakpoint at the nearest executable line.
77  static intmap add_breakpoint (const std::string& fname = "",
78  const intmap& lines = intmap (),
79  const std::string& condition = bp_empty_string)
80  {
81  return instance_ok ()
82  ? instance->do_add_breakpoint (fname, lines, condition) : intmap ();
83  }
84 
85  // Remove a breakpoint from a line in file.
86  static int remove_breakpoint (const std::string& fname = "",
87  const intmap& lines = intmap ())
88  {
89  return instance_ok ()
90  ? instance->do_remove_breakpoint (fname, lines) : 0;
91  }
92 
93  // Remove all the breakpoints in a specified file.
95  bool silent = false)
96  {
97  return instance_ok ()
98  ? instance->do_remove_all_breakpoints_in_file (fname, silent)
99  : intmap ();
100  }
101 
102  // Remove all the breakpoints registered with octave.
103  static void remove_all_breakpoints (void)
104  {
105  if (instance_ok ())
106  instance->do_remove_all_breakpoints ();
107  }
108 
109  // Return all breakpoints. Each element of the map is a vector
110  // containing the breakpoints corresponding to a given function name.
111  static fname_bp_map
113  {
114  return instance_ok ()
115  ? instance->do_get_breakpoint_list (fname_list) : fname_bp_map ();
116  }
117 
118  static bool
120  {
121  return instance_ok () ? instance->do_have_breakpoints () : 0;
122  }
123 
124  // Should we enter debugging for this particular error identifier?
125  static bool
127  {
128  return (errors_that_stop.empty () || errors_that_stop.count (ID));
129  }
130 
131  // Should we enter debugging for this particular identifier in a try/catch?
132  static bool
134  {
135  return (caught_that_stop.empty () || caught_that_stop.count (ID));
136  }
137 
138  // Should we enter debugging for this particular warning identifier?
139  static bool
141  {
142  return (warnings_that_stop.empty () || warnings_that_stop.count (ID));
143  }
144 
145  static octave_map stop_on_err_warn_status (bool toScreen);
146 
147  static void dbstop_process_map_args (const octave_map& mv);
148 
149  static void dbclear_all_signals (void);
150 
151  static bool condition_valid (const std::string& cond);
152 
153  friend void parse_dbfunction_params (const char *, const octave_value_list&,
155  std::string&);
156 
157 private:
158 
159  typedef std::set<std::string>::const_iterator const_bp_set_iterator;
160  typedef std::set<std::string>::iterator bp_set_iterator;
161 
162  // Set of function (.m file) names containing at least one breakpoint.
163  std::set<std::string> bp_set;
164 
165  // Set of error and warning message IDs that cause us to stop
166  // *if* Vdebug_on_error / Vdebug_on_caught / Vdebug_on_warning is set.
167  // Empty means stop on any error / caught error / warning.
168  static std::set<std::string> errors_that_stop;
169  static std::set<std::string> caught_that_stop;
170  static std::set<std::string> warnings_that_stop;
171 
173 
174  static void cleanup_instance (void) { delete instance; instance = 0; }
175 
176  bool do_add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
177  const intmap& line, const std::string& condition,
178  intmap& retval);
179 
180  intmap do_add_breakpoint (const std::string& fname, const intmap& lines,
181  const std::string& condition);
182 
183  int do_remove_breakpoint_1 (octave_user_code *fcn, const std::string&,
184  const intmap& lines);
185 
186  int do_remove_breakpoint (const std::string&, const intmap& lines);
187 
188  intmap do_remove_all_breakpoints_in_file_1 (octave_user_code *fcn,
189  const std::string& fname);
190 
191  intmap do_remove_all_breakpoints_in_file (const std::string& fname,
192  bool silent);
193 
194  void do_remove_all_breakpoints (void);
195 
196  fname_bp_map do_get_breakpoint_list (const octave_value_list& fname_list);
197 
198  bool do_have_breakpoints (void) { return (! bp_set.empty ()); }
199 };
200 
201 extern std::string get_file_line (const std::string& fname, size_t line);
202 
203 #endif
static bool debug_on_caught(const std::string &ID)
Definition: debug.h:133
static void cleanup_instance(void)
Definition: debug.h:174
bool do_have_breakpoints(void)
Definition: debug.h:198
static fname_bp_map get_breakpoint_list(const octave_value_list &fname_list)
Definition: debug.h:112
static intmap add_breakpoint(const std::string &fname="", const intmap &lines=intmap(), const std::string &condition=bp_empty_string)
Definition: debug.h:77
fname
Definition: load-save.cc:754
fname_bp_map::const_iterator const_fname_bp_map_iterator
Definition: debug.h:71
intmap::const_iterator const_intmap_iterator
Definition: debug.h:62
std::map< std::string, intmap > fname_line_map
Definition: debug.h:65
static bool have_breakpoints(void)
Definition: debug.h:119
~bp_table(void)
Definition: debug.h:55
std::set< std::string >::iterator bp_set_iterator
Definition: debug.h:160
static std::string bp_empty_string("")
std::set< std::string > bp_set
Definition: debug.h:163
static bool debug_on_warn(const std::string &ID)
Definition: debug.h:140
void parse_dbfunction_params(const char *who, const octave_value_list &args, std::string &symbol_name, bp_table::intmap &lines, std::string &cond)
Definition: debug.cc:226
fname_bp_map::iterator fname_bp_map_iterator
Definition: debug.h:72
octave_function * fcn
Definition: ov-class.cc:1743
bp_type(int l, const std::string &c)
Definition: debug.h:43
static std::set< std::string > caught_that_stop
Definition: debug.h:169
intmap::iterator intmap_iterator
Definition: debug.h:63
std::set< std::string >::const_iterator const_bp_set_iterator
Definition: debug.h:159
static std::set< std::string > warnings_that_stop
Definition: debug.h:170
#define OCTINTERP_API
Definition: mexproto.h:69
Definition: debug.h:47
std::map< int, int > intmap
Definition: debug.h:60
fname_line_map::iterator fname_line_map_iterator
Definition: debug.h:68
Definition: debug.h:37
std::map< std::string, std::list< bp_type > > fname_bp_map
Definition: debug.h:70
octave_value retval
Definition: data.cc:6294
std::string cond
Definition: debug.h:41
std::string get_file_line(const std::string &fname, size_t line)
Definition: debug.cc:141
static intmap remove_all_breakpoints_in_file(const std::string &fname, bool silent=false)
Definition: debug.h:94
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
static std::set< std::string > errors_that_stop
Definition: debug.h:168
int line
Definition: debug.h:40
fname_line_map::const_iterator const_fname_line_map_iterator
Definition: debug.h:67
static bp_table * instance
Definition: debug.h:172
static void remove_all_breakpoints(void)
Definition: debug.h:103
bp_table(void)
Definition: debug.h:53
static int remove_breakpoint(const std::string &fname="", const intmap &lines=intmap())
Definition: debug.h:86
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854
static bool debug_on_err(const std::string &ID)
Definition: debug.h:126