Hello everyone, I’ve spent the last couple of days debugging Clang and peeking inside SmallVector and Token really annoyed me so I decided to write some visualizers to make my life easier. I hope somebody else finds this useful and if you have any ideas about other types that should be supported just ask and I’ll try to add them.
There are two ways to make this work:
- Put the path to clangVisualizer.txt in the environmental variable called _vcee_autoexp and restart your Visual Studio. This method should work for Visual Studio 2008 and 2010 and is less invasive.
- Copy everything except the [Visualizer] tag from clangVisualizers.txt to C:\Program Files\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\autoexp.dat. Make sure you backup your original autoexp.dat first. This should work for Visual Studio 2005 and above.
Here are the visualizers in action:
Token Visualizer
SmallVector Visualizer (It works just like the one for std::vector, displays size, capacity and elements)
If you’d like to disable the visualizer for a specific variable just type variable_name,! inside the watch window.
clangVisualizers.txt (530 Bytes)
Cool.
Could you turn these instructions into a patch against
http://clang.llvm.org/hacking.html#debugging
?
I'd like for this to go into the Clang tree so everyone can get to it, but we need documentation for people to find it.
- Doug
Here’s a patch. You might want to change the beginning to include the full path to clangVisualizers.txt. I would’ve done this myself but I have no idea where will this file end up inside the source tree 
Added visualizer for StringRef (assumes null terminated string which I know isn’t the case always, but I don’t think there’s a way around this)
clangVisualizers.txt (709 Bytes)
hacking.html.patch (1.39 KB)
Added visualizer for StringRef (assumes null terminated string which I know
isn't the case always, but I don't think there's a way around this)
That's curious - though I just verified that even VS2010's
std::basic_string visualizer has the same limitation. Pity.
int main()
{
const char xs = "foo\0bar";
std::string x(xs, xs + sizeof(xs));
}
(mouseover at 'x' shows only "foo" in the preview, though the details
show a size of 8 & both null characters in there)
This is because tooltip (preview section) is evaluated using format specifiers and they only support null-terminated strings (there is more about this inside autoexp.dat). Details are evaluated using #array and correct size, so there is at least a way to get to all the characters.
Committed as r136207, thanks!
Here's a patch with visualizers for PointerIntPair and all
PointerUnions. Somebody please commit.
I've also added some people to CC that I think might be interested in
this Windows debugging stuff. Are there any other types that need a
visualizer?
clangVisualizers.patch (2.05 KB)
Here's a patch with visualizers for PointerIntPair and all
PointerUnions. Somebody please commit.
Committed in r149896, thanks!
I've also added some people to CC that I think might be interested in
this Windows debugging stuff. Are there any other types that need a
visualizer?
Anything which requires bit twiddling to get at the underlying data is
a great candidate. I can't think of any off the top of my head, but
as I run into them I'll keep a running list.
Thanks for the patch!
~Aaron
New visualizers were missing a namespace so here is a fixed version. I
also added a small change that seems to make them better 
clangVisualizers.txt.patch (1.21 KB)
Sorry for the delay in reviewing -- patch looks good, committed in r152514.
Thanks!
~Aaron