1. 程式人生 > >C++實用技巧之配置Visual C++的偵錯程式顯示資料結構的格式(附Vczh Library++配置檔案)

C++實用技巧之配置Visual C++的偵錯程式顯示資料結構的格式(附Vczh Library++配置檔案)

今天我寫了一個給Visual C++用的配置,用來讓VC++在顯示自己寫的字串和容器等設施變得跟顯示STL一樣漂亮。VC++的可配置型還是很高的,我們只要寫一個xml,就可以改變偵錯程式對自己的資料結構的顯示了.

在這裡我簡單地介紹一下用法。假設大家覺得vlpp(Vczh Library++,也就是GacUI用的那個庫)的WString啊List這些東西在偵錯程式裡面顯示出來的東西太醜,就可以用以下三步來修改它。

1:去http://gac.codeplex.com/SourceControl/changeset/view/99419#2395529下載我寫的那個natvis檔案。這個檔案在整個zip包裡面的位置是Common\vlpp.natvis
2:把這個檔案複製到C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\Debugger\Visualizers(如果使用預設安裝路徑的話)
3:重啟你最喜愛的Visual Studio 2012,就可以看到下面的東西了:

image
空的智慧指標

image
有東西的智慧指標

image
有內容的“惰性計算”類

image
有內容但是還沒計算的“惰性計算”類

image
沒內容的“惰性計算”類

image
新鮮熱辣的容器

image
新鮮熱辣的對映

image
就連一對多的對映也是如此的新鮮熱辣

image
List<Nullable<vint>>的互相巢狀也是如此的完美

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">

  <Type Name="vl::ObjectString&lt;wchar_t&gt;"
> <DisplayString>{{ size={length}, buffer={buffer+start,su} }}</DisplayString> <StringView>buffer+start,su</StringView> <Expand> <Item Name="[size]">length</Item> <ArrayItems> <Size>length</Size> <
ValuePointer>buffer+start</ValuePointer> </ArrayItems> </Expand> </Type> <Type Name="vl::ObjectString&lt;char&gt;"> <DisplayString>{{ size={length}, buffer={buffer+start,s} }}</DisplayString> <StringView>buffer+start,s</StringView> <Expand> <Item Name="[size]">length</Item> <ArrayItems> <Size>length</Size> <ValuePointer>buffer+start</ValuePointer> </ArrayItems> </Expand> </Type> <Type Name="vl::collections::List&lt;*,*&gt;"> <AlternativeType Name="vl::collections::SortedList&lt;*,*&gt;"/> <AlternativeType Name="vl::collections::Array&lt;*,*&gt;"/> <DisplayString>{{ size={count} }}</DisplayString> <Expand> <Item Name="[size]">count</Item> <ArrayItems> <Size>count</Size> <ValuePointer>buffer</ValuePointer> </ArrayItems> </Expand> </Type> <Type Name="vl::collections::Dictionary&lt;*,*,*,*&gt;"> <AlternativeType Name="vl::collections::Group&lt;*,*,*,*&gt;"/> <DisplayString>{{ size={keys.count} }}</DisplayString> <Expand> <Item Name="[size]">keys.count</Item> <Item Name="Keys">keys</Item> <Item Name="Values">values</Item> </Expand> </Type> <Type Name="vl::Ptr&lt;*&gt;"> <AlternativeType Name="vl::ComPtr&lt;*&gt;"/> <DisplayString Condition="reference == 0">[empty]</DisplayString> <DisplayString Condition="reference != 0">{*reference}</DisplayString> <Expand> <Item Condition="reference != 0" Name="[ptr]">reference</Item> </Expand> </Type> <Type Name="vl::Lazy&lt;*&gt;"> <DisplayString Condition="internalValue.reference == 0">[empty]</DisplayString> <DisplayString Condition="internalValue.reference != 0 &amp;&amp; internalValue.reference->evaluated == false">[not evaluated]</DisplayString> <DisplayString Condition="internalValue.reference != 0 &amp;&amp; internalValue.reference->evaluated == true">{internalValue.reference->value}</DisplayString> <Expand> <Item Condition="internalValue.reference != 0 &amp;&amp; internalValue.reference->evaluated == true" Name="[value]">internalValue.reference->value</Item> </Expand> </Type> <Type Name="vl::ObjectBox&lt;*&gt;"> <DisplayString>{object}</DisplayString> <Expand> <ExpandedItem>object</ExpandedItem> </Expand> </Type> <Type Name="vl::Nullable&lt;*&gt;"> <DisplayString Condition="object == 0">[empty]</DisplayString> <DisplayString Condition="object != 0">{*object}</DisplayString> <Expand> <ExpandedItem Condition="object != 0">*object</ExpandedItem> </Expand> </Type> </AutoVisualizer>
posted on 2013-03-21 11:55 陳梓瀚(vczh) 閱讀(5585) 評論(6)  編輯 收藏 引用 所屬分類: C++C++實用技巧