26 #if defined (HAVE_CONFIG_H)
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 retmap = bptab.add_breakpoints_in_function (symbol_name, class_name,
197 else if (args.length () != 1)
207 bptab.dbstop_process_map_args (mv);
219 error (
"dbstop: invalid 'bkpt' field");
228 error (
"dbstop: Cell array must contain fields 'name' and 'line'");
232 bool use_cond = mv.
isfield (
"cond");
236 std::string unconditional =
"";
239 lines.
insert (line(i).int_value ());
240 bptab.add_breakpoints_in_function (name(i).string_value (),
243 ? cond(i).string_value ()
251 tw.reset_debug_state ();
300 std::string symbol_name =
"";
301 std::string class_name =
"";
302 octave::bp_table::bp_lines lines;
305 octave::tree_evaluator& tw = interp.get_evaluator ();
307 octave::bp_table& bptab = tw.get_bp_table ();
309 bptab.parse_dbfunction_params (
"dbclear", args, symbol_name, class_name,
312 if (args.length () == 1 && symbol_name ==
"all")
314 bptab.remove_all_breakpoints ();
315 bptab.dbclear_all_signals ();
319 if (symbol_name !=
"")
320 bptab.remove_breakpoints_from_function (symbol_name, lines);
324 tw.reset_debug_state ();
329 DEFMETHOD (dbstatus, interp, args, nargout,
374 int nargin = args.length ();
376 if (nargin != 0 && nargin != 1)
377 error (
"dbstatus: only zero or one arguments accepted\n");
380 octave::bp_table::fname_bp_map bp_list;
381 std::string symbol_name;
383 octave::tree_evaluator& tw = interp.get_evaluator ();
385 octave::bp_table& bptab = tw.get_bp_table ();
389 if (! args(0).is_string ())
392 symbol_name = args(0).string_value ();
393 fcn_list(0) = symbol_name;
394 bp_list = bptab.get_breakpoint_list (fcn_list);
410 bp_list = bptab.get_breakpoint_list (fcn_list);
417 for (
auto& fnm_bp_p: bp_list)
419 std::list<octave::bp_type>
m = fnm_bp_p.second;
424 int have_unconditional = 0;
425 for (
const auto& bp :
m)
429 if (have_unconditional++)
434 if (have_unconditional)
436 const char *_s_ = (have_unconditional > 1) ?
"s" :
"";
437 octave_stdout <<
"breakpoint" << _s_ <<
" in " << fnm_bp_p.first
438 <<
" at line" << _s_ <<
' ';
440 for (
const auto& bp :
m)
449 for (
const auto& bp :
m)
453 <<
" at line " << bp.line
454 <<
" if " << bp.cond <<
"\n";
458 bptab.stop_on_err_warn_status (
true);
464 octave::help_system& help_sys = interp.get_help_system ();
473 for (
const auto& fnm_bp_p : bp_list)
474 count += fnm_bp_p.second.
size ();
481 for (
const auto& fnm_bp_p : bp_list)
483 std::string filename = fnm_bp_p.first;
484 const char *sub_fcn = strchr (filename.c_str (),
'>');
486 filename = filename.substr(0, sub_fcn - filename.c_str ());
491 for (
const auto& bp : fnm_bp_p.second)
493 names(i) = fnm_bp_p.first;
501 retmap.
assign (
"name", names);
502 retmap.
assign (
"file", file);
503 retmap.
assign (
"line", line);
504 retmap.
assign (
"cond", cond);
506 const octave_map ew = bptab.stop_on_err_warn_status (
false);
559 octave::tree_evaluator& tw = interp.get_evaluator ();
567 do_dbtype (std::ostream& os,
const std::string& name,
int start,
int end)
572 os <<
"dbtype: unknown function " << name <<
"\n";
578 os <<
"dbtype: unable to open '" << ff <<
"' for reading!\n";
584 while (std::getline (fs, text) && line <= end)
587 os << line <<
"\t" << text <<
"\n";
625 octave::tree_evaluator& tw = interp.get_evaluator ();
627 switch (args.length ())
630 dbg_fcn = tw.get_user_code ();
633 error (
"dbtype: must be inside a user function to give no arguments to dbtype\n");
642 std::string arg = argv[1];
644 std::size_t ind = arg.find (
':');
646 if (ind != std::string::npos)
648 dbg_fcn = tw.get_user_code ();
652 std::string start_str = arg.substr (0, ind);
653 std::string end_str = arg.substr (ind + 1);
656 start = atoi (start_str.c_str ());
657 if (end_str ==
"end")
660 end = atoi (end_str.c_str ());
663 error (
"dbtype: start and end lines must be >= 1\n");
666 error (
"dbtype: start line must be less than end line\n");
674 int line = atoi (arg.c_str ());
678 dbg_fcn = tw.get_user_code (arg);
681 error (
"dbtype: function <%s> not found\n", arg.c_str ());
689 error (
"dbtype: start and end lines must be >= 1\n");
691 dbg_fcn = tw.get_user_code ();
703 dbg_fcn = tw.get_user_code (argv[1]);
706 error (
"dbtype: function <%s> not found\n", argv[1].c_str ());
708 std::string arg = argv[2];
710 std::size_t ind = arg.find (
':');
712 if (ind != std::string::npos)
714 std::string start_str = arg.substr (0, ind);
715 std::string end_str = arg.substr (ind + 1);
717 start = atoi (start_str.c_str ());
718 if (end_str ==
"end")
721 end = atoi (end_str.c_str ());
725 start = atoi (arg.c_str ());
730 error (
"dbtype: start and end lines must be >= 1\n");
733 error (
"dbtype: start line must be less than end line\n");
740 error (
"dbtype: expecting zero, one, or two arguments\n");
759 if (args.length () == 1)
767 n = atoi (s_arg.c_str ());
770 n = args(0).int_value ();
773 error (
"dblist: N must be a non-negative integer");
776 octave::tree_evaluator& tw = interp.get_evaluator ();
781 error (
"dblist: must be inside a user function to use dblist\n");
783 bool have_file =
true;
790 name = dbg_fcn->
name ();
793 int l = tw.debug_user_code_line ();
813 octave_stdout <<
"dblist: unable to determine source code line"
822 int nargout, std::ostream& os)
824 int nargin = args.
length ();
835 if (nargin == 1 || nargin == 2)
848 if (s_arg ==
"-completenames")
851 n = atoi (s_arg.c_str ());
857 error (
"dbstack: N must be a non-negative integer");
864 octave::tree_evaluator& tw = interp.get_evaluator ();
873 octave::preserve_stream_state stream_state (os);
875 os <<
"stopped in:\n\n";
881 bool show_top_level =
true;
883 std::size_t max_name_len = 0;
887 std::string name = names(i).string_value ();
889 max_name_len =
std::max (name.length (), max_name_len);
894 std::string name = names(i).string_value ();
895 std::string file = files(i).string_value ();
896 int line = lines(i).int_value ();
898 if (show_top_level && i == curr_frame)
899 show_top_level =
false;
901 os << (i == curr_frame ?
" --> " :
" ")
902 << std::setw (max_name_len) << name
903 <<
" at line " << line
904 <<
" [" << file <<
']'
908 if (tw.at_top_level () && show_top_level)
909 os <<
" --> top level" << std::endl;
914 octave_map stk = tw.backtrace (curr_frame,
false);
923 curr_frame -= num_skip;
924 curr_frame = (curr_frame < 0 ? 0 : curr_frame + 1);
926 retval =
ovl (stk, curr_frame);
944 DEFMETHOD (dbstack, interp, args, nargout,
988 const std::string& who)
1000 n = atoi (s_arg.c_str ());
1003 n = args(0).int_value ();
1009 octave::tree_evaluator& tw = interp.get_evaluator ();
1011 tw.dbupdown (
n,
true);
1067 octave::tree_evaluator& tw = interp.get_evaluator ();
1069 if (! tw.in_debug_repl ())
1070 error (
"dbstep: can only be called in debug mode");
1072 int nargin = args.length ();
1082 = args(0).xstring_value (
"dbstep: input argument must be a string");
1086 else if (arg ==
"out")
1090 n = atoi (arg.c_str ());
1093 error (
"dbstep: invalid argument");
1101 tw.set_dbstep_flag (
n);
1104 tw.reset_debug_state ();
1120 octave::tree_evaluator& tw = interp.get_evaluator ();
1122 if (! tw.in_debug_repl ())
1123 error (
"dbcont: can only be called in debug mode");
1125 if (args.length () != 0)
1143 octave::tree_evaluator& tw = interp.get_evaluator ();
1145 if (! tw.in_debug_repl ())
1146 error (
"dbquit: can only be called in debug mode");
1148 int nargin = args.length ();
1156 = args(0).xstring_value (
"dbquit: input argument must be a string");
1161 error (
"dbquit: unrecognized argument '%s'", arg.c_str ());
1176 if (args.length () != 0)
1179 octave::tree_evaluator& tw = interp.get_evaluator ();
1181 return ovl (tw.in_debug_repl ());
1184 DEFMETHOD (__db_next_breakpoint_quiet__, interp, args, ,
1193 int nargin = args.length ();
1201 state = args(0).bool_value ();
1203 octave::tree_evaluator& tw = interp.get_evaluator ();
1205 tw.quiet_breakpoint_flag (
state);
charNDArray max(char d, const charNDArray &m)
charNDArray min(char d, const charNDArray &m)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Cell & insert(const Cell &a, octave_idx_type r, octave_idx_type c)
Vector representing the dimensions (size) of an Array.
std::string name(void) const
Cell getfield(const std::string &key) 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(void) const
void assign(const std::string &k, const Cell &val)
const_iterator begin(void) const
const_iterator end(void) const
const Cell & contents(const_iterator p) const
std::string fcn_file_name(void) const
std::string get_code_line(std::size_t line)
octave_idx_type length(void) const
int int_value(bool req_int=false, bool frc_str_conv=false) const
bool is_string(void) const
Cell cell_value(void) const
std::string string_value(bool force=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
static octave_value_list do_dbstack(octave::interpreter &interp, const octave_value_list &args, int nargout, std::ostream &os)
void show_octave_dbstack(void)
static void do_dbtype(std::ostream &os, const std::string &name, int start, int end)
static void do_dbupdown(octave::interpreter &interp, const octave_value_list &args, const std::string &who)
static octave_value bp_lines_to_ov(const octave::bp_table::bp_lines &lines)
OCTINTERP_API void print_usage(void)
#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)
std::string canonicalize_file_name(const std::string &name)
octave::idx_vector idx_vector
interpreter & __get_interpreter__(void)
F77_RET_T const F77_DBLE const F77_DBLE * f
std::ifstream ifstream(const std::string &filename, const std::ios::openmode mode)
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.
static uint32_t state[624]
std::string fcn_file_in_path(const std::string &name)