Debugging with MagicBox
Debugging has come a long way from the days of using gdb on a coredump.
All of the debugging facilities of a modern IDE are available to the MagicBox developer. Yes you can set breakpoints and watches; but also have automatic hot module reloading as you edit the source of a running game with players on it. No bug will escape you!
Kill the running server.
./mbkill.sh
Build the branch you wish to debug.
./mbbuild.sh <branch-name>
We wish for to debug the WorldServer in this demonstration; choose option 1.
- Debug the full game
./mbstart.sh -debug
- Debug only the LoginServer
./mblogin_start.sh -debug
The game is now listening on port 5000 for the IDE. We will open up WorldServer.java and click to the left of a line to set a breakpoint.
Select Run->Edit Configurations
Create a new Remote JVM configuration
Give the configuration a name. Set the IP address to the public IP of the MagicBox host machine and the port to 5000.
Use this new configuration to connect your IDE to MagicBox. The game will begin to bootstrap.
Breakpoint was hit!
Profiling your code
Another important aspect of development is to profile your code. Not just to see how slow your new routine runs; the profiler will catch every error masked due to empty try-catch blocks. It will tell you when you are generating 2000 objects a second. Your new branch might appear to be running fine but have hidden issues.
There are many choices available free and otherwise for Java profilers. We have tried most. The Profiler of choice for the Magicbane team is YourKit. The game has built-in support for profiling as it does debugging.
./mbstart.sh -profile
The YourKit agent is not being shipped with the image. Choice of profiler is the perrogative of your team.