简体   繁体   中英

How to debug .exe started by another .exe in Delphi

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?

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.

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.

我想你可以自己启动app2.exe并将任何必要的命令行参数传递给它。

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM