WARNING: ENDB is not maintained anymore! Please help if you're interested in this tool.
Nim comes with a platform independent debugger - the Embedded Nim Debugger (ENDB). The debugger is embedded into your executable if it has been compiled with the --debugger:on
command line option. This also defines the conditional symbol ENDB
for you.
Note: You must not compile your program with the --app:gui
command line option because then there would be no console available for the debugger.
If you start your program the debugger will immediately show a prompt on the console. You can now enter a command. The next sections deal with the possible commands. As usual in Nim in all commands underscores and case do not matter. Optional components of a command are listed in brackets [...]
here.
h
, help
q
, quit
step_into
is assumed.s
, step_into
n
, step_over
f
, skip_current
c
, continue
i
, ignore
b
, setbreak
[fromline [toline]] [file].nim
is appended for your convenience. If no line numbers are given, the current execution point's line is used. If both fromline
and toline
are given the breakpoint contains a line number range. Some examples if it is still unclear:b 12 15 thallo
creates a breakpoint that will be triggered if the instruction pointer reaches one of the lines 12-15 in the file thallo.nim
.b 12 thallo
creates a breakpoint that will be triggered if the instruction pointer reaches the line 12 in the file thallo.nim
.b 12
creates a breakpoint that will be triggered if the instruction pointer reaches the line 12 in the current file.b
creates a breakpoint that will be triggered if the instruction pointer reaches the current line in the current file again.breakpoints
disable
<identifier>enable
command.enable
<identifier>Often it happens when debugging that you keep retyping the breakpoints again and again because they are lost when you restart your program. This is not necessary: A special pragma has been defined for this:
breakpoint
pragmaThe breakpoint
pragma is syntactically a statement. It can be used to mark the following line as a breakpoint:
write("1") {.breakpoint: "before_write_2".} write("2")
The name of the breakpoint here is before_write_2
. Of course the breakpoint's name is optional - the compiler will generate one for you if you leave it out.
Code for the breakpoint
pragma is only generated if the debugger is turned on, so you don't need to remove it from your source code after debugging.
watchpoint
pragmaThe watchpoint
pragma is syntactically a statement. It can be used to mark a location as a watchpoint:
var a: array [0..20, int] {.watchpoint: a[3].} for i in 0 .. 20: a[i] = i
ENDB then writes a stack trace whenever the content of the location a[3]
changes. The current implementation only tracks a hash value of the location's contents and so locations that are not word sized may encounter false negatives in very rare cases.
Code for the watchpoint
pragma is only generated if the debugger is turned on, so you don't need to remove it from your source code after debugging.
Due to the primitive implementation watchpoints are even slower than breakpoints: After every executed Nim code line it is checked whether the location changed.
e
, eval
<exp>nim1.globalVar
localVar
. If you want to inspect variables that are not in the current stack frame, use the up
or down
command.Unfortunately, only inspecting variables is possible at the moment. Maybe a future version will implement a full-blown Nim expression evaluator, but this is not easy to do and would bloat the debugger's code.
Since displaying the whole data structures is often not needed and painfully slow, the debugger uses a maximal display depth concept for displaying.
You can alter the maximal display depth with the maxdisplay
command.
maxdisplay
<natural>o
, out
<filename> <exp>w
, where
u
, up
d
, down
stackframe
[file]stdout
or appends it to the file, depending on whether a file is given.callstack
l
, locals
g
, globals
© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/endb.html