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
389 if (pc < 0 || module->code_section.size() <= static_cast<std::size_t>(pc))389 if (pc < 0 || module->code_section.size() <= static_cast<std::size_t>(pc))
390 throw debug_cmd_error_t{ "Invalid IP for module" };390 throw debug_cmd_error_t{ "Invalid IP for module" };
391 391
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 }
393 }400 }
394 401
395 void cmd_breakpoint_clear(const std::vector<std::string> &a, dbg_cmd_cxt_t &cxt)402 void cmd_breakpoint_clear(const std::vector<std::string> &a, dbg_cmd_cxt_t &cxt)
@@ -536,7 +543,7 @@ namespace · 140 unmodified lines
536 543
537 void cmd_disassemble(const std::vector<std::string> &a, dbg_cmd_cxt_t &cxt)544 void cmd_disassemble(const std::vector<std::string> &a, dbg_cmd_cxt_t &cxt)
538 {545 {
539 auto disassemble_length = int{ 1 };546 auto disassemble_length = int{ 4 };
540 if (a.size() > 1)547 if (a.size() > 1)
541 {548 {
542 try549 try
@@ -567,7 +574,29 @@ namespace · 24 unmodified lines
567 574
568 auto msg = std::stringstream{};575 auto msg = std::stringstream{};
569 for (auto i = begin_index; i < end_index; ++i)576 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 }
571 600
572 debug_print_info(msg.str());601 debug_print_info(msg.str());
573 }602 }
@@ -727,7 +756,7 @@ namespace · 153 unmodified lines
727 756
728 { "sw", "Stack walk for the current or supplied thread", "sw ([0-9]+|\\*)?", "sw, sw 34, sw *", cmd_stackwalk },757 { "sw", "Stack walk for the current or supplied thread", "sw ([0-9]+|\\*)?", "sw, sw 34, sw *", cmd_stackwalk },
729 { "~", "Switch to thread", "~ [0-9]+", "~ 42", cmd_switchthread },758 { "~", "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 },
731 { "x", "Examine memory", "x [mp|fp] [0-9]+ ([0-9]+)?", "x mp 3, x fp 20 6", cmd_examine },760 { "x", "Examine memory", "x [mp|fp] [0-9]+ ([0-9]+)?", "x mp 3, x fp 20 6", cmd_examine },
732 { "?", "Print help", nullptr, nullptr, cmd_help },761 { "?", "Print help", nullptr, nullptr, cmd_help },
733 762
src/include/opcodes.h+3−1
@@ -7,10 +7,12 @@ · 6 unmodified lines
7#ifndef _DISVM_SRC_INCLUDE_OPCODES_H_7#ifndef _DISVM_SRC_INCLUDE_OPCODES_H_
8#define _DISVM_SRC_INCLUDE_OPCODES_H_8#define _DISVM_SRC_INCLUDE_OPCODES_H_
9 9
10#include <cstdint>
11
10namespace disvm12namespace disvm
11{13{
12 // Instruction codes for the Dis VM14 // Instruction codes for the Dis VM
13 enum class opcode_t15 enum class opcode_t : uint8_t
14 {16 {
15 invalid = 0,17 invalid = 0,
16 alt,18 alt,
src/include/vm_tools.h+1−0
@@ -69,6 +69,7 @@ namespace disvm · 68 unmodified lines
69 {69 {
70 std::shared_ptr<vm_module_t> module;70 std::shared_ptr<vm_module_t> module;
71 vm_pc_t pc;71 vm_pc_t pc;
72 opcode_t original_opcode;
72 };73 };
73 74
74 // VM tool controller75 // 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
251 const auto cookie_id = _breakpoints.cookie_counter++;251 const auto cookie_id = _breakpoints.cookie_counter++;
252 252
253 // Map the cookie to the module/pc pair.253 // 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 };
255 255
256 // Record the original opcode256 // Record the original opcode
257 auto &pc_map = _breakpoints.original_opcodes[reinterpret_cast<std::uintptr_t>(module.get())];257 auto &pc_map = _breakpoints.original_opcodes[reinterpret_cast<std::uintptr_t>(module.get())];