Minimal Stub for remote debugging
-
Upload
cathleen-brown -
Category
Documents
-
view
30 -
download
3
description
Transcript of Minimal Stub for remote debugging
![Page 1: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/1.jpg)
Minimal Stub for remote debugging
Minheng Tan
Columbia University
![Page 2: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/2.jpg)
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.
![Page 3: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/3.jpg)
Debuggers
• MSDev
• Windbg
• dbx
• gdb
![Page 4: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/4.jpg)
ChipMachine A
Remote Debugging
DebuggerProgram
Stub
![Page 5: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/5.jpg)
Remote Debugging …continued
Machine A
DebuggerRead register 3,
Read memory at 0x338828,Write “CC” at 0x380280,
Continue program.
![Page 6: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/6.jpg)
Remote Debugging …continued
Chip
Program
Stub
Register 3 is 0x75939ff3,Memory content at 0x338828 is 0x094833,
Memory content written,Program resumed execution.
![Page 7: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/7.jpg)
Remote Serial Protocol
• Request/Reply protocol
• ASCII encoding
• Packet based.
• Simple to parse, implement, extend.
• Runs on almost all communication medium
![Page 8: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/8.jpg)
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)
![Page 9: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/9.jpg)
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…
![Page 10: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/10.jpg)
Implement read register
• buf = malloc (regset->size);• res = ptrace (PTRACE_GETREGS,
childpid, 0, buf);
![Page 11: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/11.jpg)
Implement write register
• regset->fill_function (buf);• res = ptrace (PTRACE_SETREGS,
childpid, 0, (int) buf);
![Page 12: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/12.jpg)
Implement read memory
• i = 0;• while (startAddr <= endAddr) {• buffer[i++] =
ptrace(PTRACE_PEEKTEXT, childpid, startAddr, 0 );
• startAddr+=sizeof(PTRACE_XFER_TYPE);
• }
![Page 13: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/13.jpg)
Implement write memory
• i = 0;• while ( startAddr <= endAddr ) {• ptrace (PTRACE_POKETEXT, childpid,
startAddr, buffer[i++]);•
StartAddr+=sizeof(PTRACE_XFER_TYPE);
• }
![Page 14: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/14.jpg)
Implement Step/Continue
• ptrace (PTRACE_CONT, childpid, 1, 0);
• ptrace (PTRACE_SINGLESTEP, childpid, 1, 0);
![Page 15: Minimal Stub for remote debugging](https://reader036.fdocuments.net/reader036/viewer/2022082711/56812f05550346895d94a3e8/html5/thumbnails/15.jpg)
Summary
• Minimum commands implemented
• Packet based remote serial protocol.
• Debugger uses the bare minimum stub to implement big things.