无法远程连接到 windbg 服务器,可能是因为 dll 版本不匹配?

Unable to connect remotely to a windbg server, possibly because of a dll version mismatch?

我的目标是从另一个 C++ 程序控制 运行 WinDbg 实例。我看到 API DebugConnectWide 可以让你远程连接到调试客户端,所以我尝试使用它并确保通过输入此命令从 运行 windbg 客户端启动服务器:

.server npipe:pipe=testname.

我能够打开 windbg 的第二个实例并通过在命令行参数中输入以下内容远程连接到第一个实例:

-remote npipe:Pipe=sup,Server=DESKTOP-JT5S9BR.

然而,当我尝试从我的 C++ 控制台应用程序以编程方式连接时,我从 HRESULT 收到以下错误:The server is currently disabled.

#include <dbgeng.h>
#include <iostream>

int main()
{
    HRESULT hr;
    IDebugClient7* debugger = nullptr;

    hr = DebugConnectWide(L"npipe:Pipe=testname,Server=DESKTOP-NAME", IID_PPV_ARGS(&debugger));

    std::getchar();
}

我在文档中读到,如果 windbg 的所有实例想要远程连接,它们都必须具有相同的版本,这一点很重要。所以我的问题可能与此有关。我看到我的电脑上有很多版本的 dbgeng.dlldbgeng.lib,那么如何确保我的 C++ 应用程序是 运行 相同版本的 dbgeng?

是的,您需要 dbgeng.dll 服务器的版本 运行

通常在服务器和客户端安装相同的 windbg 版本,运行客户端 windbg 安装文件夹中的应用程序将工作

或者将dbgeng复制到exe所在的本地文件夹

复制 c:\prograxxxxxx\dbgeng.dll 。到可执行文件的目录

这里有一个示例流程

执行 DebugConnect() 的代码(DebugConnectWide 的 Ascii 版本)

#include <stdio.h>
#include <dbgeng.h>
#pragma comment(lib, "dbgeng.lib")
int main(int argc, char *argv[])
{
    if (argc == 2)
    {
        IDebugClient *dbgclient = NULL;
        HRESULT hr = E_FAIL;
        hr = DebugConnect(argv[1], __uuidof(IDebugClient), (VOID **)&dbgclient);
        if (hr == S_OK && dbgclient != NULL)
        {
            ULONG mask = 0xdeadbeef;
            hr = dbgclient->GetOutputMask(&mask);
            if (hr == S_OK && mask != 0xdeadbeef)
            {
                printf("Outputmask = %x\n", mask);
            }
            printf("hresult = %x\tmask = %x\n", hr, mask);
        }
        printf("hresult = %x\tdbgclient = %p\n", hr, dbgclient);
    }
    else
    {
        printf("usage %s remote connection string", argv[0]);
    }
    return 0;
}

使用 vs2017 community dev cmdprompt using

在 x64 中编译为 win10 1803 中的 x64
cl /Zi /W4 /analyze /Od /EHsc /nologo concliw.cpp /link /release

在其命令行参数中包含 cdb 的进程列表 运行 在本地计算机中

server debuggee client and wmic  commandlines 

C:\>whoami
kr\xxxxx

C:\>wmic process get CommandLine /format:list | grep -i cdb
CommandLine=cdb  -server npipe:pipe=windpipe cdb
CommandLine=cdb
CommandLine=cdb  -remote npipe:server=KR,pipe=windpipe
CommandLine=grep  -i cdb

复制了正确的dbgeng.dll并将其重命名为test_dbgeng.dll

copy "C:\Program Files (x86)\Windows Kits\Debuggers\x64\dbgeng.dll" .
ren dbgeng.dll test_dbgeng.dll

执行二进制文件重命名 dbgeng.dll 并重新执行二进制文件

concliw.exe
usage concliw.exe remote connection string
concliw.exe "npipe:server=KR,pipe=windpipe"
hresult = 8007053d      dbgclient = 0000000000000000

ren test_dbgeng.dll dbgeng.dll

concliw.exe "npipe:server=KR,pipe=windpipe"
Outputmask = 3f7
hresult = 0     mask = 3f7
hresult = 0     dbgclient = 000001FA6B9D2590