在调试器下运行进程时,我想在同一个调试器中启动子进程.
目前,我用
Process.Start("sample.exe");
Run Code Online (Sandbox Code Playgroud)
我希望它是这样的:
if (Debugger.IsAttached)
// start "sample.exe" in the same debugging session
else
Process.Start("sample.exe");
Run Code Online (Sandbox Code Playgroud)
我可以将一个标志传递给指示它调用的子进程Debugger.Launch(),但这不会捕获启动错误,并且会导致调试会话中某些功能未启用(例如编辑和继续等).调试器最好直接启动进程.
无论可能实现相同结果的其他选项(即手动添加断点),是否可以以编程方式将断点添加到Visual Studio项目的源代码中?
如:
try
{
FunctionThatThrowsErrors(obj InscrutableParameters);
}
catch(Exception ex)
{
Log.LogTheError(ex);
AddBreakPointToCallingFunction();
}
Run Code Online (Sandbox Code Playgroud)
这样,当您下次运行调试时,它将自动在上次运行中导致故障的所有点上设置断点.
我不是说这是一种特别有用的调试方式.我只是想知道能力是否存在.
该方法GetActiveObject()在 .NET Framework 中可用System.Runtime.InteropServices.Marshal,但在 .NET Core 中不可用(/sf/answers/4060761701/)。
如果我想使用 .NET Core(来自 PowerShell 7),有什么办法吗?