Mercurial > hg > octave-max
comparison src/debug.cc @ 11604:4c9677b526b1 release-3-0-x
[3-0-0-branch @ 2008-01-04 21:49:29 by jwe]
author | jwe |
---|---|
date | Fri, 04 Jan 2008 21:49:30 +0000 |
parents | 24fde8abfb90 |
children | eff8ac793dbf |
comparison
equal
deleted
inserted
replaced
11603:113fd59c0932 | 11604:4c9677b526b1 |
---|---|
1 /* | 1 /* |
2 | 2 |
3 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ben Sapp | 3 Copyright (C) 2007, 2008 John Swensen |
4 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ben Sapp | |
4 | 5 |
5 This file is part of Octave. | 6 This file is part of Octave. |
6 | 7 |
7 Octave is free software; you can redistribute it and/or modify it | 8 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 under the terms of the GNU General Public License as published by the |
91 | 92 |
92 return dbg_fcn; | 93 return dbg_fcn; |
93 } | 94 } |
94 | 95 |
95 static void | 96 static void |
96 parse_dbfunction_params (const octave_value_list& args, | 97 parse_dbfunction_params (const char *who, const octave_value_list& args, |
97 std::string& symbol_name, | 98 std::string& symbol_name, bp_table::intmap& lines) |
98 bp_table::intmap& lines) | 99 { |
99 { | |
100 octave_idx_type len = 0; | |
101 int nargin = args.length (); | 100 int nargin = args.length (); |
102 int idx = 0; | 101 int idx = 0; |
103 int list_idx = 0; | 102 int list_idx = 0; |
104 symbol_name = std::string (); | 103 symbol_name = std::string (); |
104 lines = bp_table::intmap (); | |
105 | |
106 if (args.length () == 0) | |
107 return; | |
105 | 108 |
106 // If we are already in a debugging function. | 109 // If we are already in a debugging function. |
107 if (octave_call_stack::caller_user_function ()) | 110 if (octave_call_stack::caller_user_function ()) |
108 idx = 0; | 111 { |
109 else | 112 idx = 0; |
110 { | 113 symbol_name = get_user_function ()->name (); |
111 symbol_name = args (0).string_value (); | 114 } |
115 else if (args(0).is_map ()) | |
116 { | |
117 // Problem because parse_dbfunction_params() can only pass out a | |
118 // single function | |
119 } | |
120 else if (args(0).is_string()) | |
121 { | |
122 symbol_name = args(0).string_value (); | |
112 if (error_state) | 123 if (error_state) |
113 return; | 124 return; |
114 idx = 1; | 125 idx = 1; |
115 } | 126 } |
127 else | |
128 error ("%s: invalid parameter specified", who); | |
116 | 129 |
117 for (int i = idx; i < nargin; i++ ) | 130 for (int i = idx; i < nargin; i++ ) |
118 { | 131 { |
119 if (args (i).is_string ()) | 132 if (args(i).is_string ()) |
120 len++; | |
121 else | |
122 len += args (i).numel (); | |
123 } | |
124 | |
125 lines = bp_table::intmap (); | |
126 for (int i = idx; i < nargin; i++ ) | |
127 { | |
128 if (args (i).is_string ()) | |
129 { | 133 { |
130 int line = atoi (args(i).string_value().c_str ()); | 134 int line = atoi (args(i).string_value().c_str ()); |
131 if (error_state) | 135 if (error_state) |
132 break; | 136 break; |
133 lines[list_idx++] = line; | 137 lines[list_idx++] = line; |
134 } | 138 } |
139 else if (args(i).is_map ()) | |
140 octave_stdout << who << ": accepting a struct" << std::endl; | |
135 else | 141 else |
136 { | 142 { |
137 const NDArray arg = args(i).array_value (); | 143 const NDArray arg = args(i).array_value (); |
138 | 144 |
139 if (error_state) | 145 if (error_state) |
206 { | 212 { |
207 octave_user_function *dbg_fcn = get_user_function (fname); | 213 octave_user_function *dbg_fcn = get_user_function (fname); |
208 if (dbg_fcn) | 214 if (dbg_fcn) |
209 { | 215 { |
210 tree_statement_list *cmds = dbg_fcn->body (); | 216 tree_statement_list *cmds = dbg_fcn->body (); |
211 for (int i = 0; i < len; i++) | 217 octave_value_list results = cmds->list_breakpoints (); |
218 if (results.length () > 0) | |
212 { | 219 { |
213 const_intmap_iterator p = line.find (i); | 220 for (int i = 0; i < len; i++) |
214 | 221 { |
215 if (p != line.end ()) | 222 const_intmap_iterator p = line.find (i); |
216 cmds->delete_breakpoint (p->second); | 223 |
224 if (p != line.end ()) | |
225 cmds->delete_breakpoint (p->second); | |
226 } | |
227 results = cmds->list_breakpoints (); | |
228 | |
229 breakpoint_map_iterator it = bp_map.find (fname); | |
230 if (results.length () == 0 && it != bp_map.end ()) | |
231 bp_map.erase (it); | |
217 } | 232 } |
218 | |
219 octave_value_list results = cmds->list_breakpoints (); | |
220 | |
221 if (results.length () == 0) | |
222 bp_map.erase (bp_map.find (fname)); | |
223 | 233 |
224 retval = results.length (); | 234 retval = results.length (); |
225 } | 235 } |
226 else | 236 else |
227 error ("remove_breakpoint: unable to find the function requested\n"); | 237 error ("remove_breakpoint: unable to find the function requested\n"); |
247 { | 257 { |
248 int lineno = static_cast<int> (bkpts(i).int_value ()); | 258 int lineno = static_cast<int> (bkpts(i).int_value ()); |
249 cmds->delete_breakpoint (lineno); | 259 cmds->delete_breakpoint (lineno); |
250 retval[i] = lineno; | 260 retval[i] = lineno; |
251 } | 261 } |
252 | 262 |
253 bp_map.erase (bp_map.find (fname)); | 263 breakpoint_map_iterator it = bp_map.find (fname); |
264 if (it != bp_map.end ()) | |
265 bp_map.erase (it); | |
254 } | 266 } |
255 else | 267 else |
256 error ("remove_all_breakpoint_in_file: " | 268 error ("remove_all_breakpoint_in_file: " |
257 "unable to find the function requested\n"); | 269 "unable to find the function requested\n"); |
258 | 270 |
356 { | 368 { |
357 bp_table::intmap retval; | 369 bp_table::intmap retval; |
358 std::string symbol_name; | 370 std::string symbol_name; |
359 bp_table::intmap lines; | 371 bp_table::intmap lines; |
360 | 372 |
361 parse_dbfunction_params (args, symbol_name, lines); | 373 parse_dbfunction_params ("dbstop", args, symbol_name, lines); |
362 | 374 |
363 if (! error_state) | 375 if (! error_state) |
364 retval = bp_table::add_breakpoint (symbol_name, lines); | 376 retval = bp_table::add_breakpoint (symbol_name, lines); |
365 | 377 |
366 return intmap_to_ov (retval); | 378 return intmap_to_ov (retval); |
385 { | 397 { |
386 octave_value retval; | 398 octave_value retval; |
387 std::string symbol_name = ""; | 399 std::string symbol_name = ""; |
388 bp_table::intmap lines; | 400 bp_table::intmap lines; |
389 | 401 |
390 parse_dbfunction_params (args, symbol_name, lines); | 402 parse_dbfunction_params ("dbclear", args, symbol_name, lines); |
391 | 403 |
392 if (! error_state) | 404 if (! error_state) |
393 bp_table::remove_breakpoint (symbol_name, lines); | 405 bp_table::remove_breakpoint (symbol_name, lines); |
394 | 406 |
395 return retval; | 407 return retval; |