SD Core for Windows WC2.0-0

SD BASIC - Debugging: The Full-screen Debugger

The debugger on the full screen and line by line, asking the AI, and pdump.

This page continues SD Basic - Debugging.

Full screen on a terminal, line by line everywhere else#

On a terminal that can address a cell and clear itself, the debugger takes the whole screen. Its test is that the session is a real terminal (SD can read its window size) and that the terminal definition has cup and clear: windows (the default), xterm, linux, vt100, vt102, vt220, ansi, and the terminals that behave like them. dumb and unknown have no cup and stay line by line. Then:

The full-screen display is laid out for 140 columns by 43 lines or more (a bigger window is used whole, and the extra width goes to the source). On a window smaller than that the debugger does not refuse: it says why, once, and is line by line for the session — The debugger needs a window of at least 140 columns by 43 lines for its full-screen display; this one is 100 by 30, so it is using line mode — because a small window is no reason to take away the way to debug a program. The window measured is the one on the screen, or the display term w,h gave if that is smaller. The choice is made at the first stop of a session.

If the window is made smaller while the full-screen display is up, the debugger lays itself out again within a second and shows the upper left corner of its 140 by 43 layout and nothing past the edge, and draws everything again when the window is made bigger. The command line is on row 40 of 43 (the foot is below it), so a window of 39 lines or fewer does not show where you type: the debugger then does not take keys. A warning in reverse video fills the upper left, every key is thrown away, it goes by itself when the window is big enough, and Ctrl-Q, then y leaves the debugger the way F3 (Stop) does. A window narrower than 140 but 40 lines or more high shows the left part of the lines and works as usual.

The program's own screen is kept by the terminal (that is what the alternate screen is): when you let the program run, the debugger gives the terminal back and the program's output is on its own screen, and it is on the alternate screen again at the next stop. The colors are the screen library's: if the program asked for no theme, the debugger uses the theme you chose with Ctrl-T, else the site's theme (SCREENTHEME in sd.conf, which the installer sets to paper) while it is up, and the classic one when neither names one; and whatever the program asked for otherwise. When the debugger lets the program go, the program's theme is given back, whether or not the window was resized or window n was typed on the way.

What the program's own screen becomes depends on the terminal. A terminal with an alternate screen (smcup and rmcup: xterm and its kin) keeps the program's screen aside, and gives it back untouched when the debugger lets go. A terminal without one (windows, linux, vt100, vt220, ansi) has only the one screen, so the debugger clears it when it comes up and clears it again when it lets go. A program that owns the screen library's screen (it ran SCREEN OPEN) gets everything the library knows drawn again: its forms, its cursor, its theme. What the program printed with PRINT or CRT, and what was on the screen before, is not given back — a terminal cannot be asked what it shows, and the line-by-line debugger, which does not clear anything, keeps that text. For the same reason F4 (or v) on such a terminal shows an owned screen again until a key is pressed, and says "There is no second screen to show on this terminal" for any other program.

To keep the line-by-line debugger on a terminal that would otherwise get the full screen, put the word LINE.MODE on a line of the VOC record $debug.options of the account (the same record that holds WINDOW n). Nothing about this gives the debugger more reach than before: the AI line, for instance, which the full-screen debugger offers when the AI is on for the account, is the same gated line it already was.

In a session that is not a terminal, on dumb, unknown or null, and in a window smaller than 140 by 43, the debugger is line by line. Every command works, as the transcripts on this page show, and there is a real gain: because it is line-oriented it can be driven from a script. A whole debugging session can be fed down a pipe.

@tty reads empty in a piped session, and the debugger works there anyway.

(The full-screen display does not use AccuTerm, which SD does not support.)

Asking the AI#

In the full-screen display, when the AI is on for your account (see Asking the AI), the command AI — or AI and a question, such as ai why is y empty — asks it about the stop. The AI is told the program and the line, the call stack and about fifty lines of the source round the stop. As everywhere, Enter shows your request and the size of all that will be sent first (SD's own instruction is sent but not shown), with Send and Cancel (the default); the answer is words in a box, and the debugger's screen is drawn again after it. Nothing in your program or the debugger is changed, and a command in the answer is ignored. Line mode and a phantom do not have it.

Who has it#

Read out of an account's own VOC:

VOC entry record
debug a V verb, IN, internal command 29 run a program in debug mode
debugging a K keyword, 53 the compiler keyword
pdebug a V verb, CA $PDEBUG the phantom debugger

Every account has debug and pdebug. debugging is a keyword rather than a verb, and every account has it.

A process dump from inside the program: pdump#

pdump

The statement writes a process dump of the session it runs in and the program carries on at the next line; nothing is stopped. The dump is the same file the pdump command writes for a session number (see SD TCL - Processes and Phantoms, which says where it goes): the program's variables, each string with its length, the call stack, open files, and the environment, with the value of any name that looks like a secret (a key, a token, a password) left out.

Use it to take a picture of a program's state at one point without stopping it. The dump holds the program's data, so remove it when you have read it.

What is not here#

trace does not exist. In an ordinary account it is "Unrecognized statement".

The programmatic debug statements are restricted. debug.on, debug.off, debug.set, breakpoint and watch are internal-only, and all five are "Unrecognized statement" in an ordinary account. They are what the debugger itself is built from. debug — the plain statement — is not restricted, and it is the one you want.

debug.info() is internal-only for the same reason.

No conditional breakpoints, no data breakpoints beyond the single watch, and no remote attach. The debugger runs in the session that runs the program.

See also#

SD Basic - System and Environment · SD Basic - Program Structure · SD Basic - Program Control · SD Basic - Locks and Transactions.