Debugging in Visual C
- Programming in Visual C++ takes place in the Visual Studio interactive development environment (IDE), available at Microsoft.com/express. Within this environment, a programmer can write code in the editor, and then compile and debug it in one step. The compilation process in Visual Studio defaults to the "debug" setting, so the programmer can invoke the debugger by clicking the green arrow in the menu bar. This will begin execution of the program in debugging mode.
- A "break point" stops execution of code during debug mode. The programmer can set a break point in order to stop code at a certain point, and view the status of variables and functions up to that point. This allows the programmer to skip over long points of execution to check program status where problems may be occurring. Break points are set by clicking in the left code margin of the code editor. The programmer knows that a break point is set when a small red orb appears next to a line of code (Source 2).
- Once the debugger hits a break point, the programmer executes the code line by line by stepping over each line, using the "F10" key. As each line is stepped over, the program executes that single line of code. If the line contains a function, stepping over it will execute the entire function. In order to go into the function to also execute it line by line, the programmer has to step into the function using the "F11" key. Once in the function, the programmer can continue to use the "F10" key to step over lines contained inside the function.
- In the lower section of the debugging window a small sub-window resides, called a "watch" window. The programmer can keep track of variable values at any given break point, or any point of a program, by viewing the watch window. The watch window contains the values of any variables in the current code scope. If a variable represents an object, the watch window shows the values of the object's data fields as well as information regarding any of its methods. This way, the programmer can keep track of the program while stepping over or into lines of code during debugging.
Starting the Debugger
Break Points
Stepping Over and Into Code
Watch Window
Source...