在WinAPI中调试主机时,从C ++程序启动外部应用程序并附加到visual 2008调试器 [英] Launch external application from C++ program and attach it to visual 2008 debugger while debugging host in WinAPI
问题描述
基本上我有主机和子程序。我没有孩子的来源,所以我不能改变任何东西。我想从调试器启动主机,这在某些时候应该启动Child程序。我想要自动附加到调试会话的孩子(所以任何在Child进程下加载的DLL源中设置的断点将会被击中)。
Basically I have Host and Child program. I do not have sources for Child so I can't change anything in it. I want to launch Host from debugger, which at some point should launch Child program. I want to attach Child automatically for debugging session as well (so any breakpoints set in DLL sources loaded under Child process will hit).
如何在Visual Studio 2008中执行此操作C ++与标准WinAPI?
How to do this in Visual Studio 2008 C++ with standard WinAPI?
我尝试过:
SHELLEXECUTEINFO sei = {0};
sei.cbSize = sizeof (SHELLEXECUTEINFO);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.lpVerb = "open";
sei.lpFile = "Child.exe";
sei.lpParameters = "/Param";
sei.nShow = SW_SHOWNORMAL;
if (ShellExecuteEx (&sei))
{
WaitForSingleObject (sei.hProcess, INFINITE);
}
但是这不附加Child.exe的调试器
But this does not attach debugger for Child.exe
推荐答案
您可以使用 gflags.exe
程序。这将可以从VS命令提示符访问。您可以指定在子程序启动时启动的调试器。通过在 gflags.exe
中指定 vsjitdebugger.exe
作为调试器,您可以选择当前正在运行的VS实例作为调试器
You can use the gflags.exe
program. This will be accessable from a VS command prompt. You can specify a debugger to launch when the child program gets launched. By specifying vsjitdebugger.exe
as the debugger in gflags.exe
you can select the currently running VS instance to be the debugger.
编辑:
Visual Studio中的Gflags不是默认的。您将需要 Windows调试工具。但是,如果您想要做的是为特定映像设置默认调试器,您可以使用 IFEO ,这些都是 gflags.exe
无论如何:)
Sorry about the confusion. Gflags is NOT default in Visual Studio. You will need the Debugging Tools for Windows. However if all you want to do is set the default debugger for a specific image you can use IFEO which is all gflags.exe
does anyways :)
这篇关于在WinAPI中调试主机时,从C ++程序启动外部应用程序并附加到visual 2008调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!