views:

228

answers:

5

I want to debug App2.exe, which is started by App1.exe. If App2.exe were a dll I could specify a host application, but this doesn't seem to work with an .exe.

I now use 'attach to process', but this is useless if App2.exe crashes before I do that.

Is there a way to do this with having to attach to the process manually?

+2  A: 

No, but there might be a way to get it to attach properly. Find something that you know will happen in App2 soon before the crash point, and have it pop up a modal dialog box at that point. Then it won't continue until you dismiss it, giving you time to attach the debugger.

Mason Wheeler
or you can wait till DebugHook becomes something different than 0. `while DebugHook = 0 do Sleep(1000);`
idursun
+1  A: 

I guess you could launch app2.exe yourself and pass any necessary command line parameters to it.

Aldo
That would work, but I forgot to mention that the two processes communicate with each other, so I need both of them. Thanks anyway.
Giel
A: 

If both apps are yours and you have the code than I propose the following:

  1. Make a debug mode for both apps. Use external inc file for instance
  2. Start two IDEs and load each app in its own IDE. Build in debug mode
  3. If done right you can now debug the internal communication between apps

I have a project where a server spawns multiple exe worker processes that host each its own dll module. I have a debug mode in which I can specify which dll will be loaded and I can have both processes running and communicationt in between from IDEs. It is the best way I have found so far.

Runner
What are the two IDEs for? I'm pretty sure it was Delphi 4 that introduced the ability to debug multiple processes simultaneously.
Rob Kennedy
Ah, didn't know that :) Thanks for the info. I feel stupid now :)
Runner
+3  A: 

Set the "debug spawned processes" debugging option. It is off by default. When App1 starts the new process, the debugger will pause. If the debugger isn't already attached to the new process automatically, attach to it, and then resume running it.

Rob Kennedy
This is a cool option; it is a bit hidden though: it is under Tools -> Options -> Debugger Options -> CodeGear Debuggers -> General -> Debug Spawned Processes.
Jeroen Pluimers
But I assume you cannot debug source this way? Probably only the CPU view?
Runner
If there's source available, you can debug it. It might help if you have both projects loaded in the IDE.
Rob Kennedy
+1  A: 

If you're using windows, there is a built in support for it. basically, you can tell the windows loader to launch some other process whenever a specific process is launched. for example, you can tell windows to always launch winword.exe whenever you click on notepad.exe

you can use this ability in order to automatically launch a debugger whenever you start your process (this is why this feature was originally introduced, however you are not restricted to launch only debuggers :))

You can read exactly how to do it here. You can also download the debugging tools for windows package and use GFlags to do it for you.

Moshe Levi