Difference between revisions of "Robocode/Eclipse/Debugging Robot"

From Robowiki
Jump to navigation Jump to search
m (Backup changes)
m (grammar correction)
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{stub}}
 
 
 
This page describes how to use the [[Robocode/Eclipse|Eclipse IDE]] for debugging your robots.
 
This page describes how to use the [[Robocode/Eclipse|Eclipse IDE]] for debugging your robots.
  
 
== Debugging your robot with Eclipse ==
 
== 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 [[Robocode/Eclipse|Eclipse]], you must be able to run your robot from [[Robocode/Eclipse|Eclipse]]. So if you have not already set up your project accordingly to [[Robocode/Running from Eclipse|Running your robot from Eclipse]], you must do this before you are able to proceed with debugging.
 +
 +
'''Notice:''' You must also add -<code>Ddebug=true</code> to the VM argument too. This will slow your Robocode down a little, but if this flag is missing, the Robocode will freeze when it reaches the breakpoint.
  
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 see if an event handler is ever called.
 
  
Fortunately, this is possible to do with Robocode!
+
In the following example we set a breakpoint in the first line of the <code>run()</code> 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.
  
Before you can start debugging with Eclipse, you must be able to run your robot from Eclipse. So if you have not already setup your project accordingly to Running your robot from Eclipse, you must do this before you are able to proceed with debugging.
+
Right-click in the border area of the source editor till a popup menu shows up, where you can select '''Toggle Breakpoint'''.
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".
+
[[Image:Eclipse-ToggleBreakpoint.png|Shows how to toggle a breakpoint in Eclipse by first right-clicking in the border area of the source editor, and then select "Toggle Breakpoint" in the popup menu that occurs]]
  
 
  
 
When the breakpoint has been set, a blue bullet will be shown beside the line to break at.
 
When the breakpoint has been set, a blue bullet will be shown beside the line to break at.
  
+
[[Image:Eclipse-Breakpoint.png|Shows a breakpoint that has been set in Eclipse as a blue bullet in the border of the source editor]]
 +
 
  
 
Now, let's try to start debugging our robot.
 
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.
+
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.
  
+
[[Image:Eclipse-StartDebugging.png|Shows how to start debugging of the MyRobots project in Eclipse]]
  
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.
+
When Robocode has started up, you start your robot by selecting '''New''' from the '''Battle''' 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.
 +
 
 +
[[Image:PauseDebugButton.png|Shows the Pause/Debug button of the Battle View of Robocode, which has been pressed down]]
  
 
  
 
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.
 
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 this example, [[Robocode/Eclipse|Eclipse]] should already have switched into the '''Debug Perspective'''. If this is the first time you debug with [[Robocode/Eclipse|Eclipse]], it might ask you if you want to switch into the Debug Perspective. Here I normally answer '''Yes'''.
 +
 
 +
In the Debug Perspective, the execution of your robot should already have stopped at our breakpoint.
 +
 
 +
[[Image:Eclipse-BreakpointHit.png|Shows the current stack trace in the Debug Perspective in Eclipse when the execution has stopped at the breakpoint that has been set]]
  
In the Debug Perspective, the excution of your robot should already have stopped at our breakpoint.
 
  
+
If [[Robocode/Eclipse|Eclipse]] has not stopped at our breakpoint, you should resume the battle by clicking on the '''Pause/Debug''' button until [[Robocode/Eclipse|Eclipse]] stops at our breakpoint, and then click on the '''Pause/Debug''' button again to pause the battle.
  
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'''.
  
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.
+
[[Image:Eclipse-DebugStepOverButton.png|Shows the "step over" button of the toolbar for the debugger in Eclipse]]
  
 
  
 
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.
 
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.
+
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.
 +
 
 +
[[Image:NextTurnButton.png|Shows the Next Turn button of the Battle View of Robocode, which has been pressed down]]
 +
 
 +
 
 +
In our case, we should carefully click on the '''Next Turn''' button approximately 4 times (might be more or less times) until [[Robocode/Eclipse|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.
 +
 
 +
[[Image:Eclipse-SingleStep.png|Shows a single step from a break point that has been in Eclipse]]
 +
 
 +
 
 +
Now we have made a single step with our robot. So now we could set a breakpoint on the <code>fire(1)</code> line in the <code>onScannedRobot()</code> 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, [[Robocode/Eclipse|Eclipse]] will jump right to the breakpoint set in <code>onScannedRobot()</code>.
 +
 
 +
== References ==
 +
* [http://www.eclipse.org/ Eclipse.org - Eclipse home page]
 +
* [http://www.eclipse.org/downloads/ Eclipse Downloads]
 +
* [http://download.eclipse.org/eclipse/downloads/ Eclipse project downloads - latest releases]
  
+
== See also ==
  
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.
+
=== Using Eclipse IDE ===
 +
* [[Robocode/Eclipse|Using Eclipse as IDE]]
 +
* [[Robocode/Eclipse/Create_a_Project|Creating a project for your robots]]
 +
* [[Robocode/Add_a_Robot_Project|Add robot project from an IDE into Robocode]]
 +
* [[Robocode/Eclipse/Create_a_Robot|Creating a robot in Eclipse]]
 +
* [[Robocode/Running from Eclipse|Running your robot from Eclipse]]
  
+
=== Robot API ===
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.
+
* [http://robocode.sourceforge.net/docs/robocode/ Robot API]
  
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.
+
=== Tutorials ===
 +
* [[Robocode/System Requirements|System Requirements for Robocode]]
 +
* [[Robocode/Download|How to download and install Robocode]]
 +
* [[Robocode/Robot Anatomy|The anatomy of a robot]]
 +
* [[Robocode/Getting Started|Getting started with Robocode]]
 +
* [[Robocode/My First Robot|My First Robot Tutorial]]
 +
* [[Robocode/Game Physics|Robocode Game Physics]]
 +
* [[Robocode/Scoring|Scoring in Robocode]]
 +
* [[Robocode/Robot Console|Using the robot console]]
 +
* [[Robocode/Downloading_Robots|Downloading other robots]]
 +
* [[Robocode/Learning from Robots|Learning from other robots]]
 +
* [[Robocode/Package Robot|Package your robot]]
 +
* [[Robocode/FAQ|Frequently Asked Questions (FAQ)]]
 +
* [[Robocode/Articles|Articles about Robocode]]
 +
* [[Robocode/Console Usage|Starting Robocode from the command line]]
 +
* [[Robocode/Graphical_Debugging|Graphical debugging]]
  
When our robot scans another robot, Eclipse will jump right to the breakpoint set in onScannedRobot().
+
=== News and Releases ===
 +
* [http://sourceforge.net/export/rss2_project.php?group_id=37202 RSS Feeds for the Robocode project]
 +
* [http://sourceforge.net/project/showfiles.php?group_id=37202&package_id=29609 Robocode file releases]
  
== See Also ==
+
=== Home pages ===
 +
* [http://robocode.sourceforge.net/ Classic homepage]
 +
* [http://sourceforge.net/projects/robocode Robocode project at SourceForge]
 +
* [http://robocoderepository.com/ Robocode Repository]
 +
* [[wikipedia:Robocode|Wikipediaentry for Robocode]]
  
 
[[Category:Robocode Documentation]]
 
[[Category:Robocode Documentation]]
 +
[[Category:Tutorials]]
 
[[Category:Eclipse IDE]]
 
[[Category:Eclipse IDE]]
 +
[[Category:Debugging]]

Latest revision as of 02:08, 17 June 2009

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.

Notice: You must also add -Ddebug=true to the VM argument too. This will slow your Robocode down a little, but if this flag is missing, the Robocode will freeze when it reaches the breakpoint.


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.

Shows how to toggle a breakpoint in Eclipse by first right-clicking in the border area of the source editor, and then select "Toggle Breakpoint" in the popup menu that occurs


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

Shows a breakpoint that has been set in Eclipse as a blue bullet in the border of the source editor


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.

Shows how to start debugging of the MyRobots project in Eclipse


When Robocode has started up, you start your robot by selecting New from the Battle 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.

Shows the Pause/Debug button of the Battle View of Robocode, which has been pressed down


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 execution of your robot should already have stopped at our breakpoint.

Shows the current stack trace in the Debug Perspective in Eclipse when the execution has stopped at the breakpoint that has been set


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.

Shows the "step over" button of the toolbar for the debugger in Eclipse


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.

Shows the Next Turn button of the Battle View of Robocode, which has been pressed down


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.

Shows a single step from a break point that has been in Eclipse


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().

References

See also

Using Eclipse IDE

Robot API

Tutorials

News and Releases

Home pages