Tag Archives: Programming

Visualizing STLPort data structures in Visual Studio Debugger

Recently, I had to use STL Port for a particular project. While debugging, I was hampered by the fact that my data structures were not providing as much information in the watch window as I would have hoped. Using std::vector as an example, here’s a screen shot that highlights the problem.

Screentshot before modifications to autoexp.bat file

Screentshot before modifications to autoexp.bat file

After a bit of investigation I disovered the wonderful autoexp.dat file for Visual Studio. Visual studio 2005 and 2008 allow you to customize native variable watch: i.e. how a variable previews in the watch window and tooltips. This is done via a file called autoexp.dat (auto-expand), which is hidden deep inside the VS installation (%VS_INSTALL_DIR%\Common7\Packages\Debugger). Official documentation on the specifics of the scripting language is sparse, and Microsoft’s MSDN article contains the disclaimer “The structure of this file and syntax of autoexp rules might change from one release of visual studio to the next”.

For most part, the instructions on how to write auto-expand rules for native types are located in the file itself. There are some other resources that are great to get started

Anyway, back to my predicament. After some research and some trial and error, the following visualizer worked for STLPort’s std::vector.

;———————————————–
;  STLPORT visualizer
;———————————————–

;———————————————–

;  stlp_std::vector
;———————————————–
stlp_std::vector<*>{
children
(
#array
(
expr :    ($c._M_start)[$i],

size :    $c._M_finish-$c._M_start
)
)
preview
(
#(
“[",
$e._M_finish - $e._M_start ,
"](“,

#array
(
expr :     ($c._M_start)[$i],
size :     $c._M_finish-$c._M_start
),
“)”
)

)
}

I copied the above block in the autoexp.dat file of my Visual Studio installation, and tried to look at the data structures again. I discovered that I had to make a slight modification to the above visualiser for it to work properly in the debug mode. STLPort uses debug versions of data structures in debug builds, and as a result I had to rename stlp_std::vector to stlpd_std::vector for things to work as expected. Here’s the visualiser for debug builds, followed by the screenshot of how things acually look in the watch window.

;———————————————–

;  stlpd_std::vector
;———————————————–
stlpd_std::vector<*>{
children
(
#array
(
expr :    ($c._M_start)[$i],

size :    $c._M_finish-$c._M_start
)
)
preview
(
#(
“[",
$e._M_finish - $e._M_start ,
"](“,

#array
(
expr :     ($c._M_start)[$i],
size :     $c._M_finish-$c._M_start
),
“)”
)

)
}

Screentshot after modifications to autoexp.bat file

Screentshot after modifications to autoexp.bat file

The resources linked above should be a great place if you want to experiment with autoexp.dat file.

I must point out that there is a potentially better way to create visualizers for custom types. MSDN has a couple of good articles to get you started, particularly Visualizers and How to: Write a Visualizer

4 Comments

Filed under Debugging, Programming