- Casting using ()
- taking an address using &
- expression building
5 min read
Opinion: Debugging C++ with Visual Studio
In this reprinted #altdevblogaday-opinion piece, graphics programmer Daan-Nijs shares several obscure techniques for debugging with Visual Studio, like changing a value/type in the Watch Window, and more.
[In this reprinted #altdevblogaday-opinion piece, graphics programmer Daan-Nijs shares several obscure techniques for debugging with Visual Studio, like changing a value/type in the Watch Window, re-running or skipping code, and more.] Debugging tends to be a lone wolf activity, and most of the things I learned about the Visual Studio debugger came from random glances at a co-workers screen, doing a double take, and shouting "You can do that???" to the annoyance of everyone else in the room. Hence, I want to introduce some techniques which I picked up the same way, in the hope that I can shave off some time off your Edit-Compile-Debug cycle. The explanations are terse, as these things are time-savers and I want to do the same. They're also aimed at people who have some basic knowledge, for example watching a value or stepping through code. Changing A Value In The Watch Window Sometimes you want to test your code to see if it handles certain values. The slow way is to write a test and compile/run it. The fast way is to run it and just change whatever value is already going in. To do this, load up the value in the watch window, and double click on the entry in the "value" column. You should now be able to edit the value, ENTER to commit. The changed value should now be displayed in red. This works on numerical and pointer types. Changing A Type In The Watch Window While the debugger is good at what it does, we still see more than it does. For example, maybe we're watching a value of type A, while we know we are dealing with inherited class B that derives from A. If we want to inspect B's values in the debugger, we have two options. The slow way is to edit the code to downcast from A to B, compile, run, and load this in the watch window. The fast way is to edit the declaration directly in the watch window. To do this, load up the variable declared as type A in the watch window. Double-click on the name column, and again you will be faced with an input field. The following are allowed as far as I know: