17 Debugging with MagicBox
MagicBot edited this page 3 years ago

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.

  1. Debug the full game ./mbstart.sh -debug
  2. 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.

debugide

Select Run->Edit Configurations

editmenu

Create a new Remote JVM configuration

jvmremote

Give the configuration a name. Set the IP address to the public IP of the MagicBox host machine and the port to 5000.

configremote

Use this new configuration to connect your IDE to MagicBox. The game will begin to bootstrap.

selectDebug

Breakpoint was hit!

breakpoint

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.

profiler

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.