简体   繁体   中英

IntelliJ IDEA debugger follow child process

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

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.

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.

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