Mercurial > hg > octave-lyh
comparison src/debug.cc @ 3805:44386b0e53da
[project @ 2001-03-01 16:54:31 by jwe]
author | jwe |
---|---|
date | Thu, 01 Mar 2001 16:54:33 +0000 |
parents | |
children | d38c7538b954 |
comparison
equal
deleted
inserted
replaced
3804:4073be5aefa1 | 3805:44386b0e53da |
---|---|
1 /* | |
2 | |
3 Copyright (C) 2001 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 2, or (at your option) any | |
10 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, write to the Free | |
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include "defun.h" | |
28 #include "error.h" | |
29 #include "input.h" | |
30 #include "pager.h" | |
31 #include "oct-obj.h" | |
32 #include "utils.h" | |
33 #include "parse.h" | |
34 #include "symtab.h" | |
35 #include "gripes.h" | |
36 #include "ov.h" | |
37 #include "ov-usr-fcn.h" | |
38 #include "ov-fcn.h" | |
39 #include "pt-pr-code.h" | |
40 #include "pt.h" | |
41 #include "pt-bp.h" | |
42 #include "pt-stmt.h" | |
43 #include "toplev.h" | |
44 #include "unwind-prot.h" | |
45 #include "variables.h" | |
46 | |
47 octave_user_function * | |
48 get_user_function (std::string str = "") | |
49 { | |
50 octave_user_function *dbg_fcn = NULL; | |
51 | |
52 if (curr_function) | |
53 { | |
54 dbg_fcn = curr_function; | |
55 } | |
56 else if (str.compare ("")) | |
57 { | |
58 symbol_record *ptr = curr_sym_tab->lookup (str); | |
59 | |
60 if (ptr && ptr->is_user_function ()) | |
61 { | |
62 octave_value tmp = ptr->def (); | |
63 dbg_fcn = static_cast<octave_user_function *> (tmp.function_value ()); | |
64 } | |
65 else | |
66 { | |
67 symbol_record *ptr = lookup_by_name (str, false); | |
68 | |
69 if (ptr && ptr->is_user_function ()) | |
70 { | |
71 octave_value tmp = ptr->def (); | |
72 dbg_fcn = static_cast<octave_user_function *> (tmp.function_value ()); | |
73 } | |
74 } | |
75 } | |
76 | |
77 return dbg_fcn; | |
78 } | |
79 | |
80 DEFUN_TEXT (dbg_set, args, , | |
81 "-*- texinfo -*-\n\ | |
82 @deftypefn {Loadable Function} {rline =} dbg_set (func, line)\n\ | |
83 Set a breakpoint in a function\n\ | |
84 @table @code\n\ | |
85 @item func\n\ | |
86 String representing the function name. When already in debug\n\ | |
87 mode this should be left out and only the line should be given.\n\ | |
88 @item line\n\ | |
89 Line you would like the breakpoint to be set on\n\ | |
90 @end table\n\ | |
91 \n\ | |
92 The rline returned is the real line that the breakpoint was set at.\n\ | |
93 \n\ | |
94 @end deftypefn\n\ | |
95 @seealso{dbg_delete, dbg_list, dbg_where}") | |
96 { | |
97 octave_value retval; | |
98 | |
99 int result = -1; | |
100 int nargin = args.length (); | |
101 | |
102 string_vector argv = args.make_argv ("dbg_set"); | |
103 | |
104 if (error_state) | |
105 return retval; | |
106 | |
107 if (nargin == 2) | |
108 { | |
109 std::string symbol_name = argv[1]; | |
110 | |
111 std::string line_number = argv[2]; | |
112 | |
113 int line = atoi (line_number.c_str ()); | |
114 | |
115 octave_user_function *dbg_fcn = get_user_function (symbol_name); | |
116 | |
117 if (dbg_fcn) | |
118 { | |
119 tree_statement_list *cmds = dbg_fcn->body (); | |
120 result = cmds->set_breakpoint (line); | |
121 } | |
122 else | |
123 error ("unable to find the function requested\n"); | |
124 } | |
125 else if (nargin == 1) | |
126 { | |
127 std::string line_number = argv[1]; | |
128 | |
129 int line = atoi (line_number.c_str ()); | |
130 | |
131 octave_user_function *dbg_fcn = get_user_function (); | |
132 | |
133 if (dbg_fcn) | |
134 { | |
135 tree_statement_list *cmds = dbg_fcn->body (); | |
136 result = cmds->set_breakpoint (line); | |
137 } | |
138 else | |
139 error ("unable to find the function requested\n"); | |
140 } | |
141 else | |
142 error ("one argument when in a function and two when not\n"); | |
143 | |
144 retval = static_cast<double> (result); | |
145 | |
146 return retval; | |
147 } | |
148 | |
149 DEFUN_TEXT (dbg_delete, args, , | |
150 "-*- texinfo -*-\n\ | |
151 @deftypefn {Loadable Function} {} dbg_delete (func, line)\n\ | |
152 Delete a breakpoint in a function\n\ | |
153 @table @code\n\ | |
154 @item func\n\ | |
155 String representing the function name. When already in debug\n\ | |
156 mode this should be left out and only the line should be given.\n\ | |
157 @item line\n\ | |
158 Line where you would like to remove the the breakpoint\n\ | |
159 @end table\n\ | |
160 No checking is done to make sure that the line you requested is really\n\ | |
161 a breakpoint. If you get the wrong line nothing will happen.\n\ | |
162 @end deftypefn\n\ | |
163 @seealso{dbg_set, dbg_list, dbg_where}") | |
164 { | |
165 octave_value retval; | |
166 | |
167 std::string symbol_name = ""; | |
168 | |
169 int line = -1; | |
170 int nargin = args.length (); | |
171 | |
172 if (nargin != 1 && nargin != 2) | |
173 { | |
174 error ("need one or two arguements\n"); | |
175 return retval; | |
176 } | |
177 | |
178 string_vector argv = args.make_argv ("dbg_delete"); | |
179 | |
180 if (error_state) | |
181 return retval; | |
182 | |
183 if (nargin == 2) | |
184 { | |
185 octave_stdout << "2 input arguments\n"; | |
186 symbol_name = argv[1]; | |
187 | |
188 octave_stdout << argv[1] << std::endl; | |
189 std::string line_number = argv[2]; | |
190 | |
191 line = atoi (line_number.c_str ()); | |
192 } | |
193 else if (nargin == 1) | |
194 { | |
195 octave_stdout << "1 input argument\n"; | |
196 std::string line_number = argv[1]; | |
197 | |
198 line = atoi (line_number.c_str ()); | |
199 } | |
200 else | |
201 { | |
202 error ("need one or two arguements\n"); | |
203 return retval; | |
204 } | |
205 | |
206 octave_stdout << "symbol_name = " << symbol_name << std::endl; | |
207 octave_user_function *dbg_fcn = get_user_function (symbol_name); | |
208 | |
209 if (dbg_fcn) | |
210 { | |
211 tree_statement_list *cmds = dbg_fcn->body (); | |
212 cmds->delete_breakpoint (line); | |
213 } | |
214 else | |
215 error ("unable to find the function requested\n"); | |
216 | |
217 return retval; | |
218 } | |
219 | |
220 DEFUN_TEXT (dbg_list, args, , | |
221 "-*- texinfo -*-\n\ | |
222 @deftypefn {Loadable Function} {lst =} dbg_list ([func])\n\ | |
223 Return a vector containing the lines on which a function has \n\ | |
224 breakpoints set.\n\ | |
225 @table @code\n\ | |
226 @item func\n\ | |
227 String representing the function name. When already in debug\n\ | |
228 mode this should be left out.\n\ | |
229 @end table\n\ | |
230 @end deftypefn\n\ | |
231 @seealso{dbg_delete, dbg_set, dbg_where}") | |
232 { | |
233 octave_value retval; | |
234 | |
235 int nargin = args.length (); | |
236 | |
237 if (nargin != 0 && nargin != 1) | |
238 { | |
239 error ("only zero or one arguements accepted\n"); | |
240 return retval; | |
241 } | |
242 | |
243 std::string symbol_name = ""; | |
244 | |
245 if (nargin == 1) | |
246 { | |
247 if (args(0).is_string ()) | |
248 symbol_name = args(0).string_value (); | |
249 else | |
250 gripe_wrong_type_arg ("dbg_list", args(0)); | |
251 } | |
252 | |
253 octave_user_function *dbg_fcn = get_user_function (symbol_name); | |
254 | |
255 if (dbg_fcn) | |
256 { | |
257 tree_statement_list *cmds = dbg_fcn->body (); | |
258 | |
259 octave_value_list lst = cmds->list_breakpoints (); | |
260 | |
261 RowVector vec (lst.length (), 0.0); | |
262 | |
263 for (int i = 0; i < lst.length (); i++) | |
264 { | |
265 vec(i) = lst(i).double_value (); | |
266 | |
267 if (error_state) | |
268 panic_impossible (); | |
269 } | |
270 | |
271 retval = octave_value (vec); | |
272 } | |
273 else | |
274 error ("unable to find the function you requested\n"); | |
275 | |
276 return retval; | |
277 } | |
278 | |
279 | |
280 DEFUN_TEXT (dbg_where, , , | |
281 "-*- texinfo -*-\n\ | |
282 @deftypefn {Loadable Function} {} dbg_where ()\n\ | |
283 Show where we are in the code\n\ | |
284 @end deftypefn\n\ | |
285 @seealso{dbg_delete, dbg_list, dbg_set}") | |
286 { | |
287 octave_value retval; | |
288 | |
289 octave_user_function *dbg_fcn = curr_function; | |
290 | |
291 if (dbg_fcn) | |
292 { | |
293 std::string name = dbg_fcn->function_name (); | |
294 | |
295 octave_stdout << name << ":"; | |
296 | |
297 const tree *dbg_stmt = tree::break_statement; | |
298 | |
299 if (dbg_stmt) | |
300 { | |
301 octave_stdout << "line " << dbg_stmt->line () << ", "; | |
302 octave_stdout << "column " << dbg_stmt->column () << std::endl; | |
303 } | |
304 else | |
305 octave_stdout << "-1\n"; | |
306 } | |
307 else | |
308 error ("must be inside of a user function to use dbg_where\n"); | |
309 | |
310 return retval; | |
311 } | |
312 | |
313 /* | |
314 ;;; Local Variables: *** | |
315 ;;; mode: C++ *** | |
316 ;;; End: *** | |
317 */ |