Remove tabs from all logging
Showing the changes to src/exec/debugger.cpp (1 of 5 files). Show all
Unified · Split
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | #include <utils.h> |
| 14 | 14 | #include <vm_memory.h> |
| 15 | 15 | #include <vm_asm.h> |
| 16 | +#include <exceptions.h> | |
| 16 | 17 | #include "exec.h" |
| 17 | 18 | |
| 18 | 19 | using namespace disvm; |
| @@ -289,6 +290,11 @@ namespace · 270 unmodified lines | ||
| 289 | 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 | 298 | void cmd_print_registers(const std::vector<std::string> &, dbg_cmd_cxt_t &cxt) |
| 293 | 299 | { |
| 294 | 300 | auto s = registers_to_string(*cxt.current_register); |
| @@ -740,6 +746,7 @@ namespace · 445 unmodified lines | ||
| 740 | 746 | const dbg_cmd_t cmds[] = |
| 741 | 747 | { |
| 742 | 748 | { "c", "Continue", nullptr, nullptr, cmd_continue }, |
| 749 | + { "term", "Terminate the VM instance", nullptr, nullptr, cmd_term }, | |
| 743 | 750 | |
| 744 | 751 | { "r", "Print registers", nullptr, nullptr, cmd_print_registers }, |
| 745 | 752 | { "t", "Print all threads", nullptr, nullptr, cmd_print_threads }, |
| @@ -862,8 +869,18 @@ namespace · 116 unmodified lines | ||
| 862 | 869 | } |
| 863 | 870 | } |
| 864 | 871 | |
| 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 } | |
| 867 | 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 | 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 | 918 | auto ss = std::stringstream{}; |
| 902 | 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 | 921 | << "' thrown."; |
| 905 | 922 | |
| 906 | 923 | debug_print_info(ss.str()); |
| 924 | + | |
| 925 | + if (_options.break_on_exception) | |
| 926 | + prompt(*this, *cxt.value1.registers); | |
| 907 | 927 | })); |
| 908 | 928 | |
| 909 | 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 | 948 | if (util::has_flag(m->header.runtime_flag, runtime_flags_t::builtin)) |
| 929 | 949 | ss << " (built-in)"; |
| 930 | 950 | |
| 931 | − | |
| 932 | 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 | 967 | _event_cookies.push_back(controller->subscribe_event(vm_event_t::breakpoint, [&](vm_event_t, vm_event_context_t &cxt) |