Your SlideShare is downloading. ×
Wavedigitech gdb
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Wavedigitech gdb

771
views

Published on

The GNU Debugger, usually called just GDB it is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, …

The GNU Debugger, usually called just GDB it is a portable debugger that runs on many Unix-like systems and works for many programming languages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java and partially others

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
771
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. © Copyright 2013, wavedigitech.com.Latest update: June 15, 2013,http://www.wavedigitech.com/Call us on : 91-9632839173E-Mail : info@wavedigitech.comE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 2. Presentation on ARM BasicsE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173Presentation onGDB
  • 3. Presentation on ARM BasicsE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173The GNU Debugger, usually called just GDB it is a portable debugger that runson many Unix-like systems and works for many programminglanguages, including Ada, C, C++, Objective-C, Free Pascal, Fortran, Java andpartially others.GDB offers extensive facilities for tracing and altering the execution ofcomputer programs. The user can monitor and modify the values of programsinternal variables, and even call functions independently of the programsnormal behavior.Remote debuggingGDB offers a remote mode often used when debugging embeddedsystems. Remote operation is when GDB runs on one machine and theprogram being debugged runs on another.The GNU Debugger
  • 4. Compiling for debugging• We usually compile a program asgcc [flags] <source files> -o <output file>• A -g option is added to enable the built-in debugging support(which gdb needs):gcc [other flags] -g <source files> -o <output file>Ex: gcc -Wall -Werror -ansi -pedantic-errors -g prog1.c -o prog1.xE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 5. Starting up gdb• To get the gdb prompt, type “gdb”• The program to be debugged now is loaded using(gdb) file prog1.x• Here, prog1.x is the program you want to load, and “file” isthe command to load it.• To run the program, we use(gdb) runE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 6. Setting breakpoints• Breakpoints can be used to stop the program run in the middle,at a designated point. The simplest way is the command“break.” This sets a breakpoint at a specified file-line pair(gdb) break file1.c:6• This sets a breakpoint at line 6, of file1.c. Now, if the programever reaches that location when running, the program willpause and prompt you for another command.• To break at a particular function, we use(gdb) break functionE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 7. • We can proceed onto the next breakpoint by typing “continue”(gdb) continue• step Executes the current line of the program and stops on the nextstatement to be executed(gdb) step• Like step, however, if the current line of the program contains afunction call, it executes the function and stops at the next line.(gdb) next• Until is like next, except that if you are at the end of a loop, until willcontinue execution until the loop is exited, whereas next will just takeyou back up to the beginning of the loop. This is convenient if youwant to see what happens after the loop, but dont want to step throughevery iteration.(gdb) untilE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 8. Print and Watchpoints• The print command prints the value of the variable specified, andprint/x prints the value in hexadecimal:(gdb) print variable(gdb) print/x variable• We can also modify variables values by(gdb) set < variable > = <value>• Whereas breakpoints interrupt the program at a particular line orfunction, watchpoints act on variables. They pause the programwhenever a watched variable’s value is modified.(gdb) watch variable• Now, whenever my var’s value is modified, the program willinterrupt and print out the old and new values.E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 9. • backtrace - produces a stack trace of the function calls thatlead to a segmentation fault• where - same as backtrace; you can think of this version asworking even when you’re still in the middle of the program• finish - runs until the current function is finished• delete N - deletes a specified N breakpoint• info breakpoints - shows information about all declaredbreakpointsE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 10. info commands for examiningruntime debugger state:• gdb has a large set of info X commands for displaying information aboutdifferent types of runtime state and about debugger state. Here is how to listall the info commands in help, and a description of what a few of the infocommands do:• (gdb) help status lists a bunch of info X commands• (gdb) info frame list information about the current stackframe• (gdb) info locals list local variable values of current stackframe• (gdb) info args list argument values of current stack frame• (gdb) info registers list register values• (gdb) info breakpoints list status of all breakpointsE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 11. .• (gdb) up – Move to the function that called the present function. Useful ifyour program crashes in a library function; use up to get to the last functioncall in your program• (gdb) down – Reverses the action of up• (gdb) delete – Removes breakpoint by number (see example following). Ifno number, all deleted.• (gdb) kill – Terminates the program.• (gdb) list – List 10 lines of the program being debugged. The sixth line isthe preset statement. Subsequent, consecutive entry of list will list the next10 lines.E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 12. Breakpoints• In this, we get to specify some criterion that must be met forthe breakpoint to trigger. We use the same break command asbefore:(gdb) break file1.c:6 if i >= ARRAYSIZE• This command sets a breakpoint at line 6 of file file1.c, whichtriggers only if the variable i is greater than or equal to the sizeof the arrayE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 13. Using pointers with gdb• Suppose we’re in gdb, and are at some point in the executionafter a line that looks like:struct entry * e1 = <something>;• To see the value (memory address) of the pointer:(gdb) print e1• To see a particular field of the struct the pointer is referencing:(gdb) print e1->key(gdb) print e1->name(gdb) print e1->price(gdb) print e1->serial numberE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173
  • 14. • We can also use the dereference (*) and dot (.) operators inplace of the arrow operator (->):(gdb) print (*e1).key(gdb) print (*e1).name(gdb) print (*e1).price(gdb) print (*e1).serial number• To see the entire contents of the struct the pointer references(gdb) print *e1E-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173Using pointers with gdb
  • 15. Thank You© Copyright 2013, wavedigitech.com.Latest update: June 30, 2013,http://www.wavedigitech.com/Call us on : +91-91-9632839173E-Mail : info@wavedigitech.comE-mail: info@wavedigitech.com; http://www.wavedigitech.com Phone : 91-9632839173

×