1 / 19

GDB commands

GDB commands. Hyeon-gyu Lee(hglee@archi.snu.ac.kr) School of Computer Science and Engineering Seoul National University. To Use GDB in Your Program. Additional compile option gcc –g –o prog prog.c Execute gdb gdb prog. Looking the Program Source. List instruction (gdb) list

haleyr
Télécharger la présentation

GDB commands

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GDB commands Hyeon-gyu Lee(hglee@archi.snu.ac.kr) School of Computer Science and Engineering Seoul National University

  2. To Use GDB in Your Program • Additional compile option • gcc –g –o prog prog.c • Execute gdb • gdb prog

  3. Looking the Program Source • List instruction • (gdb) list • Abbreviated to the letter ‘l’ • Shows your code of your program

  4. Looking the Program Source • List instruction options • (gdb) list <function> • Shows the code of <function> • (gdb) list <file>:<function> • Shows the code of <function> in the <file> • (gdb) list <line number> • Shows the code from <line number> • (gdb) list <file>:<line number> • Shows the code from <line number> in the <file> • (gdb) list - • Shows the code right before your current position • Current unit lines of printing: 10 • (gdb) set listsize 20 • Set the unit lines of printing to 20

  5. Running the program • Run the program • (gdb) run • Abbreviated to the letter ‘r’ • Run your code continuously • If confronts breakpoint, gdb stops there. • If there are no breakpoints, gdb runs until the program terminates. • Useful when your program has errors • (gdb) run arg1 arg2 … • Run your code continuously with arguments

  6. Breakpoints • Make points to stop • (gdb) break • Abbreviated to the letter ‘b’ • Without any option, breakpoint is made at your current position

  7. Making Breakpoints • Breakpoint options • (gdb) break <function> • Breakpoint at the start of the function • (gdb) break <file>:<function> • Breakpoint at the start of the function in the file • (gdb) break <line number> • Breakpoint at the designated line • (gdb) break <+/-number> • Breakpoint at the current-position-relatively designated line • (gdb) break <memory address> • Breakpoint at the instruction that pointed by the memory address • Used at assembly debugging • Above all options can be done with conditions • e.g. (gdb) break 10 if var==0

  8. Manipulating Breakpoints • Breakpoint information • (gdb) info break • Shows the information about your breakpoints • Valid until the gdb terminates • Deleting breakpoint • (gdb) clear • Abbreviated to ‘cl’ • Clear breakpoints that you made • Should be used with options • (gdb) clear <line number> • Delete breakpoint at that line number

  9. Manipulating Breakpoints • Deleting breakpoint options • (gdb) clear <line number> • Delete breakpoint at that line number • (gdb) clear <function> • Delete breakpoint at the start of the function • (gdb) clear <file>:<function> • Delete breakpoint at the start of the function in the file • (gdb) d • Delete all breakpoints • (gdb) disable/enable br • Disable/enable all breakpoints • (gdb) disable/enable br 1 3 • Disable/enable breakpoints with number 1, 3.

  10. Single-stepping • Single stepping • (gdb) step • Abbreviated to the letter ‘s’ • When a function is called at the point, it goes into the function • (gdb) step <number> • Repeat ‘step’ with times of the number. • (gdb) next • Abbreviated to the letter ‘n’ • When a function is called at the point, it executes the whole function continuously • (gdb) next <number> • Repeat ‘next’ with times of the number.

  11. Single-stepping • Other instructions • (gdb) continue • Abbreviated to the letter ‘c’ • Continuously execute from your current position • (gdb) advance <line number> • Continuously execute from your current position to the line number • (gdb) until • Continuously execute until current repetition finish point • When the current position is not in a repetition, it operates like ‘next’

  12. Single-stepping • Other instructions • (gdb) finish • Continuously execute from your current position until current function finish point • (gdb) return <return value> • Return without executing the remaining part of the function • When needed, you can manually designate a return value • (gdb) set var <variable>=<value> • Change the content of the variable to the given value

  13. Watchpoints • Stop when a variable is set to a specific value • (gdb) watch <variable> • Break when a value is written in the variable • (gdb) rwatch <variable> • Break when the value is read in the variable • (gdb) awatch <variable> • Break when a value is read/written in the variable

  14. Displaying Values • See values in your program • (gdb) info locals • Shows values of local variables that you can access from your current position • (gdb) info variables • Shows values of global variables that you can access from your current position • (gdb) print <variable> • Shows value of the variable • When the variable is a pointer, dereferencing is possible with an asterisk. • (gdb) print <function> • Shows address of the function

  15. Displaying Values • See values in your program • (gdb) print $<register> • Shows value of the register. • (gdb) print ‘<file>’::<variable> • Shows value of the variable in the file. • (gdb) print <function>::<variable> • Shows value of the variable in the function • (gdb) whatis <variable> • Shows type of the variable • (gdb) display <variable> • Shows value of the variable automatically with progress of the program • Enabling/disabling is possible • (gdb) undisplay <display#> • Delete display

  16. Examining the Stack • Backtracing the stack • (gdb) backtrace • Abbreviated to the ‘bt’ • Shows stack trace of your current position

  17. Killing the Executing Program in the GDB • Kill instruction • (gdb) kill • Kill the executing program forcefully

  18. Quitting the GDB • Quit and exit to the Linux • (gdb) quit • Abbreviated to the letter ‘q’

  19. References • References • http://kwanseob.blogspot.kr/2012/03/gdb.html, retrieved on May 20, 2015. • http://darkdust.net/files/GDB%20Cheat%20Sheet.pdf, retrieved on May 20, 2015. • https://kldp.org/node/71806, retrieved on May 20, 2015.

More Related