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