如何以编程方式将进程附加到当前调试器? [英] How to attach a process to the current debugger programmatically?
问题描述
我在解决方案中有2个项目可以编译为 A.exe 和 B.exe .A将启动B并通过管道连接到它.我想测试它们之间的连接,因此我想同时附加两者.每次手动进行操作都很繁琐且不便,所以我尝试了
I have 2 projects in the solution that compile to A.exe and B.exe. A will start B and connect to it through a pipe. I want to test the connection between them so I'd like to attach to both at the same time. Doing that manually every time is very tedious and inconvenient so I tried this
if(IsDebuggerPresent())
DebugActiveProcess(processId);
但是,似乎 B是附加到A的调试器而不是Visual Studio的.那么如何将B自动附加到VS调试器 ?
However it seems B is attached to A's debugger instead of Visual Studio's. So how can I attach B to VS debugger automatically?
我手边有windbg来调试故障转储,所以它也可以是一个解决方案,只要它可以在没有多个用户交互的情况下完成即可.
I have windbg at hand for debugging crash dumps so it may also be a solution, as long as it can be done without multiple user interactions
推荐答案
以编程方式附加到进程 B
Attach to a process B
programatically
方法1:使用VS
Method 1: Using VS
- 打开
B.vcxproj
,而不是您的解决方案(.sln
包含项目A
和B
的项目) - 设置断点
- Open
B.vcxproj
and not your solution (.sln
containning projectsA
andB
) - Put your breakpoints
-
在项目 A 中通过
system()
(或其他变体)运行以下dos命令:
Run this dos command from your project A via
system()
(or other variant):
devenv/nosplash/run"G:\ Logiciels \ B \ B.vcxproj"/nosplash/debugexe
devenv /nosplash /run "G:\Logiciels\B\B.vcxproj" /nosplash /debugexe
devenv
是VS路径中的命令.就我而言:
devenv
is a command in your VS path. In my case it in:
C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC
运行此命令时,将打开B项目并到达断点.
When you run this command, B project is opened and break point reached.
方法2:使用Windbg
Method 2: Using Windbg
只需调用此命令:
windbg -p ProcessID
以图形方式附加到进程 B
Attach to a process B
graphically
在另一个实例中打开您的B项目,并像这样附加到它:
Open your B project in another instance, and attach to it like this :
然后选择您的B.exe:
And select your B.exe:
这篇关于如何以编程方式将进程附加到当前调试器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!