Repository navigation
04. Debugging
Ashish Bhattarai edited this page Apr 29, 2021
·
6 revisions
In the following demostration, the Michi project that comes in the C-Programming-Guide.
You can use git to clone the project, or you can download the project from the link. You can either open Michi.sln using visual studio or build using CLANG (build.bat file generates PDB automatically if you have CLANG compiler in your path)
*Note: The pictures how alternative way of doing the same thing using GUI
- Press [F5] to run the program, then exit the program.
- Press [F10] or [F11] to start debugging the program
- Press [F10] to step over, and [F11] to step into each source code line
- Notice the difference between Step Over and Step Into (try step over and into in a line with a function call)
- Breakpoints are the points that you set in your program on which the debugger breaks (stops) the program.
- To set a breakpoint, goto the line you want to set a breakpoint and press [F9], to unset the breakpoint press [F9] again.
- You can also click on the column to the right of line number to set or unset the breakpoints. When you set a breakpoint, a red circle will be shown as an indicator
- After you set the breakpoint, press [F5] to run the program, now you can step into and step over again as before
- To put a breakpoint on a function, you can directly press [Ctrl+B] and type the name of the funtion, or you can go in the Menu:
Debug->New Breakpoint->Function Breakpoint - To view all the breakpoints, press [Ctrl+Alt+B], or in the Menu:
Debug->Windows->Breakpoints - To remove all the breakpoints from the project, press [Ctrl+Shift+F9], or in the Menu:
Debug->Delete All Breakpoints - You can set or unset the breakpoints in the while you are in mid debuging session
- Once you are in debugging session, you can get access to the Watch window:
Debug->Windows->Watch - You can give name of variables in the watch windows and video it's values
- Combine this with stepping in and over, you get to see the values in each step of the program
- You can also have constant expression results in the watch window (i.e. using it as calculator)
- You can right click on the watch windows and select hexa-decimal display which is useful sometimes
- You can put pointer variable with number separate by comma (
ptr, 12) and the watch window will show the number of consecutive address values