26 #if defined (HAVE_CONFIG_H)
55 {
"file",
"name",
"line",
"column",
nullptr };
60 : m_evaluator (evaluator), m_cs (), m_curr_frame (0),
61 m_max_stack_depth (1024), m_global_values ()
69 error (
"current_function: call stack is empty");
75 if (idx > 0 && skip_first)
80 fcn =
m_cs[idx]->function ();
98 retval = elt->line ();
111 retval = elt->column ();
125 const std::shared_ptr<stack_frame> elt =
m_cs[xframe];
129 if (
f &&
f->is_user_code ())
144 const std::shared_ptr<stack_frame> elt =
m_cs[xframe];
148 if (
f &&
f->is_user_code ())
150 int line = elt->line ();
168 const std::shared_ptr<stack_frame> elt =
m_cs[xframe];
172 if (
f &&
f->is_user_code ())
174 int column = elt->column ();
192 const std::shared_ptr<stack_frame> elt =
m_cs[xframe];
196 if (
f &&
f->is_user_code ())
197 return elt->unwind_protect_frame ();
215 const std::shared_ptr<stack_frame> elt =
m_cs[i--];
219 if (
f &&
f->is_user_code ())
241 const std::shared_ptr<stack_frame> elt =
m_cs[i--];
245 if (
f &&
f->is_user_code ())
249 retval = elt->line ();
271 const std::shared_ptr<stack_frame> elt =
m_cs[i--];
275 if (
f &&
f->is_user_code ())
279 retval = elt->column ();
304 bool retval = (
f &&
f->is_class_method ());
307 dispatch_class =
f->dispatch_class ();
318 bool retval = (
f &&
f->is_class_constructor ());
321 dispatch_class =
f->dispatch_class ();
330 auto p =
m_cs.cend ();
332 while (p !=
m_cs.cbegin ())
334 const std::shared_ptr<stack_frame> elt = *(--p);
338 if (
f && !
f->is_user_script ())
349 (std::size_t& new_frame_idx, std::shared_ptr<stack_frame>& parent_link,
350 std::shared_ptr<stack_frame>& static_link)
const
356 new_frame_idx =
m_cs.size ();
360 error (
"max_stack_depth exceeded");
365 if (new_frame_idx == 0)
368 parent_link =
m_cs[prev_frame_idx];
374 ? parent_link : parent_link->static_link ())
380 std::size_t new_frame_idx;
381 std::shared_ptr<stack_frame> parent_link;
382 std::shared_ptr<stack_frame> static_link;
386 std::shared_ptr<stack_frame>
388 parent_link, static_link));
390 m_cs.push_back (new_frame);
396 const std::shared_ptr<stack_frame>& closure_frames)
398 std::size_t new_frame_idx;
399 std::shared_ptr<stack_frame> parent_link;
400 std::shared_ptr<stack_frame> static_link;
404 std::shared_ptr<stack_frame>
406 parent_link, static_link,
409 m_cs.push_back (new_frame);
416 const std::shared_ptr<stack_frame>& closure_frames)
418 std::size_t new_frame_idx;
419 std::shared_ptr<stack_frame> parent_link;
420 std::shared_ptr<stack_frame> static_link;
424 std::shared_ptr<stack_frame>
426 parent_link, static_link, local_vars,
429 m_cs.push_back (new_frame);
436 std::size_t new_frame_idx;
437 std::shared_ptr<stack_frame> parent_link;
438 std::shared_ptr<stack_frame> static_link;
442 std::shared_ptr<stack_frame>
444 parent_link, static_link));
446 m_cs.push_back (new_frame);
453 std::size_t new_frame_idx;
454 std::shared_ptr<stack_frame> parent_link;
455 std::shared_ptr<stack_frame> static_link;
459 std::shared_ptr<stack_frame>
461 parent_link, static_link));
463 m_cs.push_back (new_frame);
472 if (
n <
m_cs.size ())
480 const std::shared_ptr<stack_frame> elt =
m_cs[
n];
493 std::shared_ptr<stack_frame> frm =
m_cs[user_frame];
495 if (! (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
496 || frm->is_scope_frame ()))
498 frm = frm->static_link ();
500 user_frame = frm->index ();
519 if (start >=
m_cs.size ())
520 error (
"invalid stack frame");
524 if (start == 0 &&
n < 0)
532 std::shared_ptr<stack_frame> frm =
m_cs[start];
534 if (! (frm && (frm->is_user_fcn_frame ()
535 || frm->is_user_script_frame ()
536 || frm->is_scope_frame ())))
537 error (
"call_stack::dbupdown: invalid initial frame in call stack!");
545 std::size_t xframe = frm->index ();
565 std::size_t last_good_frame = 0;
571 if (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
572 || frm->is_scope_frame ())
574 last_good_frame = xframe;
590 if (xframe ==
m_cs.size ())
597 return last_good_frame;
623 std::shared_ptr<stack_frame> caller_frame =
m_cs[start]->static_link ();
628 m_curr_frame = caller_frame ? caller_frame->index () : 0;
637 std::list<std::shared_ptr<stack_frame>>
640 std::list<std::shared_ptr<stack_frame>> frames;
651 for (std::size_t
n =
m_cs.size () - 1;
n > 0;
n--)
653 std::shared_ptr<stack_frame> frm =
m_cs[
n];
655 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
656 || frm->is_scope_frame ())
658 if (frm->index () == curr_frame)
659 curr_user_frame = frames.size ();
661 frames.push_back (frm);
671 std::list<std::shared_ptr<stack_frame>>
679 std::list<frame_info>
681 bool print_subfn)
const
683 std::list<std::shared_ptr<stack_frame>> frames
686 std::list<frame_info> retval;
688 for (
const auto& frm : frames)
690 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
691 || frm->is_scope_frame ())
693 retval.push_back (frame_info (frm->fcn_file_name (),
694 frm->fcn_name (print_subfn),
695 frm->line (), frm->column ()));
710 bool print_subfn)
const
712 std::list<std::shared_ptr<stack_frame>> frames
715 std::size_t nframes = frames.size ();
726 for (
const auto& frm : frames)
728 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
729 || frm->is_scope_frame ())
731 file(k) = frm->fcn_file_name ();
732 name(k) = frm->fcn_name (print_subfn);
733 line(k) = frm->line ();
734 column(k) = frm->
column ();
747 return backtrace (curr_user_frame,
true);
760 if (
m_cs.size () > 1)
762 std::shared_ptr<stack_frame> elt =
m_cs.back ();
764 std::shared_ptr<stack_frame> caller = elt->parent_link ();
768 if (elt->is_closure_context ())
769 elt->break_closure_cycles (elt);
777 while (!
m_cs.empty ())
788 std::list<std::string> retval;
792 if (nm_ov.second.is_defined ())
793 retval.push_back (nm_ov.first);
803 return m_cs[0]->variable_names ();
825 if (pat.
match (nm_ov.first))
866 return m_cs[0]->get_symbol_info ();
873 "max_stack_depth", 0);
900 return m_cs[0]->varval (name);
906 m_cs[0]->assign (name, value);
910 bool return_list,
bool verbose)
914 std::string my_name = argv[0];
916 std::string file_name;
918 bool from_file =
false;
919 bool global_only =
false;
920 bool have_regexp =
false;
925 if (argv[i] ==
"-file")
928 error (
"%s: -file option may only be specified once",
934 error (
"%s: -file argument must be followed by a filename",
937 file_name = argv[++i];
939 else if (argv[i] ==
"-regexp")
943 else if (argv[i] ==
"global")
945 else if (argv[i][0] ==
'-')
946 warning (
"%s: unrecognized option '%s'", my_name.c_str (),
954 int npatterns = argc - i;
958 patterns.
resize (npatterns);
959 for (
int j = 0; j < npatterns; j++)
960 patterns[j] = argv[i+j];
987 std::string newmsg =
"Variables in the file " + file_name +
":\n\n";
993 return do_who_two (patterns, have_regexp, return_list, verbose,
1002 return do_who_two (patterns, have_regexp, return_list, verbose);
1007 bool have_regexp,
bool return_list,
1008 bool verbose,
const std::string& msg)
1017 bool return_list,
bool verbose,
1018 const std::string& msg)
1021 std::list<std::string> symbol_names;
1027 std::string pattern = patterns[j];
1029 std::list<std::string> tmp;
1038 tmp.push_back (nm_ov.first);
1047 if (pat.
match (nm_ov.first))
1048 tmp.push_back (nm_ov.first);
1052 for (
const auto& nm : tmp)
1060 bool is_formal =
false;
1061 bool is_global =
true;
1062 bool is_persistent =
false;
1064 symbol_info syminf (nm, value, is_formal, is_global,
1067 symbol_stats.
append (syminf);
1070 symbol_names.push_back (nm);
1079 std::string caller_fcn_name;
1082 caller_fcn_name = caller_fcn->
name ();
1084 return symbol_stats.
map_value (caller_fcn_name, 1);
1089 else if (! (symbol_stats.
empty () && symbol_names.empty ()))
1116 std::size_t nframes =
size ();
1118 for (std::size_t i = 0; i < nframes; i++)
1120 m_cs[i]->display (
false);
1121 if (i < nframes - 1)
1137 DEFMETHOD (max_stack_depth, interp, args, nargout,
1207 int argc = args.length () + 1;
1213 return tw.
do_who (argc, argv, nargout == 1);
1295 int argc = args.length () + 1;
1301 return tw.
do_who (argc, argv, nargout == 1,
true);
static const octave_fields bt_fields(bt_fieldnames)
static const char * bt_fieldnames[]
Cell column(octave_idx_type i) const
void append(const elt_type &s)
void get_new_frame_index_and_links(std::size_t &new_frame_idx, std::shared_ptr< stack_frame > &parent_link, std::shared_ptr< stack_frame > &static_link) const
void set_dispatch_class(const std::string &class_name)
octave_value do_who(int argc, const string_vector &argv, bool return_list, bool verbose=false)
octave_value get_top_level_value(const std::string &name) const
std::map< std::string, octave_value > m_global_values
octave_value global_varval(const std::string &name) const
octave_map backtrace(void) const
octave_value & global_varref(const std::string &name)
octave_value do_who_two(const string_vector &patterns, bool have_regexp, bool return_list, bool verbose, const std::string &msg="")
void set_top_level_value(const std::string &name, const octave_value &value)
void goto_base_frame(void)
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
symbol_info_list top_scope_symbol_info(void) const
std::string get_dispatch_class(void) const
symbol_info_list regexp_symbol_info(const std::string &pattern) const
void make_global(const symbol_record &sym)
octave_user_code * current_user_code(void) const
int current_line(void) const
symbol_info_list get_symbol_info(void)
symbol_info_list glob_symbol_info(const std::string &pattern) const
bool is_class_method_executing(std::string &dispatch_class) const
bool goto_frame(std::size_t n=0, bool verbose=false)
bool all_scripts(void) const
void set_auto_fcn_var(stack_frame::auto_var_type avt, const octave_value &val)
int current_column(void) const
void clear_global_variables(void)
int current_user_code_line(void) const
std::list< std::string > variable_names(void) const
bool is_class_constructor_executing(std::string &dispatch_class) const
std::list< frame_info > backtrace_info(void) const
tree_evaluator & m_evaluator
octave_function * current_function(bool skip_first=false) const
int current_user_code_column(void) const
octave_value do_global_who_two(const string_vector &patterns, bool have_regexp, bool return_list, bool verbose, const std::string &msg="")
void clear_global_variable_pattern(const std::string &pattern)
octave_function * caller_function(void) const
std::shared_ptr< stack_frame > current_user_frame(void) const
call_stack(tree_evaluator &evaluator)
void push(const symbol_scope &scope)
octave_user_code * debug_user_code(void) const
std::list< std::string > top_level_variable_names(void) const
std::list< std::shared_ptr< stack_frame > > backtrace_frames(void) const
void clear_global_variable(const std::string &name)
std::size_t find_current_user_frame(void) const
std::list< std::string > global_variable_names(void) const
symbol_info_list all_variables(void)
int debug_user_code_line(void) const
std::size_t dbupdown(std::size_t start, int n, bool verbose)
std::size_t size(void) const
int debug_user_code_column(void) const
unwind_protect * curr_fcn_unwind_protect_frame(void)
void clear_global_variable_regexp(const std::string &pattern)
void goto_caller_frame(void)
octave_map empty_backtrace(void) const
void make_persistent(const symbol_record &sym)
octave_value max_stack_depth(const octave_value_list &args, int nargout)
Vector representing the dimensions (size) of an Array.
bool match(const std::string &str) const
virtual bool is_user_code(void) const
std::string name(void) const
const Cell & contents(const_iterator p) const
bool is_defined(void) const
bool is_match(const std::string &buffer) const
static stack_frame * create(tree_evaluator &tw, octave_function *fcn, std::size_t index, const std::shared_ptr< stack_frame > &parent_link, const std::shared_ptr< stack_frame > &static_link)
std::map< std::string, octave_value > local_vars_map
void resize(octave_idx_type n, const std::string &rfv="")
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix="") const
octave_idx_type numel(void) const
void display(std::ostream &os, const std::string &format) const
octave_map map_value(const std::string &caller_function_name, int nesting_level) const
octave_value do_who(int argc, const string_vector &argv, bool return_list, bool verbose=false)
octave_value max_stack_depth(const octave_value_list &args, int nargout)
octave_value whos_line_format(const octave_value_list &args, int nargout)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
void warning(const char *fmt,...)
void error(const char *fmt,...)
F77_RET_T const F77_DBLE const F77_DBLE * f
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)