| 1 | /* Target-struct-independent code to start (run) and stop an inferior process. |
| 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
| 3 | 1996, 1997, 1998, 1999, 2000, 2001 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, |
| 20 | Boston, MA 02111-1307, USA. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "gdb_string.h" |
| 24 | #include <ctype.h> |
| 25 | #include "symtab.h" |
| 26 | #include "frame.h" |
| 27 | #include "inferior.h" |
| 28 | #include "breakpoint.h" |
| 29 | #include "gdb_wait.h" |
| 30 | #include "gdbcore.h" |
| 31 | #include "gdbcmd.h" |
| 32 | #include "cli/cli-script.h" |
| 33 | #include "target.h" |
| 34 | #include "gdbthread.h" |
| 35 | #include "annotate.h" |
| 36 | #include "symfile.h" |
| 37 | #include "top.h" |
| 38 | #include <signal.h> |
| 39 | #include "inf-loop.h" |
| 40 | #include "regcache.h" |
| 41 | |
| 42 | /* Prototypes for local functions */ |
| 43 | |
| 44 | static void signals_info (char *, int); |
| 45 | |
| 46 | static void handle_command (char *, int); |
| 47 | |
| 48 | static void sig_print_info (enum target_signal); |
| 49 | |
| 50 | static void sig_print_header (void); |
| 51 | |
| 52 | static void resume_cleanups (void *); |
| 53 | |
| 54 | static int hook_stop_stub (void *); |
| 55 | |
| 56 | static void delete_breakpoint_current_contents (void *); |
| 57 | |
| 58 | static void set_follow_fork_mode_command (char *arg, int from_tty, |
| 59 | struct cmd_list_element * c); |
| 60 | |
| 61 | static struct inferior_status *xmalloc_inferior_status (void); |
| 62 | |
| 63 | static void free_inferior_status (struct inferior_status *); |
| 64 | |
| 65 | static int restore_selected_frame (void *); |
| 66 | |
| 67 | static void build_infrun (void); |
| 68 | |
| 69 | static void follow_inferior_fork (int parent_pid, int child_pid, |
| 70 | int has_forked, int has_vforked); |
| 71 | |
| 72 | static void follow_fork (int parent_pid, int child_pid); |
| 73 | |
| 74 | static void follow_vfork (int parent_pid, int child_pid); |
| 75 | |
| 76 | static void set_schedlock_func (char *args, int from_tty, |
| 77 | struct cmd_list_element * c); |
| 78 | |
| 79 | struct execution_control_state; |
| 80 | |
| 81 | static int currently_stepping (struct execution_control_state *ecs); |
| 82 | |
| 83 | static void xdb_handle_command (char *args, int from_tty); |
| 84 | |
| 85 | void _initialize_infrun (void); |
| 86 | |
| 87 | int inferior_ignoring_startup_exec_events = 0; |
| 88 | int inferior_ignoring_leading_exec_events = 0; |
| 89 | |
| 90 | /* When set, stop the 'step' command if we enter a function which has |
| 91 | no line number information. The normal behavior is that we step |
| 92 | over such function. */ |
| 93 | int step_stop_if_no_debug = 0; |
| 94 | |
| 95 | /* In asynchronous mode, but simulating synchronous execution. */ |
| 96 | |
| 97 | int sync_execution = 0; |
| 98 | |
| 99 | /* wait_for_inferior and normal_stop use this to notify the user |
| 100 | when the inferior stopped in a different thread than it had been |
| 101 | running in. */ |
| 102 | |
| 103 | static ptid_t previous_inferior_ptid; |
| 104 | |
| 105 | /* This is true for configurations that may follow through execl() and |
| 106 | similar functions. At present this is only true for HP-UX native. */ |
| 107 | |
| 108 | #ifndef MAY_FOLLOW_EXEC |
| 109 | #define MAY_FOLLOW_EXEC (0) |
| 110 | #endif |
| 111 | |
| 112 | static int may_follow_exec = MAY_FOLLOW_EXEC; |
| 113 | |
| 114 | /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the |
| 115 | program. It needs to examine the jmp_buf argument and extract the PC |
| 116 | from it. The return value is non-zero on success, zero otherwise. */ |
| 117 | |
| 118 | #ifndef GET_LONGJMP_TARGET |
| 119 | #define GET_LONGJMP_TARGET(PC_ADDR) 0 |
| 120 | #endif |
| 121 | |
| 122 | |
| 123 | /* Dynamic function trampolines are similar to solib trampolines in that they |
| 124 | are between the caller and the callee. The difference is that when you |
| 125 | enter a dynamic trampoline, you can't determine the callee's address. Some |
| 126 | (usually complex) code needs to run in the dynamic trampoline to figure out |
| 127 | the callee's address. This macro is usually called twice. First, when we |
| 128 | enter the trampoline (looks like a normal function call at that point). It |
| 129 | should return the PC of a point within the trampoline where the callee's |
| 130 | address is known. Second, when we hit the breakpoint, this routine returns |
| 131 | the callee's address. At that point, things proceed as per a step resume |
| 132 | breakpoint. */ |
| 133 | |
| 134 | #ifndef DYNAMIC_TRAMPOLINE_NEXTPC |
| 135 | #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0 |
| 136 | #endif |
| 137 | |
| 138 | /* If the program uses ELF-style shared libraries, then calls to |
| 139 | functions in shared libraries go through stubs, which live in a |
| 140 | table called the PLT (Procedure Linkage Table). The first time the |
| 141 | function is called, the stub sends control to the dynamic linker, |
| 142 | which looks up the function's real address, patches the stub so |
| 143 | that future calls will go directly to the function, and then passes |
| 144 | control to the function. |
| 145 | |
| 146 | If we are stepping at the source level, we don't want to see any of |
| 147 | this --- we just want to skip over the stub and the dynamic linker. |
| 148 | The simple approach is to single-step until control leaves the |
| 149 | dynamic linker. |
| 150 | |
| 151 | However, on some systems (e.g., Red Hat Linux 5.2) the dynamic |
| 152 | linker calls functions in the shared C library, so you can't tell |
| 153 | from the PC alone whether the dynamic linker is still running. In |
| 154 | this case, we use a step-resume breakpoint to get us past the |
| 155 | dynamic linker, as if we were using "next" to step over a function |
| 156 | call. |
| 157 | |
| 158 | IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic |
| 159 | linker code or not. Normally, this means we single-step. However, |
| 160 | if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an |
| 161 | address where we can place a step-resume breakpoint to get past the |
| 162 | linker's symbol resolution function. |
| 163 | |
| 164 | IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a |
| 165 | pretty portable way, by comparing the PC against the address ranges |
| 166 | of the dynamic linker's sections. |
| 167 | |
| 168 | SKIP_SOLIB_RESOLVER is generally going to be system-specific, since |
| 169 | it depends on internal details of the dynamic linker. It's usually |
| 170 | not too hard to figure out where to put a breakpoint, but it |
| 171 | certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of |
| 172 | sanity checking. If it can't figure things out, returning zero and |
| 173 | getting the (possibly confusing) stepping behavior is better than |
| 174 | signalling an error, which will obscure the change in the |
| 175 | inferior's state. */ |
| 176 | |
| 177 | #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE |
| 178 | #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0 |
| 179 | #endif |
| 180 | |
| 181 | #ifndef SKIP_SOLIB_RESOLVER |
| 182 | #define SKIP_SOLIB_RESOLVER(pc) 0 |
| 183 | #endif |
| 184 | |
| 185 | /* For SVR4 shared libraries, each call goes through a small piece of |
| 186 | trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates |
| 187 | to nonzero if we are current stopped in one of these. */ |
| 188 | |
| 189 | #ifndef IN_SOLIB_CALL_TRAMPOLINE |
| 190 | #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0 |
| 191 | #endif |
| 192 | |
| 193 | /* In some shared library schemes, the return path from a shared library |
| 194 | call may need to go through a trampoline too. */ |
| 195 | |
| 196 | #ifndef IN_SOLIB_RETURN_TRAMPOLINE |
| 197 | #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0 |
| 198 | #endif |
| 199 | |
| 200 | /* This function returns TRUE if pc is the address of an instruction |
| 201 | that lies within the dynamic linker (such as the event hook, or the |
| 202 | dld itself). |
| 203 | |
| 204 | This function must be used only when a dynamic linker event has |
| 205 | been caught, and the inferior is being stepped out of the hook, or |
| 206 | undefined results are guaranteed. */ |
| 207 | |
| 208 | #ifndef SOLIB_IN_DYNAMIC_LINKER |
| 209 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 |
| 210 | #endif |
| 211 | |
| 212 | /* On MIPS16, a function that returns a floating point value may call |
| 213 | a library helper function to copy the return value to a floating point |
| 214 | register. The IGNORE_HELPER_CALL macro returns non-zero if we |
| 215 | should ignore (i.e. step over) this function call. */ |
| 216 | #ifndef IGNORE_HELPER_CALL |
| 217 | #define IGNORE_HELPER_CALL(pc) 0 |
| 218 | #endif |
| 219 | |
| 220 | /* On some systems, the PC may be left pointing at an instruction that won't |
| 221 | actually be executed. This is usually indicated by a bit in the PSW. If |
| 222 | we find ourselves in such a state, then we step the target beyond the |
| 223 | nullified instruction before returning control to the user so as to avoid |
| 224 | confusion. */ |
| 225 | |
| 226 | #ifndef INSTRUCTION_NULLIFIED |
| 227 | #define INSTRUCTION_NULLIFIED 0 |
| 228 | #endif |
| 229 | |
| 230 | /* We can't step off a permanent breakpoint in the ordinary way, because we |
| 231 | can't remove it. Instead, we have to advance the PC to the next |
| 232 | instruction. This macro should expand to a pointer to a function that |
| 233 | does that, or zero if we have no such function. If we don't have a |
| 234 | definition for it, we have to report an error. */ |
| 235 | #ifndef SKIP_PERMANENT_BREAKPOINT |
| 236 | #define SKIP_PERMANENT_BREAKPOINT (default_skip_permanent_breakpoint) |
| 237 | static void |
| 238 | default_skip_permanent_breakpoint (void) |
| 239 | { |
| 240 | error_begin (); |
| 241 | fprintf_filtered (gdb_stderr, "\ |
| 242 | The program is stopped at a permanent breakpoint, but GDB does not know\n\ |
| 243 | how to step past a permanent breakpoint on this architecture. Try using\n\ |
| 244 | a command like `return' or `jump' to continue execution.\n"); |
| 245 | return_to_top_level (RETURN_ERROR); |
| 246 | } |
| 247 | #endif |
| 248 | |
| 249 | |
| 250 | /* Convert the #defines into values. This is temporary until wfi control |
| 251 | flow is completely sorted out. */ |
| 252 | |
| 253 | #ifndef HAVE_STEPPABLE_WATCHPOINT |
| 254 | #define HAVE_STEPPABLE_WATCHPOINT 0 |
| 255 | #else |
| 256 | #undef HAVE_STEPPABLE_WATCHPOINT |
| 257 | #define HAVE_STEPPABLE_WATCHPOINT 1 |
| 258 | #endif |
| 259 | |
| 260 | #ifndef HAVE_NONSTEPPABLE_WATCHPOINT |
| 261 | #define HAVE_NONSTEPPABLE_WATCHPOINT 0 |
| 262 | #else |
| 263 | #undef HAVE_NONSTEPPABLE_WATCHPOINT |
| 264 | #define HAVE_NONSTEPPABLE_WATCHPOINT 1 |
| 265 | #endif |
| 266 | |
| 267 | #ifndef HAVE_CONTINUABLE_WATCHPOINT |
| 268 | #define HAVE_CONTINUABLE_WATCHPOINT 0 |
| 269 | #else |
| 270 | #undef HAVE_CONTINUABLE_WATCHPOINT |
| 271 | #define HAVE_CONTINUABLE_WATCHPOINT 1 |
| 272 | #endif |
| 273 | |
| 274 | #ifndef CANNOT_STEP_HW_WATCHPOINTS |
| 275 | #define CANNOT_STEP_HW_WATCHPOINTS 0 |
| 276 | #else |
| 277 | #undef CANNOT_STEP_HW_WATCHPOINTS |
| 278 | #define CANNOT_STEP_HW_WATCHPOINTS 1 |
| 279 | #endif |
| 280 | |
| 281 | /* Tables of how to react to signals; the user sets them. */ |
| 282 | |
| 283 | static unsigned char *signal_stop; |
| 284 | static unsigned char *signal_print; |
| 285 | static unsigned char *signal_program; |
| 286 | |
| 287 | #define SET_SIGS(nsigs,sigs,flags) \ |
| 288 | do { \ |
| 289 | int signum = (nsigs); \ |
| 290 | while (signum-- > 0) \ |
| 291 | if ((sigs)[signum]) \ |
| 292 | (flags)[signum] = 1; \ |
| 293 | } while (0) |
| 294 | |
| 295 | #define UNSET_SIGS(nsigs,sigs,flags) \ |
| 296 | do { \ |
| 297 | int signum = (nsigs); \ |
| 298 | while (signum-- > 0) \ |
| 299 | if ((sigs)[signum]) \ |
| 300 | (flags)[signum] = 0; \ |
| 301 | } while (0) |
| 302 | |
| 303 | /* Value to pass to target_resume() to cause all threads to resume */ |
| 304 | |
| 305 | #define RESUME_ALL (pid_to_ptid (-1)) |
| 306 | |
| 307 | /* Command list pointer for the "stop" placeholder. */ |
| 308 | |
| 309 | static struct cmd_list_element *stop_command; |
| 310 | |
| 311 | /* Nonzero if breakpoints are now inserted in the inferior. */ |
| 312 | |
| 313 | static int breakpoints_inserted; |
| 314 | |
| 315 | /* Function inferior was in as of last step command. */ |
| 316 | |
| 317 | static struct symbol *step_start_function; |
| 318 | |
| 319 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ |
| 320 | |
| 321 | static int trap_expected; |
| 322 | |
| 323 | #ifdef SOLIB_ADD |
| 324 | /* Nonzero if we want to give control to the user when we're notified |
| 325 | of shared library events by the dynamic linker. */ |
| 326 | static int stop_on_solib_events; |
| 327 | #endif |
| 328 | |
| 329 | #ifdef HP_OS_BUG |
| 330 | /* Nonzero if the next time we try to continue the inferior, it will |
| 331 | step one instruction and generate a spurious trace trap. |
| 332 | This is used to compensate for a bug in HP-UX. */ |
| 333 | |
| 334 | static int trap_expected_after_continue; |
| 335 | #endif |
| 336 | |
| 337 | /* Nonzero means expecting a trace trap |
| 338 | and should stop the inferior and return silently when it happens. */ |
| 339 | |
| 340 | int stop_after_trap; |
| 341 | |
| 342 | /* Nonzero means expecting a trap and caller will handle it themselves. |
| 343 | It is used after attach, due to attaching to a process; |
| 344 | when running in the shell before the child program has been exec'd; |
| 345 | and when running some kinds of remote stuff (FIXME?). */ |
| 346 | |
| 347 | int stop_soon_quietly; |
| 348 | |
| 349 | /* Nonzero if proceed is being used for a "finish" command or a similar |
| 350 | situation when stop_registers should be saved. */ |
| 351 | |
| 352 | int proceed_to_finish; |
| 353 | |
| 354 | /* Save register contents here when about to pop a stack dummy frame, |
| 355 | if-and-only-if proceed_to_finish is set. |
| 356 | Thus this contains the return value from the called function (assuming |
| 357 | values are returned in a register). */ |
| 358 | |
| 359 | char *stop_registers; |
| 360 | |
| 361 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ |
| 362 | |
| 363 | static int breakpoints_failed; |
| 364 | |
| 365 | /* Nonzero after stop if current stack frame should be printed. */ |
| 366 | |
| 367 | static int stop_print_frame; |
| 368 | |
| 369 | static struct breakpoint *step_resume_breakpoint = NULL; |
| 370 | static struct breakpoint *through_sigtramp_breakpoint = NULL; |
| 371 | |
| 372 | /* On some platforms (e.g., HP-UX), hardware watchpoints have bad |
| 373 | interactions with an inferior that is running a kernel function |
| 374 | (aka, a system call or "syscall"). wait_for_inferior therefore |
| 375 | may have a need to know when the inferior is in a syscall. This |
| 376 | is a count of the number of inferior threads which are known to |
| 377 | currently be running in a syscall. */ |
| 378 | static int number_of_threads_in_syscalls; |
| 379 | |
| 380 | /* This is a cached copy of the pid/waitstatus of the last event |
| 381 | returned by target_wait()/target_wait_hook(). This information is |
| 382 | returned by get_last_target_status(). */ |
| 383 | static ptid_t target_last_wait_ptid; |
| 384 | static struct target_waitstatus target_last_waitstatus; |
| 385 | |
| 386 | /* This is used to remember when a fork, vfork or exec event |
| 387 | was caught by a catchpoint, and thus the event is to be |
| 388 | followed at the next resume of the inferior, and not |
| 389 | immediately. */ |
| 390 | static struct |
| 391 | { |
| 392 | enum target_waitkind kind; |
| 393 | struct |
| 394 | { |
| 395 | int parent_pid; |
| 396 | int saw_parent_fork; |
| 397 | int child_pid; |
| 398 | int saw_child_fork; |
| 399 | int saw_child_exec; |
| 400 | } |
| 401 | fork_event; |
| 402 | char *execd_pathname; |
| 403 | } |
| 404 | pending_follow; |
| 405 | |
| 406 | /* Some platforms don't allow us to do anything meaningful with a |
| 407 | vforked child until it has exec'd. Vforked processes on such |
| 408 | platforms can only be followed after they've exec'd. |
| 409 | |
| 410 | When this is set to 0, a vfork can be immediately followed, |
| 411 | and an exec can be followed merely as an exec. When this is |
| 412 | set to 1, a vfork event has been seen, but cannot be followed |
| 413 | until the exec is seen. |
| 414 | |
| 415 | (In the latter case, inferior_ptid is still the parent of the |
| 416 | vfork, and pending_follow.fork_event.child_pid is the child. The |
| 417 | appropriate process is followed, according to the setting of |
| 418 | follow-fork-mode.) */ |
| 419 | static int follow_vfork_when_exec; |
| 420 | |
| 421 | static const char follow_fork_mode_ask[] = "ask"; |
| 422 | static const char follow_fork_mode_both[] = "both"; |
| 423 | static const char follow_fork_mode_child[] = "child"; |
| 424 | static const char follow_fork_mode_parent[] = "parent"; |
| 425 | |
| 426 | static const char *follow_fork_mode_kind_names[] = |
| 427 | { |
| 428 | follow_fork_mode_ask, |
| 429 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 |
| 430 | kernel problem. It's also not terribly useful without a GUI to |
| 431 | help the user drive two debuggers. So for now, I'm disabling the |
| 432 | "both" option. */ |
| 433 | /* follow_fork_mode_both, */ |
| 434 | follow_fork_mode_child, |
| 435 | follow_fork_mode_parent, |
| 436 | NULL |
| 437 | }; |
| 438 | |
| 439 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
| 440 | \f |
| 441 | |
| 442 | static void |
| 443 | follow_inferior_fork (int parent_pid, int child_pid, int has_forked, |
| 444 | int has_vforked) |
| 445 | { |
| 446 | int followed_parent = 0; |
| 447 | int followed_child = 0; |
| 448 | |
| 449 | /* Which process did the user want us to follow? */ |
| 450 | const char *follow_mode = follow_fork_mode_string; |
| 451 | |
| 452 | /* Or, did the user not know, and want us to ask? */ |
| 453 | if (follow_fork_mode_string == follow_fork_mode_ask) |
| 454 | { |
| 455 | internal_error (__FILE__, __LINE__, |
| 456 | "follow_inferior_fork: \"ask\" mode not implemented"); |
| 457 | /* follow_mode = follow_fork_mode_...; */ |
| 458 | } |
| 459 | |
| 460 | /* If we're to be following the parent, then detach from child_pid. |
| 461 | We're already following the parent, so need do nothing explicit |
| 462 | for it. */ |
| 463 | if (follow_mode == follow_fork_mode_parent) |
| 464 | { |
| 465 | followed_parent = 1; |
| 466 | |
| 467 | /* We're already attached to the parent, by default. */ |
| 468 | |
| 469 | /* Before detaching from the child, remove all breakpoints from |
| 470 | it. (This won't actually modify the breakpoint list, but will |
| 471 | physically remove the breakpoints from the child.) */ |
| 472 | if (!has_vforked || !follow_vfork_when_exec) |
| 473 | { |
| 474 | detach_breakpoints (child_pid); |
| 475 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
| 476 | SOLIB_REMOVE_INFERIOR_HOOK (child_pid); |
| 477 | #endif |
| 478 | } |
| 479 | |
| 480 | /* Detach from the child. */ |
| 481 | dont_repeat (); |
| 482 | |
| 483 | target_require_detach (child_pid, "", 1); |
| 484 | } |
| 485 | |
| 486 | /* If we're to be following the child, then attach to it, detach |
| 487 | from inferior_ptid, and set inferior_ptid to child_pid. */ |
| 488 | else if (follow_mode == follow_fork_mode_child) |
| 489 | { |
| 490 | char child_pid_spelling[100]; /* Arbitrary length. */ |
| 491 | |
| 492 | followed_child = 1; |
| 493 | |
| 494 | /* Before detaching from the parent, detach all breakpoints from |
| 495 | the child. But only if we're forking, or if we follow vforks |
| 496 | as soon as they happen. (If we're following vforks only when |
| 497 | the child has exec'd, then it's very wrong to try to write |
| 498 | back the "shadow contents" of inserted breakpoints now -- they |
| 499 | belong to the child's pre-exec'd a.out.) */ |
| 500 | if (!has_vforked || !follow_vfork_when_exec) |
| 501 | { |
| 502 | detach_breakpoints (child_pid); |
| 503 | } |
| 504 | |
| 505 | /* Before detaching from the parent, remove all breakpoints from it. */ |
| 506 | remove_breakpoints (); |
| 507 | |
| 508 | /* Also reset the solib inferior hook from the parent. */ |
| 509 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
| 510 | SOLIB_REMOVE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
| 511 | #endif |
| 512 | |
| 513 | /* Detach from the parent. */ |
| 514 | dont_repeat (); |
| 515 | target_detach (NULL, 1); |
| 516 | |
| 517 | /* Attach to the child. */ |
| 518 | inferior_ptid = pid_to_ptid (child_pid); |
| 519 | sprintf (child_pid_spelling, "%d", child_pid); |
| 520 | dont_repeat (); |
| 521 | |
| 522 | target_require_attach (child_pid_spelling, 1); |
| 523 | |
| 524 | /* Was there a step_resume breakpoint? (There was if the user |
| 525 | did a "next" at the fork() call.) If so, explicitly reset its |
| 526 | thread number. |
| 527 | |
| 528 | step_resumes are a form of bp that are made to be per-thread. |
| 529 | Since we created the step_resume bp when the parent process |
| 530 | was being debugged, and now are switching to the child process, |
| 531 | from the breakpoint package's viewpoint, that's a switch of |
| 532 | "threads". We must update the bp's notion of which thread |
| 533 | it is for, or it'll be ignored when it triggers... */ |
| 534 | if (step_resume_breakpoint && |
| 535 | (!has_vforked || !follow_vfork_when_exec)) |
| 536 | breakpoint_re_set_thread (step_resume_breakpoint); |
| 537 | |
| 538 | /* Reinsert all breakpoints in the child. (The user may've set |
| 539 | breakpoints after catching the fork, in which case those |
| 540 | actually didn't get set in the child, but only in the parent.) */ |
| 541 | if (!has_vforked || !follow_vfork_when_exec) |
| 542 | { |
| 543 | breakpoint_re_set (); |
| 544 | insert_breakpoints (); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | /* If we're to be following both parent and child, then fork ourselves, |
| 549 | and attach the debugger clone to the child. */ |
| 550 | else if (follow_mode == follow_fork_mode_both) |
| 551 | { |
| 552 | char pid_suffix[100]; /* Arbitrary length. */ |
| 553 | |
| 554 | /* Clone ourselves to follow the child. This is the end of our |
| 555 | involvement with child_pid; our clone will take it from here... */ |
| 556 | dont_repeat (); |
| 557 | target_clone_and_follow_inferior (child_pid, &followed_child); |
| 558 | followed_parent = !followed_child; |
| 559 | |
| 560 | /* We continue to follow the parent. To help distinguish the two |
| 561 | debuggers, though, both we and our clone will reset our prompts. */ |
| 562 | sprintf (pid_suffix, "[%d] ", PIDGET (inferior_ptid)); |
| 563 | set_prompt (strcat (get_prompt (), pid_suffix)); |
| 564 | } |
| 565 | |
| 566 | /* The parent and child of a vfork share the same address space. |
| 567 | Also, on some targets the order in which vfork and exec events |
| 568 | are received for parent in child requires some delicate handling |
| 569 | of the events. |
| 570 | |
| 571 | For instance, on ptrace-based HPUX we receive the child's vfork |
| 572 | event first, at which time the parent has been suspended by the |
| 573 | OS and is essentially untouchable until the child's exit or second |
| 574 | exec event arrives. At that time, the parent's vfork event is |
| 575 | delivered to us, and that's when we see and decide how to follow |
| 576 | the vfork. But to get to that point, we must continue the child |
| 577 | until it execs or exits. To do that smoothly, all breakpoints |
| 578 | must be removed from the child, in case there are any set between |
| 579 | the vfork() and exec() calls. But removing them from the child |
| 580 | also removes them from the parent, due to the shared-address-space |
| 581 | nature of a vfork'd parent and child. On HPUX, therefore, we must |
| 582 | take care to restore the bp's to the parent before we continue it. |
| 583 | Else, it's likely that we may not stop in the expected place. (The |
| 584 | worst scenario is when the user tries to step over a vfork() call; |
| 585 | the step-resume bp must be restored for the step to properly stop |
| 586 | in the parent after the call completes!) |
| 587 | |
| 588 | Sequence of events, as reported to gdb from HPUX: |
| 589 | |
| 590 | Parent Child Action for gdb to take |
| 591 | ------------------------------------------------------- |
| 592 | 1 VFORK Continue child |
| 593 | 2 EXEC |
| 594 | 3 EXEC or EXIT |
| 595 | 4 VFORK */ |
| 596 | if (has_vforked) |
| 597 | { |
| 598 | target_post_follow_vfork (parent_pid, |
| 599 | followed_parent, |
| 600 | child_pid, |
| 601 | followed_child); |
| 602 | } |
| 603 | |
| 604 | pending_follow.fork_event.saw_parent_fork = 0; |
| 605 | pending_follow.fork_event.saw_child_fork = 0; |
| 606 | } |
| 607 | |
| 608 | static void |
| 609 | follow_fork (int parent_pid, int child_pid) |
| 610 | { |
| 611 | follow_inferior_fork (parent_pid, child_pid, 1, 0); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | /* Forward declaration. */ |
| 616 | static void follow_exec (int, char *); |
| 617 | |
| 618 | static void |
| 619 | follow_vfork (int parent_pid, int child_pid) |
| 620 | { |
| 621 | follow_inferior_fork (parent_pid, child_pid, 0, 1); |
| 622 | |
| 623 | /* Did we follow the child? Had it exec'd before we saw the parent vfork? */ |
| 624 | if (pending_follow.fork_event.saw_child_exec |
| 625 | && (PIDGET (inferior_ptid) == child_pid)) |
| 626 | { |
| 627 | pending_follow.fork_event.saw_child_exec = 0; |
| 628 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
| 629 | follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); |
| 630 | xfree (pending_follow.execd_pathname); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
| 635 | |
| 636 | static void |
| 637 | follow_exec (int pid, char *execd_pathname) |
| 638 | { |
| 639 | int saved_pid = pid; |
| 640 | struct target_ops *tgt; |
| 641 | |
| 642 | if (!may_follow_exec) |
| 643 | return; |
| 644 | |
| 645 | /* Did this exec() follow a vfork()? If so, we must follow the |
| 646 | vfork now too. Do it before following the exec. */ |
| 647 | if (follow_vfork_when_exec && |
| 648 | (pending_follow.kind == TARGET_WAITKIND_VFORKED)) |
| 649 | { |
| 650 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
| 651 | follow_vfork (PIDGET (inferior_ptid), |
| 652 | pending_follow.fork_event.child_pid); |
| 653 | follow_vfork_when_exec = 0; |
| 654 | saved_pid = PIDGET (inferior_ptid); |
| 655 | |
| 656 | /* Did we follow the parent? If so, we're done. If we followed |
| 657 | the child then we must also follow its exec(). */ |
| 658 | if (PIDGET (inferior_ptid) == pending_follow.fork_event.parent_pid) |
| 659 | return; |
| 660 | } |
| 661 | |
| 662 | /* This is an exec event that we actually wish to pay attention to. |
| 663 | Refresh our symbol table to the newly exec'd program, remove any |
| 664 | momentary bp's, etc. |
| 665 | |
| 666 | If there are breakpoints, they aren't really inserted now, |
| 667 | since the exec() transformed our inferior into a fresh set |
| 668 | of instructions. |
| 669 | |
| 670 | We want to preserve symbolic breakpoints on the list, since |
| 671 | we have hopes that they can be reset after the new a.out's |
| 672 | symbol table is read. |
| 673 | |
| 674 | However, any "raw" breakpoints must be removed from the list |
| 675 | (e.g., the solib bp's), since their address is probably invalid |
| 676 | now. |
| 677 | |
| 678 | And, we DON'T want to call delete_breakpoints() here, since |
| 679 | that may write the bp's "shadow contents" (the instruction |
| 680 | value that was overwritten witha TRAP instruction). Since |
| 681 | we now have a new a.out, those shadow contents aren't valid. */ |
| 682 | update_breakpoints_after_exec (); |
| 683 | |
| 684 | /* If there was one, it's gone now. We cannot truly step-to-next |
| 685 | statement through an exec(). */ |
| 686 | step_resume_breakpoint = NULL; |
| 687 | step_range_start = 0; |
| 688 | step_range_end = 0; |
| 689 | |
| 690 | /* If there was one, it's gone now. */ |
| 691 | through_sigtramp_breakpoint = NULL; |
| 692 | |
| 693 | /* What is this a.out's name? */ |
| 694 | printf_unfiltered ("Executing new program: %s\n", execd_pathname); |
| 695 | |
| 696 | /* We've followed the inferior through an exec. Therefore, the |
| 697 | inferior has essentially been killed & reborn. */ |
| 698 | |
| 699 | /* First collect the run target in effect. */ |
| 700 | tgt = find_run_target (); |
| 701 | /* If we can't find one, things are in a very strange state... */ |
| 702 | if (tgt == NULL) |
| 703 | error ("Could find run target to save before following exec"); |
| 704 | |
| 705 | gdb_flush (gdb_stdout); |
| 706 | target_mourn_inferior (); |
| 707 | inferior_ptid = pid_to_ptid (saved_pid); |
| 708 | /* Because mourn_inferior resets inferior_ptid. */ |
| 709 | push_target (tgt); |
| 710 | |
| 711 | /* That a.out is now the one to use. */ |
| 712 | exec_file_attach (execd_pathname, 0); |
| 713 | |
| 714 | /* And also is where symbols can be found. */ |
| 715 | symbol_file_add_main (execd_pathname, 0); |
| 716 | |
| 717 | /* Reset the shared library package. This ensures that we get |
| 718 | a shlib event when the child reaches "_start", at which point |
| 719 | the dld will have had a chance to initialize the child. */ |
| 720 | #if defined(SOLIB_RESTART) |
| 721 | SOLIB_RESTART (); |
| 722 | #endif |
| 723 | #ifdef SOLIB_CREATE_INFERIOR_HOOK |
| 724 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
| 725 | #endif |
| 726 | |
| 727 | /* Reinsert all breakpoints. (Those which were symbolic have |
| 728 | been reset to the proper address in the new a.out, thanks |
| 729 | to symbol_file_command...) */ |
| 730 | insert_breakpoints (); |
| 731 | |
| 732 | /* The next resume of this inferior should bring it to the shlib |
| 733 | startup breakpoints. (If the user had also set bp's on |
| 734 | "main" from the old (parent) process, then they'll auto- |
| 735 | matically get reset there in the new process.) */ |
| 736 | } |
| 737 | |
| 738 | /* Non-zero if we just simulating a single-step. This is needed |
| 739 | because we cannot remove the breakpoints in the inferior process |
| 740 | until after the `wait' in `wait_for_inferior'. */ |
| 741 | static int singlestep_breakpoints_inserted_p = 0; |
| 742 | \f |
| 743 | |
| 744 | /* Things to clean up if we QUIT out of resume (). */ |
| 745 | /* ARGSUSED */ |
| 746 | static void |
| 747 | resume_cleanups (void *ignore) |
| 748 | { |
| 749 | normal_stop (); |
| 750 | } |
| 751 | |
| 752 | static const char schedlock_off[] = "off"; |
| 753 | static const char schedlock_on[] = "on"; |
| 754 | static const char schedlock_step[] = "step"; |
| 755 | static const char *scheduler_mode = schedlock_off; |
| 756 | static const char *scheduler_enums[] = |
| 757 | { |
| 758 | schedlock_off, |
| 759 | schedlock_on, |
| 760 | schedlock_step, |
| 761 | NULL |
| 762 | }; |
| 763 | |
| 764 | static void |
| 765 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
| 766 | { |
| 767 | if (c->type == set_cmd) |
| 768 | if (!target_can_lock_scheduler) |
| 769 | { |
| 770 | scheduler_mode = schedlock_off; |
| 771 | error ("Target '%s' cannot support this command.", |
| 772 | target_shortname); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | |
| 777 | /* Resume the inferior, but allow a QUIT. This is useful if the user |
| 778 | wants to interrupt some lengthy single-stepping operation |
| 779 | (for child processes, the SIGINT goes to the inferior, and so |
| 780 | we get a SIGINT random_signal, but for remote debugging and perhaps |
| 781 | other targets, that's not true). |
| 782 | |
| 783 | STEP nonzero if we should step (zero to continue instead). |
| 784 | SIG is the signal to give the inferior (zero for none). */ |
| 785 | void |
| 786 | resume (int step, enum target_signal sig) |
| 787 | { |
| 788 | int should_resume = 1; |
| 789 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
| 790 | QUIT; |
| 791 | |
| 792 | /* FIXME: calling breakpoint_here_p (read_pc ()) three times! */ |
| 793 | |
| 794 | |
| 795 | /* Some targets (e.g. Solaris x86) have a kernel bug when stepping |
| 796 | over an instruction that causes a page fault without triggering |
| 797 | a hardware watchpoint. The kernel properly notices that it shouldn't |
| 798 | stop, because the hardware watchpoint is not triggered, but it forgets |
| 799 | the step request and continues the program normally. |
| 800 | Work around the problem by removing hardware watchpoints if a step is |
| 801 | requested, GDB will check for a hardware watchpoint trigger after the |
| 802 | step anyway. */ |
| 803 | if (CANNOT_STEP_HW_WATCHPOINTS && step && breakpoints_inserted) |
| 804 | remove_hw_watchpoints (); |
| 805 | |
| 806 | |
| 807 | /* Normally, by the time we reach `resume', the breakpoints are either |
| 808 | removed or inserted, as appropriate. The exception is if we're sitting |
| 809 | at a permanent breakpoint; we need to step over it, but permanent |
| 810 | breakpoints can't be removed. So we have to test for it here. */ |
| 811 | if (breakpoint_here_p (read_pc ()) == permanent_breakpoint_here) |
| 812 | SKIP_PERMANENT_BREAKPOINT (); |
| 813 | |
| 814 | if (SOFTWARE_SINGLE_STEP_P () && step) |
| 815 | { |
| 816 | /* Do it the hard way, w/temp breakpoints */ |
| 817 | SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ ); |
| 818 | /* ...and don't ask hardware to do it. */ |
| 819 | step = 0; |
| 820 | /* and do not pull these breakpoints until after a `wait' in |
| 821 | `wait_for_inferior' */ |
| 822 | singlestep_breakpoints_inserted_p = 1; |
| 823 | } |
| 824 | |
| 825 | /* Handle any optimized stores to the inferior NOW... */ |
| 826 | #ifdef DO_DEFERRED_STORES |
| 827 | DO_DEFERRED_STORES; |
| 828 | #endif |
| 829 | |
| 830 | /* If there were any forks/vforks/execs that were caught and are |
| 831 | now to be followed, then do so. */ |
| 832 | switch (pending_follow.kind) |
| 833 | { |
| 834 | case (TARGET_WAITKIND_FORKED): |
| 835 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
| 836 | follow_fork (PIDGET (inferior_ptid), |
| 837 | pending_follow.fork_event.child_pid); |
| 838 | break; |
| 839 | |
| 840 | case (TARGET_WAITKIND_VFORKED): |
| 841 | { |
| 842 | int saw_child_exec = pending_follow.fork_event.saw_child_exec; |
| 843 | |
| 844 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
| 845 | follow_vfork (PIDGET (inferior_ptid), |
| 846 | pending_follow.fork_event.child_pid); |
| 847 | |
| 848 | /* Did we follow the child, but not yet see the child's exec event? |
| 849 | If so, then it actually ought to be waiting for us; we respond to |
| 850 | parent vfork events. We don't actually want to resume the child |
| 851 | in this situation; we want to just get its exec event. */ |
| 852 | if (!saw_child_exec && |
| 853 | (PIDGET (inferior_ptid) == pending_follow.fork_event.child_pid)) |
| 854 | should_resume = 0; |
| 855 | } |
| 856 | break; |
| 857 | |
| 858 | case (TARGET_WAITKIND_EXECD): |
| 859 | /* If we saw a vfork event but couldn't follow it until we saw |
| 860 | an exec, then now might be the time! */ |
| 861 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
| 862 | /* follow_exec is called as soon as the exec event is seen. */ |
| 863 | break; |
| 864 | |
| 865 | default: |
| 866 | break; |
| 867 | } |
| 868 | |
| 869 | /* Install inferior's terminal modes. */ |
| 870 | target_terminal_inferior (); |
| 871 | |
| 872 | if (should_resume) |
| 873 | { |
| 874 | ptid_t resume_ptid; |
| 875 | |
| 876 | resume_ptid = RESUME_ALL; /* Default */ |
| 877 | |
| 878 | if ((step || singlestep_breakpoints_inserted_p) && |
| 879 | !breakpoints_inserted && breakpoint_here_p (read_pc ())) |
| 880 | { |
| 881 | /* Stepping past a breakpoint without inserting breakpoints. |
| 882 | Make sure only the current thread gets to step, so that |
| 883 | other threads don't sneak past breakpoints while they are |
| 884 | not inserted. */ |
| 885 | |
| 886 | resume_ptid = inferior_ptid; |
| 887 | } |
| 888 | |
| 889 | if ((scheduler_mode == schedlock_on) || |
| 890 | (scheduler_mode == schedlock_step && |
| 891 | (step || singlestep_breakpoints_inserted_p))) |
| 892 | { |
| 893 | /* User-settable 'scheduler' mode requires solo thread resume. */ |
| 894 | resume_ptid = inferior_ptid; |
| 895 | } |
| 896 | |
| 897 | #ifdef CANNOT_STEP_BREAKPOINT |
| 898 | /* Most targets can step a breakpoint instruction, thus executing it |
| 899 | normally. But if this one cannot, just continue and we will hit |
| 900 | it anyway. */ |
| 901 | if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) |
| 902 | step = 0; |
| 903 | #endif |
| 904 | target_resume (resume_ptid, step, sig); |
| 905 | } |
| 906 | |
| 907 | discard_cleanups (old_cleanups); |
| 908 | } |
| 909 | \f |
| 910 | |
| 911 | /* Clear out all variables saying what to do when inferior is continued. |
| 912 | First do this, then set the ones you want, then call `proceed'. */ |
| 913 | |
| 914 | void |
| 915 | clear_proceed_status (void) |
| 916 | { |
| 917 | trap_expected = 0; |
| 918 | step_range_start = 0; |
| 919 | step_range_end = 0; |
| 920 | step_frame_address = 0; |
| 921 | step_over_calls = STEP_OVER_UNDEBUGGABLE; |
| 922 | stop_after_trap = 0; |
| 923 | stop_soon_quietly = 0; |
| 924 | proceed_to_finish = 0; |
| 925 | breakpoint_proceeded = 1; /* We're about to proceed... */ |
| 926 | |
| 927 | /* Discard any remaining commands or status from previous stop. */ |
| 928 | bpstat_clear (&stop_bpstat); |
| 929 | } |
| 930 | |
| 931 | /* Basic routine for continuing the program in various fashions. |
| 932 | |
| 933 | ADDR is the address to resume at, or -1 for resume where stopped. |
| 934 | SIGGNAL is the signal to give it, or 0 for none, |
| 935 | or -1 for act according to how it stopped. |
| 936 | STEP is nonzero if should trap after one instruction. |
| 937 | -1 means return after that and print nothing. |
| 938 | You should probably set various step_... variables |
| 939 | before calling here, if you are stepping. |
| 940 | |
| 941 | You should call clear_proceed_status before calling proceed. */ |
| 942 | |
| 943 | void |
| 944 | proceed (CORE_ADDR addr, enum target_signal siggnal, int step) |
| 945 | { |
| 946 | int oneproc = 0; |
| 947 | |
| 948 | if (step > 0) |
| 949 | step_start_function = find_pc_function (read_pc ()); |
| 950 | if (step < 0) |
| 951 | stop_after_trap = 1; |
| 952 | |
| 953 | if (addr == (CORE_ADDR) -1) |
| 954 | { |
| 955 | /* If there is a breakpoint at the address we will resume at, |
| 956 | step one instruction before inserting breakpoints |
| 957 | so that we do not stop right away (and report a second |
| 958 | hit at this breakpoint). */ |
| 959 | |
| 960 | if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) |
| 961 | oneproc = 1; |
| 962 | |
| 963 | #ifndef STEP_SKIPS_DELAY |
| 964 | #define STEP_SKIPS_DELAY(pc) (0) |
| 965 | #define STEP_SKIPS_DELAY_P (0) |
| 966 | #endif |
| 967 | /* Check breakpoint_here_p first, because breakpoint_here_p is fast |
| 968 | (it just checks internal GDB data structures) and STEP_SKIPS_DELAY |
| 969 | is slow (it needs to read memory from the target). */ |
| 970 | if (STEP_SKIPS_DELAY_P |
| 971 | && breakpoint_here_p (read_pc () + 4) |
| 972 | && STEP_SKIPS_DELAY (read_pc ())) |
| 973 | oneproc = 1; |
| 974 | } |
| 975 | else |
| 976 | { |
| 977 | write_pc (addr); |
| 978 | } |
| 979 | |
| 980 | #ifdef PREPARE_TO_PROCEED |
| 981 | /* In a multi-threaded task we may select another thread |
| 982 | and then continue or step. |
| 983 | |
| 984 | But if the old thread was stopped at a breakpoint, it |
| 985 | will immediately cause another breakpoint stop without |
| 986 | any execution (i.e. it will report a breakpoint hit |
| 987 | incorrectly). So we must step over it first. |
| 988 | |
| 989 | PREPARE_TO_PROCEED checks the current thread against the thread |
| 990 | that reported the most recent event. If a step-over is required |
| 991 | it returns TRUE and sets the current thread to the old thread. */ |
| 992 | if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ())) |
| 993 | { |
| 994 | oneproc = 1; |
| 995 | } |
| 996 | |
| 997 | #endif /* PREPARE_TO_PROCEED */ |
| 998 | |
| 999 | #ifdef HP_OS_BUG |
| 1000 | if (trap_expected_after_continue) |
| 1001 | { |
| 1002 | /* If (step == 0), a trap will be automatically generated after |
| 1003 | the first instruction is executed. Force step one |
| 1004 | instruction to clear this condition. This should not occur |
| 1005 | if step is nonzero, but it is harmless in that case. */ |
| 1006 | oneproc = 1; |
| 1007 | trap_expected_after_continue = 0; |
| 1008 | } |
| 1009 | #endif /* HP_OS_BUG */ |
| 1010 | |
| 1011 | if (oneproc) |
| 1012 | /* We will get a trace trap after one instruction. |
| 1013 | Continue it automatically and insert breakpoints then. */ |
| 1014 | trap_expected = 1; |
| 1015 | else |
| 1016 | { |
| 1017 | int temp = insert_breakpoints (); |
| 1018 | if (temp) |
| 1019 | { |
| 1020 | print_sys_errmsg ("insert_breakpoints", temp); |
| 1021 | error ("Cannot insert breakpoints.\n\ |
| 1022 | The same program may be running in another process,\n\ |
| 1023 | or you may have requested too many hardware\n\ |
| 1024 | breakpoints and/or watchpoints.\n"); |
| 1025 | } |
| 1026 | |
| 1027 | breakpoints_inserted = 1; |
| 1028 | } |
| 1029 | |
| 1030 | if (siggnal != TARGET_SIGNAL_DEFAULT) |
| 1031 | stop_signal = siggnal; |
| 1032 | /* If this signal should not be seen by program, |
| 1033 | give it zero. Used for debugging signals. */ |
| 1034 | else if (!signal_program[stop_signal]) |
| 1035 | stop_signal = TARGET_SIGNAL_0; |
| 1036 | |
| 1037 | annotate_starting (); |
| 1038 | |
| 1039 | /* Make sure that output from GDB appears before output from the |
| 1040 | inferior. */ |
| 1041 | gdb_flush (gdb_stdout); |
| 1042 | |
| 1043 | /* Resume inferior. */ |
| 1044 | resume (oneproc || step || bpstat_should_step (), stop_signal); |
| 1045 | |
| 1046 | /* Wait for it to stop (if not standalone) |
| 1047 | and in any case decode why it stopped, and act accordingly. */ |
| 1048 | /* Do this only if we are not using the event loop, or if the target |
| 1049 | does not support asynchronous execution. */ |
| 1050 | if (!event_loop_p || !target_can_async_p ()) |
| 1051 | { |
| 1052 | wait_for_inferior (); |
| 1053 | normal_stop (); |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | /* Record the pc and sp of the program the last time it stopped. |
| 1058 | These are just used internally by wait_for_inferior, but need |
| 1059 | to be preserved over calls to it and cleared when the inferior |
| 1060 | is started. */ |
| 1061 | static CORE_ADDR prev_pc; |
| 1062 | static CORE_ADDR prev_func_start; |
| 1063 | static char *prev_func_name; |
| 1064 | \f |
| 1065 | |
| 1066 | /* Start remote-debugging of a machine over a serial link. */ |
| 1067 | |
| 1068 | void |
| 1069 | start_remote (void) |
| 1070 | { |
| 1071 | init_thread_list (); |
| 1072 | init_wait_for_inferior (); |
| 1073 | stop_soon_quietly = 1; |
| 1074 | trap_expected = 0; |
| 1075 | |
| 1076 | /* Always go on waiting for the target, regardless of the mode. */ |
| 1077 | /* FIXME: cagney/1999-09-23: At present it isn't possible to |
| 1078 | indicate to wait_for_inferior that a target should timeout if |
| 1079 | nothing is returned (instead of just blocking). Because of this, |
| 1080 | targets expecting an immediate response need to, internally, set |
| 1081 | things up so that the target_wait() is forced to eventually |
| 1082 | timeout. */ |
| 1083 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to |
| 1084 | differentiate to its caller what the state of the target is after |
| 1085 | the initial open has been performed. Here we're assuming that |
| 1086 | the target has stopped. It should be possible to eventually have |
| 1087 | target_open() return to the caller an indication that the target |
| 1088 | is currently running and GDB state should be set to the same as |
| 1089 | for an async run. */ |
| 1090 | wait_for_inferior (); |
| 1091 | normal_stop (); |
| 1092 | } |
| 1093 | |
| 1094 | /* Initialize static vars when a new inferior begins. */ |
| 1095 | |
| 1096 | void |
| 1097 | init_wait_for_inferior (void) |
| 1098 | { |
| 1099 | /* These are meaningless until the first time through wait_for_inferior. */ |
| 1100 | prev_pc = 0; |
| 1101 | prev_func_start = 0; |
| 1102 | prev_func_name = NULL; |
| 1103 | |
| 1104 | #ifdef HP_OS_BUG |
| 1105 | trap_expected_after_continue = 0; |
| 1106 | #endif |
| 1107 | breakpoints_inserted = 0; |
| 1108 | breakpoint_init_inferior (inf_starting); |
| 1109 | |
| 1110 | /* Don't confuse first call to proceed(). */ |
| 1111 | stop_signal = TARGET_SIGNAL_0; |
| 1112 | |
| 1113 | /* The first resume is not following a fork/vfork/exec. */ |
| 1114 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ |
| 1115 | pending_follow.fork_event.saw_parent_fork = 0; |
| 1116 | pending_follow.fork_event.saw_child_fork = 0; |
| 1117 | pending_follow.fork_event.saw_child_exec = 0; |
| 1118 | |
| 1119 | /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */ |
| 1120 | number_of_threads_in_syscalls = 0; |
| 1121 | |
| 1122 | clear_proceed_status (); |
| 1123 | } |
| 1124 | |
| 1125 | static void |
| 1126 | delete_breakpoint_current_contents (void *arg) |
| 1127 | { |
| 1128 | struct breakpoint **breakpointp = (struct breakpoint **) arg; |
| 1129 | if (*breakpointp != NULL) |
| 1130 | { |
| 1131 | delete_breakpoint (*breakpointp); |
| 1132 | *breakpointp = NULL; |
| 1133 | } |
| 1134 | } |
| 1135 | \f |
| 1136 | /* This enum encodes possible reasons for doing a target_wait, so that |
| 1137 | wfi can call target_wait in one place. (Ultimately the call will be |
| 1138 | moved out of the infinite loop entirely.) */ |
| 1139 | |
| 1140 | enum infwait_states |
| 1141 | { |
| 1142 | infwait_normal_state, |
| 1143 | infwait_thread_hop_state, |
| 1144 | infwait_nullified_state, |
| 1145 | infwait_nonstep_watch_state |
| 1146 | }; |
| 1147 | |
| 1148 | /* Why did the inferior stop? Used to print the appropriate messages |
| 1149 | to the interface from within handle_inferior_event(). */ |
| 1150 | enum inferior_stop_reason |
| 1151 | { |
| 1152 | /* We don't know why. */ |
| 1153 | STOP_UNKNOWN, |
| 1154 | /* Step, next, nexti, stepi finished. */ |
| 1155 | END_STEPPING_RANGE, |
| 1156 | /* Found breakpoint. */ |
| 1157 | BREAKPOINT_HIT, |
| 1158 | /* Inferior terminated by signal. */ |
| 1159 | SIGNAL_EXITED, |
| 1160 | /* Inferior exited. */ |
| 1161 | EXITED, |
| 1162 | /* Inferior received signal, and user asked to be notified. */ |
| 1163 | SIGNAL_RECEIVED |
| 1164 | }; |
| 1165 | |
| 1166 | /* This structure contains what used to be local variables in |
| 1167 | wait_for_inferior. Probably many of them can return to being |
| 1168 | locals in handle_inferior_event. */ |
| 1169 | |
| 1170 | struct execution_control_state |
| 1171 | { |
| 1172 | struct target_waitstatus ws; |
| 1173 | struct target_waitstatus *wp; |
| 1174 | int another_trap; |
| 1175 | int random_signal; |
| 1176 | CORE_ADDR stop_func_start; |
| 1177 | CORE_ADDR stop_func_end; |
| 1178 | char *stop_func_name; |
| 1179 | struct symtab_and_line sal; |
| 1180 | int remove_breakpoints_on_following_step; |
| 1181 | int current_line; |
| 1182 | struct symtab *current_symtab; |
| 1183 | int handling_longjmp; /* FIXME */ |
| 1184 | ptid_t ptid; |
| 1185 | ptid_t saved_inferior_ptid; |
| 1186 | int update_step_sp; |
| 1187 | int stepping_through_solib_after_catch; |
| 1188 | bpstat stepping_through_solib_catchpoints; |
| 1189 | int enable_hw_watchpoints_after_wait; |
| 1190 | int stepping_through_sigtramp; |
| 1191 | int new_thread_event; |
| 1192 | struct target_waitstatus tmpstatus; |
| 1193 | enum infwait_states infwait_state; |
| 1194 | ptid_t waiton_ptid; |
| 1195 | int wait_some_more; |
| 1196 | }; |
| 1197 | |
| 1198 | void init_execution_control_state (struct execution_control_state * ecs); |
| 1199 | |
| 1200 | void handle_inferior_event (struct execution_control_state * ecs); |
| 1201 | |
| 1202 | static void check_sigtramp2 (struct execution_control_state *ecs); |
| 1203 | static void step_into_function (struct execution_control_state *ecs); |
| 1204 | static void step_over_function (struct execution_control_state *ecs); |
| 1205 | static void stop_stepping (struct execution_control_state *ecs); |
| 1206 | static void prepare_to_wait (struct execution_control_state *ecs); |
| 1207 | static void keep_going (struct execution_control_state *ecs); |
| 1208 | static void print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info); |
| 1209 | |
| 1210 | /* Wait for control to return from inferior to debugger. |
| 1211 | If inferior gets a signal, we may decide to start it up again |
| 1212 | instead of returning. That is why there is a loop in this function. |
| 1213 | When this function actually returns it means the inferior |
| 1214 | should be left stopped and GDB should read more commands. */ |
| 1215 | |
| 1216 | void |
| 1217 | wait_for_inferior (void) |
| 1218 | { |
| 1219 | struct cleanup *old_cleanups; |
| 1220 | struct execution_control_state ecss; |
| 1221 | struct execution_control_state *ecs; |
| 1222 | |
| 1223 | old_cleanups = make_cleanup (delete_step_resume_breakpoint, |
| 1224 | &step_resume_breakpoint); |
| 1225 | make_cleanup (delete_breakpoint_current_contents, |
| 1226 | &through_sigtramp_breakpoint); |
| 1227 | |
| 1228 | /* wfi still stays in a loop, so it's OK just to take the address of |
| 1229 | a local to get the ecs pointer. */ |
| 1230 | ecs = &ecss; |
| 1231 | |
| 1232 | /* Fill in with reasonable starting values. */ |
| 1233 | init_execution_control_state (ecs); |
| 1234 | |
| 1235 | /* We'll update this if & when we switch to a new thread. */ |
| 1236 | previous_inferior_ptid = inferior_ptid; |
| 1237 | |
| 1238 | overlay_cache_invalid = 1; |
| 1239 | |
| 1240 | /* We have to invalidate the registers BEFORE calling target_wait |
| 1241 | because they can be loaded from the target while in target_wait. |
| 1242 | This makes remote debugging a bit more efficient for those |
| 1243 | targets that provide critical registers as part of their normal |
| 1244 | status mechanism. */ |
| 1245 | |
| 1246 | registers_changed (); |
| 1247 | |
| 1248 | while (1) |
| 1249 | { |
| 1250 | if (target_wait_hook) |
| 1251 | ecs->ptid = target_wait_hook (ecs->waiton_ptid, ecs->wp); |
| 1252 | else |
| 1253 | ecs->ptid = target_wait (ecs->waiton_ptid, ecs->wp); |
| 1254 | |
| 1255 | /* Now figure out what to do with the result of the result. */ |
| 1256 | handle_inferior_event (ecs); |
| 1257 | |
| 1258 | if (!ecs->wait_some_more) |
| 1259 | break; |
| 1260 | } |
| 1261 | do_cleanups (old_cleanups); |
| 1262 | } |
| 1263 | |
| 1264 | /* Asynchronous version of wait_for_inferior. It is called by the |
| 1265 | event loop whenever a change of state is detected on the file |
| 1266 | descriptor corresponding to the target. It can be called more than |
| 1267 | once to complete a single execution command. In such cases we need |
| 1268 | to keep the state in a global variable ASYNC_ECSS. If it is the |
| 1269 | last time that this function is called for a single execution |
| 1270 | command, then report to the user that the inferior has stopped, and |
| 1271 | do the necessary cleanups. */ |
| 1272 | |
| 1273 | struct execution_control_state async_ecss; |
| 1274 | struct execution_control_state *async_ecs; |
| 1275 | |
| 1276 | void |
| 1277 | fetch_inferior_event (void *client_data) |
| 1278 | { |
| 1279 | static struct cleanup *old_cleanups; |
| 1280 | |
| 1281 | async_ecs = &async_ecss; |
| 1282 | |
| 1283 | if (!async_ecs->wait_some_more) |
| 1284 | { |
| 1285 | old_cleanups = make_exec_cleanup (delete_step_resume_breakpoint, |
| 1286 | &step_resume_breakpoint); |
| 1287 | make_exec_cleanup (delete_breakpoint_current_contents, |
| 1288 | &through_sigtramp_breakpoint); |
| 1289 | |
| 1290 | /* Fill in with reasonable starting values. */ |
| 1291 | init_execution_control_state (async_ecs); |
| 1292 | |
| 1293 | /* We'll update this if & when we switch to a new thread. */ |
| 1294 | previous_inferior_ptid = inferior_ptid; |
| 1295 | |
| 1296 | overlay_cache_invalid = 1; |
| 1297 | |
| 1298 | /* We have to invalidate the registers BEFORE calling target_wait |
| 1299 | because they can be loaded from the target while in target_wait. |
| 1300 | This makes remote debugging a bit more efficient for those |
| 1301 | targets that provide critical registers as part of their normal |
| 1302 | status mechanism. */ |
| 1303 | |
| 1304 | registers_changed (); |
| 1305 | } |
| 1306 | |
| 1307 | if (target_wait_hook) |
| 1308 | async_ecs->ptid = target_wait_hook (async_ecs->waiton_ptid, async_ecs->wp); |
| 1309 | else |
| 1310 | async_ecs->ptid = target_wait (async_ecs->waiton_ptid, async_ecs->wp); |
| 1311 | |
| 1312 | /* Now figure out what to do with the result of the result. */ |
| 1313 | handle_inferior_event (async_ecs); |
| 1314 | |
| 1315 | if (!async_ecs->wait_some_more) |
| 1316 | { |
| 1317 | /* Do only the cleanups that have been added by this |
| 1318 | function. Let the continuations for the commands do the rest, |
| 1319 | if there are any. */ |
| 1320 | do_exec_cleanups (old_cleanups); |
| 1321 | normal_stop (); |
| 1322 | if (step_multi && stop_step) |
| 1323 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); |
| 1324 | else |
| 1325 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | /* Prepare an execution control state for looping through a |
| 1330 | wait_for_inferior-type loop. */ |
| 1331 | |
| 1332 | void |
| 1333 | init_execution_control_state (struct execution_control_state *ecs) |
| 1334 | { |
| 1335 | /* ecs->another_trap? */ |
| 1336 | ecs->random_signal = 0; |
| 1337 | ecs->remove_breakpoints_on_following_step = 0; |
| 1338 | ecs->handling_longjmp = 0; /* FIXME */ |
| 1339 | ecs->update_step_sp = 0; |
| 1340 | ecs->stepping_through_solib_after_catch = 0; |
| 1341 | ecs->stepping_through_solib_catchpoints = NULL; |
| 1342 | ecs->enable_hw_watchpoints_after_wait = 0; |
| 1343 | ecs->stepping_through_sigtramp = 0; |
| 1344 | ecs->sal = find_pc_line (prev_pc, 0); |
| 1345 | ecs->current_line = ecs->sal.line; |
| 1346 | ecs->current_symtab = ecs->sal.symtab; |
| 1347 | ecs->infwait_state = infwait_normal_state; |
| 1348 | ecs->waiton_ptid = pid_to_ptid (-1); |
| 1349 | ecs->wp = &(ecs->ws); |
| 1350 | } |
| 1351 | |
| 1352 | /* Call this function before setting step_resume_breakpoint, as a |
| 1353 | sanity check. There should never be more than one step-resume |
| 1354 | breakpoint per thread, so we should never be setting a new |
| 1355 | step_resume_breakpoint when one is already active. */ |
| 1356 | static void |
| 1357 | check_for_old_step_resume_breakpoint (void) |
| 1358 | { |
| 1359 | if (step_resume_breakpoint) |
| 1360 | warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint"); |
| 1361 | } |
| 1362 | |
| 1363 | /* Return the cached copy of the last pid/waitstatus returned by |
| 1364 | target_wait()/target_wait_hook(). The data is actually cached by |
| 1365 | handle_inferior_event(), which gets called immediately after |
| 1366 | target_wait()/target_wait_hook(). */ |
| 1367 | |
| 1368 | void |
| 1369 | get_last_target_status(ptid_t *ptidp, struct target_waitstatus *status) |
| 1370 | { |
| 1371 | *ptidp = target_last_wait_ptid; |
| 1372 | *status = target_last_waitstatus; |
| 1373 | } |
| 1374 | |
| 1375 | /* Switch thread contexts, maintaining "infrun state". */ |
| 1376 | |
| 1377 | static void |
| 1378 | context_switch (struct execution_control_state *ecs) |
| 1379 | { |
| 1380 | /* Caution: it may happen that the new thread (or the old one!) |
| 1381 | is not in the thread list. In this case we must not attempt |
| 1382 | to "switch context", or we run the risk that our context may |
| 1383 | be lost. This may happen as a result of the target module |
| 1384 | mishandling thread creation. */ |
| 1385 | |
| 1386 | if (in_thread_list (inferior_ptid) && in_thread_list (ecs->ptid)) |
| 1387 | { /* Perform infrun state context switch: */ |
| 1388 | /* Save infrun state for the old thread. */ |
| 1389 | save_infrun_state (inferior_ptid, prev_pc, |
| 1390 | prev_func_start, prev_func_name, |
| 1391 | trap_expected, step_resume_breakpoint, |
| 1392 | through_sigtramp_breakpoint, step_range_start, |
| 1393 | step_range_end, step_frame_address, |
| 1394 | ecs->handling_longjmp, ecs->another_trap, |
| 1395 | ecs->stepping_through_solib_after_catch, |
| 1396 | ecs->stepping_through_solib_catchpoints, |
| 1397 | ecs->stepping_through_sigtramp, |
| 1398 | ecs->current_line, ecs->current_symtab, |
| 1399 | step_sp); |
| 1400 | |
| 1401 | /* Load infrun state for the new thread. */ |
| 1402 | load_infrun_state (ecs->ptid, &prev_pc, |
| 1403 | &prev_func_start, &prev_func_name, |
| 1404 | &trap_expected, &step_resume_breakpoint, |
| 1405 | &through_sigtramp_breakpoint, &step_range_start, |
| 1406 | &step_range_end, &step_frame_address, |
| 1407 | &ecs->handling_longjmp, &ecs->another_trap, |
| 1408 | &ecs->stepping_through_solib_after_catch, |
| 1409 | &ecs->stepping_through_solib_catchpoints, |
| 1410 | &ecs->stepping_through_sigtramp, |
| 1411 | &ecs->current_line, &ecs->current_symtab, |
| 1412 | &step_sp); |
| 1413 | } |
| 1414 | inferior_ptid = ecs->ptid; |
| 1415 | } |
| 1416 | |
| 1417 | |
| 1418 | /* Given an execution control state that has been freshly filled in |
| 1419 | by an event from the inferior, figure out what it means and take |
| 1420 | appropriate action. */ |
| 1421 | |
| 1422 | void |
| 1423 | handle_inferior_event (struct execution_control_state *ecs) |
| 1424 | { |
| 1425 | CORE_ADDR tmp; |
| 1426 | int stepped_after_stopped_by_watchpoint; |
| 1427 | |
| 1428 | /* Cache the last pid/waitstatus. */ |
| 1429 | target_last_wait_ptid = ecs->ptid; |
| 1430 | target_last_waitstatus = *ecs->wp; |
| 1431 | |
| 1432 | /* Keep this extra brace for now, minimizes diffs. */ |
| 1433 | { |
| 1434 | switch (ecs->infwait_state) |
| 1435 | { |
| 1436 | case infwait_thread_hop_state: |
| 1437 | /* Cancel the waiton_ptid. */ |
| 1438 | ecs->waiton_ptid = pid_to_ptid (-1); |
| 1439 | /* Fall thru to the normal_state case. */ |
| 1440 | |
| 1441 | case infwait_normal_state: |
| 1442 | /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event |
| 1443 | is serviced in this loop, below. */ |
| 1444 | if (ecs->enable_hw_watchpoints_after_wait) |
| 1445 | { |
| 1446 | TARGET_ENABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); |
| 1447 | ecs->enable_hw_watchpoints_after_wait = 0; |
| 1448 | } |
| 1449 | stepped_after_stopped_by_watchpoint = 0; |
| 1450 | break; |
| 1451 | |
| 1452 | case infwait_nullified_state: |
| 1453 | break; |
| 1454 | |
| 1455 | case infwait_nonstep_watch_state: |
| 1456 | insert_breakpoints (); |
| 1457 | |
| 1458 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
| 1459 | handle things like signals arriving and other things happening |
| 1460 | in combination correctly? */ |
| 1461 | stepped_after_stopped_by_watchpoint = 1; |
| 1462 | break; |
| 1463 | } |
| 1464 | ecs->infwait_state = infwait_normal_state; |
| 1465 | |
| 1466 | flush_cached_frames (); |
| 1467 | |
| 1468 | /* If it's a new process, add it to the thread database */ |
| 1469 | |
| 1470 | ecs->new_thread_event = (! ptid_equal (ecs->ptid, inferior_ptid) |
| 1471 | && ! in_thread_list (ecs->ptid)); |
| 1472 | |
| 1473 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
| 1474 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED |
| 1475 | && ecs->new_thread_event) |
| 1476 | { |
| 1477 | add_thread (ecs->ptid); |
| 1478 | |
| 1479 | #ifdef UI_OUT |
| 1480 | ui_out_text (uiout, "[New "); |
| 1481 | ui_out_text (uiout, target_pid_or_tid_to_str (ecs->ptid)); |
| 1482 | ui_out_text (uiout, "]\n"); |
| 1483 | #else |
| 1484 | printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->ptid)); |
| 1485 | #endif |
| 1486 | |
| 1487 | #if 0 |
| 1488 | /* NOTE: This block is ONLY meant to be invoked in case of a |
| 1489 | "thread creation event"! If it is invoked for any other |
| 1490 | sort of event (such as a new thread landing on a breakpoint), |
| 1491 | the event will be discarded, which is almost certainly |
| 1492 | a bad thing! |
| 1493 | |
| 1494 | To avoid this, the low-level module (eg. target_wait) |
| 1495 | should call in_thread_list and add_thread, so that the |
| 1496 | new thread is known by the time we get here. */ |
| 1497 | |
| 1498 | /* We may want to consider not doing a resume here in order |
| 1499 | to give the user a chance to play with the new thread. |
| 1500 | It might be good to make that a user-settable option. */ |
| 1501 | |
| 1502 | /* At this point, all threads are stopped (happens |
| 1503 | automatically in either the OS or the native code). |
| 1504 | Therefore we need to continue all threads in order to |
| 1505 | make progress. */ |
| 1506 | |
| 1507 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); |
| 1508 | prepare_to_wait (ecs); |
| 1509 | return; |
| 1510 | #endif |
| 1511 | } |
| 1512 | |
| 1513 | switch (ecs->ws.kind) |
| 1514 | { |
| 1515 | case TARGET_WAITKIND_LOADED: |
| 1516 | /* Ignore gracefully during startup of the inferior, as it |
| 1517 | might be the shell which has just loaded some objects, |
| 1518 | otherwise add the symbols for the newly loaded objects. */ |
| 1519 | #ifdef SOLIB_ADD |
| 1520 | if (!stop_soon_quietly) |
| 1521 | { |
| 1522 | /* Remove breakpoints, SOLIB_ADD might adjust |
| 1523 | breakpoint addresses via breakpoint_re_set. */ |
| 1524 | if (breakpoints_inserted) |
| 1525 | remove_breakpoints (); |
| 1526 | |
| 1527 | /* Check for any newly added shared libraries if we're |
| 1528 | supposed to be adding them automatically. */ |
| 1529 | if (auto_solib_add) |
| 1530 | { |
| 1531 | /* Switch terminal for any messages produced by |
| 1532 | breakpoint_re_set. */ |
| 1533 | target_terminal_ours_for_output (); |
| 1534 | SOLIB_ADD (NULL, 0, NULL); |
| 1535 | target_terminal_inferior (); |
| 1536 | } |
| 1537 | |
| 1538 | /* Reinsert breakpoints and continue. */ |
| 1539 | if (breakpoints_inserted) |
| 1540 | insert_breakpoints (); |
| 1541 | } |
| 1542 | #endif |
| 1543 | resume (0, TARGET_SIGNAL_0); |
| 1544 | prepare_to_wait (ecs); |
| 1545 | return; |
| 1546 | |
| 1547 | case TARGET_WAITKIND_SPURIOUS: |
| 1548 | resume (0, TARGET_SIGNAL_0); |
| 1549 | prepare_to_wait (ecs); |
| 1550 | return; |
| 1551 | |
| 1552 | case TARGET_WAITKIND_EXITED: |
| 1553 | target_terminal_ours (); /* Must do this before mourn anyway */ |
| 1554 | print_stop_reason (EXITED, ecs->ws.value.integer); |
| 1555 | |
| 1556 | /* Record the exit code in the convenience variable $_exitcode, so |
| 1557 | that the user can inspect this again later. */ |
| 1558 | set_internalvar (lookup_internalvar ("_exitcode"), |
| 1559 | value_from_longest (builtin_type_int, |
| 1560 | (LONGEST) ecs->ws.value.integer)); |
| 1561 | gdb_flush (gdb_stdout); |
| 1562 | target_mourn_inferior (); |
| 1563 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ |
| 1564 | stop_print_frame = 0; |
| 1565 | stop_stepping (ecs); |
| 1566 | return; |
| 1567 | |
| 1568 | case TARGET_WAITKIND_SIGNALLED: |
| 1569 | stop_print_frame = 0; |
| 1570 | stop_signal = ecs->ws.value.sig; |
| 1571 | target_terminal_ours (); /* Must do this before mourn anyway */ |
| 1572 | |
| 1573 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
| 1574 | reach here unless the inferior is dead. However, for years |
| 1575 | target_kill() was called here, which hints that fatal signals aren't |
| 1576 | really fatal on some systems. If that's true, then some changes |
| 1577 | may be needed. */ |
| 1578 | target_mourn_inferior (); |
| 1579 | |
| 1580 | print_stop_reason (SIGNAL_EXITED, stop_signal); |
| 1581 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P() */ |
| 1582 | stop_stepping (ecs); |
| 1583 | return; |
| 1584 | |
| 1585 | /* The following are the only cases in which we keep going; |
| 1586 | the above cases end in a continue or goto. */ |
| 1587 | case TARGET_WAITKIND_FORKED: |
| 1588 | stop_signal = TARGET_SIGNAL_TRAP; |
| 1589 | pending_follow.kind = ecs->ws.kind; |
| 1590 | |
| 1591 | /* Ignore fork events reported for the parent; we're only |
| 1592 | interested in reacting to forks of the child. Note that |
| 1593 | we expect the child's fork event to be available if we |
| 1594 | waited for it now. */ |
| 1595 | if (ptid_equal (inferior_ptid, ecs->ptid)) |
| 1596 | { |
| 1597 | pending_follow.fork_event.saw_parent_fork = 1; |
| 1598 | pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); |
| 1599 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; |
| 1600 | prepare_to_wait (ecs); |
| 1601 | return; |
| 1602 | } |
| 1603 | else |
| 1604 | { |
| 1605 | pending_follow.fork_event.saw_child_fork = 1; |
| 1606 | pending_follow.fork_event.child_pid = PIDGET (ecs->ptid); |
| 1607 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; |
| 1608 | } |
| 1609 | |
| 1610 | stop_pc = read_pc_pid (ecs->ptid); |
| 1611 | ecs->saved_inferior_ptid = inferior_ptid; |
| 1612 | inferior_ptid = ecs->ptid; |
| 1613 | /* The second argument of bpstat_stop_status is meant to help |
| 1614 | distinguish between a breakpoint trap and a singlestep trap. |
| 1615 | This is only important on targets where DECR_PC_AFTER_BREAK |
| 1616 | is non-zero. The prev_pc test is meant to distinguish between |
| 1617 | singlestepping a trap instruction, and singlestepping thru a |
| 1618 | jump to the instruction following a trap instruction. */ |
| 1619 | |
| 1620 | stop_bpstat = bpstat_stop_status (&stop_pc, |
| 1621 | currently_stepping (ecs) && |
| 1622 | prev_pc != |
| 1623 | stop_pc - DECR_PC_AFTER_BREAK); |
| 1624 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
| 1625 | inferior_ptid = ecs->saved_inferior_ptid; |
| 1626 | goto process_event_stop_test; |
| 1627 | |
| 1628 | /* If this a platform which doesn't allow a debugger to touch a |
| 1629 | vfork'd inferior until after it exec's, then we'd best keep |
| 1630 | our fingers entirely off the inferior, other than continuing |
| 1631 | it. This has the unfortunate side-effect that catchpoints |
| 1632 | of vforks will be ignored. But since the platform doesn't |
| 1633 | allow the inferior be touched at vfork time, there's really |
| 1634 | little choice. */ |
| 1635 | case TARGET_WAITKIND_VFORKED: |
| 1636 | stop_signal = TARGET_SIGNAL_TRAP; |
| 1637 | pending_follow.kind = ecs->ws.kind; |
| 1638 | |
| 1639 | /* Is this a vfork of the parent? If so, then give any |
| 1640 | vfork catchpoints a chance to trigger now. (It's |
| 1641 | dangerous to do so if the child canot be touched until |
| 1642 | it execs, and the child has not yet exec'd. We probably |
| 1643 | should warn the user to that effect when the catchpoint |
| 1644 | triggers...) */ |
| 1645 | if (ptid_equal (ecs->ptid, inferior_ptid)) |
| 1646 | { |
| 1647 | pending_follow.fork_event.saw_parent_fork = 1; |
| 1648 | pending_follow.fork_event.parent_pid = PIDGET (ecs->ptid); |
| 1649 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; |
| 1650 | } |
| 1651 | |
| 1652 | /* If we've seen the child's vfork event but cannot really touch |
| 1653 | the child until it execs, then we must continue the child now. |
| 1654 | Else, give any vfork catchpoints a chance to trigger now. */ |
| 1655 | else |
| 1656 | { |
| 1657 | pending_follow.fork_event.saw_child_fork = 1; |
| 1658 | pending_follow.fork_event.child_pid = PIDGET (ecs->ptid); |
| 1659 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; |
| 1660 | target_post_startup_inferior ( |
| 1661 | pid_to_ptid (pending_follow.fork_event.child_pid)); |
| 1662 | follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec (); |
| 1663 | if (follow_vfork_when_exec) |
| 1664 | { |
| 1665 | target_resume (ecs->ptid, 0, TARGET_SIGNAL_0); |
| 1666 | prepare_to_wait (ecs); |
| 1667 | return; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | stop_pc = read_pc (); |
| 1672 | /* The second argument of bpstat_stop_status is meant to help |
| 1673 | distinguish between a breakpoint trap and a singlestep trap. |
| 1674 | This is only important on targets where DECR_PC_AFTER_BREAK |
| 1675 | is non-zero. The prev_pc test is meant to distinguish between |
| 1676 | singlestepping a trap instruction, and singlestepping thru a |
| 1677 | jump to the instruction following a trap instruction. */ |
| 1678 | |
| 1679 | stop_bpstat = bpstat_stop_status (&stop_pc, |
| 1680 | currently_stepping (ecs) && |
| 1681 | prev_pc != |
| 1682 | stop_pc - DECR_PC_AFTER_BREAK); |
| 1683 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
| 1684 | goto process_event_stop_test; |
| 1685 | |
| 1686 | case TARGET_WAITKIND_EXECD: |
| 1687 | stop_signal = TARGET_SIGNAL_TRAP; |
| 1688 | |
| 1689 | /* Is this a target which reports multiple exec events per actual |
| 1690 | call to exec()? (HP-UX using ptrace does, for example.) If so, |
| 1691 | ignore all but the last one. Just resume the exec'r, and wait |
| 1692 | for the next exec event. */ |
| 1693 | if (inferior_ignoring_leading_exec_events) |
| 1694 | { |
| 1695 | inferior_ignoring_leading_exec_events--; |
| 1696 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) |
| 1697 | ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid); |
| 1698 | target_resume (ecs->ptid, 0, TARGET_SIGNAL_0); |
| 1699 | prepare_to_wait (ecs); |
| 1700 | return; |
| 1701 | } |
| 1702 | inferior_ignoring_leading_exec_events = |
| 1703 | target_reported_exec_events_per_exec_call () - 1; |
| 1704 | |
| 1705 | pending_follow.execd_pathname = |
| 1706 | savestring (ecs->ws.value.execd_pathname, |
| 1707 | strlen (ecs->ws.value.execd_pathname)); |
| 1708 | |
| 1709 | /* Did inferior_ptid exec, or did a (possibly not-yet-followed) |
| 1710 | child of a vfork exec? |
| 1711 | |
| 1712 | ??rehrauer: This is unabashedly an HP-UX specific thing. On |
| 1713 | HP-UX, events associated with a vforking inferior come in |
| 1714 | threes: a vfork event for the child (always first), followed |
| 1715 | a vfork event for the parent and an exec event for the child. |
| 1716 | The latter two can come in either order. |
| 1717 | |
| 1718 | If we get the parent vfork event first, life's good: We follow |
| 1719 | either the parent or child, and then the child's exec event is |
| 1720 | a "don't care". |
| 1721 | |
| 1722 | But if we get the child's exec event first, then we delay |
| 1723 | responding to it until we handle the parent's vfork. Because, |
| 1724 | otherwise we can't satisfy a "catch vfork". */ |
| 1725 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) |
| 1726 | { |
| 1727 | pending_follow.fork_event.saw_child_exec = 1; |
| 1728 | |
| 1729 | /* On some targets, the child must be resumed before |
| 1730 | the parent vfork event is delivered. A single-step |
| 1731 | suffices. */ |
| 1732 | if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ()) |
| 1733 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
| 1734 | /* We expect the parent vfork event to be available now. */ |
| 1735 | prepare_to_wait (ecs); |
| 1736 | return; |
| 1737 | } |
| 1738 | |
| 1739 | /* This causes the eventpoints and symbol table to be reset. Must |
| 1740 | do this now, before trying to determine whether to stop. */ |
| 1741 | follow_exec (PIDGET (inferior_ptid), pending_follow.execd_pathname); |
| 1742 | xfree (pending_follow.execd_pathname); |
| 1743 | |
| 1744 | stop_pc = read_pc_pid (ecs->ptid); |
| 1745 | ecs->saved_inferior_ptid = inferior_ptid; |
| 1746 | inferior_ptid = ecs->ptid; |
| 1747 | /* The second argument of bpstat_stop_status is meant to help |
| 1748 | distinguish between a breakpoint trap and a singlestep trap. |
| 1749 | This is only important on targets where DECR_PC_AFTER_BREAK |
| 1750 | is non-zero. The prev_pc test is meant to distinguish between |
| 1751 | singlestepping a trap instruction, and singlestepping thru a |
| 1752 | jump to the instruction following a trap instruction. */ |
| 1753 | |
| 1754 | stop_bpstat = bpstat_stop_status (&stop_pc, |
| 1755 | currently_stepping (ecs) && |
| 1756 | prev_pc != |
| 1757 | stop_pc - DECR_PC_AFTER_BREAK); |
| 1758 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); |
| 1759 | inferior_ptid = ecs->saved_inferior_ptid; |
| 1760 | goto process_event_stop_test; |
| 1761 | |
| 1762 | /* These syscall events are returned on HP-UX, as part of its |
| 1763 | implementation of page-protection-based "hardware" watchpoints. |
| 1764 | HP-UX has unfortunate interactions between page-protections and |
| 1765 | some system calls. Our solution is to disable hardware watches |
| 1766 | when a system call is entered, and reenable them when the syscall |
| 1767 | completes. The downside of this is that we may miss the precise |
| 1768 | point at which a watched piece of memory is modified. "Oh well." |
| 1769 | |
| 1770 | Note that we may have multiple threads running, which may each |
| 1771 | enter syscalls at roughly the same time. Since we don't have a |
| 1772 | good notion currently of whether a watched piece of memory is |
| 1773 | thread-private, we'd best not have any page-protections active |
| 1774 | when any thread is in a syscall. Thus, we only want to reenable |
| 1775 | hardware watches when no threads are in a syscall. |
| 1776 | |
| 1777 | Also, be careful not to try to gather much state about a thread |
| 1778 | that's in a syscall. It's frequently a losing proposition. */ |
| 1779 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
| 1780 | number_of_threads_in_syscalls++; |
| 1781 | if (number_of_threads_in_syscalls == 1) |
| 1782 | { |
| 1783 | TARGET_DISABLE_HW_WATCHPOINTS (PIDGET (inferior_ptid)); |
| 1784 | } |
| 1785 | resume (0, TARGET_SIGNAL_0); |
| 1786 | prepare_to_wait (ecs); |
| 1787 | return; |
| 1788 | |
| 1789 | /* Before examining the threads further, step this thread to |
| 1790 | get it entirely out of the syscall. (We get notice of the |
| 1791 | event when the thread is just on the verge of exiting a |
| 1792 | syscall. Stepping one instruction seems to get it back |
| 1793 | into user code.) |
| 1794 | |
| 1795 | Note that although the logical place to reenable h/w watches |
| 1796 | is here, we cannot. We cannot reenable them before stepping |
| 1797 | the thread (this causes the next wait on the thread to hang). |
| 1798 | |
| 1799 | Nor can we enable them after stepping until we've done a wait. |
| 1800 | Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait |
| 1801 | here, which will be serviced immediately after the target |
| 1802 | is waited on. */ |
| 1803 | case TARGET_WAITKIND_SYSCALL_RETURN: |
| 1804 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
| 1805 | |
| 1806 | if (number_of_threads_in_syscalls > 0) |
| 1807 | { |
| 1808 | number_of_threads_in_syscalls--; |
| 1809 | ecs->enable_hw_watchpoints_after_wait = |
| 1810 | (number_of_threads_in_syscalls == 0); |
| 1811 | } |
| 1812 | prepare_to_wait (ecs); |
| 1813 | return; |
| 1814 | |
| 1815 | case TARGET_WAITKIND_STOPPED: |
| 1816 | stop_signal = ecs->ws.value.sig; |
| 1817 | break; |
| 1818 | |
| 1819 | /* We had an event in the inferior, but we are not interested |
| 1820 | in handling it at this level. The lower layers have already |
| 1821 | done what needs to be done, if anything. This case can |
| 1822 | occur only when the target is async or extended-async. One |
| 1823 | of the circumstamces for this to happen is when the |
| 1824 | inferior produces output for the console. The inferior has |
| 1825 | not stopped, and we are ignoring the event. */ |
| 1826 | case TARGET_WAITKIND_IGNORE: |
| 1827 | ecs->wait_some_more = 1; |
| 1828 | return; |
| 1829 | } |
| 1830 | |
| 1831 | /* We may want to consider not doing a resume here in order to give |
| 1832 | the user a chance to play with the new thread. It might be good |
| 1833 | to make that a user-settable option. */ |
| 1834 | |
| 1835 | /* At this point, all threads are stopped (happens automatically in |
| 1836 | either the OS or the native code). Therefore we need to continue |
| 1837 | all threads in order to make progress. */ |
| 1838 | if (ecs->new_thread_event) |
| 1839 | { |
| 1840 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); |
| 1841 | prepare_to_wait (ecs); |
| 1842 | return; |
| 1843 | } |
| 1844 | |
| 1845 | stop_pc = read_pc_pid (ecs->ptid); |
| 1846 | |
| 1847 | /* See if a thread hit a thread-specific breakpoint that was meant for |
| 1848 | another thread. If so, then step that thread past the breakpoint, |
| 1849 | and continue it. */ |
| 1850 | |
| 1851 | if (stop_signal == TARGET_SIGNAL_TRAP) |
| 1852 | { |
| 1853 | if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) |
| 1854 | ecs->random_signal = 0; |
| 1855 | else if (breakpoints_inserted |
| 1856 | && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK)) |
| 1857 | { |
| 1858 | ecs->random_signal = 0; |
| 1859 | if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, |
| 1860 | ecs->ptid)) |
| 1861 | { |
| 1862 | int remove_status; |
| 1863 | |
| 1864 | /* Saw a breakpoint, but it was hit by the wrong thread. |
| 1865 | Just continue. */ |
| 1866 | if (DECR_PC_AFTER_BREAK) |
| 1867 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->ptid); |
| 1868 | |
| 1869 | remove_status = remove_breakpoints (); |
| 1870 | /* Did we fail to remove breakpoints? If so, try |
| 1871 | to set the PC past the bp. (There's at least |
| 1872 | one situation in which we can fail to remove |
| 1873 | the bp's: On HP-UX's that use ttrace, we can't |
| 1874 | change the address space of a vforking child |
| 1875 | process until the child exits (well, okay, not |
| 1876 | then either :-) or execs. */ |
| 1877 | if (remove_status != 0) |
| 1878 | { |
| 1879 | /* FIXME! This is obviously non-portable! */ |
| 1880 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, |
| 1881 | ecs->ptid); |
| 1882 | /* We need to restart all the threads now, |
| 1883 | * unles we're running in scheduler-locked mode. |
| 1884 | * Use currently_stepping to determine whether to |
| 1885 | * step or continue. |
| 1886 | */ |
| 1887 | /* FIXME MVS: is there any reason not to call resume()? */ |
| 1888 | if (scheduler_mode == schedlock_on) |
| 1889 | target_resume (ecs->ptid, |
| 1890 | currently_stepping (ecs), |
| 1891 | TARGET_SIGNAL_0); |
| 1892 | else |
| 1893 | target_resume (RESUME_ALL, |
| 1894 | currently_stepping (ecs), |
| 1895 | TARGET_SIGNAL_0); |
| 1896 | prepare_to_wait (ecs); |
| 1897 | return; |
| 1898 | } |
| 1899 | else |
| 1900 | { /* Single step */ |
| 1901 | breakpoints_inserted = 0; |
| 1902 | if (!ptid_equal (inferior_ptid, ecs->ptid)) |
| 1903 | context_switch (ecs); |
| 1904 | ecs->waiton_ptid = ecs->ptid; |
| 1905 | ecs->wp = &(ecs->ws); |
| 1906 | ecs->another_trap = 1; |
| 1907 | |
| 1908 | ecs->infwait_state = infwait_thread_hop_state; |
| 1909 | keep_going (ecs); |
| 1910 | registers_changed (); |
| 1911 | return; |
| 1912 | } |
| 1913 | } |
| 1914 | } |
| 1915 | } |
| 1916 | else |
| 1917 | ecs->random_signal = 1; |
| 1918 | |
| 1919 | /* See if something interesting happened to the non-current thread. If |
| 1920 | so, then switch to that thread, and eventually give control back to |
| 1921 | the user. |
| 1922 | |
| 1923 | Note that if there's any kind of pending follow (i.e., of a fork, |
| 1924 | vfork or exec), we don't want to do this now. Rather, we'll let |
| 1925 | the next resume handle it. */ |
| 1926 | if (! ptid_equal (ecs->ptid, inferior_ptid) && |
| 1927 | (pending_follow.kind == TARGET_WAITKIND_SPURIOUS)) |
| 1928 | { |
| 1929 | int printed = 0; |
| 1930 | |
| 1931 | /* If it's a random signal for a non-current thread, notify user |
| 1932 | if he's expressed an interest. */ |
| 1933 | if (ecs->random_signal |
| 1934 | && signal_print[stop_signal]) |
| 1935 | { |
| 1936 | /* ??rehrauer: I don't understand the rationale for this code. If the |
| 1937 | inferior will stop as a result of this signal, then the act of handling |
| 1938 | the stop ought to print a message that's couches the stoppage in user |
| 1939 | terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior |
| 1940 | won't stop as a result of the signal -- i.e., if the signal is merely |
| 1941 | a side-effect of something GDB's doing "under the covers" for the |
| 1942 | user, such as stepping threads over a breakpoint they shouldn't stop |
| 1943 | for -- then the message seems to be a serious annoyance at best. |
| 1944 | |
| 1945 | For now, remove the message altogether. */ |
| 1946 | #if 0 |
| 1947 | printed = 1; |
| 1948 | target_terminal_ours_for_output (); |
| 1949 | printf_filtered ("\nProgram received signal %s, %s.\n", |
| 1950 | target_signal_to_name (stop_signal), |
| 1951 | target_signal_to_string (stop_signal)); |
| 1952 | gdb_flush (gdb_stdout); |
| 1953 | #endif |
| 1954 | } |
| 1955 | |
| 1956 | /* If it's not SIGTRAP and not a signal we want to stop for, then |
| 1957 | continue the thread. */ |
| 1958 | |
| 1959 | if (stop_signal != TARGET_SIGNAL_TRAP |
| 1960 | && !signal_stop[stop_signal]) |
| 1961 | { |
| 1962 | if (printed) |
| 1963 | target_terminal_inferior (); |
| 1964 | |
| 1965 | /* Clear the signal if it should not be passed. */ |
| 1966 | if (signal_program[stop_signal] == 0) |
| 1967 | stop_signal = TARGET_SIGNAL_0; |
| 1968 | |
| 1969 | target_resume (ecs->ptid, 0, stop_signal); |
| 1970 | prepare_to_wait (ecs); |
| 1971 | return; |
| 1972 | } |
| 1973 | |
| 1974 | /* It's a SIGTRAP or a signal we're interested in. Switch threads, |
| 1975 | and fall into the rest of wait_for_inferior(). */ |
| 1976 | |
| 1977 | context_switch (ecs); |
| 1978 | |
| 1979 | if (context_hook) |
| 1980 | context_hook (pid_to_thread_id (ecs->ptid)); |
| 1981 | |
| 1982 | flush_cached_frames (); |
| 1983 | } |
| 1984 | |
| 1985 | if (SOFTWARE_SINGLE_STEP_P () && singlestep_breakpoints_inserted_p) |
| 1986 | { |
| 1987 | /* Pull the single step breakpoints out of the target. */ |
| 1988 | SOFTWARE_SINGLE_STEP (0, 0); |
| 1989 | singlestep_breakpoints_inserted_p = 0; |
| 1990 | } |
| 1991 | |
| 1992 | /* If PC is pointing at a nullified instruction, then step beyond |
| 1993 | it so that the user won't be confused when GDB appears to be ready |
| 1994 | to execute it. */ |
| 1995 | |
| 1996 | /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */ |
| 1997 | if (INSTRUCTION_NULLIFIED) |
| 1998 | { |
| 1999 | registers_changed (); |
| 2000 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); |
| 2001 | |
| 2002 | /* We may have received a signal that we want to pass to |
| 2003 | the inferior; therefore, we must not clobber the waitstatus |
| 2004 | in WS. */ |
| 2005 | |
| 2006 | ecs->infwait_state = infwait_nullified_state; |
| 2007 | ecs->waiton_ptid = ecs->ptid; |
| 2008 | ecs->wp = &(ecs->tmpstatus); |
| 2009 | prepare_to_wait (ecs); |
| 2010 | return; |
| 2011 | } |
| 2012 | |
| 2013 | /* It may not be necessary to disable the watchpoint to stop over |
| 2014 | it. For example, the PA can (with some kernel cooperation) |
| 2015 | single step over a watchpoint without disabling the watchpoint. */ |
| 2016 | if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) |
| 2017 | { |
| 2018 | resume (1, 0); |
| 2019 | prepare_to_wait (ecs); |
| 2020 | return; |
| 2021 | } |
| 2022 | |
| 2023 | /* It is far more common to need to disable a watchpoint to step |
| 2024 | the inferior over it. FIXME. What else might a debug |
| 2025 | register or page protection watchpoint scheme need here? */ |
| 2026 | if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) |
| 2027 | { |
| 2028 | /* At this point, we are stopped at an instruction which has |
| 2029 | attempted to write to a piece of memory under control of |
| 2030 | a watchpoint. The instruction hasn't actually executed |
| 2031 | yet. If we were to evaluate the watchpoint expression |
| 2032 | now, we would get the old value, and therefore no change |
| 2033 | would seem to have occurred. |
| 2034 | |
| 2035 | In order to make watchpoints work `right', we really need |
| 2036 | to complete the memory write, and then evaluate the |
| 2037 | watchpoint expression. The following code does that by |
| 2038 | removing the watchpoint (actually, all watchpoints and |
| 2039 | breakpoints), single-stepping the target, re-inserting |
| 2040 | watchpoints, and then falling through to let normal |
| 2041 | single-step processing handle proceed. Since this |
| 2042 | includes evaluating watchpoints, things will come to a |
| 2043 | stop in the correct manner. */ |
| 2044 | |
| 2045 | if (DECR_PC_AFTER_BREAK) |
| 2046 | write_pc (stop_pc - DECR_PC_AFTER_BREAK); |
| 2047 | |
| 2048 | remove_breakpoints (); |
| 2049 | registers_changed (); |
| 2050 | target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */ |
| 2051 | |
| 2052 | ecs->waiton_ptid = ecs->ptid; |
| 2053 | ecs->wp = &(ecs->ws); |
| 2054 | ecs->infwait_state = infwait_nonstep_watch_state; |
| 2055 | prepare_to_wait (ecs); |
| 2056 | return; |
| 2057 | } |
| 2058 | |
| 2059 | /* It may be possible to simply continue after a watchpoint. */ |
| 2060 | if (HAVE_CONTINUABLE_WATCHPOINT) |
| 2061 | STOPPED_BY_WATCHPOINT (ecs->ws); |
| 2062 | |
| 2063 | ecs->stop_func_start = 0; |
| 2064 | ecs->stop_func_end = 0; |
| 2065 | ecs->stop_func_name = 0; |
| 2066 | /* Don't care about return value; stop_func_start and stop_func_name |
| 2067 | will both be 0 if it doesn't work. */ |
| 2068 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, |
| 2069 | &ecs->stop_func_start, &ecs->stop_func_end); |
| 2070 | ecs->stop_func_start += FUNCTION_START_OFFSET; |
| 2071 | ecs->another_trap = 0; |
| 2072 | bpstat_clear (&stop_bpstat); |
| 2073 | stop_step = 0; |
| 2074 | stop_stack_dummy = 0; |
| 2075 | stop_print_frame = 1; |
| 2076 | ecs->random_signal = 0; |
| 2077 | stopped_by_random_signal = 0; |
| 2078 | breakpoints_failed = 0; |
| 2079 | |
| 2080 | /* Look at the cause of the stop, and decide what to do. |
| 2081 | The alternatives are: |
| 2082 | 1) break; to really stop and return to the debugger, |
| 2083 | 2) drop through to start up again |
| 2084 | (set ecs->another_trap to 1 to single step once) |
| 2085 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 |
| 2086 | will be made according to the signal handling tables. */ |
| 2087 | |
| 2088 | /* First, distinguish signals caused by the debugger from signals |
| 2089 | that have to do with the program's own actions. |
| 2090 | Note that breakpoint insns may cause SIGTRAP or SIGILL |
| 2091 | or SIGEMT, depending on the operating system version. |
| 2092 | Here we detect when a SIGILL or SIGEMT is really a breakpoint |
| 2093 | and change it to SIGTRAP. */ |
| 2094 | |
| 2095 | if (stop_signal == TARGET_SIGNAL_TRAP |
| 2096 | || (breakpoints_inserted && |
| 2097 | (stop_signal == TARGET_SIGNAL_ILL |
| 2098 | || stop_signal == TARGET_SIGNAL_EMT |
| 2099 | )) |
| 2100 | || stop_soon_quietly) |
| 2101 | { |
| 2102 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) |
| 2103 | { |
| 2104 | stop_print_frame = 0; |
| 2105 | stop_stepping (ecs); |
| 2106 | return; |
| 2107 | } |
| 2108 | if (stop_soon_quietly) |
| 2109 | { |
| 2110 | stop_stepping (ecs); |
| 2111 | return; |
| 2112 | } |
| 2113 | |
| 2114 | /* Don't even think about breakpoints |
| 2115 | if just proceeded over a breakpoint. |
| 2116 | |
| 2117 | However, if we are trying to proceed over a breakpoint |
| 2118 | and end up in sigtramp, then through_sigtramp_breakpoint |
| 2119 | will be set and we should check whether we've hit the |
| 2120 | step breakpoint. */ |
| 2121 | if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected |
| 2122 | && through_sigtramp_breakpoint == NULL) |
| 2123 | bpstat_clear (&stop_bpstat); |
| 2124 | else |
| 2125 | { |
| 2126 | /* See if there is a breakpoint at the current PC. */ |
| 2127 | |
| 2128 | /* The second argument of bpstat_stop_status is meant to help |
| 2129 | distinguish between a breakpoint trap and a singlestep trap. |
| 2130 | This is only important on targets where DECR_PC_AFTER_BREAK |
| 2131 | is non-zero. The prev_pc test is meant to distinguish between |
| 2132 | singlestepping a trap instruction, and singlestepping thru a |
| 2133 | jump to the instruction following a trap instruction. */ |
| 2134 | |
| 2135 | stop_bpstat = bpstat_stop_status |
| 2136 | (&stop_pc, |
| 2137 | /* Pass TRUE if our reason for stopping is something other |
| 2138 | than hitting a breakpoint. We do this by checking that |
| 2139 | 1) stepping is going on and 2) we didn't hit a breakpoint |
| 2140 | in a signal handler without an intervening stop in |
| 2141 | sigtramp, which is detected by a new stack pointer value |
| 2142 | below any usual function calling stack adjustments. */ |
| 2143 | (currently_stepping (ecs) |
| 2144 | && prev_pc != stop_pc - DECR_PC_AFTER_BREAK |
| 2145 | && !(step_range_end |
| 2146 | && INNER_THAN (read_sp (), (step_sp - 16)))) |
| 2147 | ); |
| 2148 | /* Following in case break condition called a |
| 2149 | function. */ |
| 2150 | stop_print_frame = 1; |
| 2151 | } |
| 2152 | |
| 2153 | if (stop_signal == TARGET_SIGNAL_TRAP) |
| 2154 | ecs->random_signal |
| 2155 | = !(bpstat_explains_signal (stop_bpstat) |
| 2156 | || trap_expected |
| 2157 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P |
| 2158 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), |
| 2159 | FRAME_FP (get_current_frame ()))) |
| 2160 | || (step_range_end && step_resume_breakpoint == NULL)); |
| 2161 | |
| 2162 | else |
| 2163 | { |
| 2164 | ecs->random_signal |
| 2165 | = !(bpstat_explains_signal (stop_bpstat) |
| 2166 | /* End of a stack dummy. Some systems (e.g. Sony |
| 2167 | news) give another signal besides SIGTRAP, so |
| 2168 | check here as well as above. */ |
| 2169 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P |
| 2170 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), |
| 2171 | FRAME_FP (get_current_frame ()))) |
| 2172 | ); |
| 2173 | if (!ecs->random_signal) |
| 2174 | stop_signal = TARGET_SIGNAL_TRAP; |
| 2175 | } |
| 2176 | } |
| 2177 | |
| 2178 | /* When we reach this point, we've pretty much decided |
| 2179 | that the reason for stopping must've been a random |
| 2180 | (unexpected) signal. */ |
| 2181 | |
| 2182 | else |
| 2183 | ecs->random_signal = 1; |
| 2184 | /* If a fork, vfork or exec event was seen, then there are two |
| 2185 | possible responses we can make: |
| 2186 | |
| 2187 | 1. If a catchpoint triggers for the event (ecs->random_signal == 0), |
| 2188 | then we must stop now and issue a prompt. We will resume |
| 2189 | the inferior when the user tells us to. |
| 2190 | 2. If no catchpoint triggers for the event (ecs->random_signal == 1), |
| 2191 | then we must resume the inferior now and keep checking. |
| 2192 | |
| 2193 | In either case, we must take appropriate steps to "follow" the |
| 2194 | the fork/vfork/exec when the inferior is resumed. For example, |
| 2195 | if follow-fork-mode is "child", then we must detach from the |
| 2196 | parent inferior and follow the new child inferior. |
| 2197 | |
| 2198 | In either case, setting pending_follow causes the next resume() |
| 2199 | to take the appropriate following action. */ |
| 2200 | process_event_stop_test: |
| 2201 | if (ecs->ws.kind == TARGET_WAITKIND_FORKED) |
| 2202 | { |
| 2203 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ |
| 2204 | { |
| 2205 | trap_expected = 1; |
| 2206 | stop_signal = TARGET_SIGNAL_0; |
| 2207 | keep_going (ecs); |
| 2208 | return; |
| 2209 | } |
| 2210 | } |
| 2211 | else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED) |
| 2212 | { |
| 2213 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ |
| 2214 | { |
| 2215 | stop_signal = TARGET_SIGNAL_0; |
| 2216 | keep_going (ecs); |
| 2217 | return; |
| 2218 | } |
| 2219 | } |
| 2220 | else if (ecs->ws.kind == TARGET_WAITKIND_EXECD) |
| 2221 | { |
| 2222 | pending_follow.kind = ecs->ws.kind; |
| 2223 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ |
| 2224 | { |
| 2225 | trap_expected = 1; |
| 2226 | stop_signal = TARGET_SIGNAL_0; |
| 2227 | keep_going (ecs); |
| 2228 | return; |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | /* For the program's own signals, act according to |
| 2233 | the signal handling tables. */ |
| 2234 | |
| 2235 | if (ecs->random_signal) |
| 2236 | { |
| 2237 | /* Signal not for debugging purposes. */ |
| 2238 | int printed = 0; |
| 2239 | |
| 2240 | stopped_by_random_signal = 1; |
| 2241 | |
| 2242 | if (signal_print[stop_signal]) |
| 2243 | { |
| 2244 | printed = 1; |
| 2245 | target_terminal_ours_for_output (); |
| 2246 | print_stop_reason (SIGNAL_RECEIVED, stop_signal); |
| 2247 | } |
| 2248 | if (signal_stop[stop_signal]) |
| 2249 | { |
| 2250 | stop_stepping (ecs); |
| 2251 | return; |
| 2252 | } |
| 2253 | /* If not going to stop, give terminal back |
| 2254 | if we took it away. */ |
| 2255 | else if (printed) |
| 2256 | target_terminal_inferior (); |
| 2257 | |
| 2258 | /* Clear the signal if it should not be passed. */ |
| 2259 | if (signal_program[stop_signal] == 0) |
| 2260 | stop_signal = TARGET_SIGNAL_0; |
| 2261 | |
| 2262 | /* I'm not sure whether this needs to be check_sigtramp2 or |
| 2263 | whether it could/should be keep_going. |
| 2264 | |
| 2265 | This used to jump to step_over_function if we are stepping, |
| 2266 | which is wrong. |
| 2267 | |
| 2268 | Suppose the user does a `next' over a function call, and while |
| 2269 | that call is in progress, the inferior receives a signal for |
| 2270 | which GDB does not stop (i.e., signal_stop[SIG] is false). In |
| 2271 | that case, when we reach this point, there is already a |
| 2272 | step-resume breakpoint established, right where it should be: |
| 2273 | immediately after the function call the user is "next"-ing |
| 2274 | over. If we call step_over_function now, two bad things |
| 2275 | happen: |
| 2276 | |
| 2277 | - we'll create a new breakpoint, at wherever the current |
| 2278 | frame's return address happens to be. That could be |
| 2279 | anywhere, depending on what function call happens to be on |
| 2280 | the top of the stack at that point. Point is, it's probably |
| 2281 | not where we need it. |
| 2282 | |
| 2283 | - the existing step-resume breakpoint (which is at the correct |
| 2284 | address) will get orphaned: step_resume_breakpoint will point |
| 2285 | to the new breakpoint, and the old step-resume breakpoint |
| 2286 | will never be cleaned up. |
| 2287 | |
| 2288 | The old behavior was meant to help HP-UX single-step out of |
| 2289 | sigtramps. It would place the new breakpoint at prev_pc, which |
| 2290 | was certainly wrong. I don't know the details there, so fixing |
| 2291 | this probably breaks that. As with anything else, it's up to |
| 2292 | the HP-UX maintainer to furnish a fix that doesn't break other |
| 2293 | platforms. --JimB, 20 May 1999 */ |
| 2294 | check_sigtramp2 (ecs); |
| 2295 | keep_going (ecs); |
| 2296 | return; |
| 2297 | } |
| 2298 | |
| 2299 | /* Handle cases caused by hitting a breakpoint. */ |
| 2300 | { |
| 2301 | CORE_ADDR jmp_buf_pc; |
| 2302 | struct bpstat_what what; |
| 2303 | |
| 2304 | what = bpstat_what (stop_bpstat); |
| 2305 | |
| 2306 | if (what.call_dummy) |
| 2307 | { |
| 2308 | stop_stack_dummy = 1; |
| 2309 | #ifdef HP_OS_BUG |
| 2310 | trap_expected_after_continue = 1; |
| 2311 | #endif |
| 2312 | } |
| 2313 | |
| 2314 | switch (what.main_action) |
| 2315 | { |
| 2316 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
| 2317 | /* If we hit the breakpoint at longjmp, disable it for the |
| 2318 | duration of this command. Then, install a temporary |
| 2319 | breakpoint at the target of the jmp_buf. */ |
| 2320 | disable_longjmp_breakpoint (); |
| 2321 | remove_breakpoints (); |
| 2322 | breakpoints_inserted = 0; |
| 2323 | if (!GET_LONGJMP_TARGET (&jmp_buf_pc)) |
| 2324 | { |
| 2325 | keep_going (ecs); |
| 2326 | return; |
| 2327 | } |
| 2328 | |
| 2329 | /* Need to blow away step-resume breakpoint, as it |
| 2330 | interferes with us */ |
| 2331 | if (step_resume_breakpoint != NULL) |
| 2332 | { |
| 2333 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
| 2334 | } |
| 2335 | /* Not sure whether we need to blow this away too, but probably |
| 2336 | it is like the step-resume breakpoint. */ |
| 2337 | if (through_sigtramp_breakpoint != NULL) |
| 2338 | { |
| 2339 | delete_breakpoint (through_sigtramp_breakpoint); |
| 2340 | through_sigtramp_breakpoint = NULL; |
| 2341 | } |
| 2342 | |
| 2343 | #if 0 |
| 2344 | /* FIXME - Need to implement nested temporary breakpoints */ |
| 2345 | if (step_over_calls > 0) |
| 2346 | set_longjmp_resume_breakpoint (jmp_buf_pc, |
| 2347 | get_current_frame ()); |
| 2348 | else |
| 2349 | #endif /* 0 */ |
| 2350 | set_longjmp_resume_breakpoint (jmp_buf_pc, NULL); |
| 2351 | ecs->handling_longjmp = 1; /* FIXME */ |
| 2352 | keep_going (ecs); |
| 2353 | return; |
| 2354 | |
| 2355 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
| 2356 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: |
| 2357 | remove_breakpoints (); |
| 2358 | breakpoints_inserted = 0; |
| 2359 | #if 0 |
| 2360 | /* FIXME - Need to implement nested temporary breakpoints */ |
| 2361 | if (step_over_calls |
| 2362 | && (INNER_THAN (FRAME_FP (get_current_frame ()), |
| 2363 | step_frame_address))) |
| 2364 | { |
| 2365 | ecs->another_trap = 1; |
| 2366 | keep_going (ecs); |
| 2367 | return; |
| 2368 | } |
| 2369 | #endif /* 0 */ |
| 2370 | disable_longjmp_breakpoint (); |
| 2371 | ecs->handling_longjmp = 0; /* FIXME */ |
| 2372 | if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) |
| 2373 | break; |
| 2374 | /* else fallthrough */ |
| 2375 | |
| 2376 | case BPSTAT_WHAT_SINGLE: |
| 2377 | if (breakpoints_inserted) |
| 2378 | { |
| 2379 | remove_breakpoints (); |
| 2380 | } |
| 2381 | breakpoints_inserted = 0; |
| 2382 | ecs->another_trap = 1; |
| 2383 | /* Still need to check other stuff, at least the case |
| 2384 | where we are stepping and step out of the right range. */ |
| 2385 | break; |
| 2386 | |
| 2387 | case BPSTAT_WHAT_STOP_NOISY: |
| 2388 | stop_print_frame = 1; |
| 2389 | |
| 2390 | /* We are about to nuke the step_resume_breakpoint and |
| 2391 | through_sigtramp_breakpoint via the cleanup chain, so |
| 2392 | no need to worry about it here. */ |
| 2393 | |
| 2394 | stop_stepping (ecs); |
| 2395 | return; |
| 2396 | |
| 2397 | case BPSTAT_WHAT_STOP_SILENT: |
| 2398 | stop_print_frame = 0; |
| 2399 | |
| 2400 | /* We are about to nuke the step_resume_breakpoint and |
| 2401 | through_sigtramp_breakpoint via the cleanup chain, so |
| 2402 | no need to worry about it here. */ |
| 2403 | |
| 2404 | stop_stepping (ecs); |
| 2405 | return; |
| 2406 | |
| 2407 | case BPSTAT_WHAT_STEP_RESUME: |
| 2408 | /* This proably demands a more elegant solution, but, yeah |
| 2409 | right... |
| 2410 | |
| 2411 | This function's use of the simple variable |
| 2412 | step_resume_breakpoint doesn't seem to accomodate |
| 2413 | simultaneously active step-resume bp's, although the |
| 2414 | breakpoint list certainly can. |
| 2415 | |
| 2416 | If we reach here and step_resume_breakpoint is already |
| 2417 | NULL, then apparently we have multiple active |
| 2418 | step-resume bp's. We'll just delete the breakpoint we |
| 2419 | stopped at, and carry on. |
| 2420 | |
| 2421 | Correction: what the code currently does is delete a |
| 2422 | step-resume bp, but it makes no effort to ensure that |
| 2423 | the one deleted is the one currently stopped at. MVS */ |
| 2424 | |
| 2425 | if (step_resume_breakpoint == NULL) |
| 2426 | { |
| 2427 | step_resume_breakpoint = |
| 2428 | bpstat_find_step_resume_breakpoint (stop_bpstat); |
| 2429 | } |
| 2430 | delete_step_resume_breakpoint (&step_resume_breakpoint); |
| 2431 | break; |
| 2432 | |
| 2433 | case BPSTAT_WHAT_THROUGH_SIGTRAMP: |
| 2434 | if (through_sigtramp_breakpoint) |
| 2435 | delete_breakpoint (through_sigtramp_breakpoint); |
| 2436 | through_sigtramp_breakpoint = NULL; |
| 2437 | |
| 2438 | /* If were waiting for a trap, hitting the step_resume_break |
| 2439 | doesn't count as getting it. */ |
| 2440 | if (trap_expected) |
| 2441 | ecs->another_trap = 1; |
| 2442 | break; |
| 2443 | |
| 2444 | case BPSTAT_WHAT_CHECK_SHLIBS: |
| 2445 | case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: |
| 2446 | #ifdef SOLIB_ADD |
| 2447 | { |
| 2448 | /* Remove breakpoints, we eventually want to step over the |
| 2449 | shlib event breakpoint, and SOLIB_ADD might adjust |
| 2450 | breakpoint addresses via breakpoint_re_set. */ |
| 2451 | if (breakpoints_inserted) |
| 2452 | remove_breakpoints (); |
| 2453 | breakpoints_inserted = 0; |
| 2454 | |
| 2455 | /* Check for any newly added shared libraries if we're |
| 2456 | supposed to be adding them automatically. */ |
| 2457 | if (auto_solib_add) |
| 2458 | { |
| 2459 | /* Switch terminal for any messages produced by |
| 2460 | breakpoint_re_set. */ |
| 2461 | target_terminal_ours_for_output (); |
| 2462 | SOLIB_ADD (NULL, 0, NULL); |
| 2463 | target_terminal_inferior (); |
| 2464 | } |
| 2465 | |
| 2466 | /* Try to reenable shared library breakpoints, additional |
| 2467 | code segments in shared libraries might be mapped in now. */ |
| 2468 | re_enable_breakpoints_in_shlibs (); |
| 2469 | |
| 2470 | /* If requested, stop when the dynamic linker notifies |
| 2471 | gdb of events. This allows the user to get control |
| 2472 | and place breakpoints in initializer routines for |
| 2473 | dynamically loaded objects (among other things). */ |
| 2474 | if (stop_on_solib_events) |
| 2475 | { |
| 2476 | stop_stepping (ecs); |
| 2477 | return; |
| 2478 | } |
| 2479 | |
| 2480 | /* If we stopped due to an explicit catchpoint, then the |
| 2481 | (see above) call to SOLIB_ADD pulled in any symbols |
| 2482 | from a newly-loaded library, if appropriate. |
| 2483 | |
| 2484 | We do want the inferior to stop, but not where it is |
| 2485 | now, which is in the dynamic linker callback. Rather, |
| 2486 | we would like it stop in the user's program, just after |
| 2487 | the call that caused this catchpoint to trigger. That |
| 2488 | gives the user a more useful vantage from which to |
| 2489 | examine their program's state. */ |
| 2490 | else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) |
| 2491 | { |
| 2492 | /* ??rehrauer: If I could figure out how to get the |
| 2493 | right return PC from here, we could just set a temp |
| 2494 | breakpoint and resume. I'm not sure we can without |
| 2495 | cracking open the dld's shared libraries and sniffing |
| 2496 | their unwind tables and text/data ranges, and that's |
| 2497 | not a terribly portable notion. |
| 2498 | |
| 2499 | Until that time, we must step the inferior out of the |
| 2500 | dld callback, and also out of the dld itself (and any |
| 2501 | code or stubs in libdld.sl, such as "shl_load" and |
| 2502 | friends) until we reach non-dld code. At that point, |
| 2503 | we can stop stepping. */ |
| 2504 | bpstat_get_triggered_catchpoints (stop_bpstat, |
| 2505 | &ecs->stepping_through_solib_catchpoints); |
| 2506 | ecs->stepping_through_solib_after_catch = 1; |
| 2507 | |
| 2508 | /* Be sure to lift all breakpoints, so the inferior does |
| 2509 | actually step past this point... */ |
| 2510 | ecs->another_trap = 1; |
| 2511 | break; |
| 2512 | } |
| 2513 | else |
| 2514 | { |
| 2515 | /* We want to step over this breakpoint, then keep going. */ |
| 2516 | ecs->another_trap = 1; |
| 2517 | break; |
| 2518 | } |
| 2519 | } |
| 2520 | #endif |
| 2521 | break; |
| 2522 | |
| 2523 | case BPSTAT_WHAT_LAST: |
| 2524 | /* Not a real code, but listed here to shut up gcc -Wall. */ |
| 2525 | |
| 2526 | case BPSTAT_WHAT_KEEP_CHECKING: |
| 2527 | break; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | /* We come here if we hit a breakpoint but should not |
| 2532 | stop for it. Possibly we also were stepping |
| 2533 | and should stop for that. So fall through and |
| 2534 | test for stepping. But, if not stepping, |
| 2535 | do not stop. */ |
| 2536 | |
| 2537 | /* Are we stepping to get the inferior out of the dynamic |
| 2538 | linker's hook (and possibly the dld itself) after catching |
| 2539 | a shlib event? */ |
| 2540 | if (ecs->stepping_through_solib_after_catch) |
| 2541 | { |
| 2542 | #if defined(SOLIB_ADD) |
| 2543 | /* Have we reached our destination? If not, keep going. */ |
| 2544 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) |
| 2545 | { |
| 2546 | ecs->another_trap = 1; |
| 2547 | keep_going (ecs); |
| 2548 | return; |
| 2549 | } |
| 2550 | #endif |
| 2551 | /* Else, stop and report the catchpoint(s) whose triggering |
| 2552 | caused us to begin stepping. */ |
| 2553 | ecs->stepping_through_solib_after_catch = 0; |
| 2554 | bpstat_clear (&stop_bpstat); |
| 2555 | stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); |
| 2556 | bpstat_clear (&ecs->stepping_through_solib_catchpoints); |
| 2557 | stop_print_frame = 1; |
| 2558 | stop_stepping (ecs); |
| 2559 | return; |
| 2560 | } |
| 2561 | |
| 2562 | if (!CALL_DUMMY_BREAKPOINT_OFFSET_P) |
| 2563 | { |
| 2564 | /* This is the old way of detecting the end of the stack dummy. |
| 2565 | An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets |
| 2566 | handled above. As soon as we can test it on all of them, all |
| 2567 | architectures should define it. */ |
| 2568 | |
| 2569 | /* If this is the breakpoint at the end of a stack dummy, |
| 2570 | just stop silently, unless the user was doing an si/ni, in which |
| 2571 | case she'd better know what she's doing. */ |
| 2572 | |
| 2573 | if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (), |
| 2574 | FRAME_FP (get_current_frame ())) |
| 2575 | && !step_range_end) |
| 2576 | { |
| 2577 | stop_print_frame = 0; |
| 2578 | stop_stack_dummy = 1; |
| 2579 | #ifdef HP_OS_BUG |
| 2580 | trap_expected_after_continue = 1; |
| 2581 | #endif |
| 2582 | stop_stepping (ecs); |
| 2583 | return; |
| 2584 | } |
| 2585 | } |
| 2586 | |
| 2587 | if (step_resume_breakpoint) |
| 2588 | { |
| 2589 | /* Having a step-resume breakpoint overrides anything |
| 2590 | else having to do with stepping commands until |
| 2591 | that breakpoint is reached. */ |
| 2592 | /* I'm not sure whether this needs to be check_sigtramp2 or |
| 2593 | whether it could/should be keep_going. */ |
| 2594 | check_sigtramp2 (ecs); |
| 2595 | keep_going (ecs); |
| 2596 | return; |
| 2597 | } |
| 2598 | |
| 2599 | if (step_range_end == 0) |
| 2600 | { |
| 2601 | /* Likewise if we aren't even stepping. */ |
| 2602 | /* I'm not sure whether this needs to be check_sigtramp2 or |
| 2603 | whether it could/should be keep_going. */ |
| 2604 | check_sigtramp2 (ecs); |
| 2605 | keep_going (ecs); |
| 2606 | return; |
| 2607 | } |
| 2608 | |
| 2609 | /* If stepping through a line, keep going if still within it. |
| 2610 | |
| 2611 | Note that step_range_end is the address of the first instruction |
| 2612 | beyond the step range, and NOT the address of the last instruction |
| 2613 | within it! */ |
| 2614 | if (stop_pc >= step_range_start |
| 2615 | && stop_pc < step_range_end) |
| 2616 | { |
| 2617 | /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. |
| 2618 | So definately need to check for sigtramp here. */ |
| 2619 | check_sigtramp2 (ecs); |
| 2620 | keep_going (ecs); |
| 2621 | return; |
| 2622 | } |
| 2623 | |
| 2624 | /* We stepped out of the stepping range. */ |
| 2625 | |
| 2626 | /* If we are stepping at the source level and entered the runtime |
| 2627 | loader dynamic symbol resolution code, we keep on single stepping |
| 2628 | until we exit the run time loader code and reach the callee's |
| 2629 | address. */ |
| 2630 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc)) |
| 2631 | { |
| 2632 | CORE_ADDR pc_after_resolver = SKIP_SOLIB_RESOLVER (stop_pc); |
| 2633 | |
| 2634 | if (pc_after_resolver) |
| 2635 | { |
| 2636 | /* Set up a step-resume breakpoint at the address |
| 2637 | indicated by SKIP_SOLIB_RESOLVER. */ |
| 2638 | struct symtab_and_line sr_sal; |
| 2639 | INIT_SAL (&sr_sal); |
| 2640 | sr_sal.pc = pc_after_resolver; |
| 2641 | |
| 2642 | check_for_old_step_resume_breakpoint (); |
| 2643 | step_resume_breakpoint = |
| 2644 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
| 2645 | if (breakpoints_inserted) |
| 2646 | insert_breakpoints (); |
| 2647 | } |
| 2648 | |
| 2649 | keep_going (ecs); |
| 2650 | return; |
| 2651 | } |
| 2652 | |
| 2653 | /* We can't update step_sp every time through the loop, because |
| 2654 | reading the stack pointer would slow down stepping too much. |
| 2655 | But we can update it every time we leave the step range. */ |
| 2656 | ecs->update_step_sp = 1; |
| 2657 | |
| 2658 | /* Did we just take a signal? */ |
| 2659 | if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name) |
| 2660 | && !IN_SIGTRAMP (prev_pc, prev_func_name) |
| 2661 | && INNER_THAN (read_sp (), step_sp)) |
| 2662 | { |
| 2663 | /* We've just taken a signal; go until we are back to |
| 2664 | the point where we took it and one more. */ |
| 2665 | |
| 2666 | /* Note: The test above succeeds not only when we stepped |
| 2667 | into a signal handler, but also when we step past the last |
| 2668 | statement of a signal handler and end up in the return stub |
| 2669 | of the signal handler trampoline. To distinguish between |
| 2670 | these two cases, check that the frame is INNER_THAN the |
| 2671 | previous one below. pai/1997-09-11 */ |
| 2672 | |
| 2673 | |
| 2674 | { |
| 2675 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); |
| 2676 | |
| 2677 | if (INNER_THAN (current_frame, step_frame_address)) |
| 2678 | { |
| 2679 | /* We have just taken a signal; go until we are back to |
| 2680 | the point where we took it and one more. */ |
| 2681 | |
| 2682 | /* This code is needed at least in the following case: |
| 2683 | The user types "next" and then a signal arrives (before |
| 2684 | the "next" is done). */ |
| 2685 | |
| 2686 | /* Note that if we are stopped at a breakpoint, then we need |
| 2687 | the step_resume breakpoint to override any breakpoints at |
| 2688 | the same location, so that we will still step over the |
| 2689 | breakpoint even though the signal happened. */ |
| 2690 | struct symtab_and_line sr_sal; |
| 2691 | |
| 2692 | INIT_SAL (&sr_sal); |
| 2693 | sr_sal.symtab = NULL; |
| 2694 | sr_sal.line = 0; |
| 2695 | sr_sal.pc = prev_pc; |
| 2696 | /* We could probably be setting the frame to |
| 2697 | step_frame_address; I don't think anyone thought to |
| 2698 | try it. */ |
| 2699 | check_for_old_step_resume_breakpoint (); |
| 2700 | step_resume_breakpoint = |
| 2701 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
| 2702 | if (breakpoints_inserted) |
| 2703 | insert_breakpoints (); |
| 2704 | } |
| 2705 | else |
| 2706 | { |
| 2707 | /* We just stepped out of a signal handler and into |
| 2708 | its calling trampoline. |
| 2709 | |
| 2710 | Normally, we'd call step_over_function from |
| 2711 | here, but for some reason GDB can't unwind the |
| 2712 | stack correctly to find the real PC for the point |
| 2713 | user code where the signal trampoline will return |
| 2714 | -- FRAME_SAVED_PC fails, at least on HP-UX 10.20. |
| 2715 | But signal trampolines are pretty small stubs of |
| 2716 | code, anyway, so it's OK instead to just |
| 2717 | single-step out. Note: assuming such trampolines |
| 2718 | don't exhibit recursion on any platform... */ |
| 2719 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, |
| 2720 | &ecs->stop_func_start, |
| 2721 | &ecs->stop_func_end); |
| 2722 | /* Readjust stepping range */ |
| 2723 | step_range_start = ecs->stop_func_start; |
| 2724 | step_range_end = ecs->stop_func_end; |
| 2725 | ecs->stepping_through_sigtramp = 1; |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | |
| 2730 | /* If this is stepi or nexti, make sure that the stepping range |
| 2731 | gets us past that instruction. */ |
| 2732 | if (step_range_end == 1) |
| 2733 | /* FIXME: Does this run afoul of the code below which, if |
| 2734 | we step into the middle of a line, resets the stepping |
| 2735 | range? */ |
| 2736 | step_range_end = (step_range_start = prev_pc) + 1; |
| 2737 | |
| 2738 | ecs->remove_breakpoints_on_following_step = 1; |
| 2739 | keep_going (ecs); |
| 2740 | return; |
| 2741 | } |
| 2742 | |
| 2743 | if (stop_pc == ecs->stop_func_start /* Quick test */ |
| 2744 | || (in_prologue (stop_pc, ecs->stop_func_start) && |
| 2745 | !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) |
| 2746 | || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name) |
| 2747 | || ecs->stop_func_name == 0) |
| 2748 | { |
| 2749 | /* It's a subroutine call. */ |
| 2750 | |
| 2751 | if ((step_over_calls == STEP_OVER_NONE) |
| 2752 | || ((step_range_end == 1) |
| 2753 | && in_prologue (prev_pc, ecs->stop_func_start))) |
| 2754 | { |
| 2755 | /* I presume that step_over_calls is only 0 when we're |
| 2756 | supposed to be stepping at the assembly language level |
| 2757 | ("stepi"). Just stop. */ |
| 2758 | /* Also, maybe we just did a "nexti" inside a prolog, |
| 2759 | so we thought it was a subroutine call but it was not. |
| 2760 | Stop as well. FENN */ |
| 2761 | stop_step = 1; |
| 2762 | print_stop_reason (END_STEPPING_RANGE, 0); |
| 2763 | stop_stepping (ecs); |
| 2764 | return; |
| 2765 | } |
| 2766 | |
| 2767 | if (step_over_calls == STEP_OVER_ALL || IGNORE_HELPER_CALL (stop_pc)) |
| 2768 | { |
| 2769 | /* We're doing a "next". */ |
| 2770 | |
| 2771 | if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name) |
| 2772 | && INNER_THAN (step_frame_address, read_sp())) |
| 2773 | /* We stepped out of a signal handler, and into its |
| 2774 | calling trampoline. This is misdetected as a |
| 2775 | subroutine call, but stepping over the signal |
| 2776 | trampoline isn't such a bad idea. In order to do |
| 2777 | that, we have to ignore the value in |
| 2778 | step_frame_address, since that doesn't represent the |
| 2779 | frame that'll reach when we return from the signal |
| 2780 | trampoline. Otherwise we'll probably continue to the |
| 2781 | end of the program. */ |
| 2782 | step_frame_address = 0; |
| 2783 | |
| 2784 | step_over_function (ecs); |
| 2785 | keep_going (ecs); |
| 2786 | return; |
| 2787 | } |
| 2788 | |
| 2789 | /* If we are in a function call trampoline (a stub between |
| 2790 | the calling routine and the real function), locate the real |
| 2791 | function. That's what tells us (a) whether we want to step |
| 2792 | into it at all, and (b) what prologue we want to run to |
| 2793 | the end of, if we do step into it. */ |
| 2794 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); |
| 2795 | if (tmp != 0) |
| 2796 | ecs->stop_func_start = tmp; |
| 2797 | else |
| 2798 | { |
| 2799 | tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc); |
| 2800 | if (tmp) |
| 2801 | { |
| 2802 | struct symtab_and_line xxx; |
| 2803 | /* Why isn't this s_a_l called "sr_sal", like all of the |
| 2804 | other s_a_l's where this code is duplicated? */ |
| 2805 | INIT_SAL (&xxx); /* initialize to zeroes */ |
| 2806 | xxx.pc = tmp; |
| 2807 | xxx.section = find_pc_overlay (xxx.pc); |
| 2808 | check_for_old_step_resume_breakpoint (); |
| 2809 | step_resume_breakpoint = |
| 2810 | set_momentary_breakpoint (xxx, NULL, bp_step_resume); |
| 2811 | insert_breakpoints (); |
| 2812 | keep_going (ecs); |
| 2813 | return; |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | /* If we have line number information for the function we |
| 2818 | are thinking of stepping into, step into it. |
| 2819 | |
| 2820 | If there are several symtabs at that PC (e.g. with include |
| 2821 | files), just want to know whether *any* of them have line |
| 2822 | numbers. find_pc_line handles this. */ |
| 2823 | { |
| 2824 | struct symtab_and_line tmp_sal; |
| 2825 | |
| 2826 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
| 2827 | if (tmp_sal.line != 0) |
| 2828 | { |
| 2829 | step_into_function (ecs); |
| 2830 | return; |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | /* If we have no line number and the step-stop-if-no-debug |
| 2835 | is set, we stop the step so that the user has a chance to |
| 2836 | switch in assembly mode. */ |
| 2837 | if (step_over_calls == STEP_OVER_UNDEBUGGABLE && step_stop_if_no_debug) |
| 2838 | { |
| 2839 | stop_step = 1; |
| 2840 | print_stop_reason (END_STEPPING_RANGE, 0); |
| 2841 | stop_stepping (ecs); |
| 2842 | return; |
| 2843 | } |
| 2844 | |
| 2845 | step_over_function (ecs); |
| 2846 | keep_going (ecs); |
| 2847 | return; |
| 2848 | |
| 2849 | } |
| 2850 | |
| 2851 | /* We've wandered out of the step range. */ |
| 2852 | |
| 2853 | ecs->sal = find_pc_line (stop_pc, 0); |
| 2854 | |
| 2855 | if (step_range_end == 1) |
| 2856 | { |
| 2857 | /* It is stepi or nexti. We always want to stop stepping after |
| 2858 | one instruction. */ |
| 2859 | stop_step = 1; |
| 2860 | print_stop_reason (END_STEPPING_RANGE, 0); |
| 2861 | stop_stepping (ecs); |
| 2862 | return; |
| 2863 | } |
| 2864 | |
| 2865 | /* If we're in the return path from a shared library trampoline, |
| 2866 | we want to proceed through the trampoline when stepping. */ |
| 2867 | if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) |
| 2868 | { |
| 2869 | CORE_ADDR tmp; |
| 2870 | |
| 2871 | /* Determine where this trampoline returns. */ |
| 2872 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); |
| 2873 | |
| 2874 | /* Only proceed through if we know where it's going. */ |
| 2875 | if (tmp) |
| 2876 | { |
| 2877 | /* And put the step-breakpoint there and go until there. */ |
| 2878 | struct symtab_and_line sr_sal; |
| 2879 | |
| 2880 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 2881 | sr_sal.pc = tmp; |
| 2882 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
| 2883 | /* Do not specify what the fp should be when we stop |
| 2884 | since on some machines the prologue |
| 2885 | is where the new fp value is established. */ |
| 2886 | check_for_old_step_resume_breakpoint (); |
| 2887 | step_resume_breakpoint = |
| 2888 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
| 2889 | if (breakpoints_inserted) |
| 2890 | insert_breakpoints (); |
| 2891 | |
| 2892 | /* Restart without fiddling with the step ranges or |
| 2893 | other state. */ |
| 2894 | keep_going (ecs); |
| 2895 | return; |
| 2896 | } |
| 2897 | } |
| 2898 | |
| 2899 | if (ecs->sal.line == 0) |
| 2900 | { |
| 2901 | /* We have no line number information. That means to stop |
| 2902 | stepping (does this always happen right after one instruction, |
| 2903 | when we do "s" in a function with no line numbers, |
| 2904 | or can this happen as a result of a return or longjmp?). */ |
| 2905 | stop_step = 1; |
| 2906 | print_stop_reason (END_STEPPING_RANGE, 0); |
| 2907 | stop_stepping (ecs); |
| 2908 | return; |
| 2909 | } |
| 2910 | |
| 2911 | if ((stop_pc == ecs->sal.pc) |
| 2912 | && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab)) |
| 2913 | { |
| 2914 | /* We are at the start of a different line. So stop. Note that |
| 2915 | we don't stop if we step into the middle of a different line. |
| 2916 | That is said to make things like for (;;) statements work |
| 2917 | better. */ |
| 2918 | stop_step = 1; |
| 2919 | print_stop_reason (END_STEPPING_RANGE, 0); |
| 2920 | stop_stepping (ecs); |
| 2921 | return; |
| 2922 | } |
| 2923 | |
| 2924 | /* We aren't done stepping. |
| 2925 | |
| 2926 | Optimize by setting the stepping range to the line. |
| 2927 | (We might not be in the original line, but if we entered a |
| 2928 | new line in mid-statement, we continue stepping. This makes |
| 2929 | things like for(;;) statements work better.) */ |
| 2930 | |
| 2931 | if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end) |
| 2932 | { |
| 2933 | /* If this is the last line of the function, don't keep stepping |
| 2934 | (it would probably step us out of the function). |
| 2935 | This is particularly necessary for a one-line function, |
| 2936 | in which after skipping the prologue we better stop even though |
| 2937 | we will be in mid-line. */ |
| 2938 | stop_step = 1; |
| 2939 | print_stop_reason (END_STEPPING_RANGE, 0); |
| 2940 | stop_stepping (ecs); |
| 2941 | return; |
| 2942 | } |
| 2943 | step_range_start = ecs->sal.pc; |
| 2944 | step_range_end = ecs->sal.end; |
| 2945 | step_frame_address = FRAME_FP (get_current_frame ()); |
| 2946 | ecs->current_line = ecs->sal.line; |
| 2947 | ecs->current_symtab = ecs->sal.symtab; |
| 2948 | |
| 2949 | /* In the case where we just stepped out of a function into the middle |
| 2950 | of a line of the caller, continue stepping, but step_frame_address |
| 2951 | must be modified to current frame */ |
| 2952 | { |
| 2953 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); |
| 2954 | if (!(INNER_THAN (current_frame, step_frame_address))) |
| 2955 | step_frame_address = current_frame; |
| 2956 | } |
| 2957 | |
| 2958 | keep_going (ecs); |
| 2959 | |
| 2960 | } /* extra brace, to preserve old indentation */ |
| 2961 | } |
| 2962 | |
| 2963 | /* Are we in the middle of stepping? */ |
| 2964 | |
| 2965 | static int |
| 2966 | currently_stepping (struct execution_control_state *ecs) |
| 2967 | { |
| 2968 | return ((through_sigtramp_breakpoint == NULL |
| 2969 | && !ecs->handling_longjmp |
| 2970 | && ((step_range_end && step_resume_breakpoint == NULL) |
| 2971 | || trap_expected)) |
| 2972 | || ecs->stepping_through_solib_after_catch |
| 2973 | || bpstat_should_step ()); |
| 2974 | } |
| 2975 | |
| 2976 | static void |
| 2977 | check_sigtramp2 (struct execution_control_state *ecs) |
| 2978 | { |
| 2979 | if (trap_expected |
| 2980 | && IN_SIGTRAMP (stop_pc, ecs->stop_func_name) |
| 2981 | && !IN_SIGTRAMP (prev_pc, prev_func_name) |
| 2982 | && INNER_THAN (read_sp (), step_sp)) |
| 2983 | { |
| 2984 | /* What has happened here is that we have just stepped the |
| 2985 | inferior with a signal (because it is a signal which |
| 2986 | shouldn't make us stop), thus stepping into sigtramp. |
| 2987 | |
| 2988 | So we need to set a step_resume_break_address breakpoint and |
| 2989 | continue until we hit it, and then step. FIXME: This should |
| 2990 | be more enduring than a step_resume breakpoint; we should |
| 2991 | know that we will later need to keep going rather than |
| 2992 | re-hitting the breakpoint here (see the testsuite, |
| 2993 | gdb.base/signals.exp where it says "exceedingly difficult"). */ |
| 2994 | |
| 2995 | struct symtab_and_line sr_sal; |
| 2996 | |
| 2997 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 2998 | sr_sal.pc = prev_pc; |
| 2999 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
| 3000 | /* We perhaps could set the frame if we kept track of what the |
| 3001 | frame corresponding to prev_pc was. But we don't, so don't. */ |
| 3002 | through_sigtramp_breakpoint = |
| 3003 | set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp); |
| 3004 | if (breakpoints_inserted) |
| 3005 | insert_breakpoints (); |
| 3006 | |
| 3007 | ecs->remove_breakpoints_on_following_step = 1; |
| 3008 | ecs->another_trap = 1; |
| 3009 | } |
| 3010 | } |
| 3011 | |
| 3012 | /* Subroutine call with source code we should not step over. Do step |
| 3013 | to the first line of code in it. */ |
| 3014 | |
| 3015 | static void |
| 3016 | step_into_function (struct execution_control_state *ecs) |
| 3017 | { |
| 3018 | struct symtab *s; |
| 3019 | struct symtab_and_line sr_sal; |
| 3020 | |
| 3021 | s = find_pc_symtab (stop_pc); |
| 3022 | if (s && s->language != language_asm) |
| 3023 | ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start); |
| 3024 | |
| 3025 | ecs->sal = find_pc_line (ecs->stop_func_start, 0); |
| 3026 | /* Use the step_resume_break to step until the end of the prologue, |
| 3027 | even if that involves jumps (as it seems to on the vax under |
| 3028 | 4.2). */ |
| 3029 | /* If the prologue ends in the middle of a source line, continue to |
| 3030 | the end of that source line (if it is still within the function). |
| 3031 | Otherwise, just go to end of prologue. */ |
| 3032 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP |
| 3033 | /* no, don't either. It skips any code that's legitimately on the |
| 3034 | first line. */ |
| 3035 | #else |
| 3036 | if (ecs->sal.end |
| 3037 | && ecs->sal.pc != ecs->stop_func_start |
| 3038 | && ecs->sal.end < ecs->stop_func_end) |
| 3039 | ecs->stop_func_start = ecs->sal.end; |
| 3040 | #endif |
| 3041 | |
| 3042 | if (ecs->stop_func_start == stop_pc) |
| 3043 | { |
| 3044 | /* We are already there: stop now. */ |
| 3045 | stop_step = 1; |
| 3046 | print_stop_reason (END_STEPPING_RANGE, 0); |
| 3047 | stop_stepping (ecs); |
| 3048 | return; |
| 3049 | } |
| 3050 | else |
| 3051 | { |
| 3052 | /* Put the step-breakpoint there and go until there. */ |
| 3053 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
| 3054 | sr_sal.pc = ecs->stop_func_start; |
| 3055 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); |
| 3056 | /* Do not specify what the fp should be when we stop since on |
| 3057 | some machines the prologue is where the new fp value is |
| 3058 | established. */ |
| 3059 | check_for_old_step_resume_breakpoint (); |
| 3060 | step_resume_breakpoint = |
| 3061 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
| 3062 | if (breakpoints_inserted) |
| 3063 | insert_breakpoints (); |
| 3064 | |
| 3065 | /* And make sure stepping stops right away then. */ |
| 3066 | step_range_end = step_range_start; |
| 3067 | } |
| 3068 | keep_going (ecs); |
| 3069 | } |
| 3070 | |
| 3071 | /* We've just entered a callee, and we wish to resume until it returns |
| 3072 | to the caller. Setting a step_resume breakpoint on the return |
| 3073 | address will catch a return from the callee. |
| 3074 | |
| 3075 | However, if the callee is recursing, we want to be careful not to |
| 3076 | catch returns of those recursive calls, but only of THIS instance |
| 3077 | of the call. |
| 3078 | |
| 3079 | To do this, we set the step_resume bp's frame to our current |
| 3080 | caller's frame (step_frame_address, which is set by the "next" or |
| 3081 | "until" command, before execution begins). */ |
| 3082 | |
| 3083 | static void |
| 3084 | step_over_function (struct execution_control_state *ecs) |
| 3085 | { |
| 3086 | struct symtab_and_line sr_sal; |
| 3087 | |
| 3088 | INIT_SAL (&sr_sal); /* initialize to zeros */ |
| 3089 | sr_sal.pc = ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ())); |
| 3090 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
| 3091 | |
| 3092 | check_for_old_step_resume_breakpoint (); |
| 3093 | step_resume_breakpoint = |
| 3094 | set_momentary_breakpoint (sr_sal, get_current_frame (), bp_step_resume); |
| 3095 | |
| 3096 | if (step_frame_address && !IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc)) |
| 3097 | step_resume_breakpoint->frame = step_frame_address; |
| 3098 | |
| 3099 | if (breakpoints_inserted) |
| 3100 | insert_breakpoints (); |
| 3101 | } |
| 3102 | |
| 3103 | static void |
| 3104 | stop_stepping (struct execution_control_state *ecs) |
| 3105 | { |
| 3106 | if (target_has_execution) |
| 3107 | { |
| 3108 | /* Are we stopping for a vfork event? We only stop when we see |
| 3109 | the child's event. However, we may not yet have seen the |
| 3110 | parent's event. And, inferior_ptid is still set to the |
| 3111 | parent's pid, until we resume again and follow either the |
| 3112 | parent or child. |
| 3113 | |
| 3114 | To ensure that we can really touch inferior_ptid (aka, the |
| 3115 | parent process) -- which calls to functions like read_pc |
| 3116 | implicitly do -- wait on the parent if necessary. */ |
| 3117 | if ((pending_follow.kind == TARGET_WAITKIND_VFORKED) |
| 3118 | && !pending_follow.fork_event.saw_parent_fork) |
| 3119 | { |
| 3120 | ptid_t parent_ptid; |
| 3121 | |
| 3122 | do |
| 3123 | { |
| 3124 | if (target_wait_hook) |
| 3125 | parent_ptid = target_wait_hook (pid_to_ptid (-1), &(ecs->ws)); |
| 3126 | else |
| 3127 | parent_ptid = target_wait (pid_to_ptid (-1), &(ecs->ws)); |
| 3128 | } |
| 3129 | while (! ptid_equal (parent_ptid, inferior_ptid)); |
| 3130 | } |
| 3131 | |
| 3132 | /* Assuming the inferior still exists, set these up for next |
| 3133 | time, just like we did above if we didn't break out of the |
| 3134 | loop. */ |
| 3135 | prev_pc = read_pc (); |
| 3136 | prev_func_start = ecs->stop_func_start; |
| 3137 | prev_func_name = ecs->stop_func_name; |
| 3138 | } |
| 3139 | |
| 3140 | /* Let callers know we don't want to wait for the inferior anymore. */ |
| 3141 | ecs->wait_some_more = 0; |
| 3142 | } |
| 3143 | |
| 3144 | /* This function handles various cases where we need to continue |
| 3145 | waiting for the inferior. */ |
| 3146 | /* (Used to be the keep_going: label in the old wait_for_inferior) */ |
| 3147 | |
| 3148 | static void |
| 3149 | keep_going (struct execution_control_state *ecs) |
| 3150 | { |
| 3151 | /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug a |
| 3152 | vforked child between its creation and subsequent exit or call to |
| 3153 | exec(). However, I had big problems in this rather creaky exec |
| 3154 | engine, getting that to work. The fundamental problem is that |
| 3155 | I'm trying to debug two processes via an engine that only |
| 3156 | understands a single process with possibly multiple threads. |
| 3157 | |
| 3158 | Hence, this spot is known to have problems when |
| 3159 | target_can_follow_vfork_prior_to_exec returns 1. */ |
| 3160 | |
| 3161 | /* Save the pc before execution, to compare with pc after stop. */ |
| 3162 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ |
| 3163 | prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER |
| 3164 | BREAK is defined, the |
| 3165 | original pc would not have |
| 3166 | been at the start of a |
| 3167 | function. */ |
| 3168 | prev_func_name = ecs->stop_func_name; |
| 3169 | |
| 3170 | if (ecs->update_step_sp) |
| 3171 | step_sp = read_sp (); |
| 3172 | ecs->update_step_sp = 0; |
| 3173 | |
| 3174 | /* If we did not do break;, it means we should keep running the |
| 3175 | inferior and not return to debugger. */ |
| 3176 | |
| 3177 | if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) |
| 3178 | { |
| 3179 | /* We took a signal (which we are supposed to pass through to |
| 3180 | the inferior, else we'd have done a break above) and we |
| 3181 | haven't yet gotten our trap. Simply continue. */ |
| 3182 | resume (currently_stepping (ecs), stop_signal); |
| 3183 | } |
| 3184 | else |
| 3185 | { |
| 3186 | /* Either the trap was not expected, but we are continuing |
| 3187 | anyway (the user asked that this signal be passed to the |
| 3188 | child) |
| 3189 | -- or -- |
| 3190 | The signal was SIGTRAP, e.g. it was our signal, but we |
| 3191 | decided we should resume from it. |
| 3192 | |
| 3193 | We're going to run this baby now! |
| 3194 | |
| 3195 | Insert breakpoints now, unless we are trying to one-proceed |
| 3196 | past a breakpoint. */ |
| 3197 | /* If we've just finished a special step resume and we don't |
| 3198 | want to hit a breakpoint, pull em out. */ |
| 3199 | if (step_resume_breakpoint == NULL |
| 3200 | && through_sigtramp_breakpoint == NULL |
| 3201 | && ecs->remove_breakpoints_on_following_step) |
| 3202 | { |
| 3203 | ecs->remove_breakpoints_on_following_step = 0; |
| 3204 | remove_breakpoints (); |
| 3205 | breakpoints_inserted = 0; |
| 3206 | } |
| 3207 | else if (!breakpoints_inserted && |
| 3208 | (through_sigtramp_breakpoint != NULL || !ecs->another_trap)) |
| 3209 | { |
| 3210 | breakpoints_failed = insert_breakpoints (); |
| 3211 | if (breakpoints_failed) |
| 3212 | { |
| 3213 | stop_stepping (ecs); |
| 3214 | return; |
| 3215 | } |
| 3216 | breakpoints_inserted = 1; |
| 3217 | } |
| 3218 | |
| 3219 | trap_expected = ecs->another_trap; |
| 3220 | |
| 3221 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly |
| 3222 | specifies that such a signal should be delivered to the |
| 3223 | target program). |
| 3224 | |
| 3225 | Typically, this would occure when a user is debugging a |
| 3226 | target monitor on a simulator: the target monitor sets a |
| 3227 | breakpoint; the simulator encounters this break-point and |
| 3228 | halts the simulation handing control to GDB; GDB, noteing |
| 3229 | that the break-point isn't valid, returns control back to the |
| 3230 | simulator; the simulator then delivers the hardware |
| 3231 | equivalent of a SIGNAL_TRAP to the program being debugged. */ |
| 3232 | |
| 3233 | if (stop_signal == TARGET_SIGNAL_TRAP |
| 3234 | && !signal_program[stop_signal]) |
| 3235 | stop_signal = TARGET_SIGNAL_0; |
| 3236 | |
| 3237 | #ifdef SHIFT_INST_REGS |
| 3238 | /* I'm not sure when this following segment applies. I do know, |
| 3239 | now, that we shouldn't rewrite the regs when we were stopped |
| 3240 | by a random signal from the inferior process. */ |
| 3241 | /* FIXME: Shouldn't this be based on the valid bit of the SXIP? |
| 3242 | (this is only used on the 88k). */ |
| 3243 | |
| 3244 | if (!bpstat_explains_signal (stop_bpstat) |
| 3245 | && (stop_signal != TARGET_SIGNAL_CHLD) |
| 3246 | && !stopped_by_random_signal) |
| 3247 | SHIFT_INST_REGS (); |
| 3248 | #endif /* SHIFT_INST_REGS */ |
| 3249 | |
| 3250 | resume (currently_stepping (ecs), stop_signal); |
| 3251 | } |
| 3252 | |
| 3253 | prepare_to_wait (ecs); |
| 3254 | } |
| 3255 | |
| 3256 | /* This function normally comes after a resume, before |
| 3257 | handle_inferior_event exits. It takes care of any last bits of |
| 3258 | housekeeping, and sets the all-important wait_some_more flag. */ |
| 3259 | |
| 3260 | static void |
| 3261 | prepare_to_wait (struct execution_control_state *ecs) |
| 3262 | { |
| 3263 | if (ecs->infwait_state == infwait_normal_state) |
| 3264 | { |
| 3265 | overlay_cache_invalid = 1; |
| 3266 | |
| 3267 | /* We have to invalidate the registers BEFORE calling |
| 3268 | target_wait because they can be loaded from the target while |
| 3269 | in target_wait. This makes remote debugging a bit more |
| 3270 | efficient for those targets that provide critical registers |
| 3271 | as part of their normal status mechanism. */ |
| 3272 | |
| 3273 | registers_changed (); |
| 3274 | ecs->waiton_ptid = pid_to_ptid (-1); |
| 3275 | ecs->wp = &(ecs->ws); |
| 3276 | } |
| 3277 | /* This is the old end of the while loop. Let everybody know we |
| 3278 | want to wait for the inferior some more and get called again |
| 3279 | soon. */ |
| 3280 | ecs->wait_some_more = 1; |
| 3281 | } |
| 3282 | |
| 3283 | /* Print why the inferior has stopped. We always print something when |
| 3284 | the inferior exits, or receives a signal. The rest of the cases are |
| 3285 | dealt with later on in normal_stop() and print_it_typical(). Ideally |
| 3286 | there should be a call to this function from handle_inferior_event() |
| 3287 | each time stop_stepping() is called.*/ |
| 3288 | static void |
| 3289 | print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info) |
| 3290 | { |
| 3291 | switch (stop_reason) |
| 3292 | { |
| 3293 | case STOP_UNKNOWN: |
| 3294 | /* We don't deal with these cases from handle_inferior_event() |
| 3295 | yet. */ |
| 3296 | break; |
| 3297 | case END_STEPPING_RANGE: |
| 3298 | /* We are done with a step/next/si/ni command. */ |
| 3299 | /* For now print nothing. */ |
| 3300 | #ifdef UI_OUT |
| 3301 | /* Print a message only if not in the middle of doing a "step n" |
| 3302 | operation for n > 1 */ |
| 3303 | if (!step_multi || !stop_step) |
| 3304 | if (ui_out_is_mi_like_p (uiout)) |
| 3305 | ui_out_field_string (uiout, "reason", "end-stepping-range"); |
| 3306 | #endif |
| 3307 | break; |
| 3308 | case BREAKPOINT_HIT: |
| 3309 | /* We found a breakpoint. */ |
| 3310 | /* For now print nothing. */ |
| 3311 | break; |
| 3312 | case SIGNAL_EXITED: |
| 3313 | /* The inferior was terminated by a signal. */ |
| 3314 | #ifdef UI_OUT |
| 3315 | annotate_signalled (); |
| 3316 | if (ui_out_is_mi_like_p (uiout)) |
| 3317 | ui_out_field_string (uiout, "reason", "exited-signalled"); |
| 3318 | ui_out_text (uiout, "\nProgram terminated with signal "); |
| 3319 | annotate_signal_name (); |
| 3320 | ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info)); |
| 3321 | annotate_signal_name_end (); |
| 3322 | ui_out_text (uiout, ", "); |
| 3323 | annotate_signal_string (); |
| 3324 | ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info)); |
| 3325 | annotate_signal_string_end (); |
| 3326 | ui_out_text (uiout, ".\n"); |
| 3327 | ui_out_text (uiout, "The program no longer exists.\n"); |
| 3328 | #else |
| 3329 | annotate_signalled (); |
| 3330 | printf_filtered ("\nProgram terminated with signal "); |
| 3331 | annotate_signal_name (); |
| 3332 | printf_filtered ("%s", target_signal_to_name (stop_info)); |
| 3333 | annotate_signal_name_end (); |
| 3334 | printf_filtered (", "); |
| 3335 | annotate_signal_string (); |
| 3336 | printf_filtered ("%s", target_signal_to_string (stop_info)); |
| 3337 | annotate_signal_string_end (); |
| 3338 | printf_filtered (".\n"); |
| 3339 | |
| 3340 | printf_filtered ("The program no longer exists.\n"); |
| 3341 | gdb_flush (gdb_stdout); |
| 3342 | #endif |
| 3343 | break; |
| 3344 | case EXITED: |
| 3345 | /* The inferior program is finished. */ |
| 3346 | #ifdef UI_OUT |
| 3347 | annotate_exited (stop_info); |
| 3348 | if (stop_info) |
| 3349 | { |
| 3350 | if (ui_out_is_mi_like_p (uiout)) |
| 3351 | ui_out_field_string (uiout, "reason", "exited"); |
| 3352 | ui_out_text (uiout, "\nProgram exited with code "); |
| 3353 | ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) stop_info); |
| 3354 | ui_out_text (uiout, ".\n"); |
| 3355 | } |
| 3356 | else |
| 3357 | { |
| 3358 | if (ui_out_is_mi_like_p (uiout)) |
| 3359 | ui_out_field_string (uiout, "reason", "exited-normally"); |
| 3360 | ui_out_text (uiout, "\nProgram exited normally.\n"); |
| 3361 | } |
| 3362 | #else |
| 3363 | annotate_exited (stop_info); |
| 3364 | if (stop_info) |
| 3365 | printf_filtered ("\nProgram exited with code 0%o.\n", |
| 3366 | (unsigned int) stop_info); |
| 3367 | else |
| 3368 | printf_filtered ("\nProgram exited normally.\n"); |
| 3369 | #endif |
| 3370 | break; |
| 3371 | case SIGNAL_RECEIVED: |
| 3372 | /* Signal received. The signal table tells us to print about |
| 3373 | it. */ |
| 3374 | #ifdef UI_OUT |
| 3375 | annotate_signal (); |
| 3376 | ui_out_text (uiout, "\nProgram received signal "); |
| 3377 | annotate_signal_name (); |
| 3378 | if (ui_out_is_mi_like_p (uiout)) |
| 3379 | ui_out_field_string (uiout, "reason", "signal-received"); |
| 3380 | ui_out_field_string (uiout, "signal-name", target_signal_to_name (stop_info)); |
| 3381 | annotate_signal_name_end (); |
| 3382 | ui_out_text (uiout, ", "); |
| 3383 | annotate_signal_string (); |
| 3384 | ui_out_field_string (uiout, "signal-meaning", target_signal_to_string (stop_info)); |
| 3385 | annotate_signal_string_end (); |
| 3386 | ui_out_text (uiout, ".\n"); |
| 3387 | #else |
| 3388 | annotate_signal (); |
| 3389 | printf_filtered ("\nProgram received signal "); |
| 3390 | annotate_signal_name (); |
| 3391 | printf_filtered ("%s", target_signal_to_name (stop_info)); |
| 3392 | annotate_signal_name_end (); |
| 3393 | printf_filtered (", "); |
| 3394 | annotate_signal_string (); |
| 3395 | printf_filtered ("%s", target_signal_to_string (stop_info)); |
| 3396 | annotate_signal_string_end (); |
| 3397 | printf_filtered (".\n"); |
| 3398 | gdb_flush (gdb_stdout); |
| 3399 | #endif |
| 3400 | break; |
| 3401 | default: |
| 3402 | internal_error (__FILE__, __LINE__, |
| 3403 | "print_stop_reason: unrecognized enum value"); |
| 3404 | break; |
| 3405 | } |
| 3406 | } |
| 3407 | \f |
| 3408 | |
| 3409 | /* Here to return control to GDB when the inferior stops for real. |
| 3410 | Print appropriate messages, remove breakpoints, give terminal our modes. |
| 3411 | |
| 3412 | STOP_PRINT_FRAME nonzero means print the executing frame |
| 3413 | (pc, function, args, file, line number and line text). |
| 3414 | BREAKPOINTS_FAILED nonzero means stop was due to error |
| 3415 | attempting to insert breakpoints. */ |
| 3416 | |
| 3417 | void |
| 3418 | normal_stop (void) |
| 3419 | { |
| 3420 | /* As with the notification of thread events, we want to delay |
| 3421 | notifying the user that we've switched thread context until |
| 3422 | the inferior actually stops. |
| 3423 | |
| 3424 | (Note that there's no point in saying anything if the inferior |
| 3425 | has exited!) */ |
| 3426 | if (! ptid_equal (previous_inferior_ptid, inferior_ptid) |
| 3427 | && target_has_execution) |
| 3428 | { |
| 3429 | target_terminal_ours_for_output (); |
| 3430 | printf_filtered ("[Switching to %s]\n", |
| 3431 | target_pid_or_tid_to_str (inferior_ptid)); |
| 3432 | previous_inferior_ptid = inferior_ptid; |
| 3433 | } |
| 3434 | |
| 3435 | /* Make sure that the current_frame's pc is correct. This |
| 3436 | is a correction for setting up the frame info before doing |
| 3437 | DECR_PC_AFTER_BREAK */ |
| 3438 | if (target_has_execution && get_current_frame ()) |
| 3439 | (get_current_frame ())->pc = read_pc (); |
| 3440 | |
| 3441 | if (breakpoints_failed) |
| 3442 | { |
| 3443 | target_terminal_ours_for_output (); |
| 3444 | print_sys_errmsg ("While inserting breakpoints", breakpoints_failed); |
| 3445 | printf_filtered ("Stopped; cannot insert breakpoints.\n\ |
| 3446 | The same program may be running in another process,\n\ |
| 3447 | or you may have requested too many hardware breakpoints\n\ |
| 3448 | and/or watchpoints.\n"); |
| 3449 | } |
| 3450 | |
| 3451 | if (target_has_execution && breakpoints_inserted) |
| 3452 | { |
| 3453 | if (remove_breakpoints ()) |
| 3454 | { |
| 3455 | target_terminal_ours_for_output (); |
| 3456 | printf_filtered ("Cannot remove breakpoints because "); |
| 3457 | printf_filtered ("program is no longer writable.\n"); |
| 3458 | printf_filtered ("It might be running in another process.\n"); |
| 3459 | printf_filtered ("Further execution is probably impossible.\n"); |
| 3460 | } |
| 3461 | } |
| 3462 | breakpoints_inserted = 0; |
| 3463 | |
| 3464 | /* Delete the breakpoint we stopped at, if it wants to be deleted. |
| 3465 | Delete any breakpoint that is to be deleted at the next stop. */ |
| 3466 | |
| 3467 | breakpoint_auto_delete (stop_bpstat); |
| 3468 | |
| 3469 | /* If an auto-display called a function and that got a signal, |
| 3470 | delete that auto-display to avoid an infinite recursion. */ |
| 3471 | |
| 3472 | if (stopped_by_random_signal) |
| 3473 | disable_current_display (); |
| 3474 | |
| 3475 | /* Don't print a message if in the middle of doing a "step n" |
| 3476 | operation for n > 1 */ |
| 3477 | if (step_multi && stop_step) |
| 3478 | goto done; |
| 3479 | |
| 3480 | target_terminal_ours (); |
| 3481 | |
| 3482 | /* Look up the hook_stop and run it if it exists. */ |
| 3483 | |
| 3484 | if (stop_command && stop_command->hook_pre) |
| 3485 | { |
| 3486 | catch_errors (hook_stop_stub, stop_command->hook_pre, |
| 3487 | "Error while running hook_stop:\n", RETURN_MASK_ALL); |
| 3488 | } |
| 3489 | |
| 3490 | if (!target_has_stack) |
| 3491 | { |
| 3492 | |
| 3493 | goto done; |
| 3494 | } |
| 3495 | |
| 3496 | /* Select innermost stack frame - i.e., current frame is frame 0, |
| 3497 | and current location is based on that. |
| 3498 | Don't do this on return from a stack dummy routine, |
| 3499 | or if the program has exited. */ |
| 3500 | |
| 3501 | if (!stop_stack_dummy) |
| 3502 | { |
| 3503 | select_frame (get_current_frame (), 0); |
| 3504 | |
| 3505 | /* Print current location without a level number, if |
| 3506 | we have changed functions or hit a breakpoint. |
| 3507 | Print source line if we have one. |
| 3508 | bpstat_print() contains the logic deciding in detail |
| 3509 | what to print, based on the event(s) that just occurred. */ |
| 3510 | |
| 3511 | if (stop_print_frame |
| 3512 | && selected_frame) |
| 3513 | { |
| 3514 | int bpstat_ret; |
| 3515 | int source_flag; |
| 3516 | int do_frame_printing = 1; |
| 3517 | |
| 3518 | bpstat_ret = bpstat_print (stop_bpstat); |
| 3519 | switch (bpstat_ret) |
| 3520 | { |
| 3521 | case PRINT_UNKNOWN: |
| 3522 | if (stop_step |
| 3523 | && step_frame_address == FRAME_FP (get_current_frame ()) |
| 3524 | && step_start_function == find_pc_function (stop_pc)) |
| 3525 | source_flag = SRC_LINE; /* finished step, just print source line */ |
| 3526 | else |
| 3527 | source_flag = SRC_AND_LOC; /* print location and source line */ |
| 3528 | break; |
| 3529 | case PRINT_SRC_AND_LOC: |
| 3530 | source_flag = SRC_AND_LOC; /* print location and source line */ |
| 3531 | break; |
| 3532 | case PRINT_SRC_ONLY: |
| 3533 | source_flag = SRC_LINE; |
| 3534 | break; |
| 3535 | case PRINT_NOTHING: |
| 3536 | source_flag = SRC_LINE; /* something bogus */ |
| 3537 | do_frame_printing = 0; |
| 3538 | break; |
| 3539 | default: |
| 3540 | internal_error (__FILE__, __LINE__, |
| 3541 | "Unknown value."); |
| 3542 | } |
| 3543 | #ifdef UI_OUT |
| 3544 | /* For mi, have the same behavior every time we stop: |
| 3545 | print everything but the source line. */ |
| 3546 | if (ui_out_is_mi_like_p (uiout)) |
| 3547 | source_flag = LOC_AND_ADDRESS; |
| 3548 | #endif |
| 3549 | |
| 3550 | #ifdef UI_OUT |
| 3551 | if (ui_out_is_mi_like_p (uiout)) |
| 3552 | ui_out_field_int (uiout, "thread-id", |
| 3553 | pid_to_thread_id (inferior_ptid)); |
| 3554 | #endif |
| 3555 | /* The behavior of this routine with respect to the source |
| 3556 | flag is: |
| 3557 | SRC_LINE: Print only source line |
| 3558 | LOCATION: Print only location |
| 3559 | SRC_AND_LOC: Print location and source line */ |
| 3560 | if (do_frame_printing) |
| 3561 | show_and_print_stack_frame (selected_frame, -1, source_flag); |
| 3562 | |
| 3563 | /* Display the auto-display expressions. */ |
| 3564 | do_displays (); |
| 3565 | } |
| 3566 | } |
| 3567 | |
| 3568 | /* Save the function value return registers, if we care. |
| 3569 | We might be about to restore their previous contents. */ |
| 3570 | if (proceed_to_finish) |
| 3571 | read_register_bytes (0, stop_registers, REGISTER_BYTES); |
| 3572 | |
| 3573 | if (stop_stack_dummy) |
| 3574 | { |
| 3575 | /* Pop the empty frame that contains the stack dummy. |
| 3576 | POP_FRAME ends with a setting of the current frame, so we |
| 3577 | can use that next. */ |
| 3578 | POP_FRAME; |
| 3579 | /* Set stop_pc to what it was before we called the function. |
| 3580 | Can't rely on restore_inferior_status because that only gets |
| 3581 | called if we don't stop in the called function. */ |
| 3582 | stop_pc = read_pc (); |
| 3583 | select_frame (get_current_frame (), 0); |
| 3584 | } |
| 3585 | |
| 3586 | done: |
| 3587 | annotate_stopped (); |
| 3588 | } |
| 3589 | |
| 3590 | static int |
| 3591 | hook_stop_stub (void *cmd) |
| 3592 | { |
| 3593 | execute_user_command ((struct cmd_list_element *) cmd, 0); |
| 3594 | return (0); |
| 3595 | } |
| 3596 | \f |
| 3597 | int |
| 3598 | signal_stop_state (int signo) |
| 3599 | { |
| 3600 | return signal_stop[signo]; |
| 3601 | } |
| 3602 | |
| 3603 | int |
| 3604 | signal_print_state (int signo) |
| 3605 | { |
| 3606 | return signal_print[signo]; |
| 3607 | } |
| 3608 | |
| 3609 | int |
| 3610 | signal_pass_state (int signo) |
| 3611 | { |
| 3612 | return signal_program[signo]; |
| 3613 | } |
| 3614 | |
| 3615 | int signal_stop_update (signo, state) |
| 3616 | int signo; |
| 3617 | int state; |
| 3618 | { |
| 3619 | int ret = signal_stop[signo]; |
| 3620 | signal_stop[signo] = state; |
| 3621 | return ret; |
| 3622 | } |
| 3623 | |
| 3624 | int signal_print_update (signo, state) |
| 3625 | int signo; |
| 3626 | int state; |
| 3627 | { |
| 3628 | int ret = signal_print[signo]; |
| 3629 | signal_print[signo] = state; |
| 3630 | return ret; |
| 3631 | } |
| 3632 | |
| 3633 | int signal_pass_update (signo, state) |
| 3634 | int signo; |
| 3635 | int state; |
| 3636 | { |
| 3637 | int ret = signal_program[signo]; |
| 3638 | signal_program[signo] = state; |
| 3639 | return ret; |
| 3640 | } |
| 3641 | |
| 3642 | static void |
| 3643 | sig_print_header (void) |
| 3644 | { |
| 3645 | printf_filtered ("\ |
| 3646 | Signal Stop\tPrint\tPass to program\tDescription\n"); |
| 3647 | } |
| 3648 | |
| 3649 | static void |
| 3650 | sig_print_info (enum target_signal oursig) |
| 3651 | { |
| 3652 | char *name = target_signal_to_name (oursig); |
| 3653 | int name_padding = 13 - strlen (name); |
| 3654 | |
| 3655 | if (name_padding <= 0) |
| 3656 | name_padding = 0; |
| 3657 | |
| 3658 | printf_filtered ("%s", name); |
| 3659 | printf_filtered ("%*.*s ", name_padding, name_padding, |
| 3660 | " "); |
| 3661 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
| 3662 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); |
| 3663 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); |
| 3664 | printf_filtered ("%s\n", target_signal_to_string (oursig)); |
| 3665 | } |
| 3666 | |
| 3667 | /* Specify how various signals in the inferior should be handled. */ |
| 3668 | |
| 3669 | static void |
| 3670 | handle_command (char *args, int from_tty) |
| 3671 | { |
| 3672 | char **argv; |
| 3673 | int digits, wordlen; |
| 3674 | int sigfirst, signum, siglast; |
| 3675 | enum target_signal oursig; |
| 3676 | int allsigs; |
| 3677 | int nsigs; |
| 3678 | unsigned char *sigs; |
| 3679 | struct cleanup *old_chain; |
| 3680 | |
| 3681 | if (args == NULL) |
| 3682 | { |
| 3683 | error_no_arg ("signal to handle"); |
| 3684 | } |
| 3685 | |
| 3686 | /* Allocate and zero an array of flags for which signals to handle. */ |
| 3687 | |
| 3688 | nsigs = (int) TARGET_SIGNAL_LAST; |
| 3689 | sigs = (unsigned char *) alloca (nsigs); |
| 3690 | memset (sigs, 0, nsigs); |
| 3691 | |
| 3692 | /* Break the command line up into args. */ |
| 3693 | |
| 3694 | argv = buildargv (args); |
| 3695 | if (argv == NULL) |
| 3696 | { |
| 3697 | nomem (0); |
| 3698 | } |
| 3699 | old_chain = make_cleanup_freeargv (argv); |
| 3700 | |
| 3701 | /* Walk through the args, looking for signal oursigs, signal names, and |
| 3702 | actions. Signal numbers and signal names may be interspersed with |
| 3703 | actions, with the actions being performed for all signals cumulatively |
| 3704 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ |
| 3705 | |
| 3706 | while (*argv != NULL) |
| 3707 | { |
| 3708 | wordlen = strlen (*argv); |
| 3709 | for (digits = 0; isdigit ((*argv)[digits]); digits++) |
| 3710 | {; |
| 3711 | } |
| 3712 | allsigs = 0; |
| 3713 | sigfirst = siglast = -1; |
| 3714 | |
| 3715 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) |
| 3716 | { |
| 3717 | /* Apply action to all signals except those used by the |
| 3718 | debugger. Silently skip those. */ |
| 3719 | allsigs = 1; |
| 3720 | sigfirst = 0; |
| 3721 | siglast = nsigs - 1; |
| 3722 | } |
| 3723 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) |
| 3724 | { |
| 3725 | SET_SIGS (nsigs, sigs, signal_stop); |
| 3726 | SET_SIGS (nsigs, sigs, signal_print); |
| 3727 | } |
| 3728 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) |
| 3729 | { |
| 3730 | UNSET_SIGS (nsigs, sigs, signal_program); |
| 3731 | } |
| 3732 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) |
| 3733 | { |
| 3734 | SET_SIGS (nsigs, sigs, signal_print); |
| 3735 | } |
| 3736 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) |
| 3737 | { |
| 3738 | SET_SIGS (nsigs, sigs, signal_program); |
| 3739 | } |
| 3740 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) |
| 3741 | { |
| 3742 | UNSET_SIGS (nsigs, sigs, signal_stop); |
| 3743 | } |
| 3744 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) |
| 3745 | { |
| 3746 | SET_SIGS (nsigs, sigs, signal_program); |
| 3747 | } |
| 3748 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) |
| 3749 | { |
| 3750 | UNSET_SIGS (nsigs, sigs, signal_print); |
| 3751 | UNSET_SIGS (nsigs, sigs, signal_stop); |
| 3752 | } |
| 3753 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) |
| 3754 | { |
| 3755 | UNSET_SIGS (nsigs, sigs, signal_program); |
| 3756 | } |
| 3757 | else if (digits > 0) |
| 3758 | { |
| 3759 | /* It is numeric. The numeric signal refers to our own |
| 3760 | internal signal numbering from target.h, not to host/target |
| 3761 | signal number. This is a feature; users really should be |
| 3762 | using symbolic names anyway, and the common ones like |
| 3763 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ |
| 3764 | |
| 3765 | sigfirst = siglast = (int) |
| 3766 | target_signal_from_command (atoi (*argv)); |
| 3767 | if ((*argv)[digits] == '-') |
| 3768 | { |
| 3769 | siglast = (int) |
| 3770 | target_signal_from_command (atoi ((*argv) + digits + 1)); |
| 3771 | } |
| 3772 | if (sigfirst > siglast) |
| 3773 | { |
| 3774 | /* Bet he didn't figure we'd think of this case... */ |
| 3775 | signum = sigfirst; |
| 3776 | sigfirst = siglast; |
| 3777 | siglast = signum; |
| 3778 | } |
| 3779 | } |
| 3780 | else |
| 3781 | { |
| 3782 | oursig = target_signal_from_name (*argv); |
| 3783 | if (oursig != TARGET_SIGNAL_UNKNOWN) |
| 3784 | { |
| 3785 | sigfirst = siglast = (int) oursig; |
| 3786 | } |
| 3787 | else |
| 3788 | { |
| 3789 | /* Not a number and not a recognized flag word => complain. */ |
| 3790 | error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); |
| 3791 | } |
| 3792 | } |
| 3793 | |
| 3794 | /* If any signal numbers or symbol names were found, set flags for |
| 3795 | which signals to apply actions to. */ |
| 3796 | |
| 3797 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) |
| 3798 | { |
| 3799 | switch ((enum target_signal) signum) |
| 3800 | { |
| 3801 | case TARGET_SIGNAL_TRAP: |
| 3802 | case TARGET_SIGNAL_INT: |
| 3803 | if (!allsigs && !sigs[signum]) |
| 3804 | { |
| 3805 | if (query ("%s is used by the debugger.\n\ |
| 3806 | Are you sure you want to change it? ", |
| 3807 | target_signal_to_name |
| 3808 | ((enum target_signal) signum))) |
| 3809 | { |
| 3810 | sigs[signum] = 1; |
| 3811 | } |
| 3812 | else |
| 3813 | { |
| 3814 | printf_unfiltered ("Not confirmed, unchanged.\n"); |
| 3815 | gdb_flush (gdb_stdout); |
| 3816 | } |
| 3817 | } |
| 3818 | break; |
| 3819 | case TARGET_SIGNAL_0: |
| 3820 | case TARGET_SIGNAL_DEFAULT: |
| 3821 | case TARGET_SIGNAL_UNKNOWN: |
| 3822 | /* Make sure that "all" doesn't print these. */ |
| 3823 | break; |
| 3824 | default: |
| 3825 | sigs[signum] = 1; |
| 3826 | break; |
| 3827 | } |
| 3828 | } |
| 3829 | |
| 3830 | argv++; |
| 3831 | } |
| 3832 | |
| 3833 | target_notice_signals (inferior_ptid); |
| 3834 | |
| 3835 | if (from_tty) |
| 3836 | { |
| 3837 | /* Show the results. */ |
| 3838 | sig_print_header (); |
| 3839 | for (signum = 0; signum < nsigs; signum++) |
| 3840 | { |
| 3841 | if (sigs[signum]) |
| 3842 | { |
| 3843 | sig_print_info (signum); |
| 3844 | } |
| 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | do_cleanups (old_chain); |
| 3849 | } |
| 3850 | |
| 3851 | static void |
| 3852 | xdb_handle_command (char *args, int from_tty) |
| 3853 | { |
| 3854 | char **argv; |
| 3855 | struct cleanup *old_chain; |
| 3856 | |
| 3857 | /* Break the command line up into args. */ |
| 3858 | |
| 3859 | argv = buildargv (args); |
| 3860 | if (argv == NULL) |
| 3861 | { |
| 3862 | nomem (0); |
| 3863 | } |
| 3864 | old_chain = make_cleanup_freeargv (argv); |
| 3865 | if (argv[1] != (char *) NULL) |
| 3866 | { |
| 3867 | char *argBuf; |
| 3868 | int bufLen; |
| 3869 | |
| 3870 | bufLen = strlen (argv[0]) + 20; |
| 3871 | argBuf = (char *) xmalloc (bufLen); |
| 3872 | if (argBuf) |
| 3873 | { |
| 3874 | int validFlag = 1; |
| 3875 | enum target_signal oursig; |
| 3876 | |
| 3877 | oursig = target_signal_from_name (argv[0]); |
| 3878 | memset (argBuf, 0, bufLen); |
| 3879 | if (strcmp (argv[1], "Q") == 0) |
| 3880 | sprintf (argBuf, "%s %s", argv[0], "noprint"); |
| 3881 | else |
| 3882 | { |
| 3883 | if (strcmp (argv[1], "s") == 0) |
| 3884 | { |
| 3885 | if (!signal_stop[oursig]) |
| 3886 | sprintf (argBuf, "%s %s", argv[0], "stop"); |
| 3887 | else |
| 3888 | sprintf (argBuf, "%s %s", argv[0], "nostop"); |
| 3889 | } |
| 3890 | else if (strcmp (argv[1], "i") == 0) |
| 3891 | { |
| 3892 | if (!signal_program[oursig]) |
| 3893 | sprintf (argBuf, "%s %s", argv[0], "pass"); |
| 3894 | else |
| 3895 | sprintf (argBuf, "%s %s", argv[0], "nopass"); |
| 3896 | } |
| 3897 | else if (strcmp (argv[1], "r") == 0) |
| 3898 | { |
| 3899 | if (!signal_print[oursig]) |
| 3900 | sprintf (argBuf, "%s %s", argv[0], "print"); |
| 3901 | else |
| 3902 | sprintf (argBuf, "%s %s", argv[0], "noprint"); |
| 3903 | } |
| 3904 | else |
| 3905 | validFlag = 0; |
| 3906 | } |
| 3907 | if (validFlag) |
| 3908 | handle_command (argBuf, from_tty); |
| 3909 | else |
| 3910 | printf_filtered ("Invalid signal handling flag.\n"); |
| 3911 | if (argBuf) |
| 3912 | xfree (argBuf); |
| 3913 | } |
| 3914 | } |
| 3915 | do_cleanups (old_chain); |
| 3916 | } |
| 3917 | |
| 3918 | /* Print current contents of the tables set by the handle command. |
| 3919 | It is possible we should just be printing signals actually used |
| 3920 | by the current target (but for things to work right when switching |
| 3921 | targets, all signals should be in the signal tables). */ |
| 3922 | |
| 3923 | static void |
| 3924 | signals_info (char *signum_exp, int from_tty) |
| 3925 | { |
| 3926 | enum target_signal oursig; |
| 3927 | sig_print_header (); |
| 3928 | |
| 3929 | if (signum_exp) |
| 3930 | { |
| 3931 | /* First see if this is a symbol name. */ |
| 3932 | oursig = target_signal_from_name (signum_exp); |
| 3933 | if (oursig == TARGET_SIGNAL_UNKNOWN) |
| 3934 | { |
| 3935 | /* No, try numeric. */ |
| 3936 | oursig = |
| 3937 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
| 3938 | } |
| 3939 | sig_print_info (oursig); |
| 3940 | return; |
| 3941 | } |
| 3942 | |
| 3943 | printf_filtered ("\n"); |
| 3944 | /* These ugly casts brought to you by the native VAX compiler. */ |
| 3945 | for (oursig = TARGET_SIGNAL_FIRST; |
| 3946 | (int) oursig < (int) TARGET_SIGNAL_LAST; |
| 3947 | oursig = (enum target_signal) ((int) oursig + 1)) |
| 3948 | { |
| 3949 | QUIT; |
| 3950 | |
| 3951 | if (oursig != TARGET_SIGNAL_UNKNOWN |
| 3952 | && oursig != TARGET_SIGNAL_DEFAULT |
| 3953 | && oursig != TARGET_SIGNAL_0) |
| 3954 | sig_print_info (oursig); |
| 3955 | } |
| 3956 | |
| 3957 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); |
| 3958 | } |
| 3959 | \f |
| 3960 | struct inferior_status |
| 3961 | { |
| 3962 | enum target_signal stop_signal; |
| 3963 | CORE_ADDR stop_pc; |
| 3964 | bpstat stop_bpstat; |
| 3965 | int stop_step; |
| 3966 | int stop_stack_dummy; |
| 3967 | int stopped_by_random_signal; |
| 3968 | int trap_expected; |
| 3969 | CORE_ADDR step_range_start; |
| 3970 | CORE_ADDR step_range_end; |
| 3971 | CORE_ADDR step_frame_address; |
| 3972 | enum step_over_calls_kind step_over_calls; |
| 3973 | CORE_ADDR step_resume_break_address; |
| 3974 | int stop_after_trap; |
| 3975 | int stop_soon_quietly; |
| 3976 | CORE_ADDR selected_frame_address; |
| 3977 | char *stop_registers; |
| 3978 | |
| 3979 | /* These are here because if call_function_by_hand has written some |
| 3980 | registers and then decides to call error(), we better not have changed |
| 3981 | any registers. */ |
| 3982 | char *registers; |
| 3983 | |
| 3984 | int selected_level; |
| 3985 | int breakpoint_proceeded; |
| 3986 | int restore_stack_info; |
| 3987 | int proceed_to_finish; |
| 3988 | }; |
| 3989 | |
| 3990 | static struct inferior_status * |
| 3991 | xmalloc_inferior_status (void) |
| 3992 | { |
| 3993 | struct inferior_status *inf_status; |
| 3994 | inf_status = xmalloc (sizeof (struct inferior_status)); |
| 3995 | inf_status->stop_registers = xmalloc (REGISTER_BYTES); |
| 3996 | inf_status->registers = xmalloc (REGISTER_BYTES); |
| 3997 | return inf_status; |
| 3998 | } |
| 3999 | |
| 4000 | static void |
| 4001 | free_inferior_status (struct inferior_status *inf_status) |
| 4002 | { |
| 4003 | xfree (inf_status->registers); |
| 4004 | xfree (inf_status->stop_registers); |
| 4005 | xfree (inf_status); |
| 4006 | } |
| 4007 | |
| 4008 | void |
| 4009 | write_inferior_status_register (struct inferior_status *inf_status, int regno, |
| 4010 | LONGEST val) |
| 4011 | { |
| 4012 | int size = REGISTER_RAW_SIZE (regno); |
| 4013 | void *buf = alloca (size); |
| 4014 | store_signed_integer (buf, size, val); |
| 4015 | memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size); |
| 4016 | } |
| 4017 | |
| 4018 | /* Save all of the information associated with the inferior<==>gdb |
| 4019 | connection. INF_STATUS is a pointer to a "struct inferior_status" |
| 4020 | (defined in inferior.h). */ |
| 4021 | |
| 4022 | struct inferior_status * |
| 4023 | save_inferior_status (int restore_stack_info) |
| 4024 | { |
| 4025 | struct inferior_status *inf_status = xmalloc_inferior_status (); |
| 4026 | |
| 4027 | inf_status->stop_signal = stop_signal; |
| 4028 | inf_status->stop_pc = stop_pc; |
| 4029 | inf_status->stop_step = stop_step; |
| 4030 | inf_status->stop_stack_dummy = stop_stack_dummy; |
| 4031 | inf_status->stopped_by_random_signal = stopped_by_random_signal; |
| 4032 | inf_status->trap_expected = trap_expected; |
| 4033 | inf_status->step_range_start = step_range_start; |
| 4034 | inf_status->step_range_end = step_range_end; |
| 4035 | inf_status->step_frame_address = step_frame_address; |
| 4036 | inf_status->step_over_calls = step_over_calls; |
| 4037 | inf_status->stop_after_trap = stop_after_trap; |
| 4038 | inf_status->stop_soon_quietly = stop_soon_quietly; |
| 4039 | /* Save original bpstat chain here; replace it with copy of chain. |
| 4040 | If caller's caller is walking the chain, they'll be happier if we |
| 4041 | hand them back the original chain when restore_inferior_status is |
| 4042 | called. */ |
| 4043 | inf_status->stop_bpstat = stop_bpstat; |
| 4044 | stop_bpstat = bpstat_copy (stop_bpstat); |
| 4045 | inf_status->breakpoint_proceeded = breakpoint_proceeded; |
| 4046 | inf_status->restore_stack_info = restore_stack_info; |
| 4047 | inf_status->proceed_to_finish = proceed_to_finish; |
| 4048 | |
| 4049 | memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); |
| 4050 | |
| 4051 | read_register_bytes (0, inf_status->registers, REGISTER_BYTES); |
| 4052 | |
| 4053 | record_selected_frame (&(inf_status->selected_frame_address), |
| 4054 | &(inf_status->selected_level)); |
| 4055 | return inf_status; |
| 4056 | } |
| 4057 | |
| 4058 | struct restore_selected_frame_args |
| 4059 | { |
| 4060 | CORE_ADDR frame_address; |
| 4061 | int level; |
| 4062 | }; |
| 4063 | |
| 4064 | static int |
| 4065 | restore_selected_frame (void *args) |
| 4066 | { |
| 4067 | struct restore_selected_frame_args *fr = |
| 4068 | (struct restore_selected_frame_args *) args; |
| 4069 | struct frame_info *frame; |
| 4070 | int level = fr->level; |
| 4071 | |
| 4072 | frame = find_relative_frame (get_current_frame (), &level); |
| 4073 | |
| 4074 | /* If inf_status->selected_frame_address is NULL, there was no |
| 4075 | previously selected frame. */ |
| 4076 | if (frame == NULL || |
| 4077 | /* FRAME_FP (frame) != fr->frame_address || */ |
| 4078 | /* elz: deleted this check as a quick fix to the problem that |
| 4079 | for function called by hand gdb creates no internal frame |
| 4080 | structure and the real stack and gdb's idea of stack are |
| 4081 | different if nested calls by hands are made. |
| 4082 | |
| 4083 | mvs: this worries me. */ |
| 4084 | level != 0) |
| 4085 | { |
| 4086 | warning ("Unable to restore previously selected frame.\n"); |
| 4087 | return 0; |
| 4088 | } |
| 4089 | |
| 4090 | select_frame (frame, fr->level); |
| 4091 | |
| 4092 | return (1); |
| 4093 | } |
| 4094 | |
| 4095 | void |
| 4096 | restore_inferior_status (struct inferior_status *inf_status) |
| 4097 | { |
| 4098 | stop_signal = inf_status->stop_signal; |
| 4099 | stop_pc = inf_status->stop_pc; |
| 4100 | stop_step = inf_status->stop_step; |
| 4101 | stop_stack_dummy = inf_status->stop_stack_dummy; |
| 4102 | stopped_by_random_signal = inf_status->stopped_by_random_signal; |
| 4103 | trap_expected = inf_status->trap_expected; |
| 4104 | step_range_start = inf_status->step_range_start; |
| 4105 | step_range_end = inf_status->step_range_end; |
| 4106 | step_frame_address = inf_status->step_frame_address; |
| 4107 | step_over_calls = inf_status->step_over_calls; |
| 4108 | stop_after_trap = inf_status->stop_after_trap; |
| 4109 | stop_soon_quietly = inf_status->stop_soon_quietly; |
| 4110 | bpstat_clear (&stop_bpstat); |
| 4111 | stop_bpstat = inf_status->stop_bpstat; |
| 4112 | breakpoint_proceeded = inf_status->breakpoint_proceeded; |
| 4113 | proceed_to_finish = inf_status->proceed_to_finish; |
| 4114 | |
| 4115 | /* FIXME: Is the restore of stop_registers always needed */ |
| 4116 | memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); |
| 4117 | |
| 4118 | /* The inferior can be gone if the user types "print exit(0)" |
| 4119 | (and perhaps other times). */ |
| 4120 | if (target_has_execution) |
| 4121 | write_register_bytes (0, inf_status->registers, REGISTER_BYTES); |
| 4122 | |
| 4123 | /* FIXME: If we are being called after stopping in a function which |
| 4124 | is called from gdb, we should not be trying to restore the |
| 4125 | selected frame; it just prints a spurious error message (The |
| 4126 | message is useful, however, in detecting bugs in gdb (like if gdb |
| 4127 | clobbers the stack)). In fact, should we be restoring the |
| 4128 | inferior status at all in that case? . */ |
| 4129 | |
| 4130 | if (target_has_stack && inf_status->restore_stack_info) |
| 4131 | { |
| 4132 | struct restore_selected_frame_args fr; |
| 4133 | fr.level = inf_status->selected_level; |
| 4134 | fr.frame_address = inf_status->selected_frame_address; |
| 4135 | /* The point of catch_errors is that if the stack is clobbered, |
| 4136 | walking the stack might encounter a garbage pointer and error() |
| 4137 | trying to dereference it. */ |
| 4138 | if (catch_errors (restore_selected_frame, &fr, |
| 4139 | "Unable to restore previously selected frame:\n", |
| 4140 | RETURN_MASK_ERROR) == 0) |
| 4141 | /* Error in restoring the selected frame. Select the innermost |
| 4142 | frame. */ |
| 4143 | |
| 4144 | |
| 4145 | select_frame (get_current_frame (), 0); |
| 4146 | |
| 4147 | } |
| 4148 | |
| 4149 | free_inferior_status (inf_status); |
| 4150 | } |
| 4151 | |
| 4152 | static void |
| 4153 | do_restore_inferior_status_cleanup (void *sts) |
| 4154 | { |
| 4155 | restore_inferior_status (sts); |
| 4156 | } |
| 4157 | |
| 4158 | struct cleanup * |
| 4159 | make_cleanup_restore_inferior_status (struct inferior_status *inf_status) |
| 4160 | { |
| 4161 | return make_cleanup (do_restore_inferior_status_cleanup, inf_status); |
| 4162 | } |
| 4163 | |
| 4164 | void |
| 4165 | discard_inferior_status (struct inferior_status *inf_status) |
| 4166 | { |
| 4167 | /* See save_inferior_status for info on stop_bpstat. */ |
| 4168 | bpstat_clear (&inf_status->stop_bpstat); |
| 4169 | free_inferior_status (inf_status); |
| 4170 | } |
| 4171 | |
| 4172 | /* Oft used ptids */ |
| 4173 | ptid_t null_ptid; |
| 4174 | ptid_t minus_one_ptid; |
| 4175 | |
| 4176 | /* Create a ptid given the necessary PID, LWP, and TID components. */ |
| 4177 | |
| 4178 | ptid_t |
| 4179 | ptid_build (int pid, long lwp, long tid) |
| 4180 | { |
| 4181 | ptid_t ptid; |
| 4182 | |
| 4183 | ptid.pid = pid; |
| 4184 | ptid.lwp = lwp; |
| 4185 | ptid.tid = tid; |
| 4186 | return ptid; |
| 4187 | } |
| 4188 | |
| 4189 | /* Create a ptid from just a pid. */ |
| 4190 | |
| 4191 | ptid_t |
| 4192 | pid_to_ptid (int pid) |
| 4193 | { |
| 4194 | return ptid_build (pid, 0, 0); |
| 4195 | } |
| 4196 | |
| 4197 | /* Fetch the pid (process id) component from a ptid. */ |
| 4198 | |
| 4199 | int |
| 4200 | ptid_get_pid (ptid_t ptid) |
| 4201 | { |
| 4202 | return ptid.pid; |
| 4203 | } |
| 4204 | |
| 4205 | /* Fetch the lwp (lightweight process) component from a ptid. */ |
| 4206 | |
| 4207 | long |
| 4208 | ptid_get_lwp (ptid_t ptid) |
| 4209 | { |
| 4210 | return ptid.lwp; |
| 4211 | } |
| 4212 | |
| 4213 | /* Fetch the tid (thread id) component from a ptid. */ |
| 4214 | |
| 4215 | long |
| 4216 | ptid_get_tid (ptid_t ptid) |
| 4217 | { |
| 4218 | return ptid.tid; |
| 4219 | } |
| 4220 | |
| 4221 | /* ptid_equal() is used to test equality of two ptids. */ |
| 4222 | |
| 4223 | int |
| 4224 | ptid_equal (ptid_t ptid1, ptid_t ptid2) |
| 4225 | { |
| 4226 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp |
| 4227 | && ptid1.tid == ptid2.tid); |
| 4228 | } |
| 4229 | |
| 4230 | /* restore_inferior_ptid() will be used by the cleanup machinery |
| 4231 | to restore the inferior_ptid value saved in a call to |
| 4232 | save_inferior_ptid(). */ |
| 4233 | |
| 4234 | static void |
| 4235 | restore_inferior_ptid (void *arg) |
| 4236 | { |
| 4237 | ptid_t *saved_ptid_ptr = arg; |
| 4238 | inferior_ptid = *saved_ptid_ptr; |
| 4239 | xfree (arg); |
| 4240 | } |
| 4241 | |
| 4242 | /* Save the value of inferior_ptid so that it may be restored by a |
| 4243 | later call to do_cleanups(). Returns the struct cleanup pointer |
| 4244 | needed for later doing the cleanup. */ |
| 4245 | |
| 4246 | struct cleanup * |
| 4247 | save_inferior_ptid (void) |
| 4248 | { |
| 4249 | ptid_t *saved_ptid_ptr; |
| 4250 | |
| 4251 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); |
| 4252 | *saved_ptid_ptr = inferior_ptid; |
| 4253 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); |
| 4254 | } |
| 4255 | |
| 4256 | \f |
| 4257 | static void |
| 4258 | build_infrun (void) |
| 4259 | { |
| 4260 | stop_registers = xmalloc (REGISTER_BYTES); |
| 4261 | } |
| 4262 | |
| 4263 | void |
| 4264 | _initialize_infrun (void) |
| 4265 | { |
| 4266 | register int i; |
| 4267 | register int numsigs; |
| 4268 | struct cmd_list_element *c; |
| 4269 | |
| 4270 | build_infrun (); |
| 4271 | |
| 4272 | register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL); |
| 4273 | register_gdbarch_swap (NULL, 0, build_infrun); |
| 4274 | |
| 4275 | add_info ("signals", signals_info, |
| 4276 | "What debugger does when program gets various signals.\n\ |
| 4277 | Specify a signal as argument to print info on that signal only."); |
| 4278 | add_info_alias ("handle", "signals", 0); |
| 4279 | |
| 4280 | add_com ("handle", class_run, handle_command, |
| 4281 | concat ("Specify how to handle a signal.\n\ |
| 4282 | Args are signals and actions to apply to those signals.\n\ |
| 4283 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ |
| 4284 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ |
| 4285 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ |
| 4286 | The special arg \"all\" is recognized to mean all signals except those\n\ |
| 4287 | used by the debugger, typically SIGTRAP and SIGINT.\n", |
| 4288 | "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ |
| 4289 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
| 4290 | Stop means reenter debugger if this signal happens (implies print).\n\ |
| 4291 | Print means print a message if this signal happens.\n\ |
| 4292 | Pass means let program see this signal; otherwise program doesn't know.\n\ |
| 4293 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ |
| 4294 | Pass and Stop may be combined.", NULL)); |
| 4295 | if (xdb_commands) |
| 4296 | { |
| 4297 | add_com ("lz", class_info, signals_info, |
| 4298 | "What debugger does when program gets various signals.\n\ |
| 4299 | Specify a signal as argument to print info on that signal only."); |
| 4300 | add_com ("z", class_run, xdb_handle_command, |
| 4301 | concat ("Specify how to handle a signal.\n\ |
| 4302 | Args are signals and actions to apply to those signals.\n\ |
| 4303 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ |
| 4304 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ |
| 4305 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ |
| 4306 | The special arg \"all\" is recognized to mean all signals except those\n\ |
| 4307 | used by the debugger, typically SIGTRAP and SIGINT.\n", |
| 4308 | "Recognized actions include \"s\" (toggles between stop and nostop), \n\ |
| 4309 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ |
| 4310 | nopass), \"Q\" (noprint)\n\ |
| 4311 | Stop means reenter debugger if this signal happens (implies print).\n\ |
| 4312 | Print means print a message if this signal happens.\n\ |
| 4313 | Pass means let program see this signal; otherwise program doesn't know.\n\ |
| 4314 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ |
| 4315 | Pass and Stop may be combined.", NULL)); |
| 4316 | } |
| 4317 | |
| 4318 | if (!dbx_commands) |
| 4319 | stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command, |
| 4320 | "There is no `stop' command, but you can set a hook on `stop'.\n\ |
| 4321 | This allows you to set a list of commands to be run each time execution\n\ |
| 4322 | of the program stops.", &cmdlist); |
| 4323 | |
| 4324 | numsigs = (int) TARGET_SIGNAL_LAST; |
| 4325 | signal_stop = (unsigned char *) |
| 4326 | xmalloc (sizeof (signal_stop[0]) * numsigs); |
| 4327 | signal_print = (unsigned char *) |
| 4328 | xmalloc (sizeof (signal_print[0]) * numsigs); |
| 4329 | signal_program = (unsigned char *) |
| 4330 | xmalloc (sizeof (signal_program[0]) * numsigs); |
| 4331 | for (i = 0; i < numsigs; i++) |
| 4332 | { |
| 4333 | signal_stop[i] = 1; |
| 4334 | signal_print[i] = 1; |
| 4335 | signal_program[i] = 1; |
| 4336 | } |
| 4337 | |
| 4338 | /* Signals caused by debugger's own actions |
| 4339 | should not be given to the program afterwards. */ |
| 4340 | signal_program[TARGET_SIGNAL_TRAP] = 0; |
| 4341 | signal_program[TARGET_SIGNAL_INT] = 0; |
| 4342 | |
| 4343 | /* Signals that are not errors should not normally enter the debugger. */ |
| 4344 | signal_stop[TARGET_SIGNAL_ALRM] = 0; |
| 4345 | signal_print[TARGET_SIGNAL_ALRM] = 0; |
| 4346 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; |
| 4347 | signal_print[TARGET_SIGNAL_VTALRM] = 0; |
| 4348 | signal_stop[TARGET_SIGNAL_PROF] = 0; |
| 4349 | signal_print[TARGET_SIGNAL_PROF] = 0; |
| 4350 | signal_stop[TARGET_SIGNAL_CHLD] = 0; |
| 4351 | signal_print[TARGET_SIGNAL_CHLD] = 0; |
| 4352 | signal_stop[TARGET_SIGNAL_IO] = 0; |
| 4353 | signal_print[TARGET_SIGNAL_IO] = 0; |
| 4354 | signal_stop[TARGET_SIGNAL_POLL] = 0; |
| 4355 | signal_print[TARGET_SIGNAL_POLL] = 0; |
| 4356 | signal_stop[TARGET_SIGNAL_URG] = 0; |
| 4357 | signal_print[TARGET_SIGNAL_URG] = 0; |
| 4358 | signal_stop[TARGET_SIGNAL_WINCH] = 0; |
| 4359 | signal_print[TARGET_SIGNAL_WINCH] = 0; |
| 4360 | |
| 4361 | /* These signals are used internally by user-level thread |
| 4362 | implementations. (See signal(5) on Solaris.) Like the above |
| 4363 | signals, a healthy program receives and handles them as part of |
| 4364 | its normal operation. */ |
| 4365 | signal_stop[TARGET_SIGNAL_LWP] = 0; |
| 4366 | signal_print[TARGET_SIGNAL_LWP] = 0; |
| 4367 | signal_stop[TARGET_SIGNAL_WAITING] = 0; |
| 4368 | signal_print[TARGET_SIGNAL_WAITING] = 0; |
| 4369 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; |
| 4370 | signal_print[TARGET_SIGNAL_CANCEL] = 0; |
| 4371 | |
| 4372 | #ifdef SOLIB_ADD |
| 4373 | add_show_from_set |
| 4374 | (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, |
| 4375 | (char *) &stop_on_solib_events, |
| 4376 | "Set stopping for shared library events.\n\ |
| 4377 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
| 4378 | notifies gdb of shared library events. The most common event of interest\n\ |
| 4379 | to the user would be loading/unloading of a new library.\n", |
| 4380 | &setlist), |
| 4381 | &showlist); |
| 4382 | #endif |
| 4383 | |
| 4384 | c = add_set_enum_cmd ("follow-fork-mode", |
| 4385 | class_run, |
| 4386 | follow_fork_mode_kind_names, |
| 4387 | &follow_fork_mode_string, |
| 4388 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 |
| 4389 | kernel problem. It's also not terribly useful without a GUI to |
| 4390 | help the user drive two debuggers. So for now, I'm disabling |
| 4391 | the "both" option. */ |
| 4392 | /* "Set debugger response to a program call of fork \ |
| 4393 | or vfork.\n\ |
| 4394 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
| 4395 | parent - the original process is debugged after a fork\n\ |
| 4396 | child - the new process is debugged after a fork\n\ |
| 4397 | both - both the parent and child are debugged after a fork\n\ |
| 4398 | ask - the debugger will ask for one of the above choices\n\ |
| 4399 | For \"both\", another copy of the debugger will be started to follow\n\ |
| 4400 | the new child process. The original debugger will continue to follow\n\ |
| 4401 | the original parent process. To distinguish their prompts, the\n\ |
| 4402 | debugger copy's prompt will be changed.\n\ |
| 4403 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ |
| 4404 | By default, the debugger will follow the parent process.", |
| 4405 | */ |
| 4406 | "Set debugger response to a program call of fork \ |
| 4407 | or vfork.\n\ |
| 4408 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
| 4409 | parent - the original process is debugged after a fork\n\ |
| 4410 | child - the new process is debugged after a fork\n\ |
| 4411 | ask - the debugger will ask for one of the above choices\n\ |
| 4412 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ |
| 4413 | By default, the debugger will follow the parent process.", |
| 4414 | &setlist); |
| 4415 | /* c->function.sfunc = ; */ |
| 4416 | add_show_from_set (c, &showlist); |
| 4417 | |
| 4418 | c = add_set_enum_cmd ("scheduler-locking", class_run, |
| 4419 | scheduler_enums, /* array of string names */ |
| 4420 | &scheduler_mode, /* current mode */ |
| 4421 | "Set mode for locking scheduler during execution.\n\ |
| 4422 | off == no locking (threads may preempt at any time)\n\ |
| 4423 | on == full locking (no thread except the current thread may run)\n\ |
| 4424 | step == scheduler locked during every single-step operation.\n\ |
| 4425 | In this mode, no other thread may run during a step command.\n\ |
| 4426 | Other threads may run while stepping over a function call ('next').", |
| 4427 | &setlist); |
| 4428 | |
| 4429 | c->function.sfunc = set_schedlock_func; /* traps on target vector */ |
| 4430 | add_show_from_set (c, &showlist); |
| 4431 | |
| 4432 | c = add_set_cmd ("step-mode", class_run, |
| 4433 | var_boolean, (char*) &step_stop_if_no_debug, |
| 4434 | "Set mode of the step operation. When set, doing a step over a\n\ |
| 4435 | function without debug line information will stop at the first\n\ |
| 4436 | instruction of that function. Otherwise, the function is skipped and\n\ |
| 4437 | the step command stops at a different source line.", |
| 4438 | &setlist); |
| 4439 | add_show_from_set (c, &showlist); |
| 4440 | |
| 4441 | /* ptid initializations */ |
| 4442 | null_ptid = ptid_build (0, 0, 0); |
| 4443 | minus_one_ptid = ptid_build (-1, 0, 0); |
| 4444 | inferior_ptid = null_ptid; |
| 4445 | target_last_wait_ptid = minus_one_ptid; |
| 4446 | } |