Displaying idLib types nicely in MSVC debugger

From The DarkMod Wiki
Jump to navigationJump to search

Extra-short summary

The MSVS can be configured to show TDM objects (mostly idLib containers) nicely in the watch. To benefit from it you have to follow the instructions located in:

 \darkmod_src\tools\autoexp\

directory inside the darkmod_src SVN repo.

Introduction

In Visual Studio debugger you can see the value of any variable by either adding it to watch or holding a mouse cursor over it. Unfortunately, the information is often shown in uncomfortable way. If you want to watch the contents of an array, you'll likely see only the first element by default. If you watch the contests of an objects, you'll see all of its members, which is not nice in case the object represents a container.

Luckily, these problems can be easily solved.

Watching arrays

If you need to watch static-sized array (like "int arr[256];"), then by default all the 256 elements are shown in the watch. But in TDM you'll mostly come across dynamically allocated arrays (like "int *arr = new int[256];"). In this case debugger has no way to know the size of array, that's why it shows only one element. You can manually specify how many elements of the array to display for the pointer. Just type in the watch:

 arr,240

and you'll see exactly 240 first elements of the array.

Watching custom objects

By default any object in watch is displayed as a collection of its members. Generally it is good enough. But if the object is a commonly used container (like "idList<int> v;") then you have to type "v.list,100" each time you want to see considerable quantity of its elements.

This problem is almost identical for idLib, STL and boost containers. But since STL is integrated into the C++ language, MSVC displays all the STL containers in a nice way. This feature is implemented via the "autoexp.dat" config file inside the MSVS installation. Luckily, we can add our own templates to this file to customize the way objects of our classes are displayed. The "autoexp.dat" file is very scarcely documented by Microsoft. The only comprehensive piece of documentation is this article:

http://www.virtualdub.org/blog/pivot/entry.php?id=120

The up-to-date templates for TDM project are located in "darkmod_src\tools\autoexp\" directory inside darkmod_src SVN repository. The installation readme is located there too. By installing the templates you'll get comfortable view of the following idLib containers:

  1. idStr - the string itself is displayed in the preview: Autoexp IdStr.png
  2. idList, idStaticList - they look and behave almost like std::vector now: all the actual elements are shown: Autoexp IdList.png
  3. idKeyValue, idDict - they can be watched as an array of key/value pairs in convenient way: Autoexp IdDict.png

The appearance of idHashIndex container is improved a bit, but it is still far from perfect. idLinkList is not implemented: autoexp is familiar with linked lists, but it doesn't want to swallow idLinkList for some reason...

Suppressing the autoexp templates

Suppose that you have a list "idList<int> corrupted;" and you suspect that it is corrupted. You need to see all its members in this case. To see them you need only to add ",!" when you type the object into the watch:

 corrupted,!