190 likes | 310 Views
LESSON 20. Overview of Previous Lesson(s). Over View. Debugger A program that controls the execution of program code in such a way that we can step through the source code one line at a time, or run to a particular point in the program.
E N D
Overview of Previous Lesson(s)
Over View • Debugger • A program that controls the execution of program code in such a way that we can step through the source code one line at a time, or run to a particular point in the program. • A breakpoint is a point in our program where the debugger automatically suspends execution when in debugging mode. • A trace-point is a special kind of breakpoint that has a custom action associated with it.
Over View.. Following are the ways of starting application in debug mode.
Over View... • Local tab • The Locals tab shows the values of the variables local to the current function. • Auto Tab • Shows the automatic variables in use in the current statement and its immediate predecessor. • Threads Tab • Allows to inspect and control threads in advanced applications
Over View... • Modules Tab • Lists details of the code modules currently executing. • Watch1 Tab • Variables can be added to the Watch1 tab that we want to watch.
Over View… #include <cassert> void assert(int expression); #define NDEBUG // Switch off assertions in the code #include < cassert > // Declares assert()
Contents • Customized Debugging Code • Debugging a program • The Call Stack • Step Over to the Error
Customized Debugging Code • Customized debugging code is aimed at highlighting bugs wherever possible and providing tracking output to help you pin down where the bugs are. • Line by line debugging is monotonous & longish. • Only required in testing a phase.
Customized Debugging Code.. • This overhead is not needed in the final version. • So this code only operates in the debug version of a program, not in the release version. • The output produced by debug code provide clues as to what is causing a problem.
Adding Code • Using preprocessor directives, a programmer can add any code to the program. • Preprocessor symbol, DEBUG, is always defined automatically in Visual C++ in the debug version of a program, but is not defined in the release version. • Debugging code is enclosed between a preprocessor #ifdef / #endif pair of directives.
Adding Code.. #ifdef _DEBUG // Code for debugging purposes... #endif // _DEBUG • The code between the #ifdefand the #endifis compiled only if the symbol DEBUG is defined.
Adding Code... • The debug code can do anything that is helpful in the debugging process. • Simply outputting a message. • To trace the sequence of execution to providing additional calculations to verify and validate data, or calling functions providing debug output.
Adding Code... • Many blocks of debug code can be written in the source program. • Can use customized preprocessor symbols to provide more selectivity as to what debug code is included. • Ex .. some of debug code may produce voluminous output and only want to generate when it was really necessary. • To provide granularity in debug output, so we can pick & choose which output is produced on each run.
Adding Code... The following directives will ensure that these symbols are defined only if DEBUG is defined: #ifdef _DEBUG #define MYDEBUG #define VOLUMEDEBUG #endif Lets try it …
The Call Stack • The call stack stores information about functions that have been called and are still executing because they have not returned yet. • Call stack window shows the sequence of function calls outstanding at the current point in the program.
The Call Stack.. • The sequence of function calls outstanding runs from the most recent call at the top.