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 ();
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 ())
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 ())
271 const std::shared_ptr<stack_frame> elt =
m_cs[i--];
275 if (
f &&
f->is_user_code ())
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 (
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 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 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);
417 size_t new_frame_idx;
418 std::shared_ptr<stack_frame> parent_link;
419 std::shared_ptr<stack_frame> static_link;
423 std::shared_ptr<stack_frame>
425 parent_link, static_link, local_vars));
427 m_cs.push_back (new_frame);
434 size_t new_frame_idx;
435 std::shared_ptr<stack_frame> parent_link;
436 std::shared_ptr<stack_frame> static_link;
440 std::shared_ptr<stack_frame>
442 parent_link, static_link));
444 m_cs.push_back (new_frame);
451 size_t new_frame_idx;
452 std::shared_ptr<stack_frame> parent_link;
453 std::shared_ptr<stack_frame> static_link;
457 std::shared_ptr<stack_frame>
459 parent_link, static_link));
461 m_cs.push_back (new_frame);
470 if (
n <
m_cs.size ())
478 const std::shared_ptr<stack_frame> elt =
m_cs[
n];
491 std::shared_ptr<stack_frame> frm =
m_cs[user_frame];
493 if (! (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
494 || frm->is_scope_frame ()))
496 frm = frm->static_link ();
498 user_frame = frm->index ();
517 if (start >=
m_cs.size ())
518 error (
"invalid stack frame");
522 if (start == 0 &&
n < 0)
530 std::shared_ptr<stack_frame> frm =
m_cs[start];
532 if (! (frm && (frm->is_user_fcn_frame ()
533 || frm->is_user_script_frame ()
534 || frm->is_scope_frame ())))
535 error (
"call_stack::dbupdown: invalid initial frame in call stack!");
543 size_t xframe = frm->index ();
563 size_t last_good_frame = 0;
569 if (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
570 || frm->is_scope_frame ())
572 last_good_frame = xframe;
588 if (xframe ==
m_cs.size ())
595 return last_good_frame;
621 std::shared_ptr<stack_frame> caller_frame =
m_cs[start]->static_link ();
626 m_curr_frame = caller_frame ? caller_frame->index () : 0;
635 std::list<std::shared_ptr<stack_frame>>
638 std::list<std::shared_ptr<stack_frame>> frames;
649 for (
size_t n =
m_cs.size () - 1;
n > 0;
n--)
651 std::shared_ptr<stack_frame> frm =
m_cs[
n];
653 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
654 || frm->is_scope_frame ())
656 if (frm->index () == curr_frame)
657 curr_user_frame = frames.size ();
659 frames.push_back (frm);
669 std::list<std::shared_ptr<stack_frame>>
677 std::list<frame_info>
679 bool print_subfn)
const
681 std::list<std::shared_ptr<stack_frame>> frames
684 std::list<frame_info>
retval;
686 for (
const auto& frm : frames)
688 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
689 || frm->is_scope_frame ())
691 retval.push_back (frame_info (frm->fcn_file_name (),
692 frm->fcn_name (print_subfn),
693 frm->line (), frm->column ()));
708 bool print_subfn)
const
710 std::list<std::shared_ptr<stack_frame>> frames
713 size_t nframes = frames.size ();
724 for (
const auto& frm : frames)
726 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
727 || frm->is_scope_frame ())
729 file(k) = frm->fcn_file_name ();
730 name(k) = frm->fcn_name (print_subfn);
732 column(k) = frm->
column ();
745 return backtrace (curr_user_frame,
true);
758 if (
m_cs.size () > 1)
760 std::shared_ptr<stack_frame> elt =
m_cs.back ();
762 std::shared_ptr<stack_frame> caller = elt->parent_link ();
772 while (!
m_cs.empty ())
783 std::list<std::string>
retval;
787 if (nm_ov.second.is_defined ())
788 retval.push_back (nm_ov.first);
798 return m_cs[0]->variable_names ();
820 if (pat.
match (nm_ov.first))
861 return m_cs[0]->get_symbol_info ();
868 "max_stack_depth", 0);
905 bool return_list,
bool verbose)
909 std::string my_name = argv[0];
911 std::string file_name;
913 bool from_file =
false;
914 bool global_only =
false;
915 bool have_regexp =
false;
920 if (argv[i] ==
"-file")
923 error (
"%s: -file option may only be specified once",
929 error (
"%s: -file argument must be followed by a filename",
932 file_name = argv[++i];
934 else if (argv[i] ==
"-regexp")
938 else if (argv[i] ==
"global")
940 else if (argv[i][0] ==
'-')
941 warning (
"%s: unrecognized option '%s'", my_name.c_str (),
949 int npatterns = argc - i;
953 patterns.
resize (npatterns);
954 for (
int j = 0; j < npatterns; j++)
955 patterns[j] = argv[i+j];
983 std::string newmsg =
"Variables in the file " + file_name +
":\n\n";
989 return do_who_two (patterns, have_regexp, return_list, verbose,
998 return do_who_two (patterns, have_regexp, return_list, verbose);
1003 bool have_regexp,
bool return_list,
1004 bool verbose,
const std::string& msg)
1013 bool return_list,
bool verbose,
1014 const std::string& msg)
1017 std::list<std::string> symbol_names;
1023 std::string pattern = patterns[j];
1025 std::list<std::string> tmp;
1034 tmp.push_back (nm_ov.first);
1043 if (pat.
match (nm_ov.first))
1044 tmp.push_back (nm_ov.first);
1048 for (
const auto& nm : tmp)
1056 bool is_formal =
false;
1057 bool is_global =
true;
1058 bool is_persistent =
false;
1060 symbol_info syminf (nm, value, is_formal, is_global,
1063 symbol_stats.
append (syminf);
1066 symbol_names.push_back (nm);
1075 std::string caller_fcn_name;
1078 caller_fcn_name = caller_fcn->
name ();
1080 return symbol_stats.
map_value (caller_fcn_name, 1);
1085 else if (! (symbol_stats.
empty () && symbol_names.empty ()))
1112 size_t nframes =
size ();
1114 for (
size_t i = 0; i < nframes; i++)
1116 m_cs[i]->display (
false);
1117 if (i < nframes - 1)
1134 DEFMETHOD (max_stack_depth, interp, args, nargout,
1204 int argc = args.length () + 1;
1210 return tw.
do_who (argc, argv, nargout == 1);
1292 int argc = args.length () + 1;
1298 return tw.
do_who (argc, argv, nargout == 1,
true);
Array< T > sort(int dim=0, sortmode mode=ASCENDING) const
Size of the specified dimension.
Array< T > column(octave_idx_type k) const
Extract column: A(:,k+1).
Cell column(octave_idx_type i) const
Vector representing the dimensions (size) of an Array.
bool match(const std::string &str) const
line(const graphics_handle &mh, const graphics_handle &p)
void add_method(T *obj, void(T::*method)(Params...), Args &&... args)
void append(const elt_type &s)
symbol_info_list glob_symbol_info(const std::string &pattern) const
void clear_global_variables(void)
std::string get_dispatch_class(void) const
octave_value global_varval(const std::string &name) const
bool goto_frame(size_t n=0, bool verbose=false)
bool is_class_constructor_executing(std::string &dispatch_class) const
void push(const symbol_scope &scope)
tree_evaluator & m_evaluator
void get_new_frame_index_and_links(size_t &new_frame_idx, std::shared_ptr< stack_frame > &parent_link, std::shared_ptr< stack_frame > &static_link) const
octave_user_code * current_user_code(void) const
std::map< std::string, octave_value > m_global_values
void goto_base_frame(void)
size_t dbupdown(size_t start, int n, bool verbose)
int current_user_code_line(void) const
void set_top_level_value(const std::string &name, const octave_value &value)
void make_persistent(const symbol_record &sym)
int current_line(void) const
bool all_scripts(void) const
std::list< std::string > global_variable_names(void) const
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
std::list< std::string > top_level_variable_names(void) const
symbol_info_list top_scope_symbol_info(void) const
void set_dispatch_class(const std::string &class_name)
std::list< std::shared_ptr< stack_frame > > backtrace_frames(void) const
void goto_caller_frame(void)
symbol_info_list regexp_symbol_info(const std::string &pattern) const
void set_auto_fcn_var(stack_frame::auto_var_type avt, const octave_value &val)
std::shared_ptr< stack_frame > current_user_frame(void) const
octave_value & global_varref(const std::string &name)
octave_user_code * debug_user_code(void) const
octave_map backtrace(void) const
void make_global(const symbol_record &sym)
unwind_protect * curr_fcn_unwind_protect_frame(void)
octave_value get_top_level_value(const std::string &name) const
octave_value do_global_who_two(const string_vector &patterns, bool have_regexp, bool return_list, bool verbose, const std::string &msg="")
symbol_info_list get_symbol_info(void)
int current_user_code_column(void) const
octave_function * caller_function(void) const
octave_value do_who(int argc, const string_vector &argv, bool return_list, bool verbose=false)
bool is_class_method_executing(std::string &dispatch_class) const
octave_map empty_backtrace(void) const
call_stack(tree_evaluator &evaluator)
std::list< frame_info > backtrace_info(void) const
std::list< std::string > variable_names(void) const
void clear_global_variable(const std::string &name)
void clear_global_variable_regexp(const std::string &pattern)
octave_value max_stack_depth(const octave_value_list &args, int nargout)
void clear_global_variable_pattern(const std::string &pattern)
int debug_user_code_column(void) const
int debug_user_code_line(void) const
octave_function * current_function(bool skip_first=false) const
size_t find_current_user_frame(void) const
int current_column(void) const
octave_value do_who_two(const string_vector &patterns, bool have_regexp, bool return_list, bool verbose, const std::string &msg="")
symbol_info_list all_variables(void)
bool is_match(const std::string &buffer)
static stack_frame * create(tree_evaluator &tw, octave_function *fcn, 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
octave_map map_value(const std::string &caller_function_name, int nesting_level) const
void display(std::ostream &os, const std::string &format) 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)
virtual bool is_user_code(void) const
std::string name(void) const
bool is_defined(void) const
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
#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,...)
static const char * bt_fieldnames[]
static const octave_fields bt_fields(bt_fieldnames)
static double f(double k, double l_nu, double c_pm)
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::octave_value(const Array< char > &chm, char type) return retval
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)