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