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
13#include <utils.h>13#include <utils.h>
14#include <vm_memory.h>14#include <vm_memory.h>
15#include <vm_asm.h>15#include <vm_asm.h>
16#include <exceptions.h>
16#include "exec.h"17#include "exec.h"
17 18
18using namespace disvm;19using namespace disvm;
@@ -289,6 +290,11 @@ namespace · 270 unmodified lines
289 cxt.exit_break = true;290 cxt.exit_break = true;
290 }291 }
291 292
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
292 void cmd_print_registers(const std::vector<std::string> &, dbg_cmd_cxt_t &cxt)298 void cmd_print_registers(const std::vector<std::string> &, dbg_cmd_cxt_t &cxt)
293 {299 {
294 auto s = registers_to_string(*cxt.current_register);300 auto s = registers_to_string(*cxt.current_register);
@@ -740,6 +746,7 @@ namespace · 445 unmodified lines
740 const dbg_cmd_t cmds[] =746 const dbg_cmd_t cmds[] =
741 {747 {
742 { "c", "Continue", nullptr, nullptr, cmd_continue },748 { "c", "Continue", nullptr, nullptr, cmd_continue },
749 { "term", "Terminate the VM instance", nullptr, nullptr, cmd_term },
743 750
744 { "r", "Print registers", nullptr, nullptr, cmd_print_registers },751 { "r", "Print registers", nullptr, nullptr, cmd_print_registers },
745 { "t", "Print all threads", nullptr, nullptr, cmd_print_threads },752 { "t", "Print all threads", nullptr, nullptr, cmd_print_threads },
@@ -862,8 +869,18 @@ namespace · 116 unmodified lines
862 }869 }
863}870}
864 871
865debugger::debugger()872std::ostream& operator<<(std::ostream &ss, const debugger_options o)
866 : _tool_id{ 0 }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
881debugger::debugger(const debugger_options &opt)
882 : _options{ opt }
883 , _tool_id{ 0 }
867 , controller{ nullptr }884 , controller{ nullptr }
868{ }885{ }
869 886
@@ -896,7 +913,7 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 26 unmodified lines
896 debug_print_info(ss.str());913 debug_print_info(ss.str());
897 }));914 }));
898 915
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)
900 {917 {
901 auto ss = std::stringstream{};918 auto ss = std::stringstream{};
902 ss << "Exception '"919 ss << "Exception '"
@@ -904,6 +921,9 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 1 unmodified line
904 << "' thrown.";921 << "' thrown.";
905 922
906 debug_print_info(ss.str());923 debug_print_info(ss.str());
924
925 if (_options.break_on_exception)
926 prompt(*this, *cxt.value1.registers);
907 }));927 }));
908 928
909 _event_cookies.push_back(controller->subscribe_event(vm_event_t::exception_unhandled, [&](vm_event_t, vm_event_context_t &cxt)929 _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
928 if (util::has_flag(m->header.runtime_flag, runtime_flags_t::builtin))948 if (util::has_flag(m->header.runtime_flag, runtime_flags_t::builtin))
929 ss << " (built-in)";949 ss << " (built-in)";
930 950
931
932 debug_print_info(ss.str());951 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);
933 }));965 }));
934 966
935 _event_cookies.push_back(controller->subscribe_event(vm_event_t::breakpoint, [&](vm_event_t, vm_event_context_t &cxt)967 _event_cookies.push_back(controller->subscribe_event(vm_event_t::breakpoint, [&](vm_event_t, vm_event_context_t &cxt)