1 / 11

Gdb tutorial

Gdb tutorial. Vishnu Nath. What is gdb ?. “GNU Debugger” Great with several languages, including C and C++ Allows inspection of program during execution Segmentation fault and other errors may be much easier to find. Usage. Requires gcc compiler with the –g flag set. Syntax:

tayte
Download Presentation

Gdb tutorial

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 tutorial Vishnu Nath

  2. What is gdb? • “GNU Debugger” • Great with several languages, including C and C++ • Allows inspection of program during execution • Segmentation fault and other errors may be much easier to find

  3. Usage • Requires gcccompiler with the –g flag set. • Syntax: g++ [other flags] –g <source files> -o <output files> • Example: g++ -Wall –Werror –ansi –g program1.c –o program

  4. Startup functions in gdb • run – begin execution of program • kill – stop execution of program • quit – exit gdb • help – get description of every command in gdb

  5. Simple program – no error int main() { int x = 30, y = 20; x = y; return 0; }

  6. More functions • list – prints out lines of code above and below the line the program is stopped at • print – examine the value of the variable • set – set the value of the variable • call – call any function linked to program. This includes user and library functions. • finish – finish function execution and return to caller.

  7. About function stepping • next void foo() { … } void foo2() { … } • step void foo() { … }

  8. Call Stack • Place to find stack frames that control program flow. • Look at call stack to understand how the program is running. • Function – backtrace • frame - Change stack frame Example: (gdb) frame 7

  9. Breakpoints • Way of telling the debugger that user would like to stop program at certain lines of code. • User can have program stop during specific function calls. • Once stopped, user can examine memory and check values of all variables, examine stack and step through program.

  10. Breakpoints’ functions • break – set a breakpoint at a particular line Example: break 32 • break can be used to set a breakpoint for a function Example: break foo_func • tbreak – temporary break. Stops program only once. • Disable – remove particular breakpoint Example – disable 2 • info breakpoints – list of breakpoints and info

  11. Examine Memory • Use the ‘x’ command to examine memory. • Syntax: x/FMT ADDRESS Example: char* s = “Hello World”; Examine as string: (gdb) x/s s => Examine as character: (gdb) x/c s =>

More Related