Debugging Scripts

Terminal Debugger

C:\> pnuts -d { script }
C:\> pnuts -d:file scriptFile
C:\> pnuts -d:file -e expression

-d option of pnuts command executes Pnuts interpreter in debug mode. The debug commands are described below.

The debugger only works with the pure interpreter (not the compiler).

e.g.
C:\> pnuts -d
Copyright (c) 1997-1999 Sun Microsystems, Inc. All rights reserved.
Pnuts interpreter Version 1.0beta4, 1.2.2 (Sun Microsystems Inc.)
> 1
# Stopped at ?:1
 >>> 1
debug>

If -d:file is specified, debug commands are read from the file.

e.g.
C:\> pnuts -d:trace.dbg -e 'getProperty("java.version")'
reading /tmp/trace.dbg
# Stopped at ?:1
 >>> getProperty("java.version")
debug> trace
on
debug> cont
lib/property.pnut:1 >>> import("java.lang.System")
lib/property.pnut:2 >>> import("java.util.Properties")
lib/property.pnut:3 >>> import("java.io.FileInputStream")
lib/property.pnut:5 >>> function setProperty(name, val) {
 prop = System::getProperties()
 if (val == null) {
  prop.remove(name)
 } else {
  prop.put(name, val)
 }
}
lib/property.pnut:14 >>> function getProperty(name) {
 System::getProperty(name)
}
lib/property.pnut:18 >>> function loadProperty(fileOrStream) {
 loadProperty(fileOrStream, Properties())
}
lib/property.pnut:22 >>> function loadProperty(fileOrStream, prop) {
 prop
 if (fileOrStream instanceof String) {
  prop.load(FileInputStream(fileOrStream))
 } else {
  prop.load(fileOrStream)
 }
 prop
}
lib/property.pnut:15 >>> System::getProperty(name)
trace.dbg
trace
cont

Debug Commands

stop at {FILE:}LINENO
Stop execution at the LINENO
stop in FUNC{:NARGS}
Stop execution when FUNC is called. When NARGS is specified, stop when FUNC with NARGS is called.
clear
Clear all breakpoints
cont
Continue execution
trace
Toggle trace mode. The default is false.
step {NUM}
Single step NUM lines. The default number is 1.
step up
Step out of the current function
next {NUM}
Step NUM line (step OVER calls). The default number is 1.
help
Print a summary of commands
?
Same as help.
<Any other word>
Evaluate the word as a Pnuts script

Visual Debugger

When -d option is given to the pnuts command, a class name for the debugger can be specified to the 'pnuts.debugger' property. If the property value is "pnuts.tools.VisualDebugger", the graphical debugger is used instead of the terminal-style debugger.

java -Dpnuts.debugger=pnuts.tools.VisualDebugger pnuts.tools.Main -d { target.pnut }

The light blue line is the current position. Orange color shows a breakpoint is set at the line. To set (or reset) a breakpoint, right click on the line.


Back