debug.sh add DebugAdd

Sometimes it is desirable while debugging one script for it to enable
debugging of a child.
We can do that with

$DEBUG_DO DebugAdd tag

to add tag to DEBUG_SH but only when we are already debugging.
This commit is contained in:
Simon J. Gerraty 2024-10-22 11:07:37 -07:00
parent f6197f2bc0
commit 02653835cd
2 changed files with 30 additions and 2 deletions

View file

@ -9,6 +9,7 @@
# DebugOn [-eo] "tag" ...
# DebugOff [-eo] [rc="rc"] "tag" ...
# Debugging
# DebugAdd "tag"
# DebugEcho ...
# DebugLog ...
# DebugShell "tag" ...
@ -39,6 +40,9 @@
# default of 0. Thus if DebugOff is the last operation in a
# function, "rc" will be the return code of that function.
#
# DebugAdd allows adding a "tag" to "DEBUG_SH" to influence
# later events, possibly in a child process.
#
# DebugEcho is just shorthand for:
#.nf
# $DEBUG_DO echo "$@"
@ -74,7 +78,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
# $Id: debug.sh,v 1.40 2024/09/09 20:06:00 sjg Exp $
# $Id: debug.sh,v 1.41 2024/10/22 17:57:22 sjg Exp $
#
# @(#) Copyright (c) 1994-2024 Simon J. Gerraty
#
@ -167,6 +171,21 @@ _debugOff() {
DEBUG_X=
}
##
# DebugAdd tag
#
# Add tag to DEBUG_SH
#
DebugAdd() {
DEBUG_SH=${DEBUG_SH:+$DEBUG_SH,}$1
export DEBUG_SH
}
##
# DebugEcho message
#
# Output message if we are debugging
#
DebugEcho() {
$DEBUG_DO echo "$@"
}

View file

@ -12,7 +12,7 @@
.\" Please send copies of changes and bug-fixes to:
.\" sjg@crufty.net
.\"
.Dd January 31, 2024
.Dd October 22, 2024
.Dt DEBUG.SH 8
.Os
.Sh NAME
@ -30,6 +30,8 @@
.It
.Ic Debugging
.It
.Ic DebugAdd Ar tag
.It
.Ic DebugEcho Op Ar message
.It
.Ic DebugLog Op Ar message
@ -110,6 +112,13 @@ It is useful for bounding complex debug actions, rather than
using lots of
.Ic $DEBUG_DO
lines.
.It Ic DebugAdd Ar tag
Add
.Ar tag
to
.Va DEBUG_SH
to influence later output,
possibly in a child process.
.It Ic DebugEcho
is just shorthand for:
.Bd -literal -offset indent