| 1 | /* Target-struct-independent code to start (run) and stop an inferior process. |
| 2 | Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996 |
| 3 | Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "gdb_string.h" |
| 23 | #include <ctype.h> |
| 24 | #include "symtab.h" |
| 25 | #include "frame.h" |
| 26 | #include "inferior.h" |
| 27 | #include "breakpoint.h" |
| 28 | #include "wait.h" |
| 29 | #include "gdbcore.h" |
| 30 | #include "gdbcmd.h" |
| 31 | #include "target.h" |
| 32 | #include "gdbthread.h" |
| 33 | #include "annotate.h" |
| 34 | |
| 35 | #include <signal.h> |
| 36 | |
| 37 | /* Prototypes for local functions */ |
| 38 | |
| 39 | static void signals_info PARAMS ((char *, int)); |
| 40 | |
| 41 | static void handle_command PARAMS ((char *, int)); |
| 42 | |
| 43 | static void sig_print_info PARAMS ((enum target_signal)); |
| 44 | |
| 45 | static void sig_print_header PARAMS ((void)); |
| 46 | |
| 47 | static void resume_cleanups PARAMS ((int)); |
| 48 | |
| 49 | static int hook_stop_stub PARAMS ((char *)); |
| 50 | |
| 51 | static void delete_breakpoint_current_contents PARAMS ((PTR)); |
| 52 | |
| 53 | /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the |
| 54 | program. It needs to examine the jmp_buf argument and extract the PC |
| 55 | from it. The return value is non-zero on success, zero otherwise. */ |
| 56 | |
| 57 | #ifndef GET_LONGJMP_TARGET |
| 58 | #define GET_LONGJMP_TARGET(PC_ADDR) 0 |
| 59 | #endif |
| 60 | |
| 61 | |
| 62 | /* Some machines have trampoline code that sits between function callers |
| 63 | and the actual functions themselves. If this machine doesn't have |
| 64 | such things, disable their processing. */ |
| 65 | |
| 66 | #ifndef SKIP_TRAMPOLINE_CODE |
| 67 | #define SKIP_TRAMPOLINE_CODE(pc) 0 |
| 68 | #endif |
| 69 | |
| 70 | /* Dynamic function trampolines are similar to solib trampolines in that they |
| 71 | are between the caller and the callee. The difference is that when you |
| 72 | enter a dynamic trampoline, you can't determine the callee's address. Some |
| 73 | (usually complex) code needs to run in the dynamic trampoline to figure out |
| 74 | the callee's address. This macro is usually called twice. First, when we |
| 75 | enter the trampoline (looks like a normal function call at that point). It |
| 76 | should return the PC of a point within the trampoline where the callee's |
| 77 | address is known. Second, when we hit the breakpoint, this routine returns |
| 78 | the callee's address. At that point, things proceed as per a step resume |
| 79 | breakpoint. */ |
| 80 | |
| 81 | #ifndef DYNAMIC_TRAMPOLINE_NEXTPC |
| 82 | #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0 |
| 83 | #endif |
| 84 | |
| 85 | /* For SVR4 shared libraries, each call goes through a small piece of |
| 86 | trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates |
| 87 | to nonzero if we are current stopped in one of these. */ |
| 88 | |
| 89 | #ifndef IN_SOLIB_CALL_TRAMPOLINE |
| 90 | #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0 |
| 91 | #endif |
| 92 | |
| 93 | /* In some shared library schemes, the return path from a shared library |
| 94 | call may need to go through a trampoline too. */ |
| 95 | |
| 96 | #ifndef IN_SOLIB_RETURN_TRAMPOLINE |
| 97 | #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0 |
| 98 | #endif |
| 99 | |
| 100 | /* On MIPS16, a function that returns a floating point value may call |
| 101 | a library helper function to copy the return value to a floating point |
| 102 | register. The IGNORE_HELPER_CALL macro returns non-zero if we |
| 103 | should ignore (i.e. step over) this function call. */ |
| 104 | #ifndef IGNORE_HELPER_CALL |
| 105 | #define IGNORE_HELPER_CALL(pc) 0 |
| 106 | #endif |
| 107 | |
| 108 | /* On some systems, the PC may be left pointing at an instruction that won't |
| 109 | actually be executed. This is usually indicated by a bit in the PSW. If |
| 110 | we find ourselves in such a state, then we step the target beyond the |
| 111 | nullified instruction before returning control to the user so as to avoid |
| 112 | confusion. */ |
| 113 | |
| 114 | #ifndef INSTRUCTION_NULLIFIED |
| 115 | #define INSTRUCTION_NULLIFIED 0 |
| 116 | #endif |
| 117 | |
| 118 | /* Tables of how to react to signals; the user sets them. */ |
| 119 | |
| 120 | static unsigned char *signal_stop; |
| 121 | static unsigned char *signal_print; |
| 122 | static unsigned char *signal_program; |
| 123 | |
| 124 | #define SET_SIGS(nsigs,sigs,flags) \ |
| 125 | do { \ |
| 126 | int signum = (nsigs); \ |
| 127 | while (signum-- > 0) \ |
| 128 | if ((sigs)[signum]) \ |
| 129 | (flags)[signum] = 1; \ |
| 130 | } while (0) |
| 131 | |
| 132 | #define UNSET_SIGS(nsigs,sigs,flags) \ |
| 133 | do { \ |
| 134 | int signum = (nsigs); \ |
| 135 | while (signum-- > 0) \ |
| 136 | if ((sigs)[signum]) \ |
| 137 | (flags)[signum] = 0; \ |
| 138 | } while (0) |
| 139 | |
| 140 | |
| 141 | /* Command list pointer for the "stop" placeholder. */ |
| 142 | |
| 143 | static struct cmd_list_element *stop_command; |
| 144 | |
| 145 | /* Nonzero if breakpoints are now inserted in the inferior. */ |
| 146 | |
| 147 | static int breakpoints_inserted; |
| 148 | |
| 149 | /* Function inferior was in as of last step command. */ |
| 150 | |
| 151 | static struct symbol *step_start_function; |
| 152 | |
| 153 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ |
| 154 | |
| 155 | static int trap_expected; |
| 156 | |
| 157 | #ifdef SOLIB_ADD |
| 158 | /* Nonzero if we want to give control to the user when we're notified |
| 159 | of shared library events by the dynamic linker. */ |
| 160 | static int stop_on_solib_events; |
| 161 | #endif |
| 162 | |
| 163 | #ifdef HP_OS_BUG |
| 164 | /* Nonzero if the next time we try to continue the inferior, it will |
| 165 | step one instruction and generate a spurious trace trap. |
| 166 | This is used to compensate for a bug in HP-UX. */ |
| 167 | |
| 168 | static int trap_expected_after_continue; |
| 169 | #endif |
| 170 | |
| 171 | /* Nonzero means expecting a trace trap |
| 172 | and should stop the inferior and return silently when it happens. */ |
| 173 | |
| 174 | int stop_after_trap; |
| 175 | |
| 176 | /* Nonzero means expecting a trap and caller will handle it themselves. |
| 177 | It is used after attach, due to attaching to a process; |
| 178 | when running in the shell before the child program has been exec'd; |
| 179 | and when running some kinds of remote stuff (FIXME?). */ |
| 180 | |
| 181 | int stop_soon_quietly; |
| 182 | |
| 183 | /* Nonzero if proceed is being used for a "finish" command or a similar |
| 184 | situation when stop_registers should be saved. */ |
| 185 | |
| 186 | int proceed_to_finish; |
| 187 | |
| 188 | /* Save register contents here when about to pop a stack dummy frame, |
| 189 | if-and-only-if proceed_to_finish is set. |
| 190 | Thus this contains the return value from the called function (assuming |
| 191 | values are returned in a register). */ |
| 192 | |
| 193 | char stop_registers[REGISTER_BYTES]; |
| 194 | |
| 195 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ |
| 196 | |
| 197 | static int breakpoints_failed; |
| 198 | |
| 199 | /* Nonzero after stop if current stack frame should be printed. */ |
| 200 | |
| 201 | static int stop_print_frame; |
| 202 | |
| 203 | \f |
| 204 | /* Things to clean up if we QUIT out of resume (). */ |
| 205 | /* ARGSUSED */ |
| 206 | static void |
| 207 | resume_cleanups (arg) |
| 208 | int arg; |
| 209 | { |
| 210 | normal_stop (); |
| 211 | } |
| 212 | |
| 213 | /* Resume the inferior, but allow a QUIT. This is useful if the user |
| 214 | wants to interrupt some lengthy single-stepping operation |
| 215 | (for child processes, the SIGINT goes to the inferior, and so |
| 216 | we get a SIGINT random_signal, but for remote debugging and perhaps |
| 217 | other targets, that's not true). |
| 218 | |
| 219 | STEP nonzero if we should step (zero to continue instead). |
| 220 | SIG is the signal to give the inferior (zero for none). */ |
| 221 | void |
| 222 | resume (step, sig) |
| 223 | int step; |
| 224 | enum target_signal sig; |
| 225 | { |
| 226 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
| 227 | QUIT; |
| 228 | |
| 229 | #ifdef CANNOT_STEP_BREAKPOINT |
| 230 | /* Most targets can step a breakpoint instruction, thus executing it |
| 231 | normally. But if this one cannot, just continue and we will hit |
| 232 | it anyway. */ |
| 233 | if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) |
| 234 | step = 0; |
| 235 | #endif |
| 236 | |
| 237 | #ifdef NO_SINGLE_STEP |
| 238 | if (step) { |
| 239 | single_step(sig); /* Do it the hard way, w/temp breakpoints */ |
| 240 | step = 0; /* ...and don't ask hardware to do it. */ |
| 241 | } |
| 242 | #endif |
| 243 | |
| 244 | /* Handle any optimized stores to the inferior NOW... */ |
| 245 | #ifdef DO_DEFERRED_STORES |
| 246 | DO_DEFERRED_STORES; |
| 247 | #endif |
| 248 | |
| 249 | /* Install inferior's terminal modes. */ |
| 250 | target_terminal_inferior (); |
| 251 | |
| 252 | target_resume (-1, step, sig); |
| 253 | discard_cleanups (old_cleanups); |
| 254 | } |
| 255 | |
| 256 | \f |
| 257 | /* Clear out all variables saying what to do when inferior is continued. |
| 258 | First do this, then set the ones you want, then call `proceed'. */ |
| 259 | |
| 260 | void |
| 261 | clear_proceed_status () |
| 262 | { |
| 263 | trap_expected = 0; |
| 264 | step_range_start = 0; |
| 265 | step_range_end = 0; |
| 266 | step_frame_address = 0; |
| 267 | step_over_calls = -1; |
| 268 | stop_after_trap = 0; |
| 269 | stop_soon_quietly = 0; |
| 270 | proceed_to_finish = 0; |
| 271 | breakpoint_proceeded = 1; /* We're about to proceed... */ |
| 272 | |
| 273 | /* Discard any remaining commands or status from previous stop. */ |
| 274 | bpstat_clear (&stop_bpstat); |
| 275 | } |
| 276 | |
| 277 | /* Basic routine for continuing the program in various fashions. |
| 278 | |
| 279 | ADDR is the address to resume at, or -1 for resume where stopped. |
| 280 | SIGGNAL is the signal to give it, or 0 for none, |
| 281 | or -1 for act according to how it stopped. |
| 282 | STEP is nonzero if should trap after one instruction. |
| 283 | -1 means return after that and print nothing. |
| 284 | You should probably set various step_... variables |
| 285 | before calling here, if you are stepping. |
| 286 | |
| 287 | You should call clear_proceed_status before calling proceed. */ |
| 288 | |
| 289 | void |
| 290 | proceed (addr, siggnal, step) |
| 291 | CORE_ADDR addr; |
| 292 | enum target_signal siggnal; |
| 293 | int step; |
| 294 | { |
| 295 | int oneproc = 0; |
| 296 | |
| 297 | if (step > 0) |
| 298 | step_start_function = find_pc_function (read_pc ()); |
| 299 | if (step < 0) |
| 300 | stop_after_trap = 1; |
| 301 | |
| 302 | if (addr == (CORE_ADDR)-1) |
| 303 | { |
| 304 | /* If there is a breakpoint at the address we will resume at, |
| 305 | step one instruction before inserting breakpoints |
| 306 | so that we do not stop right away. */ |
| 307 | |
| 308 | if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) |
| 309 | oneproc = 1; |
| 310 | |
| 311 | #ifdef STEP_SKIPS_DELAY |
| 312 | /* Check breakpoint_here_p first, because breakpoint_here_p is fast |
| 313 | (it just checks internal GDB data structures) and STEP_SKIPS_DELAY |
| 314 | is slow (it needs to read memory from the target). */ |
| 315 | if (breakpoint_here_p (read_pc () + 4) |
| 316 | && STEP_SKIPS_DELAY (read_pc ())) |
| 317 | oneproc = 1; |
| 318 | #endif /* STEP_SKIPS_DELAY */ |
| 319 | } |
| 320 | else |
| 321 | write_pc (addr); |
| 322 | |
| 323 | #ifdef PREPARE_TO_PROCEED |
| 324 | /* In a multi-threaded task we may select another thread and then continue. |
| 325 | |
| 326 | In this case the thread that stopped at a breakpoint will immediately |
| 327 | cause another stop, if it is not stepped over first. On the other hand, |
| 328 | if (ADDR != -1) we only want to single step over the breakpoint if we did |
| 329 | switch to another thread. |
| 330 | |
| 331 | If we are single stepping, don't do any of the above. |
| 332 | (Note that in the current implementation single stepping another |
| 333 | thread after a breakpoint and then continuing will cause the original |
| 334 | breakpoint to be hit again, but you can always continue, so it's not |
| 335 | a big deal.) */ |
| 336 | |
| 337 | if (! step && PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ())) |
| 338 | oneproc = 1; |
| 339 | #endif /* PREPARE_TO_PROCEED */ |
| 340 | |
| 341 | #ifdef HP_OS_BUG |
| 342 | if (trap_expected_after_continue) |
| 343 | { |
| 344 | /* If (step == 0), a trap will be automatically generated after |
| 345 | the first instruction is executed. Force step one |
| 346 | instruction to clear this condition. This should not occur |
| 347 | if step is nonzero, but it is harmless in that case. */ |
| 348 | oneproc = 1; |
| 349 | trap_expected_after_continue = 0; |
| 350 | } |
| 351 | #endif /* HP_OS_BUG */ |
| 352 | |
| 353 | if (oneproc) |
| 354 | /* We will get a trace trap after one instruction. |
| 355 | Continue it automatically and insert breakpoints then. */ |
| 356 | trap_expected = 1; |
| 357 | else |
| 358 | { |
| 359 | int temp = insert_breakpoints (); |
| 360 | if (temp) |
| 361 | { |
| 362 | print_sys_errmsg ("ptrace", temp); |
| 363 | error ("Cannot insert breakpoints.\n\ |
| 364 | The same program may be running in another process."); |
| 365 | } |
| 366 | breakpoints_inserted = 1; |
| 367 | } |
| 368 | |
| 369 | if (siggnal != TARGET_SIGNAL_DEFAULT) |
| 370 | stop_signal = siggnal; |
| 371 | /* If this signal should not be seen by program, |
| 372 | give it zero. Used for debugging signals. */ |
| 373 | else if (!signal_program[stop_signal]) |
| 374 | stop_signal = TARGET_SIGNAL_0; |
| 375 | |
| 376 | annotate_starting (); |
| 377 | |
| 378 | /* Make sure that output from GDB appears before output from the |
| 379 | inferior. */ |
| 380 | gdb_flush (gdb_stdout); |
| 381 | |
| 382 | /* Resume inferior. */ |
| 383 | resume (oneproc || step || bpstat_should_step (), stop_signal); |
| 384 | |
| 385 | /* Wait for it to stop (if not standalone) |
| 386 | and in any case decode why it stopped, and act accordingly. */ |
| 387 | |
| 388 | wait_for_inferior (); |
| 389 | normal_stop (); |
| 390 | } |
| 391 | |
| 392 | /* Record the pc and sp of the program the last time it stopped. |
| 393 | These are just used internally by wait_for_inferior, but need |
| 394 | to be preserved over calls to it and cleared when the inferior |
| 395 | is started. */ |
| 396 | static CORE_ADDR prev_pc; |
| 397 | static CORE_ADDR prev_func_start; |
| 398 | static char *prev_func_name; |
| 399 | |
| 400 | \f |
| 401 | /* Start remote-debugging of a machine over a serial link. */ |
| 402 | |
| 403 | void |
| 404 | start_remote () |
| 405 | { |
| 406 | init_thread_list (); |
| 407 | init_wait_for_inferior (); |
| 408 | clear_proceed_status (); |
| 409 | stop_soon_quietly = 1; |
| 410 | trap_expected = 0; |
| 411 | wait_for_inferior (); |
| 412 | normal_stop (); |
| 413 | } |
| 414 | |
| 415 | /* Initialize static vars when a new inferior begins. */ |
| 416 | |
| 417 | void |
| 418 | init_wait_for_inferior () |
| 419 | { |
| 420 | /* These are meaningless until the first time through wait_for_inferior. */ |
| 421 | prev_pc = 0; |
| 422 | prev_func_start = 0; |
| 423 | prev_func_name = NULL; |
| 424 | |
| 425 | #ifdef HP_OS_BUG |
| 426 | trap_expected_after_continue = 0; |
| 427 | #endif |
| 428 | breakpoints_inserted = 0; |
| 429 | breakpoint_init_inferior (); |
| 430 | |
| 431 | /* Don't confuse first call to proceed(). */ |
| 432 | stop_signal = TARGET_SIGNAL_0; |
| 433 | } |
| 434 | |
| 435 | static void |
| 436 | delete_breakpoint_current_contents (arg) |
| 437 | PTR arg; |
| 438 | { |
| 439 | struct breakpoint **breakpointp = (struct breakpoint **)arg; |
| 440 | if (*breakpointp != NULL) |
| 441 | delete_breakpoint (*breakpointp); |
| 442 | } |
| 443 | \f |
| 444 | /* Wait for control to return from inferior to debugger. |
| 445 | If inferior gets a signal, we may decide to start it up again |
| 446 | instead of returning. That is why there is a loop in this function. |
| 447 | When this function actually returns it means the inferior |
| 448 | should be left stopped and GDB should read more commands. */ |
| 449 | |
| 450 | void |
| 451 | wait_for_inferior () |
| 452 | { |
| 453 | struct cleanup *old_cleanups; |
| 454 | struct target_waitstatus w; |
| 455 | int another_trap; |
| 456 | int random_signal = 0; |
| 457 | CORE_ADDR stop_func_start; |
| 458 | CORE_ADDR stop_func_end; |
| 459 | char *stop_func_name; |
| 460 | #if 0 |
| 461 | CORE_ADDR prologue_pc = 0; |
| 462 | #endif |
| 463 | CORE_ADDR tmp; |
| 464 | struct symtab_and_line sal; |
| 465 | int remove_breakpoints_on_following_step = 0; |
| 466 | int current_line; |
| 467 | struct symtab *current_symtab; |
| 468 | int handling_longjmp = 0; /* FIXME */ |
| 469 | struct breakpoint *step_resume_breakpoint = NULL; |
| 470 | struct breakpoint *through_sigtramp_breakpoint = NULL; |
| 471 | int pid; |
| 472 | int update_step_sp = 0; |
| 473 | |
| 474 | old_cleanups = make_cleanup (delete_breakpoint_current_contents, |
| 475 | &step_resume_breakpoint); |
| 476 | make_cleanup (delete_breakpoint_current_contents, |
| 477 | &through_sigtramp_breakpoint); |
| 478 | sal = find_pc_line(prev_pc, 0); |
| 479 | current_line = sal.line; |
| 480 | current_symtab = sal.symtab; |
| 481 | |
| 482 | /* Are we stepping? */ |
| 483 | #define CURRENTLY_STEPPING() \ |
| 484 | ((through_sigtramp_breakpoint == NULL \ |
| 485 | && !handling_longjmp \ |
| 486 | && ((step_range_end && step_resume_breakpoint == NULL) \ |
| 487 | || trap_expected)) \ |
| 488 | || bpstat_should_step ()) |
| 489 | |
| 490 | while (1) |
| 491 | { |
| 492 | /* We have to invalidate the registers BEFORE calling target_wait because |
| 493 | they can be loaded from the target while in target_wait. This makes |
| 494 | remote debugging a bit more efficient for those targets that provide |
| 495 | critical registers as part of their normal status mechanism. */ |
| 496 | |
| 497 | registers_changed (); |
| 498 | |
| 499 | if (target_wait_hook) |
| 500 | pid = target_wait_hook (-1, &w); |
| 501 | else |
| 502 | pid = target_wait (-1, &w); |
| 503 | |
| 504 | /* Gross. |
| 505 | |
| 506 | We goto this label from elsewhere in wait_for_inferior when we want |
| 507 | to continue the main loop without calling "wait" and trashing the |
| 508 | waitstatus contained in W. */ |
| 509 | have_waited: |
| 510 | |
| 511 | flush_cached_frames (); |
| 512 | |
| 513 | /* If it's a new process, add it to the thread database */ |
| 514 | |
| 515 | if (pid != inferior_pid |
| 516 | && !in_thread_list (pid)) |
| 517 | { |
| 518 | fprintf_unfiltered (gdb_stderr, "[New %s]\n", target_pid_to_str (pid)); |
| 519 | add_thread (pid); |
| 520 | |
| 521 | /* We may want to consider not doing a resume here in order to give |
| 522 | the user a chance to play with the new thread. It might be good |
| 523 | to make that a user-settable option. */ |
| 524 | |
| 525 | /* At this point, all threads are stopped (happens automatically in |
| 526 | either the OS or the native code). Therefore we need to continue |
| 527 | all threads in order to make progress. */ |
| 528 | |
| 529 | target_resume (-1, 0, TARGET_SIGNAL_0); |
| 530 | continue; |
| 531 | } |
| 532 | |
| 533 | switch (w.kind) |
| 534 | { |
| 535 | case TARGET_WAITKIND_LOADED: |
| 536 | /* Ignore it gracefully. */ |
| 537 | if (breakpoints_inserted) |
| 538 | { |
| 539 | mark_breakpoints_out (); |
| 540 | insert_breakpoints (); |
| 541 | } |
| 542 | resume (0, TARGET_SIGNAL_0); |
| 543 | continue; |
| 544 | |
| 545 | case TARGET_WAITKIND_SPURIOUS: |
| 546 | resume (0, TARGET_SIGNAL_0); |
| 547 | continue; |
| 548 | |
| 549 | case TARGET_WAITKIND_EXITED: |
| 550 | target_terminal_ours (); /* Must do this before mourn anyway */ |
| 551 | annotate_exited (w.value.integer); |
| 552 | if (w.value.integer) |
| 553 | printf_filtered ("\nProgram exited with code 0%o.\n", |
| 554 | (unsigned int)w.value.integer); |
| 555 | else |
| 556 | printf_filtered ("\nProgram exited normally.\n"); |
| 557 | |
| 558 | /* Record the exit code in the convenience variable $_exitcode, so |
| 559 | that the user can inspect this again later. */ |
| 560 | set_internalvar (lookup_internalvar ("_exitcode"), |
| 561 | value_from_longest (builtin_type_int, |
| 562 | (LONGEST) w.value.integer)); |
| 563 | gdb_flush (gdb_stdout); |
| 564 | target_mourn_inferior (); |
| 565 | #ifdef NO_SINGLE_STEP |
| 566 | one_stepped = 0; |
| 567 | #endif |
| 568 | stop_print_frame = 0; |
| 569 | goto stop_stepping; |
| 570 | |
| 571 | case TARGET_WAITKIND_SIGNALLED: |
| 572 | stop_print_frame = 0; |
| 573 | stop_signal = w.value.sig; |
| 574 | target_terminal_ours (); /* Must do this before mourn anyway */ |
| 575 | annotate_signalled (); |
| 576 | |
| 577 | /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED |
| 578 | mean it is already dead? This has been here since GDB 2.8, so |
| 579 | perhaps it means rms didn't understand unix waitstatuses? |
| 580 | For the moment I'm just kludging around this in remote.c |
| 581 | rather than trying to change it here --kingdon, 5 Dec 1994. */ |
| 582 | target_kill (); /* kill mourns as well */ |
| 583 | |
| 584 | printf_filtered ("\nProgram terminated with signal "); |
| 585 | annotate_signal_name (); |
| 586 | printf_filtered ("%s", target_signal_to_name (stop_signal)); |
| 587 | annotate_signal_name_end (); |
| 588 | printf_filtered (", "); |
| 589 | annotate_signal_string (); |
| 590 | printf_filtered ("%s", target_signal_to_string (stop_signal)); |
| 591 | annotate_signal_string_end (); |
| 592 | printf_filtered (".\n"); |
| 593 | |
| 594 | printf_filtered ("The program no longer exists.\n"); |
| 595 | gdb_flush (gdb_stdout); |
| 596 | #ifdef NO_SINGLE_STEP |
| 597 | one_stepped = 0; |
| 598 | #endif |
| 599 | goto stop_stepping; |
| 600 | |
| 601 | case TARGET_WAITKIND_STOPPED: |
| 602 | /* This is the only case in which we keep going; the above cases |
| 603 | end in a continue or goto. */ |
| 604 | break; |
| 605 | } |
| 606 | |
| 607 | stop_signal = w.value.sig; |
| 608 | |
| 609 | stop_pc = read_pc_pid (pid); |
| 610 | |
| 611 | /* See if a thread hit a thread-specific breakpoint that was meant for |
| 612 | another thread. If so, then step that thread past the breakpoint, |
| 613 | and continue it. */ |
| 614 | |
| 615 | if (stop_signal == TARGET_SIGNAL_TRAP) |
| 616 | { |
| 617 | #ifdef NO_SINGLE_STEP |
| 618 | if (one_stepped) |
| 619 | random_signal = 0; |
| 620 | else |
| 621 | #endif |
| 622 | if (breakpoints_inserted |
| 623 | && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK)) |
| 624 | { |
| 625 | random_signal = 0; |
| 626 | if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid)) |
| 627 | { |
| 628 | /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */ |
| 629 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid); |
| 630 | |
| 631 | remove_breakpoints (); |
| 632 | target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */ |
| 633 | /* FIXME: What if a signal arrives instead of the single-step |
| 634 | happening? */ |
| 635 | |
| 636 | if (target_wait_hook) |
| 637 | target_wait_hook (pid, &w); |
| 638 | else |
| 639 | target_wait (pid, &w); |
| 640 | insert_breakpoints (); |
| 641 | |
| 642 | /* We need to restart all the threads now. */ |
| 643 | target_resume (-1, 0, TARGET_SIGNAL_0); |
| 644 | continue; |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | else |
| 649 | random_signal = 1; |
| 650 | |
| 651 | /* See if something interesting happened to the non-current thread. If |
| 652 | so, then switch to that thread, and eventually give control back to |
| 653 | the user. */ |
| 654 | |
| 655 | if (pid != inferior_pid) |
| 656 | { |
| 657 | int printed = 0; |
| 658 | |
| 659 | /* If it's a random signal for a non-current thread, notify user |
| 660 | if he's expressed an interest. */ |
| 661 | |
| 662 | if (random_signal |
| 663 | && signal_print[stop_signal]) |
| 664 | { |
| 665 | printed = 1; |
| 666 | target_terminal_ours_for_output (); |
| 667 | printf_filtered ("\nProgram received signal %s, %s.\n", |
| 668 | target_signal_to_name (stop_signal), |
| 669 | target_signal_to_string (stop_signal)); |
| 670 | gdb_flush (gdb_stdout); |
| 671 | } |
| 672 | |
| 673 | /* If it's not SIGTRAP and not a signal we want to stop for, then |
| 674 | continue the thread. */ |
| 675 | |
| 676 | if (stop_signal != TARGET_SIGNAL_TRAP |
| 677 | && !signal_stop[stop_signal]) |
| 678 | { |
| 679 | if (printed) |
| 680 | target_terminal_inferior (); |
| 681 | |
| 682 | /* Clear the signal if it should not be passed. */ |
| 683 | if (signal_program[stop_signal] == 0) |
| 684 | stop_signal = TARGET_SIGNAL_0; |
| 685 | |
| 686 | target_resume (pid, 0, stop_signal); |
| 687 | continue; |
| 688 | } |
| 689 | |
| 690 | /* It's a SIGTRAP or a signal we're interested in. Switch threads, |
| 691 | and fall into the rest of wait_for_inferior(). */ |
| 692 | |
| 693 | /* Save infrun state for the old thread. */ |
| 694 | save_infrun_state (inferior_pid, prev_pc, |
| 695 | prev_func_start, prev_func_name, |
| 696 | trap_expected, step_resume_breakpoint, |
| 697 | through_sigtramp_breakpoint, |
| 698 | step_range_start, step_range_end, |
| 699 | step_frame_address, handling_longjmp, |
| 700 | another_trap); |
| 701 | |
| 702 | inferior_pid = pid; |
| 703 | |
| 704 | /* Load infrun state for the new thread. */ |
| 705 | load_infrun_state (inferior_pid, &prev_pc, |
| 706 | &prev_func_start, &prev_func_name, |
| 707 | &trap_expected, &step_resume_breakpoint, |
| 708 | &through_sigtramp_breakpoint, |
| 709 | &step_range_start, &step_range_end, |
| 710 | &step_frame_address, &handling_longjmp, |
| 711 | &another_trap); |
| 712 | printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid)); |
| 713 | |
| 714 | flush_cached_frames (); |
| 715 | } |
| 716 | |
| 717 | #ifdef NO_SINGLE_STEP |
| 718 | if (one_stepped) |
| 719 | single_step (0); /* This actually cleans up the ss */ |
| 720 | #endif /* NO_SINGLE_STEP */ |
| 721 | |
| 722 | /* If PC is pointing at a nullified instruction, then step beyond |
| 723 | it so that the user won't be confused when GDB appears to be ready |
| 724 | to execute it. */ |
| 725 | |
| 726 | if (INSTRUCTION_NULLIFIED) |
| 727 | { |
| 728 | struct target_waitstatus tmpstatus; |
| 729 | |
| 730 | registers_changed (); |
| 731 | target_resume (pid, 1, TARGET_SIGNAL_0); |
| 732 | |
| 733 | /* We may have received a signal that we want to pass to |
| 734 | the inferior; therefore, we must not clobber the waitstatus |
| 735 | in W. So we call wait ourselves, then continue the loop |
| 736 | at the "have_waited" label. */ |
| 737 | if (target_wait_hook) |
| 738 | target_wait_hook (pid, &tmpstatus); |
| 739 | else |
| 740 | target_wait (pid, &tmpstatus); |
| 741 | |
| 742 | |
| 743 | goto have_waited; |
| 744 | } |
| 745 | |
| 746 | #ifdef HAVE_STEPPABLE_WATCHPOINT |
| 747 | /* It may not be necessary to disable the watchpoint to stop over |
| 748 | it. For example, the PA can (with some kernel cooperation) |
| 749 | single step over a watchpoint without disabling the watchpoint. */ |
| 750 | if (STOPPED_BY_WATCHPOINT (w)) |
| 751 | { |
| 752 | resume (1, 0); |
| 753 | continue; |
| 754 | } |
| 755 | #endif |
| 756 | |
| 757 | #ifdef HAVE_NONSTEPPABLE_WATCHPOINT |
| 758 | /* It is far more common to need to disable a watchpoint |
| 759 | to step the inferior over it. FIXME. What else might |
| 760 | a debug register or page protection watchpoint scheme need |
| 761 | here? */ |
| 762 | if (STOPPED_BY_WATCHPOINT (w)) |
| 763 | { |
| 764 | /* At this point, we are stopped at an instruction which has attempted to write |
| 765 | to a piece of memory under control of a watchpoint. The instruction hasn't |
| 766 | actually executed yet. If we were to evaluate the watchpoint expression |
| 767 | now, we would get the old value, and therefore no change would seem to have |
| 768 | occurred. |
| 769 | |
| 770 | In order to make watchpoints work `right', we really need to complete the |
| 771 | memory write, and then evaluate the watchpoint expression. The following |
| 772 | code does that by removing the watchpoint (actually, all watchpoints and |
| 773 | breakpoints), single-stepping the target, re-inserting watchpoints, and then |
| 774 | falling through to let normal single-step processing handle proceed. Since |
| 775 | this includes evaluating watchpoints, things will come to a stop in the |
| 776 | correct manner. */ |
| 777 | |
| 778 | write_pc (stop_pc - DECR_PC_AFTER_BREAK); |
| 779 | |
| 780 | remove_breakpoints (); |
| 781 | target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */ |
| 782 | |
| 783 | if (target_wait_hook) |
| 784 | target_wait_hook (pid, &w); |
| 785 | else |
| 786 | target_wait (pid, &w); |
| 787 | insert_breakpoints (); |
| 788 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
| 789 | handle things like signals arriving and other things happening |
| 790 | in combination correctly? */ |
| 791 | goto have_waited; |
| 792 | } |
| 793 | #endif |
| 794 | |
| 795 | #ifdef HAVE_CONTINUABLE_WATCHPOINT |
| 796 | /* It may be possible to simply continue after a watchpoint. */ |
| 797 | STOPPED_BY_WATCHPOINT (w); |
| 798 | #endif |
| 799 | |
| 800 | stop_func_start = 0; |
| 801 | stop_func_end = 0; |
| 802 | stop_func_name = 0; |
| 803 | /* Don't care about return value; stop_func_start and stop_func_name |
| 804 | will both be 0 if it doesn't work. */ |
| 805 | find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start, |
| 806 | &stop_func_end); |
| 807 | stop_func_start += FUNCTION_START_OFFSET; |
| 808 | another_trap = 0; |
| 809 | bpstat_clear (&stop_bpstat); |
| 810 | stop_step = 0; |
| 811 | stop_stack_dummy = 0; |
| 812 | stop_print_frame = 1; |
| 813 | random_signal = 0; |
| 814 | stopped_by_random_signal = 0; |
| 815 | breakpoints_failed = 0; |
| 816 | |
| 817 | /* Look at the cause of the stop, and decide what to do. |
| 818 | The alternatives are: |
| 819 | 1) break; to really stop and return to the debugger, |
| 820 | 2) drop through to start up again |
| 821 | (set another_trap to 1 to single step once) |
| 822 | 3) set random_signal to 1, and the decision between 1 and 2 |
| 823 | will be made according to the signal handling tables. */ |
| 824 | |
| 825 | /* First, distinguish signals caused by the debugger from signals |
| 826 | that have to do with the program's own actions. |
| 827 | Note that breakpoint insns may cause SIGTRAP or SIGILL |
| 828 | or SIGEMT, depending on the operating system version. |
| 829 | Here we detect when a SIGILL or SIGEMT is really a breakpoint |
| 830 | and change it to SIGTRAP. */ |
| 831 | |
| 832 | if (stop_signal == TARGET_SIGNAL_TRAP |
| 833 | || (breakpoints_inserted && |
| 834 | (stop_signal == TARGET_SIGNAL_ILL |
| 835 | || stop_signal == TARGET_SIGNAL_EMT |
| 836 | )) |
| 837 | || stop_soon_quietly) |
| 838 | { |
| 839 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) |
| 840 | { |
| 841 | stop_print_frame = 0; |
| 842 | break; |
| 843 | } |
| 844 | if (stop_soon_quietly) |
| 845 | break; |
| 846 | |
| 847 | /* Don't even think about breakpoints |
| 848 | if just proceeded over a breakpoint. |
| 849 | |
| 850 | However, if we are trying to proceed over a breakpoint |
| 851 | and end up in sigtramp, then through_sigtramp_breakpoint |
| 852 | will be set and we should check whether we've hit the |
| 853 | step breakpoint. */ |
| 854 | if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected |
| 855 | && through_sigtramp_breakpoint == NULL) |
| 856 | bpstat_clear (&stop_bpstat); |
| 857 | else |
| 858 | { |
| 859 | /* See if there is a breakpoint at the current PC. */ |
| 860 | stop_bpstat = bpstat_stop_status |
| 861 | (&stop_pc, |
| 862 | (DECR_PC_AFTER_BREAK ? |
| 863 | /* Notice the case of stepping through a jump |
| 864 | that lands just after a breakpoint. |
| 865 | Don't confuse that with hitting the breakpoint. |
| 866 | What we check for is that 1) stepping is going on |
| 867 | and 2) the pc before the last insn does not match |
| 868 | the address of the breakpoint before the current pc. */ |
| 869 | (prev_pc != stop_pc - DECR_PC_AFTER_BREAK |
| 870 | && CURRENTLY_STEPPING ()) : |
| 871 | 0) |
| 872 | ); |
| 873 | /* Following in case break condition called a |
| 874 | function. */ |
| 875 | stop_print_frame = 1; |
| 876 | } |
| 877 | |
| 878 | if (stop_signal == TARGET_SIGNAL_TRAP) |
| 879 | random_signal |
| 880 | = !(bpstat_explains_signal (stop_bpstat) |
| 881 | || trap_expected |
| 882 | #ifndef CALL_DUMMY_BREAKPOINT_OFFSET |
| 883 | || PC_IN_CALL_DUMMY (stop_pc, read_sp (), |
| 884 | FRAME_FP (get_current_frame ())) |
| 885 | #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */ |
| 886 | || (step_range_end && step_resume_breakpoint == NULL)); |
| 887 | else |
| 888 | { |
| 889 | random_signal |
| 890 | = !(bpstat_explains_signal (stop_bpstat) |
| 891 | /* End of a stack dummy. Some systems (e.g. Sony |
| 892 | news) give another signal besides SIGTRAP, |
| 893 | so check here as well as above. */ |
| 894 | #ifndef CALL_DUMMY_BREAKPOINT_OFFSET |
| 895 | || PC_IN_CALL_DUMMY (stop_pc, read_sp (), |
| 896 | FRAME_FP (get_current_frame ())) |
| 897 | #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */ |
| 898 | ); |
| 899 | if (!random_signal) |
| 900 | stop_signal = TARGET_SIGNAL_TRAP; |
| 901 | } |
| 902 | } |
| 903 | else |
| 904 | random_signal = 1; |
| 905 | |
| 906 | /* For the program's own signals, act according to |
| 907 | the signal handling tables. */ |
| 908 | |
| 909 | if (random_signal) |
| 910 | { |
| 911 | /* Signal not for debugging purposes. */ |
| 912 | int printed = 0; |
| 913 | |
| 914 | stopped_by_random_signal = 1; |
| 915 | |
| 916 | if (signal_print[stop_signal]) |
| 917 | { |
| 918 | printed = 1; |
| 919 | target_terminal_ours_for_output (); |
| 920 | annotate_signal (); |
| 921 | printf_filtered ("\nProgram received signal "); |
| 922 | annotate_signal_name (); |
| 923 | printf_filtered ("%s", target_signal_to_name (stop_signal)); |
| 924 | annotate_signal_name_end (); |
| 925 | printf_filtered (", "); |
| 926 | annotate_signal_string (); |
| 927 | printf_filtered ("%s", target_signal_to_string (stop_signal)); |
| 928 | annotate_signal_string_end (); |
| 929 | printf_filtered (".\n"); |
| 930 | gdb_flush (gdb_stdout); |
| 931 | } |
| 932 | if (signal_stop[stop_signal]) |
| 933 | break; |
| 934 | /* If not going to stop, give terminal back |
| 935 | if we took it away. */ |
| 936 | else if (printed) |
| 937 | target_terminal_inferior (); |
| 938 | |
| 939 | /* Clear the signal if it should not be passed. */ |
| 940 | if (signal_program[stop_signal] == 0) |
| 941 | stop_signal = TARGET_SIGNAL_0; |
| 942 | |
| 943 | /* I'm not sure whether this needs to be check_sigtramp2 or |
| 944 | whether it could/should be keep_going. */ |
| 945 | goto check_sigtramp2; |
| 946 | } |
| 947 | |
| 948 | /* Handle cases caused by hitting a breakpoint. */ |
| 949 | { |
| 950 | CORE_ADDR jmp_buf_pc; |
| 951 | struct bpstat_what what; |
| 952 | |
| 953 | what = bpstat_what (stop_bpstat); |
| 954 | |
| 955 | if (what.call_dummy) |
| 956 | { |
| 957 | stop_stack_dummy = 1; |
| 958 | #ifdef HP_OS_BUG |
| 959 | trap_expected_after_continue = 1; |
| 960 | #endif |
| 961 | } |
| 962 | |
| 963 | switch (what.main_action) |
| 964 | { |
| 965 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
| 966 | /* If we hit the breakpoint at longjmp, disable it for the |
| 967 | duration of this command. Then, install a temporary |
| 968 | breakpoint at the target of the jmp_buf. */ |
| 969 | disable_longjmp_breakpoint(); |
| 970 | remove_breakpoints (); |
| 971 | breakpoints_inserted = 0; |
| 972 | if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going; |
| 973 | |
| 974 | /* Need to blow away step-resume breakpoint, as it |
| 975 | interferes with us */ |
| 976 | if (step_resume_breakpoint != NULL) |
| 977 | { |
| 978 | delete_breakpoint (step_resume_breakpoint); |
| 979 | step_resume_breakpoint = NULL; |
| 980 | } |
| 981 | /* Not sure whether we need to blow this away too, but probably |
| 982 | it is like the step-resume breakpoint. */ |
| 983 | if (through_sigtramp_breakpoint != NULL) |
| 984 | { |
| 985 | delete_breakpoint (through_sigtramp_breakpoint); |
| 986 | through_sigtramp_breakpoint = NULL; |
| 987 | } |
| 988 | |
| 989 | #if 0 |
| 990 | /* FIXME - Need to implement nested temporary breakpoints */ |
| 991 | if (step_over_calls > 0) |
| 992 | set_longjmp_resume_breakpoint(jmp_buf_pc, |
| 993 | get_current_frame()); |
| 994 | else |
| 995 | #endif /* 0 */ |
| 996 | set_longjmp_resume_breakpoint(jmp_buf_pc, NULL); |
| 997 | handling_longjmp = 1; /* FIXME */ |
| 998 | goto keep_going; |
| 999 | |
| 1000 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
| 1001 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: |
| 1002 | remove_breakpoints (); |
| 1003 | breakpoints_inserted = 0; |
| 1004 | #if 0 |
| 1005 | /* FIXME - Need to implement nested temporary breakpoints */ |
| 1006 | if (step_over_calls |
| 1007 | && (FRAME_FP (get_current_frame ()) |
| 1008 | INNER_THAN step_frame_address)) |
| 1009 | { |
| 1010 | another_trap = 1; |
| 1011 | goto keep_going; |
| 1012 | } |
| 1013 | #endif /* 0 */ |
| 1014 | disable_longjmp_breakpoint(); |
| 1015 | handling_longjmp = 0; /* FIXME */ |
| 1016 | if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) |
| 1017 | break; |
| 1018 | /* else fallthrough */ |
| 1019 | |
| 1020 | case BPSTAT_WHAT_SINGLE: |
| 1021 | if (breakpoints_inserted) |
| 1022 | remove_breakpoints (); |
| 1023 | breakpoints_inserted = 0; |
| 1024 | another_trap = 1; |
| 1025 | /* Still need to check other stuff, at least the case |
| 1026 | where we are stepping and step out of the right range. */ |
| 1027 | break; |
| 1028 | |
| 1029 | case BPSTAT_WHAT_STOP_NOISY: |
| 1030 | stop_print_frame = 1; |
| 1031 | |
| 1032 | /* We are about to nuke the step_resume_breakpoint and |
| 1033 | through_sigtramp_breakpoint via the cleanup chain, so |
| 1034 | no need to worry about it here. */ |
| 1035 | |
| 1036 | goto stop_stepping; |
| 1037 | |
| 1038 | case BPSTAT_WHAT_STOP_SILENT: |
| 1039 | stop_print_frame = 0; |
| 1040 | |
| 1041 | /* We are about to nuke the step_resume_breakpoint and |
| 1042 | through_sigtramp_breakpoint via the cleanup chain, so |
| 1043 | no need to worry about it here. */ |
| 1044 | |
| 1045 | goto stop_stepping; |
| 1046 | |
| 1047 | case BPSTAT_WHAT_STEP_RESUME: |
| 1048 | delete_breakpoint (step_resume_breakpoint); |
| 1049 | step_resume_breakpoint = NULL; |
| 1050 | break; |
| 1051 | |
| 1052 | case BPSTAT_WHAT_THROUGH_SIGTRAMP: |
| 1053 | if (through_sigtramp_breakpoint) |
| 1054 | delete_breakpoint (through_sigtramp_breakpoint); |
| 1055 | through_sigtramp_breakpoint = NULL; |
| 1056 | |
| 1057 | /* If were waiting for a trap, hitting the step_resume_break |
| 1058 | doesn't count as getting it. */ |
| 1059 | if (trap_expected) |
| 1060 | another_trap = 1; |
| 1061 | break; |
| 1062 | |
| 1063 | case BPSTAT_WHAT_CHECK_SHLIBS: |
| 1064 | #ifdef SOLIB_ADD |
| 1065 | { |
| 1066 | extern int auto_solib_add; |
| 1067 | |
| 1068 | /* Remove breakpoints, we eventually want to step over the |
| 1069 | shlib event breakpoint, and SOLIB_ADD might adjust |
| 1070 | breakpoint addresses via breakpoint_re_set. */ |
| 1071 | if (breakpoints_inserted) |
| 1072 | remove_breakpoints (); |
| 1073 | breakpoints_inserted = 0; |
| 1074 | |
| 1075 | /* Check for any newly added shared libraries if we're |
| 1076 | supposed to be adding them automatically. */ |
| 1077 | if (auto_solib_add) |
| 1078 | { |
| 1079 | /* Switch terminal for any messages produced by |
| 1080 | breakpoint_re_set. */ |
| 1081 | target_terminal_ours_for_output (); |
| 1082 | SOLIB_ADD (NULL, 0, NULL); |
| 1083 | target_terminal_inferior (); |
| 1084 | } |
| 1085 | |
| 1086 | /* Try to reenable shared library breakpoints, additional |
| 1087 | code segments in shared libraries might be mapped in now. */ |
| 1088 | re_enable_breakpoints_in_shlibs (); |
| 1089 | |
| 1090 | /* If requested, stop when the dynamic linker notifies |
| 1091 | gdb of events. This allows the user to get control |
| 1092 | and place breakpoints in initializer routines for |
| 1093 | dynamically loaded objects (among other things). */ |
| 1094 | if (stop_on_solib_events) |
| 1095 | { |
| 1096 | stop_print_frame = 0; |
| 1097 | goto stop_stepping; |
| 1098 | } |
| 1099 | else |
| 1100 | { |
| 1101 | /* We want to step over this breakpoint, then keep going. */ |
| 1102 | another_trap = 1; |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
| 1106 | #endif |
| 1107 | break; |
| 1108 | |
| 1109 | case BPSTAT_WHAT_LAST: |
| 1110 | /* Not a real code, but listed here to shut up gcc -Wall. */ |
| 1111 | |
| 1112 | case BPSTAT_WHAT_KEEP_CHECKING: |
| 1113 | break; |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | /* We come here if we hit a breakpoint but should not |
| 1118 | stop for it. Possibly we also were stepping |
| 1119 | and should stop for that. So fall through and |
| 1120 | test for stepping. But, if not stepping, |
| 1121 | do not stop. */ |
| 1122 | |
| 1123 | #ifndef CALL_DUMMY_BREAKPOINT_OFFSET |
| 1124 | /* This is the old way of detecting the end of the stack dummy. |
| 1125 | An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets |
| 1126 | handled above. As soon as we can test it on all of them, all |
| 1127 | architectures should define it. */ |
| 1128 | |
| 1129 | /* If this is the breakpoint at the end of a stack dummy, |
| 1130 | just stop silently, unless the user was doing an si/ni, in which |
| 1131 | case she'd better know what she's doing. */ |
| 1132 | |
| 1133 | if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ())) |
| 1134 | && !step_range_end) |
| 1135 | { |
| 1136 | stop_print_frame = 0; |
| 1137 | stop_stack_dummy = 1; |
| 1138 | #ifdef HP_OS_BUG |
| 1139 | trap_expected_after_continue = 1; |
| 1140 | #endif |
| 1141 | break; |
| 1142 | } |
| 1143 | #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */ |
| 1144 | |
| 1145 | if (step_resume_breakpoint) |
| 1146 | /* Having a step-resume breakpoint overrides anything |
| 1147 | else having to do with stepping commands until |
| 1148 | that breakpoint is reached. */ |
| 1149 | /* I'm not sure whether this needs to be check_sigtramp2 or |
| 1150 | whether it could/should be keep_going. */ |
| 1151 | goto check_sigtramp2; |
| 1152 | |
| 1153 | if (step_range_end == 0) |
| 1154 | /* Likewise if we aren't even stepping. */ |
| 1155 | /* I'm not sure whether this needs to be check_sigtramp2 or |
| 1156 | whether it could/should be keep_going. */ |
| 1157 | goto check_sigtramp2; |
| 1158 | |
| 1159 | /* If stepping through a line, keep going if still within it. */ |
| 1160 | if (stop_pc >= step_range_start |
| 1161 | && stop_pc < step_range_end |
| 1162 | #if 0 |
| 1163 | /* I haven't a clue what might trigger this clause, and it seems wrong anyway, |
| 1164 | so I've disabled it until someone complains. -Stu 10/24/95 */ |
| 1165 | |
| 1166 | /* The step range might include the start of the |
| 1167 | function, so if we are at the start of the |
| 1168 | step range and either the stack or frame pointers |
| 1169 | just changed, we've stepped outside */ |
| 1170 | && !(stop_pc == step_range_start |
| 1171 | && FRAME_FP (get_current_frame ()) |
| 1172 | && (read_sp () INNER_THAN step_sp |
| 1173 | || FRAME_FP (get_current_frame ()) != step_frame_address)) |
| 1174 | #endif |
| 1175 | ) |
| 1176 | { |
| 1177 | /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. |
| 1178 | So definately need to check for sigtramp here. */ |
| 1179 | goto check_sigtramp2; |
| 1180 | } |
| 1181 | |
| 1182 | /* We stepped out of the stepping range. */ |
| 1183 | |
| 1184 | /* We can't update step_sp every time through the loop, because |
| 1185 | reading the stack pointer would slow down stepping too much. |
| 1186 | But we can update it every time we leave the step range. */ |
| 1187 | update_step_sp = 1; |
| 1188 | |
| 1189 | /* Did we just take a signal? */ |
| 1190 | if (IN_SIGTRAMP (stop_pc, stop_func_name) |
| 1191 | && !IN_SIGTRAMP (prev_pc, prev_func_name) |
| 1192 | && read_sp () INNER_THAN step_sp) |
| 1193 | { |
| 1194 | /* We've just taken a signal; go until we are back to |
| 1195 | the point where we took it and one more. */ |
| 1196 | |
| 1197 | /* This code is needed at least in the following case: |
| 1198 | The user types "next" and then a signal arrives (before |
| 1199 | the "next" is done). */ |
| 1200 | |
| 1201 | /* Note that if we are stopped at a breakpoint, then we need |
| 1202 | the step_resume breakpoint to override any breakpoints at |
| 1203 | the same location, so that we will still step over the |
| 1204 | breakpoint even though the signal happened. */ |
| 1205 | |
| 1206 | { |
| 1207 | struct symtab_and_line sr_sal; |
| 1208 | |
| 1209 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 1210 | sr_sal.pc = prev_pc; |
| 1211 | /* We could probably be setting the frame to |
| 1212 | step_frame_address; I don't think anyone thought to try it. */ |
| 1213 | step_resume_breakpoint = |
| 1214 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
| 1215 | if (breakpoints_inserted) |
| 1216 | insert_breakpoints (); |
| 1217 | } |
| 1218 | |
| 1219 | /* If this is stepi or nexti, make sure that the stepping range |
| 1220 | gets us past that instruction. */ |
| 1221 | if (step_range_end == 1) |
| 1222 | /* FIXME: Does this run afoul of the code below which, if |
| 1223 | we step into the middle of a line, resets the stepping |
| 1224 | range? */ |
| 1225 | step_range_end = (step_range_start = prev_pc) + 1; |
| 1226 | |
| 1227 | remove_breakpoints_on_following_step = 1; |
| 1228 | goto keep_going; |
| 1229 | } |
| 1230 | |
| 1231 | #if 0 |
| 1232 | /* I disabled this test because it was too complicated and slow. The |
| 1233 | SKIP_PROLOGUE was especially slow, because it caused unnecessary |
| 1234 | prologue examination on various architectures. The code in the #else |
| 1235 | clause has been tested on the Sparc, Mips, PA, and Power |
| 1236 | architectures, so it's pretty likely to be correct. -Stu 10/24/95 */ |
| 1237 | |
| 1238 | /* See if we left the step range due to a subroutine call that |
| 1239 | we should proceed to the end of. */ |
| 1240 | |
| 1241 | if (stop_func_start) |
| 1242 | { |
| 1243 | struct symtab *s; |
| 1244 | |
| 1245 | /* Do this after the IN_SIGTRAMP check; it might give |
| 1246 | an error. */ |
| 1247 | prologue_pc = stop_func_start; |
| 1248 | |
| 1249 | /* Don't skip the prologue if this is assembly source */ |
| 1250 | s = find_pc_symtab (stop_pc); |
| 1251 | if (s && s->language != language_asm) |
| 1252 | SKIP_PROLOGUE (prologue_pc); |
| 1253 | } |
| 1254 | |
| 1255 | if (!(step_sp INNER_THAN read_sp ()) /* don't mistake (sig)return as a call */ |
| 1256 | && (/* Might be a non-recursive call. If the symbols are missing |
| 1257 | enough that stop_func_start == prev_func_start even though |
| 1258 | they are really two functions, we will treat some calls as |
| 1259 | jumps. */ |
| 1260 | stop_func_start != prev_func_start |
| 1261 | |
| 1262 | /* Might be a recursive call if either we have a prologue |
| 1263 | or the call instruction itself saves the PC on the stack. */ |
| 1264 | || prologue_pc != stop_func_start |
| 1265 | || read_sp () != step_sp) |
| 1266 | && (/* PC is completely out of bounds of any known objfiles. Treat |
| 1267 | like a subroutine call. */ |
| 1268 | ! stop_func_start |
| 1269 | |
| 1270 | /* If we do a call, we will be at the start of a function... */ |
| 1271 | || stop_pc == stop_func_start |
| 1272 | |
| 1273 | /* ...except on the Alpha with -O (and also Irix 5 and |
| 1274 | perhaps others), in which we might call the address |
| 1275 | after the load of gp. Since prologues don't contain |
| 1276 | calls, we can't return to within one, and we don't |
| 1277 | jump back into them, so this check is OK. */ |
| 1278 | |
| 1279 | || stop_pc < prologue_pc |
| 1280 | |
| 1281 | /* ...and if it is a leaf function, the prologue might |
| 1282 | consist of gp loading only, so the call transfers to |
| 1283 | the first instruction after the prologue. */ |
| 1284 | || (stop_pc == prologue_pc |
| 1285 | |
| 1286 | /* Distinguish this from the case where we jump back |
| 1287 | to the first instruction after the prologue, |
| 1288 | within a function. */ |
| 1289 | && stop_func_start != prev_func_start) |
| 1290 | |
| 1291 | /* If we end up in certain places, it means we did a subroutine |
| 1292 | call. I'm not completely sure this is necessary now that we |
| 1293 | have the above checks with stop_func_start (and now that |
| 1294 | find_pc_partial_function is pickier). */ |
| 1295 | || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name) |
| 1296 | |
| 1297 | /* If none of the above apply, it is a jump within a function, |
| 1298 | or a return from a subroutine. The other case is longjmp, |
| 1299 | which can no longer happen here as long as the |
| 1300 | handling_longjmp stuff is working. */ |
| 1301 | )) |
| 1302 | #else |
| 1303 | /* This test is a much more streamlined, (but hopefully correct) |
| 1304 | replacement for the code above. It's been tested on the Sparc, |
| 1305 | Mips, PA, and Power architectures with good results. */ |
| 1306 | |
| 1307 | if (stop_pc == stop_func_start /* Quick test */ |
| 1308 | || in_prologue (stop_pc, stop_func_start) |
| 1309 | || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name) |
| 1310 | || stop_func_start == 0) |
| 1311 | #endif |
| 1312 | |
| 1313 | { |
| 1314 | /* It's a subroutine call. */ |
| 1315 | |
| 1316 | if (step_over_calls == 0) |
| 1317 | { |
| 1318 | /* I presume that step_over_calls is only 0 when we're |
| 1319 | supposed to be stepping at the assembly language level |
| 1320 | ("stepi"). Just stop. */ |
| 1321 | stop_step = 1; |
| 1322 | break; |
| 1323 | } |
| 1324 | |
| 1325 | if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc)) |
| 1326 | /* We're doing a "next". */ |
| 1327 | goto step_over_function; |
| 1328 | |
| 1329 | /* If we are in a function call trampoline (a stub between |
| 1330 | the calling routine and the real function), locate the real |
| 1331 | function. That's what tells us (a) whether we want to step |
| 1332 | into it at all, and (b) what prologue we want to run to |
| 1333 | the end of, if we do step into it. */ |
| 1334 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); |
| 1335 | if (tmp != 0) |
| 1336 | stop_func_start = tmp; |
| 1337 | else |
| 1338 | { |
| 1339 | tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc); |
| 1340 | if (tmp) |
| 1341 | { |
| 1342 | struct symtab_and_line xxx; |
| 1343 | /* Why isn't this s_a_l called "sr_sal", like all of the |
| 1344 | other s_a_l's where this code is duplicated? */ |
| 1345 | INIT_SAL (&xxx); /* initialize to zeroes */ |
| 1346 | xxx.pc = tmp; |
| 1347 | step_resume_breakpoint = |
| 1348 | set_momentary_breakpoint (xxx, NULL, bp_step_resume); |
| 1349 | insert_breakpoints (); |
| 1350 | goto keep_going; |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | /* If we have line number information for the function we |
| 1355 | are thinking of stepping into, step into it. |
| 1356 | |
| 1357 | If there are several symtabs at that PC (e.g. with include |
| 1358 | files), just want to know whether *any* of them have line |
| 1359 | numbers. find_pc_line handles this. */ |
| 1360 | { |
| 1361 | struct symtab_and_line tmp_sal; |
| 1362 | |
| 1363 | tmp_sal = find_pc_line (stop_func_start, 0); |
| 1364 | if (tmp_sal.line != 0) |
| 1365 | goto step_into_function; |
| 1366 | } |
| 1367 | |
| 1368 | step_over_function: |
| 1369 | /* A subroutine call has happened. */ |
| 1370 | { |
| 1371 | /* Set a special breakpoint after the return */ |
| 1372 | struct symtab_and_line sr_sal; |
| 1373 | |
| 1374 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 1375 | sr_sal.pc = |
| 1376 | ADDR_BITS_REMOVE |
| 1377 | (SAVED_PC_AFTER_CALL (get_current_frame ())); |
| 1378 | step_resume_breakpoint = |
| 1379 | set_momentary_breakpoint (sr_sal, get_current_frame (), |
| 1380 | bp_step_resume); |
| 1381 | step_resume_breakpoint->frame = step_frame_address; |
| 1382 | if (breakpoints_inserted) |
| 1383 | insert_breakpoints (); |
| 1384 | } |
| 1385 | goto keep_going; |
| 1386 | |
| 1387 | step_into_function: |
| 1388 | /* Subroutine call with source code we should not step over. |
| 1389 | Do step to the first line of code in it. */ |
| 1390 | { |
| 1391 | struct symtab *s; |
| 1392 | |
| 1393 | s = find_pc_symtab (stop_pc); |
| 1394 | if (s && s->language != language_asm) |
| 1395 | SKIP_PROLOGUE (stop_func_start); |
| 1396 | } |
| 1397 | sal = find_pc_line (stop_func_start, 0); |
| 1398 | /* Use the step_resume_break to step until |
| 1399 | the end of the prologue, even if that involves jumps |
| 1400 | (as it seems to on the vax under 4.2). */ |
| 1401 | /* If the prologue ends in the middle of a source line, |
| 1402 | continue to the end of that source line (if it is still |
| 1403 | within the function). Otherwise, just go to end of prologue. */ |
| 1404 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP |
| 1405 | /* no, don't either. It skips any code that's |
| 1406 | legitimately on the first line. */ |
| 1407 | #else |
| 1408 | if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end) |
| 1409 | stop_func_start = sal.end; |
| 1410 | #endif |
| 1411 | |
| 1412 | if (stop_func_start == stop_pc) |
| 1413 | { |
| 1414 | /* We are already there: stop now. */ |
| 1415 | stop_step = 1; |
| 1416 | break; |
| 1417 | } |
| 1418 | else |
| 1419 | /* Put the step-breakpoint there and go until there. */ |
| 1420 | { |
| 1421 | struct symtab_and_line sr_sal; |
| 1422 | |
| 1423 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 1424 | sr_sal.pc = stop_func_start; |
| 1425 | /* Do not specify what the fp should be when we stop |
| 1426 | since on some machines the prologue |
| 1427 | is where the new fp value is established. */ |
| 1428 | step_resume_breakpoint = |
| 1429 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
| 1430 | if (breakpoints_inserted) |
| 1431 | insert_breakpoints (); |
| 1432 | |
| 1433 | /* And make sure stepping stops right away then. */ |
| 1434 | step_range_end = step_range_start; |
| 1435 | } |
| 1436 | goto keep_going; |
| 1437 | } |
| 1438 | |
| 1439 | /* We've wandered out of the step range. */ |
| 1440 | |
| 1441 | sal = find_pc_line(stop_pc, 0); |
| 1442 | |
| 1443 | if (step_range_end == 1) |
| 1444 | { |
| 1445 | /* It is stepi or nexti. We always want to stop stepping after |
| 1446 | one instruction. */ |
| 1447 | stop_step = 1; |
| 1448 | break; |
| 1449 | } |
| 1450 | |
| 1451 | /* If we're in the return path from a shared library trampoline, |
| 1452 | we want to proceed through the trampoline when stepping. */ |
| 1453 | if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name)) |
| 1454 | { |
| 1455 | CORE_ADDR tmp; |
| 1456 | |
| 1457 | /* Determine where this trampoline returns. */ |
| 1458 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); |
| 1459 | |
| 1460 | /* Only proceed through if we know where it's going. */ |
| 1461 | if (tmp) |
| 1462 | { |
| 1463 | /* And put the step-breakpoint there and go until there. */ |
| 1464 | struct symtab_and_line sr_sal; |
| 1465 | |
| 1466 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 1467 | sr_sal.pc = tmp; |
| 1468 | /* Do not specify what the fp should be when we stop |
| 1469 | since on some machines the prologue |
| 1470 | is where the new fp value is established. */ |
| 1471 | step_resume_breakpoint = |
| 1472 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
| 1473 | if (breakpoints_inserted) |
| 1474 | insert_breakpoints (); |
| 1475 | |
| 1476 | /* Restart without fiddling with the step ranges or |
| 1477 | other state. */ |
| 1478 | goto keep_going; |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | if (sal.line == 0) |
| 1483 | { |
| 1484 | /* We have no line number information. That means to stop |
| 1485 | stepping (does this always happen right after one instruction, |
| 1486 | when we do "s" in a function with no line numbers, |
| 1487 | or can this happen as a result of a return or longjmp?). */ |
| 1488 | stop_step = 1; |
| 1489 | break; |
| 1490 | } |
| 1491 | |
| 1492 | if (stop_pc == sal.pc |
| 1493 | && (current_line != sal.line || current_symtab != sal.symtab)) |
| 1494 | { |
| 1495 | /* We are at the start of a different line. So stop. Note that |
| 1496 | we don't stop if we step into the middle of a different line. |
| 1497 | That is said to make things like for (;;) statements work |
| 1498 | better. */ |
| 1499 | stop_step = 1; |
| 1500 | break; |
| 1501 | } |
| 1502 | |
| 1503 | /* We aren't done stepping. |
| 1504 | |
| 1505 | Optimize by setting the stepping range to the line. |
| 1506 | (We might not be in the original line, but if we entered a |
| 1507 | new line in mid-statement, we continue stepping. This makes |
| 1508 | things like for(;;) statements work better.) */ |
| 1509 | |
| 1510 | if (stop_func_end && sal.end >= stop_func_end) |
| 1511 | { |
| 1512 | /* If this is the last line of the function, don't keep stepping |
| 1513 | (it would probably step us out of the function). |
| 1514 | This is particularly necessary for a one-line function, |
| 1515 | in which after skipping the prologue we better stop even though |
| 1516 | we will be in mid-line. */ |
| 1517 | stop_step = 1; |
| 1518 | break; |
| 1519 | } |
| 1520 | step_range_start = sal.pc; |
| 1521 | step_range_end = sal.end; |
| 1522 | step_frame_address = FRAME_FP (get_current_frame ()); |
| 1523 | current_line = sal.line; |
| 1524 | current_symtab = sal.symtab; |
| 1525 | goto keep_going; |
| 1526 | |
| 1527 | check_sigtramp2: |
| 1528 | if (trap_expected |
| 1529 | && IN_SIGTRAMP (stop_pc, stop_func_name) |
| 1530 | && !IN_SIGTRAMP (prev_pc, prev_func_name) |
| 1531 | && read_sp () INNER_THAN step_sp) |
| 1532 | { |
| 1533 | /* What has happened here is that we have just stepped the inferior |
| 1534 | with a signal (because it is a signal which shouldn't make |
| 1535 | us stop), thus stepping into sigtramp. |
| 1536 | |
| 1537 | So we need to set a step_resume_break_address breakpoint |
| 1538 | and continue until we hit it, and then step. FIXME: This should |
| 1539 | be more enduring than a step_resume breakpoint; we should know |
| 1540 | that we will later need to keep going rather than re-hitting |
| 1541 | the breakpoint here (see testsuite/gdb.t06/signals.exp where |
| 1542 | it says "exceedingly difficult"). */ |
| 1543 | struct symtab_and_line sr_sal; |
| 1544 | |
| 1545 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 1546 | sr_sal.pc = prev_pc; |
| 1547 | /* We perhaps could set the frame if we kept track of what |
| 1548 | the frame corresponding to prev_pc was. But we don't, |
| 1549 | so don't. */ |
| 1550 | through_sigtramp_breakpoint = |
| 1551 | set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp); |
| 1552 | if (breakpoints_inserted) |
| 1553 | insert_breakpoints (); |
| 1554 | |
| 1555 | remove_breakpoints_on_following_step = 1; |
| 1556 | another_trap = 1; |
| 1557 | } |
| 1558 | |
| 1559 | keep_going: |
| 1560 | /* Come to this label when you need to resume the inferior. |
| 1561 | It's really much cleaner to do a goto than a maze of if-else |
| 1562 | conditions. */ |
| 1563 | |
| 1564 | /* Save the pc before execution, to compare with pc after stop. */ |
| 1565 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ |
| 1566 | prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER |
| 1567 | BREAK is defined, the |
| 1568 | original pc would not have |
| 1569 | been at the start of a |
| 1570 | function. */ |
| 1571 | prev_func_name = stop_func_name; |
| 1572 | |
| 1573 | if (update_step_sp) |
| 1574 | step_sp = read_sp (); |
| 1575 | update_step_sp = 0; |
| 1576 | |
| 1577 | /* If we did not do break;, it means we should keep |
| 1578 | running the inferior and not return to debugger. */ |
| 1579 | |
| 1580 | if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) |
| 1581 | { |
| 1582 | /* We took a signal (which we are supposed to pass through to |
| 1583 | the inferior, else we'd have done a break above) and we |
| 1584 | haven't yet gotten our trap. Simply continue. */ |
| 1585 | resume (CURRENTLY_STEPPING (), stop_signal); |
| 1586 | } |
| 1587 | else |
| 1588 | { |
| 1589 | /* Either the trap was not expected, but we are continuing |
| 1590 | anyway (the user asked that this signal be passed to the |
| 1591 | child) |
| 1592 | -- or -- |
| 1593 | The signal was SIGTRAP, e.g. it was our signal, but we |
| 1594 | decided we should resume from it. |
| 1595 | |
| 1596 | We're going to run this baby now! |
| 1597 | |
| 1598 | Insert breakpoints now, unless we are trying |
| 1599 | to one-proceed past a breakpoint. */ |
| 1600 | /* If we've just finished a special step resume and we don't |
| 1601 | want to hit a breakpoint, pull em out. */ |
| 1602 | if (step_resume_breakpoint == NULL |
| 1603 | && through_sigtramp_breakpoint == NULL |
| 1604 | && remove_breakpoints_on_following_step) |
| 1605 | { |
| 1606 | remove_breakpoints_on_following_step = 0; |
| 1607 | remove_breakpoints (); |
| 1608 | breakpoints_inserted = 0; |
| 1609 | } |
| 1610 | else if (!breakpoints_inserted && |
| 1611 | (through_sigtramp_breakpoint != NULL || !another_trap)) |
| 1612 | { |
| 1613 | breakpoints_failed = insert_breakpoints (); |
| 1614 | if (breakpoints_failed) |
| 1615 | break; |
| 1616 | breakpoints_inserted = 1; |
| 1617 | } |
| 1618 | |
| 1619 | trap_expected = another_trap; |
| 1620 | |
| 1621 | if (stop_signal == TARGET_SIGNAL_TRAP) |
| 1622 | stop_signal = TARGET_SIGNAL_0; |
| 1623 | |
| 1624 | #ifdef SHIFT_INST_REGS |
| 1625 | /* I'm not sure when this following segment applies. I do know, now, |
| 1626 | that we shouldn't rewrite the regs when we were stopped by a |
| 1627 | random signal from the inferior process. */ |
| 1628 | /* FIXME: Shouldn't this be based on the valid bit of the SXIP? |
| 1629 | (this is only used on the 88k). */ |
| 1630 | |
| 1631 | if (!bpstat_explains_signal (stop_bpstat) |
| 1632 | && (stop_signal != TARGET_SIGNAL_CHLD) |
| 1633 | && !stopped_by_random_signal) |
| 1634 | SHIFT_INST_REGS(); |
| 1635 | #endif /* SHIFT_INST_REGS */ |
| 1636 | |
| 1637 | resume (CURRENTLY_STEPPING (), stop_signal); |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | stop_stepping: |
| 1642 | if (target_has_execution) |
| 1643 | { |
| 1644 | /* Assuming the inferior still exists, set these up for next |
| 1645 | time, just like we did above if we didn't break out of the |
| 1646 | loop. */ |
| 1647 | prev_pc = read_pc (); |
| 1648 | prev_func_start = stop_func_start; |
| 1649 | prev_func_name = stop_func_name; |
| 1650 | } |
| 1651 | do_cleanups (old_cleanups); |
| 1652 | } |
| 1653 | \f |
| 1654 | /* Here to return control to GDB when the inferior stops for real. |
| 1655 | Print appropriate messages, remove breakpoints, give terminal our modes. |
| 1656 | |
| 1657 | STOP_PRINT_FRAME nonzero means print the executing frame |
| 1658 | (pc, function, args, file, line number and line text). |
| 1659 | BREAKPOINTS_FAILED nonzero means stop was due to error |
| 1660 | attempting to insert breakpoints. */ |
| 1661 | |
| 1662 | void |
| 1663 | normal_stop () |
| 1664 | { |
| 1665 | /* Make sure that the current_frame's pc is correct. This |
| 1666 | is a correction for setting up the frame info before doing |
| 1667 | DECR_PC_AFTER_BREAK */ |
| 1668 | if (target_has_execution && get_current_frame()) |
| 1669 | (get_current_frame ())->pc = read_pc (); |
| 1670 | |
| 1671 | if (breakpoints_failed) |
| 1672 | { |
| 1673 | target_terminal_ours_for_output (); |
| 1674 | print_sys_errmsg ("ptrace", breakpoints_failed); |
| 1675 | printf_filtered ("Stopped; cannot insert breakpoints.\n\ |
| 1676 | The same program may be running in another process.\n"); |
| 1677 | } |
| 1678 | |
| 1679 | if (target_has_execution && breakpoints_inserted) |
| 1680 | if (remove_breakpoints ()) |
| 1681 | { |
| 1682 | target_terminal_ours_for_output (); |
| 1683 | printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\ |
| 1684 | It might be running in another process.\n\ |
| 1685 | Further execution is probably impossible.\n"); |
| 1686 | } |
| 1687 | |
| 1688 | breakpoints_inserted = 0; |
| 1689 | |
| 1690 | /* Delete the breakpoint we stopped at, if it wants to be deleted. |
| 1691 | Delete any breakpoint that is to be deleted at the next stop. */ |
| 1692 | |
| 1693 | breakpoint_auto_delete (stop_bpstat); |
| 1694 | |
| 1695 | /* If an auto-display called a function and that got a signal, |
| 1696 | delete that auto-display to avoid an infinite recursion. */ |
| 1697 | |
| 1698 | if (stopped_by_random_signal) |
| 1699 | disable_current_display (); |
| 1700 | |
| 1701 | if (step_multi && stop_step) |
| 1702 | goto done; |
| 1703 | |
| 1704 | target_terminal_ours (); |
| 1705 | |
| 1706 | if (stop_bpstat |
| 1707 | && stop_bpstat->breakpoint_at |
| 1708 | && stop_bpstat->breakpoint_at->type == bp_shlib_event) |
| 1709 | printf_filtered ("Stopped due to shared library event\n"); |
| 1710 | |
| 1711 | /* Look up the hook_stop and run it if it exists. */ |
| 1712 | |
| 1713 | if (stop_command->hook) |
| 1714 | { |
| 1715 | catch_errors (hook_stop_stub, (char *)stop_command->hook, |
| 1716 | "Error while running hook_stop:\n", RETURN_MASK_ALL); |
| 1717 | } |
| 1718 | |
| 1719 | if (!target_has_stack) |
| 1720 | goto done; |
| 1721 | |
| 1722 | /* Select innermost stack frame except on return from a stack dummy routine, |
| 1723 | or if the program has exited. Print it without a level number if |
| 1724 | we have changed functions or hit a breakpoint. Print source line |
| 1725 | if we have one. */ |
| 1726 | if (!stop_stack_dummy) |
| 1727 | { |
| 1728 | select_frame (get_current_frame (), 0); |
| 1729 | |
| 1730 | if (stop_print_frame) |
| 1731 | { |
| 1732 | int source_only; |
| 1733 | |
| 1734 | source_only = bpstat_print (stop_bpstat); |
| 1735 | source_only = source_only || |
| 1736 | ( stop_step |
| 1737 | && step_frame_address == FRAME_FP (get_current_frame ()) |
| 1738 | && step_start_function == find_pc_function (stop_pc)); |
| 1739 | |
| 1740 | print_stack_frame (selected_frame, -1, source_only? -1: 1); |
| 1741 | |
| 1742 | /* Display the auto-display expressions. */ |
| 1743 | do_displays (); |
| 1744 | } |
| 1745 | } |
| 1746 | |
| 1747 | /* Save the function value return registers, if we care. |
| 1748 | We might be about to restore their previous contents. */ |
| 1749 | if (proceed_to_finish) |
| 1750 | read_register_bytes (0, stop_registers, REGISTER_BYTES); |
| 1751 | |
| 1752 | if (stop_stack_dummy) |
| 1753 | { |
| 1754 | /* Pop the empty frame that contains the stack dummy. |
| 1755 | POP_FRAME ends with a setting of the current frame, so we |
| 1756 | can use that next. */ |
| 1757 | POP_FRAME; |
| 1758 | /* Set stop_pc to what it was before we called the function. Can't rely |
| 1759 | on restore_inferior_status because that only gets called if we don't |
| 1760 | stop in the called function. */ |
| 1761 | stop_pc = read_pc(); |
| 1762 | select_frame (get_current_frame (), 0); |
| 1763 | } |
| 1764 | done: |
| 1765 | annotate_stopped (); |
| 1766 | } |
| 1767 | |
| 1768 | static int |
| 1769 | hook_stop_stub (cmd) |
| 1770 | char *cmd; |
| 1771 | { |
| 1772 | execute_user_command ((struct cmd_list_element *)cmd, 0); |
| 1773 | return (0); |
| 1774 | } |
| 1775 | \f |
| 1776 | int signal_stop_state (signo) |
| 1777 | int signo; |
| 1778 | { |
| 1779 | return signal_stop[signo]; |
| 1780 | } |
| 1781 | |
| 1782 | int signal_print_state (signo) |
| 1783 | int signo; |
| 1784 | { |
| 1785 | return signal_print[signo]; |
| 1786 | } |
| 1787 | |
| 1788 | int signal_pass_state (signo) |
| 1789 | int signo; |
| 1790 | { |
| 1791 | return signal_program[signo]; |
| 1792 | } |
| 1793 | |
| 1794 | static void |
| 1795 | sig_print_header () |
| 1796 | { |
| 1797 | printf_filtered ("\ |
| 1798 | Signal Stop\tPrint\tPass to program\tDescription\n"); |
| 1799 | } |
| 1800 | |
| 1801 | static void |
| 1802 | sig_print_info (oursig) |
| 1803 | enum target_signal oursig; |
| 1804 | { |
| 1805 | char *name = target_signal_to_name (oursig); |
| 1806 | printf_filtered ("%s", name); |
| 1807 | printf_filtered ("%*.*s ", 13 - strlen (name), 13 - strlen (name), |
| 1808 | " "); |
| 1809 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
| 1810 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); |
| 1811 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); |
| 1812 | printf_filtered ("%s\n", target_signal_to_string (oursig)); |
| 1813 | } |
| 1814 | |
| 1815 | /* Specify how various signals in the inferior should be handled. */ |
| 1816 | |
| 1817 | static void |
| 1818 | handle_command (args, from_tty) |
| 1819 | char *args; |
| 1820 | int from_tty; |
| 1821 | { |
| 1822 | char **argv; |
| 1823 | int digits, wordlen; |
| 1824 | int sigfirst, signum, siglast; |
| 1825 | enum target_signal oursig; |
| 1826 | int allsigs; |
| 1827 | int nsigs; |
| 1828 | unsigned char *sigs; |
| 1829 | struct cleanup *old_chain; |
| 1830 | |
| 1831 | if (args == NULL) |
| 1832 | { |
| 1833 | error_no_arg ("signal to handle"); |
| 1834 | } |
| 1835 | |
| 1836 | /* Allocate and zero an array of flags for which signals to handle. */ |
| 1837 | |
| 1838 | nsigs = (int)TARGET_SIGNAL_LAST; |
| 1839 | sigs = (unsigned char *) alloca (nsigs); |
| 1840 | memset (sigs, 0, nsigs); |
| 1841 | |
| 1842 | /* Break the command line up into args. */ |
| 1843 | |
| 1844 | argv = buildargv (args); |
| 1845 | if (argv == NULL) |
| 1846 | { |
| 1847 | nomem (0); |
| 1848 | } |
| 1849 | old_chain = make_cleanup (freeargv, (char *) argv); |
| 1850 | |
| 1851 | /* Walk through the args, looking for signal oursigs, signal names, and |
| 1852 | actions. Signal numbers and signal names may be interspersed with |
| 1853 | actions, with the actions being performed for all signals cumulatively |
| 1854 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ |
| 1855 | |
| 1856 | while (*argv != NULL) |
| 1857 | { |
| 1858 | wordlen = strlen (*argv); |
| 1859 | for (digits = 0; isdigit ((*argv)[digits]); digits++) {;} |
| 1860 | allsigs = 0; |
| 1861 | sigfirst = siglast = -1; |
| 1862 | |
| 1863 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) |
| 1864 | { |
| 1865 | /* Apply action to all signals except those used by the |
| 1866 | debugger. Silently skip those. */ |
| 1867 | allsigs = 1; |
| 1868 | sigfirst = 0; |
| 1869 | siglast = nsigs - 1; |
| 1870 | } |
| 1871 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) |
| 1872 | { |
| 1873 | SET_SIGS (nsigs, sigs, signal_stop); |
| 1874 | SET_SIGS (nsigs, sigs, signal_print); |
| 1875 | } |
| 1876 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) |
| 1877 | { |
| 1878 | UNSET_SIGS (nsigs, sigs, signal_program); |
| 1879 | } |
| 1880 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) |
| 1881 | { |
| 1882 | SET_SIGS (nsigs, sigs, signal_print); |
| 1883 | } |
| 1884 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) |
| 1885 | { |
| 1886 | SET_SIGS (nsigs, sigs, signal_program); |
| 1887 | } |
| 1888 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) |
| 1889 | { |
| 1890 | UNSET_SIGS (nsigs, sigs, signal_stop); |
| 1891 | } |
| 1892 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) |
| 1893 | { |
| 1894 | SET_SIGS (nsigs, sigs, signal_program); |
| 1895 | } |
| 1896 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) |
| 1897 | { |
| 1898 | UNSET_SIGS (nsigs, sigs, signal_print); |
| 1899 | UNSET_SIGS (nsigs, sigs, signal_stop); |
| 1900 | } |
| 1901 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) |
| 1902 | { |
| 1903 | UNSET_SIGS (nsigs, sigs, signal_program); |
| 1904 | } |
| 1905 | else if (digits > 0) |
| 1906 | { |
| 1907 | /* It is numeric. The numeric signal refers to our own internal |
| 1908 | signal numbering from target.h, not to host/target signal number. |
| 1909 | This is a feature; users really should be using symbolic names |
| 1910 | anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc. |
| 1911 | will work right anyway. */ |
| 1912 | |
| 1913 | sigfirst = siglast = (int) target_signal_from_command (atoi (*argv)); |
| 1914 | if ((*argv)[digits] == '-') |
| 1915 | { |
| 1916 | siglast = |
| 1917 | (int) target_signal_from_command (atoi ((*argv) + digits + 1)); |
| 1918 | } |
| 1919 | if (sigfirst > siglast) |
| 1920 | { |
| 1921 | /* Bet he didn't figure we'd think of this case... */ |
| 1922 | signum = sigfirst; |
| 1923 | sigfirst = siglast; |
| 1924 | siglast = signum; |
| 1925 | } |
| 1926 | } |
| 1927 | else |
| 1928 | { |
| 1929 | oursig = target_signal_from_name (*argv); |
| 1930 | if (oursig != TARGET_SIGNAL_UNKNOWN) |
| 1931 | { |
| 1932 | sigfirst = siglast = (int)oursig; |
| 1933 | } |
| 1934 | else |
| 1935 | { |
| 1936 | /* Not a number and not a recognized flag word => complain. */ |
| 1937 | error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | /* If any signal numbers or symbol names were found, set flags for |
| 1942 | which signals to apply actions to. */ |
| 1943 | |
| 1944 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) |
| 1945 | { |
| 1946 | switch ((enum target_signal)signum) |
| 1947 | { |
| 1948 | case TARGET_SIGNAL_TRAP: |
| 1949 | case TARGET_SIGNAL_INT: |
| 1950 | if (!allsigs && !sigs[signum]) |
| 1951 | { |
| 1952 | if (query ("%s is used by the debugger.\n\ |
| 1953 | Are you sure you want to change it? ", |
| 1954 | target_signal_to_name |
| 1955 | ((enum target_signal)signum))) |
| 1956 | { |
| 1957 | sigs[signum] = 1; |
| 1958 | } |
| 1959 | else |
| 1960 | { |
| 1961 | printf_unfiltered ("Not confirmed, unchanged.\n"); |
| 1962 | gdb_flush (gdb_stdout); |
| 1963 | } |
| 1964 | } |
| 1965 | break; |
| 1966 | case TARGET_SIGNAL_0: |
| 1967 | case TARGET_SIGNAL_DEFAULT: |
| 1968 | case TARGET_SIGNAL_UNKNOWN: |
| 1969 | /* Make sure that "all" doesn't print these. */ |
| 1970 | break; |
| 1971 | default: |
| 1972 | sigs[signum] = 1; |
| 1973 | break; |
| 1974 | } |
| 1975 | } |
| 1976 | |
| 1977 | argv++; |
| 1978 | } |
| 1979 | |
| 1980 | target_notice_signals(inferior_pid); |
| 1981 | |
| 1982 | if (from_tty) |
| 1983 | { |
| 1984 | /* Show the results. */ |
| 1985 | sig_print_header (); |
| 1986 | for (signum = 0; signum < nsigs; signum++) |
| 1987 | { |
| 1988 | if (sigs[signum]) |
| 1989 | { |
| 1990 | sig_print_info (signum); |
| 1991 | } |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | do_cleanups (old_chain); |
| 1996 | } |
| 1997 | |
| 1998 | /* Print current contents of the tables set by the handle command. |
| 1999 | It is possible we should just be printing signals actually used |
| 2000 | by the current target (but for things to work right when switching |
| 2001 | targets, all signals should be in the signal tables). */ |
| 2002 | |
| 2003 | static void |
| 2004 | signals_info (signum_exp, from_tty) |
| 2005 | char *signum_exp; |
| 2006 | int from_tty; |
| 2007 | { |
| 2008 | enum target_signal oursig; |
| 2009 | sig_print_header (); |
| 2010 | |
| 2011 | if (signum_exp) |
| 2012 | { |
| 2013 | /* First see if this is a symbol name. */ |
| 2014 | oursig = target_signal_from_name (signum_exp); |
| 2015 | if (oursig == TARGET_SIGNAL_UNKNOWN) |
| 2016 | { |
| 2017 | /* No, try numeric. */ |
| 2018 | oursig = |
| 2019 | target_signal_from_command (parse_and_eval_address (signum_exp)); |
| 2020 | } |
| 2021 | sig_print_info (oursig); |
| 2022 | return; |
| 2023 | } |
| 2024 | |
| 2025 | printf_filtered ("\n"); |
| 2026 | /* These ugly casts brought to you by the native VAX compiler. */ |
| 2027 | for (oursig = TARGET_SIGNAL_FIRST; |
| 2028 | (int)oursig < (int)TARGET_SIGNAL_LAST; |
| 2029 | oursig = (enum target_signal)((int)oursig + 1)) |
| 2030 | { |
| 2031 | QUIT; |
| 2032 | |
| 2033 | if (oursig != TARGET_SIGNAL_UNKNOWN |
| 2034 | && oursig != TARGET_SIGNAL_DEFAULT |
| 2035 | && oursig != TARGET_SIGNAL_0) |
| 2036 | sig_print_info (oursig); |
| 2037 | } |
| 2038 | |
| 2039 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); |
| 2040 | } |
| 2041 | \f |
| 2042 | /* Save all of the information associated with the inferior<==>gdb |
| 2043 | connection. INF_STATUS is a pointer to a "struct inferior_status" |
| 2044 | (defined in inferior.h). */ |
| 2045 | |
| 2046 | void |
| 2047 | save_inferior_status (inf_status, restore_stack_info) |
| 2048 | struct inferior_status *inf_status; |
| 2049 | int restore_stack_info; |
| 2050 | { |
| 2051 | inf_status->stop_signal = stop_signal; |
| 2052 | inf_status->stop_pc = stop_pc; |
| 2053 | inf_status->stop_step = stop_step; |
| 2054 | inf_status->stop_stack_dummy = stop_stack_dummy; |
| 2055 | inf_status->stopped_by_random_signal = stopped_by_random_signal; |
| 2056 | inf_status->trap_expected = trap_expected; |
| 2057 | inf_status->step_range_start = step_range_start; |
| 2058 | inf_status->step_range_end = step_range_end; |
| 2059 | inf_status->step_frame_address = step_frame_address; |
| 2060 | inf_status->step_over_calls = step_over_calls; |
| 2061 | inf_status->stop_after_trap = stop_after_trap; |
| 2062 | inf_status->stop_soon_quietly = stop_soon_quietly; |
| 2063 | /* Save original bpstat chain here; replace it with copy of chain. |
| 2064 | If caller's caller is walking the chain, they'll be happier if we |
| 2065 | hand them back the original chain when restore_i_s is called. */ |
| 2066 | inf_status->stop_bpstat = stop_bpstat; |
| 2067 | stop_bpstat = bpstat_copy (stop_bpstat); |
| 2068 | inf_status->breakpoint_proceeded = breakpoint_proceeded; |
| 2069 | inf_status->restore_stack_info = restore_stack_info; |
| 2070 | inf_status->proceed_to_finish = proceed_to_finish; |
| 2071 | |
| 2072 | memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); |
| 2073 | |
| 2074 | read_register_bytes (0, inf_status->registers, REGISTER_BYTES); |
| 2075 | |
| 2076 | record_selected_frame (&(inf_status->selected_frame_address), |
| 2077 | &(inf_status->selected_level)); |
| 2078 | return; |
| 2079 | } |
| 2080 | |
| 2081 | struct restore_selected_frame_args { |
| 2082 | CORE_ADDR frame_address; |
| 2083 | int level; |
| 2084 | }; |
| 2085 | |
| 2086 | static int restore_selected_frame PARAMS ((char *)); |
| 2087 | |
| 2088 | /* Restore the selected frame. args is really a struct |
| 2089 | restore_selected_frame_args * (declared as char * for catch_errors) |
| 2090 | telling us what frame to restore. Returns 1 for success, or 0 for |
| 2091 | failure. An error message will have been printed on error. */ |
| 2092 | |
| 2093 | static int |
| 2094 | restore_selected_frame (args) |
| 2095 | char *args; |
| 2096 | { |
| 2097 | struct restore_selected_frame_args *fr = |
| 2098 | (struct restore_selected_frame_args *) args; |
| 2099 | struct frame_info *frame; |
| 2100 | int level = fr->level; |
| 2101 | |
| 2102 | frame = find_relative_frame (get_current_frame (), &level); |
| 2103 | |
| 2104 | /* If inf_status->selected_frame_address is NULL, there was no |
| 2105 | previously selected frame. */ |
| 2106 | if (frame == NULL || |
| 2107 | FRAME_FP (frame) != fr->frame_address || |
| 2108 | level != 0) |
| 2109 | { |
| 2110 | warning ("Unable to restore previously selected frame.\n"); |
| 2111 | return 0; |
| 2112 | } |
| 2113 | select_frame (frame, fr->level); |
| 2114 | return(1); |
| 2115 | } |
| 2116 | |
| 2117 | void |
| 2118 | restore_inferior_status (inf_status) |
| 2119 | struct inferior_status *inf_status; |
| 2120 | { |
| 2121 | stop_signal = inf_status->stop_signal; |
| 2122 | stop_pc = inf_status->stop_pc; |
| 2123 | stop_step = inf_status->stop_step; |
| 2124 | stop_stack_dummy = inf_status->stop_stack_dummy; |
| 2125 | stopped_by_random_signal = inf_status->stopped_by_random_signal; |
| 2126 | trap_expected = inf_status->trap_expected; |
| 2127 | step_range_start = inf_status->step_range_start; |
| 2128 | step_range_end = inf_status->step_range_end; |
| 2129 | step_frame_address = inf_status->step_frame_address; |
| 2130 | step_over_calls = inf_status->step_over_calls; |
| 2131 | stop_after_trap = inf_status->stop_after_trap; |
| 2132 | stop_soon_quietly = inf_status->stop_soon_quietly; |
| 2133 | bpstat_clear (&stop_bpstat); |
| 2134 | stop_bpstat = inf_status->stop_bpstat; |
| 2135 | breakpoint_proceeded = inf_status->breakpoint_proceeded; |
| 2136 | proceed_to_finish = inf_status->proceed_to_finish; |
| 2137 | |
| 2138 | memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); |
| 2139 | |
| 2140 | /* The inferior can be gone if the user types "print exit(0)" |
| 2141 | (and perhaps other times). */ |
| 2142 | if (target_has_execution) |
| 2143 | write_register_bytes (0, inf_status->registers, REGISTER_BYTES); |
| 2144 | |
| 2145 | /* The inferior can be gone if the user types "print exit(0)" |
| 2146 | (and perhaps other times). */ |
| 2147 | |
| 2148 | /* FIXME: If we are being called after stopping in a function which |
| 2149 | is called from gdb, we should not be trying to restore the |
| 2150 | selected frame; it just prints a spurious error message (The |
| 2151 | message is useful, however, in detecting bugs in gdb (like if gdb |
| 2152 | clobbers the stack)). In fact, should we be restoring the |
| 2153 | inferior status at all in that case? . */ |
| 2154 | |
| 2155 | if (target_has_stack && inf_status->restore_stack_info) |
| 2156 | { |
| 2157 | struct restore_selected_frame_args fr; |
| 2158 | fr.level = inf_status->selected_level; |
| 2159 | fr.frame_address = inf_status->selected_frame_address; |
| 2160 | /* The point of catch_errors is that if the stack is clobbered, |
| 2161 | walking the stack might encounter a garbage pointer and error() |
| 2162 | trying to dereference it. */ |
| 2163 | if (catch_errors (restore_selected_frame, &fr, |
| 2164 | "Unable to restore previously selected frame:\n", |
| 2165 | RETURN_MASK_ERROR) == 0) |
| 2166 | /* Error in restoring the selected frame. Select the innermost |
| 2167 | frame. */ |
| 2168 | select_frame (get_current_frame (), 0); |
| 2169 | } |
| 2170 | } |
| 2171 | |
| 2172 | \f |
| 2173 | void |
| 2174 | _initialize_infrun () |
| 2175 | { |
| 2176 | register int i; |
| 2177 | register int numsigs; |
| 2178 | |
| 2179 | add_info ("signals", signals_info, |
| 2180 | "What debugger does when program gets various signals.\n\ |
| 2181 | Specify a signal as argument to print info on that signal only."); |
| 2182 | add_info_alias ("handle", "signals", 0); |
| 2183 | |
| 2184 | add_com ("handle", class_run, handle_command, |
| 2185 | concat ("Specify how to handle a signal.\n\ |
| 2186 | Args are signals and actions to apply to those signals.\n\ |
| 2187 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ |
| 2188 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ |
| 2189 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ |
| 2190 | The special arg \"all\" is recognized to mean all signals except those\n\ |
| 2191 | used by the debugger, typically SIGTRAP and SIGINT.\n", |
| 2192 | "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ |
| 2193 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
| 2194 | Stop means reenter debugger if this signal happens (implies print).\n\ |
| 2195 | Print means print a message if this signal happens.\n\ |
| 2196 | Pass means let program see this signal; otherwise program doesn't know.\n\ |
| 2197 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ |
| 2198 | Pass and Stop may be combined.", NULL)); |
| 2199 | |
| 2200 | stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command, |
| 2201 | "There is no `stop' command, but you can set a hook on `stop'.\n\ |
| 2202 | This allows you to set a list of commands to be run each time execution\n\ |
| 2203 | of the program stops.", &cmdlist); |
| 2204 | |
| 2205 | numsigs = (int)TARGET_SIGNAL_LAST; |
| 2206 | signal_stop = (unsigned char *) |
| 2207 | xmalloc (sizeof (signal_stop[0]) * numsigs); |
| 2208 | signal_print = (unsigned char *) |
| 2209 | xmalloc (sizeof (signal_print[0]) * numsigs); |
| 2210 | signal_program = (unsigned char *) |
| 2211 | xmalloc (sizeof (signal_program[0]) * numsigs); |
| 2212 | for (i = 0; i < numsigs; i++) |
| 2213 | { |
| 2214 | signal_stop[i] = 1; |
| 2215 | signal_print[i] = 1; |
| 2216 | signal_program[i] = 1; |
| 2217 | } |
| 2218 | |
| 2219 | /* Signals caused by debugger's own actions |
| 2220 | should not be given to the program afterwards. */ |
| 2221 | signal_program[TARGET_SIGNAL_TRAP] = 0; |
| 2222 | signal_program[TARGET_SIGNAL_INT] = 0; |
| 2223 | |
| 2224 | /* Signals that are not errors should not normally enter the debugger. */ |
| 2225 | signal_stop[TARGET_SIGNAL_ALRM] = 0; |
| 2226 | signal_print[TARGET_SIGNAL_ALRM] = 0; |
| 2227 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; |
| 2228 | signal_print[TARGET_SIGNAL_VTALRM] = 0; |
| 2229 | signal_stop[TARGET_SIGNAL_PROF] = 0; |
| 2230 | signal_print[TARGET_SIGNAL_PROF] = 0; |
| 2231 | signal_stop[TARGET_SIGNAL_CHLD] = 0; |
| 2232 | signal_print[TARGET_SIGNAL_CHLD] = 0; |
| 2233 | signal_stop[TARGET_SIGNAL_IO] = 0; |
| 2234 | signal_print[TARGET_SIGNAL_IO] = 0; |
| 2235 | signal_stop[TARGET_SIGNAL_POLL] = 0; |
| 2236 | signal_print[TARGET_SIGNAL_POLL] = 0; |
| 2237 | signal_stop[TARGET_SIGNAL_URG] = 0; |
| 2238 | signal_print[TARGET_SIGNAL_URG] = 0; |
| 2239 | |
| 2240 | #ifdef SOLIB_ADD |
| 2241 | add_show_from_set |
| 2242 | (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, |
| 2243 | (char *) &stop_on_solib_events, |
| 2244 | "Set stopping for shared library events.\n\ |
| 2245 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
| 2246 | notifies gdb of shared library events. The most common event of interest\n\ |
| 2247 | to the user would be loading/unloading of a new library.\n", |
| 2248 | &setlist), |
| 2249 | &showlist); |
| 2250 | #endif |
| 2251 | } |