How to Debug Your Own IntelliJ IDEA Instance

Some time ago, I have adopted CodeNarc IDEA plugin which helps to detect(and soon it will help fixing) Groovy code style violations.

I have a version of a plugin in the beta channel which works great but sometimes the plugin code throws a StackOverflowError that I am not able to emulate in the sandbox but that only occurs on my own IntelliJ IDEA instance. It has been also reported by my coworkers who help me with testing so I wanted to fix the issue before releasing the plugin to the general public. I need to be able to debug my own IntelliJ IDEA instance to get more details about the issue.

The first step is to launch the instance in debug mode. To do so, you need to edit the idea.vmoptions file using Edit Custom VM Options… action:

Add the following option to the end of the file:

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

Save the file and restart Intellij IDEA.

If you fail to update the file for some reason and your IntelliJ instance won't start anymore then you can find the location of idea.vmoptions in the IntelliJ configuration directory and edit it with another text editor.

You cannot debug the instance from within the instance itself. One of the options is to launch the sandboxed IDE from the plugin's project. If you are using Gradle to develop the plugin then you can run the following task:

./gradlew runIde

Other options are either downloading a different edition of the IDE (e.g. the community edition instead of ultimate) or launching the IDE with different configuration directories.

Once your regular IntelliJ IDEA instance has started then launch the other one, open the plugin's code and run Attach to Process action:

You will see idea process ready to be attached:

You will see that the debugger is attached to your IDE now and you can start debugging your plugin.

Once you are finished, do not forget to remove the debugging configuration from the idea.vmoptions file.

Many thanks to Yann Cébron, the developer advocate of IntelliJ Platform, for helping me setting up the process.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store