History

Debugger disassemble defaults to 4 instructions. Disasembler in debugger now replaces breakpoint opcode with real if it was replaced. Fix bug when setting breakpoint at same location twice.

arr committed 10 years ago

Commit f29cf0d1 parent 754ca824 files · +38 −6Browse files

Unified · Split

4 files
  1. src/exec/debugger.cpp +33 −4
  2. src/include/opcodes.h +3 −1
  3. src/include/vm_tools.h +1 −0
  4. src/vm/tool_dispatch.cpp +1 −1
src/exec/debugger.cpp+33−4
@@ -389,7 +389,14 @@ namespace · 388 unmodified lines
389389 if (pc < 0 || module->code_section.size() <= static_cast<std::size_t>(pc))
390390 throw debug_cmd_error_t{ "Invalid IP for module" };
391391
392− cxt.dbg.breakpoint_cookies.push_back(cxt.dbg.controller->set_breakpoint(module, pc));
392+ try
393+ {
394+ cxt.dbg.breakpoint_cookies.push_back(cxt.dbg.controller->set_breakpoint(module, pc));
395+ }
396+ catch (const vm_system_exception& e)
397+ {
398+ throw debug_cmd_error_t{ e.what() };
399+ }
393400 }
394401
395402 void cmd_breakpoint_clear(const std::vector<std::string> &a, dbg_cmd_cxt_t &cxt)
@@ -536,7 +543,7 @@ namespace · 140 unmodified lines
536543
537544 void cmd_disassemble(const std::vector<std::string> &a, dbg_cmd_cxt_t &cxt)
538545 {
539− auto disassemble_length = int{ 1 };
546+ auto disassemble_length = int{ 4 };
540547 if (a.size() > 1)
541548 {
542549 try
@@ -567,7 +574,29 @@ namespace · 24 unmodified lines
567574
568575 auto msg = std::stringstream{};
569576 for (auto i = begin_index; i < end_index; ++i)
570− msg << " " << std::setw(5) << i << ": " << code_section[i].op << "\n";
577+ {
578+ auto op = code_section[i].op;
579+
580+ auto op_prefix = " ";
581+
582+ // If the opcode is a breakpoint then try and replace it with the real opcode
583+ if (op.opcode == opcode_t::brkpt)
584+ {
585+ // Look up each of the known cookies to try and find the matching PC and module
586+ for (auto bp_cookie : cxt.dbg.breakpoint_cookies)
587+ {
588+ const auto details = cxt.dbg.controller->get_breakpoint_details(bp_cookie);
589+ if (details.pc == i && details.module == r.module_ref->module)
590+ {
591+ op.opcode = details.original_opcode;
592+ op_prefix = " b";
593+ break;
594+ }
595+ }
596+ }
597+
598+ msg << op_prefix << std::setw(5) << i << ": " << op << "\n";
599+ }
571600
572601 debug_print_info(msg.str());
573602 }
@@ -727,7 +756,7 @@ namespace · 153 unmodified lines
727756
728757 { "sw", "Stack walk for the current or supplied thread", "sw ([0-9]+|\\*)?", "sw, sw 34, sw *", cmd_stackwalk },
729758 { "~", "Switch to thread", "~ [0-9]+", "~ 42", cmd_switchthread },
730− { "d", "Disassemble the next/previous N instructions", "d (-?[0-9]+)?", "d, d -4, d 5", cmd_disassemble },
759+ { "d", "Disassemble the next/previous N instructions (default N = 4)", "d (-?[0-9]+)?", "d, d -4, d 5", cmd_disassemble },
731760 { "x", "Examine memory", "x [mp|fp] [0-9]+ ([0-9]+)?", "x mp 3, x fp 20 6", cmd_examine },
732761 { "?", "Print help", nullptr, nullptr, cmd_help },
733762
src/include/opcodes.h+3−1
@@ -7,10 +7,12 @@ · 6 unmodified lines
77 #ifndef _DISVM_SRC_INCLUDE_OPCODES_H_
88 #define _DISVM_SRC_INCLUDE_OPCODES_H_
99
10+#include <cstdint>
11+
1012 namespace disvm
1113 {
1214 // Instruction codes for the Dis VM
13− enum class opcode_t
15+ enum class opcode_t : uint8_t
1416 {
1517 invalid = 0,
1618 alt,
src/include/vm_tools.h+1−0
@@ -69,6 +69,7 @@ namespace disvm · 68 unmodified lines
6969 {
7070 std::shared_ptr<vm_module_t> module;
7171 vm_pc_t pc;
72+ opcode_t original_opcode;
7273 };
7374
7475 // VM tool controller
src/vm/tool_dispatch.cpp+1−1
@@ -251,7 +251,7 @@ cookie_t vm_tool_dispatch_t::set_breakpoint(std::shared_ptr<vm_module_t> module, · 250 unmodified lines
251251 const auto cookie_id = _breakpoints.cookie_counter++;
252252
253253 // Map the cookie to the module/pc pair.
254− _breakpoints.cookie_to_details[cookie_id] = { module, pc };
254+ _breakpoints.cookie_to_details[cookie_id] = { module, pc, real_opcode };
255255
256256 // Record the original opcode
257257 auto &pc_map = _breakpoints.original_opcodes[reinterpret_cast<std::uintptr_t>(module.get())];