PiotrK
PiotrK

Reputation: 4453

Launch external application from C++ program and attach it to visual 2008 debugger while debugging host in WinAPI

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).

How to do this in Visual Studio 2008 C++ with standard WinAPI?

I tried this:

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);
}

But this does not attach debugger for Child.exe

Upvotes: 1

Views: 1613

Answers (1)

linuxuser27
linuxuser27

Reputation: 7353

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.

Edit:

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 :)

Upvotes: 3

Related Questions