1<html lang="en"> 2<head> 3<title>Signals - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stopping.html#Stopping" title="Stopping"> 9<link rel="prev" href="Continuing-and-Stepping.html#Continuing-and-Stepping" title="Continuing and Stepping"> 10<link rel="next" href="Thread-Stops.html#Thread-Stops" title="Thread Stops"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<!-- 13Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 141998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 15Free Software Foundation, Inc. 16 17Permission is granted to copy, distribute and/or modify this document 18under the terms of the GNU Free Documentation License, Version 1.3 or 19any later version published by the Free Software Foundation; with the 20Invariant Sections being ``Free Software'' and ``Free Software Needs 21Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 22and with the Back-Cover Texts as in (a) below. 23 24(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 25this GNU Manual. Buying copies from GNU Press supports the FSF in 26developing GNU and promoting software freedom.''--> 27<meta http-equiv="Content-Style-Type" content="text/css"> 28<style type="text/css"><!-- 29 pre.display { font-family:inherit } 30 pre.format { font-family:inherit } 31 pre.smalldisplay { font-family:inherit; font-size:smaller } 32 pre.smallformat { font-family:inherit; font-size:smaller } 33 pre.smallexample { font-size:smaller } 34 pre.smalllisp { font-size:smaller } 35 span.sc { font-variant:small-caps } 36 span.roman { font-family:serif; font-weight:normal; } 37 span.sansserif { font-family:sans-serif; font-weight:normal; } 38--></style> 39<link rel="stylesheet" type="text/css" href="../cs.css"> 40</head> 41<body> 42<div class="node"> 43<a name="Signals"></a> 44<p> 45Next: <a rel="next" accesskey="n" href="Thread-Stops.html#Thread-Stops">Thread Stops</a>, 46Previous: <a rel="previous" accesskey="p" href="Continuing-and-Stepping.html#Continuing-and-Stepping">Continuing and Stepping</a>, 47Up: <a rel="up" accesskey="u" href="Stopping.html#Stopping">Stopping</a> 48<hr> 49</div> 50 51<h3 class="section">5.3 Signals</h3> 52 53<p><a name="index-signals-307"></a> 54A signal is an asynchronous event that can happen in a program. The 55operating system defines the possible kinds of signals, and gives each 56kind a name and a number. For example, in Unix <code>SIGINT</code> is the 57signal a program gets when you type an interrupt character (often <kbd>Ctrl-c</kbd>); 58<code>SIGSEGV</code> is the signal a program gets from referencing a place in 59memory far away from all the areas in use; <code>SIGALRM</code> occurs when 60the alarm clock timer goes off (which happens only if your program has 61requested an alarm). 62 63 <p><a name="index-fatal-signals-308"></a>Some signals, including <code>SIGALRM</code>, are a normal part of the 64functioning of your program. Others, such as <code>SIGSEGV</code>, indicate 65errors; these signals are <dfn>fatal</dfn> (they kill your program immediately) if the 66program has not specified in advance some other way to handle the signal. 67<code>SIGINT</code> does not indicate an error in your program, but it is normally 68fatal so it can carry out the purpose of the interrupt: to kill the program. 69 70 <p><span class="sc">gdb</span> has the ability to detect any occurrence of a signal in your 71program. You can tell <span class="sc">gdb</span> in advance what to do for each kind of 72signal. 73 74 <p><a name="index-handling-signals-309"></a>Normally, <span class="sc">gdb</span> is set up to let the non-erroneous signals like 75<code>SIGALRM</code> be silently passed to your program 76(so as not to interfere with their role in the program's functioning) 77but to stop your program immediately whenever an error signal happens. 78You can change these settings with the <code>handle</code> command. 79 80 81<a name="index-info-signals-310"></a> 82<a name="index-info-handle-311"></a> 83<dl><dt><code>info signals</code><dt><code>info handle</code><dd>Print a table of all the kinds of signals and how <span class="sc">gdb</span> has been told to 84handle each one. You can use this to see the signal numbers of all 85the defined types of signals. 86 87 <br><dt><code>info signals </code><var>sig</var><dd>Similar, but print information only about the specified signal number. 88 89 <p><code>info handle</code> is an alias for <code>info signals</code>. 90 91 <p><a name="index-handle-312"></a><br><dt><code>handle </code><var>signal</var> <span class="roman">[</span><var>keywords</var><code>...</code><span class="roman">]</span><dd>Change the way <span class="sc">gdb</span> handles signal <var>signal</var>. <var>signal</var> 92can be the number of a signal or its name (with or without the 93‘<samp><span class="samp">SIG</span></samp>’ at the beginning); a list of signal numbers of the form 94‘<samp><var>low</var><span class="samp">-</span><var>high</var></samp>’; or the word ‘<samp><span class="samp">all</span></samp>’, meaning all the 95known signals. Optional arguments <var>keywords</var>, described below, 96say what change to make. 97</dl> 98 99<!-- @group --> 100 <p>The keywords allowed by the <code>handle</code> command can be abbreviated. 101Their full names are: 102 103 <dl> 104<dt><code>nostop</code><dd><span class="sc">gdb</span> should not stop your program when this signal happens. It may 105still print a message telling you that the signal has come in. 106 107 <br><dt><code>stop</code><dd><span class="sc">gdb</span> should stop your program when this signal happens. This implies 108the <code>print</code> keyword as well. 109 110 <br><dt><code>print</code><dd><span class="sc">gdb</span> should print a message when this signal happens. 111 112 <br><dt><code>noprint</code><dd><span class="sc">gdb</span> should not mention the occurrence of the signal at all. This 113implies the <code>nostop</code> keyword as well. 114 115 <br><dt><code>pass</code><dt><code>noignore</code><dd><span class="sc">gdb</span> should allow your program to see this signal; your program 116can handle the signal, or else it may terminate if the signal is fatal 117and not handled. <code>pass</code> and <code>noignore</code> are synonyms. 118 119 <br><dt><code>nopass</code><dt><code>ignore</code><dd><span class="sc">gdb</span> should not allow your program to see this signal. 120<code>nopass</code> and <code>ignore</code> are synonyms. 121</dl> 122 <!-- @end group --> 123 124 <p>When a signal stops your program, the signal is not visible to the 125program until you 126continue. Your program sees the signal then, if <code>pass</code> is in 127effect for the signal in question <em>at that time</em>. In other words, 128after <span class="sc">gdb</span> reports a signal, you can use the <code>handle</code> 129command with <code>pass</code> or <code>nopass</code> to control whether your 130program sees that signal when you continue. 131 132 <p>The default is set to <code>nostop</code>, <code>noprint</code>, <code>pass</code> for 133non-erroneous signals such as <code>SIGALRM</code>, <code>SIGWINCH</code> and 134<code>SIGCHLD</code>, and to <code>stop</code>, <code>print</code>, <code>pass</code> for the 135erroneous signals. 136 137 <p>You can also use the <code>signal</code> command to prevent your program from 138seeing a signal, or cause it to see a signal it normally would not see, 139or to give it any signal at any time. For example, if your program stopped 140due to some sort of memory reference error, you might store correct 141values into the erroneous variables and continue, hoping to see more 142execution; but your program would probably terminate immediately as 143a result of the fatal signal once it saw the signal. To prevent this, 144you can continue with ‘<samp><span class="samp">signal 0</span></samp>’. See <a href="Signaling.html#Signaling">Giving your Program a Signal</a>. 145 146 <p><a name="index-extra-signal-information-313"></a><a name="extra-signal-information"></a>On some targets, <span class="sc">gdb</span> can inspect extra signal information 147associated with the intercepted signal, before it is actually 148delivered to the program being debugged. This information is exported 149by the convenience variable <code>$_siginfo</code>, and consists of data 150that is passed by the kernel to the signal handler at the time of the 151receipt of a signal. The data type of the information itself is 152target dependent. You can see the data type using the <code>ptype 153$_siginfo</code> command. On Unix systems, it typically corresponds to the 154standard <code>siginfo_t</code> type, as defined in the <samp><span class="file">signal.h</span></samp> 155system header. 156 157 <p>Here's an example, on a <span class="sc">gnu</span>/Linux system, printing the stray 158referenced address that raised a segmentation fault. 159 160<pre class="smallexample"> (gdb) continue 161 Program received signal SIGSEGV, Segmentation fault. 162 0x0000000000400766 in main () 163 69 *(int *)p = 0; 164 (gdb) ptype $_siginfo 165 type = struct { 166 int si_signo; 167 int si_errno; 168 int si_code; 169 union { 170 int _pad[28]; 171 struct {...} _kill; 172 struct {...} _timer; 173 struct {...} _rt; 174 struct {...} _sigchld; 175 struct {...} _sigfault; 176 struct {...} _sigpoll; 177 } _sifields; 178 } 179 (gdb) ptype $_siginfo._sifields._sigfault 180 type = struct { 181 void *si_addr; 182 } 183 (gdb) p $_siginfo._sifields._sigfault.si_addr 184 $1 = (void *) 0x7ffff7ff7000 185</pre> 186 <p>Depending on target support, <code>$_siginfo</code> may also be writable. 187 188 </body></html> 189 190