![]() | ![]() | |||||||||||||||
|
Debugging Tutorial - Using the SparForte DebuggerThis is a detailed look at SparForte's debugger (the breakout mode), and related features. Syntax CheckingA script is run by using the script name as an argument to SparForte. SparForte performs a syntax check before running the script. You can run just the syntax check with the --check option. bash$ spar --check demo_script.sp The Trace CommandThe execution of a script can be traced with the SparForte trace command. Suppose you want to trace the execution of the following script: #!/usr/local/bin/spar
Example: Using the trace command in a script
Once tracing is turned on by trace true (or with spar --trace), each line will be shown before it's executed, with the line number in square brackets to the right of the line. Some statements will also show additional information. For example, an assignment statement will show the value being assigned. The trace information is written to standard error, so the output from the command may appear in the wrong order because some versions of UNIX buffer their output. bash$ spar trace_demo.sp
Example: Example Output from the trace command
Breakout Mode: The DebuggerIf a script is started with the --break (or -b) option, a SIGINT (e.g. a control-c) will pause the script and give the user a command prompt. This breakout prompt is identical to a normal interactive session except for the command to quit. return will retry the last statement. step will run the next statement and then stop. logout will terminate the script. The Breakout PromptWithout a --break, a SIGINT will terminate the script, just as if a return command was executed. bash$ cat breakdemo.sp
Example: Control-C Used on a Script without --break
Since --break was not used, the script terminated. bash$ cat breakdemo.sp
Example: Breakout Prompt Appears when Control-C is used on a Script with --break
Since --break was used, SparForte breaks out of the script and provides an interactive prompt. => ? i
Example: How to Change a Variable and Resume a Script from the Breakout Prompt
Breakout PragmasTo monitor variables, use pragma inspect. Each time the script stops because of a Control-C, the value of all the variables marked for inspection will be shown. You can also use pragma inspect at the breakout prompt to start inspecting a variable, or pragma uninspect to stop inspecting a variable. To break at a specific point in a script without using Control-C, use pragma inspection_point. When this pragma is reached, SparForte will stop as if you typed a Control-C. That is, it marks a "break point" in your program. All variables selected with pragma inspect will be displayed. Use pragma inspection_peek to see the inspected variables without stopping the program. Study Questions
|
![]() Command Prompt Tutorial 1: SparForte as a Calculator Command Prompt Tutorial 2: Basic Shell Commands Command Prompt Tutorial 3: Working with Databases Script Tutorial 1: Basic Commands Scripts Script Tutorial 2: Intermediate Program Scripts Template Tutorial 1: Basic Templates Template Tutorial 2: Intermediate Templates GCC Tutorial: Compiling SparForte Scripts Debugging Tutorial - Using the SparForte Debugger |
![]() |
![]() |