VS2013 Natvis LegacyAddin 使用方法
2017-12-14 19:28
267 查看
1. 自定义类型: MyType
class MyType { public: char m_strName[32]; int m_nAge; };
2. 编写 natvis 文件: MyType.natvis
<?xml version="1.0" encoding="utf-8"?> <AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> <Type Name="MyType"> <DisplayString LegacyAddin="MyType.dll" Export="AddIn_MyType"></DisplayString> </Type> </AutoVisualizer>
3. 生成MyType.dll, 导出函数 AddIn_MyType
.htypedef struct tagDEBUGHELPER { DWORD dwVersion; HRESULT(WINAPI *ReadDebuggeeMemory)(struct tagDEBUGHELPER *pThis, DWORD dwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot); // from here only when dwVersion >= 0x20000 DWORDLONG(WINAPI *GetRealAddress)(struct tagDEBUGHELPER *pThis); HRESULT(WINAPI *ReadDebuggeeMemoryEx)(struct tagDEBUGHELPER *pThis, DWORDLONG qwAddr, DWORD nWant, VOID* pWhere, DWORD *nGot); int (WINAPI *GetProcessorType)(struct tagDEBUGHELPER *pThis); } DEBUGHELPER; typedef HRESULT(WINAPI *CUSTOMVIEWER)(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved);
.cpp
static LRESULT ReadMemory(DEBUGHELPER *pHelper, DWORDLONG qwAddr, DWORD nSize, VOID* pBuf, DWORD *nGot) { if (pHelper->dwVersion < 0x20000) { // Visual C++ 6.0 version if (pHelper->ReadDebuggeeMemory(pHelper, qwAddr, nSize, pBuf, nGot) != S_OK) { return E_FAIL; } } else { if (pHelper->ReadDebuggeeMemoryEx(pHelper, qwAddr, nSize, pBuf, nGot) != S_OK) { return E_FAIL; } } return S_OK; } __declspec(dllexport) HRESULT __stdcall AddIn_MyType(DWORD dwAddress, DEBUGHELPER *pHelper, int nBase, BOOL bUniStrings, char *pResult, size_t max, DWORD reserved) { // read file time from debuggee memory space if (pHelper->dwVersion >= 0x20000) { dwAddress = pHelper->GetRealAddress(pHelper); } DWORD nGot; char name[32] = { 0 }; int age = -1; ReadMemory(pHelper, dwAddress, sizeof(name), name, &nGot); ReadMemory(pHelper, dwAddress+ 32, sizeof(age), &age, &nGot); sprintf_s(pResult, max, "name: %s, age: %d", name, age); return S_OK; }
4. 部署并测试
将 MyType.natvis 和 MyType.dll 一起放入下面文件夹中的其中之一%VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers (requires admin access) %USERPROFILE%\My Documents\Visual Studio 2012\Visualizers\ VS extension folders
测试结果如下:
参考文章:https://stackoverflow.com/questions/11545418/how-to-write-a-custom-native-visualizer-dll-for-visual-studio-2012-debugger/11545420#11545420
相关文章推荐
- Qt用VS添加RC文件(顺便讲Qt-VS-Addin插件使用方法)
- VS2013使用SQL2012的具体方法
- VS2013中编译项目在静态库中使用MFC出现错误的解决方法
- VS2013在MFC中使用ADO方法操作Access2013数据库
- 有关VS2013中,使用scanf函数报错的解决方法
- VS2013使用winsock.h和winsock2.h发生冲突后的终极解决方法
- VS2013配置OPenGL的 方法以及超级宝典五中所使用的方案
- VS2012/2013(简称VS)Lua编辑和调试方面的工具------BabeLua的使用方法
- vs 2013 cl 查看内存模型使用方法
- VS2013添加使用lib的方法
- VS2013 TeeChart控件使用方法
- 求助:如何使用VS的Profiler跟踪框架内部的方法调用?
- VISTA中注册表项LEGACY_****的删除--另一种方法:使用psExec
- vs 2008自带报表使用方法
- VS.NET 查找未使用过的方法
- Qt 使用vs调试的方法
- VS 2008 学习笔记(5) --- CTabCtrl 使用方法
- 在VS集成IDE中使用OpenGL的配置方法
- 在非英文版 Visual Studio 中使用 WSPBuilder VS Addin 的问题
- VS 2005 Web Application Project 项目中Profile的使用方法(更新)