GNU Octave  3.8.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-2013 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) : intmap ();
82  }
83 
84  // Remove all the breakpoints registered with octave.
85  static void remove_all_breakpoints (void)
86  {
87  if (instance_ok ())
88  instance->do_remove_all_breakpoints ();
89  }
90 
91  // Return all breakpoints. Each element of the map is a vector
92  // containing the breakpoints corresponding to a given function name.
93  static fname_line_map
94  get_breakpoint_list (const octave_value_list& fname_list)
95  {
96  return instance_ok ()
97  ? instance->do_get_breakpoint_list (fname_list) : fname_line_map ();
98  }
99 
100  static bool
101  have_breakpoints (void)
102  {
103  return instance_ok () ? instance->do_have_breakpoints () : 0;
104  }
105 
106 private:
107 
108  typedef std::set<std::string>::const_iterator const_bp_set_iterator;
109  typedef std::set<std::string>::iterator bp_set_iterator;
110 
111  // Set of function names containing at least one breakpoint.
112  std::set<std::string> bp_set;
113 
115 
116  static void cleanup_instance (void) { delete instance; instance = 0; }
117 
118  bool do_add_breakpoint_1 (octave_user_code *fcn, const std::string& fname,
119  const intmap& line, intmap& retval);
120 
121  intmap do_add_breakpoint (const std::string& fname, const intmap& lines);
122 
123  int do_remove_breakpoint_1 (octave_user_code *fcn, const std::string&,
124  const intmap& lines);
125 
126  int do_remove_breakpoint (const std::string&, const intmap& lines);
127 
128  intmap do_remove_all_breakpoints_in_file_1 (octave_user_code *fcn,
129  const std::string& fname);
130 
131  intmap do_remove_all_breakpoints_in_file (const std::string& fname,
132  bool silent);
133 
134  void do_remove_all_breakpoints (void);
135 
136  fname_line_map do_get_breakpoint_list (const octave_value_list& fname_list);
137 
138  bool do_have_breakpoints (void) { return (! bp_set.empty ()); }
139 };
140 
141 extern std::string get_file_line (const std::string& fname, size_t line);
142 
143 #endif