Gdb tutorial
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

Gdb tutorial PowerPoint PPT Presentation


  • 46 Views
  • Uploaded on
  • Presentation posted in: General

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:

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Gdb tutorial

Gdb tutorial

Vishnu Nath


What is gdb

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

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


Startup functions in gdb

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


Simple program no error

Simple program – no error

int main()

{

int x = 30, y = 20;

x = y;

return 0;

}


More functions

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.


About function stepping

About function stepping

  • next

    void foo()

    {

    }

    void foo2()

    {

    }

  • step

    void foo()

    {

    }


Call stack

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


Breakpoints

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.


Breakpoints functions

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


Examine memory

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 =>


  • Login