在Visual Studio调试器中显示Google Protocol Buffers容器类型的值

47 篇文章 7 订阅
42 篇文章 7 订阅

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目录;也可以放在用户根目录或者直接放在项目中。

<?xml version="1.0" encoding="utf-8"?>

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
	<Type Name="google::protobuf::RepeatedField&lt;*&gt;">
		<DisplayString>{{ size={current_size_} }}</DisplayString>
		<Expand>
			<Item Name="[size]" ExcludeView="simple">current_size_</Item>
			<Item Name="[capacity]" ExcludeView="simple">total_size_</Item>
			<ArrayItems Condition="ptr_.rep != 0">
				<Size>current_size_</Size>
				<ValuePointer>($T1*)ptr_.rep->elements</ValuePointer>
			</ArrayItems>
		</Expand>
	</Type>
	<Type Name="google::protobuf::RepeatedPtrField&lt;*&gt;">
		<DisplayString>{{ size={current_size_} }}</DisplayString>
		<Expand>
			<Item Name="[size]" ExcludeView="simple">current_size_</Item>
			<Item Name="[capacity]" ExcludeView="simple">total_size_</Item>
			<ArrayItems Condition="rep_ != 0">
				<Size>current_size_</Size>
				<ValuePointer>($T1**)rep_->elements</ValuePointer>
			</ArrayItems>
		</Expand>
	</Type>
	<Type Name="google::protobuf::Map&lt;*&gt;">
		<DisplayString>{{size={elements_->num_elements_}}}</DisplayString>
		<Expand>
			<CustomListItems MaxItemsPerView="5000" ExcludeView="Test">

				<Variable Name="iBucket" InitialValue="elements_->index_of_first_non_null_" />
				<Variable Name="pBucket" InitialValue="elements_->table_ == nullptr ? nullptr : ((InnerMap::Node**)elements_->table_)[elements_->index_of_first_non_null_]" />
				<Variable Name="iBucketIncrement" InitialValue="-1" />

				<Size>elements_->num_elements_</Size>
				<Loop>
					<If Condition="pBucket == nullptr">
						<Exec>iBucket++</Exec>
						<Exec>iBucketIncrement = __findnonnull(((InnerMap::Node**)elements_->table_) + iBucket, elements_->num_buckets_ - iBucket)</Exec>
						<Break Condition="iBucketIncrement == -1" />
						<Exec>iBucket += iBucketIncrement</Exec>
						<Exec>pBucket = ((InnerMap::Node**)elements_->table_)[iBucket]</Exec>
					</If>
					<Item>(((InnerMap::Node*)pBucket)->kv.v_)</Item>
					<Exec>pBucket = pBucket->next</Exec>
				</Loop>
			</CustomListItems>
		</Expand>
	</Type>
</AutoVisualizer>

祝好!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值