# -*- shell-script -*- # Copyright (C) 2008-2011, 2015-2016 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. _Dbg_help_add break \ '**break** [*loc-spec*] Set a breakpoint at *loc-spec*. If no location specification is given, use the current line. Multiple breakpoints at one place are permitted, and useful if conditional. See also: --------- "tbreak" and "continue"' _Dbg_help_add tbreak \ '**tbreak* [*loc-spec*] Set a one-time breakpoint at *loc-spec*. Like "break" except the breakpoint is only temporary, so it will be deleted when hit. Equivalent to "break" followed by using "delete" on the breakpoint number. If no location specification is given, use the current line.' proc _Dbg_do_tbreak { _Dbg_do_break_common 1 $ifsjoin(Argv) return $? } proc _Dbg_do_break { _Dbg_do_break_common 0 $ifsjoin(Argv) return $? } # Add breakpoint(s) at given line number of the current file. $1 is # the line number or _Dbg_frame_lineno if omitted. $2 is a condition # to test for whether to stop. proc _Dbg_do_break_common { typeset -i is_temp=$1 shift typeset linespec if (( $# > 0 )) { global linespec := $1 } else { global linespec := $_Dbg_frame_last_lineno } shift typeset condition=$(1:-'') if [[ "$linespec" == 'if' ]] { global linespec := $_Dbg_frame_last_lineno } elif [[ -z $condition ]] { global condition := '1' } elif [[ $condition == 'if' ]] { shift } if [[ -z $condition ]] { global condition := '1' } else { global condition := "$ifsjoin(Argv)" } typeset filename typeset -i line_number typeset full_filename _Dbg_linespec_setup $linespec if [[ -n "$full_filename" ]] { if (( line_number == 0 )) { _Dbg_errmsg 'There is no line 0 to break at.' return 1 } else { _Dbg_check_line $line_number $full_filename (( $? == 0 )) && \ _Dbg_set_brkpt $full_filename $line_number $is_temp $condition } } else { _Dbg_file_not_read_in $full_filename return 2 } return 0 } # delete brkpt(s) at given file:line numbers. If no file is given # use the current file. proc _Dbg_do_clear_brkpt { typeset -r n=$(1:-$_Dbg_frame_lineno) typeset filename typeset -i line_number typeset full_filename _Dbg_linespec_setup $n if [[ -n $full_filename ]] { if (( line_number == 0 )) { _Dbg_msg "There is no line 0 to clear." return 0 } else { _Dbg_check_line $line_number $full_filename if (( $? == 0 )) { _Dbg_unset_brkpt $full_filename $line_number typeset -r found=$Status if [[ $found != 0 ]] { _Dbg_msg "Removed $found breakpoint(s)." return $found } } } } else { _Dbg_file_not_read_in $full_filename return 0 } } # list breakpoints and break condition. # If $1 is given just list those associated for that line. proc _Dbg_do_list_brkpt { eval $_seteglob if (( $# != 0 )) { typeset brkpt_num="$1" if [[ $brkpt_num != $int_pat ]] { _Dbg_errmsg "Bad breakpoint number $brkpt_num." } elif [[ -z ${_Dbg_brkpt_file[$brkpt_num]} ]] { _Dbg_errmsg "Breakpoint entry $brkpt_num is not set." } else { typeset -r -i i=$brkpt_num typeset source_file=$(_Dbg_brkpt_file[$i]) global source_file := $[_Dbg_adjust_filename $source_file] _Dbg_section "Num Type Disp Enb What" _Dbg_printf "%-3d breakpoint %-4s %-3s %s:%s" $i \ $(_Dbg_keep[${_Dbg_brkpt_onetime[$i]}]) \ $(_Dbg_yn[${_Dbg_brkpt_enable[$i]}]) \ $source_file $(_Dbg_brkpt_line[$i]) if [[ ${_Dbg_brkpt_cond[$i]} != '1' ]] { _Dbg_printf "\tstop only if %s" $(_Dbg_brkpt_cond[$i]) } _Dbg_print_brkpt_count $(_Dbg_brkpt_count[$i]) } eval $_resteglob return 0 } elif (( ${#_Dbg_brkpt_line[@]} != 0 )) { typeset -i i _Dbg_section "Num Type Disp Enb What" for (( i=1; i <= _Dbg_brkpt_max; i++ )) ; do typeset source_file=${_Dbg_brkpt_file[$i]} if [[ -n ${_Dbg_brkpt_line[$i]} ]] ; then source_file=$(_Dbg_adjust_filename "$source_file") _Dbg_printf "%-3d breakpoint %-4s %-3s %s:%s" $i \ ${_Dbg_keep[${_Dbg_brkpt_onetime[$i]}]} \ ${_Dbg_yn[${_Dbg_brkpt_enable[$i]}]} \ "$source_file" ${_Dbg_brkpt_line[$i]} if [[ ${_Dbg_brkpt_cond[$i]} != '1' ]] ; then _Dbg_printf "\tstop only if %s" "${_Dbg_brkpt_cond[$i]}" fi if (( _Dbg_brkpt_counts[$i] != 0 )) ; then _Dbg_print_brkpt_count ${_Dbg_brkpt_counts[$i]} fi fi done return 0 } else { _Dbg_msg 'No breakpoints have been set.' return 1 } } _Dbg_alias_add b break (CommandList children: [ (C {(_Dbg_help_add)} {(ControlFlow_Break break)} { (SQ <"**break** [*loc-spec*]\n"> <"\n"> <"Set a breakpoint at *loc-spec*.\n"> <"\n"> <"If no location specification is given, use the current line.\n"> <"\n"> <"Multiple breakpoints at one place are permitted, and useful if conditional.\n"> <"\n"> <"See also:\n"> <"---------\n"> <"\n"> <"\"tbreak\" and \"continue\""> ) } ) (C {(_Dbg_help_add)} {(tbreak)} { (SQ <"**tbreak* [*loc-spec*]\n"> <"\n"> <"Set a one-time breakpoint at *loc-spec*.\n"> <"\n"> <"Like \"break\" except the breakpoint is only temporary,\n"> <"so it will be deleted when hit. Equivalent to \"break\" followed\n"> <"by using \"delete\" on the breakpoint number.\n"> <"\n"> <"If no location specification is given, use the current line."> ) } ) (FuncDef name: _Dbg_do_tbreak body: (BraceGroup children: [ (C {(_Dbg_do_break_common)} {(1)} {($ VSub_At "$@")}) (ControlFlow token: arg_word:{($ VSub_QMark "$?")}) ] spids: [95] ) spids: [91 94] ) (FuncDef name: _Dbg_do_break body: (BraceGroup children: [ (C {(_Dbg_do_break_common)} {(0)} {($ VSub_At "$@")}) (ControlFlow token: arg_word:{($ VSub_QMark "$?")}) ] spids: [116] ) spids: [112 115] ) (FuncDef name: _Dbg_do_break_common body: (BraceGroup children: [ (C {(typeset)} {(-i)} {(Lit_VarLike "is_temp=") ($ VSub_Number "$1")}) (C {(shift)}) (C {(typeset)} {(linespec)}) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_Great left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:linespec) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [185] ) ] spids: [185] ) ] spids: [-1 182] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:linespec) op: Equal rhs: {(DQ ($ VSub_Name "$_Dbg_frame_last_lineno"))} spids: [194] ) ] spids: [194] ) ] spids: [191 200] ) (C {(shift)}) (C {(typeset)} {(Lit_VarLike "condition=") (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [210 215] ) } ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$linespec"))} right: {(SQ )} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:linespec) op: Equal rhs: {($ VSub_Name "$_Dbg_frame_last_lineno")} spids: [238] ) ] spids: [238] ) ] spids: [-1 235] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{($ VSub_Name "$condition")}) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:condition) op: Equal rhs: {(1)} spids: [257] ) ] spids: [257] ) ] spids: [242 254] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$condition")} right: {(SQ )} ) ) terminator: ) ] action: [(C {(shift)})] spids: [261 277] ) ] spids: [-1 283] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_z child:{($ VSub_Name "$condition")}) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:condition) op: Equal rhs: {(1)} spids: [301] ) ] spids: [301] ) ] spids: [-1 298] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:condition) op: Equal rhs: {(DQ ($ VSub_Star "$*"))} spids: [308] ) ] spids: [308] ) ] spids: [305 314] ) (C {(typeset)} {(filename)}) (C {(typeset)} {(-i)} {(line_number)}) (C {(typeset)} {(full_filename)}) (C {(_Dbg_linespec_setup)} {(DQ ($ VSub_Name "$linespec"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_n child: {(DQ ($ VSub_Name "$full_filename"))} ) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithVarRef name:line_number) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(SQ <"There is no line 0 to break at.">)}) (ControlFlow token: arg_word: {(1)} ) ] spids: [-1 376] ) ] else_action: [ (C {(_Dbg_check_line)} {($ VSub_Name "$line_number")} {(DQ ($ VSub_Name "$full_filename"))} ) (AndOr children: [ (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithWord w:{($ VSub_QMark "$?")}) right: (ArithWord w:{(Lit_Digits 0)}) ) ) (C {(_Dbg_set_brkpt)} {(DQ ($ VSub_Name "$full_filename"))} {(DQ ($ VSub_Name "$line_number"))} {($ VSub_Name "$is_temp")} {(DQ ($ VSub_Name "$condition"))} ) ] op_id: Op_DAmp ) ] spids: [391 435] ) ] spids: [-1 358] ) ] else_action: [ (C {(_Dbg_file_not_read_in)} {(DQ ($ VSub_Name "$full_filename"))}) (ControlFlow token: arg_word:{(2)}) ] spids: [438 453] ) (ControlFlow token: arg_word:{(0)}) ] spids: [146] ) spids: [142 145] ) (FuncDef name: _Dbg_do_clear_brkpt body: (BraceGroup children: [ (C {(typeset)} {(-r)} {(Lit_VarLike "n=") (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {($ VSub_Name "$_Dbg_frame_lineno")} ) spids: [481 485] ) } ) (C {(typeset)} {(filename)}) (C {(typeset)} {(-i)} {(line_number)}) (C {(typeset)} {(full_filename)}) (C {(_Dbg_linespec_setup)} {($ VSub_Name "$n")}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_n child:{($ VSub_Name "$full_filename")}) ) terminator: ) ] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithVarRef name:line_number) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(_Dbg_msg)} {(DQ ("There is no line 0 to clear."))}) (ControlFlow token: arg_word: {(0)} ) ] spids: [-1 543] ) ] else_action: [ (C {(_Dbg_check_line)} {($ VSub_Name "$line_number")} {(DQ ($ VSub_Name "$full_filename"))} ) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_DEqual left: (ArithWord w:{($ VSub_QMark "$?")}) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(_Dbg_unset_brkpt)} {(DQ ($ VSub_Name "$full_filename"))} {(DQ ($ VSub_Name "$line_number"))} ) (C {(typeset)} {(-r)} {(Lit_VarLike "found=") ($ VSub_QMark "$?")}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$found")} right: {(0)} ) ) terminator: ) ] action: [ (C {(_Dbg_msg)} { (DQ ("Removed ") ($ VSub_Name "$found") (" breakpoint(s).")) } ) (ControlFlow token: arg_word: {($ VSub_Name "$found")} ) ] spids: [-1 621] ) ] spids: [-1 638] ) ] spids: [-1 585] ) ] spids: [-1 641] ) ] spids: [558 644] ) ] spids: [-1 525] ) ] else_action: [ (C {(_Dbg_file_not_read_in)} {(DQ ($ VSub_Name "$full_filename"))}) (ControlFlow token: arg_word:{(0)}) ] spids: [647 662] ) ] spids: [473] ) spids: [469 472] ) (FuncDef name: _Dbg_do_list_brkpt body: (BraceGroup children: [ (C {(eval)} {(DQ ($ VSub_Name "$_seteglob"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(typeset)} {(Lit_VarLike "brkpt_num=") (DQ ($ VSub_Number "$1"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$brkpt_num")} right: {($ VSub_Name "$int_pat")} ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(DQ ("Bad breakpoint number ") ($ VSub_Name "$brkpt_num") (.))} ) ] spids: [-1 727] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$brkpt_num")}) ) spids: [745 750] ) } ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} { (DQ ("Breakpoint entry ") ($ VSub_Name "$brkpt_num") (" is not set.")) } ) ] spids: [739 756] ) ] else_action: [ (C {(typeset)} {(-r)} {(-i)} {(Lit_VarLike "i=") ($ VSub_Name "$brkpt_num")}) (C {(typeset)} {(Lit_VarLike "source_file=") (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [784 789] ) } ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:source_file) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(_Dbg_adjust_filename)} {(DQ ($ VSub_Name "$source_file"))} ) ] ) left_token: spids: [793 799] ) } spids: [792] ) ] spids: [792] ) (C {(_Dbg_section)} {(DQ ("Num Type Disp Enb What"))}) (C {(_Dbg_printf)} {(DQ ("%-3d breakpoint %-4s %-3s %s:%s"))} {($ VSub_Name "$i")} { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [822 827] ) } ) ) spids: [819 829] ) } { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [836 841] ) } ) ) spids: [833 843] ) } {(DQ ($ VSub_Name "$source_file"))} { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [851 856] ) } ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [863 868] ) } right: {(SQ <1>)} ) ) terminator: ) ] action: [ (C {(_Dbg_printf)} { (DQ (EscapedLiteralPart token:) ("stop only if %s") ) } { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [891 896] ) ) } ) ] spids: [-1 880] ) ] spids: [-1 900] ) (C {(_Dbg_print_brkpt_count)} { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [905 910] ) } ) ] spids: [768 913] ) (C {(eval)} {(DQ ($ VSub_Name "$_resteglob"))}) (ControlFlow token: arg_word:{(0)}) ] spids: [-1 703] ) (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound bracket_op: (WholeArray op_id:Lit_At) spids: [932 938] ) } ) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(typeset)} {(-i)} {(i)}) (C {(_Dbg_section)} {(DQ ("Num Type Disp Enb What"))}) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:i) right: (ArithWord w:{(Lit_Digits 1)}) ) cond: (ArithBinary op_id: Arith_LessEqual left: (ArithVarRef name:i) right: (ArithVarRef name:_Dbg_brkpt_max) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:i)) body: (DoGroup children: [ (C {(typeset)} {(Lit_VarLike "source_file=") (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$i")})) spids: [996 1001] ) } ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_n child: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [1010 1015] ) } ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:source_file) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(_Dbg_adjust_filename)} {(DQ ($ VSub_Name "$source_file"))} ) ] ) left_token: spids: [1025 1031] ) } spids: [1024] ) ] spids: [1024] ) (C {(_Dbg_printf)} {(DQ ("%-3d breakpoint %-4s %-3s %s:%s"))} {($ VSub_Name "$i")} { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [1047 1052] ) } ) ) spids: [1044 1054] ) } { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [1061 1066] ) } ) ) spids: [1058 1068] ) } {(DQ ($ VSub_Name "$source_file"))} { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [1076 1081] ) } ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: {($ VSub_Name "$i")} ) ) spids: [1088 1093] ) } right: {(SQ <1>)} ) ) terminator: ) ] action: [ (C {(_Dbg_printf)} { (DQ (EscapedLiteralPart token:) ("stop only if %s") ) } { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [1116 1121] ) ) } ) ] spids: [-1 1105] ) ] spids: [-1 1125] ) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithBinary op_id: Arith_LBracket left: (ArithVarRef name:_Dbg_brkpt_counts) right: (ArithWord w:{($ VSub_Name "$i")}) ) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(_Dbg_print_brkpt_count)} { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [1151 1156] ) } ) ] spids: [-1 1146] ) ] spids: [-1 1159] ) ] spids: [-1 1021] ) ] spids: [-1 1162] ) ] spids: [990 1165] ) ) (ControlFlow token: arg_word:{(0)}) ] spids: [928 948] ) ] else_action: [ (C {(_Dbg_msg)} {(SQ <"No breakpoints have been set.">)}) (ControlFlow token: arg_word:{(1)}) ] spids: [1173 1188] ) ] spids: [677] ) spids: [673 676] ) (C {(_Dbg_alias_add)} {(b)} {(ControlFlow_Break break)}) ] )