简体   繁体   English

调试当前项目启动的过程

[英]Debug a process started by the current project

My Visual studio solution contains two C++ console projects, 'A' and 'B', where 'A' programmatically starts B (using CreateProcess()). 我的Visual Studio解决方案包含两个C ++控制台项目“ A”和“ B”,其中“ A”以编程方式开始B(使用CreateProcess())。

If I start stepping through 'A' after the point where 'B' has been created, how can I have breakpoints in the 'B' project be detected and stopped at? 如果在创建“ B”点之后开始逐步浏览“ A”,那么如何在“ B”项目中检测断点并停止在该点?

Currently I just stick a "DebugBreak()" at specific points in 'B', but this is rather annoying as it usually takes a while for that window to pop up that allows you to debug the app with a VS instance, and often it won't show up the current instance, so I have to start another that takes even longer. 目前,我只是在“ B”中的特定位置贴上“ DebugBreak()”,但这很烦人,因为通常会花一些时间弹出该窗口,使您可以使用VS实例调试应用程序,并且经常不会显示当前实例,因此我必须启动另一个需要花费更长时间的实例。

I can't use attach to process, as 'B' starts up, does its thing and then closes too quick. 我无法使用附加到进程,因为'B'启动,执行其操作然后关闭太快。

Is there any of marking a project to be automatically attached, enabling me for example to have a breakpoint right at the beginning of main (similar to DebugBreak at the beginning of main)? 是否有任何标记要自动附加的项目的示例,例如使我可以在main的开头有一个断点(类似于在main的开头有DebugBreak)?

I found this note on MSDN: 我在MSDN上发现了此注释:

The debugger does not automatically attach to a child process that is started by a debugged process, even if the child project is in the same solution. 即使子项目在同一解决方案中,调试器也不会自动附加到由已调试过程启动的子进程。 To debug a child process: 要调试子进程:

  • Attach to the child process after it has been started. 启动后附加到子进程。
  • -or- -要么-
  • Configure Windows to automatically start the child process in a new instance of the debugger. 配置Windows以在调试器的新实例中自动启动子进程。

The latter of which can apparently be accomplished by some registry meddling: Automatically start a process in the debugger 后者显然可以通过某种注册表干预来实现: 在调试器中自动启动进程

The Visual Studio team has released a Visual Studio extension that allows automatically attaching child processes to the current debugger: Introducing the Child Process Debugging Power Tool . Visual Studio团队发布了一个Visual Studio扩展,该扩展允许自动将子进程附加到当前的调试器: 子进程调试Power Tool简介

It is available on the Gallery for Visual Studio 2013 and above. 在Visual Studio 2013及更高版本的库中可用。

So you can start your Project B from Project A with Process.Start and it will automatically attach the debugger to this second process. 因此,您可以使用Process.Start从项目A启动项目B,它将自动将调试器附加到第二个过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM