在Visual Studio调试器中显示Google Protocol Buffers容器类型的值
Google Protocol Buffers会生成RepeatedField和Map等容器类型,为方便在Visual Studio中进行调试,编写了如下natvis文件,可以保存为pb.natvis,然后放在Visual Studio安装目录下的Common7\Packages\Debugger\Visualizers目录中,如: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Packages\Debugger\Visualizers目录;也可以放在用户根目录或者直接放在项目中。
1<?xml version="1.0" encoding="utf-8"?>
2
3<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
4 <Type Name="google::protobuf::RepeatedField<*>">
5 <DisplayString>{{ size={current_size_} }}</DisplayString>
6 <Expand>
7 <Item Name="[size]" ExcludeView="simple">current_size_</Item>
8 <Item Name="[capacity]" ExcludeView="simple">total_size_</Item>
9 <ArrayItems Condition="ptr_.rep != 0">
10 <Size>current_size_</Size>
11 <ValuePointer>($T1*)ptr_.rep->elements</ValuePointer>
12 </ArrayItems>
13 </Expand>
14 </Type>
15 <Type Name="google::protobuf::RepeatedPtrField<*>">
16 <DisplayString>{{ size={current_size_} }}</DisplayString>
17 <Expand>
18 <Item Name="[size]" ExcludeView="simple">current_size_</Item>
19 <Item Name="[capacity]" ExcludeView="simple">total_size_</Item>
20 <ArrayItems Condition="rep_ != 0">
21 <Size>current_size_</Size>
22 <ValuePointer>($T1**)rep_->elements</ValuePointer>
23 </ArrayItems>
24 </Expand>
25 </Type>
26 <Type Name="google::protobuf::Map<*>">
27 <DisplayString>{{size={elements_->num_elements_}}}</DisplayString>
28 <Expand>
29 <CustomListItems MaxItemsPerView="5000" ExcludeView="Test">
30
31 <Variable Name="iBucket" InitialValue="elements_->index_of_first_non_null_" />
32 <Variable Name="pBucket" InitialValue="elements_->table_ == nullptr ? nullptr : ((InnerMap::Node**)elements_->table_)[elements_->index_of_first_non_null_]" />
33 <Variable Name="iBucketIncrement" InitialValue="-1" />
34
35 <Size>elements_->num_elements_</Size>
36 <Loop>
37 <If Condition="pBucket == nullptr">
38 <Exec>iBucket++</Exec>
39 <Exec>iBucketIncrement = __findnonnull(((InnerMap::Node**)elements_->table_) + iBucket, elements_->num_buckets_ - iBucket)</Exec>
40 <Break Condition="iBucketIncrement == -1" />
41 <Exec>iBucket += iBucketIncrement</Exec>
42 <Exec>pBucket = ((InnerMap::Node**)elements_->table_)[iBucket]</Exec>
43 </If>
44 <Item>(((InnerMap::Node*)pBucket)->kv.v_)</Item>
45 <Exec>pBucket = pBucket->next</Exec>
46 </Loop>
47 </CustomListItems>
48 </Expand>
49 </Type>
50</AutoVisualizer>
祝好!
- 原文作者:Witton
- 原文链接:https://wittonbell.github.io/posts/2019/2019-06-24-在Visual-Studio调试器中显示Google-Protocol-Buffers容器类型的值/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。