* core.c, exec.c, infrun.c, inftarg.c, language.c, remote.c,
[deliverable/binutils-gdb.git] / gdb / signame.c
1 /* Convert between signal names and numbers, for GDB.
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #include <stdio.h>
21 #include <signal.h>
22 /* GDB-specific, FIXME. (This is for the SYS_SIGLIST_MISSING define). */
23 #include "defs.h"
24 #include "signame.h"
25
26 static void
27 init_sig PARAMS ((int, const char *, const char *));
28
29 static void
30 init_sigs PARAMS ((void));
31
32 #if SYS_SIGLIST_MISSING
33 /* There is too much variation in Sys V signal numbers and names, so
34 we must initialize them at runtime. */
35
36 static const char undoc[] = "unknown signal";
37
38 /* We'd like to make this const char*[], but whoever's using it might
39 want to assign from it to a char*. */
40 char *sys_siglist[NSIG];
41 #endif /* SYS_SIGLIST_MISSING */
42
43 /* Table of abbreviations for signals. Note: A given number can
44 appear more than once with different abbreviations. */
45 typedef struct
46 {
47 int number;
48 const char *abbrev;
49 } num_abbrev;
50 static num_abbrev sig_table[NSIG*2];
51 /* Number of elements of sig_table used. */
52 static int sig_table_nelts = 0;
53
54 /* Enter signal number NUMBER into the tables with ABBREV and NAME. */
55 /* ARGSUSED */
56 static void
57 init_sig (number, abbrev, name)
58 int number;
59 const char *abbrev;
60 const char *name;
61 {
62 #if SYS_SIGLIST_MISSING
63 sys_siglist[number] = (char *) name;
64 #endif
65 sig_table[sig_table_nelts].number = number;
66 sig_table[sig_table_nelts++].abbrev = abbrev;
67 }
68
69 static void init_sigs ()
70 {
71 #if SYS_SIGLIST_MISSING
72 int i;
73
74 /* Initialize signal names. */
75 for (i = 0; i < NSIG; i++)
76 sys_siglist[i] = (char *) undoc;
77 #endif /* SYS_SIGLIST_MISSING */
78
79 /* Initialize signal names. */
80 #if defined (SIGHUP)
81 init_sig (SIGHUP, "HUP", "Hangup");
82 #endif
83 #if defined (SIGINT)
84 init_sig (SIGINT, "INT", "Interrupt");
85 #endif
86 #if defined (SIGQUIT)
87 init_sig (SIGQUIT, "QUIT", "Quit");
88 #endif
89 #if defined (SIGILL)
90 init_sig (SIGILL, "ILL", "Illegal Instruction");
91 #endif
92 #if defined (SIGTRAP)
93 init_sig (SIGTRAP, "TRAP", "Trace/breakpoint trap");
94 #endif
95 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
96 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
97 #if defined (SIGABRT)
98 init_sig (SIGABRT, "ABRT", "Aborted");
99 #endif
100 #if defined (SIGIOT)
101 init_sig (SIGIOT, "IOT", "IOT trap");
102 #endif
103 #if defined (SIGEMT)
104 init_sig (SIGEMT, "EMT", "EMT trap");
105 #endif
106 #if defined (SIGFPE)
107 init_sig (SIGFPE, "FPE", "Floating point exception");
108 #endif
109 #if defined (SIGKILL)
110 init_sig (SIGKILL, "KILL", "Killed");
111 #endif
112 #if defined (SIGBUS)
113 init_sig (SIGBUS, "BUS", "Bus error");
114 #endif
115 #if defined (SIGSEGV)
116 init_sig (SIGSEGV, "SEGV", "Segmentation fault");
117 #endif
118 #if defined (SIGSYS)
119 init_sig (SIGSYS, "SYS", "Bad system call");
120 #endif
121 #if defined (SIGPIPE)
122 init_sig (SIGPIPE, "PIPE", "Broken pipe");
123 #endif
124 #if defined (SIGALRM)
125 init_sig (SIGALRM, "ALRM", "Alarm clock");
126 #endif
127 #if defined (SIGTERM)
128 init_sig (SIGTERM, "TERM", "Terminated");
129 #endif
130 #if defined (SIGUSR1)
131 init_sig (SIGUSR1, "USR1", "User defined signal 1");
132 #endif
133 #if defined (SIGUSR2)
134 init_sig (SIGUSR2, "USR2", "User defined signal 2");
135 #endif
136 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
137 is what is in POSIX.1. */
138 #if defined (SIGCHLD)
139 init_sig (SIGCHLD, "CHLD", "Child exited");
140 #endif
141 #if defined (SIGCLD)
142 init_sig (SIGCLD, "CLD", "Child exited");
143 #endif
144 #if defined (SIGPWR)
145 init_sig (SIGPWR, "PWR", "Power failure");
146 #endif
147 #if defined (SIGTSTP)
148 init_sig (SIGTSTP, "TSTP", "Stopped");
149 #endif
150 #if defined (SIGTTIN)
151 init_sig (SIGTTIN, "TTIN", "Stopped (tty input)");
152 #endif
153 #if defined (SIGTTOU)
154 init_sig (SIGTTOU, "TTOU", "Stopped (tty output)");
155 #endif
156 #if defined (SIGSTOP)
157 init_sig (SIGSTOP, "STOP", "Stopped (signal)");
158 #endif
159 #if defined (SIGXCPU)
160 init_sig (SIGXCPU, "XCPU", "CPU time limit exceeded");
161 #endif
162 #if defined (SIGXFSZ)
163 init_sig (SIGXFSZ, "XFSZ", "File size limit exceeded");
164 #endif
165 #if defined (SIGVTALRM)
166 init_sig (SIGVTALRM, "VTALRM", "Virtual timer expired");
167 #endif
168 #if defined (SIGPROF)
169 init_sig (SIGPROF, "PROF", "Profiling timer expired");
170 #endif
171 #if defined (SIGWINCH)
172 /* "Window size changed" might be more accurate, but even if that
173 is all that it means now, perhaps in the future it will be
174 extended to cover other kinds of window changes. */
175 init_sig (SIGWINCH, "WINCH", "Window changed");
176 #endif
177 #if defined (SIGCONT)
178 init_sig (SIGCONT, "CONT", "Continued");
179 #endif
180 #if defined (SIGURG)
181 init_sig (SIGURG, "URG", "Urgent I/O condition");
182 #endif
183 #if defined (SIGIO)
184 /* "I/O pending" has also been suggested. A disadvantage is
185 that signal only happens when the process has
186 asked for it, not everytime I/O is pending. Another disadvantage
187 is the confusion from giving it a different name than under Unix. */
188 init_sig (SIGIO, "IO", "I/O possible");
189 #endif
190 #if defined (SIGWIND)
191 init_sig (SIGWIND, "WIND", "SIGWIND");
192 #endif
193 #if defined (SIGPHONE)
194 init_sig (SIGPHONE, "PHONE", "SIGPHONE");
195 #endif
196 #if defined (SIGPOLL)
197 init_sig (SIGPOLL, "POLL", "I/O possible");
198 #endif
199 #if defined (SIGLOST)
200 init_sig (SIGLOST, "LOST", "Resource lost");
201 #endif
202 }
203
204 /* Return the abbreviation for signal NUMBER. */
205 char *
206 sig_abbrev (number)
207 int number;
208 {
209 int i;
210
211 for (i = 0; i < sig_table_nelts; i++)
212 if (sig_table[i].number == number)
213 return (char *)sig_table[i].abbrev;
214 return NULL;
215 }
216
217 /* Return the signal number for an ABBREV, or -1 if there is no
218 signal by that name. */
219 int
220 sig_number (abbrev)
221 const char *abbrev;
222 {
223 int i;
224
225 /* Skip over "SIG" if present. */
226 if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
227 abbrev += 3;
228
229 for (i = 0; i < sig_table_nelts; i++)
230 if (abbrev[0] == sig_table[i].abbrev[0]
231 && strcmp (abbrev, sig_table[i].abbrev) == 0)
232 return sig_table[i].number;
233 return -1;
234 }
235
236 #if SYS_SIGLIST_MISSING
237 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
238 a colon, and followed by a newline. */
239 void
240 psignal (signal, message)
241 unsigned signal;
242 const char *message;
243 {
244 if (signal <= 0 || signal >= NSIG)
245 fprintf (stderr, "%s: unknown signal", message);
246 else
247 fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
248 }
249 #endif /* SYS_SIGLIST_MISSING */
250
251 void
252 _initialize_signame ()
253 {
254 init_sigs ();
255 }
This page took 0.033754 seconds and 4 git commands to generate.