7084
|
1 /* |
|
2 |
|
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 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 "ov.h" |
|
28 #include "dRowVector.h" |
|
29 |
|
30 class octave_value_list; |
|
31 class octave_user_function; |
|
32 |
|
33 // Interface to breakpoints,. |
|
34 |
|
35 class bp_table |
|
36 { |
|
37 private: |
|
38 |
|
39 bp_table (void) { } |
|
40 |
|
41 ~bp_table (void) { } |
|
42 |
|
43 public: |
|
44 |
|
45 typedef std::map<int, int> intmap; |
|
46 |
|
47 typedef intmap::const_iterator const_intmap_iterator; |
|
48 typedef intmap::iterator intmap_iterator; |
|
49 |
|
50 typedef std::map <std::string, intmap> fname_line_map; |
|
51 |
|
52 typedef fname_line_map::const_iterator const_fname_line_map_iterator; |
|
53 typedef fname_line_map::iterator fname_line_map_iterator; |
|
54 |
|
55 static bool instance_ok (void) |
|
56 { |
|
57 bool retval = true; |
|
58 |
|
59 if (! instance) |
|
60 instance = new bp_table (); |
|
61 |
|
62 if (! instance) |
|
63 { |
|
64 ::error ("unable to create breakpoint table!"); |
|
65 retval = false; |
|
66 } |
|
67 |
|
68 return retval; |
|
69 } |
|
70 |
|
71 // Add a breakpoint at the nearest executable line. |
|
72 static intmap add_breakpoint (const std::string& fname = "", |
|
73 const intmap& lines = intmap ()) |
|
74 { |
|
75 return instance_ok () |
|
76 ? instance->do_add_breakpoint (fname, lines) : intmap (); |
|
77 } |
|
78 |
|
79 // Remove a breakpoint from a line in file. |
|
80 static int remove_breakpoint (const std::string& fname = "", |
|
81 const intmap& lines = intmap ()) |
|
82 { |
|
83 return instance_ok () |
|
84 ? instance->do_remove_breakpoint (fname, lines) : 0; |
|
85 } |
|
86 |
|
87 // Remove all the breakpoints in a specified file. |
|
88 static intmap remove_all_breakpoints_in_file (const std::string& fname) |
|
89 { |
|
90 return instance_ok () |
|
91 ? instance->do_remove_all_breakpoints_in_file (fname) : intmap (); |
|
92 } |
|
93 |
|
94 // Remove all the breakpoints registered with octave. |
|
95 static void remove_all_breakpoints (void) |
|
96 { |
|
97 if (instance_ok ()) |
|
98 instance->do_remove_all_breakpoints (); |
|
99 } |
|
100 |
|
101 // Return all breakpoints. Each element of the map is a vector |
|
102 // containing the breakpoints corresponding to a given function name. |
|
103 static fname_line_map |
|
104 get_breakpoint_list (const octave_value_list& fname_list) |
|
105 { |
|
106 return instance_ok () |
|
107 ? instance->do_get_breakpoint_list (fname_list) : fname_line_map (); |
|
108 } |
|
109 |
|
110 private: |
|
111 |
|
112 // Map from function names to function objects for functions |
|
113 // containing at least one breakpoint. |
|
114 typedef std::map<std::string, octave_user_function *> breakpoint_map; |
|
115 |
|
116 typedef breakpoint_map::const_iterator const_breakpoint_map_iterator; |
|
117 typedef breakpoint_map::iterator breakpoint_map_iterator; |
|
118 |
|
119 breakpoint_map bp_map; |
|
120 |
|
121 static bp_table *instance; |
|
122 |
|
123 intmap do_add_breakpoint (const std::string& fname, const intmap& lines); |
|
124 |
|
125 int do_remove_breakpoint (const std::string&, const intmap& lines); |
|
126 |
|
127 intmap do_remove_all_breakpoints_in_file (const std::string& fname); |
|
128 |
|
129 void do_remove_all_breakpoints (void); |
|
130 |
|
131 fname_line_map do_get_breakpoint_list (const octave_value_list& fname_list); |
|
132 |
|
133 }; |
|
134 |
|
135 #endif |
|
136 |
|
137 /* |
|
138 ;;; Local Variables: *** |
|
139 ;;; mode: C++ *** |
|
140 ;;; End: *** |
|
141 */ |