160 likes | 263 Views
Minimal Stub for remote debugging. Minheng Tan Columbia University. My project - debugger stub. My GDBServer debugger stub. Runs on Red Hat Linux, x86 Provides minimum command support(but facilitates all debugging requirements) Speaks Remote Serial Protocol (RSP) over tcp/ip
E N D
Minimal Stub for remote debugging Minheng Tan Columbia University
My project - debugger stub • My GDBServer debugger stub. • Runs on Red Hat Linux, x86 • Provides minimum command support(but facilitates all debugging requirements) • Speaks Remote Serial Protocol (RSP) over tcp/ip • Debugs most applications running Linux.
Debuggers • MSDev • Windbg • dbx • gdb
Remote Debugging Chip Machine A Debugger Program Stub
Remote Debugging …continued Read register 3, Read memory at 0x338828, Write “CC” at 0x380280, Continue program. Machine A Debugger
Remote Debugging …continued Register 3 is 0x75939ff3, Memory content at 0x338828 is 0x094833, Memory content written, Program resumed execution. Chip Program Stub
Remote Serial Protocol • Request/Reply protocol • ASCII encoding • Packet based. • Simple to parse, implement, extend. • Runs on almost all communication medium
RSP commands implemented • “g” – read all register • “G” – write all register • “m” – read memory from a memory at specific address • “M” – write data to memory at specific address • “?” – Get last signal(what happened to the program)
RSP commands implements…continued • “s” – step the program. Make the debugged program execute 1 instruction and relinquish control. • “c” – continue the program. Resume the debugged program and wait until it stop on a breakpoint, bus error, access violation, etc…
Implement read register • buf = malloc (regset->size); • res = ptrace (PTRACE_GETREGS, childpid, 0, buf);
Implement write register • regset->fill_function (buf); • res = ptrace (PTRACE_SETREGS, childpid, 0, (int) buf);
Implement read memory • i = 0; • while (startAddr <= endAddr) { • buffer[i++] = ptrace(PTRACE_PEEKTEXT, childpid, startAddr, 0 ); • startAddr+=sizeof(PTRACE_XFER_TYPE); • }
Implement write memory • i = 0; • while ( startAddr <= endAddr ) { • ptrace (PTRACE_POKETEXT, childpid, startAddr, buffer[i++]); • StartAddr+=sizeof(PTRACE_XFER_TYPE); • }
Implement Step/Continue • ptrace (PTRACE_CONT, childpid, 1, 0); • ptrace (PTRACE_SINGLESTEP, childpid, 1, 0);
Summary • Minimum commands implemented • Packet based remote serial protocol. • Debugger uses the bare minimum stub to implement big things.