Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School.

Similar presentations


Presentation on theme: "Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School."— Presentation transcript:

1 Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI E-mail: droberts@cs.iupui.edu Department of Computer and Information Science, School of Science, IUPUI Fall 2003

2 Dale Roberts 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 Dale Roberts 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 Dale Roberts 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 Dale Roberts 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 run – will start your program as if you had typed a.out You can provide command line arguments if the program requires. You can provide command line arguments if the program requires.

6 Dale Roberts 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 Dale Roberts 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 Dale Roberts 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. watch expr - Sets a watchpoint for an expression. info watchpoints - Prints a table of all watch points set and not deleted

9 Dale Roberts 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 Dale Roberts 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 Dale Roberts 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 Dale Roberts 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 Dale Roberts Miscellaneous (cont) Where – helps you to know where the program crashed. Source www.cs.princeton.edu/~benjasik/gdb/gdbt ut.html www.cs.princeton.edu/~benjasik/gdb/gdbt ut.html www.cs.princeton.edu/~benjasik/gdb/gdbt ut.html There is also a reference card available through the web site.

14 Dale Roberts

15


Download ppt "Dale Roberts Debugger Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School."

Similar presentations


Ads by Google