In this tutorial I'm gonna explain how to pause your program at a selected line and see the program data during execution.
Visual Studio allows to select a position of the code in which to pause the execution by clicking over the grey line at the left of the editor area. In the image below we can see a breakpoint added (the red dot) with the program paused and the mouse over a variable showing the data contents of the variable (which hold invalid values because nothing was assigned yet):
For running the program in debug mode you can either press F5 or go to menu Tools -> Start Debugging and it will pause at the first breakpoint reached. To continue execution after the breakpoint press F5 again.
This enables us to analyze the program flow step by step and see the contents of the data in memory. In the next image we can see the contents of gameMap have changed after the setup() call:
We can see then how our data changes as the program runs each line:
If we want to move to the next line but keep with the execution paused, we can press F10 or select the "step over" option in the Debug menu. If you want to jump inside the function being called in that line, you can press F11 or select the "step into" option in the Debug menu.
Knowing how to debug your program is necessary for any program you want to make and Visual Studio makes it very easy. Now you will be able to work and analyze the program flow better when you read the next tutorial about updating the game map seen in our previous program.




No hay comentarios:
Publicar un comentario