]>
Commit | Line | Data |
---|---|---|
0150732f DJ |
1 | /* Target signal translation functions for GDB. |
2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, | |
3130066b | 3 | 2000, 2001, 2002 Free Software Foundation, Inc. |
0150732f DJ |
4 | Contributed by Cygnus Support. |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
3130066b DJ |
23 | #ifdef GDBSERVER |
24 | #include "server.h" | |
25 | #else | |
0150732f DJ |
26 | #include "defs.h" |
27 | #include "target.h" | |
309367d4 | 28 | #include "gdb_string.h" |
3130066b DJ |
29 | #endif |
30 | ||
0150732f DJ |
31 | #include <signal.h> |
32 | ||
960cb555 DJ |
33 | /* Always use __SIGRTMIN if it's available. SIGRTMIN is the lowest |
34 | _available_ realtime signal, not the lowest supported; glibc takes | |
35 | several for its own use. */ | |
36 | ||
37 | #ifndef REALTIME_LO | |
38 | # if defined(__SIGRTMIN) | |
39 | # define REALTIME_LO __SIGRTMIN | |
40 | # define REALTIME_HI __SIGRTMAX | |
41 | # elif defined(SIGRTMIN) | |
bdd73e22 DJ |
42 | # define REALTIME_LO SIGRTMIN |
43 | # define REALTIME_HI SIGRTMAX | |
960cb555 DJ |
44 | # endif |
45 | #endif | |
46 | ||
0150732f DJ |
47 | /* This table must match in order and size the signals in enum target_signal |
48 | in target.h. */ | |
49 | /* *INDENT-OFF* */ | |
50 | static struct { | |
51 | char *name; | |
52 | char *string; | |
53 | } signals [] = | |
54 | { | |
55 | {"0", "Signal 0"}, | |
56 | {"SIGHUP", "Hangup"}, | |
57 | {"SIGINT", "Interrupt"}, | |
58 | {"SIGQUIT", "Quit"}, | |
59 | {"SIGILL", "Illegal instruction"}, | |
60 | {"SIGTRAP", "Trace/breakpoint trap"}, | |
61 | {"SIGABRT", "Aborted"}, | |
62 | {"SIGEMT", "Emulation trap"}, | |
63 | {"SIGFPE", "Arithmetic exception"}, | |
64 | {"SIGKILL", "Killed"}, | |
65 | {"SIGBUS", "Bus error"}, | |
66 | {"SIGSEGV", "Segmentation fault"}, | |
67 | {"SIGSYS", "Bad system call"}, | |
68 | {"SIGPIPE", "Broken pipe"}, | |
69 | {"SIGALRM", "Alarm clock"}, | |
70 | {"SIGTERM", "Terminated"}, | |
71 | {"SIGURG", "Urgent I/O condition"}, | |
72 | {"SIGSTOP", "Stopped (signal)"}, | |
73 | {"SIGTSTP", "Stopped (user)"}, | |
74 | {"SIGCONT", "Continued"}, | |
75 | {"SIGCHLD", "Child status changed"}, | |
76 | {"SIGTTIN", "Stopped (tty input)"}, | |
77 | {"SIGTTOU", "Stopped (tty output)"}, | |
78 | {"SIGIO", "I/O possible"}, | |
79 | {"SIGXCPU", "CPU time limit exceeded"}, | |
80 | {"SIGXFSZ", "File size limit exceeded"}, | |
81 | {"SIGVTALRM", "Virtual timer expired"}, | |
82 | {"SIGPROF", "Profiling timer expired"}, | |
83 | {"SIGWINCH", "Window size changed"}, | |
84 | {"SIGLOST", "Resource lost"}, | |
85 | {"SIGUSR1", "User defined signal 1"}, | |
86 | {"SIGUSR2", "User defined signal 2"}, | |
87 | {"SIGPWR", "Power fail/restart"}, | |
88 | {"SIGPOLL", "Pollable event occurred"}, | |
89 | {"SIGWIND", "SIGWIND"}, | |
90 | {"SIGPHONE", "SIGPHONE"}, | |
91 | {"SIGWAITING", "Process's LWPs are blocked"}, | |
92 | {"SIGLWP", "Signal LWP"}, | |
93 | {"SIGDANGER", "Swap space dangerously low"}, | |
94 | {"SIGGRANT", "Monitor mode granted"}, | |
95 | {"SIGRETRACT", "Need to relinquish monitor mode"}, | |
96 | {"SIGMSG", "Monitor mode data available"}, | |
97 | {"SIGSOUND", "Sound completed"}, | |
98 | {"SIGSAK", "Secure attention"}, | |
99 | {"SIGPRIO", "SIGPRIO"}, | |
100 | {"SIG33", "Real-time event 33"}, | |
101 | {"SIG34", "Real-time event 34"}, | |
102 | {"SIG35", "Real-time event 35"}, | |
103 | {"SIG36", "Real-time event 36"}, | |
104 | {"SIG37", "Real-time event 37"}, | |
105 | {"SIG38", "Real-time event 38"}, | |
106 | {"SIG39", "Real-time event 39"}, | |
107 | {"SIG40", "Real-time event 40"}, | |
108 | {"SIG41", "Real-time event 41"}, | |
109 | {"SIG42", "Real-time event 42"}, | |
110 | {"SIG43", "Real-time event 43"}, | |
111 | {"SIG44", "Real-time event 44"}, | |
112 | {"SIG45", "Real-time event 45"}, | |
113 | {"SIG46", "Real-time event 46"}, | |
114 | {"SIG47", "Real-time event 47"}, | |
115 | {"SIG48", "Real-time event 48"}, | |
116 | {"SIG49", "Real-time event 49"}, | |
117 | {"SIG50", "Real-time event 50"}, | |
118 | {"SIG51", "Real-time event 51"}, | |
119 | {"SIG52", "Real-time event 52"}, | |
120 | {"SIG53", "Real-time event 53"}, | |
121 | {"SIG54", "Real-time event 54"}, | |
122 | {"SIG55", "Real-time event 55"}, | |
123 | {"SIG56", "Real-time event 56"}, | |
124 | {"SIG57", "Real-time event 57"}, | |
125 | {"SIG58", "Real-time event 58"}, | |
126 | {"SIG59", "Real-time event 59"}, | |
127 | {"SIG60", "Real-time event 60"}, | |
128 | {"SIG61", "Real-time event 61"}, | |
129 | {"SIG62", "Real-time event 62"}, | |
130 | {"SIG63", "Real-time event 63"}, | |
131 | {"SIGCANCEL", "LWP internal signal"}, | |
132 | {"SIG32", "Real-time event 32"}, | |
133 | {"SIG64", "Real-time event 64"}, | |
134 | {"SIG65", "Real-time event 65"}, | |
135 | {"SIG66", "Real-time event 66"}, | |
136 | {"SIG67", "Real-time event 67"}, | |
137 | {"SIG68", "Real-time event 68"}, | |
138 | {"SIG69", "Real-time event 69"}, | |
139 | {"SIG70", "Real-time event 70"}, | |
140 | {"SIG71", "Real-time event 71"}, | |
141 | {"SIG72", "Real-time event 72"}, | |
142 | {"SIG73", "Real-time event 73"}, | |
143 | {"SIG74", "Real-time event 74"}, | |
144 | {"SIG75", "Real-time event 75"}, | |
145 | {"SIG76", "Real-time event 76"}, | |
146 | {"SIG77", "Real-time event 77"}, | |
147 | {"SIG78", "Real-time event 78"}, | |
148 | {"SIG79", "Real-time event 79"}, | |
149 | {"SIG80", "Real-time event 80"}, | |
150 | {"SIG81", "Real-time event 81"}, | |
151 | {"SIG82", "Real-time event 82"}, | |
152 | {"SIG83", "Real-time event 83"}, | |
153 | {"SIG84", "Real-time event 84"}, | |
154 | {"SIG85", "Real-time event 85"}, | |
155 | {"SIG86", "Real-time event 86"}, | |
156 | {"SIG87", "Real-time event 87"}, | |
157 | {"SIG88", "Real-time event 88"}, | |
158 | {"SIG89", "Real-time event 89"}, | |
159 | {"SIG90", "Real-time event 90"}, | |
160 | {"SIG91", "Real-time event 91"}, | |
161 | {"SIG92", "Real-time event 92"}, | |
162 | {"SIG93", "Real-time event 93"}, | |
163 | {"SIG94", "Real-time event 94"}, | |
164 | {"SIG95", "Real-time event 95"}, | |
165 | {"SIG96", "Real-time event 96"}, | |
166 | {"SIG97", "Real-time event 97"}, | |
167 | {"SIG98", "Real-time event 98"}, | |
168 | {"SIG99", "Real-time event 99"}, | |
169 | {"SIG100", "Real-time event 100"}, | |
170 | {"SIG101", "Real-time event 101"}, | |
171 | {"SIG102", "Real-time event 102"}, | |
172 | {"SIG103", "Real-time event 103"}, | |
173 | {"SIG104", "Real-time event 104"}, | |
174 | {"SIG105", "Real-time event 105"}, | |
175 | {"SIG106", "Real-time event 106"}, | |
176 | {"SIG107", "Real-time event 107"}, | |
177 | {"SIG108", "Real-time event 108"}, | |
178 | {"SIG109", "Real-time event 109"}, | |
179 | {"SIG110", "Real-time event 110"}, | |
180 | {"SIG111", "Real-time event 111"}, | |
181 | {"SIG112", "Real-time event 112"}, | |
182 | {"SIG113", "Real-time event 113"}, | |
183 | {"SIG114", "Real-time event 114"}, | |
184 | {"SIG115", "Real-time event 115"}, | |
185 | {"SIG116", "Real-time event 116"}, | |
186 | {"SIG117", "Real-time event 117"}, | |
187 | {"SIG118", "Real-time event 118"}, | |
188 | {"SIG119", "Real-time event 119"}, | |
189 | {"SIG120", "Real-time event 120"}, | |
190 | {"SIG121", "Real-time event 121"}, | |
191 | {"SIG122", "Real-time event 122"}, | |
192 | {"SIG123", "Real-time event 123"}, | |
193 | {"SIG124", "Real-time event 124"}, | |
194 | {"SIG125", "Real-time event 125"}, | |
195 | {"SIG126", "Real-time event 126"}, | |
196 | {"SIG127", "Real-time event 127"}, | |
197 | ||
fd326606 DJ |
198 | {"SIGINFO", "Information request"}, |
199 | ||
200 | {NULL, "Unknown signal"}, | |
201 | {NULL, "Internal error: printing TARGET_SIGNAL_DEFAULT"}, | |
202 | ||
0150732f DJ |
203 | /* Mach exceptions */ |
204 | {"EXC_BAD_ACCESS", "Could not access memory"}, | |
205 | {"EXC_BAD_INSTRUCTION", "Illegal instruction/operand"}, | |
206 | {"EXC_ARITHMETIC", "Arithmetic exception"}, | |
207 | {"EXC_EMULATION", "Emulation instruction"}, | |
208 | {"EXC_SOFTWARE", "Software generated exception"}, | |
209 | {"EXC_BREAKPOINT", "Breakpoint"}, | |
0150732f DJ |
210 | |
211 | /* Last entry, used to check whether the table is the right size. */ | |
212 | {NULL, "TARGET_SIGNAL_MAGIC"} | |
213 | }; | |
214 | /* *INDENT-ON* */ | |
215 | ||
216 | ||
217 | ||
218 | /* Return the string for a signal. */ | |
219 | char * | |
220 | target_signal_to_string (enum target_signal sig) | |
221 | { | |
222 | if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST)) | |
223 | return signals[sig].string; | |
224 | else | |
225 | return signals[TARGET_SIGNAL_UNKNOWN].string; | |
226 | } | |
227 | ||
228 | /* Return the name for a signal. */ | |
229 | char * | |
230 | target_signal_to_name (enum target_signal sig) | |
231 | { | |
ade8f45e AC |
232 | if ((sig >= TARGET_SIGNAL_FIRST) && (sig <= TARGET_SIGNAL_LAST) |
233 | && signals[sig].name != NULL) | |
89c49e7a AC |
234 | return signals[sig].name; |
235 | else | |
ade8f45e AC |
236 | /* I think the code which prints this will always print it along |
237 | with the string, so no need to be verbose (very old comment). */ | |
238 | return "?"; | |
0150732f DJ |
239 | } |
240 | ||
241 | /* Given a name, return its signal. */ | |
242 | enum target_signal | |
243 | target_signal_from_name (char *name) | |
244 | { | |
245 | enum target_signal sig; | |
246 | ||
247 | /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD" | |
248 | for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more | |
249 | questionable; seems like by now people should call it SIGABRT | |
250 | instead. */ | |
251 | ||
252 | /* This ugly cast brought to you by the native VAX compiler. */ | |
253 | for (sig = TARGET_SIGNAL_HUP; | |
fd326606 | 254 | sig < TARGET_SIGNAL_LAST; |
0150732f | 255 | sig = (enum target_signal) ((int) sig + 1)) |
fd326606 DJ |
256 | if (signals[sig].name != NULL |
257 | && strcmp (name, signals[sig].name) == 0) | |
0150732f DJ |
258 | return sig; |
259 | return TARGET_SIGNAL_UNKNOWN; | |
260 | } | |
261 | \f | |
262 | /* The following functions are to help certain targets deal | |
263 | with the signal/waitstatus stuff. They could just as well be in | |
264 | a file called native-utils.c or unixwaitstatus-utils.c or whatever. */ | |
265 | ||
266 | /* Convert host signal to our signals. */ | |
267 | enum target_signal | |
268 | target_signal_from_host (int hostsig) | |
269 | { | |
270 | /* A switch statement would make sense but would require special kludges | |
271 | to deal with the cases where more than one signal has the same number. */ | |
272 | ||
273 | if (hostsig == 0) | |
274 | return TARGET_SIGNAL_0; | |
275 | ||
276 | #if defined (SIGHUP) | |
277 | if (hostsig == SIGHUP) | |
278 | return TARGET_SIGNAL_HUP; | |
279 | #endif | |
280 | #if defined (SIGINT) | |
281 | if (hostsig == SIGINT) | |
282 | return TARGET_SIGNAL_INT; | |
283 | #endif | |
284 | #if defined (SIGQUIT) | |
285 | if (hostsig == SIGQUIT) | |
286 | return TARGET_SIGNAL_QUIT; | |
287 | #endif | |
288 | #if defined (SIGILL) | |
289 | if (hostsig == SIGILL) | |
290 | return TARGET_SIGNAL_ILL; | |
291 | #endif | |
292 | #if defined (SIGTRAP) | |
293 | if (hostsig == SIGTRAP) | |
294 | return TARGET_SIGNAL_TRAP; | |
295 | #endif | |
296 | #if defined (SIGABRT) | |
297 | if (hostsig == SIGABRT) | |
298 | return TARGET_SIGNAL_ABRT; | |
299 | #endif | |
300 | #if defined (SIGEMT) | |
301 | if (hostsig == SIGEMT) | |
302 | return TARGET_SIGNAL_EMT; | |
303 | #endif | |
304 | #if defined (SIGFPE) | |
305 | if (hostsig == SIGFPE) | |
306 | return TARGET_SIGNAL_FPE; | |
307 | #endif | |
308 | #if defined (SIGKILL) | |
309 | if (hostsig == SIGKILL) | |
310 | return TARGET_SIGNAL_KILL; | |
311 | #endif | |
312 | #if defined (SIGBUS) | |
313 | if (hostsig == SIGBUS) | |
314 | return TARGET_SIGNAL_BUS; | |
315 | #endif | |
316 | #if defined (SIGSEGV) | |
317 | if (hostsig == SIGSEGV) | |
318 | return TARGET_SIGNAL_SEGV; | |
319 | #endif | |
320 | #if defined (SIGSYS) | |
321 | if (hostsig == SIGSYS) | |
322 | return TARGET_SIGNAL_SYS; | |
323 | #endif | |
324 | #if defined (SIGPIPE) | |
325 | if (hostsig == SIGPIPE) | |
326 | return TARGET_SIGNAL_PIPE; | |
327 | #endif | |
328 | #if defined (SIGALRM) | |
329 | if (hostsig == SIGALRM) | |
330 | return TARGET_SIGNAL_ALRM; | |
331 | #endif | |
332 | #if defined (SIGTERM) | |
333 | if (hostsig == SIGTERM) | |
334 | return TARGET_SIGNAL_TERM; | |
335 | #endif | |
336 | #if defined (SIGUSR1) | |
337 | if (hostsig == SIGUSR1) | |
338 | return TARGET_SIGNAL_USR1; | |
339 | #endif | |
340 | #if defined (SIGUSR2) | |
341 | if (hostsig == SIGUSR2) | |
342 | return TARGET_SIGNAL_USR2; | |
343 | #endif | |
344 | #if defined (SIGCLD) | |
345 | if (hostsig == SIGCLD) | |
346 | return TARGET_SIGNAL_CHLD; | |
347 | #endif | |
348 | #if defined (SIGCHLD) | |
349 | if (hostsig == SIGCHLD) | |
350 | return TARGET_SIGNAL_CHLD; | |
351 | #endif | |
352 | #if defined (SIGPWR) | |
353 | if (hostsig == SIGPWR) | |
354 | return TARGET_SIGNAL_PWR; | |
355 | #endif | |
356 | #if defined (SIGWINCH) | |
357 | if (hostsig == SIGWINCH) | |
358 | return TARGET_SIGNAL_WINCH; | |
359 | #endif | |
360 | #if defined (SIGURG) | |
361 | if (hostsig == SIGURG) | |
362 | return TARGET_SIGNAL_URG; | |
363 | #endif | |
364 | #if defined (SIGIO) | |
365 | if (hostsig == SIGIO) | |
366 | return TARGET_SIGNAL_IO; | |
367 | #endif | |
368 | #if defined (SIGPOLL) | |
369 | if (hostsig == SIGPOLL) | |
370 | return TARGET_SIGNAL_POLL; | |
371 | #endif | |
372 | #if defined (SIGSTOP) | |
373 | if (hostsig == SIGSTOP) | |
374 | return TARGET_SIGNAL_STOP; | |
375 | #endif | |
376 | #if defined (SIGTSTP) | |
377 | if (hostsig == SIGTSTP) | |
378 | return TARGET_SIGNAL_TSTP; | |
379 | #endif | |
380 | #if defined (SIGCONT) | |
381 | if (hostsig == SIGCONT) | |
382 | return TARGET_SIGNAL_CONT; | |
383 | #endif | |
384 | #if defined (SIGTTIN) | |
385 | if (hostsig == SIGTTIN) | |
386 | return TARGET_SIGNAL_TTIN; | |
387 | #endif | |
388 | #if defined (SIGTTOU) | |
389 | if (hostsig == SIGTTOU) | |
390 | return TARGET_SIGNAL_TTOU; | |
391 | #endif | |
392 | #if defined (SIGVTALRM) | |
393 | if (hostsig == SIGVTALRM) | |
394 | return TARGET_SIGNAL_VTALRM; | |
395 | #endif | |
396 | #if defined (SIGPROF) | |
397 | if (hostsig == SIGPROF) | |
398 | return TARGET_SIGNAL_PROF; | |
399 | #endif | |
400 | #if defined (SIGXCPU) | |
401 | if (hostsig == SIGXCPU) | |
402 | return TARGET_SIGNAL_XCPU; | |
403 | #endif | |
404 | #if defined (SIGXFSZ) | |
405 | if (hostsig == SIGXFSZ) | |
406 | return TARGET_SIGNAL_XFSZ; | |
407 | #endif | |
408 | #if defined (SIGWIND) | |
409 | if (hostsig == SIGWIND) | |
410 | return TARGET_SIGNAL_WIND; | |
411 | #endif | |
412 | #if defined (SIGPHONE) | |
413 | if (hostsig == SIGPHONE) | |
414 | return TARGET_SIGNAL_PHONE; | |
415 | #endif | |
416 | #if defined (SIGLOST) | |
417 | if (hostsig == SIGLOST) | |
418 | return TARGET_SIGNAL_LOST; | |
419 | #endif | |
420 | #if defined (SIGWAITING) | |
421 | if (hostsig == SIGWAITING) | |
422 | return TARGET_SIGNAL_WAITING; | |
423 | #endif | |
424 | #if defined (SIGCANCEL) | |
425 | if (hostsig == SIGCANCEL) | |
426 | return TARGET_SIGNAL_CANCEL; | |
427 | #endif | |
428 | #if defined (SIGLWP) | |
429 | if (hostsig == SIGLWP) | |
430 | return TARGET_SIGNAL_LWP; | |
431 | #endif | |
432 | #if defined (SIGDANGER) | |
433 | if (hostsig == SIGDANGER) | |
434 | return TARGET_SIGNAL_DANGER; | |
435 | #endif | |
436 | #if defined (SIGGRANT) | |
437 | if (hostsig == SIGGRANT) | |
438 | return TARGET_SIGNAL_GRANT; | |
439 | #endif | |
440 | #if defined (SIGRETRACT) | |
441 | if (hostsig == SIGRETRACT) | |
442 | return TARGET_SIGNAL_RETRACT; | |
443 | #endif | |
444 | #if defined (SIGMSG) | |
445 | if (hostsig == SIGMSG) | |
446 | return TARGET_SIGNAL_MSG; | |
447 | #endif | |
448 | #if defined (SIGSOUND) | |
449 | if (hostsig == SIGSOUND) | |
450 | return TARGET_SIGNAL_SOUND; | |
451 | #endif | |
452 | #if defined (SIGSAK) | |
453 | if (hostsig == SIGSAK) | |
454 | return TARGET_SIGNAL_SAK; | |
455 | #endif | |
456 | #if defined (SIGPRIO) | |
457 | if (hostsig == SIGPRIO) | |
458 | return TARGET_SIGNAL_PRIO; | |
459 | #endif | |
460 | ||
461 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ | |
462 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) | |
463 | if (hostsig == _NSIG + EXC_BAD_ACCESS) | |
464 | return TARGET_EXC_BAD_ACCESS; | |
465 | #endif | |
466 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) | |
467 | if (hostsig == _NSIG + EXC_BAD_INSTRUCTION) | |
468 | return TARGET_EXC_BAD_INSTRUCTION; | |
469 | #endif | |
470 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) | |
471 | if (hostsig == _NSIG + EXC_ARITHMETIC) | |
472 | return TARGET_EXC_ARITHMETIC; | |
473 | #endif | |
474 | #if defined (EXC_EMULATION) && defined (_NSIG) | |
475 | if (hostsig == _NSIG + EXC_EMULATION) | |
476 | return TARGET_EXC_EMULATION; | |
477 | #endif | |
478 | #if defined (EXC_SOFTWARE) && defined (_NSIG) | |
479 | if (hostsig == _NSIG + EXC_SOFTWARE) | |
480 | return TARGET_EXC_SOFTWARE; | |
481 | #endif | |
482 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) | |
483 | if (hostsig == _NSIG + EXC_BREAKPOINT) | |
484 | return TARGET_EXC_BREAKPOINT; | |
485 | #endif | |
486 | ||
487 | #if defined (SIGINFO) | |
488 | if (hostsig == SIGINFO) | |
489 | return TARGET_SIGNAL_INFO; | |
490 | #endif | |
491 | ||
492 | #if defined (REALTIME_LO) | |
493 | if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI) | |
494 | { | |
495 | /* This block of TARGET_SIGNAL_REALTIME value is in order. */ | |
496 | if (33 <= hostsig && hostsig <= 63) | |
497 | return (enum target_signal) | |
498 | (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33); | |
499 | else if (hostsig == 32) | |
500 | return TARGET_SIGNAL_REALTIME_32; | |
501 | else if (64 <= hostsig && hostsig <= 127) | |
502 | return (enum target_signal) | |
503 | (hostsig - 64 + (int) TARGET_SIGNAL_REALTIME_64); | |
504 | else | |
505 | error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal"); | |
506 | } | |
507 | #endif | |
508 | ||
0150732f DJ |
509 | return TARGET_SIGNAL_UNKNOWN; |
510 | } | |
511 | ||
512 | /* Convert a OURSIG (an enum target_signal) to the form used by the | |
513 | target operating system (refered to as the ``host'') or zero if the | |
514 | equivalent host signal is not available. Set/clear OURSIG_OK | |
515 | accordingly. */ | |
516 | ||
517 | static int | |
518 | do_target_signal_to_host (enum target_signal oursig, | |
519 | int *oursig_ok) | |
520 | { | |
521 | *oursig_ok = 1; | |
522 | switch (oursig) | |
523 | { | |
524 | case TARGET_SIGNAL_0: | |
525 | return 0; | |
526 | ||
527 | #if defined (SIGHUP) | |
528 | case TARGET_SIGNAL_HUP: | |
529 | return SIGHUP; | |
530 | #endif | |
531 | #if defined (SIGINT) | |
532 | case TARGET_SIGNAL_INT: | |
533 | return SIGINT; | |
534 | #endif | |
535 | #if defined (SIGQUIT) | |
536 | case TARGET_SIGNAL_QUIT: | |
537 | return SIGQUIT; | |
538 | #endif | |
539 | #if defined (SIGILL) | |
540 | case TARGET_SIGNAL_ILL: | |
541 | return SIGILL; | |
542 | #endif | |
543 | #if defined (SIGTRAP) | |
544 | case TARGET_SIGNAL_TRAP: | |
545 | return SIGTRAP; | |
546 | #endif | |
547 | #if defined (SIGABRT) | |
548 | case TARGET_SIGNAL_ABRT: | |
549 | return SIGABRT; | |
550 | #endif | |
551 | #if defined (SIGEMT) | |
552 | case TARGET_SIGNAL_EMT: | |
553 | return SIGEMT; | |
554 | #endif | |
555 | #if defined (SIGFPE) | |
556 | case TARGET_SIGNAL_FPE: | |
557 | return SIGFPE; | |
558 | #endif | |
559 | #if defined (SIGKILL) | |
560 | case TARGET_SIGNAL_KILL: | |
561 | return SIGKILL; | |
562 | #endif | |
563 | #if defined (SIGBUS) | |
564 | case TARGET_SIGNAL_BUS: | |
565 | return SIGBUS; | |
566 | #endif | |
567 | #if defined (SIGSEGV) | |
568 | case TARGET_SIGNAL_SEGV: | |
569 | return SIGSEGV; | |
570 | #endif | |
571 | #if defined (SIGSYS) | |
572 | case TARGET_SIGNAL_SYS: | |
573 | return SIGSYS; | |
574 | #endif | |
575 | #if defined (SIGPIPE) | |
576 | case TARGET_SIGNAL_PIPE: | |
577 | return SIGPIPE; | |
578 | #endif | |
579 | #if defined (SIGALRM) | |
580 | case TARGET_SIGNAL_ALRM: | |
581 | return SIGALRM; | |
582 | #endif | |
583 | #if defined (SIGTERM) | |
584 | case TARGET_SIGNAL_TERM: | |
585 | return SIGTERM; | |
586 | #endif | |
587 | #if defined (SIGUSR1) | |
588 | case TARGET_SIGNAL_USR1: | |
589 | return SIGUSR1; | |
590 | #endif | |
591 | #if defined (SIGUSR2) | |
592 | case TARGET_SIGNAL_USR2: | |
593 | return SIGUSR2; | |
594 | #endif | |
595 | #if defined (SIGCHLD) || defined (SIGCLD) | |
596 | case TARGET_SIGNAL_CHLD: | |
597 | #if defined (SIGCHLD) | |
598 | return SIGCHLD; | |
599 | #else | |
600 | return SIGCLD; | |
601 | #endif | |
602 | #endif /* SIGCLD or SIGCHLD */ | |
603 | #if defined (SIGPWR) | |
604 | case TARGET_SIGNAL_PWR: | |
605 | return SIGPWR; | |
606 | #endif | |
607 | #if defined (SIGWINCH) | |
608 | case TARGET_SIGNAL_WINCH: | |
609 | return SIGWINCH; | |
610 | #endif | |
611 | #if defined (SIGURG) | |
612 | case TARGET_SIGNAL_URG: | |
613 | return SIGURG; | |
614 | #endif | |
615 | #if defined (SIGIO) | |
616 | case TARGET_SIGNAL_IO: | |
617 | return SIGIO; | |
618 | #endif | |
619 | #if defined (SIGPOLL) | |
620 | case TARGET_SIGNAL_POLL: | |
621 | return SIGPOLL; | |
622 | #endif | |
623 | #if defined (SIGSTOP) | |
624 | case TARGET_SIGNAL_STOP: | |
625 | return SIGSTOP; | |
626 | #endif | |
627 | #if defined (SIGTSTP) | |
628 | case TARGET_SIGNAL_TSTP: | |
629 | return SIGTSTP; | |
630 | #endif | |
631 | #if defined (SIGCONT) | |
632 | case TARGET_SIGNAL_CONT: | |
633 | return SIGCONT; | |
634 | #endif | |
635 | #if defined (SIGTTIN) | |
636 | case TARGET_SIGNAL_TTIN: | |
637 | return SIGTTIN; | |
638 | #endif | |
639 | #if defined (SIGTTOU) | |
640 | case TARGET_SIGNAL_TTOU: | |
641 | return SIGTTOU; | |
642 | #endif | |
643 | #if defined (SIGVTALRM) | |
644 | case TARGET_SIGNAL_VTALRM: | |
645 | return SIGVTALRM; | |
646 | #endif | |
647 | #if defined (SIGPROF) | |
648 | case TARGET_SIGNAL_PROF: | |
649 | return SIGPROF; | |
650 | #endif | |
651 | #if defined (SIGXCPU) | |
652 | case TARGET_SIGNAL_XCPU: | |
653 | return SIGXCPU; | |
654 | #endif | |
655 | #if defined (SIGXFSZ) | |
656 | case TARGET_SIGNAL_XFSZ: | |
657 | return SIGXFSZ; | |
658 | #endif | |
659 | #if defined (SIGWIND) | |
660 | case TARGET_SIGNAL_WIND: | |
661 | return SIGWIND; | |
662 | #endif | |
663 | #if defined (SIGPHONE) | |
664 | case TARGET_SIGNAL_PHONE: | |
665 | return SIGPHONE; | |
666 | #endif | |
667 | #if defined (SIGLOST) | |
668 | case TARGET_SIGNAL_LOST: | |
669 | return SIGLOST; | |
670 | #endif | |
671 | #if defined (SIGWAITING) | |
672 | case TARGET_SIGNAL_WAITING: | |
673 | return SIGWAITING; | |
674 | #endif | |
675 | #if defined (SIGCANCEL) | |
676 | case TARGET_SIGNAL_CANCEL: | |
677 | return SIGCANCEL; | |
678 | #endif | |
679 | #if defined (SIGLWP) | |
680 | case TARGET_SIGNAL_LWP: | |
681 | return SIGLWP; | |
682 | #endif | |
683 | #if defined (SIGDANGER) | |
684 | case TARGET_SIGNAL_DANGER: | |
685 | return SIGDANGER; | |
686 | #endif | |
687 | #if defined (SIGGRANT) | |
688 | case TARGET_SIGNAL_GRANT: | |
689 | return SIGGRANT; | |
690 | #endif | |
691 | #if defined (SIGRETRACT) | |
692 | case TARGET_SIGNAL_RETRACT: | |
693 | return SIGRETRACT; | |
694 | #endif | |
695 | #if defined (SIGMSG) | |
696 | case TARGET_SIGNAL_MSG: | |
697 | return SIGMSG; | |
698 | #endif | |
699 | #if defined (SIGSOUND) | |
700 | case TARGET_SIGNAL_SOUND: | |
701 | return SIGSOUND; | |
702 | #endif | |
703 | #if defined (SIGSAK) | |
704 | case TARGET_SIGNAL_SAK: | |
705 | return SIGSAK; | |
706 | #endif | |
707 | #if defined (SIGPRIO) | |
708 | case TARGET_SIGNAL_PRIO: | |
709 | return SIGPRIO; | |
710 | #endif | |
711 | ||
712 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ | |
713 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) | |
714 | case TARGET_EXC_BAD_ACCESS: | |
715 | return _NSIG + EXC_BAD_ACCESS; | |
716 | #endif | |
717 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) | |
718 | case TARGET_EXC_BAD_INSTRUCTION: | |
719 | return _NSIG + EXC_BAD_INSTRUCTION; | |
720 | #endif | |
721 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) | |
722 | case TARGET_EXC_ARITHMETIC: | |
723 | return _NSIG + EXC_ARITHMETIC; | |
724 | #endif | |
725 | #if defined (EXC_EMULATION) && defined (_NSIG) | |
726 | case TARGET_EXC_EMULATION: | |
727 | return _NSIG + EXC_EMULATION; | |
728 | #endif | |
729 | #if defined (EXC_SOFTWARE) && defined (_NSIG) | |
730 | case TARGET_EXC_SOFTWARE: | |
731 | return _NSIG + EXC_SOFTWARE; | |
732 | #endif | |
733 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) | |
734 | case TARGET_EXC_BREAKPOINT: | |
735 | return _NSIG + EXC_BREAKPOINT; | |
736 | #endif | |
737 | ||
738 | #if defined (SIGINFO) | |
739 | case TARGET_SIGNAL_INFO: | |
740 | return SIGINFO; | |
741 | #endif | |
742 | ||
743 | default: | |
744 | #if defined (REALTIME_LO) | |
960cb555 | 745 | if (oursig < REALTIME_LO || oursig >= REALTIME_HI) |
0150732f | 746 | { |
960cb555 DJ |
747 | *oursig_ok = 0; |
748 | return 0; | |
0150732f | 749 | } |
0150732f | 750 | |
0150732f DJ |
751 | if (oursig >= TARGET_SIGNAL_REALTIME_33 |
752 | && oursig <= TARGET_SIGNAL_REALTIME_63) | |
753 | { | |
754 | /* This block of signals is continuous, and | |
755 | TARGET_SIGNAL_REALTIME_33 is 33 by definition. */ | |
756 | int retsig = | |
757 | (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33; | |
960cb555 | 758 | return retsig; |
0150732f | 759 | } |
2f2cf184 DJ |
760 | else if (oursig == TARGET_SIGNAL_REALTIME_32) |
761 | { | |
762 | /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with | |
763 | TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */ | |
764 | return 32; | |
765 | } | |
766 | else if (oursig >= TARGET_SIGNAL_REALTIME_64 | |
767 | && oursig <= TARGET_SIGNAL_REALTIME_127) | |
768 | { | |
769 | /* This block of signals is continuous, and | |
770 | TARGET_SIGNAL_REALTIME_64 is 64 by definition. */ | |
771 | int retsig = | |
772 | (int) oursig - (int) TARGET_SIGNAL_REALTIME_64 + 64; | |
773 | return retsig; | |
774 | } | |
0150732f | 775 | #endif |
960cb555 | 776 | |
0150732f DJ |
777 | *oursig_ok = 0; |
778 | return 0; | |
779 | } | |
780 | } | |
781 | ||
782 | int | |
783 | target_signal_to_host_p (enum target_signal oursig) | |
784 | { | |
785 | int oursig_ok; | |
786 | do_target_signal_to_host (oursig, &oursig_ok); | |
787 | return oursig_ok; | |
788 | } | |
789 | ||
790 | int | |
791 | target_signal_to_host (enum target_signal oursig) | |
792 | { | |
793 | int oursig_ok; | |
794 | int targ_signo = do_target_signal_to_host (oursig, &oursig_ok); | |
795 | if (!oursig_ok) | |
796 | { | |
797 | /* The user might be trying to do "signal SIGSAK" where this system | |
798 | doesn't have SIGSAK. */ | |
799 | warning ("Signal %s does not exist on this system.\n", | |
800 | target_signal_to_name (oursig)); | |
801 | return 0; | |
802 | } | |
803 | else | |
804 | return targ_signo; | |
805 | } | |
806 | ||
807 | /* In some circumstances we allow a command to specify a numeric | |
808 | signal. The idea is to keep these circumstances limited so that | |
809 | users (and scripts) develop portable habits. For comparison, | |
810 | POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a | |
811 | numeric signal at all is obsolescent. We are slightly more | |
812 | lenient and allow 1-15 which should match host signal numbers on | |
813 | most systems. Use of symbolic signal names is strongly encouraged. */ | |
814 | ||
815 | enum target_signal | |
816 | target_signal_from_command (int num) | |
817 | { | |
818 | if (num >= 1 && num <= 15) | |
819 | return (enum target_signal) num; | |
820 | error ("Only signals 1-15 are valid as numeric signals.\n\ | |
821 | Use \"info signals\" for a list of symbolic signals."); | |
822 | } | |
823 | ||
3130066b | 824 | #ifndef GDBSERVER |
0150732f DJ |
825 | void |
826 | _initialize_signals (void) | |
827 | { | |
3130066b | 828 | if (strcmp (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC") != 0) |
0150732f DJ |
829 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
830 | } | |
3130066b | 831 | #endif |