如果你更喜欢 c++ 而不是 c,你可以使用 windbg sdk 提供的 engextcpp 框架
提供可单击 dml 链接的示例代码,单击该链接时将在当前指令指针处打印调用堆栈
编译前的目录内容
D:\barebones>ls
barebones.cpp barebones.def
源代码
D:\barebones>cat barebones.cpp
#include <engextcpp.cpp>
#pragma comment (lib ,"dbgeng.lib")
class EXT_CLASS : public ExtExtension
{
public:
EXT_COMMAND_METHOD(barebones);
};
EXT_DECLARE_GLOBALS();
EXT_COMMAND(barebones,"","")
{
DmlCmdExec( "CallStack\n","kb");
}
def文件的内容
D:\barebones>cat barebones.def
EXPORTS
DebugExtensionInitialize
DebugExtensionUninitialize
DebugExtensionNotify
barebones
init vs devcmd 提示
D:\barebones>runvs
D:\barebones>pushd .
D:\barebones>cd /d "c:\Program Files\Microsoft Visual Studio\2017\Community\Common7\Tools\"
c:\Program Files\Microsoft Visual Studio\2017\Community\Common7\Tools>vsdevcmd.bat
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.4
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
c:\Program Files\Microsoft Visual Studio\2017\Community\Common7\Tools>popd
目录后编译链接的内容
D:\barebones>cl /Zi /W3 /EHsc /Od /LD /nologo /I e:\windjs\windbg_18362\inc barebones.cpp /link /release /def:barebones.def /nologo
barebones.cpp
Creating library barebones.lib and object barebones.exp
D:\barebones>ls -lg
total 7684
-rw-rw-rw- 1 0 247 2019-10-03 16:46 barebones.cpp
-rw-rw-rw- 1 0 96 2019-10-03 16:09 barebones.def
-rw-rw-rw- 1 0 373248 2019-10-03 16:54 barebones.dll
-rw-rw-rw- 1 0 1198 2019-10-03 16:54 barebones.exp
-rw-rw-rw- 1 0 2520 2019-10-03 16:54 barebones.lib
-rw-rw-rw- 1 0 460094 2019-10-03 16:54 barebones.obj
-rw-rw-rw- 1 0 6500352 2019-10-03 16:54 barebones.pdb
-rw-rw-rw- 1 0 512000 2019-10-03 16:54 vc140.pdb
D:\barebones>
用法
.load {path to barebones.dll}
type !barbones and hit enter
click the link Named CallStack to get a stacktrace