Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio debugger tips & tricks (for C/C++ projects)

I'm interested in tips and tricks regarding debugging a C/C++ project in Visual Studio's debugger. I recently found out that if you have a pointer to a certain data type, let's say char* ptr, then you can see it as an array in the watch window using a syntax such as:

ptr,10

This will display the first 10 elements from the ptr address, in the same way as it would be displayed if the definition would be:

char ptr[10];

What other tips and tricks do you know about Visual Studio debugger?

PS: I hope this subject wasn't already discussed. Should you find a similar post, please let me know.

like image 764
botismarius Avatar asked Oct 20 '08 11:10

botismarius


People also ask

How do I Debug a code in Visual Studio?

To bring up the Run and Debug view, select the Run and Debug icon in the Activity Bar on the side of VS Code. You can also use the keyboard shortcut Ctrl+Shift+D. The Run and Debug view displays all information related to running and debugging and has a top bar with debugging commands and configuration settings.


2 Answers

I really like the possibility to tweak the Debugger display of types and structures through AutoExp.dat. The file is located at

..\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\autoexp.dat

and allows to define own templates for the display of data during debugging:

While debugging, Data Tips and items in the Watch and Variable windows are automatically expanded to show their most important elements. The expansion follows the format given by the rules in this file. You can add rules for your types or change the predefined rules.

The file is full of good examples and you can easily adapt certain templates to your own needs or add new ones for your own classes.

like image 92
fhe Avatar answered Oct 12 '22 00:10

fhe


You can set the names of your threads using a somewhat awkward piece of code. See this article at MSDN.

like image 30
staffan Avatar answered Oct 12 '22 01:10

staffan