# -*- shell-script -*- # condition.sh - gdb-like "condition" debugger command # # Copyright (C) 2002-2006, 2008, 2009, 2011, 2016 # Rocky Bernstein rocky@gnu.org # # 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 condition \ "**condition** *bp_number* *zsh-cond* +Break only if *bassh-cond* is true in breakpoint number *bp_number*. *bp_number* is an integer and *cond* is an zsh expression to be evaluated whenever breakpoint *bp_number* is reached. Examples: --------- condition 5 x > 10 # Breakpoint 5 now has condition x > 10 condition 5 # Remove above condition See also: --------- *break*, *tbreak*. " 1 _Dbg_complete_brkpt_range # Set a condition for a given breakpoint $1 is a breakpoint number # $2 is a condition. If not given, set "unconditional" or 1. # returns 0 if success or 1 if fail. proc _Dbg_do_condition { if (( $# < 1 )) { _Dbg_errmsg 'condition: Argument required (breakpoint number).' return 1 } typeset -r n=$1 shift eval $_seteglob if [[ $n != $int_pat ]] { eval $_resteglob _Dbg_errmsg "condition: Bad breakpoint number: $n" return 2 } eval $_resteglob if [[ -z ${_Dbg_brkpt_file[$n]} ]] { _Dbg_msg "condition: Breakpoint entry $n is not set. Condition not changed." return 3 } if [[ -z $condition ]] { global condition := '1' _Dbg_msg "Breakpoint $n now unconditional." } _Dbg_brkpt_cond[$n]="$condition" return 0 } (CommandList children: [ (C {(_Dbg_help_add)} {(condition)} { (DQ ("**condition** *bp_number* *zsh-cond*\n") ("\n") ("+Break only if *bassh-cond* is true in breakpoint number *bp_number*.\n") ("\n") ("*bp_number* is an integer and *cond* is an zsh expression to be evaluated whenever\n") ("breakpoint *bp_number* is reached.\n") ("\n") ("Examples:\n") ("---------\n") ("\n") (" condition 5 x > 10 # Breakpoint 5 now has condition x > 10\n") (" condition 5 # Remove above condition\n") ("\n") ("See also:\n") ("---------\n") ("\n") ("*break*, *tbreak*.\n") ) } {(1)} {(_Dbg_complete_brkpt_range)} ) (FuncDef name: _Dbg_do_condition body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_Less left: (ArithWord w:{($ VSub_Pound "$#")}) right: (ArithWord w:{(Lit_Digits 1)}) ) ) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(SQ <"condition: Argument required (breakpoint number).">)}) (ControlFlow token: arg_word:{(1)}) ] spids: [-1 123] ) ] spids: [-1 138] ) (C {(typeset)} {(-r)} {(Lit_VarLike "n=") ($ VSub_Number "$1")}) (C {(shift)}) (C {(eval)} {(DQ ($ VSub_Name "$_seteglob"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_Name "$n")} right: {($ VSub_Name "$int_pat")} ) ) terminator: ) ] action: [ (C {(eval)} {(DQ ($ VSub_Name "$_resteglob"))}) (C {(_Dbg_errmsg)} {(DQ ("condition: Bad breakpoint number: ") ($ VSub_Name "$n"))}) (ControlFlow token: arg_word:{(2)}) ] spids: [-1 174] ) ] spids: [-1 197] ) (C {(eval)} {(DQ ($ VSub_Name "$_resteglob"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{($ VSub_Name "$n")})) spids: [214 219] ) } ) ) terminator: ) ] action: [ (C {(_Dbg_msg)} { (DQ ("condition: Breakpoint entry ") ($ VSub_Name "$n") (" is not set. Condition not changed.") ) } ) (ControlFlow token: arg_word:{(3)}) ] spids: [-1 225] ) ] spids: [-1 242] ) (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: [261] ) ] spids: [261] ) (C {(_Dbg_msg)} {(DQ ("Breakpoint ") ($ VSub_Name "$n") (" now unconditional."))}) ] spids: [-1 258] ) ] spids: [-1 274] ) (C {(_Dbg_brkpt_cond) (Lit_Other "[") ($ VSub_Name "$n") (Lit_Other "]") (Lit_Other "=") (DQ ($ VSub_Name "$condition")) } ) (ControlFlow token: arg_word:{(0)}) ] spids: [104] ) spids: [100 103] ) ] )