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

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

Unified · Split

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