Lab 1 - Using the debugger in Visual Studio

advertisement
Name: ___________________________________
Lab 1 - Using the debugger in Visual Studio
 The objective for this lab is for you to become familiar with debugging in VS. When you finish, you should know
how to set breakpoints, view the contents of local variables, and set watches.
 You need to be able to see the line numbers of the code. If you can't see the line numbers, do the following:
o Click on Tools->Options
o On the left side, scroll down to Text Editor, go to C/C++ and expand the selection.
o Select General and then place a check mark in the Line numbers box.
 If at any time you need to start over, select Debug->Stop Debugging or hit [Shift]F5
Follow these steps and answer the questions along the way:
1. Download the file "Debugging.cpp" from cs.mwsu.edu/~cerise/
2. Add it to a project and build the solution.
3. Notice that there are global variables along with a function named addNums.
4. Add a breakpoint on lines 7, 15, and 18.
5. Hit Local Windows Debugger (green arrow) or hit F5.
6. Did it stop at the breakpoint on line 7? _____________
7. Hit Continue (or F5) to run to line 16. Select Debug->Windows->Local if that window is not already open at the
bottom.
8. Which 2 local variables were initialized? ___________________________________________
9. Why do the others have garbage?
_____________________________________________________________________________
10. Why don't the variables globalX, globalY, globalFlag, and globalFlag2 show up in this window?
____________________________________________________________________________
11. To see their values, you can set a watch on them. If there is not a Watch tab at the bottom, go to Debug->
Windows->Watch->Watch1. Click under name and enter the names of each global variable and then [ENTER]
12. Which global variables have garbage? ____________________
13. Why do none of the global variables have garbage in them?
___________________________________________________________________________
14. Next, go back to the Locals tab. Hit F10 (Step over) and watch as x and localX change.
Name: ___________________________________
15. You should be on line 18 after the loop. (Remember that if you go too far, stop by using Shift + F5 and just start
over.) What is the value of x at that point? _____________ What is in localX? ____________________
16. Make sure you are on line 18. Use F11 to step into the addNums function.
17. Why did localX, localY, localFlag, and localFlag2 disappear from the Locals tab?
___________________________________________________________________________
18. Use F10 (Step over) to step through the loop. Stop at line 34. Which variables are considered local inside this
function and what are their values at this point?
19. Click on the Watch1 tab. Hit F10 until you reach line 34. Which global variable(s) changes in this function?
____________________ What happens when its value changes?
______________________________________________________
20. Now click back on the Locals tab. Hit F10 until you are back in main at line 18. Notice how the list of local
variables changes. Also notice that you see "addNums returned". What value is returned?
_____________________
21. Click on the Watch1 tab and notice how the global variables change values after lines 21 and 22.
22. Hand this paper to the GA and make sure you sign the gold sign-in sheet.
Download