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