2015-07-21 50 views
1

我很难用WinDbg来控制我的应用程序,我已经发布了我的问题here,因为我无法找到一种方法关于如何实现这一点。 现在我正在处理断点被击中后的方法,我想分支出我的应用程序执行并提示来自运行调试器的用户的输入。WinDbg可以连接到正在远程运行的调试对象的stdin

DWORD dwRand = 0; 
volatile bool bDebug = false; 
if (!bDebug) 
{ 
    dwRand = Rand(minValue, maxValue); 
} 
else 
{ 
    cout << "\n Enter dwRand: "; 
    cin >> dwRand; 
} 
return dwRand; 

所以我的想法是设置bDebug,并得到用户的输入,所以我可以继续其他线程的执行,并等待用户输入。 我发现这些链接123正在解释这种技术,但我想附加一个已经远程运行的进程。我尝试使用WinDbg命令选项,但这并不是我的解决方案。有人可以建议我如何做到这一点。

+1

我想知道你为这个问题的自动化付出了多少努力。你多久调试一次?为什么要为此编写某种用户界面?这对我来说似乎是一个XY问题。你正在努力实现某些目标,并且似乎是这样做的错误方式。但是我们不能说,因为我们不了解整个用例。例如。为什么不从磁盘读取伪随机值呢?或者用硬编码的随机数发生器替换随机数发生器对象? –

+0

@Thomas,现在我排除了这种情况,并决定禁用导致超时的设备。你可以参考讨论[这里](http://stackoverflow.com/questions/31378816/data-input-to-debugger-before-hitting-the-breakpoint/31386173?noredirect=1#comment51034791_31386173)。 – Panch

回答

4

上面的伪代码并不表达您的意图。

我不知道为什么你需要一个内核调试连接到远程调试可执行(参考链接中查询)

,如果你要调试的可执行文件运行在远程机器可以连接使用远程调试连接会话。

下面列举的样品设置调试CALC.EXE在远程机器使用远程调试会话

主机-----------------物理机器XP SP3 32位运行
目标---------------虚拟机XP SP3 32位
网络--------------环回适配器

C:\>net view | grep -i xp & echo kd wont connect target not booted with /DEBUG 
\\XPSP3VM 
kd wont connect target not booted with /DEBUG 

C:\>kd -k com:pipe,port=\\.\pipe\debugPipe,resets=0,reconnect 
Opened \\.\pipe\debugPipe 
Waiting to reconnect... 
^B <---------force exit 
"lets run windbg -server npipe:pipe=\\.\pipe\debugPipe -v calc.exe 
in the target machine and connect to it with cdb -server:xxxx from host 

C:\>cdb -remote npipe:server=xpsp3vm,pipe=\\.\pipe\debugPipe 
Connected to server with 'npipe:server=xpsp3vm,pipe=\\.\pipe\debugPipe' 

CommandLine: calc.exe (mapped shared folder in host) 
Symbol search path is: srv*z:\*http://msdl.microsoft.com/download/symbols 

7c90120e cc    int  3 
\Admin (npipe \\.\pipe\debugPipe) connected at Wed Jul 22 11:49:41 2015 
0:000> .echo "yay we are remote debucking now" 
yay we are remote debucking now 
0:000> lm m calc* 
start end  module name 
01000000 0101f000 calc  (deferred) 
.clients 
\Admin (npipe \\.\pipe\debugPipe), last active Wed Jul 22 11:54:19 2015 
HostMachine\HostUser, last active Wed Jul 22 11:44:06 2015 
0:000> kb 
ChildEBP RetAddr Args to Child 
0007fb1c 7c9402ed 7ffde000 7ffdf000 00000000 ntdll!DbgBreakPoint 
0007fc94 7c91fad7 0007fd30 7c900000 0007fce0 ntdll!LdrpInitializeProcess+0x1014 
0007fd1c 7c90e457 0007fd30 7c900000 00000000 ntdll!_LdrpInitialize+0x183 
00000000 00000000 00000000 00000000 00000000 ntdll!KiUserApcDispatcher+0x7 
0:000> .echo "only echo is echoed all other aw are dumped here" 
only echo is echoed all other aw are dumped here 

添加一个屏幕截图,以防被乱写的声音enter image description here

+0

感谢您的详细信息,我使用tcp进行通讯而不是管道。我在远程计算机上运行'dbgsrv.exe -t tcp:port = 1234',并从我的桌面上使用'windbg -premote tcp:port = 1234,host = -pn myapp.exe'。 – Panch

+0

以及任何岩石你的船应该罚款,如果你认为你从上面发布的答案找到答案,以便它漂浮在上面,一些徒步旅行者可以看到来自信标的梁 – blabb