Title: Minimal Stub for remote debugging
1Minimal Stub for remote debugging
- Minheng Tan
- Columbia University
2My 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.
3Debuggers
4Remote Debugging
Chip
Machine A
Debugger
Program
Stub
5Remote Debugging continued
Read register 3, Read memory at 0x338828, Write
CC at 0x380280, Continue program.
Machine A
Debugger
6Remote Debugging continued
Register 3 is 0x75939ff3, Memory content at
0x338828 is 0x094833, Memory content
written, Program resumed execution.
Chip
Program
Stub
7Remote Serial Protocol
- Request/Reply protocol
- ASCII encoding
- Packet based.
- Simple to parse, implement, extend.
- Runs on almost all communication medium
8RSP 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)
9RSP commands implementscontinued
- 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
10Implement read register
- buf malloc (regset-gtsize)
- res ptrace (PTRACE_GETREGS, childpid, 0, buf)
11Implement write register
- regset-gtfill_function (buf)
- res ptrace (PTRACE_SETREGS, childpid, 0, (int)
buf)
12Implement read memory
- i 0
- while (startAddr lt endAddr)
- bufferi ptrace(PTRACE_PEEKTEXT,
childpid, startAddr, 0 ) - startAddrsizeof(PTRACE_XFER_TYPE)
13Implement write memory
- i 0
- while ( startAddr lt endAddr )
- ptrace (PTRACE_POKETEXT, childpid, startAddr,
bufferi) - StartAddrsizeof(PTRACE_XFER_TYPE)
14Implement Step/Continue
- ptrace (PTRACE_CONT, childpid, 1, 0)
- ptrace (PTRACE_SINGLESTEP, childpid, 1, 0)
15Summary
- Minimum commands implemented
- Packet based remote serial protocol.
- Debugger uses the bare minimum stub to implement
big things.