Summary of gdb common commands (assembly and c)

Refer to
the installation of gdb: Reference

simple command

gdb test Run the program target
gdb test --args test 1 2 3 Run the program test, and the parameter list (args) is [test,1,2,3]
show args display args
set args modify args

Use the up and down keys to view the command history (in tui, if the selected window is not the cmd window, the shortcut key function will be replaced by another one).
If you forget the usage, you can help command, you can see the usage of a certain command, for examplehelp p

b breakpoint
info b view breakpoint
del or clear delete breakpoint
ingore (ignore N COUNT) ignore breakpoint N, the number of times is COUNT, that is, the previous COUNT breakpoint is not triggered

start run (automatically stops at the main function)
r run (stop if there is no breakpoint)
c continue to run
j(jump) ( reference ) jump to a certain position (it is not 快进到某个位置, it is 直接跳转到那个位置, it will not run in the middle command), I don’t use it often, and I don’t know it very well. If you need to know it, you can refer to this example ( Introduction to the Linux GDB jump command ).

n the next line of code
s enters the function
ni the next instruction
si enters the function (assembly level)

n 10 run 10 lines of code
ni 10 run 10 instructions

until exit the loop
finish exit the function (equivalent to fast forward)
return exit the function (it is a forced exit, skipping the middle instruction)
call call function

l show code
bt view stack

p print variable
x parameter is the memory address, print memory ( help xsee usage)
info reg all print all registers
info reg rsp print rsp register (shorthand i r rsp)
p rsp print rsp register (note, here need to add ' rsp print rsp register (note, here Need to add`r s p print r s p register ( note , you need to add the symbol ' ` here , but the above command does not need it)
p $xmm0.v2_double print xmm0 register (think it stores two doubles)

tui related commands ( reference )
layout src display source code
layout asm display assembly
layout reg display register
layout split display multiple windows
tui reg general display general registers
tui reg all display all registers
tui enable enable tui
tui disable close tui
ctrl+x, aclose tui
ctrl+Lrefresh window
updateupdate tui
focus cmd Select the command window

info threads view thread information
info frame view frame information
frame N switch frame

edit location Modify the code (the default compiler is ex, never used, but it can be changed to vim)
info float View the floating point device hardware
info vector View the status of the vector register

Intermediate function

  • Conditional breakpoints ( reference ), for example b foo if a==1, a conditional breakpoint is triggered
  • Monitor breakpoints ( reference ), trigger breakpoints when the variable/register/memory we monitor changes. For example watch var_i, watch *(int*)0x7fff123456,watch $rsp
  • Temporary breakpoint (breakpoint only takes effect once), the command is tbreak, abbreviated astb
  • Automatically print variables (every time the program pauses, it will be automatically printed, and I personally feel that it is a bit disturbing to print too much) The command isdisplay
  • Temporary variables
  • Modify the value of a variable or register or memory ( reference )
  • Execute the shell command (just enter the shell before the command, for example, shell clearit is equivalent to executing the clear command in the shell to clear the screen)
  • Pipeline command (just enter pipe before the command, for example, pipe disassemble main | tee main.sit is equivalent to redirecting the assembly code of the main function to the main.s file through the pipeline, and the pipeline command in tui seems to be invalid)

Advanced Features

  • Remote debugging (remote debug)
  • Debug a running program (attach)
  • gdb jumps back (there will be some side effects, reference materials ), you can also use checkpoint
  • gdb script (still easy to use)
  • gdb+python script (it feels more powerful, but not very useful, refer to )
  • Snapshot function (core file, reference )
  • search in memory ( reference )
  • memory region (less commonly referenced )

Guess you like

Origin blog.csdn.net/qq_29809823/article/details/118941735