Difference between revisions of "Robocode/Eclipse/Debugging Robot"
m (Image) |
m (grammar correction) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
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. | 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 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. | 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. | ||
Line 68: | Line 71: | ||
When our robot scans another robot, [[Robocode/Eclipse|Eclipse]] will jump right to the breakpoint set in <code>onScannedRobot()</code>. | When our robot scans another robot, [[Robocode/Eclipse|Eclipse]] will jump right to the breakpoint set in <code>onScannedRobot()</code>. | ||
− | == See | + | == References == |
− | * [[Robocode/ | + | * [http://www.eclipse.org/ Eclipse.org - Eclipse home page] |
− | * [[Robocode/Eclipse/Create_a_Project|Creating a | + | * [http://www.eclipse.org/downloads/ Eclipse Downloads] |
− | * [[Robocode/ | + | * [http://download.eclipse.org/eclipse/downloads/ Eclipse project downloads - latest releases] |
− | * [[Robocode/ | + | |
+ | == See also == | ||
+ | |||
+ | === 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]] | * [[Robocode/Running from Eclipse|Running your robot from Eclipse]] | ||
+ | === Robot API === | ||
+ | * [http://robocode.sourceforge.net/docs/robocode/ Robot API] | ||
+ | |||
+ | === 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]] | ||
+ | |||
+ | === 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] | ||
+ | |||
+ | === 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]] | [[Category:Debugging]] |
Latest revision as of 02:08, 17 June 2009
This page describes how to use the Eclipse IDE for debugging your robots.
Contents
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.
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 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.
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.
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()
.
References
See also
Using Eclipse IDE
- Using Eclipse as IDE
- Creating a project for your robots
- Add robot project from an IDE into Robocode
- Creating a robot in Eclipse
- Running your robot from Eclipse
Robot API
Tutorials
- System Requirements for Robocode
- How to download and install Robocode
- The anatomy of a robot
- Getting started with Robocode
- My First Robot Tutorial
- Robocode Game Physics
- Scoring in Robocode
- Using the robot console
- Downloading other robots
- Learning from other robots
- Package your robot
- Frequently Asked Questions (FAQ)
- Articles about Robocode
- Starting Robocode from the command line
- Graphical debugging