75 size_t sz = fs.
size ();
77 std::ifstream file (fname.c_str (), std::ios::in|std::ios::binary);
81 std::string buf (sz+1, 0);
83 file.read (&buf[0], sz+1);
92 error (
"error reading file %s", fname.c_str ());
99 static std::deque<size_t>
105 std::deque<size_t> offsets;
107 offsets.push_back (0);
109 size_t len = buf.length ();
111 for (
size_t i = 0; i < len; i++)
115 if (c ==
'\r' && ++i < len)
120 offsets.push_back (i+1);
122 offsets.push_back (i);
125 offsets.push_back (i+1);
128 offsets.push_back (len);
138 static std::string last_fname;
140 static std::string buf;
142 static std::deque<size_t> offsets;
144 if (fname != last_fname)
154 if (line < offsets.size () - 1)
156 size_t bol = offsets[line];
157 size_t eol = offsets[line+1];
159 while (eol > 0 && eol > bol && (buf[eol-1] ==
'\n' || buf[eol-1] ==
'\r'))
162 retval = buf.substr (bol, eol - bol);
194 int nargin = args.
length ();
197 symbol_name = std::string ();
209 else if (args(0).is_map ())
214 else if (args(0).is_string ())
216 symbol_name = args(0).string_value ();
222 error (
"%s: invalid parameter specified", who);
224 for (
int i = idx; i < nargin; i++ )
226 if (args(i).is_string ())
228 int line = atoi (args(i).string_value ().c_str ());
231 lines[list_idx++] = line;
233 else if (args(i).is_map ())
244 int line =
static_cast<int> (arg.
elem (j));
247 lines[list_idx++] = line;
271 ::error (
"unable to create breakpoint table!");
280 const std::string& fname,
322 const std::list<std::string> subfcn_names
325 std::map<std::string, octave_value> subfcns
328 for (std::list<std::string>::const_iterator p = subfcn_names.begin ();
329 p != subfcn_names.end (); p++)
331 std::map<std::string, octave_value>::const_iterator
332 q = subfcns.find (*p);
334 if (q != subfcns.end ())
345 error (
"add_breakpoint: unable to find the requested function\n");
355 const std::string& fname,
370 if (results.
length () > 0)
374 for (
int i = 0; i < len; i++)
378 if (p != line.end ())
380 int lineno = p->second;
396 retval = results.
length ();
413 retval = results.size ();
425 const std::list<std::string> subfcn_names
428 std::map<std::string, octave_value> subfcns
431 for (std::list<std::string>::const_iterator p = subfcn_names.begin ();
432 p != subfcn_names.end (); p++)
434 std::map<std::string, octave_value>::const_iterator
435 q = subfcns.find (*p);
437 if (q != subfcns.end ())
446 error (
"remove_breakpoint: unable to find the requested function\n");
456 const std::string& fname)
490 typedef std::map<std::string, octave_value>::const_iterator
491 subfcns_const_iterator;
493 std::map<std::string, octave_value> subfcns = dbg_fcn->
subfunctions ();
495 for (subfcns_const_iterator p = subfcns.begin ();
496 p != subfcns.end (); p++)
503 retval.insert (tmp.begin (), tmp.end ());
507 error (
"remove_all_breakpoint_in_file: "
508 "unable to find the requested function\n");
531 for (
int i = 0; i < slist.
length (); i++)
533 if (slist (i).string_value () ==
match)
535 retval = slist(i).string_value ();
551 if (fname_list.
length () == 0
571 for (
int i = 0; i < len; i++)
572 bkpts_vec[i] = bkpts (i).double_value ();
574 std::string symbol_name = f->
name ();
576 retval[symbol_name] = bkpts_vec;
593 for (
size_t i = 0; i < line.size (); i++)
597 if (p != line.end ())
599 int lineno = p->second;
600 retval(idx++) = lineno;
609 DEFUN (dbstop, args, ,
611 @deftypefn {Built-in Function} {@var{rline} =} dbstop (\"@var{func}\")\n\
612 @deftypefnx {Built-in Function} {@var{rline} =} dbstop (\"@var{func}\", @var{line})\n\
613 @deftypefnx {Built-in Function} {@var{rline} =} dbstop (\"@var{func}\", @var{line1}, @var{line2}, @dots{})\n\
614 Set a breakpoint in function @var{func}.\n\
620 Function name as a string variable. When already in debug\n\
621 mode this should be left out and only the line should be given.\n\
624 Line number where the breakpoint should be set. Multiple\n\
625 lines may be given as separate arguments or as a vector.\n\
628 When called with a single argument @var{func}, the breakpoint\n\
629 is set at the first executable line in the named function.\n\
631 The optional output @var{rline} is the real line number where the\n\
632 breakpoint was set. This can differ from specified line if\n\
633 the line is not executable. For example, if a breakpoint attempted on a\n\
634 blank line then Octave will set the real breakpoint at the\n\
635 next executable line.\n\
636 @seealso{dbclear, dbstatus, dbstep, debug_on_error, debug_on_warning, debug_on_interrupt}\n\
640 std::string symbol_name;
645 if (lines.size () == 0)
654 DEFUN (dbclear, args, ,
656 @deftypefn {Built-in Function} {} dbclear (\"@var{func}\")\n\
657 @deftypefnx {Built-in Function} {} dbclear (\"@var{func}\", @var{line}, @dots{})\n\
658 @deftypefnx {Built-in Function} {} dbclear (@var{line}, @dots{})\n\
659 Delete a breakpoint in the function @var{func}.\n\
665 Function name as a string variable. When already in debug\n\
666 mode this argument should be omitted and only the line number should be\n\
670 Line number from which to remove a breakpoint. Multiple\n\
671 lines may be given as separate arguments or as a vector.\n\
674 When called without a line number specification all breakpoints\n\
675 in the named function are cleared.\n\
677 If the requested line is not a breakpoint no action is performed.\n\
678 @seealso{dbstop, dbstatus, dbwhere}\n\
682 std::string symbol_name =
"";
693 DEFUN (dbstatus, args, nargout,
695 @deftypefn {Built-in Function} {} dbstatus ()\n\
696 @deftypefnx {Built-in Function} {@var{brk_list} =} dbstatus ()\n\
697 @deftypefnx {Built-in Function} {@var{brk_list} =} dbstatus (\"@var{func}\")\n\
698 Report the location of active breakpoints.\n\
700 When called with no input or output arguments, print the list of\n\
701 all functions with breakpoints and the line numbers where those\n\
702 breakpoints are set.\n\
703 If a function name @var{func} is specified then only report breakpoints\n\
704 for the named function.\n\
706 The optional return argument @var{brk_list} is a struct array with the\n\
711 The name of the function with a breakpoint.\n\
714 The name of the m-file where the function code is located.\n\
717 A line number, or vector of line numbers, with a breakpoint.\n\
720 @seealso{dbclear, dbwhere}\n\
724 int nargin = args.
length ();
727 std::string symbol_name;
729 if (nargin != 0 && nargin != 1)
731 error (
"dbstatus: only zero or one arguments accepted\n");
737 if (args(0).is_string ())
739 symbol_name = args(0).string_value ();
740 fcn_list(0) = symbol_name;
751 symbol_name = dbg_fcn->
name ();
752 fcn_list(0) = symbol_name;
763 it != bp_list.end (); it++)
767 size_t nel = m.size ();
775 for (
size_t j = 0; j < nel; j++)
793 it != bp_list.end (); it++)
795 names(i) = it->first;
801 retval.
assign (
"name", names);
802 retval.
assign (
"file", file);
803 retval.
assign (
"line", line);
811 @deftypefn {Command} {} dbwhere\n\
812 In debugging mode, report the current file and line number where\n\
813 execution is stopped.\n\
814 @seealso{dbstatus, dbcont, dbstep, dbup}\n\
823 bool have_file =
true;
831 name = dbg_fcn->
name ();
854 error (
"dbwhere: must be inside a user function to use dbwhere\n");
862 do_dbtype (std::ostream& os,
const std::string& name,
int start,
int end)
868 std::ifstream fs (ff.c_str (), std::ios::in);
874 bool isnewline =
true;
877 while (fs.get (ch) && line <= end)
879 if (isnewline && line >= start)
898 os <<
"dbtype: unable to open '" << ff <<
"' for reading!\n";
901 os <<
"dbtype: unknown function " << name <<
"\n";
906 DEFUN (dbtype, args, ,
908 @deftypefn {Command} {} dbtype\n\
909 @deftypefnx {Command} {} dbtype @var{lineno}\n\
910 @deftypefnx {Command} {} dbtype @var{startl:endl}\n\
911 @deftypefnx {Command} {} dbtype @var{startl:end}\n\
912 @deftypefnx {Command} {} dbtype @var{func}\n\
913 @deftypefnx {Command} {} dbtype @var{func} @var{lineno}\n\
914 @deftypefnx {Command} {} dbtype @var{func} @var{startl:endl}\n\
915 @deftypefnx {Command} {} dbtype @var{func} @var{startl:end}\n\
916 Display a script file with line numbers.\n\
918 When called with no arguments in debugging mode, display the script file\n\
919 currently being debugged. An optional range specification can be used to\n\
920 list only a portion of the file. The special keyword @qcode{\"end\"} is a\n\
921 valid line number specification for the last line of the file.\n\
923 When called with the name of a function, list that script file with line\n\
925 @seealso{dbwhere, dbstatus, dbstop}\n\
931 int nargin = args.length ();
945 error (
"dbtype: must be inside a user function to give no arguments to dbtype\n");
950 std::string
arg = argv[1];
952 size_t ind = arg.
find (
':');
954 if (ind != std::string::npos)
960 std::string start_str = arg.substr (0, ind);
961 std::string end_str = arg.substr (ind + 1);
964 start = atoi (start_str.c_str ());
965 if (end_str ==
"end")
968 end = atoi (end_str.c_str ());
971 error (
"dbtype: start and end lines must be >= 1\n");
976 error (
"dbtype: start line must be less than end line\n");
987 error (
"dbtype: function <%s> not found\n", arg.c_str ());
997 std::string
arg = argv[2];
999 size_t ind = arg.
find (
':');
1001 if (ind != std::string::npos)
1003 std::string start_str = arg.substr (0, ind);
1004 std::string end_str = arg.substr (ind + 1);
1006 start = atoi (start_str.c_str ());
1007 if (end_str ==
"end")
1010 end = atoi (end_str.c_str ());
1014 start = atoi (arg.c_str ());
1019 error (
"dbtype: start and end lines must be >= 1\n");
1024 error (
"dbtype: start line must be less than end line\n");
1027 error (
"dbtype: function <%s> not found\n", argv[1].c_str ());
1032 error (
"dbtype: expecting zero, one, or two arguments\n");
1039 DEFUN (dblist, args, ,
1041 @deftypefn {Command} {} dblist\n\
1042 @deftypefnx {Command} {} dblist @var{n}\n\
1043 In debugging mode, list @var{n} lines of the function being debugged\n\
1044 centered around the current line to be executed. If unspecified @var{n}\n\
1045 defaults to 10 (+/- 5 lines)\n\
1046 @seealso{dbwhere, dbtype}\n\
1053 if (args.length () == 1)
1061 n = atoi (s_arg.c_str ());
1064 n = args(0).int_value ();
1067 error (
"dblist: N must be a non-negative integer");
1074 bool have_file =
true;
1081 name = dbg_fcn->
name ();
1091 int l_max = l + n/2;
1095 if (! line.empty ())
1103 octave_stdout <<
"dblist: unable to determine source code line"
1108 error (
"dblist: must be inside a user function to use dblist\n");
1128 if (len == 1 || len == 2)
1142 if (s_arg ==
"-completenames")
1145 n = atoi (s_arg.c_str ());
1151 error (
"dbstack: N must be a non-negative integer");
1168 if (nframes_to_display > 0)
1172 os <<
"stopped in:\n\n";
1178 bool show_top_level =
true;
1180 size_t max_name_len = 0;
1184 std::string name =
names(i).string_value ();
1186 max_name_len =
std::max (name.length (), max_name_len);
1191 std::string name =
names(i).string_value ();
1192 std::string file = files(i).string_value ();
1193 int line = lines(i).int_value ();
1195 if (show_top_level && i == curr_frame)
1196 show_top_level =
false;
1198 os << (i == curr_frame ?
" --> " :
" ")
1199 << std::setw (max_name_len) << name
1200 <<
" at line " << line
1201 <<
" [" << file <<
"]"
1206 os <<
" --> top level" << std::endl;
1211 retval(1) = curr_frame < 0 ? 1 : curr_frame + 1;
1230 DEFUN (dbstack, args, nargout,
1232 @deftypefn {Command} {} dbstack\n\
1233 @deftypefnx {Command} {} dbstack @var{n}\n\
1234 @deftypefnx {Command} {} dbstack @var{-completenames}\n\
1235 @deftypefnx {Built-in Function} {[@var{stack}, @var{idx}] =} dbstack (@dots{})\n\
1236 Display or return current debugging function stack information.\n\
1237 With optional argument @var{n}, omit the @var{n} innermost stack frames.\n\
1239 Although accepted, the argument @var{-completenames} is silently ignored.\n\
1240 Octave always returns absolute file names. The arguments @var{n} and\n\
1241 @var{-completenames} can be both specified in any order.\n\
1243 The optional return argument @var{stack} is a struct array with the\n\
1244 following fields:\n\
1248 The name of the m-file where the function code is located.\n\
1251 The name of the function with a breakpoint.\n\
1254 The line number of an active breakpoint.\n\
1257 The column number of the line where the breakpoint begins.\n\
1266 The return argument @var{idx} specifies which element of the @var{stack}\n\
1267 struct array is currently active.\n\
1268 @seealso{dbup, dbdown, dbwhere, dbstatus}\n\
1287 n = atoi (s_arg.c_str ());
1290 n = args(0).int_value ();
1299 error (
"%s: invalid stack frame", who.c_str ());
1303 DEFUN (dbup, args, ,
1305 @deftypefn {Built-in Function} {} dbup\n\
1306 @deftypefnx {Built-in Function} {} dbup (@var{n})\n\
1307 In debugging mode, move up the execution stack @var{n} frames.\n\
1308 If @var{n} is omitted, move up one frame.\n\
1309 @seealso{dbstack, dbdown}\n\
1319 DEFUN (dbdown, args, ,
1321 @deftypefn {Built-in Function} {} dbdown\n\
1322 @deftypefnx {Built-in Function} {} dbdown (@var{n})\n\
1323 In debugging mode, move down the execution stack @var{n} frames.\n\
1324 If @var{n} is omitted, move down one frame.\n\
1325 @seealso{dbstack, dbup}\n\
1335 DEFUN (dbstep, args, ,
1337 @deftypefn {Command} {} dbstep\n\
1338 @deftypefnx {Command} {} dbstep @var{n}\n\
1339 @deftypefnx {Command} {} dbstep in\n\
1340 @deftypefnx {Command} {} dbstep out\n\
1341 @deftypefnx {Command} {} dbnext @dots{}\n\
1342 In debugging mode, execute the next @var{n} lines of code.\n\
1343 If @var{n} is omitted, execute the next single line of code.\n\
1344 If the next line of code is itself defined in terms of an m-file remain in\n\
1345 the existing function.\n\
1347 Using @code{dbstep in} will cause execution of the next line to step into\n\
1348 any m-files defined on the next line. Using @code{dbstep out} will cause\n\
1349 execution to continue until the current function returns.\n\
1351 @code{dbnext} is an alias for @code{dbstep}.\n\
1352 @seealso{dbcont, dbquit}\n\
1357 int nargin = args.length ();
1361 else if (nargin == 1)
1363 if (args(0).is_string ())
1365 std::string
arg = args(0).string_value ();
1375 else if (arg ==
"out")
1383 int n = atoi (arg.c_str ());
1392 error (
"dbstep: invalid argument");
1397 error (
"dbstep: input argument must be a character string");
1407 error (
"dbstep: can only be called in debug mode");
1414 DEFUN (dbcont, args, ,
1416 @deftypefn {Command} {} dbcont\n\
1417 Leave command-line debugging mode and continue code execution normally.\n\
1418 @seealso{dbstep, dbquit}\n\
1423 if (args.length () == 0)
1433 error (
"dbcont: can only be called in debug mode");
1438 DEFUN (dbquit, args, ,
1440 @deftypefn {Command} {} dbquit\n\
1441 Quit debugging mode immediately without further code execution and\n\
1442 return to the Octave prompt.\n\
1443 @seealso{dbcont, dbstep}\n\
1448 if (args.length () == 0)
1460 error (
"dbquit: can only be called in debug mode");
1465 DEFUN (isdebugmode, args, ,
1467 @deftypefn {Built-in Function} {} isdebugmode ()\n\
1468 Return true if in debugging mode, otherwise false.\n\
1469 @seealso{dbwhere, dbstack, dbstatus}\n\
1474 if (args.length () == 0)