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