comparison src/debug.cc @ 10315:57a59eae83cc

untabify src C++ source files
author John W. Eaton <jwe@octave.org>
date Thu, 11 Feb 2010 12:41:46 -0500
parents 0efd486813fe
children 65bc065bec95
comparison
equal deleted inserted replaced
10314:07ebe522dac2 10315:57a59eae83cc
71 size_t sz = fs.size (); 71 size_t sz = fs.size ();
72 72
73 std::ifstream file (fname.c_str (), std::ios::in|std::ios::binary); 73 std::ifstream file (fname.c_str (), std::ios::in|std::ios::binary);
74 74
75 if (file) 75 if (file)
76 { 76 {
77 std::string buf (sz+1, 0); 77 std::string buf (sz+1, 0);
78 78
79 file.read (&buf[0], sz+1); 79 file.read (&buf[0], sz+1);
80 80
81 if (file.eof ()) 81 if (file.eof ())
82 { 82 {
83 // Expected to read the entire file. 83 // Expected to read the entire file.
84 84
85 retval = buf; 85 retval = buf;
86 } 86 }
87 else 87 else
88 error ("error reading file %s", fname.c_str ()); 88 error ("error reading file %s", fname.c_str ());
89 } 89 }
90 } 90 }
91 91
92 return retval; 92 return retval;
93 } 93 }
94 94
107 for (size_t i = 0; i < len; i++) 107 for (size_t i = 0; i < len; i++)
108 { 108 {
109 char c = buf[i]; 109 char c = buf[i];
110 110
111 if (c == '\r' && ++i < len) 111 if (c == '\r' && ++i < len)
112 { 112 {
113 c = buf[i]; 113 c = buf[i];
114 114
115 if (c == '\n') 115 if (c == '\n')
116 offsets.push_back (i+1); 116 offsets.push_back (i+1);
117 else 117 else
118 offsets.push_back (i); 118 offsets.push_back (i);
119 } 119 }
120 else if (c == '\n') 120 else if (c == '\n')
121 offsets.push_back (i+1); 121 offsets.push_back (i+1);
122 } 122 }
123 123
124 offsets.push_back (len); 124 offsets.push_back (len);
125 125
126 return offsets; 126 return offsets;
151 { 151 {
152 size_t bol = offsets[line]; 152 size_t bol = offsets[line];
153 size_t eol = offsets[line+1]; 153 size_t eol = offsets[line+1];
154 154
155 while (eol > 0 && (buf[eol-1] == '\n' || buf[eol-1] == '\r')) 155 while (eol > 0 && (buf[eol-1] == '\n' || buf[eol-1] == '\r'))
156 eol--; 156 eol--;
157 157
158 retval = buf.substr (bol, eol - bol); 158 retval = buf.substr (bol, eol - bol);
159 } 159 }
160 160
161 return retval; 161 return retval;
175 else 175 else
176 { 176 {
177 octave_value fcn = symbol_table::find_function (fname); 177 octave_value fcn = symbol_table::find_function (fname);
178 178
179 if (fcn.is_defined () && fcn.is_user_code ()) 179 if (fcn.is_defined () && fcn.is_user_code ())
180 dbg_fcn = fcn.user_code_value (); 180 dbg_fcn = fcn.user_code_value ();
181 } 181 }
182 182
183 return dbg_fcn; 183 return dbg_fcn;
184 } 184 }
185 185
186 static void 186 static void
187 parse_dbfunction_params (const char *who, const octave_value_list& args, 187 parse_dbfunction_params (const char *who, const octave_value_list& args,
188 std::string& symbol_name, bp_table::intmap& lines) 188 std::string& symbol_name, bp_table::intmap& lines)
189 { 189 {
190 int nargin = args.length (); 190 int nargin = args.length ();
191 int idx = 0; 191 int idx = 0;
192 int list_idx = 0; 192 int list_idx = 0;
193 symbol_name = std::string (); 193 symbol_name = std::string ();
209 } 209 }
210 else if (args(0).is_string()) 210 else if (args(0).is_string())
211 { 211 {
212 symbol_name = args(0).string_value (); 212 symbol_name = args(0).string_value ();
213 if (error_state) 213 if (error_state)
214 return; 214 return;
215 idx = 1; 215 idx = 1;
216 } 216 }
217 else 217 else
218 error ("%s: invalid parameter specified", who); 218 error ("%s: invalid parameter specified", who);
219 219
220 for (int i = idx; i < nargin; i++ ) 220 for (int i = idx; i < nargin; i++ )
221 { 221 {
222 if (args(i).is_string ()) 222 if (args(i).is_string ())
223 { 223 {
224 int line = atoi (args(i).string_value().c_str ()); 224 int line = atoi (args(i).string_value().c_str ());
225 if (error_state) 225 if (error_state)
226 break; 226 break;
227 lines[list_idx++] = line; 227 lines[list_idx++] = line;
228 } 228 }
229 else if (args(i).is_map ()) 229 else if (args(i).is_map ())
230 octave_stdout << who << ": accepting a struct" << std::endl; 230 octave_stdout << who << ": accepting a struct" << std::endl;
231 else 231 else
232 { 232 {
233 const NDArray arg = args(i).array_value (); 233 const NDArray arg = args(i).array_value ();
234 234
235 if (error_state) 235 if (error_state)
236 break; 236 break;
237 237
238 for (octave_idx_type j = 0; j < arg.nelem (); j++) 238 for (octave_idx_type j = 0; j < arg.nelem (); j++)
239 { 239 {
240 int line = static_cast<int> (arg.elem (j)); 240 int line = static_cast<int> (arg.elem (j));
241 if (error_state) 241 if (error_state)
242 break; 242 break;
243 lines[list_idx++] = line; 243 lines[list_idx++] = line;
244 } 244 }
245 245
246 if (error_state) 246 if (error_state)
247 break; 247 break;
248 } 248 }
249 } 249 }
250 } 250 }
251 251
252 bp_table::intmap 252 bp_table::intmap
253 bp_table::do_add_breakpoint (const std::string& fname, 253 bp_table::do_add_breakpoint (const std::string& fname,
254 const bp_table::intmap& line) 254 const bp_table::intmap& line)
255 { 255 {
256 intmap retval; 256 intmap retval;
257 257
258 octave_idx_type len = line.size (); 258 octave_idx_type len = line.size ();
259 259
262 if (dbg_fcn) 262 if (dbg_fcn)
263 { 263 {
264 tree_statement_list *cmds = dbg_fcn->body (); 264 tree_statement_list *cmds = dbg_fcn->body ();
265 265
266 if (cmds) 266 if (cmds)
267 { 267 {
268 for (int i = 0; i < len; i++) 268 for (int i = 0; i < len; i++)
269 { 269 {
270 const_intmap_iterator p = line.find (i); 270 const_intmap_iterator p = line.find (i);
271 271
272 if (p != line.end ()) 272 if (p != line.end ())
273 { 273 {
274 int lineno = p->second; 274 int lineno = p->second;
275 275
276 retval[i] = cmds->set_breakpoint (lineno); 276 retval[i] = cmds->set_breakpoint (lineno);
277 277
278 if (retval[i] != 0) 278 if (retval[i] != 0)
279 { 279 {
280 bp_set.insert (fname); 280 bp_set.insert (fname);
281 } 281 }
282 } 282 }
283 } 283 }
284 } 284 }
285 } 285 }
286 else 286 else
287 error ("add_breakpoint: unable to find the function requested\n"); 287 error ("add_breakpoint: unable to find the function requested\n");
288 288
289 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; 289 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
292 } 292 }
293 293
294 294
295 int 295 int
296 bp_table::do_remove_breakpoint (const std::string& fname, 296 bp_table::do_remove_breakpoint (const std::string& fname,
297 const bp_table::intmap& line) 297 const bp_table::intmap& line)
298 { 298 {
299 int retval = 0; 299 int retval = 0;
300 300
301 octave_idx_type len = line.size (); 301 octave_idx_type len = line.size ();
302 302
308 else 308 else
309 { 309 {
310 octave_user_code *dbg_fcn = get_user_code (fname); 310 octave_user_code *dbg_fcn = get_user_code (fname);
311 311
312 if (dbg_fcn) 312 if (dbg_fcn)
313 { 313 {
314 tree_statement_list *cmds = dbg_fcn->body (); 314 tree_statement_list *cmds = dbg_fcn->body ();
315 315
316 if (cmds) 316 if (cmds)
317 { 317 {
318 octave_value_list results = cmds->list_breakpoints (); 318 octave_value_list results = cmds->list_breakpoints ();
319 319
320 if (results.length () > 0) 320 if (results.length () > 0)
321 { 321 {
322 for (int i = 0; i < len; i++) 322 for (int i = 0; i < len; i++)
323 { 323 {
324 const_intmap_iterator p = line.find (i); 324 const_intmap_iterator p = line.find (i);
325 325
326 if (p != line.end ()) 326 if (p != line.end ())
327 cmds->delete_breakpoint (p->second); 327 cmds->delete_breakpoint (p->second);
328 } 328 }
329 329
330 results = cmds->list_breakpoints (); 330 results = cmds->list_breakpoints ();
331 331
332 bp_set_iterator it = bp_set.find (fname); 332 bp_set_iterator it = bp_set.find (fname);
333 if (results.length () == 0 && it != bp_set.end ()) 333 if (results.length () == 0 && it != bp_set.end ())
334 bp_set.erase (it); 334 bp_set.erase (it);
335 335
336 } 336 }
337 337
338 retval = results.length (); 338 retval = results.length ();
339 } 339 }
340 } 340 }
341 else 341 else
342 error ("remove_breakpoint: unable to find the function requested\n"); 342 error ("remove_breakpoint: unable to find the function requested\n");
343 } 343 }
344 344
345 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; 345 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
346 346
347 return retval; 347 return retval;
348 } 348 }
349 349
350 350
351 bp_table::intmap 351 bp_table::intmap
352 bp_table::do_remove_all_breakpoints_in_file (const std::string& fname, 352 bp_table::do_remove_all_breakpoints_in_file (const std::string& fname,
353 bool silent) 353 bool silent)
354 { 354 {
355 intmap retval; 355 intmap retval;
356 356
357 octave_user_code *dbg_fcn = get_user_code (fname); 357 octave_user_code *dbg_fcn = get_user_code (fname);
358 358
359 if (dbg_fcn) 359 if (dbg_fcn)
360 { 360 {
361 tree_statement_list *cmds = dbg_fcn->body (); 361 tree_statement_list *cmds = dbg_fcn->body ();
362 362
363 if (cmds) 363 if (cmds)
364 { 364 {
365 octave_value_list bkpts = cmds->list_breakpoints (); 365 octave_value_list bkpts = cmds->list_breakpoints ();
366 366
367 for (int i = 0; i < bkpts.length (); i++) 367 for (int i = 0; i < bkpts.length (); i++)
368 { 368 {
369 int lineno = static_cast<int> (bkpts(i).int_value ()); 369 int lineno = static_cast<int> (bkpts(i).int_value ());
370 cmds->delete_breakpoint (lineno); 370 cmds->delete_breakpoint (lineno);
371 retval[i] = lineno; 371 retval[i] = lineno;
372 } 372 }
373 373
374 bp_set_iterator it = bp_set.find (fname); 374 bp_set_iterator it = bp_set.find (fname);
375 if (it != bp_set.end ()) 375 if (it != bp_set.end ())
376 bp_set.erase (it); 376 bp_set.erase (it);
377 377
378 } 378 }
379 } 379 }
380 else if (! silent) 380 else if (! silent)
381 error ("remove_all_breakpoint_in_file: " 381 error ("remove_all_breakpoint_in_file: "
382 "unable to find the function requested\n"); 382 "unable to find the function requested\n");
383 383
384 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; 384 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
385 385
386 return retval; 386 return retval;
387 } 387 }
396 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging; 396 tree_evaluator::debug_mode = bp_table::have_breakpoints () || Vdebugging;
397 } 397 }
398 398
399 std::string 399 std::string
400 do_find_bkpt_list (octave_value_list slist, 400 do_find_bkpt_list (octave_value_list slist,
401 std::string match) 401 std::string match)
402 { 402 {
403 std::string retval; 403 std::string retval;
404 404
405 for (int i = 0; i < slist.length (); i++) 405 for (int i = 0; i < slist.length (); i++)
406 { 406 {
407 if (slist (i).string_value () == match) 407 if (slist (i).string_value () == match)
408 { 408 {
409 retval = slist(i).string_value (); 409 retval = slist(i).string_value ();
410 break; 410 break;
411 } 411 }
412 } 412 }
413 413
414 return retval; 414 return retval;
415 } 415 }
416 416
421 fname_line_map retval; 421 fname_line_map retval;
422 422
423 for (bp_set_iterator it = bp_set.begin (); it != bp_set.end (); it++) 423 for (bp_set_iterator it = bp_set.begin (); it != bp_set.end (); it++)
424 { 424 {
425 if (fname_list.length () == 0 425 if (fname_list.length () == 0
426 || do_find_bkpt_list (fname_list, *it) != "") 426 || do_find_bkpt_list (fname_list, *it) != "")
427 { 427 {
428 octave_user_code *f = get_user_code (*it); 428 octave_user_code *f = get_user_code (*it);
429 429
430 if (f) 430 if (f)
431 { 431 {
432 tree_statement_list *cmds = f->body (); 432 tree_statement_list *cmds = f->body ();
433 433
434 if (cmds) 434 if (cmds)
435 { 435 {
436 octave_value_list bkpts = cmds->list_breakpoints (); 436 octave_value_list bkpts = cmds->list_breakpoints ();
437 octave_idx_type len = bkpts.length (); 437 octave_idx_type len = bkpts.length ();
438 438
439 if (len > 0) 439 if (len > 0)
440 { 440 {
441 bp_table::intmap bkpts_vec; 441 bp_table::intmap bkpts_vec;
442 442
443 for (int i = 0; i < len; i++) 443 for (int i = 0; i < len; i++)
444 bkpts_vec[i] = bkpts (i).double_value (); 444 bkpts_vec[i] = bkpts (i).double_value ();
445 445
446 std::string symbol_name = f->name (); 446 std::string symbol_name = f->name ();
447 447
448 retval[symbol_name] = bkpts_vec; 448 retval[symbol_name] = bkpts_vec;
449 } 449 }
450 } 450 }
451 } 451 }
452 } 452 }
453 } 453 }
454 454
455 return retval; 455 return retval;
456 } 456 }
457 457
465 for (size_t i = 0; i < line.size (); i++) 465 for (size_t i = 0; i < line.size (); i++)
466 { 466 {
467 bp_table::const_intmap_iterator p = line.find (i); 467 bp_table::const_intmap_iterator p = line.find (i);
468 468
469 if (p != line.end ()) 469 if (p != line.end ())
470 { 470 {
471 int lineno = p->second; 471 int lineno = p->second;
472 retval(idx++) = lineno; 472 retval(idx++) = lineno;
473 } 473 }
474 } 474 }
475 475
476 retval.resize (dim_vector (1, idx)); 476 retval.resize (dim_vector (1, idx));
477 477
478 return retval; 478 return retval;
565 } 565 }
566 566
567 if (nargin == 1) 567 if (nargin == 1)
568 { 568 {
569 if (args(0).is_string ()) 569 if (args(0).is_string ())
570 { 570 {
571 symbol_name = args(0).string_value (); 571 symbol_name = args(0).string_value ();
572 fcn_list(0) = symbol_name; 572 fcn_list(0) = symbol_name;
573 bp_list = bp_table::get_breakpoint_list (fcn_list); 573 bp_list = bp_table::get_breakpoint_list (fcn_list);
574 } 574 }
575 else 575 else
576 gripe_wrong_type_arg ("dbstatus", args(0)); 576 gripe_wrong_type_arg ("dbstatus", args(0));
577 } 577 }
578 else 578 else
579 { 579 {
580 octave_user_code *dbg_fcn = get_user_code (); 580 octave_user_code *dbg_fcn = get_user_code ();
581 if (dbg_fcn) 581 if (dbg_fcn)
582 { 582 {
583 symbol_name = dbg_fcn->name (); 583 symbol_name = dbg_fcn->name ();
584 fcn_list(0) = symbol_name; 584 fcn_list(0) = symbol_name;
585 } 585 }
586 586
587 bp_list = bp_table::get_breakpoint_list (fcn_list); 587 bp_list = bp_table::get_breakpoint_list (fcn_list);
588 } 588 }
589 589
590 if (nargout == 0) 590 if (nargout == 0)
591 { 591 {
592 // Print out the breakpoint information. 592 // Print out the breakpoint information.
593 593
594 for (bp_table::fname_line_map_iterator it = bp_list.begin (); 594 for (bp_table::fname_line_map_iterator it = bp_list.begin ();
595 it != bp_list.end (); it++) 595 it != bp_list.end (); it++)
596 { 596 {
597 octave_stdout << "Breakpoint in " << it->first << " at line(s) "; 597 octave_stdout << "Breakpoint in " << it->first << " at line(s) ";
598 598
599 bp_table::intmap m = it->second; 599 bp_table::intmap m = it->second;
600 600
601 size_t nel = m.size (); 601 size_t nel = m.size ();
602 602
603 for (size_t j = 0; j < nel; j++) 603 for (size_t j = 0; j < nel; j++)
604 octave_stdout << m[j] << ((j < nel - 1) ? ", " : "."); 604 octave_stdout << m[j] << ((j < nel - 1) ? ", " : ".");
605 605
606 if (nel > 0) 606 if (nel > 0)
607 octave_stdout << std::endl; 607 octave_stdout << std::endl;
608 } 608 }
609 return octave_value (); 609 return octave_value ();
610 } 610 }
611 else 611 else
612 { 612 {
613 // Fill in an array for return. 613 // Fill in an array for return.
616 Cell names (dim_vector (bp_list.size (), 1)); 616 Cell names (dim_vector (bp_list.size (), 1));
617 Cell file (dim_vector (bp_list.size (), 1)); 617 Cell file (dim_vector (bp_list.size (), 1));
618 Cell line (dim_vector (bp_list.size (), 1)); 618 Cell line (dim_vector (bp_list.size (), 1));
619 619
620 for (bp_table::const_fname_line_map_iterator it = bp_list.begin (); 620 for (bp_table::const_fname_line_map_iterator it = bp_list.begin ();
621 it != bp_list.end (); it++) 621 it != bp_list.end (); it++)
622 { 622 {
623 names(i) = it->first; 623 names(i) = it->first;
624 line(i) = intmap_to_ov (it->second); 624 line(i) = intmap_to_ov (it->second);
625 file(i) = do_which (it->first); 625 file(i) = do_which (it->first);
626 i++; 626 i++;
627 } 627 }
628 628
629 retval.assign ("name", names); 629 retval.assign ("name", names);
630 retval.assign ("file", file); 630 retval.assign ("file", file);
631 retval.assign ("line", line); 631 retval.assign ("line", line);
632 632
650 bool have_file = true; 650 bool have_file = true;
651 651
652 std::string name = dbg_fcn->fcn_file_name (); 652 std::string name = dbg_fcn->fcn_file_name ();
653 653
654 if (name.empty ()) 654 if (name.empty ())
655 { 655 {
656 have_file = false; 656 have_file = false;
657 657
658 name = dbg_fcn->name (); 658 name = dbg_fcn->name ();
659 } 659 }
660 660
661 octave_stdout << name << ":"; 661 octave_stdout << name << ":";
662 662
663 unwind_protect frame; 663 unwind_protect frame;
664 664
669 octave_call_stack::goto_frame_relative (0); 669 octave_call_stack::goto_frame_relative (0);
670 670
671 int l = octave_call_stack::current_line (); 671 int l = octave_call_stack::current_line ();
672 672
673 if (l > 0) 673 if (l > 0)
674 { 674 {
675 octave_stdout << " line " << l; 675 octave_stdout << " line " << l;
676 676
677 int c = octave_call_stack::current_column (); 677 int c = octave_call_stack::current_column ();
678 678
679 if (c > 0) 679 if (c > 0)
680 octave_stdout << ", column " << c; 680 octave_stdout << ", column " << c;
681 681
682 octave_stdout << std::endl; 682 octave_stdout << std::endl;
683 683
684 if (have_file) 684 if (have_file)
685 { 685 {
686 std::string line = get_file_line (name, l); 686 std::string line = get_file_line (name, l);
687 687
688 if (! line.empty ()) 688 if (! line.empty ())
689 octave_stdout << l << ": " << line << std::endl; 689 octave_stdout << l << ": " << line << std::endl;
690 } 690 }
691 } 691 }
692 else 692 else
693 octave_stdout << " (unknown line)\n"; 693 octave_stdout << " (unknown line)\n";
694 } 694 }
695 else 695 else
696 error ("dbwhere: must be inside of a user function to use dbwhere\n"); 696 error ("dbwhere: must be inside of a user function to use dbwhere\n");
697 697
698 return retval; 698 return retval;
708 if (! ff.empty ()) 708 if (! ff.empty ())
709 { 709 {
710 std::ifstream fs (ff.c_str (), std::ios::in); 710 std::ifstream fs (ff.c_str (), std::ios::in);
711 711
712 if (fs) 712 if (fs)
713 { 713 {
714 char ch; 714 char ch;
715 int line = 1; 715 int line = 1;
716 716
717 if (line >= start && line <= end) 717 if (line >= start && line <= end)
718 os << line << "\t"; 718 os << line << "\t";
719 719
720 while (fs.get (ch)) 720 while (fs.get (ch))
721 { 721 {
722 if (line >= start && line <= end) 722 if (line >= start && line <= end)
723 { 723 {
724 os << ch; 724 os << ch;
725 } 725 }
726 726
727 if (ch == '\n') 727 if (ch == '\n')
728 { 728 {
729 line++; 729 line++;
730 if (line >= start && line <= end) 730 if (line >= start && line <= end)
731 os << line << "\t"; 731 os << line << "\t";
732 } 732 }
733 } 733 }
734 } 734 }
735 else 735 else
736 os << "dbtype: unable to open `" << ff << "' for reading!\n"; 736 os << "dbtype: unable to open `" << ff << "' for reading!\n";
737 } 737 }
738 else 738 else
739 os << "dbtype: unknown function " << name << "\n"; 739 os << "dbtype: unknown function " << name << "\n";
740 740
741 os.flush (); 741 os.flush ();
755 string_vector argv = args.make_argv ("dbtype"); 755 string_vector argv = args.make_argv ("dbtype");
756 756
757 if (! error_state) 757 if (! error_state)
758 { 758 {
759 switch (nargin) 759 switch (nargin)
760 { 760 {
761 case 0: // dbtype 761 case 0: // dbtype
762 dbg_fcn = get_user_code (); 762 dbg_fcn = get_user_code ();
763 763
764 if (dbg_fcn) 764 if (dbg_fcn)
765 do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); 765 do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX);
766 else 766 else
767 error ("dbtype: must be in a user function to give no arguments to dbtype\n"); 767 error ("dbtype: must be in a user function to give no arguments to dbtype\n");
768 break; 768 break;
769 769
770 case 1: // (dbtype func) || (dbtype start:end) 770 case 1: // (dbtype func) || (dbtype start:end)
771 dbg_fcn = get_user_code (argv[1]); 771 dbg_fcn = get_user_code (argv[1]);
772 772
773 if (dbg_fcn) 773 if (dbg_fcn)
774 do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX); 774 do_dbtype (octave_stdout, dbg_fcn->name (), 0, INT_MAX);
775 else 775 else
776 { 776 {
777 dbg_fcn = get_user_code (); 777 dbg_fcn = get_user_code ();
778 778
779 if (dbg_fcn) 779 if (dbg_fcn)
780 { 780 {
781 std::string arg = argv[1]; 781 std::string arg = argv[1];
782 782
783 size_t ind = arg.find (':'); 783 size_t ind = arg.find (':');
784 784
785 if (ind != std::string::npos) 785 if (ind != std::string::npos)
786 { 786 {
787 std::string start_str = arg.substr (0, ind); 787 std::string start_str = arg.substr (0, ind);
788 std::string end_str = arg.substr (ind + 1); 788 std::string end_str = arg.substr (ind + 1);
789 789
790 int start = atoi (start_str.c_str ()); 790 int start = atoi (start_str.c_str ());
791 int end = atoi (end_str.c_str ()); 791 int end = atoi (end_str.c_str ());
792 792
793 if (std::min (start, end) <= 0) 793 if (std::min (start, end) <= 0)
794 error ("dbtype: start and end lines must be >= 1\n"); 794 error ("dbtype: start and end lines must be >= 1\n");
795 795
796 if (start <= end) 796 if (start <= end)
797 do_dbtype (octave_stdout, dbg_fcn->name (), start, end); 797 do_dbtype (octave_stdout, dbg_fcn->name (), start, end);
798 else 798 else
799 error ("dbtype: start line must be less than end line\n"); 799 error ("dbtype: start line must be less than end line\n");
800 } 800 }
801 else 801 else
802 error ("dbtype: line specification must be `start:end'"); 802 error ("dbtype: line specification must be `start:end'");
803 } 803 }
804 } 804 }
805 break; 805 break;
806 806
807 case 2: // (dbtype func start:end) , (dbtype func start) 807 case 2: // (dbtype func start:end) , (dbtype func start)
808 dbg_fcn = get_user_code (argv[1]); 808 dbg_fcn = get_user_code (argv[1]);
809 809
810 if (dbg_fcn) 810 if (dbg_fcn)
811 { 811 {
812 std::string arg = argv[2]; 812 std::string arg = argv[2];
813 int start = 0; 813 int start = 0;
814 int end = 0; 814 int end = 0;
815 size_t ind = arg.find (':'); 815 size_t ind = arg.find (':');
816 816
817 if (ind != std::string::npos) 817 if (ind != std::string::npos)
818 { 818 {
819 std::string start_str = arg.substr (0, ind); 819 std::string start_str = arg.substr (0, ind);
820 std::string end_str = arg.substr (ind + 1); 820 std::string end_str = arg.substr (ind + 1);
821 821
822 start = atoi (start_str.c_str ()); 822 start = atoi (start_str.c_str ());
823 end = atoi (end_str.c_str ()); 823 end = atoi (end_str.c_str ());
824 824
825 } 825 }
826 else 826 else
827 { 827 {
828 start = atoi (arg.c_str ()); 828 start = atoi (arg.c_str ());
829 end = start; 829 end = start;
830 } 830 }
831 831
832 if (std::min (start, end) <= 0) 832 if (std::min (start, end) <= 0)
833 error ("dbtype: start and end lines must be >= 1\n"); 833 error ("dbtype: start and end lines must be >= 1\n");
834 834
835 if (start <= end) 835 if (start <= end)
836 do_dbtype (octave_stdout, dbg_fcn->name (), start, end); 836 do_dbtype (octave_stdout, dbg_fcn->name (), start, end);
837 else 837 else
838 error ("dbtype: start line must be less than end line\n"); 838 error ("dbtype: start line must be less than end line\n");
839 } 839 }
840 break; 840 break;
841 841
842 default: 842 default:
843 error ("dbtype: expecting zero, one, or two arguments\n"); 843 error ("dbtype: expecting zero, one, or two arguments\n");
844 } 844 }
845 } 845 }
846 846
847 return retval; 847 return retval;
848 } 848 }
849 849
868 int n = 0; 868 int n = 0;
869 869
870 octave_value arg = args(0); 870 octave_value arg = args(0);
871 871
872 if (arg.is_string ()) 872 if (arg.is_string ())
873 { 873 {
874 std::string s_arg = arg.string_value (); 874 std::string s_arg = arg.string_value ();
875 875
876 n = atoi (s_arg.c_str ()); 876 n = atoi (s_arg.c_str ());
877 } 877 }
878 else 878 else
879 n = args(0).int_value (); 879 n = args(0).int_value ();
880 880
881 if (n > 0) 881 if (n > 0)
882 nskip = n; 882 nskip = n;
883 else 883 else
884 error ("dbstack: expecting N to be a nonnegative integer"); 884 error ("dbstack: expecting N to be a nonnegative integer");
885 } 885 }
886 886
887 if (! error_state) 887 if (! error_state)
888 { 888 {
889 Octave_map stk = octave_call_stack::backtrace (nskip, curr_frame); 889 Octave_map stk = octave_call_stack::backtrace (nskip, curr_frame);
890 890
891 if (nargout == 0) 891 if (nargout == 0)
892 { 892 {
893 octave_idx_type nframes_to_display = stk.numel (); 893 octave_idx_type nframes_to_display = stk.numel ();
894 894
895 if (nframes_to_display > 0) 895 if (nframes_to_display > 0)
896 { 896 {
897 octave_stdout << "Stopped in:\n\n"; 897 octave_stdout << "Stopped in:\n\n";
898 898
899 Cell names = stk.contents ("name"); 899 Cell names = stk.contents ("name");
900 Cell lines = stk.contents ("line"); 900 Cell lines = stk.contents ("line");
901 Cell columns = stk.contents ("column"); 901 Cell columns = stk.contents ("column");
902 902
903 for (octave_idx_type i = 0; i < nframes_to_display; i++) 903 for (octave_idx_type i = 0; i < nframes_to_display; i++)
904 { 904 {
905 octave_value name = names(i); 905 octave_value name = names(i);
906 octave_value line = lines(i); 906 octave_value line = lines(i);
907 octave_value column = columns(i); 907 octave_value column = columns(i);
908 908
909 octave_stdout << (i == curr_frame ? "--> " : " ") 909 octave_stdout << (i == curr_frame ? "--> " : " ")
910 << name.string_value () 910 << name.string_value ()
911 << " at line " << line.int_value () 911 << " at line " << line.int_value ()
912 << " column " << column.int_value () 912 << " column " << column.int_value ()
913 << std::endl; 913 << std::endl;
914 } 914 }
915 } 915 }
916 } 916 }
917 else 917 else
918 { 918 {
919 retval(1) = curr_frame < 0 ? 1 : curr_frame + 1; 919 retval(1) = curr_frame < 0 ? 1 : curr_frame + 1;
920 retval(0) = stk; 920 retval(0) = stk;
921 } 921 }
922 } 922 }
923 923
924 return retval; 924 return retval;
925 } 925 }
926 926
932 if (args.length () == 1) 932 if (args.length () == 1)
933 { 933 {
934 octave_value arg = args(0); 934 octave_value arg = args(0);
935 935
936 if (arg.is_string ()) 936 if (arg.is_string ())
937 { 937 {
938 std::string s_arg = arg.string_value (); 938 std::string s_arg = arg.string_value ();
939 939
940 n = atoi (s_arg.c_str ()); 940 n = atoi (s_arg.c_str ());
941 } 941 }
942 else 942 else
943 n = args(0).int_value (); 943 n = args(0).int_value ();
944 } 944 }
945 945
946 if (! error_state) 946 if (! error_state)
947 { 947 {
948 if (who == "dbup") 948 if (who == "dbup")
949 n = -n; 949 n = -n;
950 950
951 if (! octave_call_stack::goto_frame_relative (n, true)) 951 if (! octave_call_stack::goto_frame_relative (n, true))
952 error ("%s: invalid stack frame", who.c_str ()); 952 error ("%s: invalid stack frame", who.c_str ());
953 } 953 }
954 } 954 }
955 955
956 DEFUN (dbup, args, , 956 DEFUN (dbup, args, ,
957 "-*- texinfo -*-\n\ 957 "-*- texinfo -*-\n\
1005 if (Vdebugging) 1005 if (Vdebugging)
1006 { 1006 {
1007 int nargin = args.length (); 1007 int nargin = args.length ();
1008 1008
1009 if (nargin > 1) 1009 if (nargin > 1)
1010 print_usage (); 1010 print_usage ();
1011 else if (nargin == 1) 1011 else if (nargin == 1)
1012 { 1012 {
1013 if (args(0).is_string ()) 1013 if (args(0).is_string ())
1014 { 1014 {
1015 std::string arg = args(0).string_value (); 1015 std::string arg = args(0).string_value ();
1016 1016
1017 if (! error_state) 1017 if (! error_state)
1018 { 1018 {
1019 if (arg == "in") 1019 if (arg == "in")
1020 { 1020 {
1021 Vdebugging = false; 1021 Vdebugging = false;
1022 1022
1023 tree_evaluator::dbstep_flag = -1; 1023 tree_evaluator::dbstep_flag = -1;
1024 } 1024 }
1025 else if (arg == "out") 1025 else if (arg == "out")
1026 { 1026 {
1027 Vdebugging = false; 1027 Vdebugging = false;
1028 1028
1029 tree_evaluator::dbstep_flag = -2; 1029 tree_evaluator::dbstep_flag = -2;
1030 } 1030 }
1031 else 1031 else
1032 { 1032 {
1033 int n = atoi (arg.c_str ()); 1033 int n = atoi (arg.c_str ());
1034 1034
1035 if (n > 0) 1035 if (n > 0)
1036 { 1036 {
1037 Vdebugging = false; 1037 Vdebugging = false;
1038 1038
1039 tree_evaluator::dbstep_flag = n; 1039 tree_evaluator::dbstep_flag = n;
1040 } 1040 }
1041 else 1041 else
1042 error ("dbstep: invalid argument"); 1042 error ("dbstep: invalid argument");
1043 } 1043 }
1044 } 1044 }
1045 } 1045 }
1046 else 1046 else
1047 error ("dbstep: expecting character string as argument"); 1047 error ("dbstep: expecting character string as argument");
1048 } 1048 }
1049 else 1049 else
1050 { 1050 {
1051 Vdebugging = false; 1051 Vdebugging = false;
1052 1052
1053 tree_evaluator::dbstep_flag = 1; 1053 tree_evaluator::dbstep_flag = 1;
1054 } 1054 }
1055 } 1055 }
1056 else 1056 else
1057 error ("dbstep: can only be called in debug mode"); 1057 error ("dbstep: can only be called in debug mode");
1058 1058
1059 return octave_value_list (); 1059 return octave_value_list ();
1069 @end deftypefn") 1069 @end deftypefn")
1070 { 1070 {
1071 if (Vdebugging) 1071 if (Vdebugging)
1072 { 1072 {
1073 if (args.length () == 0) 1073 if (args.length () == 0)
1074 { 1074 {
1075 Vdebugging = false; 1075 Vdebugging = false;
1076 1076
1077 tree_evaluator::reset_debug_state (); 1077 tree_evaluator::reset_debug_state ();
1078 } 1078 }
1079 else 1079 else
1080 print_usage (); 1080 print_usage ();
1081 } 1081 }
1082 else 1082 else
1083 error ("dbcont: can only be called in debug mode"); 1083 error ("dbcont: can only be called in debug mode");
1084 1084
1085 return octave_value_list (); 1085 return octave_value_list ();
1093 @end deftypefn") 1093 @end deftypefn")
1094 { 1094 {
1095 if (Vdebugging) 1095 if (Vdebugging)
1096 { 1096 {
1097 if (args.length () == 0) 1097 if (args.length () == 0)
1098 { 1098 {
1099 Vdebugging = false; 1099 Vdebugging = false;
1100 1100
1101 tree_evaluator::reset_debug_state (); 1101 tree_evaluator::reset_debug_state ();
1102 1102
1103 octave_throw_interrupt_exception (); 1103 octave_throw_interrupt_exception ();
1104 } 1104 }
1105 else 1105 else
1106 print_usage (); 1106 print_usage ();
1107 } 1107 }
1108 else 1108 else
1109 error ("dbquit: can only be called in debug mode"); 1109 error ("dbquit: can only be called in debug mode");
1110 1110
1111 return octave_value_list (); 1111 return octave_value_list ();