[英]How do I attach a process to the debugger in Visual Studio?
I know I can start a process in code with Process.Start()
.我知道我可以使用
Process.Start()
在代码中启动一个进程。 Is it also possible to attach the debugger to that process?是否也可以将调试器附加到该进程?
Not from code per se , but just a way to do it?不是来自代码本身,而是一种实现方式?
You can attach to a running process using Tools | Attach to Process
您可以使用
Tools | Attach to Process
附加到正在运行的进程 Tools | Attach to Process
. Tools | Attach to Process
。 If it's a Web Application, you can attach to it by attaching to aspnet_wp.exe
or w3wp.exe
. 如果它是Web应用程序,您可以通过附加到
aspnet_wp.exe
或w3wp.exe
来附加它。
To answer your question on how to attach to a process programmatically: 要回答有关如何以编程方式附加到流程的问题:
Here are other Stack Overflow questions that deal with that: 以下是其他Stack Overflow问题:
In visual studio click Tools | 在visual studio中单击工具| Attach to process.
附加到流程。 Then select appropriate service.
然后选择适当的服务。
You can do this in pretty much any debugger worth its salt. 你可以在几乎任何有价值的调试器中执行此操作。
Visual Studio has one that should fit your needs. Visual Studio有一个适合您的需求。
If you need a little more advanced control, try OllyDbg , which is a disassembler, so you can actually manipulate your program at the assembly level. 如果您需要更高级的控制,请尝试OllyDbg ,它是一个反汇编程序,因此您可以在程序集级别实际操作程序。 This will give you complete control, but it might be information overload as well.
这将为您提供完全控制,但也可能是信息过载。
In Visual Studio 2015, click 'Debug > Attach to process' in the menu. 在Visual Studio 2015中,单击菜单中的“调试>附加到进程”。 Alternatively, there is a shortcut key Ctrl+Alt+P.
或者,有一个快捷键Ctrl + Alt + P.
You can do this in your code. 您可以在代码中执行此操作。
public static void Attach(DTE2 dte)
{
var processes = dte.Debugger.LocalProcesses;
foreach (var proc in processes.Cast<EnvDTE.Process>().Where(proc => proc.Name.IndexOf("YourProcess.exe") != -1))
proc.Attach();
}
internal static DTE2 GetCurrent()
{
var dte2 = (DTE2)Marshal.GetActiveObject("VisualStudio.DTE.12.0"); // For VisualStudio 2013
return dte2;
}
Usage: 用法:
Attach(GetCurrent());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.