GNU Octave  9.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-2024 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  OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (bp_table)
66 
67  ~bp_table () = default;
68 
69  // Set of breakpoint lines.
70  typedef std::set<int> bp_lines;
71 
72  typedef bp_lines::const_iterator const_bp_lines_iterator;
73  typedef bp_lines::iterator bp_lines_iterator;
74 
75  typedef std::map <std::string, bp_lines> fname_line_map;
76 
77  typedef fname_line_map::const_iterator const_fname_line_map_iterator;
78  typedef fname_line_map::iterator fname_line_map_iterator;
79 
80  typedef std::map <std::string, std::list<bp_type>> fname_bp_map;
81  typedef fname_bp_map::const_iterator const_fname_bp_map_iterator;
82  typedef fname_bp_map::iterator fname_bp_map_iterator;
83 
84  // Add a breakpoint at the nearest executable line in a function.
85  int add_breakpoint_in_function (const std::string& fcn_ident = "",
86  int line = 1,
87  const std::string& condition = "");
88 
89  // Add a set of breakpoints at the nearest executable lines in a
90  // function.
91  bp_lines add_breakpoints_in_function (const std::string& fcn_ident = "",
92  const bp_lines& lines = bp_lines (),
93  const std::string& condition = "");
94 
95  // Add a breakpoint at the nearest executable line in a file.
96  int add_breakpoint_in_file (const std::string& file = "",
97  int line = 1,
98  const std::string& condition = "");
99 
100  // Add a set of breakpoints at the nearest executable lines in a
101  // file.
102  bp_lines add_breakpoints_in_file (const std::string& file = "",
103  const bp_lines& lines = bp_lines (),
104  const std::string& condition = "");
105 
106  // Remove a breakpoint from the given line in file.
107  int remove_breakpoint_from_function (const std::string& fcn_ident = "",
108  int line = 1);
109 
110  // Remove a set of breakpoints from the given lines in file.
111  int remove_breakpoints_from_function (const std::string& fcn_ident = "",
112  const bp_lines& lines = bp_lines ());
113 
114  // Remove all the breakpoints in a specified function.
115  bp_lines remove_all_breakpoints_from_function (const std::string& fcn_ident,
116  bool silent = false);
117 
118  // Remove a breakpoint from the given line in file.
119  int remove_breakpoint_from_file (const std::string& file = "",
120  int line = 1);
121 
122  // Remove a set of breakpoints from the given lines in file.
123  int remove_breakpoints_from_file (const std::string& file = "",
124  const bp_lines& lines = bp_lines ());
125 
126 
127  // Remove all the breakpoints from a file.
128  bp_lines remove_all_breakpoints_from_file (const std::string& file,
129  bool silent = false);
130 
131  // Remove all the breakpoints registered with octave.
132  void remove_all_breakpoints ();
133 
134  // Return all breakpoints. Each element of the map is a vector
135  // containing the breakpoints corresponding to a given function name.
136  fname_bp_map get_breakpoint_list (const octave_value_list& fname_list);
137 
138  bool have_breakpoints () { return (! m_bp_set.empty ()); }
139 
140  // Should we enter debugging for this particular error identifier?
141  bool debug_on_err (const std::string& id)
142  {
143  return (m_errors_that_stop.empty () || m_errors_that_stop.count (id));
144  }
145 
146  // Should we enter debugging for this particular identifier in a try/catch?
147  bool debug_on_caught (const std::string& id)
148  {
149  return (m_caught_that_stop.empty () || m_caught_that_stop.count (id));
150  }
151 
152  // Should we enter debugging for this particular warning identifier?
153  bool debug_on_warn (const std::string& id)
154  {
155  return (m_warnings_that_stop.empty () || m_warnings_that_stop.count (id));
156  }
157 
158  octave_map stop_on_err_warn_status (bool to_screen);
159 
160  void dbstop_process_map_args (const octave_map& mv);
161 
162  void dbclear_all_signals ();
163 
164  bool condition_valid (const std::string& cond);
165 
166  void parse_dbfunction_params (const char *who,
167  const octave_value_list& args,
168  std::string& fcn_name,
169  std::string& class_name,
170  bp_table::bp_lines& lines,
171  std::string& cond);
172 
173 private:
174 
175  typedef std::set<std::string>::const_iterator const_bp_set_iterator;
176  typedef std::set<std::string>::iterator bp_set_iterator;
177 
178  tree_evaluator& m_evaluator;
179 
180  // Set of function (.m file) names containing at least one breakpoint.
181  std::set<std::string> m_bp_set;
182 
183  // Set of error and warning message IDs that cause us to stop
184  // *if* Vdebug_on_error / Vdebug_on_caught / Vdebug_on_warning is set.
185  // Empty means stop on any error / caught error / warning.
186  std::set<std::string> m_errors_that_stop;
187  std::set<std::string> m_caught_that_stop;
188  std::set<std::string> m_warnings_that_stop;
189 
190  void set_stop_flag (const char *who, const std::string& condition,
191  bool on_off);
192 
193  void process_id_list (const char *who, const std::string& condition,
194  const octave_value_list& args,
195  int nargin, int& pos, bool on_off,
196  std::set<std::string>& id_list);
197 
198  bool add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
199  const bp_lines& line, const std::string& condition,
200  bp_lines& retval);
201 
202  int remove_breakpoint_1 (octave_user_code *fcn, const std::string&,
203  const bp_lines& lines);
204 
205  bp_lines remove_all_breakpoints_in_file_1 (octave_user_code *fcn,
206  const std::string& fname);
207 };
208 
209 OCTAVE_END_NAMESPACE(octave)
210 
211 #endif
bool debug_on_warn(const std::string &id)
Definition: bp-table.h:153
~bp_table()=default
bool debug_on_err(const std::string &id)
Definition: bp-table.h:141
fname_line_map::iterator fname_line_map_iterator
Definition: bp-table.h:78
std::set< int > bp_lines
Definition: bp-table.h:70
bool have_breakpoints()
Definition: bp-table.h:138
fname_bp_map::iterator fname_bp_map_iterator
Definition: bp-table.h:82
bp_lines::iterator bp_lines_iterator
Definition: bp-table.h:73
bp_lines::const_iterator const_bp_lines_iterator
Definition: bp-table.h:72
bp_table(tree_evaluator &tw)
Definition: bp-table.h:60
fname_bp_map::const_iterator const_fname_bp_map_iterator
Definition: bp-table.h:81
std::map< std::string, std::list< bp_type > > fname_bp_map
Definition: bp-table.h:80
fname_line_map::const_iterator const_fname_line_map_iterator
Definition: bp-table.h:77
bool debug_on_caught(const std::string &id)
Definition: bp-table.h:147
std::map< std::string, bp_lines > fname_line_map
Definition: bp-table.h:75
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