public
Description: Debugger for zsh (at least 4.3.6-dev-2)
Homepage:
Clone URL: git://github.com/rocky/zshdb.git
rocky (author)
Fri Jul 03 22:57:20 -0700 2009
commit  d3370dfff7846c64685aa948be7662c9ca3093c1
tree    0daa8cce92dcca6e42b66e85602c19c5952699b7
parent  8f7b94496c279d3f07c37f7bbc9d8a335683f893
zshdb / zshdb.in
100755 126 lines (106 sloc) 3.993 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!@SH_PROG@ -f
# -*- shell-script -*-
# zshdb - top-level debugger program.
#
# Copyright (C) 2008 Rocky Bernstein rocky@gnu.org
#
# zshdb 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.
#
# zshdb 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 zshdb; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
# This routine gets called via the -c or --command option and its sole
# purpose is to capture the command string such as via "x $*" or
# in a traceback ("where").
function _Dbg_eval {
  eval $* # Type: "x $*" to see what's being run.
}
 
# Name we refer to ourselves by
typeset _Dbg_debugger_name='@PACKAGE@'
 
# The shell we are configured to run under.
typeset _Dbg_shell='@SH_PROG@'
 
# The release name we are configured to run under.
typeset _Dbg_release='@PACKAGE_VERSION@'
 
# The short shell name. Helps keep code common in bash, zsh, and ksh debuggers.
typeset _Dbg_shell_name=${_Dbg_shell##*/} # Equivalent to basename(_Dbg_shell)
 
# Original $0. Note we can't set this in an include.
typeset _Dbg_orig_0=$0
 
# Equivalent to basename $0; the short program name
typeset _Dbg_pname=${0##*/}
 
## Stuff set by autoconf/configure ###
typeset prefix=@prefix@
typeset _Dbg_libdir=@PKGDATADIR@
###
 
[[ ! -d $_Dbg_libdir ]] && _Dbg_libdir='.'
# Parse just the libdir option
local -a libdir
zparseopts -a libdir -E L: -library:
if (( ${#libdir} > 0 )) ; then
    typeset -a lib_opts; eval "lib_opts=($libdir)"
    if [[ ! -d ${lib_opts[2]} ]] ; then
print "${lib_opts[2]} is not a directory"
exit 1
    fi
    _Dbg_libdir=${lib_opts[2]}
    unset lib_opts
fi
unset libdir
 
# Pull in the rest of the debugger code.
typeset _Dbg_main="$_Dbg_libdir/dbg-main.sh"
if [[ ! -r $_Dbg_main ]] ; then
  print "${_Dbg_pname}: Can't read debugger library file '${_Dbg_main}'."
  print "${_Dbg_pname}: Perhaps @PACKAGE@ is installed wrong (if its installed)." >&2
  print "${_Dbg_pname}: Try running @PACKAGE@ using -L (with a different directory)." >&2
  print "${_Dbg_pname}: Run @PACKAGE@ --help for a list and explanation of options." >&2
  exit 1
fi
 
. ${_Dbg_libdir}/dbg-main.sh
 
_Dbg_set_debugger_entry
 
# Note that this is called via zshdb rather than "zsh --debugger" or zshdb-trace
_Dbg_script=1
 
if [[ -n $_Dbg_EXECUTION_STRING ]] ; then
    _Dbg_script_file=$(_Dbg_tempname cmd)
    echo "$_Dbg_EXECUTION_STRING" >$_Dbg_script_file
fi
 
if (( ${#_Dbg_script_args[@]} > 0 )) ; then
    _Dbg_script_file="${_Dbg_script_args[0]}"
     shift _Dbg_script_args
elif [[ -z $_Dbg_EXECUTION_STRING ]] ; then
    echo >&2 "${_Dbg_pname}: need to give a script to debug or use the -c option."
    exit 1
fi
 
if [[ ! -r "$_Dbg_script_file" ]] ; then
  echo "${_Dbg_pname}: cannot read program to debug: $_Dbg_script_file." >&2
  exit 1
fi
typeset _Dbg_source_file
_Dbg_source_file=$(_Dbg_expand_filename $_Dbg_script_file)
 
# Directory in which the script is located
typeset _Dbg_cdir=${_Dbg_source_file%/*}
 
if ((_Dbg_history_save)) && [[ -r $_Dbg_histfile ]] ; then
    fc -ap $_Dbg_histfile $_Dbg_history_length $_Dbg_history_length
fi
while : ; do
  # trap 'echo ERR encountered inside debugger' ERR
 
  _Dbg_set_to_return_from_debugger
  _Dbg_step_ignore=2
  emulate -R zsh
  trap '_Dbg_hook $? "$@"
    case $_Dbg_rc in
    2 ) setopt errexit ;;
    255 ) return $_Dbg_return_rc ;;
    * ) ;;
    esac' DEBUG
  . $_Dbg_source_file ${_Dbg_script_args[@]}
  trap '' DEBUG
  _Dbg_msg "Program terminated. Type 's' or 'R' to restart."
  _Dbg_process_commands
done