Revision: 2818 Author: [email protected] Date: Wed Sep 2 07:46:40 2009 Log: Fix the debugger in the ARM simulator.
The debugger in the ARM simulator is now working again. Added a help command and a command to print all registers. Made the printobject command print something in release builds. Review URL: http://codereview.chromium.org/191004 http://code.google.com/p/v8/source/detail?r=2818 Modified: /branches/bleeding_edge/src/arm/simulator-arm.cc ======================================= --- /branches/bleeding_edge/src/arm/simulator-arm.cc Mon Aug 31 05:40:37 2009 +++ /branches/bleeding_edge/src/arm/simulator-arm.cc Wed Sep 2 07:46:40 2009 @@ -70,7 +70,7 @@ Simulator* sim_; - bool GetValue(char* desc, int32_t* value); + bool GetValue(const char* desc, int32_t* value); // Set or delete a breakpoint. Returns true if successful. bool SetBreakpoint(Instr* breakpc); @@ -132,6 +132,8 @@ #endif +// The order of these are important, see the handling of the 'print all' +// debugger command. static const char* reg_names[] = { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", @@ -147,7 +149,7 @@ 11, 10}; -static int RegNameToRegNum(char* name) { +static int RegNameToRegNum(const char* name) { int reg = 0; while (*reg_names[reg] != 0) { if (strcmp(reg_names[reg], name) == 0) { @@ -159,7 +161,7 @@ } -bool Debugger::GetValue(char* desc, int32_t* value) { +bool Debugger::GetValue(const char* desc, int32_t* value) { int regnum = RegNameToRegNum(desc); if (regnum >= 0) { if (regnum == 15) { @@ -246,7 +248,7 @@ v8::internal::EmbeddedVector<char, 256> buffer; dasm.InstructionDecode(buffer, reinterpret_cast<byte*>(sim_->get_pc())); - PrintF(" 0x%x %s\n", sim_->get_pc(), buffer.start()); + PrintF(" 0x%08x %s\n", sim_->get_pc(), buffer.start()); last_pc = sim_->get_pc(); } char* line = ReadLine("sim> "); @@ -270,13 +272,25 @@ } else if ((strcmp(cmd, "p") == 0) || (strcmp(cmd, "print") == 0)) { if (args == 2) { int32_t value; - if (GetValue(arg1, &value)) { - PrintF("%s: %d 0x%x\n", arg1, value, value); + if (strcmp(arg1, "all") == 0) { + for (int i = 0; i <= 15; i++) { + if (GetValue(reg_names[i], &value)) { + if (i <= 10) { + PrintF("%3s: 0x%08x %d\n", reg_names[i], value, value); + } else { + PrintF("%3s: 0x%08x %d\n", reg_names[15 + 16 - i], value, value); + } + } + } } else { - PrintF("%s unrecognized\n", arg1); + if (GetValue(arg1, &value)) { + PrintF("%s: 0x%08x %d \n", arg1, value, value); + } else { + PrintF("%s unrecognized\n", arg1); + } } } else { - PrintF("print value\n"); + PrintF("print <register>\n"); } } else if ((strcmp(cmd, "po") == 0) || (strcmp(cmd, "printobject") == 0)) { @@ -286,14 +300,17 @@ Object* obj = reinterpret_cast<Object*>(value); USE(obj); PrintF("%s: \n", arg1); -#if defined(DEBUG) +#ifdef DEBUG obj->PrintLn(); -#endif // defined(DEBUG) +#else + obj->ShortPrint(); + PrintF("\n"); +#endif } else { PrintF("%s unrecognized\n", arg1); } } else { - PrintF("printobject value\n"); + PrintF("printobject <value>\n"); } } else if (strcmp(cmd, "disasm") == 0) { disasm::NameConverter converter; @@ -325,7 +342,7 @@ while (cur < end) { dasm.InstructionDecode(buffer, cur); - PrintF(" 0x%x %s\n", cur, buffer.start()); + PrintF(" 0x%08x %s\n", cur, buffer.start()); cur += Instr::kInstrSize; } } else if (strcmp(cmd, "gdb") == 0) { @@ -343,7 +360,7 @@ PrintF("%s unrecognized\n", arg1); } } else { - PrintF("break addr\n"); + PrintF("break <address>\n"); } } else if (strcmp(cmd, "del") == 0) { if (!DeleteBreakpoint(NULL)) { @@ -362,6 +379,30 @@ } else { PrintF("Not at debugger stop."); } + } else if ((strcmp(cmd, "h") == 0) || (strcmp(cmd, "help") == 0)) { + PrintF("cont\n"); + PrintF(" continue execution (alias 'c')\n"); + PrintF("stepi\n"); + PrintF(" step one instruction (alias 'si')\n"); + PrintF("print <register>\n"); + PrintF(" print register content (alias 'p')\n"); + PrintF(" use register name 'all' to print all registers\n"); + PrintF("printobject <register>\n"); + PrintF(" print an object from a register (alias 'po')\n"); + PrintF("flags\n"); + PrintF(" print flags\n"); + PrintF("disasm [<instructions>]\n"); + PrintF("disasm [[<address>] <instructions>]\n"); + PrintF(" disassemble code, default is 10 instructions from pc\n"); + PrintF("gdb\n"); + PrintF(" enter gdb\n"); + PrintF("break <address>\n"); + PrintF(" set a break point on the address\n"); + PrintF("del\n"); + PrintF(" delete the breakpoint\n"); + PrintF("unstop\n"); + PrintF(" ignore the stop instruction at the current location"); + PrintF(" from now on\n"); } else { PrintF("Unknown command: %s\n", cmd); } @@ -576,7 +617,7 @@ intptr_t* ptr = reinterpret_cast<intptr_t*>(addr); return *ptr; } - PrintF("Unaligned read at %x\n", addr); + PrintF("Unaligned read at 0x%08x\n", addr); UNIMPLEMENTED(); return 0; } @@ -588,7 +629,7 @@ *ptr = value; return; } - PrintF("Unaligned write at %x, pc=%p\n", addr, instr); + PrintF("Unaligned write at 0x%08x, pc=%p\n", addr, instr); UNIMPLEMENTED(); } @@ -598,7 +639,7 @@ uint16_t* ptr = reinterpret_cast<uint16_t*>(addr); return *ptr; } - PrintF("Unaligned unsigned halfword read at %x, pc=%p\n", addr, instr); + PrintF("Unaligned unsigned halfword read at 0x%08x, pc=%p\n", addr, instr); UNIMPLEMENTED(); return 0; } @@ -609,7 +650,7 @@ int16_t* ptr = reinterpret_cast<int16_t*>(addr); return *ptr; } - PrintF("Unaligned signed halfword read at %x\n", addr); + PrintF("Unaligned signed halfword read at 0x%08x\n", addr); UNIMPLEMENTED(); return 0; } @@ -621,7 +662,7 @@ *ptr = value; return; } - PrintF("Unaligned unsigned halfword write at %x, pc=%p\n", addr, instr); + PrintF("Unaligned unsigned halfword write at 0x%08x, pc=%p\n", addr, instr); UNIMPLEMENTED(); } @@ -632,7 +673,7 @@ *ptr = value; return; } - PrintF("Unaligned halfword write at %x, pc=%p\n", addr, instr); + PrintF("Unaligned halfword write at 0x%08x, pc=%p\n", addr, instr); UNIMPLEMENTED(); } @@ -671,7 +712,7 @@ // Unsupported instructions use Format to print an error and stop execution. void Simulator::Format(Instr* instr, const char* format) { - PrintF("Simulator found unsupported instruction:\n 0x%x: %s\n", + PrintF("Simulator found unsupported instruction:\n 0x%08x: %s\n", instr, format); UNIMPLEMENTED(); } @@ -1726,7 +1767,8 @@ uint16_t halfword = ReadH(addr, instr); set_register(rd, halfword); } else { - UNIMPLEMENTED(); + Debugger dbg(this); + dbg.Stop(instr); } } @@ -1741,7 +1783,7 @@ v8::internal::EmbeddedVector<char, 256> buffer; dasm.InstructionDecode(buffer, reinterpret_cast<byte*>(instr)); - PrintF(" 0x%x %s\n", instr, buffer.start()); + PrintF(" 0x%08x %s\n", instr, buffer.start()); } if (instr->ConditionField() == special_condition) { DecodeUnconditional(instr); --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
