Jim Cromie | 21 Aug 2012 16:08
Picon

[PATCH 0/1] debug: debug functions

following patch is an RFC prototype for dbg_echo() and dbg_echo_v()
functions which could be useful in the install shell scripts.

Theres other ways to do this kind of thing, some with more
flexibility, but possibly with less easy usability.

Basic idea (atm) is turn on debugging in copyfiles.sh with:

      export DBG_copyfiles=1	# something other than ""
      export DBG_ALL=1		# something other than ""

Then dbg_echo()s added in copyfiles.sh will be enabled, and will echo
when called.  DBG_ALL enables all dbg_echo()s in all user-scripts.

If numeric values are used (only in DBG_<scriptname>, not in DBG_ALL),
then dbg_echo_v() is enabled according to the numeric value:

dbg_echo_v 2 "echo me" $*	# will echo if envar=2 or more.

Use of separate vars for each file to be debugged gives both
flexibility and precision; script names must match exactly, after
scriptname massaging.  The massaging is basename, drop suffix, convert
'-' to '_', so path-to/script-utils.sh becomes DBG_script_utils.

Although the above implies that exports are needed on the DBG_* vars,
the exports are done by debug.rc for you, so that they are available
to subshells even when given on the cmdline, thus the following works:

       $ VDBG=x DBG_mydbg=2 DBG_script_utils=1 sh mydbg.sh yabadaba
       exported DBG_mydbg=2
(Continue reading)

Jim Cromie | 21 Aug 2012 16:08
Picon

[PATCH] debug: add debug.rc and demo script mydbg.sh

debug.rc defines dbg_echo() and dbg_echo_v() as either silent functions
or as echos, depending upon envars.

If DBG_ALL or DBG_<script-basename-w/o-suffix> are defined as non-null,
the functions are active, otherwise they do nothing.

dbg_echo_v() is active if DBG_<script> is >= 1st arg passed in,
and silent otherwise.

See mydbg.sh for simple usage.

There are other ways to do this selective echoing, for example:
- DBG_="name1:name2:name3", where names must match script-names
  (modulo trimming as done in DBG_<script...>)
- substring matching on $DBG_ so that some symbolic-ish names can be used
- others
- combos of above

So this is just a prototype, and fodder for discussion.

Signed-off-by: Jim Cromie <jim.cromie@...>
---
 usr/local/sbin/debug.rc | 44 ++++++++++++++++++++++++++++++++++++++++++++
 usr/local/sbin/mydbg.sh |  7 +++++++
 2 files changed, 51 insertions(+)
 create mode 100644 usr/local/sbin/debug.rc
 create mode 100644 usr/local/sbin/mydbg.sh

diff --git a/usr/local/sbin/debug.rc b/usr/local/sbin/debug.rc
new file mode 100644
(Continue reading)


Gmane