Template level External Article ID
KBA00039873
Issue
Important information regarding debugging perl reports, including pertinent files/directories and a cheat-sheet.
Resolution
Common important files:
$INDBDIR/perllib/sdsdate.pl – contains date converting subroutines
$INDBDIR /perllib/sds.pl – automagically includes sdsdate.pl for you
$INDBDIR /perllib/ctree.pl – automagically includes sds.pl
$FORCEDIR/perllib/xml_rpt.pl - includes data needed to render PDF (.xx) reports
$FORCEDIR/util/reportCron.pl - used for PDF crons and sending emails (includes emailAttach.pl)
$INDBDIR /perllib/wherefile.pl – defines a subroutine to help you find a file your script requires
Important directories:
$INDBDIR/perllib/ - Many important perl files are located here, such as sds.pl and ctree.pl
$FORCEDIR/perllib – These directories contain many Perl files that are needed for all reports. For example, ucr_subs.pl and ucr_cfg.pl reside here, which are necessary for running all UCR reports.
$FORCEDIR/xsl – Contains style sheets which can be applied with AddStylesheet() within a report
$FORCEDIR/uxsl - Contains custom style sheets and agency logos
$FORCEDIR/rpt – Standard reports are contained here
$FORCEDIR/urpt – Standard custom reports are contained here
$FORCEDIR/prt – Screen (print) reports are contained here
$FORCEDIR/uprt – Custom screen (print) reports are contained here
$FORCEDIR/util - Contains necessary files such as reportCron.pl and emailAttach.pl
Perl Debugger Cheat-Sheet: | |
Commands used to navigate through the program: n – next statement (skips subroutines) s – single step (steps into subroutines) c [line | sub] – continue (optionally stop at the specified line or subroutine, otherwise continues until a breakpoint is reached or the program terminates) r – return from a subroutine T – stack trace; shows which subroutine(s) you are in | |
Commands used to control execution of the program: b [line|sub] – place a breakpoint at line or subroutine B [line|*] – delete a specific / all breakpoints w $variable – break when a variable’s value changes W [line|*] – delete a specific / all watchpoints R – restart the script. Doesn’t always work the way you want it to when debugging a CtPerl report, so beware. | |
Commands used to examine data: p $variable – print content of a variable x $variable – examine a variable. Works best when used on a scalar. To examine a hash or array, put a backslash "\" in front of the sigil (@, $, % & are sigils) to turn it into a reference. | |
Commands used to list / search source lines: l [sub] – shows the next 10 lines of code; given a subroutine name, it will show the first 10 lines of that subroutine l line – shows a single line of code v [line] – shows a few lines surrounding the specified line number S [pattern] – lists names of all subroutines matching pattern (hint: S ^main:: shows names of all user-defined subroutines) /pattern/ - search forward for a line of code containing pattern ?pattern? - search backward for a line of code containing pattern | |
What to do if you’re stuck: h – general help h [cmd] – more help on a specific command See man perldebug or perldoc perldebug for more help | |
Debugging rpt/ reports on UNIX:
| |
Debugging prt/ reports on UNIX:
| |
Debugging rpt/ reports on Windows: (Note: whenever you see ctperl in a command, translate that to perl -MCtperl for use on Windows)
| |
Q: The first thing I see is 'Debugged program terminated. Use q to quit or R to restart.' Where did I go wrong? A: Your program must compile before it can be run; most compilation errors arise from invalid syntax. Perl will tell you more about what is wrong if you ask it nicely. Here’s how: ctperl -c -Mdiagnostics report.x1 | |
Q: When I print out a value (p $variable), nothing appears on the screen! A: After perl executes the require 'sds.pl'; line of code, all output is redirected to the location referred to by the environment variable $SPOOLER. To get it back, run this command in the debugger: select STDOUT | |
Q: How do I get a report into debug mode in Force? A: Shell out of Spillman, change to the directory containing the report, and execute the following command: report dscript rpreport (Do not give the file’s extension!) Choose the Debug option, and change the –S in the shebang line into a –d, save and exit. When you run the report, it will put you in the debugger. | |