# -*- shell-script -*- # dbg-main.sh - debugger main include # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2010, # 2011 Rocky Bernstein # # 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]}" ]] { echo "Sorry, you need to use a debugger-enabled version of bash." !2 > !1 exit 2 } # 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] { source $(_Dbg_libdir)/init/$(_Dbg_file).sh } for _Dbg_file in [$(_Dbg_libdir)/lib/*.sh $(_Dbg_libdir)/command/*.sh] { source $_Dbg_file } if [[ -r /dev/stdin ]] { _Dbg_do_source /dev/stdin } elif [[ $(tty) != 'not a tty' ]] { _Dbg_do_source $[tty] } # 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" ]] { global _Dbg_input := '("'$DBG_INPUT") _Dbg_do_source $(_Dbg_input[0]) global _Dbg_no_nx := '1' } typeset _Dbg_startup_cmdfile=$(HOME:-~)/.$(_Dbg_debugger_name)rc if (( 0 == _Dbg_o_nx)) && [[ -r "$_Dbg_startup_cmdfile" ]] { _Dbg_do_source $_Dbg_startup_cmdfile } # _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}" ]] { typeset -xi _Dbg_DEBUGGER_LEVEL=1 } # 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} == '.' ]] { # Relative file name global _Dbg_libdir := $[_Dbg_expand_filename $(_Dbg_init_cwd)/$(_Dbg_libdir)] } for source_file in [$(_Dbg_o_init_files[@]) $DBG_RESTART_FILE] { if [[ -n "$source_file" ]] { if [[ -r "$source_file" ]] && [[ -f "$source_file" ]] { source $source_file } else { _Dbg_errmsg "Unable to read shell script: $(source_file)" } } } (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [69 74] ) ) } ) ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Sorry, you need to use a debugger-enabled version of bash."))}] redirects: [(Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[91])] ) (C {(exit)} {(2)}) ] spids: [-1 81] ) ] spids: [-1 99] ) (ForEach iter_name: _Dbg_file iter_words: [{(require)} {(pre)} {(vars)} {(io)}] do_arg_iter: False body: (DoGroup children: [ (C {(source)} {(${ VSub_Name _Dbg_libdir) (/init/) (${ VSub_Name _Dbg_file) (.sh)}) ] spids: [124 139] ) spids: [113 122] ) (ForEach iter_name: _Dbg_file iter_words: [ {(${ VSub_Name _Dbg_libdir) (/lib/) (Lit_Other "*") (.sh)} {(${ VSub_Name _Dbg_libdir) (/command/) (Lit_Other "*") (.sh)} ] do_arg_iter: False body: (DoGroup children:[(C {(source)} {($ VSub_Name "$_Dbg_file")})] spids:[164172]) spids: [147 162] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_r child:{(/dev/stdin)})) terminator: ) ] action: [(C {(_Dbg_do_source)} {(/dev/stdin)})] spids: [-1 187] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: { (CommandSubPart command_list: (CommandList children:[(C {(tty)})]) left_token: spids: [198 200] ) } right: {(SQ <"not a tty">)} ) ) terminator: ) ] action: [ (C {(_Dbg_do_source)} { (CommandSubPart command_list: (CommandList children:[(C {(tty)})]) left_token: spids: [217 219] ) } ) ] spids: [194 212] ) ] spids: [-1 221] ) (C {(typeset)} {(-a)} {(_Dbg_input)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_n child:{(DQ ($ VSub_Name "$DBG_INPUT"))}) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_Dbg_input) op: Equal rhs: {(ArrayLiteralPart words:[{(DQ ($ VSub_Name "$DBG_INPUT"))}])} spids: [264] ) ] spids: [264] ) (C {(_Dbg_do_source)} { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [275 280] ) ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:_Dbg_no_nx) op:Equal rhs:{(1)} spids:[284])] spids: [284] ) ] spids: [-1 260] ) ] spids: [-1 287] ) (C {(typeset)} {(Lit_VarLike "_Dbg_startup_cmdfile=") (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{("~")}) spids: [293 297] ) (/.) (${ VSub_Name _Dbg_debugger_name) (rc) } ) (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithWord w:{(Lit_Digits 0)}) right: (ArithVarRef name:_Dbg_o_nx) ) ) (DBracket expr: (BoolUnary op_id: BoolUnary_r child: {(DQ ($ VSub_Name "$_Dbg_startup_cmdfile"))} ) ) ] op_id: Op_DAmp ) terminator: ) ] action: [(C {(_Dbg_do_source)} {(DQ ($ VSub_Name "$_Dbg_startup_cmdfile"))})] spids: [-1 330] ) ] spids: [-1 339] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{(DQ (${ VSub_Name _Dbg_DEBUGGER_LEVEL))}) ) terminator: ) ] action: [(C {(typeset)} {(-xi)} {(Lit_VarLike "_Dbg_DEBUGGER_LEVEL=") (1)})] spids: [-1 364] ) ] spids: [-1 374] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithWord w:{(Lit_Digits 1)}) ) spids: [391 397] ) } right: {(SQ <.>)} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:_Dbg_libdir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(_Dbg_expand_filename)} {(${ VSub_Name _Dbg_init_cwd) (/) (${ VSub_Name _Dbg_libdir)} ) ] ) left_token: spids: [417 427] ) } spids: [416] ) ] spids: [416] ) ] spids: [-1 409] ) ] spids: [-1 429] ) (ForEach iter_name: source_file iter_words: [ { (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [438 443] ) } {(DQ ($ VSub_Name "$DBG_RESTART_FILE"))} ] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_n child:{(DQ ($ VSub_Name "$source_file"))}) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (DBracket expr: (BoolUnary op_id: BoolUnary_r child: {(DQ ($ VSub_Name "$source_file"))} ) ) (DBracket expr: (BoolUnary op_id: BoolUnary_f child: {(DQ ($ VSub_Name "$source_file"))} ) ) ] op_id: Op_DAmp ) terminator: ) ] action: [(C {(source)} {($ VSub_Name "$source_file")})] spids: [-1 496] ) ] else_action: [ (C {(_Dbg_errmsg)} {(DQ ("Unable to read shell script: ") (${ VSub_Name source_file))} ) ] spids: [504 517] ) ] spids: [-1 467] ) ] spids: [-1 520] ) ] spids: [450 522] ) spids: [437 448] ) ] )