Update checked-in copy for convenience. (FSF releases build their own.)
[deliverable/binutils-gdb.git] / gdb / signame.c
CommitLineData
dd3b648e
RP
1/* Convert between signal names and numbers.
2 Copyright (C) 1990 Free Software Foundation, Inc.
3
99a7de40
JG
4 This file is part of GDB.
5
dd3b648e
RP
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
99a7de40
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
dd3b648e
RP
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
99a7de40
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
dd3b648e
RP
19
20#include <stdio.h>
21#include <signal.h>
22#include "signame.h"
23
04a0511c
JK
24/* GDB-specific, FIXME. (This is for the SYS_SIGLIST_MISSING define). */
25#include "defs.h"
26#include "param.h"
27
dd3b648e
RP
28#ifdef __STDC__
29#define CONST const
30#else
31#define CONST
32#endif
33
ff8aef19 34#if SYS_SIGLIST_MISSING
dd3b648e
RP
35/* There is too much variation in Sys V signal numbers and names, so
36 we must initialize them at runtime. */
37
38static CONST char undoc[] = "unknown signal";
39
63a463b1
JK
40/* We'd like to make this const char*[], but whoever's using it might
41 want to assign from it to a char*. */
3f2e006b 42char *sys_siglist[NSIG];
dd3b648e
RP
43#endif /* SYS_SIGLIST_MISSING */
44
45/* Table of abbreviations for signals. Note: A given number can
46 appear more than once with different abbreviations. */
47typedef struct
48 {
49 int number;
50 CONST char *abbrev;
51 } num_abbrev;
52static num_abbrev sig_table[NSIG*2];
53/* Number of elements of sig_table used. */
54static int sig_table_nelts = 0;
55
56/* Enter signal number NUMBER into the tables with ABBREV and NAME. */
c4668207 57/* ARGSUSED */
dd3b648e
RP
58static void
59init_sig (number, abbrev, name)
60 int number;
61 CONST char *abbrev;
62 CONST char *name;
63{
ff8aef19 64#if SYS_SIGLIST_MISSING
63a463b1 65 sys_siglist[number] = (char *) name;
dd3b648e
RP
66#endif
67 sig_table[sig_table_nelts].number = number;
68 sig_table[sig_table_nelts++].abbrev = abbrev;
69}
70
71static void init_sigs ()
72{
ff8aef19 73#if SYS_SIGLIST_MISSING
3f2e006b
JG
74 int i;
75
dd3b648e
RP
76 /* Initialize signal names. */
77 for (i = 0; i < NSIG; i++)
63a463b1 78 sys_siglist[i] = (char *) undoc;
dd3b648e
RP
79#endif /* SYS_SIGLIST_MISSING */
80
81 /* Initialize signal names. */
82#if defined (SIGHUP)
83 init_sig (SIGHUP, "HUP", "Hangup");
84#endif
85#if defined (SIGINT)
86 init_sig (SIGINT, "INT", "Interrupt");
87#endif
88#if defined (SIGQUIT)
89 init_sig (SIGQUIT, "QUIT", "Quit");
90#endif
91#if defined (SIGILL)
92 init_sig (SIGILL, "ILL", "Illegal Instruction");
93#endif
94#if defined (SIGTRAP)
95 init_sig (SIGTRAP, "TRAP", "Trace/breakpoint trap");
96#endif
97 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
98 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
99#if defined (SIGABRT)
100 init_sig (SIGABRT, "ABRT", "Aborted");
101#endif
102#if defined (SIGIOT)
103 init_sig (SIGIOT, "IOT", "IOT trap");
104#endif
105#if defined (SIGEMT)
106 init_sig (SIGEMT, "EMT", "EMT trap");
107#endif
108#if defined (SIGFPE)
109 init_sig (SIGFPE, "FPE", "Floating point exception");
110#endif
111#if defined (SIGKILL)
112 init_sig (SIGKILL, "KILL", "Killed");
113#endif
114#if defined (SIGBUS)
115 init_sig (SIGBUS, "BUS", "Bus error");
116#endif
117#if defined (SIGSEGV)
118 init_sig (SIGSEGV, "SEGV", "Segmentation fault");
119#endif
120#if defined (SIGSYS)
121 init_sig (SIGSYS, "SYS", "Bad system call");
122#endif
123#if defined (SIGPIPE)
124 init_sig (SIGPIPE, "PIPE", "Broken pipe");
125#endif
126#if defined (SIGALRM)
127 init_sig (SIGALRM, "ALRM", "Alarm clock");
128#endif
129#if defined (SIGTERM)
130 init_sig (SIGTERM, "TERM", "Terminated");
131#endif
132#if defined (SIGUSR1)
133 init_sig (SIGUSR1, "USR1", "User defined signal 1");
134#endif
135#if defined (SIGUSR2)
136 init_sig (SIGUSR2, "USR2", "User defined signal 2");
137#endif
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");
142#endif
143#if defined (SIGCLD)
144 init_sig (SIGCLD, "CLD", "Child exited");
145#endif
146#if defined (SIGPWR)
147 init_sig (SIGPWR, "PWR", "Power failure");
148#endif
149#if defined (SIGTSTP)
150 init_sig (SIGTSTP, "TSTP", "Stopped");
151#endif
152#if defined (SIGTTIN)
153 init_sig (SIGTTIN, "TTIN", "Stopped (tty input)");
154#endif
155#if defined (SIGTTOU)
156 init_sig (SIGTTOU, "TTOU", "Stopped (tty output)");
157#endif
158#if defined (SIGSTOP)
159 init_sig (SIGSTOP, "STOP", "Stopped (signal)");
160#endif
161#if defined (SIGXCPU)
162 init_sig (SIGXCPU, "XCPU", "CPU time limit exceeded");
163#endif
164#if defined (SIGXFSZ)
165 init_sig (SIGXFSZ, "XFSZ", "File size limit exceeded");
166#endif
167#if defined (SIGVTALRM)
168 init_sig (SIGVTALRM, "VTALRM", "Virtual timer expired");
169#endif
170#if defined (SIGPROF)
171 init_sig (SIGPROF, "PROF", "Profiling timer expired");
172#endif
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");
178#endif
179#if defined (SIGCONT)
180 init_sig (SIGCONT, "CONT", "Continued");
181#endif
182#if defined (SIGURG)
183 init_sig (SIGURG, "URG", "Urgent I/O condition");
184#endif
185#if defined (SIGIO)
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");
191#endif
192#if defined (SIGWIND)
193 init_sig (SIGWIND, "WIND", "SIGWIND");
194#endif
195#if defined (SIGPHONE)
196 init_sig (SIGPHONE, "PHONE", "SIGPHONE");
197#endif
198#if defined (SIGPOLL)
199 init_sig (SIGPOLL, "POLL", "I/O possible");
200#endif
201#if defined (SIGLOST)
202 init_sig (SIGLOST, "LOST", "Resource lost");
203#endif
204}
205
206/* Return the abbreviation for signal NUMBER. */
207char *
208sig_abbrev (number)
209 int number;
210{
211 int i;
212
213 for (i = 0; i < sig_table_nelts; i++)
214 if (sig_table[i].number == number)
215 return (char *)sig_table[i].abbrev;
216 return NULL;
217}
218
219/* Return the signal number for an ABBREV, or -1 if there is no
220 signal by that name. */
221int
222sig_number (abbrev)
223 CONST char *abbrev;
224{
225 int i;
226
227 /* Skip over "SIG" if present. */
228 if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
229 abbrev += 3;
230
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;
235 return -1;
236}
237
ff8aef19 238#if SYS_SIGLIST_MISSING
dd3b648e
RP
239/* Print to standard error the name of SIGNAL, preceded by MESSAGE and
240 a colon, and followed by a newline. */
241void
242psignal (signal, message)
243 unsigned signal;
244 CONST char *message;
245{
246 if (signal <= 0 || signal >= NSIG)
247 fprintf (stderr, "%s: unknown signal", message);
248 else
249 fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
250}
ff8aef19 251#endif /* SYS_SIGLIST_MISSING */
dd3b648e
RP
252
253void
254_initialize_signame ()
255{
256 init_sigs ();
257}
This page took 0.05166 seconds and 4 git commands to generate.