背景
c++开发的软件在生产环境中运行出现一些bug,比如参数错误等问题,通过日志只能打印异常的行号或函数,但具体的结构体/类的参数内容打印却非常麻烦,无法做到一些更高级语言的反射功能。
要做到能够通过变量地址就打印变量的内容信息,就需要依赖ms提供的msdia120.dll和程序编译后的pdb文件。
原理
msdia120.dll 需要注册到目标机器,通过提供的接口函数可以解析pdb文件中的结构体、类,并提供这个成员变量的类型、相对的地址偏移。
效果
demo
1 | #include <typeinfo> |
输出效果
1 | { |
后续在每个关键函数的入口增加一个宏定义,就可以轻松的定位参数错误的问题,而省去了大量的远程调试时间。
二次开发
visual studio 的安装路径下存在一个demo程序:DIA SDK 。可以通过修改其中的代码实现,当然
我的百度网盘有封装后的sdk更加容易使用。
https://pan.baidu.com/s/1takuuHhxGt_WkLQWGDeacQ
- msdia120.dll
- tcDump.dll
- tcDump.h
- tcDump.lib
- tcDumpD.lib
- tcDumpD.dll
- 使用说明.txt