History

Name the entry module in the exec program. Re-write stack walking function for debugger. System exceptions now print out call stack.

arr committed 10 years ago

Commit 794ecfc1 parent 4f6417b5 files · +54 −35Browse files

Showing the changes to src/vm/thread.cpp (1 of 5 files). Show all

Unified · Split

src/vm/thread.cpp+24−3
@@ -153,6 +153,27 @@ vm_registers_t::~vm_registers_t() · 152 unmodified lines
153153 debug::assign_debug_pointer(&module_ref);
154154 }
155155
156+void disvm::runtime::walk_stack(const vm_registers_t &r, vm_stack_walk_callback_t callback)
157+{
158+ assert(callback != nullptr);
159+
160+ auto current_pc = r.pc;
161+ auto current_module = r.module_ref;
162+ auto current_frame = r.stack.peek_frame();
163+ while (current_frame != nullptr)
164+ {
165+ if (!callback(current_frame->base(), current_pc, *current_module))
166+ break;
167+
168+ current_pc = current_frame->prev_pc();
169+ auto prev_module_maybe = current_frame->prev_module_ref();
170+ if (prev_module_maybe != nullptr)
171+ current_module = prev_module_maybe;
172+
173+ current_frame = current_frame->prev_frame();
174+ }
175+}
176+
156177 std::shared_ptr<const type_descriptor_t> vm_thread_t::type_desc()
157178 {
158179 return intrinsic_type_desc::type<vm_thread_t>();
@@ -252,17 +273,17 @@ vm_thread_state_t vm_thread_t::execute(vm_t &virtual_machine, const uint32_t qua · 93 unmodified lines
252273 catch (const unhandled_user_exception &uue)
253274 {
254275 // [TODO] Store the exception
255− std::printf("%s - %s in %s at instruction %d\n", uue.what(), uue.exception_id, uue.module_name, uue.program_counter);
276+ std::fprintf(stderr, "%s - %s in %s at instruction %d\n", uue.what(), uue.exception_id, uue.module_name, uue.program_counter);
256277 _registers.current_thread_state = vm_thread_state_t::broken;
257278 }
258279 catch (const index_out_of_range_memory &ioor)
259280 {
260− std::printf("%s - %d [%d,%d]\n", ioor.what(), ioor.invalid_value, ioor.valid_min, ioor.valid_max);
281+ std::fprintf(stderr, "%s - %d [%d,%d]\n", ioor.what(), ioor.invalid_value, ioor.valid_min, ioor.valid_max);
261282 _registers.current_thread_state = vm_thread_state_t::broken;
262283 }
263284 catch (const vm_user_exception &ue)
264285 {
265− std::printf("%s\n", ue.what());
286+ std::fprintf(stderr, "%s\n", ue.what());
266287 _registers.current_thread_state = vm_thread_state_t::broken;
267288 }
268289