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/scheduler.cpp (1 of 5 files). Show all

Unified · Split

src/vm/scheduler.cpp+19−2
@@ -5,6 +5,7 @@ · 4 unmodified lines
55 //
66
77 #include <debug.h>
8+#include <sstream>
89 #include <exceptions.h>
910 #include "scheduler.h"
1011
@@ -45,8 +46,24 @@ void default_scheduler_t::worker_main(default_scheduler_t &instance) · 34 unmodified lines
4546 }
4647 catch (const vm_system_exception &se)
4748 {
48− std::printf("%s\n", se.what());
49+ std::stringstream err_msg;
50+ err_msg << se.what() << "\n";
4951
52+ if (current_thread != nullptr)
53+ {
54+ const auto &r = current_thread->vm_thread->get_registers();
55+ walk_stack(r, [&err_msg](const pointer_t, const vm_pc_t pc, const vm_module_ref_t &module_ref)
56+ {
57+ auto module_name = "<No Name>";
58+ if (module_ref.module->module_name != nullptr)
59+ module_name = module_ref.module->module_name->str();
60+
61+ err_msg << "\t" << module_name << "@" << pc << "\n";
62+ return true;
63+ });
64+ }
65+
66+ std::fprintf(stderr, "%s\n", err_msg.str().c_str());
5067 instance._terminating = true;
5168 instance._worker_event.notify_all();
5269 }
@@ -89,7 +106,7 @@ default_scheduler_t::~default_scheduler_t() · 36 unmodified lines
89106 bool default_scheduler_t::is_idle() const
90107 {
91108 std::lock_guard<std::mutex> lock{ _vm_threads_lock };
92− return _running_vm_thread_count == 0 && _runnable_vm_threads.empty() && _blocked_vm_thread_ids.empty() && !_terminating;
109+ return (_terminating) || (_running_vm_thread_count == 0 && _runnable_vm_threads.empty() && _blocked_vm_thread_ids.empty());
93110 }
94111
95112 vm_scheduler_control_t &default_scheduler_t::get_controller() const