Mercurial > hg > octave-lyh
annotate src/debug.h @ 9183:94ae487acd1b
use set instead of map to keep track of debugger breakpoints
author | jpswensen@compsci34-754-2010.compscidhcp.jhu.edu |
---|---|
date | Tue, 05 May 2009 15:10:25 -0400 |
parents | eb63fbe60fab |
children | 3c1762c7e787 |
rev | line source |
---|---|
7084 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Ben Sapp |
7084 | 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> | |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
27 #include <set> |
7084 | 28 #include "ov.h" |
29 #include "dRowVector.h" | |
30 | |
31 class octave_value_list; | |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7084
diff
changeset
|
32 class octave_user_code; |
7084 | 33 |
34 // Interface to breakpoints,. | |
35 | |
36 class bp_table | |
37 { | |
38 private: | |
39 | |
40 bp_table (void) { } | |
41 | |
42 ~bp_table (void) { } | |
43 | |
44 public: | |
45 | |
46 typedef std::map<int, int> intmap; | |
47 | |
48 typedef intmap::const_iterator const_intmap_iterator; | |
49 typedef intmap::iterator intmap_iterator; | |
50 | |
51 typedef std::map <std::string, intmap> fname_line_map; | |
52 | |
53 typedef fname_line_map::const_iterator const_fname_line_map_iterator; | |
54 typedef fname_line_map::iterator fname_line_map_iterator; | |
55 | |
56 static bool instance_ok (void) | |
57 { | |
58 bool retval = true; | |
59 | |
60 if (! instance) | |
61 instance = new bp_table (); | |
62 | |
63 if (! instance) | |
64 { | |
65 ::error ("unable to create breakpoint table!"); | |
66 retval = false; | |
67 } | |
68 | |
69 return retval; | |
70 } | |
71 | |
72 // Add a breakpoint at the nearest executable line. | |
73 static intmap add_breakpoint (const std::string& fname = "", | |
74 const intmap& lines = intmap ()) | |
75 { | |
76 return instance_ok () | |
77 ? instance->do_add_breakpoint (fname, lines) : intmap (); | |
78 } | |
79 | |
80 // Remove a breakpoint from a line in file. | |
81 static int remove_breakpoint (const std::string& fname = "", | |
82 const intmap& lines = intmap ()) | |
83 { | |
84 return instance_ok () | |
85 ? instance->do_remove_breakpoint (fname, lines) : 0; | |
86 } | |
87 | |
88 // Remove all the breakpoints in a specified file. | |
8123
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
7719
diff
changeset
|
89 static intmap remove_all_breakpoints_in_file (const std::string& fname, |
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
7719
diff
changeset
|
90 bool silent = false) |
7084 | 91 { |
92 return instance_ok () | |
8123
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
7719
diff
changeset
|
93 ? instance->do_remove_all_breakpoints_in_file (fname, silent) : intmap (); |
7084 | 94 } |
95 | |
96 // Remove all the breakpoints registered with octave. | |
97 static void remove_all_breakpoints (void) | |
98 { | |
99 if (instance_ok ()) | |
100 instance->do_remove_all_breakpoints (); | |
101 } | |
102 | |
103 // Return all breakpoints. Each element of the map is a vector | |
104 // containing the breakpoints corresponding to a given function name. | |
105 static fname_line_map | |
106 get_breakpoint_list (const octave_value_list& fname_list) | |
107 { | |
108 return instance_ok () | |
109 ? instance->do_get_breakpoint_list (fname_list) : fname_line_map (); | |
110 } | |
111 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
112 static bool |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
113 have_breakpoints (void) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
114 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
115 return instance_ok () ? instance->do_have_breakpoints () : 0; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
116 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
117 |
7084 | 118 private: |
119 | |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
120 typedef std::set<std::string>::const_iterator const_bp_set_iterator; |
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
121 typedef std::set<std::string>::iterator bp_set_iterator; |
7084 | 122 |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
123 // Set of function names containing at least one breakpoint. |
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
124 std::set<std::string> bp_set; |
7084 | 125 |
126 static bp_table *instance; | |
127 | |
128 intmap do_add_breakpoint (const std::string& fname, const intmap& lines); | |
129 | |
130 int do_remove_breakpoint (const std::string&, const intmap& lines); | |
131 | |
8123
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
7719
diff
changeset
|
132 intmap do_remove_all_breakpoints_in_file (const std::string& fname, |
eb2beef9a9ff
clear breakpoints is function found to be out of date
David Bateman <dbateman@free.fr>
parents:
7719
diff
changeset
|
133 bool silent); |
7084 | 134 |
135 void do_remove_all_breakpoints (void); | |
136 | |
137 fname_line_map do_get_breakpoint_list (const octave_value_list& fname_list); | |
138 | |
9183
94ae487acd1b
use set instead of map to keep track of debugger breakpoints
jpswensen@compsci34-754-2010.compscidhcp.jhu.edu
parents:
8920
diff
changeset
|
139 bool do_have_breakpoints (void) { return (! bp_set.empty ()); } |
7084 | 140 }; |
141 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
142 std::string get_file_line (const std::string& fname, size_t line); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8123
diff
changeset
|
143 |
7084 | 144 #endif |
145 | |
146 /* | |
147 ;;; Local Variables: *** | |
148 ;;; mode: C++ *** | |
149 ;;; End: *** | |
150 */ |