Mercurial > hg > octave-nkf
annotate src/debug.cc @ 7539:3e107d73aeb4
debug.cc: use find_function instead of find_user_function
author | John Swensen |
---|---|
date | Thu, 28 Feb 2008 02:17:05 -0500 |
parents | d1a97ad87264 |
children | 87eda1f8faaa |
rev | line source |
---|---|
3805 | 1 /* |
2 | |
7348 | 3 Copyright (C) 2007, 2008 John Swensen |
4 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Ben Sapp | |
3805 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3805 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3805 | 21 |
22 */ | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3895 | 27 #include <iostream> |
28 #include <fstream> | |
3948 | 29 #include <string> |
7082 | 30 #include <set> |
31 | |
3895 | 32 |
3805 | 33 #include "defun.h" |
34 #include "error.h" | |
7082 | 35 #include "help.h" |
3805 | 36 #include "input.h" |
37 #include "pager.h" | |
38 #include "oct-obj.h" | |
39 #include "utils.h" | |
40 #include "parse.h" | |
41 #include "symtab.h" | |
42 #include "gripes.h" | |
43 #include "ov.h" | |
44 #include "ov-usr-fcn.h" | |
45 #include "ov-fcn.h" | |
7082 | 46 #include "ov-list.h" |
47 #include "ov-struct.h" | |
3805 | 48 #include "pt-pr-code.h" |
49 #include "pt.h" | |
50 #include "pt-bp.h" | |
51 #include "pt-stmt.h" | |
52 #include "toplev.h" | |
53 #include "unwind-prot.h" | |
54 #include "variables.h" | |
55 | |
7082 | 56 #include "debug.h" |
57 | |
58 // Initialize the singleton object | |
7083 | 59 bp_table *bp_table::instance = 0; |
7082 | 60 |
5743 | 61 // Return a pointer to the user-defined function FNAME. If FNAME is |
62 // empty, search backward for the first user-defined function in the | |
63 // current call stack. | |
7083 | 64 |
3949 | 65 static octave_user_function * |
7083 | 66 get_user_function (const std::string& fname = std::string ()) |
3805 | 67 { |
3956 | 68 octave_user_function *dbg_fcn = 0; |
3805 | 69 |
7083 | 70 if (fname.empty ()) |
5744 | 71 dbg_fcn = octave_call_stack::caller_user_function (); |
5743 | 72 else |
3805 | 73 { |
7539
3e107d73aeb4
debug.cc: use find_function instead of find_user_function
John Swensen
parents:
7348
diff
changeset
|
74 octave_value fcn = symbol_table::find_function (fname); |
3946 | 75 |
7539
3e107d73aeb4
debug.cc: use find_function instead of find_user_function
John Swensen
parents:
7348
diff
changeset
|
76 if (fcn.is_defined ()) |
3e107d73aeb4
debug.cc: use find_function instead of find_user_function
John Swensen
parents:
7348
diff
changeset
|
77 dbg_fcn = fcn.user_function_value (); |
3805 | 78 } |
79 | |
80 return dbg_fcn; | |
81 } | |
82 | |
7082 | 83 static void |
7348 | 84 parse_dbfunction_params (const char *who, const octave_value_list& args, |
85 std::string& symbol_name, bp_table::intmap& lines) | |
7082 | 86 { |
87 int nargin = args.length (); | |
88 int idx = 0; | |
89 int list_idx = 0; | |
90 symbol_name = std::string (); | |
7348 | 91 lines = bp_table::intmap (); |
92 | |
93 if (args.length () == 0) | |
94 return; | |
7082 | 95 |
7083 | 96 // If we are already in a debugging function. |
97 if (octave_call_stack::caller_user_function ()) | |
7348 | 98 { |
99 idx = 0; | |
100 symbol_name = get_user_function ()->name (); | |
101 } | |
102 else if (args(0).is_map ()) | |
7082 | 103 { |
7348 | 104 // Problem because parse_dbfunction_params() can only pass out a |
105 // single function | |
106 } | |
107 else if (args(0).is_string()) | |
108 { | |
109 symbol_name = args(0).string_value (); | |
7082 | 110 if (error_state) |
111 return; | |
112 idx = 1; | |
113 } | |
7348 | 114 else |
115 error ("%s: invalid parameter specified", who); | |
7082 | 116 |
117 for (int i = idx; i < nargin; i++ ) | |
118 { | |
7348 | 119 if (args(i).is_string ()) |
7082 | 120 { |
7083 | 121 int line = atoi (args(i).string_value().c_str ()); |
7082 | 122 if (error_state) |
7083 | 123 break; |
7082 | 124 lines[list_idx++] = line; |
125 } | |
7348 | 126 else if (args(i).is_map ()) |
127 octave_stdout << who << ": accepting a struct" << std::endl; | |
7082 | 128 else |
129 { | |
7083 | 130 const NDArray arg = args(i).array_value (); |
7082 | 131 |
132 if (error_state) | |
133 break; | |
134 | |
7083 | 135 for (octave_idx_type j = 0; j < arg.nelem (); j++) |
7082 | 136 { |
137 int line = static_cast<int> (arg.elem (j)); | |
138 if (error_state) | |
139 break; | |
140 lines[list_idx++] = line; | |
141 } | |
142 | |
143 if (error_state) | |
144 break; | |
145 } | |
146 } | |
147 } | |
148 | |
7083 | 149 bp_table::intmap |
150 bp_table::do_add_breakpoint (const std::string& fname, | |
151 const bp_table::intmap& line) | |
7082 | 152 { |
7083 | 153 intmap retval; |
7082 | 154 |
155 octave_idx_type len = line.size (); | |
7083 | 156 |
7082 | 157 octave_user_function *dbg_fcn = get_user_function (fname); |
158 | |
159 if (dbg_fcn) | |
160 { | |
161 tree_statement_list *cmds = dbg_fcn->body (); | |
7083 | 162 |
7082 | 163 for (int i = 0; i < len; i++) |
164 { | |
7083 | 165 const_intmap_iterator p = line.find (i); |
166 | |
7082 | 167 if (p != line.end ()) |
168 { | |
169 int lineno = p->second; | |
7083 | 170 |
7082 | 171 retval[i] = cmds->set_breakpoint (lineno); |
7083 | 172 |
7082 | 173 if (retval[i] != 0) |
7083 | 174 bp_map[fname] = dbg_fcn; |
7082 | 175 } |
176 } | |
177 } | |
178 else | |
179 error ("add_breakpoint: unable to find the function requested\n"); | |
180 | |
181 return retval; | |
182 } | |
183 | |
184 | |
185 int | |
7083 | 186 bp_table::do_remove_breakpoint (const std::string& fname, |
187 const bp_table::intmap& line) | |
7082 | 188 { |
7083 | 189 int retval = 0; |
7082 | 190 |
191 octave_idx_type len = line.size (); | |
192 | |
193 if (len == 0) | |
194 { | |
195 intmap results = remove_all_breakpoints_in_file (fname); | |
196 retval = results.size (); | |
197 } | |
198 else | |
199 { | |
200 octave_user_function *dbg_fcn = get_user_function (fname); | |
201 if (dbg_fcn) | |
202 { | |
203 tree_statement_list *cmds = dbg_fcn->body (); | |
7348 | 204 octave_value_list results = cmds->list_breakpoints (); |
205 if (results.length () > 0) | |
7082 | 206 { |
7348 | 207 for (int i = 0; i < len; i++) |
208 { | |
209 const_intmap_iterator p = line.find (i); | |
210 | |
211 if (p != line.end ()) | |
212 cmds->delete_breakpoint (p->second); | |
213 } | |
214 results = cmds->list_breakpoints (); | |
7083 | 215 |
7348 | 216 breakpoint_map_iterator it = bp_map.find (fname); |
217 if (results.length () == 0 && it != bp_map.end ()) | |
218 bp_map.erase (it); | |
7082 | 219 } |
7083 | 220 |
7082 | 221 retval = results.length (); |
222 } | |
223 else | |
224 error ("remove_breakpoint: unable to find the function requested\n"); | |
225 } | |
226 return retval; | |
227 } | |
228 | |
229 | |
7083 | 230 bp_table::intmap |
231 bp_table::do_remove_all_breakpoints_in_file (const std::string& fname) | |
7082 | 232 { |
7083 | 233 intmap retval; |
7082 | 234 |
235 octave_user_function *dbg_fcn = get_user_function (fname); | |
236 | |
237 if (dbg_fcn) | |
238 { | |
239 tree_statement_list *cmds = dbg_fcn->body (); | |
7083 | 240 |
241 octave_value_list bkpts = cmds->list_breakpoints (); | |
242 | |
7082 | 243 for (int i = 0; i < bkpts.length (); i++) |
244 { | |
7083 | 245 int lineno = static_cast<int> (bkpts(i).int_value ()); |
7082 | 246 cmds->delete_breakpoint (lineno); |
247 retval[i] = lineno; | |
248 } | |
7348 | 249 |
250 breakpoint_map_iterator it = bp_map.find (fname); | |
251 if (it != bp_map.end ()) | |
252 bp_map.erase (it); | |
7082 | 253 } |
254 else | |
255 error ("remove_all_breakpoint_in_file: " | |
256 "unable to find the function requested\n"); | |
257 | |
258 return retval; | |
259 } | |
260 | |
261 void | |
7083 | 262 bp_table::do_remove_all_breakpoints (void) |
7082 | 263 { |
7083 | 264 for (const_breakpoint_map_iterator it = bp_map.begin (); |
265 it != bp_map.end (); it++) | |
266 remove_all_breakpoints_in_file (it->first); | |
7082 | 267 } |
268 | |
269 std::string | |
270 do_find_bkpt_list (octave_value_list slist, | |
271 std::string match) | |
272 { | |
273 std::string retval; | |
7083 | 274 |
7082 | 275 for (int i = 0; i < slist.length (); i++) |
276 { | |
277 if (slist (i).string_value () == match) | |
278 { | |
7083 | 279 retval = slist(i).string_value (); |
7082 | 280 break; |
281 } | |
282 } | |
283 return retval; | |
284 } | |
285 | |
286 | |
7083 | 287 bp_table::fname_line_map |
288 bp_table::do_get_breakpoint_list (const octave_value_list& fname_list) | |
7082 | 289 { |
7083 | 290 fname_line_map retval; |
7082 | 291 |
292 // Iterate through each of the files in the map and get the | |
7083 | 293 // name and list of breakpoints. |
294 | |
295 for (breakpoint_map_iterator it = bp_map.begin (); it != bp_map.end (); it++) | |
7082 | 296 { |
7083 | 297 if (fname_list.length () == 0 |
298 || do_find_bkpt_list (fname_list, it->first) != "") | |
7082 | 299 { |
300 octave_value_list bkpts = it->second->body ()->list_breakpoints (); | |
7083 | 301 |
7082 | 302 octave_idx_type len = bkpts.length (); |
7083 | 303 |
304 bp_table::intmap bkpts_vec; | |
305 | |
7082 | 306 for (int i = 0; i < len; i++) |
307 bkpts_vec[i] = bkpts (i).double_value (); | |
7083 | 308 |
309 retval[it->first] = bkpts_vec; | |
7082 | 310 } |
311 } | |
7083 | 312 |
7082 | 313 return retval; |
314 } | |
315 | |
316 static octave_value | |
7083 | 317 intmap_to_ov (const bp_table::intmap& line) |
7082 | 318 { |
319 int idx = 0; | |
7083 | 320 |
321 NDArray retval (dim_vector (1, line.size ())); | |
322 | |
323 for (size_t i = 0; i < line.size (); i++) | |
7082 | 324 { |
7083 | 325 bp_table::const_intmap_iterator p = line.find (i); |
326 | |
7082 | 327 if (p != line.end ()) |
328 { | |
329 int lineno = p->second; | |
7083 | 330 retval(idx++) = lineno; |
7082 | 331 } |
332 } | |
7083 | 333 |
7082 | 334 retval.resize (dim_vector (1, idx)); |
7083 | 335 |
7082 | 336 return retval; |
337 } | |
3895 | 338 |
4208 | 339 DEFCMD (dbstop, args, , |
3805 | 340 "-*- texinfo -*-\n\ |
7083 | 341 @deftypefn {Loadable Function} {rline =} dbstop (@var{func}, @var{line}, @dots{})\n\ |
3805 | 342 Set a breakpoint in a function\n\ |
343 @table @code\n\ | |
344 @item func\n\ | |
345 String representing the function name. When already in debug\n\ | |
346 mode this should be left out and only the line should be given.\n\ | |
347 @item line\n\ | |
6646 | 348 Line you would like the breakpoint to be set on. Multiple\n\ |
7001 | 349 lines might be given as separate arguments or as a vector.\n\ |
3805 | 350 @end table\n\ |
351 \n\ | |
352 The rline returned is the real line that the breakpoint was set at.\n\ | |
5642 | 353 @seealso{dbclear, dbstatus, dbnext}\n\ |
354 @end deftypefn") | |
3805 | 355 { |
7083 | 356 bp_table::intmap retval; |
357 std::string symbol_name; | |
358 bp_table::intmap lines; | |
359 | |
7348 | 360 parse_dbfunction_params ("dbstop", args, symbol_name, lines); |
6646 | 361 |
7083 | 362 if (! error_state) |
7082 | 363 retval = bp_table::add_breakpoint (symbol_name, lines); |
3805 | 364 |
7083 | 365 return intmap_to_ov (retval); |
3805 | 366 } |
367 | |
4208 | 368 DEFCMD (dbclear, args, , |
3805 | 369 "-*- texinfo -*-\n\ |
7083 | 370 @deftypefn {Loadable Function} {} dbclear (@var{func}, @var{line}, @dots{})\n\ |
3805 | 371 Delete a breakpoint in a function\n\ |
372 @table @code\n\ | |
373 @item func\n\ | |
374 String representing the function name. When already in debug\n\ | |
375 mode this should be left out and only the line should be given.\n\ | |
376 @item line\n\ | |
6653 | 377 Line where you would like to remove the breakpoint. Multiple\n\ |
7001 | 378 lines might be given as separate arguments or as a vector.\n\ |
3805 | 379 @end table\n\ |
380 No checking is done to make sure that the line you requested is really\n\ | |
6646 | 381 a breakpoint. If you get the wrong line nothing will happen.\n\ |
5642 | 382 @seealso{dbstop, dbstatus, dbwhere}\n\ |
383 @end deftypefn") | |
3805 | 384 { |
385 octave_value retval; | |
386 std::string symbol_name = ""; | |
7083 | 387 bp_table::intmap lines; |
388 | |
7348 | 389 parse_dbfunction_params ("dbclear", args, symbol_name, lines); |
7082 | 390 |
7083 | 391 if (! error_state) |
7082 | 392 bp_table::remove_breakpoint (symbol_name, lines); |
3805 | 393 |
394 return retval; | |
395 } | |
396 | |
7082 | 397 DEFCMD (dbstatus, args, nargout, |
3805 | 398 "-*- texinfo -*-\n\ |
7083 | 399 @deftypefn {Loadable Function} {lst =} dbstatus (@var{func})\n\ |
3805 | 400 Return a vector containing the lines on which a function has \n\ |
401 breakpoints set.\n\ | |
402 @table @code\n\ | |
403 @item func\n\ | |
404 String representing the function name. When already in debug\n\ | |
405 mode this should be left out.\n\ | |
406 @end table\n\ | |
5642 | 407 @seealso{dbclear, dbwhere}\n\ |
408 @end deftypefn") | |
3805 | 409 { |
7082 | 410 Octave_map retval; |
3805 | 411 int nargin = args.length (); |
7082 | 412 octave_value_list fcn_list; |
7083 | 413 bp_table::fname_line_map bp_list; |
414 std::string symbol_name; | |
3805 | 415 |
416 if (nargin != 0 && nargin != 1) | |
417 { | |
3948 | 418 error ("dbstatus: only zero or one arguements accepted\n"); |
7082 | 419 return octave_value (); |
3805 | 420 } |
421 | |
422 if (nargin == 1) | |
423 { | |
424 if (args(0).is_string ()) | |
7082 | 425 { |
7083 | 426 symbol_name = args(0).string_value (); |
427 fcn_list(0) = symbol_name; | |
7082 | 428 bp_list = bp_table::get_breakpoint_list (fcn_list); |
429 } | |
3805 | 430 else |
7083 | 431 gripe_wrong_type_arg ("dbstatus", args(0)); |
7082 | 432 } |
433 else | |
434 { | |
435 octave_user_function *dbg_fcn = get_user_function (); | |
436 if (dbg_fcn) | |
437 { | |
438 symbol_name = dbg_fcn->name (); | |
7083 | 439 fcn_list(0) = symbol_name; |
7082 | 440 } |
7083 | 441 |
7082 | 442 bp_list = bp_table::get_breakpoint_list (fcn_list); |
3805 | 443 } |
444 | |
7083 | 445 if (nargout == 0) |
3805 | 446 { |
7083 | 447 // Print out the breakpoint information. |
448 | |
449 for (bp_table::fname_line_map_iterator it = bp_list.begin (); | |
450 it != bp_list.end (); it++) | |
451 { | |
452 octave_stdout << "Breakpoint in " << it->first << " at line(s) "; | |
453 | |
454 bp_table::intmap m = it->second; | |
455 | |
456 size_t nel = m.size (); | |
457 | |
458 for (size_t j = 0; j < nel; j++) | |
459 octave_stdout << m[j] << ((j < nel - 1) ? ", " : "."); | |
460 | |
461 if (nel > 0) | |
462 octave_stdout << std::endl; | |
463 } | |
464 return octave_value (); | |
465 } | |
466 else | |
467 { | |
468 // Fill in an array for return. | |
469 | |
7082 | 470 int i = 0; |
471 Cell names (dim_vector (bp_list.size (), 1)); | |
472 Cell file (dim_vector (bp_list.size (), 1)); | |
473 Cell line (dim_vector (bp_list.size (), 1)); | |
7083 | 474 |
475 for (bp_table::const_fname_line_map_iterator it = bp_list.begin (); | |
476 it != bp_list.end (); it++) | |
3946 | 477 { |
7083 | 478 names(i) = it->first; |
479 line(i) = intmap_to_ov (it->second); | |
480 file(i) = do_which (it->first); | |
7082 | 481 i++; |
3805 | 482 } |
7083 | 483 |
7082 | 484 retval.assign ("name", names); |
485 retval.assign ("file", file); | |
486 retval.assign ("line", line); | |
7083 | 487 |
7082 | 488 return octave_value (retval); |
3805 | 489 } |
490 } | |
491 | |
4208 | 492 DEFCMD (dbwhere, , , |
3805 | 493 "-*- texinfo -*-\n\ |
3895 | 494 @deftypefn {Loadable Function} {} dbwhere ()\n\ |
3805 | 495 Show where we are in the code\n\ |
5642 | 496 @seealso{dbclear, dbstatus, dbstop}\n\ |
5645 | 497 @end deftypefn") |
3805 | 498 { |
499 octave_value retval; | |
3946 | 500 |
5743 | 501 octave_user_function *dbg_fcn = get_user_function (); |
3805 | 502 |
503 if (dbg_fcn) | |
504 { | |
4748 | 505 std::string name = dbg_fcn->name (); |
3805 | 506 |
507 octave_stdout << name << ":"; | |
508 | |
509 const tree *dbg_stmt = tree::break_statement; | |
510 | |
511 if (dbg_stmt) | |
512 { | |
7083 | 513 octave_stdout << " line " << dbg_stmt->line () << ", "; |
3805 | 514 octave_stdout << "column " << dbg_stmt->column () << std::endl; |
515 } | |
516 else | |
7083 | 517 octave_stdout << " (unknown line)\n"; |
3805 | 518 } |
519 else | |
3948 | 520 error ("dbwhere: must be inside of a user function to use dbwhere\n"); |
3895 | 521 |
522 return retval; | |
523 } | |
524 | |
525 // Copied and modified from the do_type command in help.cc | |
3946 | 526 // Maybe we could share some code? |
527 void | |
3949 | 528 do_dbtype (std::ostream& os, const std::string& name, int start, int end) |
3895 | 529 { |
530 std::string ff = fcn_file_in_path (name); | |
531 | |
532 if (! ff.empty ()) | |
533 { | |
534 std::ifstream fs (ff.c_str (), std::ios::in); | |
3946 | 535 |
3895 | 536 if (fs) |
3946 | 537 { |
3895 | 538 char ch; |
539 int line = 1; | |
3946 | 540 |
3895 | 541 if (line >= start && line <= end) |
542 os << line << "\t"; | |
3946 | 543 |
3895 | 544 while (fs.get (ch)) |
545 { | |
546 if (line >= start && line <= end) | |
547 { | |
548 os << ch; | |
549 } | |
550 | |
551 if (ch == '\n') | |
552 { | |
553 line++; | |
554 if (line >= start && line <= end) | |
3946 | 555 os << line << "\t"; |
3895 | 556 } |
557 } | |
558 } | |
3946 | 559 else |
3949 | 560 os << "dbtype: unable to open `" << ff << "' for reading!\n"; |
3895 | 561 } |
562 else | |
6317 | 563 os << "dbtype: unknown function " << name << "\n"; |
3895 | 564 |
6646 | 565 os.flush (); |
3895 | 566 } |
567 | |
4208 | 568 DEFCMD (dbtype, args, , |
3895 | 569 "-*- texinfo -*-\n\ |
570 @deftypefn {Loadable Function} {} dbtype ()\n\ | |
571 List script file with line numbers.\n\ | |
5642 | 572 @seealso{dbclear, dbstatus, dbstop}\n\ |
573 @end deftypefn") | |
3895 | 574 { |
575 octave_value retval; | |
576 octave_user_function *dbg_fcn; | |
3946 | 577 |
3895 | 578 int nargin = args.length (); |
579 string_vector argv = args.make_argv ("dbtype"); | |
3946 | 580 |
3895 | 581 if (! error_state) |
582 { | |
583 switch (nargin) | |
584 { | |
585 case 0: // dbtype | |
586 dbg_fcn = get_user_function (); | |
587 | |
588 if (dbg_fcn) | |
4748 | 589 do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); |
3895 | 590 else |
3948 | 591 error ("dbtype: must be in a user function to give no arguments to dbtype\n"); |
3946 | 592 break; |
3895 | 593 |
3946 | 594 case 1: // (dbtype func) || (dbtype start:end) |
3948 | 595 dbg_fcn = get_user_function (argv[1]); |
3895 | 596 |
597 if (dbg_fcn) | |
4748 | 598 do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); |
3895 | 599 else |
600 { | |
7083 | 601 dbg_fcn = get_user_function (); |
3895 | 602 |
603 if (dbg_fcn) | |
604 { | |
3948 | 605 std::string arg = argv[1]; |
606 | |
607 size_t ind = arg.find (':'); | |
3895 | 608 |
3948 | 609 if (ind != NPOS) |
610 { | |
611 std::string start_str = arg.substr (0, ind); | |
612 std::string end_str = arg.substr (ind + 1); | |
613 | |
614 int start = atoi (start_str.c_str ()); | |
615 int end = atoi (end_str.c_str ()); | |
3946 | 616 |
6317 | 617 if (std::min (start, end) <= 0) |
618 error ("dbtype: start and end lines must be >= 1\n"); | |
619 | |
620 if (start <= end) | |
621 do_dbtype (octave_stdout, dbg_fcn->name (), start, end); | |
3948 | 622 else |
6317 | 623 error ("dbtype: start line must be less than end line\n"); |
3895 | 624 } |
3948 | 625 else |
6317 | 626 error ("dbtype: line specification must be `start:end'"); |
3895 | 627 } |
628 } | |
629 break; | |
3946 | 630 |
6317 | 631 case 2: // (dbtype func start:end) , (dbtype func start) |
3948 | 632 dbg_fcn = get_user_function (argv[1]); |
3895 | 633 |
634 if (dbg_fcn) | |
635 { | |
3948 | 636 std::string arg = argv[2]; |
6317 | 637 int start = 0; |
638 int end = 0; | |
3948 | 639 size_t ind = arg.find (':'); |
3895 | 640 |
3948 | 641 if (ind != NPOS) |
3895 | 642 { |
3948 | 643 std::string start_str = arg.substr (0, ind); |
644 std::string end_str = arg.substr (ind + 1); | |
3895 | 645 |
6317 | 646 start = atoi (start_str.c_str ()); |
647 end = atoi (end_str.c_str ()); | |
648 | |
3948 | 649 } |
650 else | |
6317 | 651 { |
652 start = atoi (arg.c_str ()); | |
653 end = start; | |
654 } | |
655 | |
656 if (std::min (start, end) <= 0) | |
657 error ("dbtype: start and end lines must be >= 1\n"); | |
658 | |
659 if (start <= end) | |
660 do_dbtype (octave_stdout, dbg_fcn->name (), start, end); | |
661 else | |
662 error ("dbtype: start line must be less than end line\n"); | |
3895 | 663 } |
3946 | 664 break; |
3895 | 665 |
666 default: | |
3948 | 667 error ("dbtype: expecting zero, one, or two arguments\n"); |
3895 | 668 } |
669 } | |
3805 | 670 |
671 return retval; | |
672 } | |
673 | |
674 /* | |
675 ;;; Local Variables: *** | |
676 ;;; mode: C++ *** | |
677 ;;; End: *** | |
678 */ |