26#if defined (HAVE_CONFIG_H)
65bp_lines_to_ov (
const octave::bp_table::bp_lines& lines)
71 for (
const auto& lineno : lines)
72 retval(idx++) = lineno;
170 octave::bp_table::bp_lines retmap;
171 std::string symbol_name =
"";
172 std::string class_name =
"";
173 octave::bp_table::bp_lines lines;
174 std::string condition =
"";
177 octave::tree_evaluator& tw = interp.get_evaluator ();
179 octave::bp_table& bptab = tw.get_bp_table ();
181 if (args.length() >= 1 && ! args(0).isstruct ())
184 bptab.parse_dbfunction_params (
"dbstop", args, symbol_name,
185 class_name, lines, condition);
187 if (lines.size () == 0)
190 if (symbol_name !=
"")
192 std::string fcn_ident;
193 if (class_name.empty ())
194 fcn_ident = symbol_name;
196 fcn_ident =
"@" + class_name +
"/" + symbol_name;
198 retmap = bptab.add_breakpoints_in_function (fcn_ident, lines,
200 retval = bp_lines_to_ov (retmap);
203 else if (args.length () != 1)
213 bptab.dbstop_process_map_args (mv);
225 error (
"dbstop: invalid 'bkpt' field");
234 error (
"dbstop: Cell array must contain fields 'name' and 'line'");
238 bool use_cond = mv.
isfield (
"cond");
242 std::string unconditional =
"";
249 lines.insert (line(i).int_value ());
250 bptab.add_breakpoints_in_function (name(i).string_value (),
253 ? cond(i).string_value ()
261 tw.reset_debug_state ();
310 std::string symbol_name =
"";
311 std::string class_name =
"";
312 octave::bp_table::bp_lines lines;
315 octave::tree_evaluator& tw = interp.get_evaluator ();
317 octave::bp_table& bptab = tw.get_bp_table ();
319 bptab.parse_dbfunction_params (
"dbclear", args, symbol_name, class_name,
322 if (args.length () == 1 && symbol_name ==
"all")
324 bptab.remove_all_breakpoints ();
325 bptab.dbclear_all_signals ();
327 else if (symbol_name !=
"")
329 std::string fcn_ident;
330 if (class_name.empty ())
331 fcn_ident = symbol_name;
333 fcn_ident =
"@" + class_name +
"/" + symbol_name;
335 bptab.remove_breakpoints_from_function (fcn_ident, lines);
339 tw.reset_debug_state ();
344DEFMETHOD (dbstatus, interp, args, nargout,
389 int nargin = args.length ();
391 if (nargin != 0 && nargin != 1)
392 error (
"dbstatus: only zero or one arguments accepted\n");
395 octave::bp_table::fname_bp_map bp_list;
396 std::string symbol_name;
398 octave::tree_evaluator& tw = interp.get_evaluator ();
400 octave::bp_table& bptab = tw.get_bp_table ();
404 if (! args(0).is_string ())
407 symbol_name = args(0).string_value ();
408 fcn_list(0) = symbol_name;
409 bp_list = bptab.get_breakpoint_list (fcn_list);
425 bp_list = bptab.get_breakpoint_list (fcn_list);
432 for (
auto& fnm_bp_p: bp_list)
434 std::list<octave::bp_type> m = fnm_bp_p.second;
439 int have_unconditional = 0;
440 for (
const auto& bp : m)
444 if (have_unconditional++)
449 if (have_unconditional)
451 const char *_s_ = (have_unconditional > 1) ?
"s" :
"";
452 octave_stdout <<
"breakpoint" << _s_ <<
" in " << fnm_bp_p.first
453 <<
" at line" << _s_ <<
' ';
455 for (
const auto& bp : m)
464 for (
const auto& bp : m)
468 <<
" at line " << bp.line
469 <<
" if " << bp.cond <<
"\n";
473 bptab.stop_on_err_warn_status (
true);
479 octave::help_system& help_sys = interp.get_help_system ();
488 for (
const auto& fnm_bp_p : bp_list)
489 count += fnm_bp_p.second.size ();
496 for (
const auto& fnm_bp_p : bp_list)
498 std::string filename = fnm_bp_p.first;
499 const char *sub_fcn = strchr (filename.c_str (),
'>');
501 filename = filename.substr(0, sub_fcn - filename.c_str ());
504 = octave::sys::canonicalize_file_name (help_sys.which (filename));
506 for (
const auto& bp : fnm_bp_p.second)
508 names(i) = fnm_bp_p.first;
516 retmap.
assign (
"name", names);
517 retmap.
assign (
"file", file);
518 retmap.
assign (
"line", line);
519 retmap.
assign (
"cond", cond);
521 const octave_map ew = bptab.stop_on_err_warn_status (
false);
588 octave::tree_evaluator& tw = interp.get_evaluator ();
596parse_start_end (
const std::string& arg,
int& start,
int& end,
const char *who)
601 std::size_t ind = arg.find (
':');
603 if (ind != std::string::npos)
605 std::string start_str = arg.substr (0, ind);
606 std::string end_str = arg.substr (ind+1);
610 start = std::stoi (start_str);
612 if (end_str ==
"end")
613 end = std::numeric_limits<int>::max ();
615 end = std::stoi (end_str);
617 catch (
const std::invalid_argument&)
619 error (
"%s: invalid integer conversion while parsing range '%s'", who, arg.c_str ());
621 catch (
const std::out_of_range&)
623 error (
"%s: integer value out of bounds while parsing range '%s'", who, arg.c_str ());
626 if (std::min (start, end) <= 0)
627 error (
"%s: start and end lines must be >= 1\n", who);
630 error (
"%s: start line must be less than end line\n", who);
636 int line = std::stoi (arg);
639 error (
"%s: start and end lines must be >= 1\n", who);
644 catch (
const std::invalid_argument&)
649 catch (
const std::out_of_range&)
651 error (
"%s: integer value out of bounds while parsing '%s'", who, arg.c_str ());
685 std::string fcn_name;
688 int end = std::numeric_limits<int>::max ();
690 switch (args.length ())
697 std::string arg = argv[1];
699 if (! parse_start_end (arg, start, end,
"dbtype"))
708 if (! parse_start_end (argv[2], start, end,
"dbtype"))
709 error (
"dbtype: expecting start:end or location argument, found '%s'", argv[2].c_str ());
714 error (
"dbtype: expecting zero, one, or two arguments\n");
717 if (fcn_name.empty ())
719 octave::tree_evaluator& tw = interp.get_evaluator ();
725 std::string file_name = octave::fcn_file_in_path (fcn_name);
727 if (file_name.empty ())
728 error (
"dbtype: unknown function '%s'", fcn_name.c_str ());
730 octave::display_file_lines (
octave_stdout, file_name, start, end, -1,
"",
"dbtype");
737parse_integer_argument (
const std::string& arg,
const char *who)
745 catch (
const std::invalid_argument&)
747 error (
"%s: invalid value of N, found '%s'", arg.c_str (), who);
749 catch (
const std::out_of_range&)
751 error (
"%s: value of N ('%s') is out of range", arg.c_str (), who);
770 int numel = args.length ();
780 n = parse_integer_argument (arg.
string_value (),
"dblist");
782 n = args(0).int_value ();
785 error (
"dblist: N must be a non-negative integer");
788 octave::tree_evaluator& tw = interp.get_evaluator ();
797 int nargout, std::ostream& os)
799 int nargin = args.
length ();
810 if (nargin == 1 || nargin == 2)
823 if (s_arg ==
"-completenames")
826 n = parse_integer_argument (s_arg,
"dbstack");
832 error (
"dbstack: N must be a non-negative integer");
839 octave::tree_evaluator& tw = interp.get_evaluator ();
848 octave::preserve_stream_state stream_state (os);
850 os <<
"stopped in:\n\n";
856 bool show_top_level =
true;
858 std::size_t max_name_len = 0;
862 std::string name = names(i).string_value ();
864 max_name_len = std::max (name.length (), max_name_len);
869 std::string name = names(i).string_value ();
870 std::string file = files(i).string_value ();
871 int line = lines(i).int_value ();
873 if (show_top_level && i == curr_frame)
874 show_top_level =
false;
876 os << (i == curr_frame ?
" --> " :
" ")
877 << std::setw (max_name_len) << name
878 <<
" at line " << line
879 <<
" [" << file <<
']'
883 if (tw.at_top_level () && show_top_level)
884 os <<
" --> top level" << std::endl;
889 octave_map stk = tw.backtrace (curr_frame,
false);
898 curr_frame -= num_skip;
899 curr_frame = (curr_frame < 0 ? 0 : curr_frame + 1);
901 retval =
ovl (stk, curr_frame);
915 do_dbstack (octave::__get_interpreter__ (),
919DEFMETHOD (dbstack, interp, args, nargout,
963 const std::string& who)
972 n = parse_integer_argument (arg.
string_value (), who.c_str ());
974 n = args(0).int_value ();
980 octave::tree_evaluator& tw = interp.get_evaluator ();
982 tw.dbupdown (n,
true);
995 do_dbupdown (interp, args,
"dbup");
1010 do_dbupdown (interp, args,
"dbdown");
1039 octave::tree_evaluator& tw = interp.get_evaluator ();
1041 if (! tw.in_debug_repl ())
1042 error (
"dbstep: can only be called in debug mode");
1044 int nargin = args.
length ();
1054 = args(0).xstring_value (
"dbstep: input argument must be a string");
1058 else if (arg ==
"out")
1062 n = parse_integer_argument (arg,
"dbstep");
1065 error (
"dbstep: N must be greater than zero");
1073 tw.set_dbstep_flag (n);
1076 tw.reset_debug_state ();
1092 octave::tree_evaluator& tw = interp.get_evaluator ();
1094 if (! tw.in_debug_repl ())
1095 error (
"dbcont: can only be called in debug mode");
1116 octave::tree_evaluator& tw = interp.get_evaluator ();
1118 if (! tw.in_debug_repl ())
1119 error (
"dbquit: can only be called in debug mode");
1121 int nargin = args.
length ();
1129 = args(0).xstring_value (
"dbquit: input argument must be a string");
1134 error (
"dbquit: unrecognized argument '%s'", arg.c_str ());
1152 octave::tree_evaluator& tw = interp.get_evaluator ();
1154 return ovl (tw.in_debug_repl ());
1157DEFMETHOD (__db_next_breakpoint_quiet__, interp, args, ,
1166 int nargin = args.
length ();
1174 state = args(0).bool_value ();
1176 octave::tree_evaluator& tw = interp.get_evaluator ();
1178 tw.quiet_breakpoint_flag (state);
1183OCTAVE_END_NAMESPACE(octave)
octave_idx_type numel() const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
Cell getfield(const std::string &key) const
const_iterator end() const
const Cell & contents(const_iterator p) const
bool isfield(const std::string &name) const
void delete_elements(const octave::idx_vector &i)
void setfield(const std::string &key, const Cell &val)
octave_idx_type numel() const
void assign(const std::string &k, const Cell &val)
const_iterator begin() const
octave_idx_type length() const
int int_value(bool req_int=false, bool frc_str_conv=false) const
std::string string_value(bool force=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void show_octave_dbstack()
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
void error(const char *fmt,...)
void err_wrong_type_arg(const char *name, const char *s)
F77_RET_T const F77_DBLE const F77_DBLE * f
T::size_type numel(const T &str)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.