1 /* Convert between signal names and numbers.
2 Copyright (C) 1990 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 /* GDB-specific, FIXME. (This is for the SYS_SIGLIST_MISSING define). */
34 #if SYS_SIGLIST_MISSING
35 /* There is too much variation in Sys V signal numbers and names, so
36 we must initialize them at runtime. */
38 static CONST char undoc[] = "unknown signal";
40 /* We'd like to make this const char*[], but whoever's using it might
41 want to assign from it to a char*. */
42 char *sys_siglist[NSIG];
43 #endif /* SYS_SIGLIST_MISSING */
45 /* Table of abbreviations for signals. Note: A given number can
46 appear more than once with different abbreviations. */
52 static num_abbrev sig_table[NSIG*2];
53 /* Number of elements of sig_table used. */
54 static int sig_table_nelts = 0;
56 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
59 init_sig (number, abbrev, name)
64 #if SYS_SIGLIST_MISSING
65 sys_siglist[number] = (char *) name;
67 sig_table[sig_table_nelts].number = number;
68 sig_table[sig_table_nelts++].abbrev = abbrev;
71 static void init_sigs ()
73 #if SYS_SIGLIST_MISSING
76 /* Initialize signal names. */
77 for (i = 0; i < NSIG; i++)
78 sys_siglist[i] = (char *) undoc;
79 #endif /* SYS_SIGLIST_MISSING */
81 /* Initialize signal names. */
83 init_sig (SIGHUP, "HUP", "Hangup");
86 init_sig (SIGINT, "INT", "Interrupt");
89 init_sig (SIGQUIT, "QUIT", "Quit");
92 init_sig (SIGILL, "ILL", "Illegal Instruction");
95 init_sig (SIGTRAP, "TRAP", "Trace/breakpoint trap");
97 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
98 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
100 init_sig (SIGABRT, "ABRT", "Aborted");
103 init_sig (SIGIOT, "IOT", "IOT trap");
106 init_sig (SIGEMT, "EMT", "EMT trap");
109 init_sig (SIGFPE, "FPE", "Floating point exception");
111 #if defined (SIGKILL)
112 init_sig (SIGKILL, "KILL", "Killed");
115 init_sig (SIGBUS, "BUS", "Bus error");
117 #if defined (SIGSEGV)
118 init_sig (SIGSEGV, "SEGV", "Segmentation fault");
121 init_sig (SIGSYS, "SYS", "Bad system call");
123 #if defined (SIGPIPE)
124 init_sig (SIGPIPE, "PIPE", "Broken pipe");
126 #if defined (SIGALRM)
127 init_sig (SIGALRM, "ALRM", "Alarm clock");
129 #if defined (SIGTERM)
130 init_sig (SIGTERM, "TERM", "Terminated");
132 #if defined (SIGUSR1)
133 init_sig (SIGUSR1, "USR1", "User defined signal 1");
135 #if defined (SIGUSR2)
136 init_sig (SIGUSR2, "USR2", "User defined signal 2");
138 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
139 is what is in POSIX.1. */
140 #if defined (SIGCHLD)
141 init_sig (SIGCHLD, "CHLD", "Child exited");
144 init_sig (SIGCLD, "CLD", "Child exited");
147 init_sig (SIGPWR, "PWR", "Power failure");
149 #if defined (SIGTSTP)
150 init_sig (SIGTSTP, "TSTP", "Stopped");
152 #if defined (SIGTTIN)
153 init_sig (SIGTTIN, "TTIN", "Stopped (tty input)");
155 #if defined (SIGTTOU)
156 init_sig (SIGTTOU, "TTOU", "Stopped (tty output)");
158 #if defined (SIGSTOP)
159 init_sig (SIGSTOP, "STOP", "Stopped (signal)");
161 #if defined (SIGXCPU)
162 init_sig (SIGXCPU, "XCPU", "CPU time limit exceeded");
164 #if defined (SIGXFSZ)
165 init_sig (SIGXFSZ, "XFSZ", "File size limit exceeded");
167 #if defined (SIGVTALRM)
168 init_sig (SIGVTALRM, "VTALRM", "Virtual timer expired");
170 #if defined (SIGPROF)
171 init_sig (SIGPROF, "PROF", "Profiling timer expired");
173 #if defined (SIGWINCH)
174 /* "Window size changed" might be more accurate, but even if that
175 is all that it means now, perhaps in the future it will be
176 extended to cover other kinds of window changes. */
177 init_sig (SIGWINCH, "WINCH", "Window changed");
179 #if defined (SIGCONT)
180 init_sig (SIGCONT, "CONT", "Continued");
183 init_sig (SIGURG, "URG", "Urgent I/O condition");
186 /* "I/O pending" has also been suggested. A disadvantage is
187 that signal only happens when the process has
188 asked for it, not everytime I/O is pending. Another disadvantage
189 is the confusion from giving it a different name than under Unix. */
190 init_sig (SIGIO, "IO", "I/O possible");
192 #if defined (SIGWIND)
193 init_sig (SIGWIND, "WIND", "SIGWIND");
195 #if defined (SIGPHONE)
196 init_sig (SIGPHONE, "PHONE", "SIGPHONE");
198 #if defined (SIGPOLL)
199 init_sig (SIGPOLL, "POLL", "I/O possible");
201 #if defined (SIGLOST)
202 init_sig (SIGLOST, "LOST", "Resource lost");
206 /* Return the abbreviation for signal NUMBER. */
213 for (i = 0; i < sig_table_nelts; i++)
214 if (sig_table[i].number == number)
215 return (char *)sig_table[i].abbrev;
219 /* Return the signal number for an ABBREV, or -1 if there is no
220 signal by that name. */
227 /* Skip over "SIG" if present. */
228 if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
231 for (i = 0; i < sig_table_nelts; i++)
232 if (abbrev[0] == sig_table[i].abbrev[0]
233 && strcmp (abbrev, sig_table[i].abbrev) == 0)
234 return sig_table[i].number;
238 #if SYS_SIGLIST_MISSING
239 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
240 a colon, and followed by a newline. */
242 psignal (signal, message)
246 if (signal <= 0 || signal >= NSIG)
247 fprintf (stderr, "%s: unknown signal", message);
249 fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
251 #endif /* SYS_SIGLIST_MISSING */
254 _initialize_signame ()