Remote Debugging a Process using IntelliJ

Vinoth Chandar
Sep 16, 2018 · 2 min read

[Reposted from my blogger]

This is a brief post on something that is rather very important. Your company probably handed you a macbook or laptop and have a Linux VM hosted somewhere, that you will do all your development on. And now the circus begins.

You like to stay on your laptop since you get all the nice IDEs and Code diffing tools and what not. But, your code only runs on the VM, rightfully so in the highly SOA (Service Oriented Architecture, basically meaning everything is REST and has nagios alerts).

So, here’s how to get the best of both worlds.

Pre-requisite: Use a tool like unison or Bittorrent sync or roll your own scripts to rsync your local repo on laptop with a directory on your VM.

End state would be

  • You git clone or svn checkout on VM
  • Syncing gets it down to your laptop
  • From there on you make code changes on your IDE and syncing reflects them on VM

Most of all, it means that intellij can look for the source code for the classes you debug, on your repo on your laptop. Now, onto the actual setting up of debugging itself.

  1. In IntelliJ, go to run > edit configurations. Click on the + , pick remote. IntelliJ automatically tells you what to use to launch your remote JVM.
Image for post
Image for post

A useful note on the options

  • suspend=y/n , controls whether the JVM should wait for the debugger to attach before starting up. So, if you have trouble starting up your application, use suspend=y to troubleshoot

From here on,

1. Setup whatever breakpoints you want to in your project.

2. Launch your application on your VM, with the suggested params

3. (Optional) Setup port forwarding if needed

Sometimes, your VM may not allow incoming connections at a random port that Intellij picks out for you. you can either change the Intellij port or

A) Enter localhost as the hostname in your debug configuration

B) ssh -L <debugport>:<vm.hostname>:<debugport> <vm.hostname>

eg: ssh -L 5005:vm.mycompany.com:5000 vm.mycompany.com

4. In IntelliJ, hit “Debug” on your debug configuration ..

Happy debugging!

bytearray

Occasional quips on technology/programming/work/life

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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