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