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 AST interpreter (not the compiler).

e.g.
C:\> pnuts -d
Copyright (c) 1997-1999 Sun Microsystems, Inc. All rights reserved.
Pnuts interpreter Version 1.0, 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
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:1 >>> import("java.lang.System")
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:2 >>> import("java.util.Properties")
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:3 >>> import("java.io.InputStream")
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:4 >>> import("java.io.File")
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:5 >>> import("java.io.FileInputStream")
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:7 >>> function setProperty(name, val) {
 prop = System::getProperties()
 if (val == null) {
  prop.remove(name)
 } else {
  prop.put(name, val)
 }
}
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:16 >>> function getProperty(name) {
 System::getProperty(name)
}
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:20 >>> function loadProperties(resourceOrStream) {
 loadProperties(resourceOrStream, Properties())
}
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:24 >>> function loadProperties(input, prop) {
 if (input instanceof String) {
  url = getResource(input)
  if (url == null) {
   return null
  }
  prop.load(openURL(url))
 } else if (input instanceof File) {
  prop.load(fd = open(input))
  fd.close()
 } else if (input instanceof InputStream) {
  prop.load(input)
 } else {
  throw(IllegalArgumentException(string(input)))
 }
 prop
}
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:16 >>> {
 System::getProperty(name)
}
jar:file:/usr/local/pnuts/modules/pnuts-modules.jar!/pnuts/util/property.pnut:17 >>> System::getProperty(name)
# Returns "1.4.2"
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.
trace function {FUNCTION}
Toggle trace function 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 -vd option is given to the pnuts command, the graphical debugger is used instead of the terminal-style debugger. See also "Properties" on pnuts.debugger property.

C:\> pnuts -vd { script }

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.