Download presentation
Presentation is loading. Please wait.
1
Minimal Stub for remote debugging Minheng Tan Columbia University
2
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.
3
Debuggers MSDev Windbg dbx gdb
4
Chip Machine A Remote Debugging Debugger Program Stub
5
Remote Debugging …continued Machine A Debugger Read register 3, Read memory at 0x338828, Write “CC” at 0x380280, Continue program.
6
Remote Debugging …continued Chip Program Stub Register 3 is 0x75939ff3, Memory content at 0x338828 is 0x094833, Memory content written, Program resumed execution.
7
Remote Serial Protocol Request/Reply protocol ASCII encoding Packet based. Simple to parse, implement, extend. Runs on almost all communication medium
8
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)
9
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…
10
Implement read register buf = malloc (regset->size); res = ptrace (PTRACE_GETREGS, childpid, 0, buf);
11
Implement write register regset->fill_function (buf); res = ptrace (PTRACE_SETREGS, childpid, 0, (int) buf);
12
Implement read memory i = 0; while (startAddr <= endAddr) { buffer[i++] = ptrace(PTRACE_PEEKTEXT, childpid, startAddr, 0 ); startAddr+=sizeof(PTRACE_XFER_TYPE); }
13
Implement write memory i = 0; while ( startAddr <= endAddr ) { ptrace (PTRACE_POKETEXT, childpid, startAddr, buffer[i++]); StartAddr+=sizeof(PTRACE_XFER_TYPE); }
14
Implement Step/Continue ptrace (PTRACE_CONT, childpid, 1, 0); ptrace (PTRACE_SINGLESTEP, childpid, 1, 0);
15
Summary Minimum commands implemented Packet based remote serial protocol. Debugger uses the bare minimum stub to implement big things.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.