PBDB - Primitive Bash Debugger

pdbd.bsh

A debugger written in bash with no extra requirements to debug bash scripts.

The debugger can be started via calling set_trace

To get “dbstop if error” behavior (start the debugger automatically on an error)

Debugger stop if error

set -Ee # Preferably set -Eeu
trap set_trace ERR
_debug_prompt

The prompt the debugger shows, default $

_debug_L_file_color
_debug_L_function_color
_debug_L_line
_debug_L_current_line

The default colors used when printing out lines of code (l command)

JUST_DEBUG_READ_METHOD

The method for reading from the keyboard. Three methods are supported.

  • read - Using “readline” via read -e, which includes its own separate history file. This is ok for single line entry only. Works using pure bash

  • manual - A manual implementation of read that supports multiple lines (via ending a line with \ and pressing enter), has a separate history (JUST_DEBUG_HISTORY), and is unfinished. Also works using pure bash

  • {python} - Given the name of a python executable (either full path or just python3), runs debug_readline.py in python to get user input. This is the best option, but requires a python install with prompt_toolkit and pygments installed. The color scheme for python can be changed by setting the _debug_read_color_scheme environment variable (default vim).

JUST_DEBUG_HISTORY

The history file used for storing previous values. The read JUST_DEBUG_READ_METHOD appends a 2 to the filename, and the python method appends a 3

JUST_DEBUG_HISTORY_LENGTH

The manual JUST_DEBUG_READ_METHOD will limit itself to JUST_DEBUG_HISTORY_LENGTH unique entries, default 1000.

set_trace
Arguments:

[$1] - Number of stacks to skip

Output:

By default outputs to stderr(2), but if you redirect stderr, you can redirect set_trace to another stream (3 for example) using 2>&3.

Starts the debugger