Ankur Sharma co-leads Eclipse Plug-in Development Environment (PDE) project. He holds a Masters degree in Computer Applications and has been working in Software Industry since 2002. Ankur is a DZone MVB and is not an employee of DZone and has posted 11 posts at DZone. View Full User Profile

Remote Debugging Eclipse

05.31.2010
| 13354 views |
  • submit to reddit
Recently I ran into a nasty bug that will get reproduced only in a hosted instance ofEclipse. The best way to catch this type of bug is through remote debugging.
Remote Debugging
Remote debugging is a Java feature. Since Eclipse is a Java application (running inside a JVM) we can remote debug it given the JVM used to launch Eclipse supports it. Most JVMs supports remote debugging from pre-1.4 era.
WebSphere give a nice definition: "Debugging a program running on one system while controlling the program from another system is known as remote debugging. The debugger supports remote debugging by allowing you to run the debugger user interface on one system, while running the debug engine on another system. The system running the debugger user interface is known as the local system. The system where the debug engine runs is known as the remote system."
How to remote debug Eclipse?
  1. Start the Eclipse as server
  2. We need to pass -Xdebug VM argument to Eclipse to tell JVM to get launched with debugger. We need to pass certain more options to tell it to start in server mode and listen to a particular socket.

    This command shall be entered on the command prompt
    eclipse.exe -vmargs -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044 
     

    See the complete details for the options and their meaning at Connection and Invocation Details page.

  3. Creating a Remote Java Application debug config
  4. Start another instance of Eclipse where we will debug the other instance launched in Step 1. Also check out the code that you want to debug. Once this is done, open debug launch configurations and choose 'Remote Java Application' and create a new debug config.

    The project text box shall contain the project which has the code that needs to be debugged. The connection type shall be standard socket attach while port will contain the socket address we gave in Step 1. The host is localhost we both instances are running of same machine.
  5. Connecting and attaching to the remote server
  6. Launch the debug config like any other debug config. This will launch the debug mode. Place the breakpoints and do the relevant actions in the server Eclipse instance to hit the.
  7. Debugging
  8. The debug process is the same as normal debug. No differences. However, if you change the code then the updated code is not what that would run. Remember the server Eclipse is still running in separate JVM. So what you are getting is only a reflection of the code execution. The debug session will end when the serve Eclipse instance is closed or the client Eclipse is disconnected using the disconnect button in the debug view.
Host Eclipse: The default eclipse instance is referred to as Host Eclipse. When self-hosting, a new Eclipse is launched from it, it is referred to as Guest Eclipse or Nested Eclipse Instance.

From http://blog.ankursharma.org/2010/05/remote-debugging-eclipse.html

Published at DZone with permission of Ankur Sharma, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Florin Botis replied on Tue, 2010/06/01 - 6:12am

And the bug is?

Nirmal Mukundan replied on Fri, 2011/01/28 - 5:59am

Hi, I am using calypso dataserver for development. Its been deployed in unix enviornment. I am working in eclipse from a windows machine remotely. Could you please help me in setting up the debugger for eclipse to connect to the dataserver. Also could you please tell which file I have to modify to enter the debug properties (-Xdebug). Waiting for your earliest reply. Thanks Nirmal

Javin Paul replied on Fri, 2011/04/08 - 9:17am

Nice article. Just to add You need to ensure that you run the same code base in eclipse which is deployed in your remote machine so that what you debug and see in eclipse is true and real. you also need to ensure that your code is compile with debug option "-g" so that eclipse can easily gather debug info. I have also written a blog post about eclipse remote debugging  which talks about setting up eclipse for remote debugging and issues faced during remote debugging, you may find it interesting.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.