annotate libinterp/corefcn/call-stack.cc @ 28425:a5be4fc661d6 stable

hide specific stack frame and stack frame walker classes * stack-frame.h, stack-frame.cc (compiled_fcn_stack_frame, script_stack_frame, user_fcn_stack_frame, scope_stack_frame): Move class declarations from header to source file. (stack_frame::create): New static member functions that can create specific stack frame types and return pointers to generic stack_frame objects. (stack_frame::who): New function. * call-stack.cc (call_stack::push): Use new stack_frame::create methods instead of creating specific stack frame objects. (call_stack::do_who_two): Simply forward to stack_frame::who method. * stack-frame-walker.h, syminfo-accumulator.h: Delete. Move class declarations and definitions to stack-frame.cc. * libinterp/corefcn/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Fri, 24 Apr 2020 14:21:07 -0400
parents 5cb09ac94e81
children 9a3deb17b4ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 1995-2020 The Octave Project Developers
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
30 #include <iostream>
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
31
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
32 #include "lo-regexp.h"
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
33 #include "str-vec.h"
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
34
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "call-stack.h"
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
36 #include "defun.h"
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
37 #include "interpreter.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
38 #include "interpreter-private.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "oct-map.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "ov.h"
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "ov-fcn.h"
22253
dbf7fd79e391 More informative messages for errors in anonymous functions (bug #46136).
Olaf Till <olaf.till@uni-jena.de>
parents: 22091
diff changeset
42 #include "ov-fcn-handle.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "ov-usr-fcn.h"
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
44 #include "pager.h"
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
45 #include "parse.h"
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
46 #include "stack-frame.h"
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
47 #include "syminfo.h"
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
48 #include "symrec.h"
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
49 #include "symscope.h"
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
50 #include "variables.h"
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
52 namespace octave
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 {
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
54 // Use static fields for the best efficiency.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
55 // NOTE: C++0x will allow these two to be merged into one.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
56 static const char *bt_fieldnames[] =
27470
96d4094585da eliminate unused backtrace field name "scope"
John W. Eaton <jwe@octave.org>
parents: 27211
diff changeset
57 { "file", "name", "line", "column", nullptr };
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
58
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
59 static const octave_fields bt_fields (bt_fieldnames);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27071
diff changeset
60
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
61 call_stack::call_stack (tree_evaluator& evaluator)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
62 : m_evaluator (evaluator), m_cs (), m_curr_frame (0),
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
63 m_max_stack_depth (1024), m_global_values ()
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
64 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
65 push (symbol_scope ("top scope"));
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
66 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
68 octave_function * call_stack::current_function (bool skip_first) const
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
69 {
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
70 if (m_cs.empty ())
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
71 error ("current_function: call stack is empty");
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
72
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
73 octave_function *fcn = nullptr;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
74
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
75 size_t idx = size ();
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
76
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
77 if (idx > 1 && skip_first)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
78 --idx;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
79
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
80 while (--idx)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
81 {
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
82 fcn = m_cs[idx]->function ();
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
83
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
84 if (fcn)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
85 break;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
86 }
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
87
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
88 return fcn;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
89 }
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
90
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
91 int call_stack::current_line (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
92 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
93 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
95 if (! m_cs.empty ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
96 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
97 const stack_frame *elt = m_cs[m_curr_frame];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
98 retval = elt->line ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
99 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
100
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
101 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
102 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
103
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
104 int call_stack::current_column (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
105 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
106 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
108 if (! m_cs.empty ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
109 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
110 const stack_frame *elt = m_cs[m_curr_frame];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
111 retval = elt->column ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
112 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
113
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
114 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
115 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
116
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
117 octave_user_code * call_stack::current_user_code (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
118 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
119 // Start at current frame.
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
120
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
121 size_t xframe = find_current_user_frame ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
123 if (xframe > 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
124 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
125 const stack_frame *elt = m_cs[xframe];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
126
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
127 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
129 if (f && f->is_user_code ())
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
130 return dynamic_cast<octave_user_code *> (f);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
131 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
132
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
133 return nullptr;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
134 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
135
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
136 int call_stack::current_user_code_line (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
137 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
138 // Start at current frame.
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
139
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
140 size_t xframe = find_current_user_frame ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
142 if (xframe > 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
143 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
144 const stack_frame *elt = m_cs[xframe];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
145
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
146 octave_function *f = elt->function ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
147
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
148 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
149 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
150 int line = elt->line ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
151
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
152 if (line > 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
153 return line;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
154 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
155 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
157 return -1;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
158 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
159
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
160 int call_stack::current_user_code_column (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
161 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
162 // Start at current frame.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
163
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
164 size_t xframe = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
165
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
166 if (xframe > 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
167 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
168 const stack_frame *elt = m_cs[xframe];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
169
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
170 octave_function *f = elt->function ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
171
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
172 if (f && f->is_user_code ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
173 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
174 int column = elt->column ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
175
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
176 if (column > 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
177 return column;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
178 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
179 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
180
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
181 return -1;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
182 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
183
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
184 unwind_protect * call_stack::curr_fcn_unwind_protect_frame (void) const
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
185 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
186 // Start at current frame.
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
187
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
188 size_t xframe = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
189
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
190 if (xframe > 0)
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
191 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
192 const stack_frame *elt = m_cs[xframe];
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
193
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
194 octave_function *f = elt->function ();
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
195
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
196 if (f && f->is_user_code ())
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
197 return elt->unwind_protect_frame ();
25399
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
198 }
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
199
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
200 return nullptr;
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
201 }
6ca2c0d76d84 store unwind protect frame for function evaluation in call_stack object
John W. Eaton <jwe@octave.org>
parents: 25343
diff changeset
202
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
203 octave_user_code * call_stack::debug_user_code (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
204 {
23457
21baad6b35c4 maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents: 23450
diff changeset
205 octave_user_code *retval = nullptr;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
207 // This should never happen...
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
208 if (m_curr_frame == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
209 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
210
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
211 size_t i = m_curr_frame;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
213 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
214 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
215 const stack_frame *elt = m_cs[i--];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
216
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
217 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
219 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
220 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
221 retval = dynamic_cast<octave_user_code *> (f);
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
222 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
223 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
224 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
226 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
227 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
228
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
229 int call_stack::debug_user_code_line (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
230 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
231 int retval = -1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
232
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
233 // This should never happen...
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
234 if (m_curr_frame == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
235 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
236
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
237 size_t i = m_curr_frame;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
238
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
239 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
240 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
241 const stack_frame *elt = m_cs[i--];
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
243 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
245 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
246 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
247 if (elt->line ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
248 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
249 retval = elt->line ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
250 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
251 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
252 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
253 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
255 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
256 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
257
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
258 int call_stack::debug_user_code_column (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
259 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
260 int retval = -1;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
262 // This should never happen...
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
263 if (m_curr_frame == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
264 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
265
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
266 // Start looking with the caller of the calling debug function.
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
267 size_t i = m_curr_frame;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
268
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
269 while (i != 0)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
270 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
271 const stack_frame *elt = m_cs[i--];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
272
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
273 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
275 if (f && f->is_user_code ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
276 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
277 if (elt->column ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
278 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
279 retval = elt->column ();
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
280 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
281 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
282 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
283 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
285 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
286 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
287
26965
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
288 std::string call_stack::get_dispatch_class (void) const
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
289 {
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
290 return m_cs[m_curr_frame]->get_dispatch_class ();
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
291 }
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
292
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
293 void call_stack::set_dispatch_class (const std::string& class_name)
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
294 {
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
295 m_cs[m_curr_frame]->set_dispatch_class (class_name);
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
296 }
be5c2a1bad93 allow dispatch class to be stored in stack frame (bug #45351)
John W. Eaton <jwe@octave.org>
parents: 26825
diff changeset
297
26795
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
298 bool call_stack::is_class_method_executing (std::string& dispatch_class) const
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
299 {
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
300 dispatch_class = "";
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
301
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
302 octave_function *f = current_function ();
26795
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
303
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
304 bool retval = (f && f->is_class_method ());
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
305
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
306 if (retval)
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
307 dispatch_class = f->dispatch_class ();
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
308
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
309 return retval;
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
310 }
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
311
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
312 bool call_stack::is_class_constructor_executing (std::string& dispatch_class) const
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
313 {
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
314 dispatch_class = "";
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
315
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
316 octave_function *f = current_function ();
26795
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
317
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
318 bool retval = (f && f->is_class_constructor ());
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
319
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
320 if (retval)
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
321 dispatch_class = f->dispatch_class ();
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
322
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
323 return retval;
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
324 }
80f9bc7cdf74 new functions for checking whether constructor or method is executing
John W. Eaton <jwe@octave.org>
parents: 26698
diff changeset
325
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
326 bool call_stack::all_scripts (void) const
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
327 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
328 bool retval = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
329
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
330 auto p = m_cs.cend ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
331
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
332 while (p != m_cs.cbegin ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
333 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
334 const stack_frame *elt = *(--p);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
335
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
336 octave_function *f = elt->function ();
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
337
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
338 if (f && ! f->is_user_script ())
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
339 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
340 retval = false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
341 break;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
342 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
343 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
345 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
346 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
348 stack_frame * call_stack::get_static_link (size_t prev_frame) const
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
349 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
350 // FIXME: is there a better way?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
351
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
352 stack_frame *slink = nullptr;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
353
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
354 if (m_curr_frame > 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
355 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
356 octave_function *t_fcn = m_cs[prev_frame]->function ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
357
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
358 slink = (t_fcn
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
359 ? (t_fcn->is_user_code ()
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
360 ? m_cs[prev_frame] : m_cs[prev_frame]->static_link ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
361 : m_cs[prev_frame]);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
362 }
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
363
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
364 return slink;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
365 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
366
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
367 void call_stack::push (const symbol_scope& scope)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
368 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
369 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
370 m_curr_frame = m_cs.size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
371
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
372 // m_max_stack_depth should never be less than zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
373 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
374 error ("max_stack_depth exceeded");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
375
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
376 stack_frame *slink = get_static_link (prev_frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
377
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
378 stack_frame *new_frame
28425
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
379 = stack_frame::create (m_evaluator, scope, m_curr_frame, slink);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
380
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
381 m_cs.push_back (new_frame);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
382 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
383
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26795
diff changeset
384 void call_stack::push (octave_user_function *fcn, unwind_protect *up_frame,
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26795
diff changeset
385 stack_frame *closure_frames)
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
386 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
387 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
388 m_curr_frame = m_cs.size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
389
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
390 // m_max_stack_depth should never be less than zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
391 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
392 error ("max_stack_depth exceeded");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
393
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
394 stack_frame *slink = get_static_link (prev_frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
395
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
396 stack_frame *new_frame
28425
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
397 = stack_frame::create (m_evaluator, fcn, up_frame, m_curr_frame,
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
398 slink, closure_frames);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
399
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
400 m_cs.push_back (new_frame);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
401 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
402
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
403 void call_stack::push (octave_user_script *script, unwind_protect *up_frame)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
404 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
405 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
406 m_curr_frame = m_cs.size ();
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
407
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
408 // m_max_stack_depth should never be less than zero.
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
409 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
410 error ("max_stack_depth exceeded");
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
411
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
412 stack_frame *slink = get_static_link (prev_frame);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
413
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
414 stack_frame *new_frame
28425
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
415 = stack_frame::create (m_evaluator, script, up_frame, m_curr_frame,
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
416 slink);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
417
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
418 m_cs.push_back (new_frame);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
419 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
420
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
421 void call_stack::push (octave_function *fcn)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
422 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
423 size_t prev_frame = m_curr_frame;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
424 m_curr_frame = m_cs.size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
425
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
426 // m_max_stack_depth should never be less than zero.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
427 if (m_curr_frame > static_cast<size_t> (m_max_stack_depth))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
428 error ("max_stack_depth exceeded");
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
429
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
430 stack_frame *slink = get_static_link (prev_frame);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
431
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
432 stack_frame *new_frame
28425
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
433 = stack_frame::create (m_evaluator, fcn, m_curr_frame, slink);
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
434
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
435 m_cs.push_back (new_frame);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
436 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
437
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
438 bool call_stack::goto_frame (size_t n, bool verbose)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
439 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
440 bool retval = false;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
441
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
442 if (n < m_cs.size ())
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
443 {
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
444 retval = true;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
445
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
446 m_curr_frame = n;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
447
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
448 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
449 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
450 const stack_frame *elt = m_cs[n];
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
451
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
452 elt->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
453 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
454 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
455
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
456 return retval;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
457 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
458
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
459 size_t call_stack::find_current_user_frame (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
460 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
461 size_t user_frame = m_curr_frame;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
462
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
463 stack_frame *frm = m_cs[user_frame];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
464
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
465 if (! (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
466 || frm->is_scope_frame ()))
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
467 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
468 frm = frm->static_link ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
469
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
470 user_frame = frm->index ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
471 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
472
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
473 return user_frame;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
474 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
475
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
476 stack_frame *call_stack::current_user_frame (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
477 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
478 size_t frame = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
479
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
480 return m_cs[frame];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
481 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
482
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
483 // Go to the Nth frame (up if N is negative or down if positive) in
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
484 // the call stack that corresponds to a script, function, or scope
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
485 // beginning with the frame indexed by START.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
486
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
487 size_t call_stack::dbupdown (size_t start, int n, bool verbose)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
488 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
489 if (start >= m_cs.size ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
490 error ("invalid stack frame");
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
491
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
492 // Can't go up from here.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
493
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
494 if (start == 0 && n < 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
495 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
496 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
497 m_cs[start]->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
498
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
499 return start;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
500 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
501
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
502 stack_frame *frm = m_cs[start];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
503
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
504 if (! (frm && (frm->is_user_fcn_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
505 || frm->is_user_script_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
506 || frm->is_scope_frame ())))
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
507 error ("call_stack::dbupdown: invalid initial frame in call stack!");
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
508
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
509 // Use index into the call stack to begin the search. At this point
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
510 // we iterate up or down using indexing instead of static links
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
511 // because ... FIXME: it's a bit complicated, but deserves
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
512 // explanation. May be easiest with some pictures of the call stack
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
513 // for an example or two.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
514
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
515 size_t xframe = frm->index ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
516
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
517 if (n == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
518 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
519 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
520 frm->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
521
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
522 return xframe;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
523 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
524
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
525 int incr = 0;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
526
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
527 if (n < 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
528 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
529 incr = -1;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
530 n = -n;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
531 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
532 else if (n > 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
533 incr = 1;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
534
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
535 size_t last_good_frame = 0;
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
537 while (true)
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
538 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
539 frm = m_cs[xframe];
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
540
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
541 if (frm->is_user_fcn_frame () || frm->is_user_script_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
542 || frm->is_scope_frame ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
543 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
544 last_good_frame = xframe;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
545
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
546 if (n == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
547 break;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
548
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
549 n--;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
550 }
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
551
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
552 xframe += incr;
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
553
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
554 if (xframe == 0)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
555 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
556 last_good_frame = 0;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
557 break;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
558 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
560 if (xframe == m_cs.size ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
561 break;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
562 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
563
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
564 if (verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
565 m_cs[last_good_frame]->display_stopped_in_message (octave_stdout);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
566
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
567 return last_good_frame;
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
568 }
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
569
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
570 // Like dbupdown above but find the starting frame automatically from
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
571 // the current frame. If the current frame is already a user
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
572 // function, script, or scope frame, use that. Otherwise, follow
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
573 // the static link for the current frame. If that is not a user
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
574 // function, script or scope frame then there is an error in the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
575 // implementation.
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
576
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
577 size_t call_stack::dbupdown (int n, bool verbose)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
578 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
579 size_t start = find_current_user_frame ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
580
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
581 return dbupdown (start, n, verbose);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
582 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
583
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
584 // May be used to temporarily change the value ov m_curr_frame inside
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
585 // a function like evalin. If used in a function like dbup, the new
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
586 // value of m_curr_frame would be wiped out when dbup returns and the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
587 // stack frame for dbup is popped.
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
588
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
589 void call_stack::goto_caller_frame (void)
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
590 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
591 size_t start = find_current_user_frame ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
592
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
593 // FIXME: is this supposed to be an error?
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
594 if (start == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
595 error ("already at top level");
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
596
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
597 m_curr_frame = dbupdown (start, -1, false);
23052
f97e22a9012a move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22862
diff changeset
598 }
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
599
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
600 void call_stack::goto_base_frame (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
601 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
602 if (m_curr_frame > 0)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
603 m_curr_frame = 0;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
604 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
605
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
606 std::list<stack_frame *>
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
607 call_stack::backtrace_frames (octave_idx_type& curr_user_frame) const
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
608 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
609 std::list<stack_frame *> frames;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
610
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
611 // curr_frame is the index to the current frame in the overall call
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
612 // stack, which includes any compiled function frames and scope
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
613 // frames. The curr_user_frame value we set is the index into the
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
614 // subset of frames returned in the octave_map object.
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
615
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
616 size_t curr_frame = find_current_user_frame ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
617
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
618 // Don't include top-level stack frame in the list.
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
619
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
620 for (size_t n = m_cs.size () - 1; n > 0; n--)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
621 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
622 stack_frame *frm = m_cs[n];
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
623
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
624 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
625 || frm->is_scope_frame ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
626 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
627 if (frm->index () == curr_frame)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
628 curr_user_frame = frames.size ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
629
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
630 frames.push_back (frm);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
631 }
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
632
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
633 if (n == 0)
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
634 break;
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
635 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
636
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
637 return frames;
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
638 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
639
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
640 std::list<stack_frame *>
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
641 call_stack::backtrace_frames (void) const
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
642 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
643 octave_idx_type curr_user_frame = -1;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
644
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
645 return backtrace_frames (curr_user_frame);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
646 }
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
647
27471
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
648 std::list<frame_info>
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
649 call_stack::backtrace_info (octave_idx_type& curr_user_frame,
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
650 bool print_subfn) const
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
651 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
652 std::list<stack_frame *> frames = backtrace_frames (curr_user_frame);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
653
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
654 std::list<frame_info> retval;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
655
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
656 for (const auto *frm : frames)
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
657 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
658 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
659 || frm->is_scope_frame ())
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
660 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
661 retval.push_back (frame_info (frm->fcn_file_name (),
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
662 frm->fcn_name (print_subfn),
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
663 frm->line (), frm->column ()));
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
664 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
665 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
666
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
667 return retval;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
668 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
669
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
670 std::list<frame_info> call_stack::backtrace_info (void) const
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
671 {
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
672 octave_idx_type curr_user_frame = -1;
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
673
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
674 return backtrace_info (curr_user_frame, true);
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
675 }
fd32c1a9b1bd revamp error handling
John W. Eaton <jwe@octave.org>
parents: 27470
diff changeset
676
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
677 octave_map call_stack::backtrace (octave_idx_type& curr_user_frame,
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
678 bool print_subfn) const
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
679 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
680 std::list<stack_frame *> frames = backtrace_frames (curr_user_frame);
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
681
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
682 size_t nframes = frames.size ();
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
683
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
684 octave_map retval (dim_vector (nframes, 1), bt_fields);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
685
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
686 Cell& file = retval.contents (0);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
687 Cell& name = retval.contents (1);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
688 Cell& line = retval.contents (2);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
689 Cell& column = retval.contents (3);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
690
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
691 octave_idx_type k = 0;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
692
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
693 for (const auto *frm : frames)
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
694 {
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
695 if (frm->is_user_script_frame () || frm->is_user_fcn_frame ()
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
696 || frm->is_scope_frame ())
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
697 {
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
698 file(k) = frm->fcn_file_name ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
699 name(k) = frm->fcn_name (print_subfn);
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
700 line(k) = frm->line ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
701 column(k) = frm->column ();
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
702
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
703 k++;
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
704 }
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
705 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
706
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
707 return retval;
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
708 }
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
709
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
710 octave_map call_stack::backtrace (void) const
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
711 {
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
712 octave_idx_type curr_user_frame = -1;
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
713
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
714 return backtrace (curr_user_frame, true);
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
715 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
716
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
717 octave_map call_stack::empty_backtrace (void) const
23553
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
718 {
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
719 return octave_map (dim_vector (0, 1), bt_fields);
14723784b9f2 don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
720 }
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
721
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
722 void call_stack::pop (void)
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
723 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
724 // Never pop top scope.
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
725 // FIXME: is it possible for this case to happen?
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
726
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
727 if (m_cs.size () > 1)
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
728 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
729 stack_frame *elt = m_cs.back ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
730
27037
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
731 stack_frame *caller = elt->static_link ();
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
732
8408acb7ca4f make dbup/dbdown work again (bug #56020)
John W. Eaton <jwe@octave.org>
parents: 27005
diff changeset
733 m_curr_frame = caller->index ();
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
734
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
735 m_cs.pop_back ();
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
736
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
737 delete elt;
23630
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
738 }
8a47d4735655 avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents: 23602
diff changeset
739 }
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
740
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
741 void call_stack::clear (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
742 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
743 while (! m_cs.empty ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
744 pop ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
745 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
746
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
747 symbol_info_list call_stack::all_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
748 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
749 return m_cs[m_curr_frame]->all_variables ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
750 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
751
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
752 std::list<std::string> call_stack::global_variable_names (void) const
26092
661dfb062485 use symbol_info_list to gather data for save function
John W. Eaton <jwe@octave.org>
parents: 26089
diff changeset
753 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
754 std::list<std::string> retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
755
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
756 for (const auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
757 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
758 if (nm_ov.second.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
759 retval.push_back (nm_ov.first);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
760 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
761
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
762 retval.sort ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
763
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
764 return retval;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
765 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
766
27594
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
767 std::list<std::string> call_stack::top_level_variable_names (void) const
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
768 {
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
769 return m_cs[0]->variable_names ();
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
770 }
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
771
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
772 std::list<std::string> call_stack::variable_names (void) const
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
773 {
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
774 return m_cs[m_curr_frame]->variable_names ();
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
775 }
e091e09d26f0 restore some symbol table functions for backward compatibility
John W. Eaton <jwe@octave.org>
parents: 27471
diff changeset
776
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
777 void call_stack::clear_global_variable (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
778 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
779 auto p = m_global_values.find (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
780
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
781 if (p != m_global_values.end ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
782 p->second = octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
783 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
784
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
785 void call_stack::clear_global_variable_pattern (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
786 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
787 glob_match pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
788
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
789 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
790 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
791 if (pat.match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
792 nm_ov.second = octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
793 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
794 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
795
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
796 void call_stack::clear_global_variable_regexp (const std::string& pattern)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
797 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
798 octave::regexp pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
799
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
800 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
801 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
802 if (pat.is_match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
803 nm_ov.second = octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
804 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
805 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
806
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
807 void call_stack::clear_global_variables (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
808 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
809 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
810 nm_ov.second = octave_value ();
26092
661dfb062485 use symbol_info_list to gather data for save function
John W. Eaton <jwe@octave.org>
parents: 26089
diff changeset
811 }
661dfb062485 use symbol_info_list to gather data for save function
John W. Eaton <jwe@octave.org>
parents: 26089
diff changeset
812
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
813 symbol_info_list
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
814 call_stack::glob_symbol_info (const std::string& pattern) const
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
815 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
816 return m_cs[m_curr_frame]->glob_symbol_info (pattern);
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
817 }
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
818
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
819 symbol_info_list
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
820 call_stack::regexp_symbol_info (const std::string& pattern) const
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
821 {
28326
991dc4d31949 fix apparent copy/paste error in call stack function
John W. Eaton <jwe@octave.org>
parents: 27932
diff changeset
822 return m_cs[m_curr_frame]->regexp_symbol_info (pattern);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
823 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
824
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
825 symbol_info_list call_stack::get_symbol_info (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
826 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
827 return m_cs[m_curr_frame]->get_symbol_info ();
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
828 }
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
829
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
830 symbol_info_list call_stack::top_scope_symbol_info (void) const
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
831 {
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
832 return m_cs[0]->get_symbol_info ();
26093
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
833 }
6a03af2c4c9e use symbol_info_list to gather data for saving workspace on crash
John W. Eaton <jwe@octave.org>
parents: 26092
diff changeset
834
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
835 octave_value call_stack::max_stack_depth (const octave_value_list& args,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
836 int nargout)
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
837 {
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
838 return set_internal_variable (m_max_stack_depth, args, nargout,
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
839 "max_stack_depth", 0);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
840 }
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
841
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
842 void call_stack::make_persistent (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
843 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
844 m_cs[m_curr_frame]->make_persistent (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
845 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
846
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
847 void call_stack::make_global (const symbol_record& sym)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
848 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
849 m_cs[m_curr_frame]->make_global (sym);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
850 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
851
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
852 octave_value call_stack::global_varval (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
853 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
854 auto p = m_global_values.find (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
855
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
856 return p == m_global_values.end () ? octave_value () : p->second;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
857 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
858
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
859 octave_value& call_stack::global_varref (const std::string& name)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
860 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
861 return m_global_values[name];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
862 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
863
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
864 octave_value call_stack::get_top_level_value (const std::string& name) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
865 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
866 return m_cs[0]->varval (name);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
867 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
868
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
869 void call_stack::set_top_level_value (const std::string& name,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
870 const octave_value& value)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
871 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
872 m_cs[0]->assign (name, value);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
873 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
874
27005
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
875 octave_value call_stack::do_who (int argc, const string_vector& argv,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
876 bool return_list, bool verbose)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
877 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
878 octave_value retval;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
879
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
880 std::string my_name = argv[0];
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
881
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
882 std::string file_name;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
883
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
884 bool from_file = false;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
885 bool global_only = false;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
886 bool have_regexp = false;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
887
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
888 int i = 1;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
889 while (i < argc)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
890 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
891 if (argv[i] == "-file")
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
892 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
893 if (from_file)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
894 error ("%s: -file option may only be specified once",
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
895 my_name.c_str ());
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
896
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
897 from_file = true;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
898
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
899 if (i == argc - 1)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
900 error ("%s: -file argument must be followed by a filename",
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
901 my_name.c_str ());
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
902
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
903 file_name = argv[++i];
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
904 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
905 else if (argv[i] == "-regexp")
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
906 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
907 have_regexp = true;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
908 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
909 else if (argv[i] == "global")
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
910 global_only = true;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
911 else if (argv[i][0] == '-')
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
912 warning ("%s: unrecognized option '%s'", my_name.c_str (),
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
913 argv[i].c_str ());
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
914 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
915 break;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
916
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
917 i++;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
918 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
919
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
920 int npatterns = argc - i;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
921 string_vector patterns;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
922 if (npatterns > 0)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
923 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
924 patterns.resize (npatterns);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
925 for (int j = 0; j < npatterns; j++)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
926 patterns[j] = argv[i+j];
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
927 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
928 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
929 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
930 patterns.resize (1);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
931 patterns[0] = "*";
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
932 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
933
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
934 if (from_file)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
935 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
936 // FIXME: This is an inefficient manner to implement this as the
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
937 // variables are loaded in to a temporary context and then treated.
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
938 // It would be better to refactor symbol_info_list to not store the
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
939 // symbol records and then use it in load-save.cc (do_load) to
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
940 // implement this option there so that the variables are never
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
941 // stored at all.
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
942
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
943 unwind_protect frame;
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
944
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
945 // Set up temporary scope.
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
946
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
947 symbol_scope tmp_scope ("$dummy_scope$");
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
948
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
949 push (tmp_scope);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
950 frame.add_method (*this, &call_stack::pop);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
951
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
952 feval ("load", octave_value (file_name), 0);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
953
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
954 std::string newmsg = "Variables in the file " + file_name + ":\n\n";
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
955
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
956 if (global_only)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
957 return do_global_who_two (patterns, have_regexp, return_list,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
958 verbose, newmsg);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
959 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
960 return do_who_two (patterns, have_regexp, return_list, verbose,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
961 newmsg);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
962 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
963 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
964 {
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
965 if (global_only)
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
966 return do_global_who_two (patterns, have_regexp, return_list,
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
967 verbose);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
968 else
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
969 return do_who_two (patterns, have_regexp, return_list, verbose);
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
970 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
971 }
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
972
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
973 octave_value call_stack::do_who_two (const string_vector& patterns,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
974 bool have_regexp, bool return_list,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
975 bool verbose, const std::string& msg)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
976 {
28425
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
977 return m_cs[m_curr_frame]->who (patterns, have_regexp, return_list,
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
978 verbose, m_evaluator.whos_line_format (),
a5be4fc661d6 hide specific stack frame and stack frame walker classes
John W. Eaton <jwe@octave.org>
parents: 28328
diff changeset
979 msg);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
980 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
981
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
982 octave_value call_stack::do_global_who_two (const string_vector& patterns,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
983 bool have_regexp,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
984 bool return_list, bool verbose,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
985 const std::string& msg)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
986 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
987 symbol_info_list symbol_stats;
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
988 std::list<std::string> symbol_names;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
989
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
990 octave_idx_type npatterns = patterns.numel ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
991
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
992 for (octave_idx_type j = 0; j < npatterns; j++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
993 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
994 std::string pattern = patterns[j];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
995
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
996 std::list<std::string> tmp;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
997
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
998 if (have_regexp)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
999 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1000 octave::regexp pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1001
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1002 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1003 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1004 if (pat.is_match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1005 tmp.push_back (nm_ov.first);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1006 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1007 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1008 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1009 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1010 glob_match pat (pattern);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1011
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1012 for (auto& nm_ov : m_global_values)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1013 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1014 if (pat.match (nm_ov.first))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1015 tmp.push_back (nm_ov.first);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1016 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1017 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1018
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1019 for (const auto& nm : tmp)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1020 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1021 octave_value value = m_global_values[nm];
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1022
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1023 if (value.is_defined ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1024 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1025 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1026 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1027 bool is_formal = false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1028 bool is_global = true;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1029 bool is_persistent = false;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1030
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1031 symbol_info syminf (nm, value, is_formal, is_global,
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
1032 is_persistent);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1033
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1034 symbol_stats.append (syminf);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1035 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1036 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1037 symbol_names.push_back (nm);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1038 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1039 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1040 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1041
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1042 if (return_list)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1043 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1044 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1045 {
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1046 std::string caller_fcn_name;
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1047 octave_function *caller_fcn = caller_function ();
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1048 if (caller_fcn)
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1049 caller_fcn_name = caller_fcn->name ();
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1050
27873
020d0e8f7ac6 reafactor mlock, munlock, and mislocked functions
John W. Eaton <jwe@octave.org>
parents: 27844
diff changeset
1051 return symbol_stats.map_value (caller_fcn_name, 1);
26661
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1052 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1053 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1054 return Cell (string_vector (symbol_names));
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1055 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1056 else if (! (symbol_stats.empty () && symbol_names.empty ()))
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1057 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1058 if (msg.empty ())
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1059 octave_stdout << "Global variables:\n\n";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1060 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1061 octave_stdout << msg;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1062
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1063 if (verbose)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1064 symbol_stats.display (octave_stdout,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1065 m_evaluator.whos_line_format ());
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1066 else
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1067 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1068 string_vector names (symbol_names);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1069
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1070 names.list_in_columns (octave_stdout);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1071 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1072
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1073 octave_stdout << "\n";
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1074 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1075
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1076 return octave_value ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1077 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1078
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1079 void call_stack::clear_current_frame_values (void)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1080 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1081 m_cs[m_curr_frame]->clear_values ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1082 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1083
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1084 void call_stack::display (void) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1085 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1086 std::ostream& os = octave_stdout;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1087
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1088 size_t nframes = size ();
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1089
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1090 for (size_t i = 0; i < nframes; i++)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1091 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1092 m_cs[i]->display (false);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1093 if (i < nframes - 1)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1094 os << std::endl;
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1095 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1096 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1097
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1098 void call_stack::set_auto_fcn_var (stack_frame::auto_var_type avt,
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1099 const octave_value& val)
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1100 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1101 m_cs[m_curr_frame]->set_auto_fcn_var (avt, val);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1102 }
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1103
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1104 octave_value call_stack::get_auto_fcn_var (stack_frame::auto_var_type avt) const
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1105 {
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1106 return m_cs[m_curr_frame]->get_auto_fcn_var (avt);
cf9e10ce3351 move variable values from symbol_record objects to stack_frame objects
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
1107 }
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1108 }
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1109
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1110 DEFMETHOD (max_stack_depth, interp, args, nargout,
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1111 doc: /* -*- texinfo -*-
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1112 @deftypefn {} {@var{val} =} max_stack_depth ()
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1113 @deftypefnx {} {@var{old_val} =} max_stack_depth (@var{new_val})
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1114 @deftypefnx {} {} max_stack_depth (@var{new_val}, "local")
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1115 Query or set the internal limit on the number of times a function may
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1116 be called recursively.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1117
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1118 If the limit is exceeded, an error message is printed and control returns to
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1119 the top level.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1120
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1121 When called from inside a function with the @qcode{"local"} option, the
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1122 variable is changed locally for the function and any subroutines it calls.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1123 The original variable value is restored when exiting the function.
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1124
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1125 @seealso{max_recursion_depth}
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1126 @end deftypefn */)
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1127 {
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1128 octave::tree_evaluator& tw = interp.get_evaluator ();
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1129
27211
8c27802a76c4 store reference to evaluator instead of call stack in stack frame
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
1130 return tw.max_stack_depth (args, nargout);
24855
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1131 }
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1132
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1133 /*
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1134 %!test
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1135 %! orig_val = max_stack_depth ();
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1136 %! old_val = max_stack_depth (2*orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1137 %! assert (orig_val, old_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1138 %! assert (max_stack_depth (), 2*orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1139 %! max_stack_depth (orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1140 %! assert (max_stack_depth (), orig_val);
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1141
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1142 %!error (max_stack_depth (1, 2))
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1143 */
41f80b9af274 prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents: 24706
diff changeset
1144
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1145 DEFMETHOD (who, interp, args, nargout,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1146 doc: /* -*- texinfo -*-
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1147 @deftypefn {} {} who
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1148 @deftypefnx {} {} who pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1149 @deftypefnx {} {} who option pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1150 @deftypefnx {} {C =} who ("pattern", @dots{})
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1151 List currently defined variables matching the given patterns.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1152
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1153 Valid pattern syntax is the same as described for the @code{clear} command.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1154 If no patterns are supplied, all variables are listed.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1155
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1156 By default, only variables visible in the local scope are displayed.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1157
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1158 The following are valid options, but may not be combined.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1159
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1160 @table @code
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1161 @item global
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1162 List variables in the global scope rather than the current scope.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1163
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1164 @item -regexp
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1165 The patterns are considered to be regular expressions when matching the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1166 variables to display. The same pattern syntax accepted by the @code{regexp}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1167 function is used.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1168
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1169 @item -file
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1170 The next argument is treated as a filename. All variables found within the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1171 specified file are listed. No patterns are accepted when reading variables
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1172 from a file.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1173 @end table
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1174
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1175 If called as a function, return a cell array of defined variable names
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1176 matching the given patterns.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1177 @seealso{whos, isglobal, isvarname, exist, regexp}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1178 @end deftypefn */)
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1179 {
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1180 int argc = args.length () + 1;
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1181
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1182 string_vector argv = args.make_argv ("who");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1183
27005
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1184 octave::tree_evaluator& tw = interp.get_evaluator ();
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1185
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1186 return tw.do_who (argc, argv, nargout == 1);
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1187 }
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1188
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1189 /*
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1190 %!test
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1191 %! avar = magic (4);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1192 %! ftmp = [tempname() ".mat"];
26698
63b5a17ba30f Use save_default_options() to make BIST test suite robust against user configurations.
Rik <rik@octave.org>
parents: 26661
diff changeset
1193 %! save_default_options ("-binary", "local");
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1194 %! unwind_protect
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1195 %! save (ftmp, "avar");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1196 %! vars = whos ("-file", ftmp);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1197 %! assert (numel (vars), 1);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1198 %! assert (isstruct (vars));
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1199 %! assert (vars.name, "avar");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1200 %! assert (vars.size, [4, 4]);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1201 %! assert (vars.class, "double");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1202 %! assert (vars.bytes, 128);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1203 %! unwind_protect_cleanup
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1204 %! unlink (ftmp);
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1205 %! end_unwind_protect
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1206 */
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1207
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1208 DEFMETHOD (whos, interp, args, nargout,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1209 doc: /* -*- texinfo -*-
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1210 @deftypefn {} {} whos
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1211 @deftypefnx {} {} whos pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1212 @deftypefnx {} {} whos option pattern @dots{}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1213 @deftypefnx {} {S =} whos ("pattern", @dots{})
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1214 Provide detailed information on currently defined variables matching the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1215 given patterns.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1216
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1217 Options and pattern syntax are the same as for the @code{who} command.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1218
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1219 Extended information about each variable is summarized in a table with the
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1220 following default entries.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1221
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1222 @table @asis
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1223 @item Attr
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1224 Attributes of the listed variable. Possible attributes are:
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1225
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1226 @table @asis
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1227 @item blank
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1228 Variable in local scope
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1229
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1230 @item @code{c}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1231 Variable of complex type.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1232
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1233 @item @code{f}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1234 Formal parameter (function argument).
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1235
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1236 @item @code{g}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1237 Variable with global scope.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1238
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1239 @item @code{p}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1240 Persistent variable.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1241 @end table
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1242
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1243 @item Name
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1244 The name of the variable.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1245
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1246 @item Size
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1247 The logical size of the variable. A scalar is 1x1, a vector is
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1248 @nospell{1xN} or @nospell{Nx1}, a 2-D matrix is @nospell{MxN}.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1249
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1250 @item Bytes
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1251 The amount of memory currently used to store the variable.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1252
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1253 @item Class
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1254 The class of the variable. Examples include double, single, char, uint16,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1255 cell, and struct.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1256 @end table
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1257
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1258 The table can be customized to display more or less information through
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1259 the function @code{whos_line_format}.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1260
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1261 If @code{whos} is called as a function, return a struct array of defined
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1262 variable names matching the given patterns. Fields in the structure
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1263 describing each variable are: name, size, bytes, class, global, sparse,
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1264 complex, nesting, persistent.
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1265 @seealso{who, whos_line_format}
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1266 @end deftypefn */)
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1267 {
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1268 int argc = args.length () + 1;
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1269
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1270 string_vector argv = args.make_argv ("whos");
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1271
27005
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1272 octave::tree_evaluator& tw = interp.get_evaluator ();
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1273
a1ea0e7aecde move do_who inside call_stack, make accessible from evaluator
John W. Eaton <jwe@octave.org>
parents: 26965
diff changeset
1274 return tw.do_who (argc, argv, nargout == 1, true);
26089
e71893aa322c move Fwho, Fwhos, and supporting functions to call-stack.cc
John W. Eaton <jwe@octave.org>
parents: 25399
diff changeset
1275 }