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