GNU Octave  4.0.0
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-2015 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 <map>
27 #include <set>
28 #include "ov.h"
29 #include "dRowVector.h"
30 
31 class octave_value_list;
32 class octave_user_code;
33 
34 // Interface to breakpoints,.
35 
36 class
39 {
40 private:
41 
42  bp_table (void) : bp_set () { }
43 
44  ~bp_table (void) { }
45 
46 public:
47 
48  typedef std::map<int, int> intmap;
49 
50  typedef intmap::const_iterator const_intmap_iterator;
51  typedef intmap::iterator intmap_iterator;
52 
53  typedef std::map <std::string, intmap> fname_line_map;
54 
55  typedef fname_line_map::const_iterator const_fname_line_map_iterator;
56  typedef fname_line_map::iterator fname_line_map_iterator;
57 
58  static bool instance_ok (void);
59 
60  // Add a breakpoint at the nearest executable line.
61  static intmap add_breakpoint (const std::string& fname = "",
62  const intmap& lines = intmap ())
63  {
64  return instance_ok ()
65  ? instance->do_add_breakpoint (fname, lines) : intmap ();
66  }
67 
68  // Remove a breakpoint from a line in file.
69  static int remove_breakpoint (const std::string& fname = "",
70  const intmap& lines = intmap ())
71  {
72  return instance_ok ()
73  ? instance->do_remove_breakpoint (fname, lines) : 0;
74  }
75 
76  // Remove all the breakpoints in a specified file.
77  static intmap remove_all_breakpoints_in_file (const std::string& fname,
78  bool silent = false)
79  {
80  return instance_ok ()
81  ? instance->do_remove_all_breakpoints_in_file (fname, silent)
82  : intmap ();
83  }
84 
85  // Remove all the breakpoints registered with octave.
86  static void remove_all_breakpoints (void)
87  {
88  if (instance_ok ())
89  instance->do_remove_all_breakpoints ();
90  }
91 
92  // Return all breakpoints. Each element of the map is a vector
93  // containing the breakpoints corresponding to a given function name.
94  static fname_line_map
96  {
97  return instance_ok ()
98  ? instance->do_get_breakpoint_list (fname_list) : fname_line_map ();
99  }
100 
101  static bool
103  {
104  return instance_ok () ? instance->do_have_breakpoints () : 0;
105  }
106 
107 private:
108 
109  typedef std::set<std::string>::const_iterator const_bp_set_iterator;
110  typedef std::set<std::string>::iterator bp_set_iterator;
111 
112  // Set of function names containing at least one breakpoint.
113  std::set<std::string> bp_set;
114 
116 
117  static void cleanup_instance (void) { delete instance; instance = 0; }
118 
119  bool do_add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
120  const intmap& line, intmap& retval);
121 
122  intmap do_add_breakpoint (const std::string& fname, const intmap& lines);
123 
124  int do_remove_breakpoint_1 (octave_user_code *fcn, const std::string&,
125  const intmap& lines);
126 
127  int do_remove_breakpoint (const std::string&, const intmap& lines);
128 
129  intmap do_remove_all_breakpoints_in_file_1 (octave_user_code *fcn,
130  const std::string& fname);
131 
132  intmap do_remove_all_breakpoints_in_file (const std::string& fname,
133  bool silent);
134 
135  void do_remove_all_breakpoints (void);
136 
137  fname_line_map do_get_breakpoint_list (const octave_value_list& fname_list);
138 
139  bool do_have_breakpoints (void) { return (! bp_set.empty ()); }
140 };
141 
142 extern std::string get_file_line (const std::string& fname, size_t line);
143 
144 #endif
static void cleanup_instance(void)
Definition: debug.h:117
bool do_have_breakpoints(void)
Definition: debug.h:139
intmap::const_iterator const_intmap_iterator
Definition: debug.h:50
std::map< std::string, intmap > fname_line_map
Definition: debug.h:53
static bool have_breakpoints(void)
Definition: debug.h:102
~bp_table(void)
Definition: debug.h:44
std::set< std::string >::iterator bp_set_iterator
Definition: debug.h:110
std::set< std::string > bp_set
Definition: debug.h:113
intmap::iterator intmap_iterator
Definition: debug.h:51
std::set< std::string >::const_iterator const_bp_set_iterator
Definition: debug.h:109
#define OCTINTERP_API
Definition: mexproto.h:66
Definition: debug.h:36
std::map< int, int > intmap
Definition: debug.h:48
fname_line_map::iterator fname_line_map_iterator
Definition: debug.h:56
std::string get_file_line(const std::string &fname, size_t line)
Definition: debug.cc:132
static intmap remove_all_breakpoints_in_file(const std::string &fname, bool silent=false)
Definition: debug.h:77
fname_line_map::const_iterator const_fname_line_map_iterator
Definition: debug.h:55
static bp_table * instance
Definition: debug.h:115
static void remove_all_breakpoints(void)
Definition: debug.h:86
bp_table(void)
Definition: debug.h:42
static int remove_breakpoint(const std::string &fname="", const intmap &lines=intmap())
Definition: debug.h:69
static intmap add_breakpoint(const std::string &fname="", const intmap &lines=intmap())
Definition: debug.h:61
static fname_line_map get_breakpoint_list(const octave_value_list &fname_list)
Definition: debug.h:95