minimal stub for remote debugging

15
Minimal Stub for remote debugging Minheng Tan Columbia University

Upload: cathleen-brown

Post on 31-Dec-2015

30 views

Category:

Documents


3 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Minimal Stub for remote debugging

Minimal Stub for remote debugging

Minheng Tan

Columbia University

Page 2: Minimal Stub for remote debugging

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

Debuggers

• MSDev

• Windbg

• dbx

• gdb

Page 4: Minimal Stub for remote debugging

ChipMachine A

Remote Debugging

DebuggerProgram

Stub

Page 5: Minimal Stub for remote debugging

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

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

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

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

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

Implement read register

• buf = malloc (regset->size);• res = ptrace (PTRACE_GETREGS,

childpid, 0, buf);

Page 11: Minimal Stub for remote debugging

Implement write register

• regset->fill_function (buf);• res = ptrace (PTRACE_SETREGS,

childpid, 0, (int) buf);

Page 12: Minimal Stub for remote debugging

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

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

Implement Step/Continue

• ptrace (PTRACE_CONT, childpid, 1, 0);

• ptrace (PTRACE_SINGLESTEP, childpid, 1, 0);

Page 15: Minimal Stub for remote debugging

Summary

• Minimum commands implemented

• Packet based remote serial protocol.

• Debugger uses the bare minimum stub to implement big things.