bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bash debugging.


From: David Shuman
Subject: Bash debugging.
Date: Sat, 5 Oct 2024 16:14:04 -0400

I have been working on several items as I am using bash to configure
systems.

I started wanting to log the output of my scripts.  Then I added a prefixed
message construct so detailed logs could be summarized without extraneous
debugging information (I have written an extract program using c in the
past that could also probably be written in bash (readlng a line at a time
from the log file}. The code is expected to be modified to establish
project oriented bash environment settings for the execution of the
configuration scripts.   I have a function to print the bash reverse
function trace and the accumulated arguments table (BASH_ARGV).  The
function is user callable .It can also be issued as the first statement of
a function call (a function trace option).  Most importantly the reverse
trace is in theory (currently being tested as the initial processing for
trap statements.

Does this sound potentially like a section of the bash handbook?

Tease of the content  is an example of the current bash reverse function
trace follows

#X# 2 132 bf_showTRACE 2 D 132

#D# $0=bash/functions/bf_showTRACE.sh
#D# $1=D
#D# $2=132

#D# BASH_SUBSHELL=0 TRAP={none}

#D# lCommand=bf_showTRACE
#D# lOperandCnt=2
#D# lOperand=D 132

#D# Function Back Trace
#D# LVL FUNCTION LINENO ARGC SOURCE

#D# - bf_showTRACE 132 2 bash/functions/bf_showTRACE.sh

#D# 0 bf_showTRACE 132 2 bash/functions/bf_showTRACE.sh
#D# 1 main 0 1 bash/functions/bf_showTRACE.sh
#D# 2

#D# ARGV
#D# NO VALUE
#D# 0 132
#D# 1 D
#D# 2 -X
#D# 3

The first (#X#) ;line represents an abbreviated function trace without
backtrace data.
#X# {FuncLvl} {LineNo} (FuncName) {No Args} {Args)

The next lines #D# $x={value} are debug lines that probably should be
eliminated.

The following #?# lines start
    #D# - when the function is user invoked
    #F# - when the function is called as the first executable line of a
function
    #T# - when the function is called from a trap statement.

Display non-array BASH data
    #?# BASH_SUBSHELL= ... TRAP=....

Display function name (D/F) or trapped command (T)
    #?# lCommand=...

Display Argument count and values
  #?# lOperandCnt=...
  #?# lOperands=...

Function Back Trace
    Headings
        #?# Function Back Trace
        #?# LVL FUNCTION LINENO ARGC SOURCE

    Invoked Function or Trapped Statement
      Possibly this should only appear for a Trapped Statement
          as for #D# and #F# this is redundant with the next line
        #?# - bf_showTRACE 132 2 bash/functions/bf_showTRACE.sh

    BackTrace of Function Calls
      The current Function
        #?# 0 bf_showTRACE 132 2 bash/functions/bf_showTRACE.sh

      a Parent script invoked by bash (main)
        #?# 1 main 0 1 bash/functions/bf_showTRACE.sh

      A dummy source file
        #?# 2

Argument trace
    Headings
        #?# ARGV
        #?# NO VALUE

    Values
      function 0 above the ARGC value (2) says these are the arguments
(reverse order)
        #?# 0 132
        #?# 1 D

      function 1 above the ARGC value (1) says this is the argument
        #?# 2 -X

      appears to be a dummy unused argument
        #?# 3


Let me know what you think?

David Shuman


reply via email to

[Prev in Thread] Current Thread [Next in Thread]