History

Additional debugger command (term) Add command line arguments for enabling debugger from exec

Remove tabs from all logging

arr committed 10 years ago

Commit 660681b1 parent e2f8e255 files · +190 −23Browse files

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

Unified · Split

src/exec/debugger.cpp+36−4
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <utils.h>
1414 #include <vm_memory.h>
1515 #include <vm_asm.h>
16+#include <exceptions.h>
1617 #include "exec.h"
1718
1819 using namespace disvm;
@@ -289,6 +290,11 @@ namespace · 270 unmodified lines
289290 cxt.exit_break = true;
290291 }
291292
293+ void cmd_term(const std::vector<std::string> &, dbg_cmd_cxt_t &cxt)
294+ {
295+ throw vm_user_exception{ "Debugger signaled VM termination" };
296+ }
297+
292298 void cmd_print_registers(const std::vector<std::string> &, dbg_cmd_cxt_t &cxt)
293299 {
294300 auto s = registers_to_string(*cxt.current_register);
@@ -740,6 +746,7 @@ namespace · 445 unmodified lines
740746 const dbg_cmd_t cmds[] =
741747 {
742748 { "c", "Continue", nullptr, nullptr, cmd_continue },
749+ { "term", "Terminate the VM instance", nullptr, nullptr, cmd_term },
743750
744751 { "r", "Print registers", nullptr, nullptr, cmd_print_registers },
745752 { "t", "Print all threads", nullptr, nullptr, cmd_print_threads },
@@ -862,8 +869,18 @@ namespace · 116 unmodified lines
862869 }
863870 }
864871
865−debugger::debugger()
866− : _tool_id{ 0 }
872+std::ostream& operator<<(std::ostream &ss, const debugger_options o)
873+{
874+ ss << "Break on enter: " << std::boolalpha << o.break_on_enter << "\n"
875+ << "Break on module load: " << std::boolalpha << o.break_on_module_load << "\n"
876+ << "Break on exception: " << std::boolalpha << o.break_on_exception << "\n";
877+
878+ return ss;
879+}
880+
881+debugger::debugger(const debugger_options &opt)
882+ : _options{ opt }
883+ , _tool_id{ 0 }
867884 , controller{ nullptr }
868885 { }
869886
@@ -896,7 +913,7 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 26 unmodified lines
896913 debug_print_info(ss.str());
897914 }));
898915
899− _event_cookies.push_back(controller->subscribe_event(vm_event_t::exception_raised, [](vm_event_t, vm_event_context_t &cxt)
916+ _event_cookies.push_back(controller->subscribe_event(vm_event_t::exception_raised, [&](vm_event_t, vm_event_context_t &cxt)
900917 {
901918 auto ss = std::stringstream{};
902919 ss << "Exception '"
@@ -904,6 +921,9 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 1 unmodified line
904921 << "' thrown.";
905922
906923 debug_print_info(ss.str());
924+
925+ if (_options.break_on_exception)
926+ prompt(*this, *cxt.value1.registers);
907927 }));
908928
909929 _event_cookies.push_back(controller->subscribe_event(vm_event_t::exception_unhandled, [&](vm_event_t, vm_event_context_t &cxt)
@@ -928,8 +948,20 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 18 unmodified lines
928948 if (util::has_flag(m->header.runtime_flag, runtime_flags_t::builtin))
929949 ss << " (built-in)";
930950
931−
932951 debug_print_info(ss.str());
952+
953+ // If the break on enter flag was set, it will be true
954+ // and the first module load will be the user entry module.
955+ if (_options.break_on_enter)
956+ {
957+ // Reset the break on enter flag and set a breakpoint
958+ // on the entry PC for the module - 'break on enter'
959+ _options.break_on_enter = false;
960+ controller->set_breakpoint(m, m->header.entry_pc);
961+ }
962+
963+ if (_options.break_on_module_load)
964+ prompt(*this, *cxt.value1.registers);
933965 }));
934966
935967 _event_cookies.push_back(controller->subscribe_event(vm_event_t::breakpoint, [&](vm_event_t, vm_event_context_t &cxt)