gdb usage steps
-
set arch riscv:rv32
set to 32bit for e21 -
target remote :3333
连到openocd端口3333 -
monitor reset halt
reset -
flushregs
flushregs -- Force gdb to flush its register cache (maintainer command) -
file elf_file_full_path
指定elf -
thread apply all load
load elf
gdb script
可以在<gdb>的命令行里面执行脚本,比如:
source init.gdb
可以执行init.gdb中的命令,可以加速debug过程。
gdb commands
-
x /[Length][Format] [Address expression]
显示地址中的数据
int main()
{
char testArray[] = "0123456789ABCDEF";
return 0;
}
-
x/5i $pc
显示从当前位置开始的5条指令 . -
x testArray
显示1个字符和对应的ascii码0x33323130
-
x/c testArray
显示1个字符和对应的ascii码48 '0'
-
x/3c testArray
显示3个字符和对应的ascii码48 '0' 49 '1' 50 '2'
-
x/s testArray
显示字符串0123456789ABCDEF
-
x/wx testArray
显示32bit0x33323130
-
x/gx testArray
显示giant-word,64bit0x3736353433323130
-
x/2hx testArray
显示half-word,16bit0x3130 0x3332
-
info variables __dtb_dt_begin 显示dtb起始地址
-
info variables __dtb_dt_end 显示dtb结束地址
-
info b
显示breakpoints -
info registers
显示的寄存器 -
info all-registers
显示所有的寄存器,包括msr -
info registers a5
显示a5值
info registers m
显示a5值
a0 a2 a4 a6 all loat general pc restore s10 s2 s4 s6 s8 save system t1 t3 t5 tp zero
a1 a3 a5 a7 csr p gp ra s1 s11 s3 s5 s7 s9 sp t0 t2 t4 t6 vector
-
backtrace
显示调用stack -
apropos
apropos -- Search for commands matching a REGEXP -
set variable control_base=0x20000000
set variable to a value -
set $pc=__metal_driver_sifive_uart0_getc
set PC to a function -
p/x ch
print ch's value in hexial value -
show commands
show last 10 commands -
Debugging with GDB
非常全的一个参考资料
13. GDB Command Reference
This section of the website contains an incomplete reference of most frequently used GDB commands. The commands described here can be used with the command-line GDB as well as under VisualGDB.
Breakpoint and watchpoint management
break
clear
delete
disable
enable
info breakpoints
set multiple-symbols
Checkpoint-related commands
checkpoint
delete checkpoint
info checkpoints
restart
Debugged program settings
set args
set detach-on-fork
set disable-randomization
set follow-fork-mode
set new-console
tty
Disassembly-related commands
disassemble
set disassemble-next-line
set disassembly-flavor
Execution control commands
attach
continue
detach
kill
run
start
Expression evaluating commands
display
print
set print address
set print array-indexes
set print array
set print elements
set print frame-arguments
undisplay
x
Information displaying comands
info address
info registers
info files
info functions
info line
info registers
info source
info sources
info symbol
info types
info variables
info vector
info vtbl
Shared library commands
info sharedlibrary
set auto-solib-add
set solib-search-path
set stop-on-solib-events
set sysroot
sharedlibrary
Stack-related commands
backtrace
down
frame
info args
info frame
info locals
select-frame
set backtrace limit
set backtrace past-entry
set backtrace past-main
set filename-display
up
aliases
ni -- Step one instruction
rc -- Continue program being debugged but run it in reverse
rni -- Step backward one instruction
rsi -- Step backward exactly one instruction
si -- Step one instruction exactly
stepping -- Specify single-stepping behavior at a tracepoint
tp -- Set a tracepoint at specified location
tty -- Set terminal for future runs of program being debugged
where -- Print backtrace of all stack frames
ws -- Specify single-stepping behavior at a tracepoint
breakpoints
awatch -- Set a watchpoint for an expression
break -- Set breakpoint at specified location
break-range -- Set a breakpoint for an address range
catch -- Set catchpoints to catch events
catch assert -- Catch failed Ada assertions
catch catch -- Catch an exception
catch exception -- Catch Ada exceptions
catch exec -- Catch calls to exec
catch fork -- Catch calls to fork
catch handlers -- Catch Ada exceptions
catch load -- Catch loads of shared libraries
catch rethrow -- Catch an exception
catch signal -- Catch signals by their names and/or numbers
catch syscall -- Catch system calls by their names
catch throw -- Catch an exception
catch unload -- Catch unloads of shared libraries
catch vfork -- Catch calls to vfork
clear -- Clear breakpoint at specified location
commands -- Set commands to be executed when the given breakpoints are hit
condition -- Specify breakpoint number N to break only if COND is true
delete -- Delete some breakpoints or auto-display expressions
delete bookmark -- Delete a bookmark from the bookmark list
delete breakpoints -- Delete some breakpoints or auto-display expressions
delete display -- Cancel some expressions to be displayed when program stops
delete mem -- Delete memory region
delete tracepoints -- Delete specified tracepoints
delete tvariable -- Delete one or more trace state variables
disable -- Disable some breakpoints
disable breakpoints -- Disable some breakpoints
disable display -- Disable some expressions to be displayed when program stops
disable mem -- Disable memory region
disable probes -- Disable probes
dprintf -- Set a dynamic printf at specified location
enable -- Enable some breakpoints
enable breakpoints -- Enable some breakpoints
enable breakpoints count -- Enable breakpoints for COUNT hits
enable breakpoints delete -- Enable breakpoints and delete when hit
enable breakpoints once -- Enable breakpoints for one hit
enable count -- Enable breakpoints for COUNT hits
enable delete -- Enable breakpoints and delete when hit
enable display -- Enable some expressions to be displayed when program stops
enable mem -- Enable memory region
enable once -- Enable breakpoints for one hit
enable probes -- Enable probes
ftrace -- Set a fast tracepoint at specified location
hbreak -- Set a hardware assisted breakpoint
ignore -- Set ignore-count of breakpoint number N to COUNT
rbreak -- Set a breakpoint for all functions matching REGEXP
rwatch -- Set a read watchpoint for an expression
save -- Save breakpoint definitions as a script
save breakpoints -- Save current breakpoint definitions as a script
save gdb-index -- Save a gdb-index file
save tracepoints -- Save current tracepoint definitions as a script
skip -- Ignore a function while stepping
skip delete -- Delete skip entries
skip disable -- Disable skip entries
skip enable -- Enable skip entries
skip file -- Ignore a file while stepping
skip function -- Ignore a function while stepping
strace -- Set a static tracepoint at location or marker
tbreak -- Set a temporary breakpoint
tcatch -- Set temporary catchpoints to catch events
tcatch assert -- Catch failed Ada assertions
tcatch catch -- Catch an exception
tcatch exception -- Catch Ada exceptions
tcatch exec -- Catch calls to exec
tcatch fork -- Catch calls to fork
tcatch handlers -- Catch Ada exceptions
tcatch load -- Catch loads of shared libraries
tcatch rethrow -- Catch an exception
tcatch signal -- Catch signals by their names and/or numbers
tcatch syscall -- Catch system calls by their names
tcatch throw -- Catch an exception
tcatch unload -- Catch unloads of shared libraries
tcatch vfork -- Catch calls to vfork
thbreak -- Set a temporary hardware assisted breakpoint
trace -- Set a tracepoint at specified location
watch -- Set a watchpoint for an expression
target: Connect to a target machine or process
target core -- Use a core file as a target
target exec -- Use an executable file as a target
target extended-remote -- Use a remote computer via a serial line
target record-btrace -- Collect control-flow trace and provide the execution history
target record-core -- Log program while executing and replay execution from log
target record-full -- Log program while executing and replay execution from log
target remote -- Use a remote computer via a serial line
target tfile -- Use a trace file as a target
网友评论