Debugger
Introduction to the debugger
The JARU IDE debugger runs your program in its own VM and stops it at the lines you mark, so you can step through it line by line and look at the values of your variables. Its buttons are in the Build tab of the ribbon, in the Debug group.
Breakpoints
A breakpoint stops the program when it reaches that line.
- To set one, click in the left margin of the code editor, next to the line number, or put the cursor on the line and press
F9. - A red mark appears in the margin.
- To remove it, click the mark again or press
F9on the line.
Starting a debug session
- Set at least one breakpoint.
- Press Debug, or
F5in the code editor. The IDE compiles the project and starts it in its own VM. - When it reaches the breakpoint, the program stops, the editor highlights the line and the Output says at which line and file it is paused. The IDE comes to the front.
While it is paused, the game window does not respond, and Windows may say "Not responding". That is normal: it is waiting for you to let it go on.
Controls
| Action | Button | Shortcut | What it does |
|---|---|---|---|
| Debug | Debug | F5 | Compiles and starts the program for debugging |
| Continue | Continue | F5 | Runs on to the next breakpoint |
| Step Over | Step Over | F10 | Runs the highlighted line without going into the functions it calls |
| Step Into | Step Into | Runs the highlighted line going into the function it calls | |
| Stop | Stop | Closes the program and its console |
The shortcuts work with the cursor in the code editor. Stop is in the Compiler group of the same tab.
Watch window
Watch, in the Debug group, opens a window that shows the variables you ask for:
- Type the name of the variable in the box at the top. It comes with "New Variable..." written in it: delete that first.
- Press
Enter. - While the program is paused, the window shows its value (Value), its type (Type) and its context (Context), for example
local.
Long lists are shown in pages: Items/page says how many items fit in each one.
You can also add it from the code editor: put the cursor on the name of the variable, or select it, right-click and choose Add Watch. If Watch is closed, it opens it; if the program is paused, it shows its value straight away, and if the variable was already in the list, it tells you so. The right click does not move the cursor: it takes the word where the cursor is, not the one under the mouse.
Practical example
func factorial(n)
if (n <= 1) then // Put the breakpoint here
return 1
end
return n * factorial(n - 1)
end
var result = factorial(5)
print(result)
- Set a breakpoint on the
ifline, with a click in the margin or withF9. - Press
F5to debug. The program stops at theif. - In Watch, add
n: it is 5. - Press
F5to go on. The program stops at theifagain with the next call, and Watch shows the newn.
What it does not have yet
The debugger has no conditional breakpoints, and a breakpoint cannot be disabled without removing it. It does not show the call stack or a panel with the local variables, and it has no console to evaluate expressions. There is no button to step out of the current function (Step Out) either.
Tips
Step Over (F10) does not go into functions: it is the quickest way when you already know a function does what it should.
Step-by-step debugging is slower than normal execution. Put breakpoints where you need them instead of stepping through all the code line by line.