|
| 1 | +# -*- shell-script -*- |
| 2 | +# Set up to Debug into another script... |
| 3 | +# |
| 4 | +# Copyright (C) 2019 Rocky Bernstein <rocky@gnu.org> |
| 5 | +# |
| 6 | +# This program is free software; you can redistribute it and/or |
| 7 | +# modify it under the terms of the GNU General Public License as |
| 8 | +# published by the Free Software Foundation; either version 2, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | +# General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU General Public License |
| 17 | +# along with this program; see the file COPYING. If not, write to |
| 18 | +# the Free Software Foundation, 59 Temple Place, Suite 330, Boston, |
| 19 | +# MA 02111 USA. |
| 20 | + |
| 21 | +_Dbg_help_add debug \ |
| 22 | +"debug [*script*] |
| 23 | +
|
| 24 | +Set up *script* for debugging. |
| 25 | +
|
| 26 | +If *script* is not given, take the script name from the command that |
| 27 | +is about to be executed. Note that when the nested debug finished, you |
| 28 | +are still where you were prior to entering the debugger. |
| 29 | +" 1 |
| 30 | + |
| 31 | +# TODO: would work better if instead of using $source_line below |
| 32 | +# which might have several statements, we could just pick up the next |
| 33 | +# single statement. |
| 34 | +_Dbg_do_debug() { |
| 35 | + |
| 36 | + # _Dbg_shell_new_shell_profile |
| 37 | + |
| 38 | + typeset script_cmd=${@:-$_Dbg_last_ksh_command} |
| 39 | + if (( $# == 0 )) ; then |
| 40 | + script_cmd=$_Dbg_last_ksh_command |
| 41 | + fi |
| 42 | + |
| 43 | + # We need to expand variables that might be in $script_cmd. |
| 44 | + # set_Dbg_nested_debug_cmd is set up to to be eval'd below. |
| 45 | + typeset set_Dbg_debug_cmd="typeset _Dbg_debug_cmd=\"$script_cmd\""; |
| 46 | + |
| 47 | + export SHELL=${_Dbg_shell} |
| 48 | + |
| 49 | + eval "$_seteglob" |
| 50 | + # Add appropriate ksh debugging options |
| 51 | + if (( ! _Dbg_script )) ; then |
| 52 | + set_Dbg_debug_cmd="typeset _Dbg_debug_cmd=\"$SHELL --init-file ${_Dbg_shell_temp_profile} --debugger $script_cmd\""; |
| 53 | + elif [[ $_Dbg_orig_0/// == *kshdb/// ]] ; then |
| 54 | + # Running "kshdb", so prepend "ksh kshdb .." |
| 55 | + set_Dbg_debug_cmd="typeset _Dbg_debug_cmd=\"$SHELL $_Dbg_orig_0 -q -L $_Dbg_libdir $script_cmd\""; |
| 56 | + fi |
| 57 | + eval "$_resteglob" |
| 58 | + eval $set_Dbg_debug_cmd |
| 59 | + |
| 60 | + if (( _Dbg_set_basename )) ; then |
| 61 | + _Dbg_msg "Debugging new script with $script_cmd" |
| 62 | + else |
| 63 | + _Dbg_msg "Debugging new script with $_Dbg_debug_cmd" |
| 64 | + fi |
| 65 | + ((_Dbg_DEBUGGER_LEVEL++)) |
| 66 | + ((_Dbg_QUIT_LEVELS++)) |
| 67 | + $_Dbg_debug_cmd |
| 68 | + ((_Dbg_QUIT_LEVELS--)) |
| 69 | + ((_Dbg_DEBUGGER_LEVEL--)) |
| 70 | + # _Dbg_restore_from_nested_shell |
| 71 | +} |
0 commit comments