forked from Trepan-Debuggers/bashdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbg-main.sh
85 lines (73 loc) · 2.85 KB
/
dbg-main.sh
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
# -*- shell-script -*-
# dbg-main.sh - debugger main include
# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010,
# 2011 Rocky Bernstein <[email protected]>
#
# 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.
# Are we using a debugger-enabled bash? If not let's stop right here.
if [[ -z "${BASH_SOURCE[0]}" ]] ; then
echo "Sorry, you need to use a debugger-enabled version of bash." 2>&1
exit 2
fi
# Code that specifically has to come first.
# Note: "init" comes first and "cmds" has to come after "io".
for _Dbg_file in require pre vars io ; do
source "${_Dbg_libdir}/init/${_Dbg_file}.sh"
done
for _Dbg_file in "${_Dbg_libdir}/lib/"*.sh "${_Dbg_libdir}/command/"*.sh ; do
source "$_Dbg_file"
done
if [[ -r /dev/stdin ]] ; then
_Dbg_do_source /dev/stdin
elif [[ $(tty) != 'not a tty' ]] ; then
_Dbg_do_source "$(tty)"
fi
# List of command files to process
typeset -a _Dbg_input
# Have we already specified where to read debugger input from?
#
# Note: index 0 is only set by the debugger. It is not used otherwise for
# I/O like those indices >= _Dbg_INPUT_START_DESC are.
if [[ -n "$DBG_INPUT" ]] ; then
_Dbg_input=("$DBG_INPUT")
_Dbg_do_source "${_Dbg_input[0]}"
_Dbg_no_nx=1
fi
typeset _Dbg_startup_cmdfile=${HOME:-~}/.${_Dbg_debugger_name}rc
if (( 0 == _Dbg_o_nx)) && [[ -r "$_Dbg_startup_cmdfile" ]] ; then
_Dbg_do_source "$_Dbg_startup_cmdfile"
fi
# _Dbg_DEBUGGER_LEVEL is the number of times we are nested inside a debugger
# by virtue of running "debug" for example.
if [[ -z "${_Dbg_DEBUGGER_LEVEL}" ]] ; then
typeset -xi _Dbg_DEBUGGER_LEVEL=1
fi
# This is put at the so we have something at the end to stop at
# when we debug this. By stopping at the end all of the above functions
# and variables can be tested.
if [[ ${_Dbg_libdir:0:1} == '.' ]] ; then
# Relative file name
_Dbg_libdir="$(_Dbg_expand_filename "${_Dbg_init_cwd}/${_Dbg_libdir}")"
fi
for _Dbg_source_file in "${_Dbg_o_init_files[@]}" "$DBG_RESTART_FILE"; do
if [[ -n "$_Dbg_source_file" ]] ; then
if [[ -r "$_Dbg_source_file" ]] && [[ -f "$_Dbg_source_file" ]] ; then
source "$_Dbg_source_file"
else
_Dbg_errmsg "Unable to read shell script: ${_Dbg_source_file}"
fi
fi
done