• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 (const 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    const char *name;
41    const 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.  */
target_signal_to_name(enum target_signal sig)208 const 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.  */
target_signal_from_name(const char * name)220 enum target_signal target_signal_from_name (const 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.  */
target_signal_from_host(int hostsig)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 #if defined (VKI_SIGRTMIN)
470    if (hostsig >= VKI_SIGRTMIN && hostsig < VKI_SIGRTMAX) {
471       /* This block of TARGET_SIGNAL_REALTIME value is in order.  */
472       if (33 <= hostsig && hostsig <= 63)
473          return (enum target_signal)
474             (hostsig - 33 + (int) TARGET_SIGNAL_REALTIME_33);
475       else if (hostsig == 32)
476          return TARGET_SIGNAL_REALTIME_32;
477       else if (64 <= hostsig && hostsig <= 127)
478          return (enum target_signal)
479             (hostsig - 64 + (int) TARGET_SIGNAL_REALTIME_64);
480    }
481 #endif
482 
483    error ("Valgrind GDBSERVER bug: (target_signal_from_host):"
484           " unrecognized vki signal %d\n", hostsig);
485    return TARGET_SIGNAL_UNKNOWN;
486 }
487 
488 /* Convert a OURSIG (an enum target_signal) to the form used by the
489    target operating system (referred to as the ``host'') or zero if the
490    equivalent host signal is not available.  Set/clear OURSIG_OK
491    accordingly. */
492 
493 static
do_target_signal_to_host(enum target_signal oursig,int * oursig_ok)494 int do_target_signal_to_host (enum target_signal oursig,
495                               int *oursig_ok)
496 {
497    *oursig_ok = 1;
498    switch (oursig) {
499    case TARGET_SIGNAL_0:
500       return 0;
501 
502 #if defined (VKI_SIGHUP)
503    case TARGET_SIGNAL_HUP:
504       return VKI_SIGHUP;
505 #endif
506 #if defined (VKI_SIGINT)
507    case TARGET_SIGNAL_INT:
508       return VKI_SIGINT;
509 #endif
510 #if defined (VKI_SIGQUIT)
511    case TARGET_SIGNAL_QUIT:
512       return VKI_SIGQUIT;
513 #endif
514 #if defined (VKI_SIGILL)
515    case TARGET_SIGNAL_ILL:
516       return VKI_SIGILL;
517 #endif
518 #if defined (VKI_SIGTRAP)
519    case TARGET_SIGNAL_TRAP:
520       return VKI_SIGTRAP;
521 #endif
522 #if defined (VKI_SIGABRT)
523    case TARGET_SIGNAL_ABRT:
524       return VKI_SIGABRT;
525 #endif
526 #if defined (VKI_SIGEMT)
527    case TARGET_SIGNAL_EMT:
528       return VKI_SIGEMT;
529 #endif
530 #if defined (VKI_SIGFPE)
531    case TARGET_SIGNAL_FPE:
532       return VKI_SIGFPE;
533 #endif
534 #if defined (VKI_SIGKILL)
535    case TARGET_SIGNAL_KILL:
536       return VKI_SIGKILL;
537 #endif
538 #if defined (VKI_SIGBUS)
539    case TARGET_SIGNAL_BUS:
540       return VKI_SIGBUS;
541 #endif
542 #if defined (VKI_SIGSEGV)
543    case TARGET_SIGNAL_SEGV:
544       return VKI_SIGSEGV;
545 #endif
546 #if defined (VKI_SIGSYS)
547    case TARGET_SIGNAL_SYS:
548       return VKI_SIGSYS;
549 #endif
550 #if defined (VKI_SIGPIPE)
551    case TARGET_SIGNAL_PIPE:
552       return VKI_SIGPIPE;
553 #endif
554 #if defined (VKI_SIGALRM)
555    case TARGET_SIGNAL_ALRM:
556       return VKI_SIGALRM;
557 #endif
558 #if defined (VKI_SIGTERM)
559    case TARGET_SIGNAL_TERM:
560       return VKI_SIGTERM;
561 #endif
562 #if defined (VKI_SIGUSR1)
563    case TARGET_SIGNAL_USR1:
564       return VKI_SIGUSR1;
565 #endif
566 #if defined (VKI_SIGUSR2)
567    case TARGET_SIGNAL_USR2:
568       return VKI_SIGUSR2;
569 #endif
570 #if defined (VKI_SIGCHLD) || defined (VKI_SIGCLD)
571    case TARGET_SIGNAL_CHLD:
572 #if defined (VKI_SIGCHLD)
573       return VKI_SIGCHLD;
574 #else
575       return VKI_SIGCLD;
576 #endif
577 #endif /* SIGCLD or SIGCHLD */
578 #if defined (VKI_SIGPWR)
579    case TARGET_SIGNAL_PWR:
580       return VKI_SIGPWR;
581 #endif
582 #if defined (VKI_SIGWINCH)
583    case TARGET_SIGNAL_WINCH:
584       return VKI_SIGWINCH;
585 #endif
586 #if defined (VKI_SIGURG)
587    case TARGET_SIGNAL_URG:
588       return VKI_SIGURG;
589 #endif
590 #if defined (VKI_SIGIO)
591    case TARGET_SIGNAL_IO:
592       return VKI_SIGIO;
593 #endif
594 #if defined (VKI_SIGPOLL)
595    case TARGET_SIGNAL_POLL:
596       return VKI_SIGPOLL;
597 #endif
598 #if defined (VKI_SIGSTOP)
599    case TARGET_SIGNAL_STOP:
600       return VKI_SIGSTOP;
601 #endif
602 #if defined (VKI_SIGTSTP)
603    case TARGET_SIGNAL_TSTP:
604       return VKI_SIGTSTP;
605 #endif
606 #if defined (VKI_SIGCONT)
607    case TARGET_SIGNAL_CONT:
608       return VKI_SIGCONT;
609 #endif
610 #if defined (VKI_SIGTTIN)
611    case TARGET_SIGNAL_TTIN:
612       return VKI_SIGTTIN;
613 #endif
614 #if defined (VKI_SIGTTOU)
615    case TARGET_SIGNAL_TTOU:
616       return VKI_SIGTTOU;
617 #endif
618 #if defined (VKI_SIGVTALRM)
619    case TARGET_SIGNAL_VTALRM:
620       return VKI_SIGVTALRM;
621 #endif
622 #if defined (VKI_SIGPROF)
623    case TARGET_SIGNAL_PROF:
624       return VKI_SIGPROF;
625 #endif
626 #if defined (VKI_SIGXCPU)
627    case TARGET_SIGNAL_XCPU:
628       return VKI_SIGXCPU;
629 #endif
630 #if defined (VKI_SIGXFSZ)
631    case TARGET_SIGNAL_XFSZ:
632       return VKI_SIGXFSZ;
633 #endif
634 #if defined (VKI_SIGWIND)
635    case TARGET_SIGNAL_WIND:
636       return VKI_SIGWIND;
637 #endif
638 #if defined (VKI_SIGPHONE)
639    case TARGET_SIGNAL_PHONE:
640       return VKI_SIGPHONE;
641 #endif
642 #if defined (VKI_SIGLOST)
643    case TARGET_SIGNAL_LOST:
644       return VKI_SIGLOST;
645 #endif
646 #if defined (VKI_SIGWAITING)
647    case TARGET_SIGNAL_WAITING:
648       return VKI_SIGWAITING;
649 #endif
650 #if defined (VKI_SIGCANCEL)
651    case TARGET_SIGNAL_CANCEL:
652       return VKI_SIGCANCEL;
653 #endif
654 #if defined (VKI_SIGLWP)
655    case TARGET_SIGNAL_LWP:
656       return VKI_SIGLWP;
657 #endif
658 #if defined (VKI_SIGDANGER)
659    case TARGET_SIGNAL_DANGER:
660       return VKI_SIGDANGER;
661 #endif
662 #if defined (VKI_SIGGRANT)
663    case TARGET_SIGNAL_GRANT:
664       return VKI_SIGGRANT;
665 #endif
666 #if defined (VKI_SIGRETRACT)
667    case TARGET_SIGNAL_RETRACT:
668       return VKI_SIGRETRACT;
669 #endif
670 #if defined (VKI_SIGMSG)
671    case TARGET_SIGNAL_MSG:
672       return VKI_SIGMSG;
673 #endif
674 #if defined (VKI_SIGSOUND)
675    case TARGET_SIGNAL_SOUND:
676       return VKI_SIGSOUND;
677 #endif
678 #if defined (VKI_SIGSAK)
679    case TARGET_SIGNAL_SAK:
680       return VKI_SIGSAK;
681 #endif
682 #if defined (VKI_SIGPRIO)
683    case TARGET_SIGNAL_PRIO:
684       return VKI_SIGPRIO;
685 #endif
686 
687       /* Mach exceptions.  Assumes that the values for EXC_ are positive! */
688 #if defined (EXC_BAD_ACCESS) && defined (_NSIG)
689    case TARGET_EXC_BAD_ACCESS:
690       return _NSIG + EXC_BAD_ACCESS;
691 #endif
692 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG)
693    case TARGET_EXC_BAD_INSTRUCTION:
694       return _NSIG + EXC_BAD_INSTRUCTION;
695 #endif
696 #if defined (EXC_ARITHMETIC) && defined (_NSIG)
697    case TARGET_EXC_ARITHMETIC:
698       return _NSIG + EXC_ARITHMETIC;
699 #endif
700 #if defined (EXC_EMULATION) && defined (_NSIG)
701    case TARGET_EXC_EMULATION:
702       return _NSIG + EXC_EMULATION;
703 #endif
704 #if defined (EXC_SOFTWARE) && defined (_NSIG)
705    case TARGET_EXC_SOFTWARE:
706       return _NSIG + EXC_SOFTWARE;
707 #endif
708 #if defined (EXC_BREAKPOINT) && defined (_NSIG)
709    case TARGET_EXC_BREAKPOINT:
710       return _NSIG + EXC_BREAKPOINT;
711 #endif
712 
713 #if defined (VKI_SIGINFO)
714    case TARGET_SIGNAL_INFO:
715       return VKI_SIGINFO;
716 #endif
717 
718    default:
719 #if defined (VKI_SIGRTMIN)
720       {
721          int retsig = 0;
722 
723          if (oursig >= TARGET_SIGNAL_REALTIME_33
724              && oursig <= TARGET_SIGNAL_REALTIME_63) {
725             /* This block of signals is continuous, and
726                TARGET_SIGNAL_REALTIME_33 is 33 by definition.  */
727             retsig = (int) oursig - (int) TARGET_SIGNAL_REALTIME_33 + 33;
728          } else if (oursig == TARGET_SIGNAL_REALTIME_32) {
729             /* TARGET_SIGNAL_REALTIME_32 isn't contiguous with
730                TARGET_SIGNAL_REALTIME_33.  It is 32 by definition.  */
731             retsig = 32;
732          } else if (oursig >= TARGET_SIGNAL_REALTIME_64
733                     && oursig <= TARGET_SIGNAL_REALTIME_127) {
734             /* This block of signals is continuous, and
735                TARGET_SIGNAL_REALTIME_64 is 64 by definition.  */
736             retsig = (int) oursig - (int) TARGET_SIGNAL_REALTIME_64 + 64;
737          }
738 
739          if (retsig >= VKI_SIGRTMIN && retsig < VKI_SIGRTMAX)
740             return retsig;
741       }
742 #endif
743       error ("Valgrind GDBSERVER bug: (do_target_signal_to_host):"
744              " unrecognized target signal %u\n", oursig);
745       *oursig_ok = 0;
746       return 0;
747    }
748 }
749 
target_signal_to_host_p(enum target_signal oursig)750 int target_signal_to_host_p (enum target_signal oursig)
751 {
752    int oursig_ok;
753    do_target_signal_to_host (oursig, &oursig_ok);
754    return oursig_ok;
755 }
756 
target_signal_to_host(enum target_signal oursig)757 int target_signal_to_host (enum target_signal oursig)
758 {
759    int oursig_ok;
760    int targ_signo = do_target_signal_to_host (oursig, &oursig_ok);
761    if (!oursig_ok) {
762       /* The user might be trying to do "signal SIGSAK" where this system
763          doesn't have SIGSAK.  */
764       warning ("Signal %s does not exist on this system.\n",
765                target_signal_to_name (oursig));
766       return 0;
767    } else {
768       return targ_signo;
769    }
770 }
771 
772 /* In some circumstances we allow a command to specify a numeric
773    signal.  The idea is to keep these circumstances limited so that
774    users (and scripts) develop portable habits.  For comparison,
775    POSIX.2 `kill' requires that 1,2,3,6,9,14, and 15 work (and using a
776    numeric signal at all is obsolescent.  We are slightly more
777    lenient and allow 1-15 which should match host signal numbers on
778    most systems.  Use of symbolic signal names is strongly encouraged.  */
779 
target_signal_from_command(int num)780 enum target_signal target_signal_from_command (int num)
781 {
782    if (num >= 1 && num <= 15)
783       return (enum target_signal) num;
784    error ("Only signals 1-15 are valid as numeric signals.\n\
785 Use \"info signals\" for a list of symbolic signals.\n");
786 }
787