Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 237 lines (191 sloc) 6.313 kb
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
1 #include <iostream>
2
3 #include "call_frame.hpp"
4 #include "builtin/variable_scope.hpp"
5 #include "builtin/class.hpp"
6 #include "builtin/module.hpp"
7 #include "builtin/symbol.hpp"
35dbaf5 Dirkjan Bussink Rename CompiledMethod to CompiledCode
dbussink authored
8 #include "builtin/compiledcode.hpp"
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
9 #include "builtin/tuple.hpp"
a7b957a Josep M. Bach Rename StaticScope to ConstantScope... EVERYWHERE
txus authored
10 #include "builtin/constantscope.hpp"
6035068 Rewire debugger infrastructure, add new simple debugger.
Evan Phoenix authored
11 #include "builtin/lookuptable.hpp"
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
12 #include "builtin/nativemethod.hpp"
1618911 Refactor and work on the inlined code
Evan Phoenix authored
13
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
14 #include "object_utils.hpp"
15
16 namespace rubinius {
dda607b Handle last_match in an inline block properly. Fixes #720
Evan Phoenix authored
17 Object* CallFrame::last_match(STATE) {
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
18 CallFrame* use = this->top_ruby_frame();;
dda607b Handle last_match in an inline block properly. Fixes #720
Evan Phoenix authored
19
20 while(use && use->is_inline_block()) {
21 CallFrame* yielder = use->previous;
832cbb3 Brian Shirai Removed use of Qtrue|false|nil|undef from native code.
brixen authored
22 if(!yielder) return cNil;
21f81c9 Dirkjan Bussink Fix a bunch of typo's in the VM
dbussink authored
23 // This works because the creator is always one above
dda607b Handle last_match in an inline block properly. Fixes #720
Evan Phoenix authored
24 // the yielder with inline blocks.
25 use = yielder->previous;
26 }
27
832cbb3 Brian Shirai Removed use of Qtrue|false|nil|undef from native code.
brixen authored
28 if(!use) return cNil;
dda607b Handle last_match in an inline block properly. Fixes #720
Evan Phoenix authored
29 return use->scope->last_match(state);
30 }
31
32 void CallFrame::set_last_match(STATE, Object* obj) {
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
33 CallFrame* use = this->top_ruby_frame();
dda607b Handle last_match in an inline block properly. Fixes #720
Evan Phoenix authored
34
35 while(use && use->is_inline_block()) {
36 CallFrame* yielder = use->previous;
37 if(!yielder) return;
21f81c9 Dirkjan Bussink Fix a bunch of typo's in the VM
dbussink authored
38 // This works because the creator is always one above
dda607b Handle last_match in an inline block properly. Fixes #720
Evan Phoenix authored
39 // the yielder with inline blocks.
40 use = yielder->previous;
41 }
42
43 if(!use) return;
44 use->scope->set_last_match(state, obj);
45 }
46
e3e2306 Improve block creation speed
Evan Phoenix authored
47 VariableScope* CallFrame::promote_scope_full(STATE) {
8e02327 Support ability to have closed VariableScope objects
Evan Phoenix authored
48 return scope->create_heap_alias(state, this, !has_closed_scope_p());
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
49 }
50
2f768b8 Add zsuper instruction to fix super bugs
Evan Phoenix authored
51 VariableScope* CallFrame::method_scope(STATE) {
52 VariableScope* current = promote_scope(state);
53 if(!multiple_scopes_p()) return current;
54
55 for(;;) {
56 if(current->block_as_method_p()) return current;
57 VariableScope* parent = current->parent();
58 if(!parent->nil_p()) {
59 current = parent;
60 } else {
61 return current;
62 }
63 }
64
ac34941 Fix JIT exception handler calculation bug
Evan Phoenix authored
65 // Shouldn't ever get here.
66 return 0;
2f768b8 Add zsuper instruction to fix super bugs
Evan Phoenix authored
67 }
68
f47488d Evan Phoenix Add limit to CallFrame::print_backtrace
evanphx authored
69 void CallFrame::print_backtrace(STATE, int total) {
70 print_backtrace(state, std::cout, total);
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
71 }
72
f47488d Evan Phoenix Add limit to CallFrame::print_backtrace
evanphx authored
73 void CallFrame::print_backtrace(STATE, std::ostream& stream, int total) {
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
74 CallFrame* cf = this;
75
f47488d Evan Phoenix Add limit to CallFrame::print_backtrace
evanphx authored
76 int i = -1;
77
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
78 while(cf) {
f47488d Evan Phoenix Add limit to CallFrame::print_backtrace
evanphx authored
79 i++;
80
81 if(total > 0 && i == total) return;
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
82 stream << static_cast<void*>(cf) << ": ";
83
84 if(NativeMethodFrame* nmf = cf->native_method_frame()) {
85 NativeMethod* nm = try_as<NativeMethod>(nmf->get_object(nmf->method()));
6a10774 Dirkjan Bussink Use proper condition for native method frame name
dbussink authored
86 if(nm && nm->name()->symbol_p()) {
392f4bb Dirkjan Bussink Audited usage of char* for Symbols
dbussink authored
87 stream << "capi:" << nm->name()->debug_str(state) << " at ";
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
88 stream << nm->file()->c_str(state);
89 } else {
90 stream << "unknown capi";
91 }
92
93 stream << std::endl;
422359a Dirkjan Bussink CallFrame#previous is already a CallFrame, no need to cast
dbussink authored
94 cf = cf->previous;
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
95 continue;
96 }
97
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
98 if(!cf->compiled_code) {
422359a Dirkjan Bussink CallFrame#previous is already a CallFrame, no need to cast
dbussink authored
99 cf = cf->previous;
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
100 continue;
101 }
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
102
0a13e07 Refactor CallFrame a little, get JIT wired in
Evan Phoenix authored
103 if(cf->is_block_p(state)) {
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
104 stream << "__block__";
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
105 } else {
ebebe89 Brian Shirai Renamed MetaClass to SingletonClass.
brixen authored
106 if(SingletonClass* sc = try_as<SingletonClass>(cf->module())) {
63ae26d Brian Shirai Fixed Module#name.
brixen authored
107 Object* obj = sc->attached_instance();
108
109 if(Module* mod = try_as<Module>(obj)) {
110 stream << mod->debug_str(state) << ".";
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
111 } else {
63ae26d Brian Shirai Fixed Module#name.
brixen authored
112 if(obj == G(main)) {
76034fd Allow CallFrame::print_backtrace to see included modules
Evan Phoenix authored
113 stream << "MAIN.";
114 } else {
63ae26d Brian Shirai Fixed Module#name.
brixen authored
115 stream << "#<" << obj->class_object(state)->debug_str(state) <<
116 ":" << (void*)obj->id(state)->to_native() << ">.";
76034fd Allow CallFrame::print_backtrace to see included modules
Evan Phoenix authored
117 }
118 }
119 } else if(IncludedModule* im = try_as<IncludedModule>(cf->module())) {
63ae26d Brian Shirai Fixed Module#name.
brixen authored
120 stream << im->module()->debug_str(state) << "#";
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
121 } else {
63ae26d Brian Shirai Fixed Module#name.
brixen authored
122 Symbol* name;
392f4bb Dirkjan Bussink Audited usage of char* for Symbols
dbussink authored
123 std::string mod_name;
63ae26d Brian Shirai Fixed Module#name.
brixen authored
124
1618911 Refactor and work on the inlined code
Evan Phoenix authored
125 if(cf->module()->nil_p()) {
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
126 mod_name = cf->compiled_code->scope()->module()->debug_str(state);
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
127 } else {
63ae26d Brian Shirai Fixed Module#name.
brixen authored
128 if((name = try_as<Symbol>(cf->module()->module_name()))) {
129 mod_name = name->debug_str(state);
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
130 } else if((name = try_as<Symbol>(
131 cf->compiled_code->scope()->module()->module_name()))) {
63ae26d Brian Shirai Fixed Module#name.
brixen authored
132 mod_name = name->debug_str(state);
29571c7 Evan Phoenix Guard against modules with no names
evanphx authored
133 } else {
134 mod_name = "<anonymous module>";
135 }
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
136 }
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
137 stream << mod_name << "#";
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
138 }
139
84d2003 Refactor CallFrame::name
Evan Phoenix authored
140 Symbol* name = try_as<Symbol>(cf->name());
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
141 if(name) {
392f4bb Dirkjan Bussink Audited usage of char* for Symbols
dbussink authored
142 stream << name->debug_str(state);
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
143 } else {
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
144 stream << cf->compiled_code->name()->debug_str(state);
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
145 }
146 }
147
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
148 stream << " in ";
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
149 if(Symbol* file_sym = try_as<Symbol>(cf->compiled_code->file())) {
392f4bb Dirkjan Bussink Audited usage of char* for Symbols
dbussink authored
150 stream << file_sym->debug_str(state) << ":" << cf->line(state);
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
151 } else {
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
152 stream << "<unknown>";
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
153 }
154
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
155 stream << " (+" << cf->ip();
1618911 Refactor and work on the inlined code
Evan Phoenix authored
156 if(cf->is_inline_frame()) {
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
157 stream << " inline";
db013c4 Ignore inlined methods when considering what to JIT
Evan Phoenix authored
158 } else if(cf->jitted_p()) {
159 stream << " jit";
1618911 Refactor and work on the inlined code
Evan Phoenix authored
160 }
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
161 stream << ")";
3d7bc75 Fix reraising off non-Exception raise values
Evan Phoenix authored
162
058bc9f Add backtrace and discover ability to QueryAgent
Evan Phoenix authored
163 stream << std::endl;
422359a Dirkjan Bussink CallFrame#previous is already a CallFrame, no need to cast
dbussink authored
164 cf = cf->previous;
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
165 }
166
167 }
168
169 int CallFrame::line(STATE) {
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
170 if(!compiled_code) return -2; // trampoline context
171 return compiled_code->line(state, ip());
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
172 }
7773919 Eero Saynatkari Fix caller, top-level exceptions and __printbt__.
rue authored
173
44978a8 Fix Module#define_method
Evan Phoenix authored
174 // Walks the CallFrame list to see if +scope+ is still running
175 bool CallFrame::scope_still_valid(VariableScope* scope) {
176 CallFrame* cur = this;
177 while(cur) {
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
178 if(cur->scope && cur->scope->on_heap() == scope) return true;
422359a Dirkjan Bussink CallFrame#previous is already a CallFrame, no need to cast
dbussink authored
179 cur = cur->previous;
44978a8 Fix Module#define_method
Evan Phoenix authored
180 }
181
182 return false;
183 }
184
bf3c468 Add debugging method for CallFrame
Evan Phoenix authored
185 void CallFrame::dump() {
35a49f3 Evan Phoenix Introduce State class as STATE
evanphx authored
186 VM* vm = VM::current();
187 State state_obj(vm), *state = &state_obj;
188
bf3c468 Add debugging method for CallFrame
Evan Phoenix authored
189 std::cout << "<CallFrame:" << (void*)this << " ";
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
190
191 if(native_method_p()) {
192 std::cout << "capi>\n";
193 return;
194 }
195
bf3c468 Add debugging method for CallFrame
Evan Phoenix authored
196 if(is_inline_frame()) {
197 std::cout << "inline ";
198 }
199
200 if(is_block_p(state)) {
201 std::cout << "block ";
fd84366 Fix JIT code unloading
Evan Phoenix authored
202 } else if(dispatch_data) {
392f4bb Dirkjan Bussink Audited usage of char* for Symbols
dbussink authored
203 std::cout << "name=" << name()->debug_str(state) << " ";
bf3c468 Add debugging method for CallFrame
Evan Phoenix authored
204 } else {
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
205 std::cout << "name=" << compiled_code->name()->debug_str(state) << " ";
bf3c468 Add debugging method for CallFrame
Evan Phoenix authored
206 }
207
208 std::cout << "ip=" << ip_ << " ";
209
210 std::cout << "line=" << line(state);
211
212 std::cout << ">\n";
213 }
214
6035068 Rewire debugger infrastructure, add new simple debugger.
Evan Phoenix authored
215 Object* CallFrame::find_breakpoint(STATE) {
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
216 if(!compiled_code) return 0;
cd104c1 Evan Phoenix More fixes for new CAPI CallFrames
evanphx authored
217
149a364 Brian Shirai Cleaned up debris from CompiledMethod rename.
brixen authored
218 LookupTable* tbl = compiled_code->breakpoints();
6035068 Rewire debugger infrastructure, add new simple debugger.
Evan Phoenix authored
219 if(tbl->nil_p()) return 0;
220
221 bool found = false;
222
223 Object* obj = tbl->fetch(state, Fixnum::from(ip()), &found);
224 if(found) return obj;
225
226 return 0;
227 }
228
7773919 Eero Saynatkari Fix caller, top-level exceptions and __printbt__.
rue authored
229 /* For debugging. */
230 extern "C" {
231 void __printbt__(CallFrame* call_frame) {
35a49f3 Evan Phoenix Introduce State class as STATE
evanphx authored
232 State state(VM::current());
233 call_frame->print_backtrace(&state);
7773919 Eero Saynatkari Fix caller, top-level exceptions and __printbt__.
rue authored
234 }
235 }
77c68c4 Checkout. Add CallFrame
Evan Phoenix authored
236 }
Something went wrong with that request. Please try again.