History

Change nullptr return value in debugger to an exception. Pull out the split() function from the debugger and push it into utils.h.

arr committed 9 years ago

Commit 2e5c41c1 parent 551c5002 files · +40 −40Browse files

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

Unified · Split

src/exec/debugger.cpp+3−37
@@ -770,7 +770,7 @@ namespace · 769 unmodified lines
770770 }
771771
772772 // [TODO] Didn't find the cmd, try ignoring case?
773− return nullptr;
773+ throw debug_cmd_error_t{ "Unknown command. '?' for help." };
774774 }
775775
776776 void print_help()
@@ -797,31 +797,6 @@ namespace · 20 unmodified lines
797797 debug_print_info(ss.str());
798798 }
799799
800− // split the string using the supplied delimiter
801− std::vector<std::string> split(const std::string &str, const char delim = ' ')
802− {
803− auto split_string = std::vector<std::string>{};
804−
805− auto curr = str.begin();
806− auto end = str.cend();
807− while (curr != end)
808− {
809− auto curr_begin = curr;
810− while (curr != end && *curr != delim)
811− ++curr;
812−
813− if (curr_begin != curr)
814− split_string.push_back(std::move(std::string{ curr_begin, curr }));
815−
816− if (curr == end)
817− break;
818−
819− ++curr;
820− }
821−
822− return split_string;
823− }
824−
825800 void prompt(debugger &debugger, const vm_registers_t &r)
826801 {
827802 debugger.controller->suspend_all_threads();
@@ -845,22 +820,13 @@ namespace · 17 unmodified lines
845820 << console_modifiers::reset_all;
846821
847822 std::getline(std::cin, cmd);
848− if (cmd.empty())
849− continue;
850−
851− const auto cmd_tokens = split(cmd);
823+ const auto cmd_tokens = util::split(cmd);
852824 if (cmd_tokens.empty())
853825 continue;
854826
855− auto cmd_exec = find_cmd(cmd_tokens[0]);
856− if (cmd_exec == nullptr)
857− {
858− debug_print_error("Unknown command. '?' for help.");
859− continue;
860− }
861−
862827 try
863828 {
829+ auto cmd_exec = find_cmd(cmd_tokens[0]);
864830 cmd_exec(cmd_tokens, cxt);
865831 if (cxt.exit_break)
866832 break;