26 #if defined (HAVE_CONFIG_H)
65 bp_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 ();
344 DEFMETHOD (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 ());
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);
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 ();
596 do_dbtype (std::ostream& os,
const std::string& name,
int start,
int end)
601 os <<
"dbtype: unknown function " << name <<
"\n";
607 os <<
"dbtype: unable to open '" << ff <<
"' for reading!\n";
613 while (std::getline (fs,
text) &&
line <= end)
654 octave::tree_evaluator& tw = interp.get_evaluator ();
656 switch (args.length ())
659 dbg_fcn = tw.get_user_code ();
662 error (
"dbtype: must be inside a user function to give no arguments to dbtype\n");
671 std::string arg = argv[1];
673 std::size_t ind = arg.find (
':');
675 if (ind != std::string::npos)
677 dbg_fcn = tw.get_user_code ();
681 std::string start_str = arg.substr (0, ind);
682 std::string end_str = arg.substr (ind + 1);
685 start = atoi (start_str.c_str ());
686 if (end_str ==
"end")
689 end = atoi (end_str.c_str ());
692 error (
"dbtype: start and end lines must be >= 1\n");
695 error (
"dbtype: start line must be less than end line\n");
703 int line = atoi (arg.c_str ());
707 dbg_fcn = tw.get_user_code (arg);
710 error (
"dbtype: function <%s> not found\n", arg.c_str ());
718 error (
"dbtype: start and end lines must be >= 1\n");
720 dbg_fcn = tw.get_user_code ();
732 dbg_fcn = tw.get_user_code (argv[1]);
735 error (
"dbtype: function <%s> not found\n", argv[1].c_str ());
737 std::string arg = argv[2];
739 std::size_t ind = arg.find (
':');
741 if (ind != std::string::npos)
743 std::string start_str = arg.substr (0, ind);
744 std::string end_str = arg.substr (ind + 1);
746 start = atoi (start_str.c_str ());
747 if (end_str ==
"end")
750 end = atoi (end_str.c_str ());
754 start = atoi (arg.c_str ());
759 error (
"dbtype: start and end lines must be >= 1\n");
762 error (
"dbtype: start line must be less than end line\n");
769 error (
"dbtype: expecting zero, one, or two arguments\n");
788 if (args.length () == 1)
796 n = atoi (s_arg.c_str ());
799 n = args(0).int_value ();
802 error (
"dblist: N must be a non-negative integer");
805 octave::tree_evaluator& tw = interp.get_evaluator ();
810 error (
"dblist: must be inside a user function to use dblist\n");
812 bool have_file =
true;
819 name = dbg_fcn->
name ();
822 int l = tw.debug_user_code_line ();
842 octave_stdout <<
"dblist: unable to determine source code line"
851 int nargout, std::ostream& os)
853 int nargin = args.
length ();
864 if (nargin == 1 || nargin == 2)
877 if (s_arg ==
"-completenames")
880 n = atoi (s_arg.c_str ());
886 error (
"dbstack: N must be a non-negative integer");
893 octave::tree_evaluator& tw = interp.get_evaluator ();
902 octave::preserve_stream_state stream_state (os);
904 os <<
"stopped in:\n\n";
910 bool show_top_level =
true;
912 std::size_t max_name_len = 0;
916 std::string name = names(i).string_value ();
918 max_name_len =
std::max (name.length (), max_name_len);
923 std::string name = names(i).string_value ();
924 std::string file = files(i).string_value ();
925 int line = lines(i).int_value ();
927 if (show_top_level && i == curr_frame)
928 show_top_level =
false;
930 os << (i == curr_frame ?
" --> " :
" ")
931 << std::setw (max_name_len) << name
932 <<
" at line " <<
line
933 <<
" [" << file <<
']'
937 if (tw.at_top_level () && show_top_level)
938 os <<
" --> top level" << std::endl;
943 octave_map stk = tw.backtrace (curr_frame,
false);
952 curr_frame -= num_skip;
953 curr_frame = (curr_frame < 0 ? 0 : curr_frame + 1);
955 retval =
ovl (stk, curr_frame);
973 DEFMETHOD (dbstack, interp, args, nargout,
1017 const std::string& who)
1029 n = atoi (s_arg.c_str ());
1032 n = args(0).int_value ();
1038 octave::tree_evaluator& tw = interp.get_evaluator ();
1040 tw.dbupdown (
n,
true);
1053 do_dbupdown (interp, args,
"dbup");
1068 do_dbupdown (interp, args,
"dbdown");
1097 octave::tree_evaluator& tw = interp.get_evaluator ();
1099 if (! tw.in_debug_repl ())
1100 error (
"dbstep: can only be called in debug mode");
1102 int nargin = args.
length ();
1112 = args(0).xstring_value (
"dbstep: input argument must be a string");
1116 else if (arg ==
"out")
1120 n = atoi (arg.c_str ());
1123 error (
"dbstep: invalid argument");
1131 tw.set_dbstep_flag (
n);
1134 tw.reset_debug_state ();
1150 octave::tree_evaluator& tw = interp.get_evaluator ();
1152 if (! tw.in_debug_repl ())
1153 error (
"dbcont: can only be called in debug mode");
1174 octave::tree_evaluator& tw = interp.get_evaluator ();
1176 if (! tw.in_debug_repl ())
1177 error (
"dbquit: can only be called in debug mode");
1179 int nargin = args.
length ();
1187 = args(0).xstring_value (
"dbquit: input argument must be a string");
1192 error (
"dbquit: unrecognized argument '%s'", arg.c_str ());
1210 octave::tree_evaluator& tw = interp.get_evaluator ();
1212 return ovl (tw.in_debug_repl ());
1215 DEFMETHOD (__db_next_breakpoint_quiet__, interp, args, ,
1224 int nargin = args.
length ();
1232 state = args(0).bool_value ();
1234 octave::tree_evaluator& tw = interp.get_evaluator ();
1236 tw.quiet_breakpoint_flag (state);
1241 OCTAVE_END_NAMESPACE(
octave)
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
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
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
const Cell & contents(const_iterator p) const
std::string get_code_line(std::size_t line)
std::string fcn_file_name() 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)
octave::idx_vector idx_vector
interpreter & __get_interpreter__()
F77_RET_T const F77_DBLE const F77_DBLE * f
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
std::string canonicalize_file_name(const std::string &name)
std::string fcn_file_in_path(const std::string &name)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.