Robocode/Eclipse/Debugging Robot

From Robowiki
< Robocode‎ | Eclipse
Revision as of 23:07, 28 November 2007 by FlemmingLarsen (talk | contribs) (Backup changes)
Jump to navigation Jump to search
This article is a stub. You can help RoboWiki by expanding it.

This page describes how to use the Eclipse IDE for debugging your robots.

Debugging your robot with Eclipse

In some situations, you might want to debug your robot by setting break points (e.g. conditional breakpoints), step through lines of codes and see how the values of your variables changes as the code goes along, or just check if an event handler is ever being called.

Fortunately, this is possible to do with Robocode!

Before you can start debugging with Eclipse, you must be able to run your robot from Eclipse. So if you have not already set up your project accordingly to Running your robot from Eclipse, you must do this before you are able to proceed with debugging.

In the following example we set a breakpoint in the first line of the run() method of a robot. In this case, the robot is a simple Robot where each command takes exactly 1 turn to execute before it processes the next.

Right-click in the border area of the source editor till a popup menu shows up, where you can select Toggle Breakpoint.


When the breakpoint has been set, a blue bullet will be shown beside the line to break at.


Now, let's try to start debugging our robot.

You start debugging by clicking on the debug button that looks like a bug and selecting your launch configuration. Alternatively, you could just click on the debug button, which will start debugging from the last launch configuration that was started.


When Robocode has started up, you start your robot by selecting Battle->New from the menu or by using the hotkey Ctrl+N. Next, you select your robot and perhaps some opponent robots, and press "Start Battle".

Notice: As soon as the battle begins, it is important that you must press the "Pause/Debug" button at the bottom of the battle window.


This will pause Robocode making debugging possible. If you do not pause Robocode, the game will run, and the robot that you debug will be seen as inactive when it hits a breakpoint, as it has not been active for some time. Besides, when Robocode is paused the internal time is also put on hold, which can be critical when debugging.

In this example, Eclipse should already have switched into the Debug Perspective. If this is the first time you debug with Eclipse, it might ask you if you want to switch into the Debug Perspective. Here I normally answer "Yes".

In the Debug Perspective, the excution of your robot should already have stopped at our breakpoint.


If Eclipse has not stopped at our breakpoint, you should resume the battle by clicking on the "Pause/Debug" button until Eclipse stops at our breakpoint, and then click on the "Pause/Debug" button again to pause the battle.

Now we want to step to the next line after our breakpoint. Therefore we press the "Step Over" button or alternatively press the F5 key.


Nothing happens? Well, Robocode is still paused, so we will not be able to proceed the debugging before we continue the battle. However, we do not want Robocode to rush with continuing the battle, playing lot's of turns before we get the chance of getting to the next line after our breakpoint. We just want to execute one turn at a time when debugging.

Here the "Next Turn" button becomes handy, which is located next to the "Pause/Debug" button at the bottom of the battle window. This button can only be activated when the game is paused, and is used for letting Robocode execute to the next turn of the battle, i.e. it performs a single turn.


In our case, we should carefully click on the "Next Turn" button approximately 4 times (might be more or less times) until Eclipse steps to the next line of code after our breakpoint. The reason why you have to hit the button several times is because it takes several turns until the robot has finished turning.


Now we have made a single step with our robot. So now we could set a breakpoint on the "fire(1)" line in the onScannedRobot() method, which is the event handler that is called whenever our robot scans another robot.

Here we don't want to make one turn at the time. Instead, we just resume the game by clicking on the "Pause/Resume" button.

When our robot scans another robot, Eclipse will jump right to the breakpoint set in onScannedRobot().

See Also