]>
Commit | Line | Data |
---|---|---|
0150732f | 1 | /* Target signal translation functions for GDB. |
8c719703 | 2 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
7b6bb8da | 3 | 2000, 2001, 2002, 2003, 2006, 2007, 2008, 2009, 2010, 2011 |
0fb0cc75 | 4 | Free Software Foundation, Inc. |
0150732f DJ |
5 | Contributed by Cygnus Support. |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
0150732f DJ |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
0150732f | 21 | |
3130066b DJ |
22 | #ifdef GDBSERVER |
23 | #include "server.h" | |
24 | #else | |
0150732f | 25 | #include "defs.h" |
309367d4 | 26 | #include "gdb_string.h" |
3130066b DJ |
27 | #endif |
28 | ||
68070c10 | 29 | #ifdef HAVE_SIGNAL_H |
0150732f | 30 | #include <signal.h> |
68070c10 | 31 | #endif |
0150732f | 32 | |
2aecd87f DE |
33 | #include "gdb_signals.h" |
34 | ||
1cded358 AR |
35 | struct gdbarch; |
36 | ||
960cb555 DJ |
37 | /* Always use __SIGRTMIN if it's available. SIGRTMIN is the lowest |
38 | _available_ realtime signal, not the lowest supported; glibc takes | |
39 | several for its own use. */ | |
40 | ||
41 | #ifndef REALTIME_LO | |
42 | # if defined(__SIGRTMIN) | |
43 | # define REALTIME_LO __SIGRTMIN | |
0b757755 | 44 | # define REALTIME_HI (__SIGRTMAX + 1) |
960cb555 | 45 | # elif defined(SIGRTMIN) |
bdd73e22 | 46 | # define REALTIME_LO SIGRTMIN |
0b757755 | 47 | # define REALTIME_HI (SIGRTMAX + 1) |
960cb555 DJ |
48 | # endif |
49 | #endif | |
50 | ||
a19cae16 JK |
51 | /* This table must match in order and size the signals in enum target_signal. */ |
52 | ||
54363045 DE |
53 | static const struct { |
54 | const char *name; | |
55 | const char *string; | |
0150732f DJ |
56 | } signals [] = |
57 | { | |
a6eb9bc8 | 58 | #define SET(symbol, constant, name, string) { name, string }, |
a19cae16 | 59 | #include "gdb/signals.def" |
a19cae16 | 60 | #undef SET |
0150732f | 61 | }; |
0150732f DJ |
62 | |
63 | ||
64 | /* Return the string for a signal. */ | |
54363045 | 65 | const char * |
0150732f DJ |
66 | target_signal_to_string (enum target_signal sig) |
67 | { | |
d5d6fca5 | 68 | if ((int) sig >= TARGET_SIGNAL_FIRST && (int) sig <= TARGET_SIGNAL_LAST) |
0150732f DJ |
69 | return signals[sig].string; |
70 | else | |
71 | return signals[TARGET_SIGNAL_UNKNOWN].string; | |
72 | } | |
73 | ||
74 | /* Return the name for a signal. */ | |
54363045 | 75 | const char * |
0150732f DJ |
76 | target_signal_to_name (enum target_signal sig) |
77 | { | |
d5d6fca5 | 78 | if ((int) sig >= TARGET_SIGNAL_FIRST && (int) sig <= TARGET_SIGNAL_LAST |
ade8f45e | 79 | && signals[sig].name != NULL) |
89c49e7a AC |
80 | return signals[sig].name; |
81 | else | |
ade8f45e AC |
82 | /* I think the code which prints this will always print it along |
83 | with the string, so no need to be verbose (very old comment). */ | |
84 | return "?"; | |
0150732f DJ |
85 | } |
86 | ||
87 | /* Given a name, return its signal. */ | |
88 | enum target_signal | |
54363045 | 89 | target_signal_from_name (const char *name) |
0150732f DJ |
90 | { |
91 | enum target_signal sig; | |
92 | ||
93 | /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD" | |
94 | for TARGET_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more | |
95 | questionable; seems like by now people should call it SIGABRT | |
96 | instead. */ | |
97 | ||
98 | /* This ugly cast brought to you by the native VAX compiler. */ | |
99 | for (sig = TARGET_SIGNAL_HUP; | |
fd326606 | 100 | sig < TARGET_SIGNAL_LAST; |
0150732f | 101 | sig = (enum target_signal) ((int) sig + 1)) |
fd326606 DJ |
102 | if (signals[sig].name != NULL |
103 | && strcmp (name, signals[sig].name) == 0) | |
0150732f DJ |
104 | return sig; |
105 | return TARGET_SIGNAL_UNKNOWN; | |
106 | } | |
107 | \f | |
108 | /* The following functions are to help certain targets deal | |
109 | with the signal/waitstatus stuff. They could just as well be in | |
110 | a file called native-utils.c or unixwaitstatus-utils.c or whatever. */ | |
111 | ||
112 | /* Convert host signal to our signals. */ | |
113 | enum target_signal | |
114 | target_signal_from_host (int hostsig) | |
115 | { | |
116 | /* A switch statement would make sense but would require special kludges | |
117 | to deal with the cases where more than one signal has the same number. */ | |
118 | ||
119 | if (hostsig == 0) | |
120 | return TARGET_SIGNAL_0; | |
121 | ||
122 | #if defined (SIGHUP) | |
123 | if (hostsig == SIGHUP) | |
124 | return TARGET_SIGNAL_HUP; | |
125 | #endif | |
126 | #if defined (SIGINT) | |
127 | if (hostsig == SIGINT) | |
128 | return TARGET_SIGNAL_INT; | |
129 | #endif | |
130 | #if defined (SIGQUIT) | |
131 | if (hostsig == SIGQUIT) | |
132 | return TARGET_SIGNAL_QUIT; | |
133 | #endif | |
134 | #if defined (SIGILL) | |
135 | if (hostsig == SIGILL) | |
136 | return TARGET_SIGNAL_ILL; | |
137 | #endif | |
138 | #if defined (SIGTRAP) | |
139 | if (hostsig == SIGTRAP) | |
140 | return TARGET_SIGNAL_TRAP; | |
141 | #endif | |
142 | #if defined (SIGABRT) | |
143 | if (hostsig == SIGABRT) | |
144 | return TARGET_SIGNAL_ABRT; | |
145 | #endif | |
146 | #if defined (SIGEMT) | |
147 | if (hostsig == SIGEMT) | |
148 | return TARGET_SIGNAL_EMT; | |
149 | #endif | |
150 | #if defined (SIGFPE) | |
151 | if (hostsig == SIGFPE) | |
152 | return TARGET_SIGNAL_FPE; | |
153 | #endif | |
154 | #if defined (SIGKILL) | |
155 | if (hostsig == SIGKILL) | |
156 | return TARGET_SIGNAL_KILL; | |
157 | #endif | |
158 | #if defined (SIGBUS) | |
159 | if (hostsig == SIGBUS) | |
160 | return TARGET_SIGNAL_BUS; | |
161 | #endif | |
162 | #if defined (SIGSEGV) | |
163 | if (hostsig == SIGSEGV) | |
164 | return TARGET_SIGNAL_SEGV; | |
165 | #endif | |
166 | #if defined (SIGSYS) | |
167 | if (hostsig == SIGSYS) | |
168 | return TARGET_SIGNAL_SYS; | |
169 | #endif | |
170 | #if defined (SIGPIPE) | |
171 | if (hostsig == SIGPIPE) | |
172 | return TARGET_SIGNAL_PIPE; | |
173 | #endif | |
174 | #if defined (SIGALRM) | |
175 | if (hostsig == SIGALRM) | |
176 | return TARGET_SIGNAL_ALRM; | |
177 | #endif | |
178 | #if defined (SIGTERM) | |
179 | if (hostsig == SIGTERM) | |
180 | return TARGET_SIGNAL_TERM; | |
181 | #endif | |
182 | #if defined (SIGUSR1) | |
183 | if (hostsig == SIGUSR1) | |
184 | return TARGET_SIGNAL_USR1; | |
185 | #endif | |
186 | #if defined (SIGUSR2) | |
187 | if (hostsig == SIGUSR2) | |
188 | return TARGET_SIGNAL_USR2; | |
189 | #endif | |
190 | #if defined (SIGCLD) | |
191 | if (hostsig == SIGCLD) | |
192 | return TARGET_SIGNAL_CHLD; | |
193 | #endif | |
194 | #if defined (SIGCHLD) | |
195 | if (hostsig == SIGCHLD) | |
196 | return TARGET_SIGNAL_CHLD; | |
197 | #endif | |
198 | #if defined (SIGPWR) | |
199 | if (hostsig == SIGPWR) | |
200 | return TARGET_SIGNAL_PWR; | |
201 | #endif | |
202 | #if defined (SIGWINCH) | |
203 | if (hostsig == SIGWINCH) | |
204 | return TARGET_SIGNAL_WINCH; | |
205 | #endif | |
206 | #if defined (SIGURG) | |
207 | if (hostsig == SIGURG) | |
208 | return TARGET_SIGNAL_URG; | |
209 | #endif | |
210 | #if defined (SIGIO) | |
211 | if (hostsig == SIGIO) | |
212 | return TARGET_SIGNAL_IO; | |
213 | #endif | |
214 | #if defined (SIGPOLL) | |
215 | if (hostsig == SIGPOLL) | |
216 | return TARGET_SIGNAL_POLL; | |
217 | #endif | |
218 | #if defined (SIGSTOP) | |
219 | if (hostsig == SIGSTOP) | |
220 | return TARGET_SIGNAL_STOP; | |
221 | #endif | |
222 | #if defined (SIGTSTP) | |
223 | if (hostsig == SIGTSTP) | |
224 | return TARGET_SIGNAL_TSTP; | |
225 | #endif | |
226 | #if defined (SIGCONT) | |
227 | if (hostsig == SIGCONT) | |
228 | return TARGET_SIGNAL_CONT; | |
229 | #endif | |
230 | #if defined (SIGTTIN) | |
231 | if (hostsig == SIGTTIN) | |
232 | return TARGET_SIGNAL_TTIN; | |
233 | #endif | |
234 | #if defined (SIGTTOU) | |
235 | if (hostsig == SIGTTOU) | |
236 | return TARGET_SIGNAL_TTOU; | |
237 | #endif | |
238 | #if defined (SIGVTALRM) | |
239 | if (hostsig == SIGVTALRM) | |
240 | return TARGET_SIGNAL_VTALRM; | |
241 | #endif | |
242 | #if defined (SIGPROF) | |
243 | if (hostsig == SIGPROF) | |
244 | return TARGET_SIGNAL_PROF; | |
245 | #endif | |
246 | #if defined (SIGXCPU) | |
247 | if (hostsig == SIGXCPU) | |
248 | return TARGET_SIGNAL_XCPU; | |
249 | #endif | |
250 | #if defined (SIGXFSZ) | |
251 | if (hostsig == SIGXFSZ) | |
252 | return TARGET_SIGNAL_XFSZ; | |
253 | #endif | |
254 | #if defined (SIGWIND) | |
255 | if (hostsig == SIGWIND) | |
256 | return TARGET_SIGNAL_WIND; | |
257 | #endif | |
258 | #if defined (SIGPHONE) | |
259 | if (hostsig == SIGPHONE) | |
260 | return TARGET_SIGNAL_PHONE; | |
261 | #endif | |
262 | #if defined (SIGLOST) | |
263 | if (hostsig == SIGLOST) | |
264 | return TARGET_SIGNAL_LOST; | |
265 | #endif | |
266 | #if defined (SIGWAITING) | |
267 | if (hostsig == SIGWAITING) | |
268 | return TARGET_SIGNAL_WAITING; | |
269 | #endif | |
270 | #if defined (SIGCANCEL) | |
271 | if (hostsig == SIGCANCEL) | |
272 | return TARGET_SIGNAL_CANCEL; | |
273 | #endif | |
274 | #if defined (SIGLWP) | |
275 | if (hostsig == SIGLWP) | |
276 | return TARGET_SIGNAL_LWP; | |
277 | #endif | |
278 | #if defined (SIGDANGER) | |
279 | if (hostsig == SIGDANGER) | |
280 | return TARGET_SIGNAL_DANGER; | |
281 | #endif | |
282 | #if defined (SIGGRANT) | |
283 | if (hostsig == SIGGRANT) | |
284 | return TARGET_SIGNAL_GRANT; | |
285 | #endif | |
286 | #if defined (SIGRETRACT) | |
287 | if (hostsig == SIGRETRACT) | |
288 | return TARGET_SIGNAL_RETRACT; | |
289 | #endif | |
290 | #if defined (SIGMSG) | |
291 | if (hostsig == SIGMSG) | |
292 | return TARGET_SIGNAL_MSG; | |
293 | #endif | |
294 | #if defined (SIGSOUND) | |
295 | if (hostsig == SIGSOUND) | |
296 | return TARGET_SIGNAL_SOUND; | |
297 | #endif | |
298 | #if defined (SIGSAK) | |
299 | if (hostsig == SIGSAK) | |
300 | return TARGET_SIGNAL_SAK; | |
301 | #endif | |
302 | #if defined (SIGPRIO) | |
303 | if (hostsig == SIGPRIO) | |
304 | return TARGET_SIGNAL_PRIO; | |
305 | #endif | |
306 | ||
307 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ | |
308 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) | |
309 | if (hostsig == _NSIG + EXC_BAD_ACCESS) | |
310 | return TARGET_EXC_BAD_ACCESS; | |
311 | #endif | |
312 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) | |
313 | if (hostsig == _NSIG + EXC_BAD_INSTRUCTION) | |
314 | return TARGET_EXC_BAD_INSTRUCTION; | |
315 | #endif | |
316 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) | |
317 | if (hostsig == _NSIG + EXC_ARITHMETIC) | |
318 | return TARGET_EXC_ARITHMETIC; | |
319 | #endif | |
320 | #if defined (EXC_EMULATION) && defined (_NSIG) | |
321 | if (hostsig == _NSIG + EXC_EMULATION) | |
322 | return TARGET_EXC_EMULATION; | |
323 | #endif | |
324 | #if defined (EXC_SOFTWARE) && defined (_NSIG) | |
325 | if (hostsig == _NSIG + EXC_SOFTWARE) | |
326 | return TARGET_EXC_SOFTWARE; | |
327 | #endif | |
328 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) | |
329 | if (hostsig == _NSIG + EXC_BREAKPOINT) | |
330 | return TARGET_EXC_BREAKPOINT; | |
331 | #endif | |
332 | ||
333 | #if defined (SIGINFO) | |
334 | if (hostsig == SIGINFO) | |
335 | return TARGET_SIGNAL_INFO; | |
336 | #endif | |
337 | ||
338 | #if defined (REALTIME_LO) | |
339 | if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI) | |
340 | { | |
341 | /* This block of TARGET_SIGNAL_REALTIME value is in order. */ | |
342 | if (33 <= hostsig && hostsig <= 63) | |
343 | return (enum target_signal) | |
344 | (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33); | |
345 | else if (hostsig == 32) | |
346 | return TARGET_SIGNAL_REALTIME_32; | |
347 | else if (64 <= hostsig && hostsig <= 127) | |
348 | return (enum target_signal) | |
349 | (hostsig - 64 + (int) TARGET_SIGNAL_REALTIME_64); | |
350 | else | |
351 | error ("GDB bug: target.c (target_signal_from_host): unrecognized real-time signal"); | |
352 | } | |
353 | #endif | |
354 | ||
0150732f DJ |
355 | return TARGET_SIGNAL_UNKNOWN; |
356 | } | |
357 | ||
358 | /* Convert a OURSIG (an enum target_signal) to the form used by the | |
359 | target operating system (refered to as the ``host'') or zero if the | |
360 | equivalent host signal is not available. Set/clear OURSIG_OK | |
361 | accordingly. */ | |
362 | ||
363 | static int | |
364 | do_target_signal_to_host (enum target_signal oursig, | |
365 | int *oursig_ok) | |
366 | { | |
f541410f | 367 | int retsig; |
68070c10 PA |
368 | /* Silence the 'not used' warning, for targets that |
369 | do not support signals. */ | |
370 | (void) retsig; | |
f541410f | 371 | |
0150732f DJ |
372 | *oursig_ok = 1; |
373 | switch (oursig) | |
374 | { | |
375 | case TARGET_SIGNAL_0: | |
376 | return 0; | |
377 | ||
378 | #if defined (SIGHUP) | |
379 | case TARGET_SIGNAL_HUP: | |
380 | return SIGHUP; | |
381 | #endif | |
382 | #if defined (SIGINT) | |
383 | case TARGET_SIGNAL_INT: | |
384 | return SIGINT; | |
385 | #endif | |
386 | #if defined (SIGQUIT) | |
387 | case TARGET_SIGNAL_QUIT: | |
388 | return SIGQUIT; | |
389 | #endif | |
390 | #if defined (SIGILL) | |
391 | case TARGET_SIGNAL_ILL: | |
392 | return SIGILL; | |
393 | #endif | |
394 | #if defined (SIGTRAP) | |
395 | case TARGET_SIGNAL_TRAP: | |
396 | return SIGTRAP; | |
397 | #endif | |
398 | #if defined (SIGABRT) | |
399 | case TARGET_SIGNAL_ABRT: | |
400 | return SIGABRT; | |
401 | #endif | |
402 | #if defined (SIGEMT) | |
403 | case TARGET_SIGNAL_EMT: | |
404 | return SIGEMT; | |
405 | #endif | |
406 | #if defined (SIGFPE) | |
407 | case TARGET_SIGNAL_FPE: | |
408 | return SIGFPE; | |
409 | #endif | |
410 | #if defined (SIGKILL) | |
411 | case TARGET_SIGNAL_KILL: | |
412 | return SIGKILL; | |
413 | #endif | |
414 | #if defined (SIGBUS) | |
415 | case TARGET_SIGNAL_BUS: | |
416 | return SIGBUS; | |
417 | #endif | |
418 | #if defined (SIGSEGV) | |
419 | case TARGET_SIGNAL_SEGV: | |
420 | return SIGSEGV; | |
421 | #endif | |
422 | #if defined (SIGSYS) | |
423 | case TARGET_SIGNAL_SYS: | |
424 | return SIGSYS; | |
425 | #endif | |
426 | #if defined (SIGPIPE) | |
427 | case TARGET_SIGNAL_PIPE: | |
428 | return SIGPIPE; | |
429 | #endif | |
430 | #if defined (SIGALRM) | |
431 | case TARGET_SIGNAL_ALRM: | |
432 | return SIGALRM; | |
433 | #endif | |
434 | #if defined (SIGTERM) | |
435 | case TARGET_SIGNAL_TERM: | |
436 | return SIGTERM; | |
437 | #endif | |
438 | #if defined (SIGUSR1) | |
439 | case TARGET_SIGNAL_USR1: | |
440 | return SIGUSR1; | |
441 | #endif | |
442 | #if defined (SIGUSR2) | |
443 | case TARGET_SIGNAL_USR2: | |
444 | return SIGUSR2; | |
445 | #endif | |
446 | #if defined (SIGCHLD) || defined (SIGCLD) | |
447 | case TARGET_SIGNAL_CHLD: | |
448 | #if defined (SIGCHLD) | |
449 | return SIGCHLD; | |
450 | #else | |
451 | return SIGCLD; | |
452 | #endif | |
453 | #endif /* SIGCLD or SIGCHLD */ | |
454 | #if defined (SIGPWR) | |
455 | case TARGET_SIGNAL_PWR: | |
456 | return SIGPWR; | |
457 | #endif | |
458 | #if defined (SIGWINCH) | |
459 | case TARGET_SIGNAL_WINCH: | |
460 | return SIGWINCH; | |
461 | #endif | |
462 | #if defined (SIGURG) | |
463 | case TARGET_SIGNAL_URG: | |
464 | return SIGURG; | |
465 | #endif | |
466 | #if defined (SIGIO) | |
467 | case TARGET_SIGNAL_IO: | |
468 | return SIGIO; | |
469 | #endif | |
470 | #if defined (SIGPOLL) | |
471 | case TARGET_SIGNAL_POLL: | |
472 | return SIGPOLL; | |
473 | #endif | |
474 | #if defined (SIGSTOP) | |
475 | case TARGET_SIGNAL_STOP: | |
476 | return SIGSTOP; | |
477 | #endif | |
478 | #if defined (SIGTSTP) | |
479 | case TARGET_SIGNAL_TSTP: | |
480 | return SIGTSTP; | |
481 | #endif | |
482 | #if defined (SIGCONT) | |
483 | case TARGET_SIGNAL_CONT: | |
484 | return SIGCONT; | |
485 | #endif | |
486 | #if defined (SIGTTIN) | |
487 | case TARGET_SIGNAL_TTIN: | |
488 | return SIGTTIN; | |
489 | #endif | |
490 | #if defined (SIGTTOU) | |
491 | case TARGET_SIGNAL_TTOU: | |
492 | return SIGTTOU; | |
493 | #endif | |
494 | #if defined (SIGVTALRM) | |
495 | case TARGET_SIGNAL_VTALRM: | |
496 | return SIGVTALRM; | |
497 | #endif | |
498 | #if defined (SIGPROF) | |
499 | case TARGET_SIGNAL_PROF: | |
500 | return SIGPROF; | |
501 | #endif | |
502 | #if defined (SIGXCPU) | |
503 | case TARGET_SIGNAL_XCPU: | |
504 | return SIGXCPU; | |
505 | #endif | |
506 | #if defined (SIGXFSZ) | |
507 | case TARGET_SIGNAL_XFSZ: | |
508 | return SIGXFSZ; | |
509 | #endif | |
510 | #if defined (SIGWIND) | |
511 | case TARGET_SIGNAL_WIND: | |
512 | return SIGWIND; | |
513 | #endif | |
514 | #if defined (SIGPHONE) | |
515 | case TARGET_SIGNAL_PHONE: | |
516 | return SIGPHONE; | |
517 | #endif | |
518 | #if defined (SIGLOST) | |
519 | case TARGET_SIGNAL_LOST: | |
520 | return SIGLOST; | |
521 | #endif | |
522 | #if defined (SIGWAITING) | |
523 | case TARGET_SIGNAL_WAITING: | |
524 | return SIGWAITING; | |
525 | #endif | |
526 | #if defined (SIGCANCEL) | |
527 | case TARGET_SIGNAL_CANCEL: | |
528 | return SIGCANCEL; | |
529 | #endif | |
530 | #if defined (SIGLWP) | |
531 | case TARGET_SIGNAL_LWP: | |
532 | return SIGLWP; | |
533 | #endif | |
534 | #if defined (SIGDANGER) | |
535 | case TARGET_SIGNAL_DANGER: | |
536 | return SIGDANGER; | |
537 | #endif | |
538 | #if defined (SIGGRANT) | |
539 | case TARGET_SIGNAL_GRANT: | |
540 | return SIGGRANT; | |
541 | #endif | |
542 | #if defined (SIGRETRACT) | |
543 | case TARGET_SIGNAL_RETRACT: | |
544 | return SIGRETRACT; | |
545 | #endif | |
546 | #if defined (SIGMSG) | |
547 | case TARGET_SIGNAL_MSG: | |
548 | return SIGMSG; | |
549 | #endif | |
550 | #if defined (SIGSOUND) | |
551 | case TARGET_SIGNAL_SOUND: | |
552 | return SIGSOUND; | |
553 | #endif | |
554 | #if defined (SIGSAK) | |
555 | case TARGET_SIGNAL_SAK: | |
556 | return SIGSAK; | |
557 | #endif | |
558 | #if defined (SIGPRIO) | |
559 | case TARGET_SIGNAL_PRIO: | |
560 | return SIGPRIO; | |
561 | #endif | |
562 | ||
563 | /* Mach exceptions. Assumes that the values for EXC_ are positive! */ | |
564 | #if defined (EXC_BAD_ACCESS) && defined (_NSIG) | |
565 | case TARGET_EXC_BAD_ACCESS: | |
566 | return _NSIG + EXC_BAD_ACCESS; | |
567 | #endif | |
568 | #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) | |
569 | case TARGET_EXC_BAD_INSTRUCTION: | |
570 | return _NSIG + EXC_BAD_INSTRUCTION; | |
571 | #endif | |
572 | #if defined (EXC_ARITHMETIC) && defined (_NSIG) | |
573 | case TARGET_EXC_ARITHMETIC: | |
574 | return _NSIG + EXC_ARITHMETIC; | |
575 | #endif | |
576 | #if defined (EXC_EMULATION) && defined (_NSIG) | |
577 | case TARGET_EXC_EMULATION: | |
578 | return _NSIG + EXC_EMULATION; | |
579 | #endif | |
580 | #if defined (EXC_SOFTWARE) && defined (_NSIG) | |
581 | case TARGET_EXC_SOFTWARE: | |
582 | return _NSIG + EXC_SOFTWARE; | |
583 | #endif | |
584 | #if defined (EXC_BREAKPOINT) && defined (_NSIG) | |
585 | case TARGET_EXC_BREAKPOINT: | |
586 | return _NSIG + EXC_BREAKPOINT; | |
587 | #endif | |
588 | ||
589 | #if defined (SIGINFO) | |
590 | case TARGET_SIGNAL_INFO: | |
591 | return SIGINFO; | |
592 | #endif | |
593 | ||
594 | default: | |
595 | #if defined (REALTIME_LO) | |
f541410f | 596 | retsig = 0; |
0150732f | 597 | |
0150732f DJ |
598 | if (oursig >= TARGET_SIGNAL_REALTIME_33 |
599 | && oursig <= TARGET_SIGNAL_REALTIME_63) | |
600 | { | |
601 | /* This block of signals is continuous, and | |
602 | TARGET_SIGNAL_REALTIME_33 is 33 by definition. */ | |
f541410f | 603 | retsig = (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33; |
0150732f | 604 | } |
2f2cf184 DJ |
605 | else if (oursig == TARGET_SIGNAL_REALTIME_32) |
606 | { | |
607 | /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with | |
608 | TARGET_SIGNAL_REALTIME_33. It is 32 by definition. */ | |
f541410f | 609 | retsig = 32; |
2f2cf184 DJ |
610 | } |
611 | else if (oursig >= TARGET_SIGNAL_REALTIME_64 | |
612 | && oursig <= TARGET_SIGNAL_REALTIME_127) | |
613 | { | |
614 | /* This block of signals is continuous, and | |
615 | TARGET_SIGNAL_REALTIME_64 is 64 by definition. */ | |
f541410f | 616 | retsig = (int) oursig - (int) TARGET_SIGNAL_REALTIME_64 + 64; |
2f2cf184 | 617 | } |
f541410f DJ |
618 | |
619 | if (retsig >= REALTIME_LO && retsig < REALTIME_HI) | |
620 | return retsig; | |
0150732f | 621 | #endif |
960cb555 | 622 | |
0150732f DJ |
623 | *oursig_ok = 0; |
624 | return 0; | |
625 | } | |
626 | } | |
627 | ||
628 | int | |
629 | target_signal_to_host_p (enum target_signal oursig) | |
630 | { | |
631 | int oursig_ok; | |
632 | do_target_signal_to_host (oursig, &oursig_ok); | |
633 | return oursig_ok; | |
634 | } | |
635 | ||
636 | int | |
637 | target_signal_to_host (enum target_signal oursig) | |
638 | { | |
639 | int oursig_ok; | |
640 | int targ_signo = do_target_signal_to_host (oursig, &oursig_ok); | |
641 | if (!oursig_ok) | |
642 | { | |
643 | /* The user might be trying to do "signal SIGSAK" where this system | |
644 | doesn't have SIGSAK. */ | |
645 | warning ("Signal %s does not exist on this system.\n", | |
646 | target_signal_to_name (oursig)); | |
647 | return 0; | |
648 | } | |
649 | else | |
650 | return targ_signo; | |
651 | } | |
652 | ||
2aecd87f DE |
653 | #ifndef GDBSERVER |
654 | ||
0150732f DJ |
655 | /* In some circumstances we allow a command to specify a numeric |
656 | signal. The idea is to keep these circumstances limited so that | |
657 | users (and scripts) develop portable habits. For comparison, | |
658 | POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a | |
659 | numeric signal at all is obsolescent. We are slightly more | |
660 | lenient and allow 1-15 which should match host signal numbers on | |
661 | most systems. Use of symbolic signal names is strongly encouraged. */ | |
662 | ||
663 | enum target_signal | |
664 | target_signal_from_command (int num) | |
665 | { | |
666 | if (num >= 1 && num <= 15) | |
667 | return (enum target_signal) num; | |
668 | error ("Only signals 1-15 are valid as numeric signals.\n\ | |
669 | Use \"info signals\" for a list of symbolic signals."); | |
670 | } | |
671 | ||
b9362cc7 AC |
672 | extern initialize_file_ftype _initialize_signals; /* -Wmissing-prototype */ |
673 | ||
0150732f DJ |
674 | void |
675 | _initialize_signals (void) | |
676 | { | |
3130066b | 677 | if (strcmp (signals[TARGET_SIGNAL_LAST].string, "TARGET_SIGNAL_MAGIC") != 0) |
0150732f DJ |
678 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
679 | } | |
1cded358 AR |
680 | |
681 | int | |
682 | default_target_signal_to_host (struct gdbarch *gdbarch, enum target_signal ts) | |
683 | { | |
684 | return target_signal_to_host (ts); | |
685 | } | |
686 | ||
687 | enum target_signal | |
688 | default_target_signal_from_host (struct gdbarch *gdbarch, int signo) | |
689 | { | |
690 | return target_signal_from_host (signo); | |
691 | } | |
2aecd87f DE |
692 | |
693 | #endif /* ! GDBSERVER */ |