Mercurial > octave
diff libinterp/corefcn/stack-frame.cc @ 28793:c5953e65c6aa stable
track direct caller in stack frames
* stack-frame.h, stack-frame.cc (stack_frame::m_parent_link): New data
member to track direct parent, not just user-defined function, script,
or scope frames as m_static_link does.
(stack_frame::parent_link): New function.
(stack_frame::stack_frame): Accept parent_link argument. Change all uses.
(stack_frame::create): Accept parent_link argument. Change all uses.
* call-stack.cc (call_stack::pop): Set m_curr_frame to parent_link,
not static_link.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 25 Sep 2020 09:43:53 -0400 |
parents | c09bc9e108b5 |
children | 43ad651cf5a0 336356206de7 |
line wrap: on
line diff
--- a/libinterp/corefcn/stack-frame.cc Wed Sep 23 21:23:01 2020 +0200 +++ b/libinterp/corefcn/stack-frame.cc Fri Sep 25 09:43:53 2020 -0400 @@ -57,8 +57,10 @@ compiled_fcn_stack_frame (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) - : stack_frame (tw, index, static_link, static_link->access_link ()), + : stack_frame (tw, index, parent_link, static_link, + static_link->access_link ()), m_fcn (fcn) { } @@ -176,6 +178,7 @@ script_stack_frame (tree_evaluator& tw, octave_user_script *script, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link); script_stack_frame (const script_stack_frame& elt) = default; @@ -288,9 +291,10 @@ base_value_stack_frame (tree_evaluator& tw, size_t num_symbols, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link, const std::shared_ptr<stack_frame>& access_link) - : stack_frame (tw, index, static_link, access_link), + : stack_frame (tw, index, parent_link, static_link, access_link), m_values (num_symbols, octave_value ()), m_flags (num_symbols, LOCAL), m_auto_vars (NUM_AUTO_VARS, octave_value ()) @@ -393,9 +397,11 @@ user_fcn_stack_frame (tree_evaluator& tw, octave_user_function *fcn, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link, const std::shared_ptr<stack_frame>& access_link = std::shared_ptr<stack_frame> ()) - : base_value_stack_frame (tw, get_num_symbols (fcn), index, static_link, + : base_value_stack_frame (tw, get_num_symbols (fcn), index, + parent_link, static_link, (access_link ? access_link : get_access_link (fcn, static_link))), @@ -404,9 +410,11 @@ user_fcn_stack_frame (tree_evaluator& tw, octave_user_function *fcn, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link, const local_vars_map& local_vars) - : base_value_stack_frame (tw, get_num_symbols (fcn), index, static_link, + : base_value_stack_frame (tw, get_num_symbols (fcn), index, + parent_link, static_link, get_access_link (fcn, static_link)), m_fcn (fcn), m_unwind_protect_frame (nullptr) { @@ -495,9 +503,10 @@ scope_stack_frame (tree_evaluator& tw, const symbol_scope& scope, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link) : base_value_stack_frame (tw, scope.num_symbols (), index, - static_link, nullptr), + parent_link, static_link, nullptr), m_scope (scope) { } @@ -1024,40 +1033,45 @@ stack_frame * 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) { - return new compiled_fcn_stack_frame (tw, fcn, index, static_link); + return new compiled_fcn_stack_frame (tw, fcn, index, parent_link, static_link); } stack_frame * stack_frame::create (tree_evaluator& tw, octave_user_script *script, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link) { - return new script_stack_frame (tw, script, index, static_link); + return new script_stack_frame (tw, script, index, parent_link, static_link); } stack_frame * stack_frame::create (tree_evaluator& tw, octave_user_function *fcn, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link, const std::shared_ptr<stack_frame>& access_link) { - return new user_fcn_stack_frame (tw, fcn, index, static_link, access_link); + return new user_fcn_stack_frame (tw, fcn, index, parent_link, static_link, access_link); } stack_frame * stack_frame::create (tree_evaluator& tw, octave_user_function *fcn, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link, const local_vars_map& local_vars) { - return new user_fcn_stack_frame (tw, fcn, index, static_link, local_vars); + return new user_fcn_stack_frame (tw, fcn, index, parent_link, static_link, local_vars); } stack_frame * stack_frame::create (tree_evaluator& tw, const symbol_scope& scope, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link) { - return new scope_stack_frame (tw, scope, index, static_link); + return new scope_stack_frame (tw, scope, index, parent_link, static_link); } // This function is only implemented for user_fcn stack frames and @@ -1388,6 +1402,13 @@ os << "-- [stack_frame] (" << this << ") --" << std::endl; + os << "parent link: "; + if (m_parent_link) + os << m_parent_link.get (); + else + os << "NULL"; + os << std::endl; + os << "static link: "; if (m_static_link) os << m_static_link.get (); @@ -1441,8 +1462,10 @@ script_stack_frame::script_stack_frame (tree_evaluator& tw, octave_user_script *script, size_t index, + const std::shared_ptr<stack_frame>& parent_link, const std::shared_ptr<stack_frame>& static_link) - : stack_frame (tw, index, static_link, get_access_link (static_link)), + : stack_frame (tw, index, parent_link, static_link, + get_access_link (static_link)), m_script (script), m_unwind_protect_frame (nullptr), m_lexical_frame_offsets (get_num_symbols (script), 1), m_value_offsets (get_num_symbols (script), 0)