Embedded Systems Principle of Debugger
Reference Materials kl.de/avr_projects/arm_projects/#winarmhttp:// kl.de/avr_projects/arm_projects/#winarm ocument/debugger/ew_GDB_RSP.pdfhttp:// ocument/debugger/ew_GDB_RSP.pdf
Software Debugging
GDB Host PC Target Board gdb's Remote Serial Protocol (RSP) Debugging Stub/Agent GDB Server GDB
Debugging Agent/Stub Small Code Response to GDB Request –Read / Write Memory –Read / Write Register –Set / Remove Breakpoints Provide Debug Trap –Breakpoint exception –Invalid instruction exception –System error exception Transmit CPU Status Data to Remote Debugger Host PC Target Board gdb's Remote Serial Protocol (RSP) Debugging Agent/Stub GDB
Typical Debug Session localhost$ sh-hitachi-hms-gdb a.out GNU gdb 5.0 Copyright 2000 Free Software Foundation, Inc. (gdb) target remote /dev/ttyS0 (gdb) load Loading section.text, size 0x1280 vma 0x1000 Loading section.data, size 0x760 vma 0x2280 Loading section.stack, size 0x10 vma 0x30000 Start address 0x1000 Transfer rate: bits in <1 sec. (gdb) b main Breakpoint 1 at 0x : file test.c, line 5. (gdb) continue Breakpoint 1, main () at test.c:5 5 for( i = 0; i < 10; i++ ) { (gdb) display j 1: j = (gdb) step 6 j = i * 2 + 1; 1: j = (gdb) step 5 for( i = 0; i < 10; i++ ) { 1: j = 1 (gdb) quit
GDB Remote Serial Protocol (RSP) RSP Message $ # CKSUM_MSN CKSUM_LSN Response of RSP Message + … - … Host PC Target Board gdb's Remote Serial Protocol (RSP) Debugging Agent/Stub GDB if the received checksum was correct, and the receiver is ready for the next packet if the received checksum was incorrect, and the message needs to be retransmitted sum of, keep last 8-bit, expressed in ASCII
RSP Example Read All Registers [gdb]$g#67 [target]+$ abcdef abcdef...#xx Write All Registers [gdb] $G abcdef0...#xx [target]+ $OK#9a Write Specific Registers [gdb] $P10= c#b3 [target]+ $OK#9a Read Memory [gdb] $m4015bc,2#5a [target]+ $2f86#06 Write Memory [gdb] $ M4015cc,2:c320#6d [target] + $OK#9a Set register 16 to the value 0x40149c All register values Read two bytes, starting at address 0x4015bc Write the value 0xc320 to address 0x4015cc
RSP Example Step [gdb]$s#73 Continue [gdb] $c#63 Console Output [target] $O48656c6c6f2c20776f726c64210a#55 Prints “Hello, world!\n” on the gdb console
Request ? : Read current Status g : Read all registers G : Write all registers m , : Read memory M , : : Write meoory c : Continue s : Single step k : Kill RSP Command List Response “” : Command not support E : Error OK : w : Exit X : Terminate at signal S : Stop at signal O : Console output
Detailed Example of a GDB Session write break point write memory run until stop read memory stopped, response with register value that GDB may be interested response with memory data stopped, response with register value that GDB may be interested
Break Point & Step Break point Program Codes GDB Stub Set Breakpoint Run User Code Wait for Exception Report CPU status Remove Breakpoint Program Stops Enter Exception ISR Waiting For Debugging Command … … … … … … … … … … … …
Use GDB with Embedded Linux user board GDB Ethernet Cable GBD Server Remote PC Running Linux
Transfer Binary to Board Transfer Method Ethernet FTP NFS UART Z-Modem Root Image USB-Disk CF/SD-Card Storage RAM FlashROM Remote Disk Communication Applications on the Development Board Device Driver for These Storage Rebuild and download Root Image Network Hardware
Bootloader Linux need to copy kernel from ROM to RAM Kernel Image Root Image ROM User Data Storage Kernel Root Image RAM User Data Storage User Apps
NFS Debugging Mode Kernel RAM User Data Storage NFS Server Ethernet Chip User Apps Avoid repeatedly re-write Flashrom
Start Remote Debug gdbserver :1234 Hello_arm xxx-elf-linux-gdb Hello_arm target remote :1234 IP address of PC (Can be found by command “ ifconfig ”) run from the development board Run from PC IP address of development board Run from PC
Remote Debugging Commands br main set break point at main() cont continue run (stopped at main()) l list source code n step n
Other Useful GDB Command Stop running “Ctrl-C” exit GDB quit run program run Set breakpoint break main Clear breakpoint clear main Check existing breakpoint info b Step ( enter subroutine ) s Step ( skip subroutine ) n Show call stack bt check memory 0x200 x 0x200 Check variable m p m Change value of m to 7 set m=7 Display reg. PC p/x $pc Dislpay reg. SP p/x $sp Change PC to 0 set $pc=0 Disassember from addr. 0 x/5i 0x0