Mercurial > octave
annotate libinterp/corefcn/call-stack.cc @ 24855:41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
* call-stack.h, call-stack.cc (call_stack::m_max_stack_depth):
New member variable.
(call_stack::max_stack_depth): New function.
(Fmax_stack_depth): New function.
(call_stack::push): Error if call_stack size exceeds m_max_stack_depth.
* pt-eval.cc (Fmax_recursion_depth): Add @seealso to doc string.
* expr.txi: Document max_stack_depth.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 09 Mar 2018 17:14:52 -0500 |
parents | 30e1d0bf7ade |
children | 6652d3823428 |
rev | line source |
---|---|
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 /* |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1995-2017 John W. Eaton |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 This file is part of Octave. |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
10 (at your option) any later version. |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22600
diff
changeset
|
15 GNU General Public License for more details. |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24362
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 */ |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 # include "config.h" |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 #endif |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 #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
|
28 #include "defun.h" |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
29 #include "interpreter.h" |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include "oct-map.h" |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include "ov.h" |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #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
|
33 #include "ov-fcn-handle.h" |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include "ov-usr-fcn.h" |
23630
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
35 #include "pager.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 "variables.h" |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 // Use static fields for the best efficiency. |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 // NOTE: C++0x will allow these two to be merged into one. |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
40 static const char *bt_fieldnames[] = |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23630
diff
changeset
|
41 { "file", "name", "line", "column", "scope", "context", nullptr }; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 static const octave_fields bt_fields (bt_fieldnames); |
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
44 namespace octave |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
45 { |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
46 std::string |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
47 call_stack::stack_frame::fcn_file_name (void) const |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
48 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
49 return m_fcn ? m_fcn->fcn_file_name () : ""; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
50 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
51 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
52 std::string |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
53 call_stack::stack_frame::fcn_name (bool print_subfn) const |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
54 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
55 std::string retval; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
57 if (m_fcn) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
58 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
59 std::string parent_fcn_name = m_fcn->parent_fcn_name (); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
60 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
61 if (print_subfn && ! parent_fcn_name.empty ()) |
24279
a26a8714db26
delete filemarker function and corresponding internal variable
John W. Eaton <jwe@octave.org>
parents:
24270
diff
changeset
|
62 retval = parent_fcn_name + '>'; |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
63 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
64 if (m_fcn->is_anonymous_function ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
65 retval += octave_fcn_handle::anonymous; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
66 else |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
67 retval += m_fcn->name (); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
68 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
69 else |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
70 retval = "<unknown>"; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
71 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
72 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
73 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
75 bool |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
76 call_stack::stack_frame::operator == (const call_stack::stack_frame& rhs) const |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
77 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
78 if (this->line () != rhs.line ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
79 return false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
80 else if (this->column () != rhs.column ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
81 return false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
82 else if (this->fcn_file_name () != rhs.fcn_file_name ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
83 return false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
84 else if (this->fcn_name () != rhs.fcn_name ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
85 return false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
86 else |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
87 return true; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
88 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
90 call_stack::call_stack (interpreter& interp) |
24855
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
91 : cs (), curr_frame (0), m_max_stack_depth (1024), m_interpreter (interp) |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
92 { |
23602
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
93 symbol_table& symtab = m_interpreter.get_symbol_table (); |
214cb58ccc1c
use pointer to scope instead of scope id
John W. Eaton <jwe@octave.org>
parents:
23599
diff
changeset
|
94 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23630
diff
changeset
|
95 push (nullptr, symtab.top_scope (), 0); |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
96 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
97 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
98 int |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
99 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
|
100 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
101 int retval = -1; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
102 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
103 if (! cs.empty ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
104 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
105 const stack_frame& elt = cs[curr_frame]; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
106 retval = elt.m_line; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
107 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
108 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
109 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
110 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
111 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
112 int |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
113 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
|
114 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
115 int retval = -1; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
117 if (! cs.empty ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
118 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
119 const stack_frame& elt = cs[curr_frame]; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
120 retval = elt.m_column; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
121 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
122 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
123 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
124 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
125 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
126 size_t |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
127 call_stack::num_user_code_frames (octave_idx_type& curr_user_frame) const |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
128 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
129 size_t retval = 0; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
130 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
131 curr_user_frame = 0; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
132 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
133 // Look for the caller of dbstack. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
134 size_t xframe = cs[curr_frame].m_prev; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
136 bool found = false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
137 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
138 size_t k = cs.size (); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
139 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
140 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
141 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
142 octave_function *f = (*p).m_fcn; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
143 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
144 if (--k == xframe) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
145 found = true; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
146 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
147 if (f && f->is_user_code ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
148 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
149 if (! found) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
150 curr_user_frame++; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
151 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
152 retval++; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
153 } |
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 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
156 // We counted how many user frames were not the one, in reverse. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
157 // Now set curr_user_frame to be the index in the other direction. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
158 curr_user_frame = retval - curr_user_frame - 1; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
159 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
160 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
161 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
162 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
163 octave_user_code * |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
164 call_stack::caller_user_code (size_t nskip) const |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
165 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
166 octave_user_code *retval = nullptr; |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
167 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
168 const_iterator p = cs.end (); |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
169 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
170 while (p != cs.begin ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
171 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
172 const stack_frame& elt = *(--p); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
173 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
174 octave_function *f = elt.m_fcn; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
175 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
176 if (f && f->is_user_code ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
177 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
178 if (nskip > 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
179 nskip--; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
180 else |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
181 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
182 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
|
183 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
184 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
185 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
186 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
187 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
188 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
189 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
190 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
191 int |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
192 call_stack::caller_user_code_line (void) const |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
193 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
194 int retval = -1; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
195 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
196 const_iterator p = cs.end (); |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
197 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
198 while (p != cs.begin ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
199 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
200 const stack_frame& elt = *(--p); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
201 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
202 octave_function *f = elt.m_fcn; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
203 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
204 if (f && f->is_user_code ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
205 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
206 if (elt.m_line > 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
207 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
208 retval = elt.m_line; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
209 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
210 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
211 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
212 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
213 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
214 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
215 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
216 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
217 int |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
218 call_stack::caller_user_code_column (void) const |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
219 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
220 int retval = -1; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
221 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
222 const_iterator p = cs.end (); |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
223 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
224 while (p != cs.begin ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
225 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
226 const stack_frame& elt = *(--p); |
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 octave_function *f = elt.m_fcn; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
229 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
230 if (f && f->is_user_code ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
231 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
232 if (elt.m_column) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
233 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
234 retval = elt.m_column; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
235 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
236 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
237 } |
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 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
240 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
241 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
242 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
243 octave_user_code * |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
244 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
|
245 { |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
246 octave_user_code *retval = nullptr; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
247 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
248 // This should never happen... |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
249 if (curr_frame == 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
250 return retval; |
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 // Start looking with the caller of the calling debug function. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
253 size_t i = cs[curr_frame].m_prev; |
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 while (i != 0) |
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 const stack_frame& elt = cs[i--]; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
258 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
259 octave_function *f = elt.m_fcn; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
260 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
261 if (f && f->is_user_code ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
262 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
263 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
|
264 break; |
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 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
267 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
268 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
269 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
270 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
271 int |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
272 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
|
273 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
274 int retval = -1; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
275 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
276 // This should never happen... |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
277 if (curr_frame == 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
278 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
279 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
280 // Start looking with the caller of the calling debug function. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
281 size_t i = cs[curr_frame].m_prev; |
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 while (i != 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
284 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
285 const stack_frame& elt = cs[i--]; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
286 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
287 octave_function *f = elt.m_fcn; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
288 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
289 if (f && f->is_user_code ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
290 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
291 if (elt.m_line) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
292 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
293 retval = elt.m_line; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
294 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
295 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
296 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
297 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
298 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
299 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
300 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
301 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
302 int |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
303 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
|
304 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
305 int retval = -1; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
306 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
307 // This should never happen... |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
308 if (curr_frame == 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
309 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
310 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
311 // Start looking with the caller of the calling debug function. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
312 size_t i = cs[curr_frame].m_prev; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
313 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
314 while (i != 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
315 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
316 const stack_frame& elt = cs[i--]; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
317 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
318 octave_function *f = elt.m_fcn; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
319 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
320 if (f && f->is_user_code ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
321 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
322 if (elt.m_column) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
323 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
324 retval = elt.m_column; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
325 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
326 } |
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 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
329 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
330 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
331 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
332 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
333 bool |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
334 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
|
335 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
336 bool retval = true; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
337 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
338 const_iterator p = cs.end (); |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
339 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
340 while (p != cs.begin ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
341 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
342 const stack_frame& elt = *(--p); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
343 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
344 octave_function *f = elt.m_fcn; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
345 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
346 if (f && ! f->is_user_script ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
347 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
348 retval = false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
349 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
350 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
351 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
352 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
353 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
354 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
355 |
23630
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
356 void |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
357 call_stack::push (octave_function *fcn) |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
358 { |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
359 symbol_table& symtab = m_interpreter.get_symbol_table (); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
360 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
361 push (fcn, symtab.current_scope (), symtab.current_context ()); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
362 } |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
363 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
364 void |
24361
8bcfddad15ec
use shared_ptr to manage symbol_scope objects
John W. Eaton <jwe@octave.org>
parents:
24279
diff
changeset
|
365 call_stack::push (octave_function *fcn, const symbol_scope& scope, |
24362
3fc24b792a24
avoid including symtab.h, symscope.h, or symrec.h unnecessarily
John W. Eaton <jwe@octave.org>
parents:
24361
diff
changeset
|
366 symbol_record::context_id context) |
23630
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
367 { |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
368 size_t prev_frame = curr_frame; |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
369 curr_frame = 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
|
370 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
371 // m_max_stack_depth should never be less than zero. |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
372 if (curr_frame > static_cast<size_t> (m_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
|
373 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
|
374 |
23630
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
375 cs.push_back (stack_frame (fcn, scope, context, prev_frame)); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
376 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
377 symbol_table& symtab = m_interpreter.get_symbol_table (); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
378 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
379 symtab.set_scope_and_context (scope, context); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
380 } |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
381 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
382 bool |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
383 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
|
384 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
385 bool retval = false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
386 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
387 if (n < cs.size ()) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
388 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
389 retval = true; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
390 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
391 curr_frame = n; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
392 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
393 const stack_frame& elt = cs[n]; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
394 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
395 symbol_table& symtab = m_interpreter.get_symbol_table (); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
396 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
397 symtab.set_scope_and_context (elt.m_scope, elt.m_context); |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
398 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
399 if (verbose) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
400 octave_stdout << "stopped in " << elt.fcn_name () |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
401 << " at line " << elt.m_line |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
402 << " column " << elt.m_column |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
403 << " [" << elt.fcn_file_name () << "] " |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
404 << "[context = " << elt.m_context << "])" |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
405 << std::endl; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
406 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
407 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
408 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
409 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
410 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
411 bool |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
412 call_stack::goto_frame_relative (int nskip, bool verbose) |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
413 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
414 bool retval = false; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
415 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
416 int incr = 0; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
417 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
418 if (nskip < 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
419 incr = -1; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
420 else if (nskip > 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
421 incr = 1; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
422 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
423 // Start looking with the caller of dbup/dbdown/keyboard. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
424 size_t xframe = cs[curr_frame].m_prev; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
425 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
426 while (true) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
427 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
428 if ((incr < 0 && xframe == 0) || (incr > 0 && xframe == cs.size () - 1)) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
429 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
430 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
431 xframe += incr; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
432 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
433 const stack_frame& elt = cs[xframe]; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
434 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
435 octave_function *f = elt.m_fcn; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
436 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
437 if (xframe == 0 || (f && f->is_user_code ())) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
438 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
439 if (nskip > 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
440 nskip--; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
441 else if (nskip < 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
442 nskip++; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
443 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
444 if (nskip == 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
445 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
446 curr_frame = xframe; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
447 cs[cs.size () - 1].m_prev = curr_frame; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
448 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
449 symbol_table& symtab = m_interpreter.get_symbol_table (); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
450 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
451 symtab.set_scope_and_context (elt.m_scope, elt.m_context); |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
452 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
453 if (verbose) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
454 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
455 std::ostringstream buf; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
456 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
457 if (f) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
458 buf << "stopped in " << elt.fcn_name () |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
459 << " at line " << elt.m_line |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
460 << " [" << elt.fcn_file_name () << "] " |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
461 << std::endl; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
462 else |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
463 buf << "at top level" << std::endl; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
464 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
465 octave_stdout << buf.str (); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
466 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
467 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
468 retval = true; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
469 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
470 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
471 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
472 else if (incr == 0) // Break out of infinite loop by choosing an incr. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
473 incr = -1; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
474 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
475 // There is no need to set scope and context here. That will |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
476 // happen when the dbup/dbdown/keyboard frame is popped and we |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
477 // jump to the new "prev" frame set above. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
478 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
479 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
480 return retval; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
481 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
482 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
483 void |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
484 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
|
485 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
486 size_t xframe = curr_frame; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
487 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
488 bool skipped = false; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
489 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
490 while (xframe != 0) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
491 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
492 xframe = cs[xframe].m_prev; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
493 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
494 const stack_frame& elt = cs[xframe]; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
495 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
496 octave_function *f = elt.m_fcn; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
497 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
498 if (elt.m_scope == cs[0].m_scope || (f && f->is_user_code ())) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
499 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
500 if (! skipped) |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
501 // We found the current user code frame, so skip it. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
502 skipped = true; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
503 else |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
504 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
505 // We found the caller user code frame. |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
506 stack_frame tmp (elt); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
507 tmp.m_prev = curr_frame; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
508 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
509 curr_frame = cs.size (); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
510 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
511 cs.push_back (tmp); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
512 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
513 symbol_table& symtab = m_interpreter.get_symbol_table (); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
514 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
515 symtab.set_scope_and_context (tmp.m_scope, tmp.m_context); |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
516 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
517 break; |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
518 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
519 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
520 } |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
521 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
522 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
523 void |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
524 call_stack::goto_base_frame (void) |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
525 { |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
526 stack_frame tmp (cs[0]); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
527 tmp.m_prev = curr_frame; |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
528 |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
529 curr_frame = cs.size (); |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
530 |
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
531 cs.push_back (tmp); |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
532 |
23599
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
533 symbol_table& symtab = m_interpreter.get_symbol_table (); |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
534 |
5cb3a2bb5e1e
don't use singleton for symbol_table
John W. Eaton <jwe@octave.org>
parents:
23553
diff
changeset
|
535 symtab.set_scope_and_context (tmp.m_scope, tmp.m_context); |
23052
f97e22a9012a
move octave_call_stack inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
22862
diff
changeset
|
536 } |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
537 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
538 std::list<call_stack::stack_frame> |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
539 call_stack::backtrace_frames (size_t nskip, |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
540 octave_idx_type& curr_user_frame) const |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
541 { |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
542 std::list<call_stack::stack_frame> retval; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
543 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
544 size_t user_code_frames = num_user_code_frames (curr_user_frame); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
545 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
546 size_t nframes = (nskip <= user_code_frames ? user_code_frames - nskip : 0); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
547 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
548 // Our list is reversed. |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
549 curr_user_frame = nframes - curr_user_frame - 1; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
550 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
551 if (nframes > 0) |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
552 { |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
553 for (const_reverse_iterator p = cs.rbegin (); p != cs.rend (); p++) |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
554 { |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
555 const stack_frame& elt = *p; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
556 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
557 octave_function *f = elt.m_fcn; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
558 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
559 if (f && f->is_user_code ()) |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
560 { |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
561 if (nskip > 0) |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
562 nskip--; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
563 else |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
564 retval.push_back (elt); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
565 } |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
566 } |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
567 } |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
568 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
569 return retval; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
570 } |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
571 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
572 octave_map |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
573 call_stack::backtrace (size_t nskip, octave_idx_type& curr_user_frame, |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
574 bool print_subfn) const |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
575 { |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
576 std::list<call_stack::stack_frame> frames |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
577 = backtrace_frames (nskip, curr_user_frame); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
578 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
579 size_t nframes = frames.size (); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
580 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
581 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
|
582 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
583 Cell& file = retval.contents (0); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
584 Cell& name = retval.contents (1); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
585 Cell& line = retval.contents (2); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
586 Cell& column = retval.contents (3); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
587 Cell& context = retval.contents (5); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
588 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
589 octave_idx_type k = 0; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
590 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
591 for (const auto& frm : frames) |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
592 { |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
593 context(k) = frm.m_context; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
594 file(k) = frm.fcn_file_name (); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
595 name(k) = frm.fcn_name (print_subfn); |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
596 line(k) = frm.m_line; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
597 column(k) = frm.m_column; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
598 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
599 k++; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
600 } |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
601 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
602 return retval; |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
603 } |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
604 |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
605 octave_map |
23630
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
606 call_stack::backtrace (size_t nskip) |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
607 { |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
608 octave_idx_type curr_user_frame = -1; |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
609 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
610 return backtrace (nskip, curr_user_frame, true); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
611 } |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
612 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
613 octave_map |
23553
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
614 call_stack::empty_backtrace (void) const |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
615 { |
14723784b9f2
don't use singleton for call_stack
John W. Eaton <jwe@octave.org>
parents:
23457
diff
changeset
|
616 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
|
617 } |
23630
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
618 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
619 void |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
620 call_stack::pop (void) |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
621 { |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
622 if (cs.size () > 1) |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
623 { |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
624 const stack_frame& elt = cs.back (); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
625 curr_frame = elt.m_prev; |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
626 cs.pop_back (); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
627 const stack_frame& new_elt = cs[curr_frame]; |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
628 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
629 symbol_table& symtab = m_interpreter.get_symbol_table (); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
630 |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
631 symtab.set_scope_and_context (new_elt.m_scope, new_elt.m_context); |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
632 } |
8a47d4735655
avoid memory leak in interpreter
John W. Eaton <jwe@octave.org>
parents:
23602
diff
changeset
|
633 } |
24855
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
634 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
635 octave_value |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
636 call_stack::max_stack_depth (const octave_value_list& args, int nargout) |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
637 { |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
638 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
|
639 "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
|
640 } |
22091
0f6fc2ec3b1a
move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
641 } |
24855
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
642 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
643 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
|
644 doc: /* -*- texinfo -*- |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
645 @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
|
646 @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
|
647 @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
|
648 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
|
649 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
|
650 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
651 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
|
652 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
|
653 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
654 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
|
655 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
|
656 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
|
657 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
658 @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
|
659 @end deftypefn */) |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
660 { |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
661 octave::call_stack& cs = interp.get_call_stack (); |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
662 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
663 return cs.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
|
664 } |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
665 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
666 /* |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
667 %!test |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
668 %! 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
|
669 %! 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
|
670 %! 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
|
671 %! 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
|
672 %! 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
|
673 %! 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
|
674 |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
675 %!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
|
676 */ |
41f80b9af274
prevent stack overflow crash on deeply nested function calls (bug #47620)
John W. Eaton <jwe@octave.org>
parents:
24706
diff
changeset
|
677 |