# -*- shell-script -*- # signal.sh - gdb-like "signal" debugger command # # Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008 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 signal \ "signal SIGNAL Send a signal to the debugged program. SIGNAL can be a name like \"TERM\" (for SIGTERM) or a positive number like 15 (which in \*nix systems is the equivalent number. On \*nix systems the command \"kill -l\" sometimes will give a list of signal names and numbers. The signal is sent to process \$\$ (which is $Pid right now). Also similar is the \"kill\" command." proc _Dbg_do_signal { typeset sig=$1 typeset -i signum if [[ -z $sig ]] { _Dbg_errmsg "Missing signal name or signal number." return 1 } eval $_seteglob if [[ $sig == $int_pat ]] { eval $_resteglob global signame := $[_Dbg_signum2name $sig] if (( $? != 0 )) { _Dbg_msg "Bad signal number: $sig" return 1 } global signum := 'sig' } else { eval $_resteglob typeset signum; global signum := $[_Dbg_name2signum $sig] if (( $? != 0 )) { _Dbg_msg "Bad signal name: $sig" return 1 } } kill -$signum $Pid return 0 } (CommandList children: [ (C {(_Dbg_help_add)} {(signal)} { (DQ ("signal SIGNAL\n") ("\n") ("Send a signal to the debugged program.\n") ("\n") ("SIGNAL can be a name like ") (EscapedLiteralPart token:) (TERM) (EscapedLiteralPart token:) (" (for SIGTERM) or a positive number like \n") ("15 (which in ") (EscapedLiteralPart token:) ("nix systems is the equivalent number. On ") (EscapedLiteralPart token:) ("nix systems the\n") ("command ") (EscapedLiteralPart token:) ("kill -l") (EscapedLiteralPart token:) (" sometimes will give a list of signal names and numbers.\n") ("\n") ("The signal is sent to process ") (EscapedLiteralPart token:) (EscapedLiteralPart token:) (" (which is ") ($ VSub_Dollar "$$") (" right now).\n") ("\n") ("Also similar is the ") (EscapedLiteralPart token:) (kill) (EscapedLiteralPart token:) (" command.") ) } ) (FuncDef name: _Dbg_do_signal body: (BraceGroup children: [ (C {(typeset)} {(Lit_VarLike "sig=") ($ VSub_Number "$1")}) (C {(typeset)} {(-i)} {(signum)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_z child:{($ VSub_Name "$sig")})) terminator: ) ] action: [ (C {(_Dbg_errmsg)} {(DQ ("Missing signal name or signal number."))}) (ControlFlow token: arg_word:{(1)}) ] spids: [-1 134] ) ] spids: [-1 149] ) (C {(eval)} {(DQ ($ VSub_Name "$_seteglob"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$sig")} right: {($ VSub_Name "$int_pat")} ) ) terminator: ) ] action: [ (C {(eval)} {(DQ ($ VSub_Name "$_resteglob"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:signame) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(_Dbg_signum2name)} {($ VSub_Name "$sig")})] ) left_token: spids: [184 188] ) } spids: [183] ) ] spids: [183] ) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w:{($ VSub_QMark "$?")}) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(_Dbg_msg)} {(DQ ("Bad signal number: ") ($ VSub_Name "$sig"))}) (ControlFlow token: arg_word: {(1)} ) ] spids: [-1 206] ) ] spids: [-1 222] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:signum) op: Equal rhs: {(sig)} spids: [225] ) ] spids: [225] ) ] spids: [-1 173] ) ] else_action: [ (C {(eval)} {(DQ ($ VSub_Name "$_resteglob"))}) (Sentence child:(C {(typeset)} {(signum)}) terminator:) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:signum) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(_Dbg_name2signum)} {($ VSub_Name "$sig")})] ) left_token: spids: [246 250] ) } spids: [245] ) ] spids: [245] ) (If arms: [ (if_arm cond: [ (Sentence child: (DParen child: (ArithBinary op_id: Arith_NEqual left: (ArithWord w:{($ VSub_QMark "$?")}) right: (ArithWord w:{(Lit_Digits 0)}) ) ) terminator: ) ] action: [ (C {(_Dbg_msg)} {(DQ ("Bad signal name: ") ($ VSub_Name "$sig"))}) (ControlFlow token: arg_word: {(1)} ) ] spids: [-1 268] ) ] spids: [-1 284] ) ] spids: [229 287] ) (C {(kill)} {(-) ($ VSub_Name "$signum")} {($ VSub_Dollar "$$")}) (ControlFlow token: arg_word:{(0)}) ] spids: [106] ) spids: [102 105] ) ] )