1 / 10

Debugging with gdb

Debugging with gdb. Eileen Kraemer CSCI 6950 – Research Methods in CS August 31, 2009. What does a debugger do?. Allows you to see what is going on "inside" a program while it executes AND/ OR what that program was doing at the moment it crashed. GDB functions.

ward
Download Presentation

Debugging with gdb

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. Debugging with gdb Eileen Kraemer CSCI 6950 – Research Methods in CS August 31, 2009

  2. What does a debugger do? • Allows you to see • what is going on "inside" a program while it executes • AND/ OR • what that program was doing at the moment it crashed.

  3. GDB functions • GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: • * Start your program, specifying anything that might affect its behavior. • * Make your program stop on specified conditions. • * Examine what has happened, when your program has stopped. • * Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn about another.

  4. Preparing to debug • In order to debug a program effectively, you need to generate debugging information when you compile it. This debugging information is stored in the object file; it describes the data type of each variable or function and the correspondence between source line numbers and addresses in the executable code. • To request debugging information, specify the `-g' option when you run the compiler. Specifying –ggdb will provide additional info.

  5. Gdb commands • Running/Resuming Execution • Stopping Execution • Examining the Data and Source Code • Examining the Stack

  6. Running/Resuming Execution • run • Start your program • Step [count] (s) • Continue running until control reaches another source line • next [count] (n) • Continue running until next source line in current stack frame • Continue (c) • Resume where you left off • finish • Continue running until the current stack frame returns

  7. Stopping execution • break – set breakpoints • more on next slide … • watch EXPR • stop execution whenever the value of an expression changes • info • Print a table of all breakpoints and watchpoints set and not deleted • clear • delete breakpoints by location • delete • delete breakpoints by argument

  8. break • break FUNCTION • Set breakpoint at entry to FUNCTION. • break LINENUM • Set breakpoint at LINENUM in current source file. • break FILENAME:LINENUM • Set a breakpoint at LINENUM in source file FILENAME. • break FILENAME:FUNCTION • Set breakpoint at entry to FUNCTION in FILENAME. • break ... if COND • Set breakpoint with condition COND; evaluate the expression COND each time the breakpoint is reached, and stop only if the value is nonzero--that is, if COND evaluates as true. ... stands for one of the possible arguments described above (or no argument) specifying where to break.

  9. Examining Data and Source Code • print [exp] (p) • exp = a source language expression • display EXP (disp) • add EXP to the list of things that display whenever your program stops • list (l) • list LINENUM • list FUNCTION • list • list -

  10. Examining the stack • backtrace • where

More Related