Principle of Debugger

Download Report

Transcript Principle of Debugger

Embedded Systems
Principle of Debugger
Reference Materials
•http://billgatliff.com
•http://www.embedded.com/
•http://www.siwawi.arubi.unikl.de/avr_projects/arm_projects/#winarm
•http://twentyone.blogchina.com/
•http://www.huihoo.org/mirrors/pub/embed/d
ocument/debugger/ew_GDB_RSP.pdf
Software Debugging
GDB
Host PC
Target Board
GDB
Debugging
Stub/Agent
GDB Server
gdb's Remote Serial
Protocol (RSP)
Debugging Agent/Stub
• Small Code
• Response to GDB Request
– Read / Write Memory
– Read / Write Register
– Set / Remove Breakpoints
Host PC
Target Board
GDB
Debugging
Agent/Stub
gdb's Remote Serial
Protocol (RSP)
• Provide Debug Trap
– Breakpoint exception
– Invalid instruction exception
– System error exception
• Transmit CPU Status Data to Remote Debugger
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: 53120 bits in <1 sec.
(gdb) b main
Breakpoint 1 at 0x8048476: 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 = 1074136126
(gdb) step
6 j = i * 2 + 1;
1: j = 1074136126
(gdb) step
5 for( i = 0; i < 10; i++ ) {
1: j = 1
(gdb) quit
Typical
Debug
Session
GDB Remote Serial Protocol (RSP)
sum of <data>, keep last 8-bit, expressed in ASCII
• RSP Message
$ <data> # CKSUM_MSN CKSUM_LSN
• Response of RSP Message
+…
-…
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
Host PC
Target Board
GDB
Debugging
Agent/Stub
gdb's Remote Serial
Protocol (RSP)
• Read All Registers
RSP Example
[gdb]
$g#67
[target] +$0123456789abcdef0123456789abcdef...#xx
• Write All Registers
All register values
[gdb]
$G123456789abcdef0...#xx
[target] + $OK#9a
• Write Specific Registers
[gdb]
$P10=0040149c#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
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
Prints “Hello, world!\n” on
the gdb console
[target] $O48656c6c6f2c20776f726c64210a#55
RSP Command List
Request
?:Read current Status
g:Read all registers
G<regiater_data>:Write all registers
m<address>,<length>:Read memory
M<address>,<length>:<memory_data>:Write meoory
c:Continue Response
s:Single step
“”:Command not support
k:Kill
E: Error
OK:
w<exit_Status>:Exit
X<signal>:Terminate at signal
S<signal>:Stop at signal
O:Console output
write memory
write break point
run until stop
stopped, response with
register value that GDB
may be interested
read memory
response
with memory
data
stopped, response with
register value that GDB
may be interested
Detailed
Example
of a GDB
Session
Break Point & Step
Waiting For
Debugging Command
Program
Codes
Set Breakpoint
…
…
…
…
…
…
Break point
Run User Code
Wait for Exception
Remove
Breakpoint
…
GDB Stub
…
Report CPU
status
…
Program Stops
Enter Exception ISR
…
…
…
Use GDB
with
Embedded
Linux
Ethernet
Cable
user board
GBD Server
Remote PC
Running Linux
GDB
Transfer Binary to Board
Storage
RAM
FlashROM
Remote Disk
Transfer Method
• Ethernet
FTP
NFS
• UART
Z-Modem
Rebuild and download
Root Image
• Root Image
• USB-Disk
• CF/SD-Card
Network
Hardware
Communication
Applications on
the Development
Board
Device Driver for
These Storage
Linux need to copy kernel from ROM to
RAM
RAM
ROM
User Data
Storage
User Data
Storage
User Apps
Root Image
Root Image
Kernel Image
Bootloader
User Apps
Kernel
NFS Debugging Mode
RAM
NFS
Server
User Apps
User Data
Storage
Avoid repeatedly
re-write Flashrom
Kernel
Ethernet
Chip
Start Remote Debug
gdbserver 192.168.5.111:1234 Hello_arm
run from the development board
IP address of PC
(Can be found by command “ifconfig”)
xxx-elf-linux-gdb Hello_arm
Run from PC
target remote 192.168.5.222:1234
Run from PC
IP address of development board
Remote Debugging Commands
br main
cont
l
n
n
set break point at main()
continue run (stopped at main())
list source code
step
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Stop running
exit GDB
run program
Set breakpoint
Clear breakpoint
Check existing breakpoint
Step(enter subroutine)
Step(skip subroutine)
Show call stack
check memory 0x200
Check variable m
Change value of m to 7
Display reg. PC
Dislpay reg. SP
Change PC to 0
Disassember from addr. 0
“Ctrl-C”
quit
run
break main
clear main
info b
s
Other Useful
n
GDB Command
bt
x
0x200
p
m
set
m=7
p/x
$pc
p/x
$sp
set
$pc=0
x/5i 0x0