GNU Octave  6.2.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-2021 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 
40 namespace octave
41 {
42  class tree_evaluator;
43 
44  struct bp_type
45  {
46  int line;
47  std::string cond;
48 
49  bp_type (int l, const std::string& c) : line (l), cond (c) { }
50  };
51 
52  // Interface to breakpoints.
53  class OCTINTERP_API bp_table
54  {
55  public:
56 
58  : m_evaluator (tw), m_bp_set (), m_errors_that_stop (),
59  m_caught_that_stop (), m_warnings_that_stop ()
60  { }
61 
62  ~bp_table (void) = default;
63 
64  // mapping from (FIXME: arbitrary index??) to line number of breakpoint
65  typedef std::map<int, int> intmap;
66 
67  typedef intmap::const_iterator const_intmap_iterator;
68  typedef intmap::iterator intmap_iterator;
69 
70  typedef std::map <std::string, intmap> fname_line_map;
71 
72  typedef fname_line_map::const_iterator const_fname_line_map_iterator;
73  typedef fname_line_map::iterator fname_line_map_iterator;
74 
75  typedef std::map <std::string, std::list<bp_type>> fname_bp_map;
76  typedef fname_bp_map::const_iterator const_fname_bp_map_iterator;
77  typedef fname_bp_map::iterator fname_bp_map_iterator;
78 
79  // Add a breakpoint at the nearest executable line.
80  intmap add_breakpoint (const std::string& fname = "",
81  const std::string& class_name = "",
82  const intmap& lines = intmap (),
83  const std::string& condition = "");
84 
85  // Remove a breakpoint from a line in file.
86  int remove_breakpoint (const std::string& fname = "",
87  const intmap& lines = intmap ());
88 
89  // Remove all the breakpoints in a specified file.
90  intmap remove_all_breakpoints_in_file (const std::string& fname,
91  bool silent = false);
92 
93  // Remove all the breakpoints registered with octave.
94  void remove_all_breakpoints (void);
95 
96  // Return all breakpoints. Each element of the map is a vector
97  // containing the breakpoints corresponding to a given function name.
98  fname_bp_map get_breakpoint_list (const octave_value_list& fname_list);
99 
100  bool have_breakpoints (void) { return (! m_bp_set.empty ()); }
101 
102  // Should we enter debugging for this particular error identifier?
103  bool debug_on_err (const std::string& id)
104  {
105  return (m_errors_that_stop.empty () || m_errors_that_stop.count (id));
106  }
107 
108  // Should we enter debugging for this particular identifier in a try/catch?
109  bool debug_on_caught (const std::string& id)
110  {
111  return (m_caught_that_stop.empty () || m_caught_that_stop.count (id));
112  }
113 
114  // Should we enter debugging for this particular warning identifier?
115  bool debug_on_warn (const std::string& id)
116  {
117  return (m_warnings_that_stop.empty () || m_warnings_that_stop.count (id));
118  }
119 
120  octave_map stop_on_err_warn_status (bool to_screen);
121 
122  void dbstop_process_map_args (const octave_map& mv);
123 
124  void dbclear_all_signals (void);
125 
126  bool condition_valid (const std::string& cond);
127 
128  void parse_dbfunction_params (const char *who, const octave_value_list& args,
129  std::string& func_name, std::string& class_name,
130  bp_table::intmap& lines, std::string& cond);
131 
132  private:
133 
134  typedef std::set<std::string>::const_iterator const_bp_set_iterator;
135  typedef std::set<std::string>::iterator bp_set_iterator;
136 
138 
139  // Set of function (.m file) names containing at least one breakpoint.
140  std::set<std::string> m_bp_set;
141 
142  // Set of error and warning message IDs that cause us to stop
143  // *if* Vdebug_on_error / Vdebug_on_caught / Vdebug_on_warning is set.
144  // Empty means stop on any error / caught error / warning.
145  std::set<std::string> m_errors_that_stop;
146  std::set<std::string> m_caught_that_stop;
147  std::set<std::string> m_warnings_that_stop;
148 
149  void set_stop_flag (const char *who, const std::string& condition,
150  bool on_off);
151 
152  void process_id_list (const char *who, const std::string& condition,
153  const octave_value_list& args,
154  int nargin, int& pos, bool on_off,
155  std::set<std::string>& id_list);
156 
157  bool add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
158  const intmap& line, const std::string& condition,
159  intmap& retval);
160 
161  int remove_breakpoint_1 (octave_user_code *fcn, const std::string&,
162  const intmap& lines);
163 
165  const std::string& fname);
166  };
167 
168  OCTAVE_DEPRECATED (5, "use 'octave::get_user_code' instead")
169  extern octave_user_code * get_user_code (const std::string& fname = "");
170 }
171 
172 #endif
bool have_breakpoints(void)
Definition: bp-table.h:100
std::map< std::string, intmap > fname_line_map
Definition: bp-table.h:70
fname_line_map::const_iterator const_fname_line_map_iterator
Definition: bp-table.h:72
fname_bp_map::const_iterator const_fname_bp_map_iterator
Definition: bp-table.h:76
fname_bp_map::iterator fname_bp_map_iterator
Definition: bp-table.h:77
intmap::iterator intmap_iterator
Definition: bp-table.h:68
std::map< std::string, std::list< bp_type > > fname_bp_map
Definition: bp-table.h:75
std::set< std::string > m_warnings_that_stop
Definition: bp-table.h:147
bp_table(tree_evaluator &tw)
Definition: bp-table.h:57
std::set< std::string > m_errors_that_stop
Definition: bp-table.h:145
std::set< std::string >::iterator bp_set_iterator
Definition: bp-table.h:135
bool debug_on_err(const std::string &id)
Definition: bp-table.h:103
~bp_table(void)=default
bool debug_on_warn(const std::string &id)
Definition: bp-table.h:115
intmap remove_all_breakpoints_in_file_1(octave_user_code *fcn, const std::string &fname)
intmap::const_iterator const_intmap_iterator
Definition: bp-table.h:67
fname_line_map::iterator fname_line_map_iterator
Definition: bp-table.h:73
std::set< std::string > m_caught_that_stop
Definition: bp-table.h:146
std::set< std::string > m_bp_set
Definition: bp-table.h:140
bool debug_on_caught(const std::string &id)
Definition: bp-table.h:109
std::set< std::string >::const_iterator const_bp_set_iterator
Definition: bp-table.h:134
std::map< int, int > intmap
Definition: bp-table.h:65
tree_evaluator & m_evaluator
Definition: bp-table.h:137
octave_user_code * get_user_code(const std::string &fname)
Definition: bp-table.cc:1002
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
bp_type(int l, const std::string &c)
Definition: bp-table.h:49
std::string cond
Definition: bp-table.h:47