Windbg远程调试

双机远程调试方法总结

Posted by QH on January 9, 2019

Windbg远程调试

Windbg的远程调试在本地调试受限,或者无法直接本地调试定位问题时,非常的有用的一个功能。Windbg也提供了 管道(pipe),TCP,com 几种远程调试连接方式。以下以TCP的方式总结一下Windbg远程调试的功能。

  1. 被调试机器使用cdb(或kd、Windbg)的 -server 命令行参数,开启一个调试会话

    cdb -server tcp:port=5005 notepad.exe cdb server result

  2. 调试机器使用cdb(或kd、Windbg)的 -remote 参数进行远程调试的连接

    cdb -remote tcp:server=192.168.254.129,port=5005 cdb remote result

  3. 当调试连接成功后,在被调试机器上会出现如下提示 cdb remote result1

使用以上方法调试时,pdb文件必须在 被调试机器 上! 如果不想把pdb文件拷贝到被调试的机器上,可以在被调试机器上使用 dbgsvr.exe 进行远程调试

  1. 运行 dbgsvr.exe 监听调试连接

    dbgsvr.exe -t tcp:port=5005

  2. 调试机器中使用Windbg的 “Connect to Remote Stub…“ 进行连接 windbg remote connect

  3. 连接成功后就可以使用Windbg的 F6 查看到被调试机器上的进程 windbg remote attach

  4. 在调试机器中使用windbg的 -premote 命令进行远程调试

    windbg.exe -premote tcp:server=192.168.254.129,port=5005

  5. 启动被调试机器上的指定进程

    windbg.exe -premote tcp:server=192.168.254.129,port=5005 exe_path 注意:exe_path中有空格,需要使用”exe_path”模式

  6. 附加到被调试机器上的指定进程

    windbg.exe -premote tcp:server=192.168.254.129,port=5005 -p pid

参考

Remote Debugging connecting to a Remote Stub using the Microsoft Debugging Tools for Windows