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