除了在Visual Studio 2017中启动之外,如何将调试器附加到其他进程? [英] How do I attach a debugger to other process than I start in Visual Studio 2017?

查看:107
本文介绍了除了在Visual Studio 2017中启动之外,如何将调试器附加到其他进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须处理的架构非常复杂:一个本机C ++ Windows服务创建一个进程外COM对象(本机C ++,上下文为CLSCTX_LOCAL_SERVER的CoCreateInstance),该对象动态加载(AfxLoadLibrary)我的C#DLL.

An architecture which I have to deal with is quite complicated: a native C++ Windows Service creates an out-of-process COM object (native C++, CoCreateInstance with context = CLSCTX_LOCAL_SERVER) which dynamically loads (AfxLoadLibrary) my C# DLL.

当我单击调试"->开始调试"时,我想调试DLL.

我知道当我使用Debug-> Attach to process附加到COM对象进程时,可以调试它,并且如果我可以在DLL代码中使用 System.Diagnostics.Debugger.Launch()需要调试启动,但是所有这些选项都不会自动运行.

I know that I can debug it when I attach to COM object process using Debug -> Attach to process and I can use System.Diagnostics.Debugger.Launch() in my DLL code if I need to debug startup but none of this options work automatically.

我也尝试了这种技术: https://docs.microsoft.com/zh-cn/previous-versions/visualstudio/visual-studio-2010/a329t4ed(v = vs.100),但COM进程的运行方式为一个SYSTEM用户,因此我无法选择将我的C#项目与现有的Visual Studio解决方案一起用作调试器,只能在仅加载EXE的情况下启动新实例.

I also tried this technique: https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/a329t4ed(v=vs.100) but the COM process runs as a SYSTEM user so that I cannot select my existing Visual Studio Solution with my C# project to use as a debugger, I can only start a new instance with only EXE loaded.

我也尝试过启动外部程序",但是我需要启动的是不是我要调试的进程的服务,因为我的DLL在另一个进程(COM-one)中运行.因此,一旦启动服务,调试就会停止(因为我使用脚本运行它,也许是个问题).

I tried "Start external program" too but what I need to start is a service which is not the process I want to debug, because my DLL runs in another process (the COM-one). So, debugging stops as soon as service is started (because I run it with a script, maybe this is a problem).

推荐答案

我看不到使用标准Visual Studio功能完全自动化它的选项.因此,我建议您编写一个简单的 Visual Studio扩展.只需使用模板,然后在菜单或某些自定义窗口中添加一个按钮,单击该按钮即可:

I don't see an option to automate it entirely with standard Visual Studio features. So I would propose you to write a simple Visual Studio extension. Just use the template and add a button to the menu or to some custom window, which on click will:

  • 遍历正在运行的进程,并等待直到在命令行上出现带有COM类guid的dllhost.exe实例
  • 找到流程后,请使用
  • iterate through the running processes and wait until an instance of the dllhost.exe with your COM class guid on the command line, appears
  • when you find the process, attach to it using the Process2 interface (code in VB is available)

我不确定是否有帮助,但是您可以检查一下我的简单 VS扩展.我前段时间写到配置符号在调试器中.

I'm not sure if it will help, but you may check my simple VS extension. I wrote it some time ago to configure symbols in the debugger.

这篇关于除了在Visual Studio 2017中启动之外,如何将调试器附加到其他进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆