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
Advertisement
Answer
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.