Eclipse Debugging

You can set up Eclipse to debug and step through any part of your CT application, be it the CT server, a GUI client, an agent, or a controller.

Adding a new debug configuration

Eclipse calls each set of run/debug settings a "configuration"(don't confuse this with CT configuration classes, of course).

Every configuration corresponds to one class with a main(String[] args) method that you can run.

This is example shows you how to make a debug configuration for the CT server. Note that when you are debugging CT configuration classes, they are run by the server, so this is how you would debug your confguration class.

  1. Click Run > Debug Configurations
  2. Select "Java Application."
  3. Press the New button.
  4. Give the configuration a name.
  5. Choose your Eclipse project from the list.
  6. Pick the main class by clicking Search and finding the class FrontEnd in the package edu.harvard.eecs.airg.coloredtrails.shared.app.
  7. Open the Arguments tab.
  8. Enter
    -s
    as the argument. This is the command-line argument that causes the FrontEnd class to launch the CT server.
  9. Open the Common tab.
  10. Choose Save as... > Shared file, and pick your branch's top-level directory. This way, the debug configuration will be stored in a file that you can put into Subversion; you won't have recreate it every time you work on a different machine.

Before debugging

Before debugging one of your classes, don't forget to run the appropriate Ant build tasks (in some cases, you may need to precede these with the clean task. Otherwise, some of the classes that get loaded at runtime may be outdated.

Remote debugging

You can debug remotely (with Eclipse) as such:

  1. In order to debug a specific agent, run it in debug mode with an accepting socket of a specific port. This is done as such:
    1. Locate the command for the agent running: "java -classpath dist/ct3.jar SomeAgent SomePin Argument1 Argument2"
    2. Change as such: "java -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=6079,server=y,suspend=n -classpath dist/ct3.jar SomeAgent SomePin Argument1 Argument2"
    3. In this example, we opened as socket at port 6079 which will be the debugging server.
  2. In Eclipse, start a new remote debugging session by:
    1. choosing "Run" --> "Debug configurations"...
    2. Creating a new configuration under "Remote Java Application". Give it a name (e.g. "My remote agent debug").
    3. Connection Type is: "Standard (Socket Attach)"
    4. Host is: "localhost". You can choose a different machine by a NetBIOS name or IP as well.
    5. Port is: "6079" (in our example).
    6. In the source tab, select the correct source folder. It is also recommended to make it include subfolders as well.
    7. After launching the agent, click on "Debug". You can add breakpoints as you wish.