This commit was generated by cvs2svn to track changes on a CVS vendor
[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 CONST 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 /* Initialize signal names. */
66 for (i = 0; i < NSIG; i++)
67 sys_siglist[i] = undoc;
68 #endif /* SYS_SIGLIST_MISSING */
69
70 /* Initialize signal names. */
71 #if defined (SIGHUP)
72 init_sig (SIGHUP, "HUP", "Hangup");
73 #endif
74 #if defined (SIGINT)
75 init_sig (SIGINT, "INT", "Interrupt");
76 #endif
77 #if defined (SIGQUIT)
78 init_sig (SIGQUIT, "QUIT", "Quit");
79 #endif
80 #if defined (SIGILL)
81 init_sig (SIGILL, "ILL", "Illegal Instruction");
82 #endif
83 #if defined (SIGTRAP)
84 init_sig (SIGTRAP, "TRAP", "Trace/breakpoint trap");
85 #endif
86 /* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
87 SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
88 #if defined (SIGABRT)
89 init_sig (SIGABRT, "ABRT", "Aborted");
90 #endif
91 #if defined (SIGIOT)
92 init_sig (SIGIOT, "IOT", "IOT trap");
93 #endif
94 #if defined (SIGEMT)
95 init_sig (SIGEMT, "EMT", "EMT trap");
96 #endif
97 #if defined (SIGFPE)
98 init_sig (SIGFPE, "FPE", "Floating point exception");
99 #endif
100 #if defined (SIGKILL)
101 init_sig (SIGKILL, "KILL", "Killed");
102 #endif
103 #if defined (SIGBUS)
104 init_sig (SIGBUS, "BUS", "Bus error");
105 #endif
106 #if defined (SIGSEGV)
107 init_sig (SIGSEGV, "SEGV", "Segmentation fault");
108 #endif
109 #if defined (SIGSYS)
110 init_sig (SIGSYS, "SYS", "Bad system call");
111 #endif
112 #if defined (SIGPIPE)
113 init_sig (SIGPIPE, "PIPE", "Broken pipe");
114 #endif
115 #if defined (SIGALRM)
116 init_sig (SIGALRM, "ALRM", "Alarm clock");
117 #endif
118 #if defined (SIGTERM)
119 init_sig (SIGTERM, "TERM", "Terminated");
120 #endif
121 #if defined (SIGUSR1)
122 init_sig (SIGUSR1, "USR1", "User defined signal 1");
123 #endif
124 #if defined (SIGUSR2)
125 init_sig (SIGUSR2, "USR2", "User defined signal 2");
126 #endif
127 /* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
128 is what is in POSIX.1. */
129 #if defined (SIGCHLD)
130 init_sig (SIGCHLD, "CHLD", "Child exited");
131 #endif
132 #if defined (SIGCLD)
133 init_sig (SIGCLD, "CLD", "Child exited");
134 #endif
135 #if defined (SIGPWR)
136 init_sig (SIGPWR, "PWR", "Power failure");
137 #endif
138 #if defined (SIGTSTP)
139 init_sig (SIGTSTP, "TSTP", "Stopped");
140 #endif
141 #if defined (SIGTTIN)
142 init_sig (SIGTTIN, "TTIN", "Stopped (tty input)");
143 #endif
144 #if defined (SIGTTOU)
145 init_sig (SIGTTOU, "TTOU", "Stopped (tty output)");
146 #endif
147 #if defined (SIGSTOP)
148 init_sig (SIGSTOP, "STOP", "Stopped (signal)");
149 #endif
150 #if defined (SIGXCPU)
151 init_sig (SIGXCPU, "XCPU", "CPU time limit exceeded");
152 #endif
153 #if defined (SIGXFSZ)
154 init_sig (SIGXFSZ, "XFSZ", "File size limit exceeded");
155 #endif
156 #if defined (SIGVTALRM)
157 init_sig (SIGVTALRM, "VTALRM", "Virtual timer expired");
158 #endif
159 #if defined (SIGPROF)
160 init_sig (SIGPROF, "PROF", "Profiling timer expired");
161 #endif
162 #if defined (SIGWINCH)
163 /* "Window size changed" might be more accurate, but even if that
164 is all that it means now, perhaps in the future it will be
165 extended to cover other kinds of window changes. */
166 init_sig (SIGWINCH, "WINCH", "Window changed");
167 #endif
168 #if defined (SIGCONT)
169 init_sig (SIGCONT, "CONT", "Continued");
170 #endif
171 #if defined (SIGURG)
172 init_sig (SIGURG, "URG", "Urgent I/O condition");
173 #endif
174 #if defined (SIGIO)
175 /* "I/O pending" has also been suggested. A disadvantage is
176 that signal only happens when the process has
177 asked for it, not everytime I/O is pending. Another disadvantage
178 is the confusion from giving it a different name than under Unix. */
179 init_sig (SIGIO, "IO", "I/O possible");
180 #endif
181 #if defined (SIGWIND)
182 init_sig (SIGWIND, "WIND", "SIGWIND");
183 #endif
184 #if defined (SIGPHONE)
185 init_sig (SIGPHONE, "PHONE", "SIGPHONE");
186 #endif
187 #if defined (SIGPOLL)
188 init_sig (SIGPOLL, "POLL", "I/O possible");
189 #endif
190 #if defined (SIGLOST)
191 init_sig (SIGLOST, "LOST", "Resource lost");
192 #endif
193 }
194
195 /* Return the abbreviation for signal NUMBER. */
196 char *
197 sig_abbrev (number)
198 int number;
199 {
200 int i;
201
202 for (i = 0; i < sig_table_nelts; i++)
203 if (sig_table[i].number == number)
204 return (char *)sig_table[i].abbrev;
205 return NULL;
206 }
207
208 /* Return the signal number for an ABBREV, or -1 if there is no
209 signal by that name. */
210 int
211 sig_number (abbrev)
212 CONST char *abbrev;
213 {
214 int i;
215
216 /* Skip over "SIG" if present. */
217 if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
218 abbrev += 3;
219
220 for (i = 0; i < sig_table_nelts; i++)
221 if (abbrev[0] == sig_table[i].abbrev[0]
222 && strcmp (abbrev, sig_table[i].abbrev) == 0)
223 return sig_table[i].number;
224 return -1;
225 }
226
227 #if defined (SYS_SIGLIST_MISSING)
228 /* Print to standard error the name of SIGNAL, preceded by MESSAGE and
229 a colon, and followed by a newline. */
230 void
231 psignal (signal, message)
232 unsigned signal;
233 CONST char *message;
234 {
235 if (signal <= 0 || signal >= NSIG)
236 fprintf (stderr, "%s: unknown signal", message);
237 else
238 fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
239 }
240 #endif
241
242 void
243 _initialize_signame ()
244 {
245 init_sigs ();
246 }
This page took 0.035688 seconds and 5 git commands to generate.