GDB (API)
|
00001 /* Target signal translation functions for GDB. 00002 Copyright (C) 1990-2013 Free Software Foundation, Inc. 00003 Contributed by Cygnus Support. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #ifdef GDBSERVER 00021 #include "server.h" 00022 #else 00023 #include "defs.h" 00024 #include "gdb_string.h" 00025 #endif 00026 00027 #ifdef HAVE_SIGNAL_H 00028 #include <signal.h> 00029 #endif 00030 00031 #include "gdb_signals.h" 00032 00033 struct gdbarch; 00034 00035 /* Always use __SIGRTMIN if it's available. SIGRTMIN is the lowest 00036 _available_ realtime signal, not the lowest supported; glibc takes 00037 several for its own use. */ 00038 00039 #ifndef REALTIME_LO 00040 # if defined(__SIGRTMIN) 00041 # define REALTIME_LO __SIGRTMIN 00042 # define REALTIME_HI (__SIGRTMAX + 1) 00043 # elif defined(SIGRTMIN) 00044 # define REALTIME_LO SIGRTMIN 00045 # define REALTIME_HI (SIGRTMAX + 1) 00046 # endif 00047 #endif 00048 00049 /* This table must match in order and size the signals in enum 00050 gdb_signal. */ 00051 00052 static const struct { 00053 const char *name; 00054 const char *string; 00055 } signals [] = 00056 { 00057 #define SET(symbol, constant, name, string) { name, string }, 00058 #include "gdb/signals.def" 00059 #undef SET 00060 }; 00061 00062 00063 /* Return the string for a signal. */ 00064 const char * 00065 gdb_signal_to_string (enum gdb_signal sig) 00066 { 00067 if ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST) 00068 return signals[sig].string; 00069 else 00070 return signals[GDB_SIGNAL_UNKNOWN].string; 00071 } 00072 00073 /* Return the name for a signal. */ 00074 const char * 00075 gdb_signal_to_name (enum gdb_signal sig) 00076 { 00077 if ((int) sig >= GDB_SIGNAL_FIRST && (int) sig <= GDB_SIGNAL_LAST 00078 && signals[sig].name != NULL) 00079 return signals[sig].name; 00080 else 00081 /* I think the code which prints this will always print it along 00082 with the string, so no need to be verbose (very old comment). */ 00083 return "?"; 00084 } 00085 00086 /* Given a name, return its signal. */ 00087 enum gdb_signal 00088 gdb_signal_from_name (const char *name) 00089 { 00090 enum gdb_signal sig; 00091 00092 /* It's possible we also should allow "SIGCLD" as well as "SIGCHLD" 00093 for GDB_SIGNAL_SIGCHLD. SIGIOT, on the other hand, is more 00094 questionable; seems like by now people should call it SIGABRT 00095 instead. */ 00096 00097 /* This ugly cast brought to you by the native VAX compiler. */ 00098 for (sig = GDB_SIGNAL_HUP; 00099 sig < GDB_SIGNAL_LAST; 00100 sig = (enum gdb_signal) ((int) sig + 1)) 00101 if (signals[sig].name != NULL 00102 && strcmp (name, signals[sig].name) == 0) 00103 return sig; 00104 return GDB_SIGNAL_UNKNOWN; 00105 } 00106 00107 /* The following functions are to help certain targets deal 00108 with the signal/waitstatus stuff. They could just as well be in 00109 a file called native-utils.c or unixwaitstatus-utils.c or whatever. */ 00110 00111 /* Convert host signal to our signals. */ 00112 enum gdb_signal 00113 gdb_signal_from_host (int hostsig) 00114 { 00115 /* A switch statement would make sense but would require special kludges 00116 to deal with the cases where more than one signal has the same number. */ 00117 00118 if (hostsig == 0) 00119 return GDB_SIGNAL_0; 00120 00121 #if defined (SIGHUP) 00122 if (hostsig == SIGHUP) 00123 return GDB_SIGNAL_HUP; 00124 #endif 00125 #if defined (SIGINT) 00126 if (hostsig == SIGINT) 00127 return GDB_SIGNAL_INT; 00128 #endif 00129 #if defined (SIGQUIT) 00130 if (hostsig == SIGQUIT) 00131 return GDB_SIGNAL_QUIT; 00132 #endif 00133 #if defined (SIGILL) 00134 if (hostsig == SIGILL) 00135 return GDB_SIGNAL_ILL; 00136 #endif 00137 #if defined (SIGTRAP) 00138 if (hostsig == SIGTRAP) 00139 return GDB_SIGNAL_TRAP; 00140 #endif 00141 #if defined (SIGABRT) 00142 if (hostsig == SIGABRT) 00143 return GDB_SIGNAL_ABRT; 00144 #endif 00145 #if defined (SIGEMT) 00146 if (hostsig == SIGEMT) 00147 return GDB_SIGNAL_EMT; 00148 #endif 00149 #if defined (SIGFPE) 00150 if (hostsig == SIGFPE) 00151 return GDB_SIGNAL_FPE; 00152 #endif 00153 #if defined (SIGKILL) 00154 if (hostsig == SIGKILL) 00155 return GDB_SIGNAL_KILL; 00156 #endif 00157 #if defined (SIGBUS) 00158 if (hostsig == SIGBUS) 00159 return GDB_SIGNAL_BUS; 00160 #endif 00161 #if defined (SIGSEGV) 00162 if (hostsig == SIGSEGV) 00163 return GDB_SIGNAL_SEGV; 00164 #endif 00165 #if defined (SIGSYS) 00166 if (hostsig == SIGSYS) 00167 return GDB_SIGNAL_SYS; 00168 #endif 00169 #if defined (SIGPIPE) 00170 if (hostsig == SIGPIPE) 00171 return GDB_SIGNAL_PIPE; 00172 #endif 00173 #if defined (SIGALRM) 00174 if (hostsig == SIGALRM) 00175 return GDB_SIGNAL_ALRM; 00176 #endif 00177 #if defined (SIGTERM) 00178 if (hostsig == SIGTERM) 00179 return GDB_SIGNAL_TERM; 00180 #endif 00181 #if defined (SIGUSR1) 00182 if (hostsig == SIGUSR1) 00183 return GDB_SIGNAL_USR1; 00184 #endif 00185 #if defined (SIGUSR2) 00186 if (hostsig == SIGUSR2) 00187 return GDB_SIGNAL_USR2; 00188 #endif 00189 #if defined (SIGCLD) 00190 if (hostsig == SIGCLD) 00191 return GDB_SIGNAL_CHLD; 00192 #endif 00193 #if defined (SIGCHLD) 00194 if (hostsig == SIGCHLD) 00195 return GDB_SIGNAL_CHLD; 00196 #endif 00197 #if defined (SIGPWR) 00198 if (hostsig == SIGPWR) 00199 return GDB_SIGNAL_PWR; 00200 #endif 00201 #if defined (SIGWINCH) 00202 if (hostsig == SIGWINCH) 00203 return GDB_SIGNAL_WINCH; 00204 #endif 00205 #if defined (SIGURG) 00206 if (hostsig == SIGURG) 00207 return GDB_SIGNAL_URG; 00208 #endif 00209 #if defined (SIGIO) 00210 if (hostsig == SIGIO) 00211 return GDB_SIGNAL_IO; 00212 #endif 00213 #if defined (SIGPOLL) 00214 if (hostsig == SIGPOLL) 00215 return GDB_SIGNAL_POLL; 00216 #endif 00217 #if defined (SIGSTOP) 00218 if (hostsig == SIGSTOP) 00219 return GDB_SIGNAL_STOP; 00220 #endif 00221 #if defined (SIGTSTP) 00222 if (hostsig == SIGTSTP) 00223 return GDB_SIGNAL_TSTP; 00224 #endif 00225 #if defined (SIGCONT) 00226 if (hostsig == SIGCONT) 00227 return GDB_SIGNAL_CONT; 00228 #endif 00229 #if defined (SIGTTIN) 00230 if (hostsig == SIGTTIN) 00231 return GDB_SIGNAL_TTIN; 00232 #endif 00233 #if defined (SIGTTOU) 00234 if (hostsig == SIGTTOU) 00235 return GDB_SIGNAL_TTOU; 00236 #endif 00237 #if defined (SIGVTALRM) 00238 if (hostsig == SIGVTALRM) 00239 return GDB_SIGNAL_VTALRM; 00240 #endif 00241 #if defined (SIGPROF) 00242 if (hostsig == SIGPROF) 00243 return GDB_SIGNAL_PROF; 00244 #endif 00245 #if defined (SIGXCPU) 00246 if (hostsig == SIGXCPU) 00247 return GDB_SIGNAL_XCPU; 00248 #endif 00249 #if defined (SIGXFSZ) 00250 if (hostsig == SIGXFSZ) 00251 return GDB_SIGNAL_XFSZ; 00252 #endif 00253 #if defined (SIGWIND) 00254 if (hostsig == SIGWIND) 00255 return GDB_SIGNAL_WIND; 00256 #endif 00257 #if defined (SIGPHONE) 00258 if (hostsig == SIGPHONE) 00259 return GDB_SIGNAL_PHONE; 00260 #endif 00261 #if defined (SIGLOST) 00262 if (hostsig == SIGLOST) 00263 return GDB_SIGNAL_LOST; 00264 #endif 00265 #if defined (SIGWAITING) 00266 if (hostsig == SIGWAITING) 00267 return GDB_SIGNAL_WAITING; 00268 #endif 00269 #if defined (SIGCANCEL) 00270 if (hostsig == SIGCANCEL) 00271 return GDB_SIGNAL_CANCEL; 00272 #endif 00273 #if defined (SIGLWP) 00274 if (hostsig == SIGLWP) 00275 return GDB_SIGNAL_LWP; 00276 #endif 00277 #if defined (SIGDANGER) 00278 if (hostsig == SIGDANGER) 00279 return GDB_SIGNAL_DANGER; 00280 #endif 00281 #if defined (SIGGRANT) 00282 if (hostsig == SIGGRANT) 00283 return GDB_SIGNAL_GRANT; 00284 #endif 00285 #if defined (SIGRETRACT) 00286 if (hostsig == SIGRETRACT) 00287 return GDB_SIGNAL_RETRACT; 00288 #endif 00289 #if defined (SIGMSG) 00290 if (hostsig == SIGMSG) 00291 return GDB_SIGNAL_MSG; 00292 #endif 00293 #if defined (SIGSOUND) 00294 if (hostsig == SIGSOUND) 00295 return GDB_SIGNAL_SOUND; 00296 #endif 00297 #if defined (SIGSAK) 00298 if (hostsig == SIGSAK) 00299 return GDB_SIGNAL_SAK; 00300 #endif 00301 #if defined (SIGPRIO) 00302 if (hostsig == SIGPRIO) 00303 return GDB_SIGNAL_PRIO; 00304 #endif 00305 00306 /* Mach exceptions. Assumes that the values for EXC_ are positive! */ 00307 #if defined (EXC_BAD_ACCESS) && defined (_NSIG) 00308 if (hostsig == _NSIG + EXC_BAD_ACCESS) 00309 return TARGET_EXC_BAD_ACCESS; 00310 #endif 00311 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) 00312 if (hostsig == _NSIG + EXC_BAD_INSTRUCTION) 00313 return TARGET_EXC_BAD_INSTRUCTION; 00314 #endif 00315 #if defined (EXC_ARITHMETIC) && defined (_NSIG) 00316 if (hostsig == _NSIG + EXC_ARITHMETIC) 00317 return TARGET_EXC_ARITHMETIC; 00318 #endif 00319 #if defined (EXC_EMULATION) && defined (_NSIG) 00320 if (hostsig == _NSIG + EXC_EMULATION) 00321 return TARGET_EXC_EMULATION; 00322 #endif 00323 #if defined (EXC_SOFTWARE) && defined (_NSIG) 00324 if (hostsig == _NSIG + EXC_SOFTWARE) 00325 return TARGET_EXC_SOFTWARE; 00326 #endif 00327 #if defined (EXC_BREAKPOINT) && defined (_NSIG) 00328 if (hostsig == _NSIG + EXC_BREAKPOINT) 00329 return TARGET_EXC_BREAKPOINT; 00330 #endif 00331 00332 #if defined (SIGINFO) 00333 if (hostsig == SIGINFO) 00334 return GDB_SIGNAL_INFO; 00335 #endif 00336 00337 #if defined (REALTIME_LO) 00338 if (hostsig >= REALTIME_LO && hostsig < REALTIME_HI) 00339 { 00340 /* This block of GDB_SIGNAL_REALTIME value is in order. */ 00341 if (33 <= hostsig && hostsig <= 63) 00342 return (enum gdb_signal) 00343 (hostsig - 33 + (int) GDB_SIGNAL_REALTIME_33); 00344 else if (hostsig == 32) 00345 return GDB_SIGNAL_REALTIME_32; 00346 else if (64 <= hostsig && hostsig <= 127) 00347 return (enum gdb_signal) 00348 (hostsig - 64 + (int) GDB_SIGNAL_REALTIME_64); 00349 else 00350 error (_("GDB bug: target.c (gdb_signal_from_host): " 00351 "unrecognized real-time signal")); 00352 } 00353 #endif 00354 00355 return GDB_SIGNAL_UNKNOWN; 00356 } 00357 00358 /* Convert a OURSIG (an enum gdb_signal) to the form used by the 00359 target operating system (refered to as the ``host'') or zero if the 00360 equivalent host signal is not available. Set/clear OURSIG_OK 00361 accordingly. */ 00362 00363 static int 00364 do_gdb_signal_to_host (enum gdb_signal oursig, 00365 int *oursig_ok) 00366 { 00367 int retsig; 00368 /* Silence the 'not used' warning, for targets that 00369 do not support signals. */ 00370 (void) retsig; 00371 00372 *oursig_ok = 1; 00373 switch (oursig) 00374 { 00375 case GDB_SIGNAL_0: 00376 return 0; 00377 00378 #if defined (SIGHUP) 00379 case GDB_SIGNAL_HUP: 00380 return SIGHUP; 00381 #endif 00382 #if defined (SIGINT) 00383 case GDB_SIGNAL_INT: 00384 return SIGINT; 00385 #endif 00386 #if defined (SIGQUIT) 00387 case GDB_SIGNAL_QUIT: 00388 return SIGQUIT; 00389 #endif 00390 #if defined (SIGILL) 00391 case GDB_SIGNAL_ILL: 00392 return SIGILL; 00393 #endif 00394 #if defined (SIGTRAP) 00395 case GDB_SIGNAL_TRAP: 00396 return SIGTRAP; 00397 #endif 00398 #if defined (SIGABRT) 00399 case GDB_SIGNAL_ABRT: 00400 return SIGABRT; 00401 #endif 00402 #if defined (SIGEMT) 00403 case GDB_SIGNAL_EMT: 00404 return SIGEMT; 00405 #endif 00406 #if defined (SIGFPE) 00407 case GDB_SIGNAL_FPE: 00408 return SIGFPE; 00409 #endif 00410 #if defined (SIGKILL) 00411 case GDB_SIGNAL_KILL: 00412 return SIGKILL; 00413 #endif 00414 #if defined (SIGBUS) 00415 case GDB_SIGNAL_BUS: 00416 return SIGBUS; 00417 #endif 00418 #if defined (SIGSEGV) 00419 case GDB_SIGNAL_SEGV: 00420 return SIGSEGV; 00421 #endif 00422 #if defined (SIGSYS) 00423 case GDB_SIGNAL_SYS: 00424 return SIGSYS; 00425 #endif 00426 #if defined (SIGPIPE) 00427 case GDB_SIGNAL_PIPE: 00428 return SIGPIPE; 00429 #endif 00430 #if defined (SIGALRM) 00431 case GDB_SIGNAL_ALRM: 00432 return SIGALRM; 00433 #endif 00434 #if defined (SIGTERM) 00435 case GDB_SIGNAL_TERM: 00436 return SIGTERM; 00437 #endif 00438 #if defined (SIGUSR1) 00439 case GDB_SIGNAL_USR1: 00440 return SIGUSR1; 00441 #endif 00442 #if defined (SIGUSR2) 00443 case GDB_SIGNAL_USR2: 00444 return SIGUSR2; 00445 #endif 00446 #if defined (SIGCHLD) || defined (SIGCLD) 00447 case GDB_SIGNAL_CHLD: 00448 #if defined (SIGCHLD) 00449 return SIGCHLD; 00450 #else 00451 return SIGCLD; 00452 #endif 00453 #endif /* SIGCLD or SIGCHLD */ 00454 #if defined (SIGPWR) 00455 case GDB_SIGNAL_PWR: 00456 return SIGPWR; 00457 #endif 00458 #if defined (SIGWINCH) 00459 case GDB_SIGNAL_WINCH: 00460 return SIGWINCH; 00461 #endif 00462 #if defined (SIGURG) 00463 case GDB_SIGNAL_URG: 00464 return SIGURG; 00465 #endif 00466 #if defined (SIGIO) 00467 case GDB_SIGNAL_IO: 00468 return SIGIO; 00469 #endif 00470 #if defined (SIGPOLL) 00471 case GDB_SIGNAL_POLL: 00472 return SIGPOLL; 00473 #endif 00474 #if defined (SIGSTOP) 00475 case GDB_SIGNAL_STOP: 00476 return SIGSTOP; 00477 #endif 00478 #if defined (SIGTSTP) 00479 case GDB_SIGNAL_TSTP: 00480 return SIGTSTP; 00481 #endif 00482 #if defined (SIGCONT) 00483 case GDB_SIGNAL_CONT: 00484 return SIGCONT; 00485 #endif 00486 #if defined (SIGTTIN) 00487 case GDB_SIGNAL_TTIN: 00488 return SIGTTIN; 00489 #endif 00490 #if defined (SIGTTOU) 00491 case GDB_SIGNAL_TTOU: 00492 return SIGTTOU; 00493 #endif 00494 #if defined (SIGVTALRM) 00495 case GDB_SIGNAL_VTALRM: 00496 return SIGVTALRM; 00497 #endif 00498 #if defined (SIGPROF) 00499 case GDB_SIGNAL_PROF: 00500 return SIGPROF; 00501 #endif 00502 #if defined (SIGXCPU) 00503 case GDB_SIGNAL_XCPU: 00504 return SIGXCPU; 00505 #endif 00506 #if defined (SIGXFSZ) 00507 case GDB_SIGNAL_XFSZ: 00508 return SIGXFSZ; 00509 #endif 00510 #if defined (SIGWIND) 00511 case GDB_SIGNAL_WIND: 00512 return SIGWIND; 00513 #endif 00514 #if defined (SIGPHONE) 00515 case GDB_SIGNAL_PHONE: 00516 return SIGPHONE; 00517 #endif 00518 #if defined (SIGLOST) 00519 case GDB_SIGNAL_LOST: 00520 return SIGLOST; 00521 #endif 00522 #if defined (SIGWAITING) 00523 case GDB_SIGNAL_WAITING: 00524 return SIGWAITING; 00525 #endif 00526 #if defined (SIGCANCEL) 00527 case GDB_SIGNAL_CANCEL: 00528 return SIGCANCEL; 00529 #endif 00530 #if defined (SIGLWP) 00531 case GDB_SIGNAL_LWP: 00532 return SIGLWP; 00533 #endif 00534 #if defined (SIGDANGER) 00535 case GDB_SIGNAL_DANGER: 00536 return SIGDANGER; 00537 #endif 00538 #if defined (SIGGRANT) 00539 case GDB_SIGNAL_GRANT: 00540 return SIGGRANT; 00541 #endif 00542 #if defined (SIGRETRACT) 00543 case GDB_SIGNAL_RETRACT: 00544 return SIGRETRACT; 00545 #endif 00546 #if defined (SIGMSG) 00547 case GDB_SIGNAL_MSG: 00548 return SIGMSG; 00549 #endif 00550 #if defined (SIGSOUND) 00551 case GDB_SIGNAL_SOUND: 00552 return SIGSOUND; 00553 #endif 00554 #if defined (SIGSAK) 00555 case GDB_SIGNAL_SAK: 00556 return SIGSAK; 00557 #endif 00558 #if defined (SIGPRIO) 00559 case GDB_SIGNAL_PRIO: 00560 return SIGPRIO; 00561 #endif 00562 00563 /* Mach exceptions. Assumes that the values for EXC_ are positive! */ 00564 #if defined (EXC_BAD_ACCESS) && defined (_NSIG) 00565 case TARGET_EXC_BAD_ACCESS: 00566 return _NSIG + EXC_BAD_ACCESS; 00567 #endif 00568 #if defined (EXC_BAD_INSTRUCTION) && defined (_NSIG) 00569 case TARGET_EXC_BAD_INSTRUCTION: 00570 return _NSIG + EXC_BAD_INSTRUCTION; 00571 #endif 00572 #if defined (EXC_ARITHMETIC) && defined (_NSIG) 00573 case TARGET_EXC_ARITHMETIC: 00574 return _NSIG + EXC_ARITHMETIC; 00575 #endif 00576 #if defined (EXC_EMULATION) && defined (_NSIG) 00577 case TARGET_EXC_EMULATION: 00578 return _NSIG + EXC_EMULATION; 00579 #endif 00580 #if defined (EXC_SOFTWARE) && defined (_NSIG) 00581 case TARGET_EXC_SOFTWARE: 00582 return _NSIG + EXC_SOFTWARE; 00583 #endif 00584 #if defined (EXC_BREAKPOINT) && defined (_NSIG) 00585 case TARGET_EXC_BREAKPOINT: 00586 return _NSIG + EXC_BREAKPOINT; 00587 #endif 00588 00589 #if defined (SIGINFO) 00590 case GDB_SIGNAL_INFO: 00591 return SIGINFO; 00592 #endif 00593 00594 default: 00595 #if defined (REALTIME_LO) 00596 retsig = 0; 00597 00598 if (oursig >= GDB_SIGNAL_REALTIME_33 00599 && oursig <= GDB_SIGNAL_REALTIME_63) 00600 { 00601 /* This block of signals is continuous, and 00602 GDB_SIGNAL_REALTIME_33 is 33 by definition. */ 00603 retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_33 + 33; 00604 } 00605 else if (oursig == GDB_SIGNAL_REALTIME_32) 00606 { 00607 /* GDB_SIGNAL_REALTIME_32 isn't contiguous with 00608 GDB_SIGNAL_REALTIME_33. It is 32 by definition. */ 00609 retsig = 32; 00610 } 00611 else if (oursig >= GDB_SIGNAL_REALTIME_64 00612 && oursig <= GDB_SIGNAL_REALTIME_127) 00613 { 00614 /* This block of signals is continuous, and 00615 GDB_SIGNAL_REALTIME_64 is 64 by definition. */ 00616 retsig = (int) oursig - (int) GDB_SIGNAL_REALTIME_64 + 64; 00617 } 00618 00619 if (retsig >= REALTIME_LO && retsig < REALTIME_HI) 00620 return retsig; 00621 #endif 00622 00623 *oursig_ok = 0; 00624 return 0; 00625 } 00626 } 00627 00628 int 00629 gdb_signal_to_host_p (enum gdb_signal oursig) 00630 { 00631 int oursig_ok; 00632 do_gdb_signal_to_host (oursig, &oursig_ok); 00633 return oursig_ok; 00634 } 00635 00636 int 00637 gdb_signal_to_host (enum gdb_signal oursig) 00638 { 00639 int oursig_ok; 00640 int targ_signo = do_gdb_signal_to_host (oursig, &oursig_ok); 00641 if (!oursig_ok) 00642 { 00643 /* The user might be trying to do "signal SIGSAK" where this system 00644 doesn't have SIGSAK. */ 00645 warning (_("Signal %s does not exist on this system."), 00646 gdb_signal_to_name (oursig)); 00647 return 0; 00648 } 00649 else 00650 return targ_signo; 00651 }