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,
390 int nargin = args.length ();
392 if (nargin != 0 && nargin != 1)
393 error (
"dbstatus: only zero or one arguments accepted\n");
396 octave::bp_table::fname_bp_map bp_list;
397 std::string symbol_name;
399 octave::tree_evaluator& tw = interp.get_evaluator ();
401 octave::bp_table& bptab = tw.get_bp_table ();
405 if (! args(0).is_string ())
408 symbol_name = args(0).string_value ();
409 fcn_list(0) = symbol_name;
410 bp_list = bptab.get_breakpoint_list (fcn_list);
426 bp_list = bptab.get_breakpoint_list (fcn_list);
433 for (
auto& fnm_bp_p: bp_list)
435 std::list<octave::bp_type> m = fnm_bp_p.second;
440 int have_unconditional = 0;
441 for (
const auto& bp : m)
445 if (have_unconditional++)
450 if (have_unconditional)
452 const char *_s_ = (have_unconditional > 1) ?
"s" :
"";
453 octave_stdout <<
"breakpoint" << _s_ <<
" in " << fnm_bp_p.first
454 <<
" at line" << _s_ <<
' ';
456 for (
const auto& bp : m)
465 for (
const auto& bp : m)
469 <<
" at line " << bp.line
470 <<
" if " << bp.cond <<
"\n";
474 bptab.stop_on_err_warn_status (
true);
480 octave::help_system& help_sys = interp.get_help_system ();
489 for (
const auto& fnm_bp_p : bp_list)
490 count += fnm_bp_p.second.size ();
497 for (
const auto& fnm_bp_p : bp_list)
499 std::string filename = fnm_bp_p.first;
500 const char *sub_fcn = strchr (filename.c_str (),
'>');
502 filename = filename.substr(0, sub_fcn - filename.c_str ());
505 = octave::sys::canonicalize_file_name (help_sys.which (filename));
507 for (
const auto& bp : fnm_bp_p.second)
509 names(i) = fnm_bp_p.first;
517 retmap.
assign (
"name", names);
518 retmap.
assign (
"file", file);
519 retmap.
assign (
"line", line);
520 retmap.
assign (
"cond", cond);
522 const octave_map ew = bptab.stop_on_err_warn_status (
false);
589 octave::tree_evaluator& tw = interp.get_evaluator ();
597parse_start_end (
const std::string& arg,
int& start,
int& end,
const char *who)
599 std::size_t idx = arg.find (
':');
601 if (idx != std::string::npos)
603 std::string start_str = arg.substr (0, idx);
604 std::string end_str = arg.substr (idx+1);
608 start = std::stoi (start_str);
610 if (end_str ==
"end")
611 end = std::numeric_limits<int>::max ();
613 end = std::stoi (end_str);
615 catch (
const std::invalid_argument&)
617 error (
"%s: invalid integer conversion while parsing range '%s'", who, arg.c_str ());
619 catch (
const std::out_of_range&)
621 error (
"%s: integer value out of bounds while parsing range '%s'", who, arg.c_str ());
624 if (std::min (start, end) <= 0)
625 error (
"%s: start and end lines must be >= 1\n", who);
628 error (
"%s: start line must be less than end line\n", who);
634 int line = std::stoi (arg);
637 error (
"%s: start and end lines must be >= 1\n", who);
641 catch (
const std::invalid_argument&)
646 catch (
const std::out_of_range&)
648 error (
"%s: integer value out of bounds while parsing '%s'", who, arg.c_str ());
682 std::string fcn_name;
685 int end = std::numeric_limits<int>::max ();
687 switch (args.length ())
694 std::string arg = argv[1];
696 if (! parse_start_end (arg, start, end,
"dbtype"))
705 if (! parse_start_end (argv[2], start, end,
"dbtype"))
706 error (
"dbtype: expecting start:end or location argument, found '%s'", argv[2].c_str ());
711 error (
"dbtype: expecting zero, one, or two arguments\n");
714 if (fcn_name.empty ())
716 octave::tree_evaluator& tw = interp.get_evaluator ();
722 std::string file_name = octave::fcn_file_in_path (fcn_name);
724 if (file_name.empty ())
725 error (
"dbtype: unknown function '%s'", fcn_name.c_str ());
727 octave::display_file_lines (
octave_stdout, file_name, start, end, -1,
"",
"dbtype");
734parse_integer_argument (
const std::string& arg,
const char *who)
742 catch (
const std::invalid_argument&)
744 error (
"%s: invalid value of N, found '%s'", arg.c_str (), who);
746 catch (
const std::out_of_range&)
748 error (
"%s: value of N ('%s') is out of range", arg.c_str (), who);
767 int numel = args.length ();
777 n = parse_integer_argument (arg.
string_value (),
"dblist");
779 n = args(0).int_value ();
782 error (
"dblist: N must be a non-negative integer");
785 octave::tree_evaluator& tw = interp.get_evaluator ();
794 int nargout, std::ostream& os)
796 int nargin = args.
length ();
807 if (nargin == 1 || nargin == 2)
820 if (s_arg ==
"-completenames")
823 n = parse_integer_argument (s_arg,
"dbstack");
829 error (
"dbstack: N must be a non-negative integer");
836 octave::tree_evaluator& tw = interp.get_evaluator ();
845 octave::preserve_stream_state stream_state (os);
847 os <<
"stopped in:\n\n";
853 bool show_top_level =
true;
855 std::size_t max_name_len = 0;
859 std::string name = names(i).string_value ();
861 max_name_len = std::max (name.length (), max_name_len);
866 std::string name = names(i).string_value ();
867 std::string file = files(i).string_value ();
868 int line = lines(i).int_value ();
870 if (show_top_level && i == curr_frame)
871 show_top_level =
false;
873 os << (i == curr_frame ?
" --> " :
" ")
874 << std::setw (max_name_len) << name
875 <<
" at line " << line
876 <<
" [" << file <<
']'
880 if (tw.at_top_level () && show_top_level)
881 os <<
" --> top level" << std::endl;
886 octave_map stk = tw.backtrace (curr_frame,
false);
895 curr_frame -= num_skip;
896 curr_frame = (curr_frame < 0 ? 0 : curr_frame + 1);
898 retval =
ovl (stk, curr_frame);
912 do_dbstack (octave::__get_interpreter__ (),
916DEFMETHOD (dbstack, interp, args, nargout,
960 const std::string& who)
969 n = parse_integer_argument (arg.
string_value (), who.c_str ());
971 n = args(0).int_value ();
977 octave::tree_evaluator& tw = interp.get_evaluator ();
979 tw.dbupdown (n,
true);
992 do_dbupdown (interp, args,
"dbup");
1007 do_dbupdown (interp, args,
"dbdown");
1036 octave::tree_evaluator& tw = interp.get_evaluator ();
1038 if (! tw.in_debug_repl ())
1039 error (
"dbstep: can only be called in debug mode");
1041 int nargin = args.
length ();
1051 = args(0).xstring_value (
"dbstep: input argument must be a string");
1055 else if (arg ==
"out")
1059 n = parse_integer_argument (arg,
"dbstep");
1062 error (
"dbstep: N must be greater than zero");
1070 tw.set_dbstep_flag (n);
1073 tw.reset_debug_state ();
1089 octave::tree_evaluator& tw = interp.get_evaluator ();
1091 if (! tw.in_debug_repl ())
1092 error (
"dbcont: can only be called in debug mode");
1113 octave::tree_evaluator& tw = interp.get_evaluator ();
1115 if (! tw.in_debug_repl ())
1116 error (
"dbquit: can only be called in debug mode");
1118 int nargin = args.
length ();
1126 = args(0).xstring_value (
"dbquit: input argument must be a string");
1131 error (
"dbquit: unrecognized argument '%s'", arg.c_str ());
1149 octave::tree_evaluator& tw = interp.get_evaluator ();
1151 return ovl (tw.in_debug_repl ());
1154DEFMETHOD (__db_next_breakpoint_quiet__, interp, args, ,
1163 int nargin = args.
length ();
1171 state = args(0).bool_value ();
1173 octave::tree_evaluator& tw = interp.get_evaluator ();
1175 tw.quiet_breakpoint_flag (state);
1180OCTAVE_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)
T::size_type numel(const T &str)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
F77_RET_T const F77_DBLE const F77_DBLE * f