Imported from ../bash-2.0.tar.gz.
This commit is contained in:
parent
726f63884d
commit
ccc6cda312
502 changed files with 91988 additions and 69123 deletions
27
examples/bashdb/PERMISSION
Normal file
27
examples/bashdb/PERMISSION
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
From mikel@ora.com Tue Aug 1 12:13:20 1995
|
||||
Flags: 10
|
||||
Return-Path: mikel@ora.com
|
||||
Received: from ruby.ora.com (ruby.ora.com [198.112.208.25]) by odin.INS.CWRU.Edu with ESMTP (8.6.12+cwru/CWRU-2.1-ins)
|
||||
id MAA01565; Tue, 1 Aug 1995 12:13:18 -0400 (from mikel@ora.com for <chet@odin.INS.CWRU.Edu>)
|
||||
Received: (from fax@localhost) by ruby.ora.com (8.6.12/8.6.11) with UUCP id MAA23251; Tue, 1 Aug 1995 12:07:51 -0400
|
||||
Received: by los.ora.com (4.1/Spike-2.1)
|
||||
id AA00672; Tue, 1 Aug 95 08:57:32 EDT
|
||||
Date: Tue, 1 Aug 95 08:57:32 EDT
|
||||
From: mikel@ora.com (Michael Loukides)
|
||||
Message-Id: <9508011257.AA00672@los.ora.com>
|
||||
Subject: Re: Ksh debugger from Rosenblatt's book [for bash]
|
||||
To: Chet Ramey <chet@odin.INS.CWRU.Edu>
|
||||
Cc: cmarie@ora.com, cam@iinet.com.au, brosenblatt@tm.com
|
||||
In-Reply-To: Chet Ramey <chet@odin.INS.CWRU.Edu>, Mon, 31 Jul 1995 16:22:48 -0400
|
||||
|
||||
I've modified a (modified) version of Bill Rosenblatt's ksh debugger
|
||||
to work with bash-2.0. Does ORA have any problem with me distributing
|
||||
it with bash-2.0?
|
||||
|
||||
That's great!
|
||||
|
||||
Go ahead and circulate it; in fact, we should probably grab it and
|
||||
stick it in our ftp archive, and put a reference to it in the book.
|
||||
(Too late to actually discuss the thing, at least for this edition).
|
||||
-------
|
||||
|
||||
8
examples/bashdb/README
Normal file
8
examples/bashdb/README
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
This is a modified version of the Korn Shell debugger from Bill
|
||||
Rosenblatt's `Learning the Korn Shell', published by O'Reilly
|
||||
and Associates (ISBN 1-56592-054-6).
|
||||
|
||||
The original `kshdb' is available for anonymous FTP with the URL
|
||||
|
||||
ftp://ftp.uu.net/published/oreilly/nutshell/ksh/ksh.tar.Z
|
||||
|
||||
29
examples/bashdb/bashdb
Normal file
29
examples/bashdb/bashdb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# kshdb - Korn Shell Debugger main file
|
||||
# adapted from 'Learning the Korn Shell' by Bill Rosenblatt (O'Reilly)
|
||||
# by Cigy Cyriac (cigy@felix.tulblr.unisys.com)
|
||||
# Main driver: constructs full script (with preamble) and runs it
|
||||
|
||||
echo 'Bourne-Again Shell Debugger version 0.1'
|
||||
|
||||
_pname=${0##*/}
|
||||
|
||||
[ $# -eq 0 ] && {
|
||||
echo "${_pname}: usage: ${_pname} <script_file>"
|
||||
exit 1
|
||||
}
|
||||
|
||||
_guineapig=$1
|
||||
|
||||
[ -r $_guineapig ] || {
|
||||
echo "${_pname}: cannot read $_guineapig." >&2
|
||||
exit 1
|
||||
}
|
||||
shift
|
||||
|
||||
_tmpdir=/tmp
|
||||
_libdir=.
|
||||
_dbgfile=$_tmpdir/bashdb$$ #temp file for script being debugged
|
||||
|
||||
cat $_libdir/bashdb.pre $_guineapig > $_dbgfile
|
||||
exec bash $_dbgfile $_guineapig $_tmpdir $_libdir "$@"
|
||||
# end of bashdb
|
||||
235
examples/bashdb/bashdb.fns
Normal file
235
examples/bashdb/bashdb.fns
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
# bashdb.fns - Bourne-Again Shell Debugger functions
|
||||
|
||||
_BUFSIZ=100
|
||||
|
||||
# Here after each statement in script being debugged.
|
||||
# Handle single-step and breakpoints.
|
||||
_steptrap() {
|
||||
let _curline=$1-1 # no. of line that just ran
|
||||
let "$_curline < 1" && let _curline=1
|
||||
|
||||
let "$_curline > $_firstline+$_BUFSIZ" && _readin $_curline
|
||||
|
||||
let " $_trace" &&
|
||||
_msg "$PS4, line $_curline: ${_lines[$(($_curline-$_firstline+1))]}"
|
||||
|
||||
# if in step mode, decrement counter
|
||||
let " $_steps >= 0" && let _steps="$_steps - 1"
|
||||
|
||||
# first check if line num or string brkpt. reached
|
||||
if _at_linenumbp || _at_stringbp; then
|
||||
_msg "Reached breakpoint at line $_curline"
|
||||
_cmdloop # enter debugger
|
||||
|
||||
# if not, check whether break condition exists and is true
|
||||
elif [ -n "$_brcond" ] && eval $_brcond; then
|
||||
_msg "Break condition $_brcond true at line $_curline"
|
||||
_cmdloop # enter debugger
|
||||
|
||||
# next, check if step mode and no. of steps is up
|
||||
elif let "$_steps == 0"; then
|
||||
_msg "Stopped at line $_curline"
|
||||
_cmdloop # enter debugger
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Debugger command loop.
|
||||
# Here at start of debugger session, when brkpt. reached, or after single-step.
|
||||
_cmdloop() {
|
||||
local cmd args
|
||||
|
||||
# added support for default command (last one entered)
|
||||
|
||||
while read -e -p "bashdb> [$lastcmd $lastargs] " cmd args; do
|
||||
if [ -z "$cmd" ]; then
|
||||
cmd=$lastcmd
|
||||
args=$lastargs
|
||||
fi
|
||||
|
||||
lastcmd="$cmd"
|
||||
lastargs=$args
|
||||
|
||||
# made commands to be debugger commands by default, no need for '*' prefix
|
||||
|
||||
case $cmd in
|
||||
bp ) _setbp $args ;; #set brkpt at line num or string
|
||||
|
||||
bc ) _setbc $args ;; # set break condition
|
||||
|
||||
cb ) _clearbp ;; # clear all brkpts.
|
||||
|
||||
g ) return ;; # start/resume execution
|
||||
|
||||
s ) let _steps=${args:-1}
|
||||
return ;; # single-step N times(default 1)
|
||||
|
||||
x ) _xtrace ;; # toggle execution trace
|
||||
|
||||
pr ) _print $args ;; # print lines in file
|
||||
|
||||
\? | h | help ) _menu ;; # print command menu
|
||||
|
||||
hi ) history ;; # show command history
|
||||
|
||||
q ) _cleanup; exit ;; # quit
|
||||
|
||||
\! ) eval $args ;; # run shell command
|
||||
|
||||
* ) _msg "Invalid command: $cmd" ; _menu ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
# see if next line no. is a brkpt.
|
||||
_at_linenumbp() {
|
||||
if [ -z "${_linebp}" ]; then
|
||||
return 1
|
||||
fi
|
||||
echo "${curline}" | egrep -s "(${linebp%\|})" >/dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
# search string brkpts to see if next line in script matches.
|
||||
_at_stringbp() {
|
||||
local l;
|
||||
if [ -z "$_stringbp" ]; then
|
||||
return 1;
|
||||
fi
|
||||
l=${_lines[$_curline-$_firstline+1]}
|
||||
echo "${l} | egrep -s "*(${stringbp%\|})*" >/dev/null 2>&1
|
||||
return $?
|
||||
}
|
||||
|
||||
|
||||
# print message to stderr
|
||||
_msg() {
|
||||
echo -e "$@" >&2
|
||||
}
|
||||
|
||||
|
||||
# set brkpt(s) at given line numbers and/or strings
|
||||
# by appending lines to brkpt file
|
||||
_setbp() {
|
||||
declare -i n
|
||||
case "$1" in
|
||||
"") _listbp ;;
|
||||
[0-9]*) #number, set brkpt at that line
|
||||
n=$1
|
||||
_linebp="${_linebp}$n|"
|
||||
_msg "Breakpoint at line " $1
|
||||
;;
|
||||
*) #string, set brkpt at next line w/string
|
||||
_stringbp="${_stringbp}$@|"
|
||||
_msg "Breakpoint at next line containing $@."
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
# list brkpts and break condition.
|
||||
_listbp() {
|
||||
_msg "Breakpoints at lines:"
|
||||
_msg "$(echo $_linebp | tr '|' ' ')"
|
||||
_msg "Breakpoints at strings:"
|
||||
_msg "$(echo $_stringbp | tr '|' ' ')"
|
||||
_msg "Break on condition:"
|
||||
_msg "$_brcond"
|
||||
}
|
||||
|
||||
|
||||
# set or clear break condition
|
||||
_setbc() {
|
||||
if [ -n "$@" ] ; then
|
||||
_brcond=$args
|
||||
_msg "Break when true: $_brcond"
|
||||
else
|
||||
_brcond=
|
||||
_msg "Break condition cleared"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# clear all brkpts
|
||||
_clearbp() {
|
||||
_linebp=
|
||||
_stringbp=
|
||||
_msg "All breakpoints cleared"
|
||||
}
|
||||
|
||||
|
||||
# toggle execution trace feature
|
||||
_xtrace() {
|
||||
let _trace="! $_trace"
|
||||
|
||||
_msg "Execution trace \c"
|
||||
let " $_trace" && _msg "on." || _msg "off."
|
||||
}
|
||||
|
||||
|
||||
# print command menu
|
||||
_menu() {
|
||||
|
||||
# made commands to be debugger commands by default, no need for '*' prefix
|
||||
|
||||
_msg 'bashdb commands:
|
||||
bp N set breakpoint at line N
|
||||
bp string set breakpoint at next line containing "string"
|
||||
bp list breakpoints and break condition
|
||||
bc string set break condition to "string"
|
||||
bc clear break condition
|
||||
cb clear all breakpoints
|
||||
g start/resume execution
|
||||
s [N] execute N statements (default 1)
|
||||
x toggle execution trace on/off (default on)
|
||||
pr [start|.] [cnt] print "cnt" lines from line no. "start"
|
||||
?, h, help print this menu
|
||||
hi show command history
|
||||
q quit
|
||||
|
||||
! cmd [args] execute command "cmd" with "args"
|
||||
|
||||
default: last command (in "[ ]" at the prompt)
|
||||
|
||||
Readline command line editing (emacs/vi mode) is available'
|
||||
}
|
||||
|
||||
|
||||
# erase temp files before exiting
|
||||
_cleanup() {
|
||||
rm $_dbgfile 2>/dev/null
|
||||
}
|
||||
|
||||
|
||||
# read $_BUFSIZ lines from $_guineapig into _lines array, starting from line $1
|
||||
# save number of first line read in _firstline
|
||||
_readin() {
|
||||
declare -i _i=1
|
||||
let _firstline=$1
|
||||
|
||||
SEDCMD="$_firstline,$(($_firstline+$_BUFSIZ))p"
|
||||
|
||||
sed -n "$SEDCMD" $_guineapig > /tmp/_script.$$
|
||||
while read -r _lines[$_i]; do
|
||||
_i=_i+1
|
||||
done < /tmp/_script.$$
|
||||
rm -f /tmp/_script.$$ 2>/dev/null
|
||||
}
|
||||
|
||||
_print() {
|
||||
typeset _start _cnt
|
||||
|
||||
if [ -z "$1" ] || [ "$1" = . ]; then
|
||||
_start=$_curline
|
||||
else
|
||||
_start=$1
|
||||
fi
|
||||
|
||||
_cnt=${2:-9}
|
||||
|
||||
SEDCMD="$_start,$(($_start+$_cnt))p"
|
||||
|
||||
pr -tn $_guineapig | sed -n "$SEDCMD"
|
||||
}
|
||||
37
examples/bashdb/bashdb.pre
Normal file
37
examples/bashdb/bashdb.pre
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# bashdb.pre - Bourne-Again Shell Debugger preamble file
|
||||
# prepended to script being ddebugged
|
||||
#arguments:
|
||||
# $1 = name of original guineapig script
|
||||
# $2 = dir where temp files are stored
|
||||
# $3 = dir where bashdb.pre and bashdb.fns are stored
|
||||
|
||||
# separate history file for bashdb
|
||||
HISTFILE=~/.bashdb_history
|
||||
set -o history
|
||||
set +H
|
||||
|
||||
# prompt for trace line
|
||||
PS4=$1
|
||||
|
||||
_dbgfile=$0
|
||||
_guineapig=$1
|
||||
_tmpdir=$2
|
||||
_libdir=$3
|
||||
shift 3 #move user's args into place
|
||||
|
||||
. $_libdir/bashdb.fns #read in the debugger functions
|
||||
|
||||
_linebp=
|
||||
_stringbp=
|
||||
let _trace=1 #init execution trace flag to on
|
||||
|
||||
#read guineapig file into _lines array
|
||||
_readin 1
|
||||
|
||||
trap _cleanup EXIT #erase files before exiting
|
||||
|
||||
let _steps=1 #no. of statements to run after setting trap
|
||||
#set LINENO, gets incremented to 1
|
||||
LINENO=0
|
||||
trap '_steptrap $LINENO' DEBUG
|
||||
:
|
||||
Loading…
Add table
Add a link
Reference in a new issue