History

Add support to debugger to have the last successful command be the default command.

arr committed 9 years ago

Commit ad4a6c31 parent 232a6591 file · +22 −7Browse files

Unified · Split

src/exec/debugger.cpp+22−7
@@ -89,6 +89,8 @@ namespace · 88 unmodified lines
8989 // Debug command context
9090 struct dbg_cmd_cxt_t
9191 {
92+ static std::string last_successful_cmd_option;
93+
9294 dbg_cmd_cxt_t(debugger &d, const vm_registers_t &r)
9395 : dbg{ d }
9496 , exit_break{ false }
@@ -96,9 +98,16 @@ namespace · 1 unmodified line
9698 , vm{ d.controller->get_vm_instance() }
9799 {
98100 current_register = &initial_register;
101+ last_successful_cmd = dbg.get_option(last_successful_cmd_option);
102+ }
103+
104+ ~dbg_cmd_cxt_t()
105+ {
106+ dbg.set_option(last_successful_cmd_option, std::move(last_successful_cmd));
99107 }
100108
101109 bool exit_break;
110+ std::string last_successful_cmd;
102111
103112 debugger &dbg;
104113 const vm_t &vm;
@@ -106,6 +115,8 @@ namespace · 1 unmodified line
106115 const vm_registers_t &initial_register;
107116 };
108117
118+ std::string dbg_cmd_cxt_t::last_successful_cmd_option = "last_successful_cmd";
119+
109120 // Debug command exec operation
110121 using dbg_cmd_exec_t = void(*)(const std::vector<std::string> &, dbg_cmd_cxt_t &cxt);
111122
@@ -379,7 +390,7 @@ namespace · 267 unmodified lines
379390
380391 auto msg = std::stringstream{};
381392 auto module_funcs = cxt.dbg.get_module_functions(vm_id, name_to_match);
382− msg << "[PC range] Function";
393+ msg << " [PC range] Function";
383394 for (auto &f : module_funcs)
384395 msg << "\n " << f;
385396
@@ -650,7 +661,7 @@ namespace · 264 unmodified lines
650661 {
651662 auto op = code_section[curr_pc].op;
652663
653− auto op_prefix = " ";
664+ auto op_prefix = " ";
654665
655666 // If the opcode is a breakpoint then try and replace it with the real opcode
656667 if (op.opcode == opcode_t::brkpt)
@@ -662,7 +673,7 @@ namespace · 5 unmodified lines
662673 if (details.pc == curr_pc && details.module == r.module_ref->module)
663674 {
664675 op.opcode = details.original_opcode;
665− op_prefix = " b";
676+ op_prefix = " b ";
666677 break;
667678 }
668679 }
@@ -929,7 +940,7 @@ namespace · 260 unmodified lines
929940 debug_print_info(msg.str());
930941 }
931942
932− void execute_single_command(dbg_cmd_cxt_t &cxt, const std::string &cmd)
943+ void execute_single_command(dbg_cmd_cxt_t &cxt, std::string cmd)
933944 {
934945 const auto cmd_tokens = util::split(cmd);
935946 if (cmd_tokens.empty())
@@ -939,6 +950,8 @@ namespace · 3 unmodified lines
939950 {
940951 auto cmd_exec = find_cmd(cmd_tokens[0]);
941952 cmd_exec(cmd_tokens, cxt);
953+
954+ cxt.last_successful_cmd = std::move(cmd);
942955 }
943956 catch (const debug_cmd_error_t &e)
944957 {
@@ -969,9 +982,11 @@ namespace · 24 unmodified lines
969982 << console_modifiers::reset_all;
970983
971984 std::getline(std::cin, cmd);
985+ if (cmd.empty())
986+ cmd = cxt.last_successful_cmd;
972987
973988 assert(!cxt.exit_break && "Precondition on exit_break state before execute failed");
974− execute_single_command(cxt, cmd);
989+ execute_single_command(cxt, std::move(cmd));
975990 if (cxt.exit_break)
976991 break;
977992 }
@@ -1178,11 +1193,11 @@ void debugger::on_load(vm_tool_controller_t &controller_, std::size_t tool_id) · 200 unmodified lines
11781193
11791194 debug_print_info(ss.str());
11801195
1181− const auto bp_cmd = get_option({ "bp-cmd" });
1196+ auto bp_cmd = get_option({ "bp-cmd" });
11821197 if (!bp_cmd.empty())
11831198 {
11841199 dbg_cmd_cxt_t dbg_cxt{ *this, *cxt.value1.registers };
1185− execute_single_command(dbg_cxt, bp_cmd);
1200+ execute_single_command(dbg_cxt, std::move(bp_cmd));
11861201 }
11871202
11881203 prompt(*this, *cxt.value1.registers);