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