Showing posts with label remote debugging. Show all posts
Showing posts with label remote debugging. Show all posts

Thursday, February 6, 2014

How to Debug Eclipse Based Application

There are at least two way to do it:
  1. Run your eclipse application from your eclipse development environment in debug mode
  2. Attach to running eclipse application using Eclipse remote debugger 


Run your eclipse application from your eclipse development environment in debug mode


For this option you need to have all sources imported in eclipse development environment and compiled without errors. Then you can just create Eclipse Application launch configuration and run it in debug mode. If for some reason it is not possible, you still can debug your application with second option.


Attach to running eclipse application using Eclipse remote debugger


Using this approach you need to start your eclipse app with remote debugger enabled. Add in your eclipse application ini file following lines in -vmargs part
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y
So you would have something like this (note last two lines)
-startup
plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.100.v20110505
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-XX:MaxPermSize=512m
-Xms1024m
-Xmx2048m
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y
Now you can start custom eclipse. You won't see anything because it would be in debug mode and wait until remote debugger is attached. When console output shows the message
...
Listening for transport dt_socket at address: 8001
It is time to start remote debugger session in eclipse development environment.
Import source code you want to debug into development workspace. Make sure you use source code eclipse application was built from or line numbers won't match in debug. There is no need to have source compiled without errors because your application is already running.
Select Project->Debug Configurations ... form bar menu and create new Remote Java Application configuration with name you want and configure port as 8001 (see options in ini file above). Do not forget to visit Source tab and add all projects with sources you need during debug session.
Run it ignoring a warning about compilation errors and you should see eclipse splash form your eclipse application started before. After that you can use debugger as usual.

Conclusion


Both options require to have configured development environment in Eclipse, I prefer to use option (2) because it doesn't require to have everything compiled without problems in eclipse workspace. You always can start from what you really interested in and then add missing sources into development environment in the middle of debugging session.

Tuesday, April 13, 2010

Remote Debugging for Eclipse Test Plugin Running by Tycho

When I report an issue in bug tracking system about a nightly build's JUnit test error I usually get simple answer that it is supposed to be working because it is working on developers workstation. After that routine conversation starts and it turns out that tests were running from development environment under Eclipse. Here I usually have to explain again and again that's not the same running tests from development environment and in build.

The right way to make yourself sure your tests will work in most cases without errors in nightly build is to start tests the same way as nightly build does. It was not easy for JBoss Tools tests until we created experimental branch and switched to Maven Tycho project. That means it is fairly easy to run tests now. Basically you need to change current directory and execute maven install goal. If it runs in development environment and in maven your tests are good and in most cases it should be fine in nightly build. Problems begin if it runs in development environment but it doesn't in maven. In this scenario you need to debug tests running in Tycho somehow and fix it. Fortunately it can be done using Java remote debugging support.

First of all you need to be sure you have built your sources you're going to debug and there is no differences between .java and .class files. If you're going find problem from previous build just get right tagged version and build it before debugging session.

Then open pom.xml for your Eclipse Test Plug-in and add Java VM arguments like it shown below (actual port numbers, server names and other parameters may be different, it depends from your environment)




   org.sonatype.tycho
      maven-osgi-test-plugin
      ${tycho-version}
      
      -Xdebug -Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=y
      
   


This snipped configured for remote debugging in OpenJDK 6, if your is different you might need to read [1] and configure it right for your java version.

Configure java projects with sources you're going to debug in Eclipse and create Remote Java Application configuration in Eclipse Debug Configuration dialog. Fill 'host' and 'port' fields with the same values from pom.xml argLine element. Press Apply button to save your changes and start your test plug-in from terminal like

$mvn install

It will go through build process and finally you ll see something like

[INFO] Expected eclipse log file: /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work/data/.metadata/.log
[INFO] Command line:
/bin/sh -c cd /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test && /usr/lib/jvm/java-6-openjdk/jre/bin/java -Dosgi.noShutdown=false -Dosgi.os=linux -Dosgi.ws=gtk -Dosgi.arch=x86 -agentlib:jdwp=transport=dt_socket,address=8001,server=y,suspend=y -jar /home/eskimo/.m2/repository/p2/osgi/bundle/org.eclipse.equinox.launcher/1.0.201.R35x_v20090715/org.eclipse.equinox.launcher-1.0.201.R35x_v20090715.jar -data /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work/data -dev file:/home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/dev.properties -install /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work -configuration /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/work/configuration -application org.codehaus.tycho.surefire.osgibooter.uitest -testproperties /home/eskimo/Projects/jbt-modular/jst/tests/org.jboss.tools.jst.web.kb.test/target/surefire.properties
Listening for transport dt_socket at address: 8001

At this point build is waiting for you to attach remote debugger to the process because of using

suspend=y

in argLine element of your pom.xml file. So you need to return to eclipse and hit 'Debug' button in dialog opened before.

Build will continue at this point and stop on your break points so you can find out what is wrong with tests during nightly build.

[1] Java Platform Debugger Architecture - http://java.sun.com/javase/technologies/core/toolsapis/jpda/#Invocation