3

We have some Java code that starts a new process using the following code: Runtime.getRuntime().exec(command); I'd like to be able to tell the debugger that it should follow the child process like you can do with GDB as documented here by issuing the set follow-fork-mode child command.

Is there something equivalent in the IntelliJ IDEA Java debugger? If so how do I configure it?

Thanks

Andrew Jessop
  • 135
  • 2
  • 7
  • Hit up @wajiii on Twitter, he's likely to know that. – JohnMetta Sep 13 '12 at 06:04
  • Is child process a JVM? Note that you will have to adjust the VM options for this process so that it starts in debug mode. No, IDEA doesn't support it in automatic way, but you could use the second Remote debug configuration to connect and debug the child process started with appropriate debug options. – CrazyCoder Sep 13 '12 at 07:40
  • @CrazyCoder: Yes the child process is a JVM. Thanks for the reply. I was looking for an automatic way without having to use the remote debugging but it doesn't look like I have much choice. – Andrew Jessop Sep 16 '12 at 23:28

2 Answers2

4

Java doesn't provide an automated way to debug processes and their child processes. One needs to run the child process with the JVM options to enable debugging. IDEA Remote Debug configuration will suggest the proper options to use. Once the process is started with the appropriate options you can connect to it from IDEA with the Remote Debug configuration.

Sample options:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

You may want to start with suspend=y so that the execution is suspended until you connect with the debugger.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • Yes, you can connect in both ways: wait for application and application waits for debugger. This way you can achieve all possible scenarios. You can follow on to this thread: https://stackoverflow.com/questions/21114066/attach-intellij-idea-debugger-to-a-running-java-process – Vinit Siriah May 28 '21 at 04:40
0

We now have this Intellij plugin that uses a java agent to automatically start all child processes in debug mode.

It listens for any debugee processes on 7857, then attaching debugger to those processes.

  1. Install AttachMe
  2. To enable automatic mode, run this first, source ~/.attachme/conf.sh
  3. Afterwards start AttachMe listener
  4. Test it with maybe a Play application in prod mode (assuming play plugin is enabled), do sbt start. Play in prod mode forks another JVM process. Debug points should now hit.
Gagandeep Kalra
  • 1,034
  • 14
  • 13