1 / 15

Debugger

Department of Computer and Information Science, School of Science, IUPUI Fall 2003. Debugger. Dale Roberts, Lecturer Computer Science, IUPUI E-mail: droberts@cs.iupui.edu. GDB. The purpose of a debugger such as GDB is to allow you to see what is going on inside the program while it executes.

Download Presentation

Debugger

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. Department of Computer and Information Science,School of Science, IUPUIFall 2003 Debugger Dale Roberts, Lecturer Computer Science, IUPUI E-mail: droberts@cs.iupui.edu

  2. GDB • The purpose of a debugger such as GDB is to allow you to see what is going on inside the program while it executes. • GDB – GNU debugger • GDB can be used to debug programs written in C, C++. • The C++ debugging facilities are jointly implemented by the C++ compiler and GDB. • To debug your C++ code, you must compile your C++ programs with a supported C++ compiler, such as GNU g++, or the HP ANSI C++ compiler (aCC) with a –g option to include symbols.

  3. GDB cont…. 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 that you can experiment with correcting the effects of one bug and go on to learn about another.

  4. GDB Commands • GDB is invoked by running the program gdb. Once the debugger is started, GDB reads command until you tell it to exit. GDB can be started with variety of arguments and options. • The most usual way to start debugging is • gdb program – one argument, which is an executable file more than one arguments can be provided • gdb program core – two arguments, one executable and one core file • gdb program 1234 – specify process id as second argument

  5. Run command When gdb starts, your program is not actually running. It won't run until you instruct gdb how to run it. run – will start your program as if you had typed a.out You can provide command line arguments if the program requires.

  6. Break points • A break point makes your program stop whenever a certain point in the program is reached • Ways to set a break point • break function - Set a breakpoint at entry to function function • break +offset - • break -offset - Sets a breakpoint some number of lines forward or back from the position at which execution stopped. • break linenum - Sets a breakpoint at line linenum in the current source file

  7. Break points Cont…. • break filename:function - Sets a breakpoint at entry to function function found in file filename. Specifying a file name as well as a function name is superfluous except when multiple files contain similarly named functions. • info breakpoints • info break - Prints a table of all breakpoints set and not deleted

  8. Watch Points • A watch point is a special breakpoint that stops your program when the value of an expression changes • Ways to set a watch point watch expr - Sets a watchpoint for an expression. • info watchpoints - Prints a table of all watch points set and not deleted

  9. Deleting Break and Watch points Deleting Break points and watch points • clear • clear function • clear filename:function • clear linenum • clear filename:linenum • delete n – deletes the break point. n is a break point number.

  10. Continue and stepping • continue [ignore-count] - Continuing means resuming program execution until your program completes normally. Resumes program execution, at the address where your program last stopped, any breakpoints set at that address are bypassed. The optional argument ignore-count allows you to specify a further number of times to ignore a breakpoint at this location. • step - Continue running your program until control reaches a different source line, then stop it and return control.

  11. Stepping Continued • step count Continue running as in step, but do so count times. If a breakpoint is reached, or a signal not related to stepping occurs before count steps, stepping stops right away. • Next - Like step, however, if the current line of the program contains a function call, it executes the function and stops at the next line.Step stops at the beginning of the function.

  12. Miscellaneous • Print E – prints the value of E,in the current frame,in the program.E is a variable • Quit or ctrl-x – will quit gdb • display E - Print a variable's value at each step of a program • Help command – Provides a brief description of a GDB command

  13. Miscellaneous (cont) • Where – helps you to know where the program crashed. • Source www.cs.princeton.edu/~benjasik/gdb/gdbtut.html • There is also a reference card available through the web site.

More Related