znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
阅读:2620回复:3

使用windbg进行远程调试

楼主#
更多 发布于:2009-04-12 09:28
在某些情况下我们需要进行远程调试(比如该程序运行需要时候全屏,或者程序在客户的机器上crash崩溃), 这时候可以使用WinDBG的远程调试功能。



WinDBG的远程调试由服务端和客户端组成,和visual studio类似。 被调试的机器是服务端(server), 我们做调试的机器是客户端(client)。 两台机器都需要安装WinDBG。



第一步, 建立WinDBG server 端。



使用 -server 参数可以使WinDBG 以服务器方式启动。 WinDBG可以用多种连接协议让客户端连接,比如命名管道(named pipe), 安全管道(secure pipe), TCP 协议(socket), SSL 协议, 串口/并口(COM port) 等等。



命名管道

WinDBG.exe -server npipe:pipe=PipeName[,hidden][,password=Password][,IcfEnable] [-noio] [Options]



TCP 协议

WinDBG.exe -server tcp:port=Socket[,hidden][,password=Password][,ipversion=6][,IcfEnable] [-noio] [Options]
WinDBG.exe -server tcp:port=Socket,clicon=Client[,password=Password][,ipversion=6] [-noio] [Options]



串口/并口
WinDBG.exe -server com:port=COMPort,baud=BaudRate,channel=COMChannel[,hidden],password=Password] [-noio] [Options]



安全管道

WinDBG.exe -server spipe:proto=Protocol,certuser=Cert|machuser=Cert},pipe=PipeName[,hidden],password=Password] [-noio] [Options]



SSL 协议

WinDBG.exe -server ssl:proto=Protocol,certuser=Cert|machuser=Cert},port=Socket[,hidden],password=Password] [-noio] [Options]
WinDBG.exe -server ssl:proto=Protocol,certuser=Cert|machuser=Cert},port=Socket,clicon=Client[,password=Password] [-noio] [Options]





示例:

WinDBG.exe -server npipe:pipe=DbgPipe winmine.exe (使用命名管道DbgPipe 建立调试服务,调试winmine.exe 程序)



WinDBG.exe -server tcp:port=1025 -p 122 (使用TCP协议,在端口1025建立调试服务, 调试机器上进程号为122的程序, 或者说Attach 到122进程进行调试)





第二步, 用WinDBG client 端连接服务端



使用 -remote 参数可以使WinDBG 以客户端方式启动去连接服务端, 可以指定不同的连接方式:



命名管道

WinDBG.exe -remote npipe:server=Server,pipe=PipeName[,password=Password]



TCP 协议

WinDBG.exe -remote tcp:server=Server,port=Socket[,password=Password][,ipversion=6]
WinDBG.exe -remote tcp:clicon=Server,port=Socket[,password=Password][,ipversion=6]



串口/并口

WinDBG.exe -remote com:port=COMPort,baud=BaudRate,channel=COMChannel[,password=Password]



安全管道

WinDBG.exe -remote spipe:proto=Protocol,{certuser=Cert|machuser=Cert},server=Server,pipe=PipeName[,password=Password]



SSL 协议

WinDBG.exe -remote ssl:proto=Protocol,{certuser=Cert|machuser=Cert},server=Server,port=Socket[,password=Password]
WinDBG.exe -remote ssl:proto=Protocol,{certuser=Cert|machuser=Cert},clicon=Server,port=Socket[,password=Password]





示例 (假设被调试的机器名字是dbgPC):


WinDBG.exe-remote npipe:server=dbgPC,pipe=DbgPipe (使用命名管道DbgPipe 建立连接被调试机器dbgPC)


WinDBG.exe-remote tcp:server=dbgPC,port=1025 (使用TC协议, 连接被调试机器dbgPC的端口1025)





关于Windows 远程调试更多详细的内容,请参考MSDN http://msdn.microsoft.com/en-us/library/cc266457.aspx

信息来源:

http://blog.csdn.net/WinGeek/archive/2009/02/27/3941301.aspx
http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
沙发#
发布于:2009-04-12 09:33
Debugging LSA via dbgsrv.exe

 

This is my latest best friend ( thanks to a colleague of mine on the base Dev Support team ) .. easy to use and not all the setup of a kernel or csrss debug. You don’t have the risks of debugging LSA on the same machine, nor do you need to reboot to use this method.

 

When using this method you don’t need symbols on the target either – another bonus.

 

On the target machine:

Find the PID for LSA via  tlist.exe

Then run this command:

C:\Program Files\Debugging Tools for Windows>dbgsrv.exe -t tcp:port=1234,password=spat

 

On your debugger:

Run this command to attach to LSA on the remote machine.            

            I:\debugger>windbg.exe -premote tcp:server=192.168.1.102,port=1234,password=spat -p 596  -- where 596 = PID of LSASS

 

Set your symbols on your debugger:

 

0:021> .sympath

Symbol search path is: SRV*i:\symbols_pub*http://msdl.microsoft.com/download/symbols

 

Note that anything which needs LSASS on the target machine, will be postponed while you debug LSA ( until you ‘g’  the debugger )

 

Now you are ready to go!

 

When you want to quit – make sure you use ‘qd’ to  ‘quit and detach’ so you don’t kill LSA  on the target machine.

 

Have fun debugging...
http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
板凳#
发布于:2009-04-12 09:35
双机方向调应用程序(我以前发过原创版本的)
http://blogs.msdn.com/spatdsg/archive/2005/12/27/507265.aspx



Debugging LSA from Kernel

 

A kernel debug also gives me the advantage of debugging any other process on the machine. LSA ends up processing a lot of requests from other processes via LPC calls. So,  many time, it is very nice to be able to set breaks in these other processes.

 

When doing a kernel debug with LSA I like to use something like this:

 

Get the process address for LSASS

 

0: kd> !process 0 0 lsass.exe

PROCESS 815196c0  SessionId: 0  Cid: 010c    Peb: 7ffdf000  ParentCid: 00e4

    DirBase: 042d2000  ObjectTable: 81519aa8  TableSize: 859.

    Image: LSASS.EXE

 

Switch to the process context:

 

Either

 

.process /p /r  815196c0  

 

Or

 

.process –i 815196c0  ;g;.reload /user
http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
lyndll
驱动牛犊
驱动牛犊
  • 注册日期2009-02-14
  • 最后登录2010-05-04
  • 粉丝0
  • 关注0
  • 积分36分
  • 威望151点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分1分
地板#
发布于:2009-06-01 12:06
没有 人 回 我 顶 摸索 windbg 中
游客

返回顶部