diff --git a/cpu/ppc/ppcexec.cpp b/cpu/ppc/ppcexec.cpp index ee7dabf..ce918a0 100644 --- a/cpu/ppc/ppcexec.cpp +++ b/cpu/ppc/ppcexec.cpp @@ -817,14 +817,15 @@ void ppc_cpu_init(uint32_t proc_version) void print_gprs() { for (int i = 0; i < 32; i++) - cout << "GPR " << dec << i << " : " << hex << ppc_state.ppc_gpr[i] << endl; + cout << "GPR " << dec << i << " : " << uppercase << hex + << ppc_state.ppc_gpr[i] << endl; - cout << "PC: " << hex << ppc_state.ppc_pc << endl; - cout << "LR: " << hex << ppc_state.ppc_spr[SPR::LR] << endl; - cout << "CR: " << hex << ppc_state.ppc_cr << endl; - cout << "CTR: " << hex << ppc_state.ppc_spr[SPR::CTR] << endl; - cout << "XER: " << hex << ppc_state.ppc_spr[SPR::XER] << endl; - cout << "MSR: " << hex << ppc_state.ppc_msr << endl; + cout << "PC: " << uppercase << hex << ppc_state.ppc_pc << endl; + cout << "LR: " << uppercase << hex << ppc_state.ppc_spr[SPR::LR] << endl; + cout << "CR: " << uppercase << hex << ppc_state.ppc_cr << endl; + cout << "CTR: " << uppercase << hex << ppc_state.ppc_spr[SPR::CTR] << endl; + cout << "XER: " << uppercase << hex << ppc_state.ppc_spr[SPR::XER] << endl; + cout << "MSR: " << uppercase << hex << ppc_state.ppc_msr << endl; } void print_fprs() diff --git a/debugger/debugger.cpp b/debugger/debugger.cpp index 8b598d6..8098e3d 100644 --- a/debugger/debugger.cpp +++ b/debugger/debugger.cpp @@ -88,9 +88,16 @@ static void dump_mem(string& params) uint32_t count, addr; uint64_t val; string num_type_str, addr_str; + size_t separator_pos; - num_type_str = params.substr(0, params.find(",")); - addr_str = params.substr(params.find(",") + 1); + separator_pos = params.find_first_of(","); + if (separator_pos == std::string::npos) { + cout << "dump: not enough arguments specified." << endl; + return; + } + + num_type_str = params.substr(0, params.find_first_of(",")); + addr_str = params.substr(params.find_first_of(",") + 1); is_char = false; @@ -175,9 +182,11 @@ static void dump_mem(string& params) void enter_debugger() { - string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str, inst_string, inst_num_str; + string inp, cmd, addr_str, expr_str, reg_expr, last_cmd, reg_value_str, + inst_string, inst_num_str; uint32_t addr, inst_grab; std::stringstream ss; + size_t separator_pos; cout << "Welcome to the DingusPPC command line debugger." << endl; cout << "Please enter a command or 'help'." << endl << endl; @@ -216,9 +225,16 @@ void enter_debugger() } else if (cmd == "set") { ss >> expr_str; + + separator_pos = expr_str.find_first_of("="); + if (separator_pos == std::string::npos) { + cout << "set: not enough arguments specified." << endl; + continue; + } + try { - reg_expr = expr_str.substr(0, expr_str.find("=")); - addr_str = expr_str.substr(expr_str.find("=") + 1); + reg_expr = expr_str.substr(0, expr_str.find_first_of("=")); + addr_str = expr_str.substr(expr_str.find_first_of("=") + 1); addr = str2addr(addr_str); set_reg(reg_expr, addr); } @@ -248,9 +264,14 @@ void enter_debugger() expr_str = ""; ss >> expr_str; if (expr_str.length() > 0) { - inst_num_str = expr_str.substr(0, expr_str.find(",")); + separator_pos = expr_str.find_first_of(","); + if (separator_pos == std::string::npos) { + cout << "disas: not enough arguments specified." << endl; + continue; + } + inst_num_str = expr_str.substr(0, expr_str.find_first_of(",")); inst_grab = stol(inst_num_str, NULL, 0); - addr_str = expr_str.substr(expr_str.find(",") + 1); + addr_str = expr_str.substr(expr_str.find_first_of(",") + 1); try { addr = str2addr(addr_str); } @@ -272,6 +293,7 @@ void enter_debugger() } } else { + /* disas without arguments defaults to disas 1,pc */ addr_str = "PC"; addr = get_reg(addr_str); disasm(1, addr);