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
770 }770 }
771 771
772 // [TODO] Didn't find the cmd, try ignoring case?772 // [TODO] Didn't find the cmd, try ignoring case?
773 return nullptr;773 throw debug_cmd_error_t{ "Unknown command. '?' for help." };
774 }774 }
775 775
776 void print_help()776 void print_help()
@@ -797,31 +797,6 @@ namespace · 20 unmodified lines
797 debug_print_info(ss.str());797 debug_print_info(ss.str());
798 }798 }
799 799
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
825 void prompt(debugger &debugger, const vm_registers_t &r)800 void prompt(debugger &debugger, const vm_registers_t &r)
826 {801 {
827 debugger.controller->suspend_all_threads();802 debugger.controller->suspend_all_threads();
@@ -845,22 +820,13 @@ namespace · 17 unmodified lines
845 << console_modifiers::reset_all;820 << console_modifiers::reset_all;
846 821
847 std::getline(std::cin, cmd);822 std::getline(std::cin, cmd);
848 if (cmd.empty())823 const auto cmd_tokens = util::split(cmd);
849 continue;
850
851 const auto cmd_tokens = split(cmd);
852 if (cmd_tokens.empty())824 if (cmd_tokens.empty())
853 continue;825 continue;
854 826
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
862 try827 try
863 {828 {
829 auto cmd_exec = find_cmd(cmd_tokens[0]);
864 cmd_exec(cmd_tokens, cxt);830 cmd_exec(cmd_tokens, cxt);
865 if (cxt.exit_break)831 if (cxt.exit_break)
866 break;832 break;