gdb tutorial
Download
Skip this Video
Download Presentation
Gdb tutorial

Loading in 2 Seconds...

play fullscreen
1 / 11

Gdb tutorial - PowerPoint PPT Presentation


  • 64 Views
  • Uploaded on

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:

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Gdb tutorial' - kaden-head


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

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

ad