Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Start to sync with bashdb and zshdb

  • Loading branch information...
commit 63f277140d49ade4fd058b15baf116cc2243ad37 1 parent 0ece54b
@rocky authored
View
2  AUTHORS
@@ -4,5 +4,3 @@ Kate Ward is the author of shunit2 used in unit testing
Stéphane Chazelas is the author of getopts_long.sh for GNU long options
processing
-
-Nikolaj Schumacher is the author of elk-test.el used in GNU Emacs testing
View
45 Makefile.am
@@ -1,27 +1,23 @@
-# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+# Copyright (C) 2008, 2011 Rocky Bernstein <rocky@gnu.org>
#
-# kshdb is free software; you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation; either version 2, or (at your option) any later
-# version.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or
+# (at your option) any later version.
#
-# kshdb is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
#
-# You should have received a copy of the GNU General Public License along
-# with kshdb; see the file COPYING. If not, write to the Free Software
-# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
+# MA 02111 USA.
AUTOMAKE_OPTIONS = dist-bzip2
-if INSTALL_EMACS_LISP
-emacs = emacs
-else
-emacs =
-endif
-SUBDIRS = command doc $(emacs) lib test
+SUBDIRS = command lib data doc test
pkgdata_DATA = \
dbg-pre.sh \
@@ -31,14 +27,12 @@ pkgdata_DATA = \
dbg-trace.sh \
getopts_long.sh
-# Set up the install target
+# Set up the install target. Can't figure out how to use @PACKAGE@
bin_SCRIPTS = kshdb
-EXTRA_DIST = $(pkgdata_DATA) THANKS
-
-MAINTAINERCLEANFILES = ChangeLog
+MOSTLYCLEANFILES = *.orig *.rej
-test: check
+EXTRA_DIST = $(pkgdata_DATA) THANKS
# Unit testing
check-unit: test-unit
@@ -49,16 +43,13 @@ test-unit:
test-integration:
cd test/integration && make check
-phony = check test-unit check-unit
+MAINTAINERCLEANFILES = ChangeLog
if MAINTAINER_MODE
-CL = ChangeLog
ChangeLog:
git log --pretty --numstat --summary | $(GIT2CL) > $@
ACLOCAL_AMFLAGS=-I .
endif
-
-.PHONY: $(CL) test
View
2  THANKS
@@ -2,4 +2,4 @@ Thanks to David Korn for the adding necessary support to ksh
needed to get this off the ground and make debugging possible.
Thanks to Kate Ward, Stéphane Chazelas and Nikolaj Schumacher for
-programs used in conjunction with zshdb.
+programs used in conjunction with kshdb.
View
1  configure.ac
@@ -88,6 +88,7 @@ AC_CONFIG_FILES([ \
command/info_sub/Makefile \
command/show_sub/Makefile \
command/Makefile \
+ data/Makefile \
doc/Makefile \
dbg-trace.sh \
emacs/Makefile \
View
3  data/.gitignore
@@ -0,0 +1,3 @@
+/Makefile.in
+/Makefile
+/*~
View
6 data/Makefile.am
@@ -0,0 +1,6 @@
+pkgdatadir = ${datadir}/@PACKAGE@/data
+pkgdata_DATA = \
+ shell.sh
+
+EXTRA_DIST = $(pkgdata_DATA)
+MOSTLYCLEANFILES = *.orig *.rej
View
39 data/shell.sh
@@ -0,0 +1,39 @@
+# -*- shell-script -*-
+# shell.sh - helper routines for 'shell' debugger command
+#
+# Copyright (C) 2011 Rocky Bernstein <rocky@gnu.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
+# MA 02111 USA.
+
+trap '_Dbg_write_saved_vars' EXIT
+typeset -a _Dbg_save_vars
+
+# _Dbg_tmpdir='/tmp'
+# _Dbg_restore_info="${_Dbg_tmpdir}/${_Dbg_debugger_name}_restore_$$"
+typeset -a _Dbg_save_vars; _Dbg_save_vars=()
+
+# User level routine which should be called to mark which
+# variables should persist.
+save_vars() {
+ _Dbg_save_vars+=($@)
+}
+
+_Dbg_write_saved_vars() {
+ typeset param
+ for param in "${_Dbg_save_vars[@]}" ; do
+ typeset -p $param | sed -e 's:declare [^ ]* ::'
+ done > $_Dbg_restore_info
+}
View
6 lib/Makefile.am
@@ -1,5 +1,6 @@
pkgdatadir = ${datadir}/@PACKAGE@/lib
pkgdata_DATA = \
+ action.sh \
alias.sh \
break.sh \
columnize.sh \
@@ -20,6 +21,11 @@ pkgdata_DATA = \
save-restore.sh \
set-d-vars.sh \
sort.sh \
+ term-highlight.py \
tty.sh
+install-data-hook:
+ chmod +x $(DESTDIR)$(pkgdatadir)/term-highlight.py
+
EXTRA_DIST = $(pkgdata_DATA)
+MOSTLYCLEANFILES = *.orig *.rej
View
169 lib/action.sh
@@ -0,0 +1,169 @@
+# -*- shell-script -*-
+#
+# Copyright (C) 2010 Rocky Bernstein <rocky@gnu.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING. If not, write to
+# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
+# MA 02111 USA.
+
+#================ VARIABLE INITIALIZATIONS ====================#
+
+# Number of actions.
+typeset -i _Dbg_action_count=0
+
+# 1/0 if enabled or not
+typeset -a _Dbg_action_enable; _Dbg_action_enable=()
+
+# filename of action $i
+typeset -a _Dbg_action_file; _Dbg_action_file=()
+
+# Line number of action $i
+typeset -a _Dbg_action_line; _Dbg_action_line=()
+
+# statement to run when line is hit
+typeset -a _Dbg_action_stmt; _Dbg_action_stmt=()
+
+# Needed because we can't figure out what the max index is and arrays
+# can be sparse.
+typeset -i _Dbg_action_max=0
+
+# Maps a resolved filename to a list of action entries.
+typeset -A _Dbg_action_file2action; _Dbg_action_file2action=()
+
+# Maps a resolved filename to a list of action line numbers in that file
+typeset -A _Dbg_action_file2linenos; _Dbg_action_file2linenos=()
+
+# Note: we loop over possibly sparse arrays with _Dbg_brkpt_max by adding one
+# and testing for an entry. Could add yet another array to list only
+# used indices. Zsh is kind of primitive.
+
+#========================= FUNCTIONS ============================#
+
+function _Dbg_save_actions {
+ typeset -p _Dbg_action_line >> $_Dbg_statefile
+ typeset -p _Dbg_action_file >> $_Dbg_statefile
+ typeset -p _Dbg_action_enable >> $_Dbg_statefile
+ typeset -p _Dbg_action_stmt >> $_Dbg_statefile
+ typeset -p _Dbg_action_max >> $_Dbg_statefile
+ typeset -p _Dbg_action_file2linenos >> $_Dbg_statefile
+ typeset -p _Dbg_action_file2action >> $_Dbg_statefile
+}
+
+# list actions
+_Dbg_list_action() {
+
+ if [ ${#_Dbg_action_line[@]} != 0 ]; then
+ _Dbg_msg "Actions at following places:"
+ typeset -i i
+
+ _Dbg_msg "Num Enb Stmt file:line"
+ for (( i=1; (( i <= _Dbg_action_max )) ; i++ )) ; do
+ if [[ -n ${_Dbg_action_line[$i]} ]] ; then
+ typeset source_file=${_Dbg_action_file[$i]}
+ source_file=$(_Dbg_adjust_filename "$source_file")
+ _Dbg_printf "%-3d %3d %-18s %s:%s" $i ${_Dbg_action_enable[$i]} \
+ "${_Dbg_action_stmt[$i]}" \
+ $source_file ${_Dbg_action_line[$i]}
+ fi
+ done
+ else
+ _Dbg_msg "No actions have been set."
+ fi
+}
+
+# Internal routine to a set action unconditonally.
+
+_Dbg_set_action() {
+ (( $# != 3 )) && return 1
+ typeset source_file
+ source_file=$(_Dbg_expand_filename "$1")
+
+ $(_Dbg_is_int $2) || return 1
+ typeset -ri lineno=$2
+ typeset -r stmt=$3
+
+ # Increment action_max here because we are 1-origin
+ ((_Dbg_action_max++))
+ ((_Dbg_action_count++))
+
+ _Dbg_action_line[$_Dbg_action_max]=$lineno
+ _Dbg_action_file[$_Dbg_action_max]="$source_file"
+ _Dbg_action_stmt[$_Dbg_action_max]="$stmt"
+ _Dbg_action_enable[$_Dbg_action_max]=1
+
+ typeset dq_source_file
+ typeset dq_source_file=$(_Dbg_esc_dq "$source_file")
+ typeset dq_stmt=$(_Dbg_esc_dq "$stmt")
+
+ _Dbg_write_journal "_Dbg_action_line[$_Dbg_action_max]=$lineno"
+ _Dbg_write_journal "_Dbg_action_file[$_Dbg_action_max]=\"$dq_source_file\""
+ _Dbg_write_journal "_Dbg_action_stmt[$_Dbg_action_max]=\"$dq_stmt\""
+ _Dbg_write_journal "_Dbg_action_enable[$_Dbg_action_max]=1"
+
+ # Add line number with a leading and trailing space. Delimiting the
+ # number with space helps do a string search for the line number.
+ _Dbg_action_file2linenos[$source_file]+=" $lineno "
+ _Dbg_action_file2action[$source_file]+=" $_Dbg_action_max "
+
+ source_file=$(_Dbg_adjust_filename "$source_file")
+ _Dbg_msg "Action $_Dbg_action_max set in file ${source_file}, line $lineno."
+ _Dbg_write_journal "_Dbg_action_max=$_Dbg_action_max"
+ return 0
+}
+
+# Internal routine to delete an action by file/line.
+# 0 is returned if we were able to unset the action.
+# Nonzero is returned otherwize.
+_Dbg_unset_action() {
+ (( $# == 2 )) || return 1
+ typeset -r filename="$1"
+ $(_Dbg_is_int "$2") || return 1
+ typeset -i lineno=$2
+ typeset fullname
+ fullname=$(_Dbg_expand_filename "$filename")
+
+ # FIXME: combine with something?
+ typeset -a linenos
+ eval "linenos=(${_Dbg_action_file2linenos[$fullname]})"
+ typeset -a action_nos
+ eval "action_nos=(${_Dbg_action_file2action[$fullname]})"
+
+ typeset -i i
+ for ((i=0; i < ${#linenos[@]}; i++)); do
+ if (( linenos[i] == lineno )) ; then
+ # Got a match, find action entry number
+ typeset -i action_num
+ (( action_num = action_nos[i] ))
+ _Dbg_unset_action_arrays $action_num
+ unset linenos[i]
+ _Dbg_action_file2linenos[$fullname]=${linenos[@]}
+ return 0
+ fi
+ done
+ _Dbg_errmsg "No action found in file ${filename}, line $lineno."
+ return 1
+}
+
+# Internal routine to unset the actual action arrays
+# 0 is returned if successful
+_Dbg_unset_action_arrays() {
+ (( $# != 1 )) && return 1
+ typeset -i del=$1
+ _Dbg_write_journal_eval "unset _Dbg_action_enable[$del]"
+ _Dbg_write_journal_eval "unset _Dbg_action_file[$del]"
+ _Dbg_write_journal_eval "unset _Dbg_action_line[$del]"
+ _Dbg_write_journal_eval "unset _Dbg_action_stmt[$del]"
+ ((_Dbg_action_count--))
+ return 0
+}
View
21 lib/alias.sh
@@ -1,18 +1,18 @@
# -*- shell-script -*-
-# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
+# Copyright (C) 2008, 2010, Rocky Bernstein <rocky@gnu.org>
#
-# kshdb is free software; you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation; either version 2, or (at your option) any later
-# version.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, or
+# (at your option) any later version.
#
-# kshdb is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
-# with kshdb; see the file COPYING. If not, write to the Free Software
+# with this program; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
# Command aliases are stored here.
@@ -37,6 +37,7 @@ _Dbg_alias_remove() {
_Dbg_alias_expand() {
(( $# != 1 )) && return 1
expanded_alias="$1"
+ [[ -z "$1" ]] && return 0
[[ -n ${_Dbg_aliases[$1]} ]] && expanded_alias=${_Dbg_aliases[$1]}
return 0
}
View
116 lib/term-highlight.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python
+# from pydbgr.api import debug
+# debug()
+from pygments import highlight
+from pygments.lexers import BashLexer
+from pygments.formatters import TerminalFormatter
+from pygments.token import Keyword, Name, Comment, String, Error, \
+ Number, Operator, Generic, Token, Whitespace
+from tempfile import mktemp
+import os, sys
+
+#: Map token types to a tuple of color values for light and dark
+#: backgrounds.
+TERMINAL_COLORS = {
+ Token: ('', ''),
+
+ Whitespace: ('lightgray', 'darkgray'),
+ Comment: ('brown', 'darkgray'),
+ Comment.Preproc: ('teal', 'turquoise'),
+ Keyword: ('*darkgreen*', 'blue'),
+ Keyword.Type: ('teal', 'turquoise'),
+ Operator.Word: ('purple', 'fuchsia'),
+ Name.Builtin: ('teal', 'turquoise'),
+ Name.Function: ('darkgreen', 'green'),
+ Name.Namespace: ('_teal_', '_turquoise_'),
+ Name.Class: ('_darkgreen_', '_green_'),
+ Name.Exception: ('teal', 'turquoise'),
+ Name.Decorator: ('darkgray', 'lightgray'),
+ Name.Variable: ('darkblue', 'blue'),
+ Name.Constant: ('darkblue', 'blue'),
+ Name.Attribute: ('teal', 'turquoise'),
+ Name.Tag: ('blue', 'blue'),
+ String: ('brown', 'brown'),
+ Number: ('black', 'blue'),
+
+ Generic.Deleted: ('red', 'red'),
+ Generic.Inserted: ('darkgreen', 'green'),
+ Generic.Heading: ('**', '**'),
+ Generic.Subheading: ('*purple*', '*fuchsia*'),
+ Generic.Error: ('red', 'red'),
+
+ Error: ('_red_', '_red_'),
+}
+
+
+def syntax_highlight_file(input_filename, to_stdout = False, color_file=None):
+ if to_stdout:
+ outfile = sys.stdout
+ out_filename = None
+ else:
+ basename = os.path.basename(input_filename)
+ out_filename=mktemp('.term', basename + '_')
+ try:
+ outfile = open(out_filename, 'w')
+ except IOError, (errno, strerror):
+ print "I/O in opening debugger output file %s" % out_filename
+ print "error(%s): %s" % (errno, strerror)
+ sys.exit(1)
+ except:
+ print "Unexpected error in opening output file %s" % out_filename
+ sys.exit(1)
+ pass
+ pass
+
+ if input_filename:
+ try:
+ infile = open(input_filename)
+ except IOError, (errno, strerror):
+ print "I/O in opening debugger input file %s" % input_filename
+ print "error(%s): %s" % (errno, strerror)
+ sys.exit(2)
+ except:
+ print "Unexpected error in opening output file %s" % out_filename
+ sys.exit(2)
+ pass
+ pass
+ else:
+ infile = sys.stdin
+ pass
+
+ formatter = TerminalFormatter()
+ if color_file and os.path.isfile(color_file):
+ try:
+ execfile(color_file)
+ except:
+ sys.exit(10)
+ pass
+ pass
+ formatter.colorscheme = TERMINAL_COLORS
+ for code_line in infile.readlines():
+ line = highlight(code_line, BashLexer(), formatter).strip("\r\n")
+ outfile.write(line + "\n")
+ # print line,
+ pass
+ outfile.close
+ if out_filename: print out_filename
+ sys.exit(0)
+ pass
+
+if __name__=='__main__':
+ color_file = None
+ to_stdout = False
+ if len(sys.argv) == 1:
+ to_stdout = True
+ filename = None
+ elif len(sys.argv) == 2:
+ filename = sys.argv[1]
+ elif len(sys.argv) == 3:
+ filename = sys.argv[1]
+ color_file = sys.argv[2]
+ else:
+ print "usage: $0 [FILE [color-file]]"
+ sys.exit(3)
+ pass
+ syntax_highlight_file(filename, to_stdout, color_file)
+ pass
Please sign in to comment.
Something went wrong with that request. Please try again.