DebuggerGDBGDB cont….GDB CommandsRun commandBreak pointsBreak points Cont….Watch PointsDeleting Break and Watch pointsContinue and steppingStepping ContinuedMiscellaneousMiscellaneous (cont)Slide 14Slide 15Dale RobertsDebuggerDebuggerDale Roberts, LecturerComputer Science, IUPUIE-mail: [email protected] of Computer and Information Science,School of Science, IUPUIDale RobertsGDB GDB The purpose of a debugger such as GDB is to allow you to see what is The purpose of a debugger such as GDB is to allow you to see what is going on inside the program while it executes.going on inside the program while it executes.GDB – GNU debuggerGDB – GNU debuggerGDB can be used to debug programs written in C, C++.GDB can be used to debug programs written in C, C++.The C++ debugging facilities are jointly implemented by the C++ compiler The C++ debugging facilities are jointly implemented by the C++ compiler and GDB. Therefore, to debug your C++ code, you must compile your C++ and GDB. Therefore, to debug your C++ code, you must compile your C++ programs with a supported C++ compiler, such as GNU programs with a supported C++ compiler, such as GNU g++g++, or the HP , or the HP ANSI C++ compiler (ANSI C++ compiler (aCCaCC) with a –g option to include symbols. ) with a –g option to include symbols.Dale RobertsGDB cont….GDB cont….GDB can do four main kinds of things (plus other things in support GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act: of these) to help you catch bugs in the act: Start your program, specifying anything that might affect its Start your program, specifying anything that might affect its behavior. behavior. Make your program stop on specified conditions. Make your program stop on specified conditions. Examine what has happened, when your program has stopped. Examine what has happened, when your program has stopped. Change things in your program, so that you can experiment with Change things in your program, so that you can experiment with correcting the effects of one bug and go on to learn about another.correcting the effects of one bug and go on to learn about another.Dale RobertsGDB CommandsGDB CommandsGDB is invoked by running the program gdb. Once the debugger is started, 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 GDB reads command until you tell it to exit. GDB can be started with variety of arguments and options.variety of arguments and options.The most usual way to start debugging isThe most usual way to start debugging is gdb gdb program – program – one argument, which is an executable fileone argument, which is an executable file more than one arguments can be providedmore than one arguments can be provided gdb gdb program coreprogram core – two arguments, one executable and one core file – two arguments, one executable and one core file gdb gdb program 1234 – program 1234 – specify process id as second argumentspecify process id as second argumentDale RobertsRun commandRun commandWhen gdb starts, your program is not actually running. It won't run until When gdb starts, your program is not actually running. It won't run until you instruct gdb how to run it.you instruct gdb how to run it. run – will start your program as if you had typedrun – will start your program as if you had typed a.outa.out You can provide command line arguments if the program You can provide command line arguments if the program requires.requires.Dale RobertsBreak pointsBreak pointsA A break break point makes your program stop whenever a certain point in the point makes your program stop whenever a certain point in the program is reachedprogram is reachedWays to set a break pointWays to set a break point break break functionfunction - Set a breakpoint at entry to function - Set a breakpoint at entry to function functionfunction break break +offset+offset - - break -break -offsetoffset - Sets a breakpoint some number of lines forward or back - Sets a breakpoint some number of lines forward or back from the position at which execution stopped.from the position at which execution stopped. break break linenumlinenum - Sets a breakpoint at line - Sets a breakpoint at line linenumlinenum in the current source in the current source filefileDale RobertsBreak points Cont….Break points Cont….break break filenamefilename::functionfunction - Sets a breakpoint at entry to function - Sets a breakpoint at entry to function functionfunction found in file found in file filenamefilename. Specifying a file name as well as a function . Specifying a file name as well as a function name is superfluous except when multiple files contain similarly named name is superfluous except when multiple files contain similarly named functions.functions. info breakpoints info breakpoints info break info break Print a table of all breakpoints and watch points set and not deleted Print a table of all breakpoints and watch points set and not deletedDale RobertsWatch PointsWatch PointsA A watch watch point is a special breakpoint that stops your program when the point is a special breakpoint that stops your program when the value of an expression changesvalue of an expression changesWays to set a watch pointWays to set a watch point watch watch exprexpr - Sets a watchpoint for an expression. - Sets a watchpoint for an expression. info watchpointsinfo watchpoints - Prints a table of all breakpoints and watch points set - Prints a table of all breakpoints and watch points set and not deleted and not deletedDale RobertsDeleting Break and Watch pointsDeleting Break and Watch pointsDeleting Break points and watch pointsDeleting Break points and watch pointsclearclear clear clear functionfunction clear clear filenamefilename::functionfunction clear clear linenumlinenum clear clear filenamefilename::linenumlinenum delete n – deletes the break point. delete n – deletes the break point. n is a break point number.n is a break point number.Dale RobertsContinue and steppingContinue and steppingcontinue [continue [ignore-countignore-count]] - - ContinuingContinuing means resuming program means resuming program execution until your program completes normally.execution until your program completes normally. Resumes program execution, at the address
View Full Document