GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
bp-table.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2001-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_bp_table_h)
27 #define octave_bp_table_h 1
28 
29 #include "octave-config.h"
30 
31 #include <list>
32 #include <map>
33 #include <set>
34 #include <string>
35 
36 class octave_map;
37 class octave_user_code;
38 class octave_value_list;
39 
41 
42 class tree_evaluator;
43 
44 struct bp_type
45 {
46 public:
47  bp_type (int l, const std::string& c) : line (l), cond (c) { }
48 
49  //--------
50 
51  int line;
52  std::string cond;
53 };
54 
55 // Interface to breakpoints.
56 class OCTINTERP_API bp_table
57 {
58 public:
59 
61  : m_evaluator (tw), m_bp_set (), m_errors_that_stop (),
62  m_caught_that_stop (), m_warnings_that_stop ()
63  { }
64 
65  ~bp_table (void) = default;
66 
67  // Set of breakpoint lines.
68  typedef std::set<int> bp_lines;
69 
70  typedef bp_lines::const_iterator const_bp_lines_iterator;
71  typedef bp_lines::iterator bp_lines_iterator;
72 
73  typedef std::map <std::string, bp_lines> fname_line_map;
74 
75  typedef fname_line_map::const_iterator const_fname_line_map_iterator;
76  typedef fname_line_map::iterator fname_line_map_iterator;
77 
78  typedef std::map <std::string, std::list<bp_type>> fname_bp_map;
79  typedef fname_bp_map::const_iterator const_fname_bp_map_iterator;
80  typedef fname_bp_map::iterator fname_bp_map_iterator;
81 
82 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
83  OCTAVE_DEPRECATED (7, "use 'bp_table::add_breakpoints_in_function' instead")
84  int add_breakpoint (const std::string& fname = "",
85  const std::string& class_name = "",
86  int line = 1,
87  const std::string& condition = "")
88  {
89  return add_breakpoint_in_function (fname, class_name, line, condition);
90  }
91 
92  OCTAVE_DEPRECATED (7, "use 'bp_table::add_breakpoints_in_function' instead")
93  bp_lines add_breakpoint (const std::string& fname = "",
94  const std::string& class_name = "",
95  const bp_lines& lines = bp_lines (),
96  const std::string& condition = "")
97  {
98  return add_breakpoints_in_function (fname, class_name, lines, condition);
99  }
100 #endif
101 
102  // Add a breakpoint at the nearest executable line in a function.
103  int add_breakpoint_in_function (const std::string& fname = "",
104  const std::string& class_name = "",
105  int line = 1,
106  const std::string& condition = "");
107 
108  // Add a set of breakpoints at the nearest executable lines in a
109  // function.
110  bp_lines add_breakpoints_in_function (const std::string& fname = "",
111  const std::string& class_name = "",
112  const bp_lines& lines = bp_lines (),
113  const std::string& condition = "");
114 
115  // Add a breakpoint at the nearest executable line in a file.
116  int add_breakpoint_in_file (const std::string& file = "",
117  int line = 1,
118  const std::string& condition = "");
119 
120  // Add a set of breakpoints at the nearest executable lines in a
121  // file.
122  bp_lines add_breakpoints_in_file (const std::string& file = "",
123  const bp_lines& lines = bp_lines (),
124  const std::string& condition = "");
125 
126 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
127  OCTAVE_DEPRECATED (7, "use 'bp_table::remove_breakpoint_from_function' instead")
128  int remove_breakpoint (const std::string& fname = "",
129  int line = 1)
130  {
131  return remove_breakpoint_from_function (fname, line);
132  }
133 
134  OCTAVE_DEPRECATED (7, "use 'bp_table::remove_breakpoints_from_function' instead")
135  int remove_breakpoint (const std::string& fname = "",
136  const bp_lines& lines = bp_lines ())
137  {
138  return remove_breakpoints_from_function (fname, lines);
139  }
140 #endif
141 
142  // Remove a breakpoint from the given line in file.
143  int remove_breakpoint_from_function (const std::string& fname = "",
144  int line = 1);
145 
146  // Remove a set of breakpoints from the given lines in file.
147  int remove_breakpoints_from_function (const std::string& fname = "",
148  const bp_lines& lines = bp_lines ());
149 
150  // Remove all the breakpoints in a specified function.
151  bp_lines remove_all_breakpoints_from_function (const std::string& fname,
152  bool silent = false);
153 
154  // Remove a breakpoint from the given line in file.
155  int remove_breakpoint_from_file (const std::string& file = "",
156  int line = 1);
157 
158  // Remove a set of breakpoints from the given lines in file.
159  int remove_breakpoints_from_file (const std::string& file = "",
160  const bp_lines& lines = bp_lines ());
161 
162 
163 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
164  OCTAVE_DEPRECATED (7, "use 'bp_table::remove_all_breakpoints_from_function' instead")
165  bp_lines remove_all_breakpoints_in_file (const std::string& fname,
166  bool silent = false)
167  {
168  return remove_all_breakpoints_from_function (fname, silent);
169  }
170 #endif
171 
172  // Remove all the breakpoints from a file.
173  bp_lines remove_all_breakpoints_from_file (const std::string& file,
174  bool silent = false);
175 
176  // Remove all the breakpoints registered with octave.
177  void remove_all_breakpoints (void);
178 
179  // Return all breakpoints. Each element of the map is a vector
180  // containing the breakpoints corresponding to a given function name.
181  fname_bp_map get_breakpoint_list (const octave_value_list& fname_list);
182 
183  bool have_breakpoints (void) { return (! m_bp_set.empty ()); }
184 
185  // Should we enter debugging for this particular error identifier?
186  bool debug_on_err (const std::string& id)
187  {
188  return (m_errors_that_stop.empty () || m_errors_that_stop.count (id));
189  }
190 
191  // Should we enter debugging for this particular identifier in a try/catch?
192  bool debug_on_caught (const std::string& id)
193  {
194  return (m_caught_that_stop.empty () || m_caught_that_stop.count (id));
195  }
196 
197  // Should we enter debugging for this particular warning identifier?
198  bool debug_on_warn (const std::string& id)
199  {
200  return (m_warnings_that_stop.empty () || m_warnings_that_stop.count (id));
201  }
202 
203  octave_map stop_on_err_warn_status (bool to_screen);
204 
205  void dbstop_process_map_args (const octave_map& mv);
206 
207  void dbclear_all_signals (void);
208 
209  bool condition_valid (const std::string& cond);
210 
211  void parse_dbfunction_params (const char *who,
212  const octave_value_list& args,
213  std::string& fcn_name,
214  std::string& class_name,
215  bp_table::bp_lines& lines,
216  std::string& cond);
217 
218 private:
219 
220  typedef std::set<std::string>::const_iterator const_bp_set_iterator;
221  typedef std::set<std::string>::iterator bp_set_iterator;
222 
224 
225  // Set of function (.m file) names containing at least one breakpoint.
226  std::set<std::string> m_bp_set;
227 
228  // Set of error and warning message IDs that cause us to stop
229  // *if* Vdebug_on_error / Vdebug_on_caught / Vdebug_on_warning is set.
230  // Empty means stop on any error / caught error / warning.
231  std::set<std::string> m_errors_that_stop;
232  std::set<std::string> m_caught_that_stop;
233  std::set<std::string> m_warnings_that_stop;
234 
235  void set_stop_flag (const char *who, const std::string& condition,
236  bool on_off);
237 
238  void process_id_list (const char *who, const std::string& condition,
239  const octave_value_list& args,
240  int nargin, int& pos, bool on_off,
241  std::set<std::string>& id_list);
242 
243  bool add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
244  const bp_lines& line, const std::string& condition,
245  bp_lines& retval);
246 
247  int remove_breakpoint_1 (octave_user_code *fcn, const std::string&,
248  const bp_lines& lines);
249 
251  const std::string& fname);
252 };
253 
255 
256 #endif
OCTAVE_END_NAMESPACE(octave)
bool debug_on_warn(const std::string &id)
Definition: bp-table.h:198
std::set< std::string > m_caught_that_stop
Definition: bp-table.h:232
~bp_table(void)=default
bool debug_on_err(const std::string &id)
Definition: bp-table.h:186
fname_line_map::iterator fname_line_map_iterator
Definition: bp-table.h:76
tree_evaluator & m_evaluator
Definition: bp-table.h:223
std::set< std::string > m_warnings_that_stop
Definition: bp-table.h:233
std::set< std::string >::iterator bp_set_iterator
Definition: bp-table.h:221
std::set< std::string > m_errors_that_stop
Definition: bp-table.h:231
std::set< int > bp_lines
Definition: bp-table.h:68
fname_bp_map::iterator fname_bp_map_iterator
Definition: bp-table.h:80
bp_lines::iterator bp_lines_iterator
Definition: bp-table.h:71
std::set< std::string >::const_iterator const_bp_set_iterator
Definition: bp-table.h:220
bp_lines::const_iterator const_bp_lines_iterator
Definition: bp-table.h:70
bp_table(tree_evaluator &tw)
Definition: bp-table.h:60
bool have_breakpoints(void)
Definition: bp-table.h:183
fname_bp_map::const_iterator const_fname_bp_map_iterator
Definition: bp-table.h:79
std::set< std::string > m_bp_set
Definition: bp-table.h:226
std::map< std::string, std::list< bp_type > > fname_bp_map
Definition: bp-table.h:78
fname_line_map::const_iterator const_fname_line_map_iterator
Definition: bp-table.h:75
bool debug_on_caught(const std::string &id)
Definition: bp-table.h:192
bp_lines remove_all_breakpoints_in_file_1(octave_user_code *fcn, const std::string &fname)
std::map< std::string, bp_lines > fname_line_map
Definition: bp-table.h:73
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
int line
Definition: bp-table.h:51
std::string cond
Definition: bp-table.h:52
bp_type(int l, const std::string &c)
Definition: bp-table.h:47