| 1 | /* Target-struct-independent code to start (run) and stop an inferior |
| 2 | process. |
| 3 | |
| 4 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
| 5 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
| 6 | 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
| 7 | |
| 8 | This file is part of GDB. |
| 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 3 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 22 | |
| 23 | #include "defs.h" |
| 24 | #include "gdb_string.h" |
| 25 | #include <ctype.h> |
| 26 | #include "symtab.h" |
| 27 | #include "frame.h" |
| 28 | #include "inferior.h" |
| 29 | #include "exceptions.h" |
| 30 | #include "breakpoint.h" |
| 31 | #include "gdb_wait.h" |
| 32 | #include "gdbcore.h" |
| 33 | #include "gdbcmd.h" |
| 34 | #include "cli/cli-script.h" |
| 35 | #include "target.h" |
| 36 | #include "gdbthread.h" |
| 37 | #include "annotate.h" |
| 38 | #include "symfile.h" |
| 39 | #include "top.h" |
| 40 | #include <signal.h> |
| 41 | #include "inf-loop.h" |
| 42 | #include "regcache.h" |
| 43 | #include "value.h" |
| 44 | #include "observer.h" |
| 45 | #include "language.h" |
| 46 | #include "solib.h" |
| 47 | #include "main.h" |
| 48 | #include "dictionary.h" |
| 49 | #include "block.h" |
| 50 | #include "gdb_assert.h" |
| 51 | #include "mi/mi-common.h" |
| 52 | #include "event-top.h" |
| 53 | #include "record.h" |
| 54 | #include "inline-frame.h" |
| 55 | #include "jit.h" |
| 56 | #include "tracepoint.h" |
| 57 | |
| 58 | /* Prototypes for local functions */ |
| 59 | |
| 60 | static void signals_info (char *, int); |
| 61 | |
| 62 | static void handle_command (char *, int); |
| 63 | |
| 64 | static void sig_print_info (enum target_signal); |
| 65 | |
| 66 | static void sig_print_header (void); |
| 67 | |
| 68 | static void resume_cleanups (void *); |
| 69 | |
| 70 | static int hook_stop_stub (void *); |
| 71 | |
| 72 | static int restore_selected_frame (void *); |
| 73 | |
| 74 | static int follow_fork (void); |
| 75 | |
| 76 | static void set_schedlock_func (char *args, int from_tty, |
| 77 | struct cmd_list_element *c); |
| 78 | |
| 79 | static int currently_stepping (struct thread_info *tp); |
| 80 | |
| 81 | static int currently_stepping_or_nexting_callback (struct thread_info *tp, |
| 82 | void *data); |
| 83 | |
| 84 | static void xdb_handle_command (char *args, int from_tty); |
| 85 | |
| 86 | static int prepare_to_proceed (int); |
| 87 | |
| 88 | static void print_exited_reason (int exitstatus); |
| 89 | |
| 90 | static void print_signal_exited_reason (enum target_signal siggnal); |
| 91 | |
| 92 | static void print_no_history_reason (void); |
| 93 | |
| 94 | static void print_signal_received_reason (enum target_signal siggnal); |
| 95 | |
| 96 | static void print_end_stepping_range_reason (void); |
| 97 | |
| 98 | void _initialize_infrun (void); |
| 99 | |
| 100 | void nullify_last_target_wait_ptid (void); |
| 101 | |
| 102 | static void insert_step_resume_breakpoint_at_frame (struct frame_info *); |
| 103 | |
| 104 | static void insert_step_resume_breakpoint_at_caller (struct frame_info *); |
| 105 | |
| 106 | static void insert_step_resume_breakpoint_at_sal (struct gdbarch *, |
| 107 | struct symtab_and_line , |
| 108 | struct frame_id); |
| 109 | |
| 110 | static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR); |
| 111 | |
| 112 | /* When set, stop the 'step' command if we enter a function which has |
| 113 | no line number information. The normal behavior is that we step |
| 114 | over such function. */ |
| 115 | int step_stop_if_no_debug = 0; |
| 116 | static void |
| 117 | show_step_stop_if_no_debug (struct ui_file *file, int from_tty, |
| 118 | struct cmd_list_element *c, const char *value) |
| 119 | { |
| 120 | fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value); |
| 121 | } |
| 122 | |
| 123 | /* In asynchronous mode, but simulating synchronous execution. */ |
| 124 | |
| 125 | int sync_execution = 0; |
| 126 | |
| 127 | /* wait_for_inferior and normal_stop use this to notify the user |
| 128 | when the inferior stopped in a different thread than it had been |
| 129 | running in. */ |
| 130 | |
| 131 | static ptid_t previous_inferior_ptid; |
| 132 | |
| 133 | /* Default behavior is to detach newly forked processes (legacy). */ |
| 134 | int detach_fork = 1; |
| 135 | |
| 136 | int debug_displaced = 0; |
| 137 | static void |
| 138 | show_debug_displaced (struct ui_file *file, int from_tty, |
| 139 | struct cmd_list_element *c, const char *value) |
| 140 | { |
| 141 | fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value); |
| 142 | } |
| 143 | |
| 144 | int debug_infrun = 0; |
| 145 | static void |
| 146 | show_debug_infrun (struct ui_file *file, int from_tty, |
| 147 | struct cmd_list_element *c, const char *value) |
| 148 | { |
| 149 | fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); |
| 150 | } |
| 151 | |
| 152 | /* If the program uses ELF-style shared libraries, then calls to |
| 153 | functions in shared libraries go through stubs, which live in a |
| 154 | table called the PLT (Procedure Linkage Table). The first time the |
| 155 | function is called, the stub sends control to the dynamic linker, |
| 156 | which looks up the function's real address, patches the stub so |
| 157 | that future calls will go directly to the function, and then passes |
| 158 | control to the function. |
| 159 | |
| 160 | If we are stepping at the source level, we don't want to see any of |
| 161 | this --- we just want to skip over the stub and the dynamic linker. |
| 162 | The simple approach is to single-step until control leaves the |
| 163 | dynamic linker. |
| 164 | |
| 165 | However, on some systems (e.g., Red Hat's 5.2 distribution) the |
| 166 | dynamic linker calls functions in the shared C library, so you |
| 167 | can't tell from the PC alone whether the dynamic linker is still |
| 168 | running. In this case, we use a step-resume breakpoint to get us |
| 169 | past the dynamic linker, as if we were using "next" to step over a |
| 170 | function call. |
| 171 | |
| 172 | in_solib_dynsym_resolve_code() says whether we're in the dynamic |
| 173 | linker code or not. Normally, this means we single-step. However, |
| 174 | if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an |
| 175 | address where we can place a step-resume breakpoint to get past the |
| 176 | linker's symbol resolution function. |
| 177 | |
| 178 | in_solib_dynsym_resolve_code() can generally be implemented in a |
| 179 | pretty portable way, by comparing the PC against the address ranges |
| 180 | of the dynamic linker's sections. |
| 181 | |
| 182 | SKIP_SOLIB_RESOLVER is generally going to be system-specific, since |
| 183 | it depends on internal details of the dynamic linker. It's usually |
| 184 | not too hard to figure out where to put a breakpoint, but it |
| 185 | certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of |
| 186 | sanity checking. If it can't figure things out, returning zero and |
| 187 | getting the (possibly confusing) stepping behavior is better than |
| 188 | signalling an error, which will obscure the change in the |
| 189 | inferior's state. */ |
| 190 | |
| 191 | /* This function returns TRUE if pc is the address of an instruction |
| 192 | that lies within the dynamic linker (such as the event hook, or the |
| 193 | dld itself). |
| 194 | |
| 195 | This function must be used only when a dynamic linker event has |
| 196 | been caught, and the inferior is being stepped out of the hook, or |
| 197 | undefined results are guaranteed. */ |
| 198 | |
| 199 | #ifndef SOLIB_IN_DYNAMIC_LINKER |
| 200 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 |
| 201 | #endif |
| 202 | |
| 203 | /* "Observer mode" is somewhat like a more extreme version of |
| 204 | non-stop, in which all GDB operations that might affect the |
| 205 | target's execution have been disabled. */ |
| 206 | |
| 207 | static int non_stop_1 = 0; |
| 208 | |
| 209 | int observer_mode = 0; |
| 210 | static int observer_mode_1 = 0; |
| 211 | |
| 212 | static void |
| 213 | set_observer_mode (char *args, int from_tty, |
| 214 | struct cmd_list_element *c) |
| 215 | { |
| 216 | extern int pagination_enabled; |
| 217 | |
| 218 | if (target_has_execution) |
| 219 | { |
| 220 | observer_mode_1 = observer_mode; |
| 221 | error (_("Cannot change this setting while the inferior is running.")); |
| 222 | } |
| 223 | |
| 224 | observer_mode = observer_mode_1; |
| 225 | |
| 226 | may_write_registers = !observer_mode; |
| 227 | may_write_memory = !observer_mode; |
| 228 | may_insert_breakpoints = !observer_mode; |
| 229 | may_insert_tracepoints = !observer_mode; |
| 230 | /* We can insert fast tracepoints in or out of observer mode, |
| 231 | but enable them if we're going into this mode. */ |
| 232 | if (observer_mode) |
| 233 | may_insert_fast_tracepoints = 1; |
| 234 | may_stop = !observer_mode; |
| 235 | update_target_permissions (); |
| 236 | |
| 237 | /* Going *into* observer mode we must force non-stop, then |
| 238 | going out we leave it that way. */ |
| 239 | if (observer_mode) |
| 240 | { |
| 241 | target_async_permitted = 1; |
| 242 | pagination_enabled = 0; |
| 243 | non_stop = non_stop_1 = 1; |
| 244 | } |
| 245 | |
| 246 | if (from_tty) |
| 247 | printf_filtered (_("Observer mode is now %s.\n"), |
| 248 | (observer_mode ? "on" : "off")); |
| 249 | } |
| 250 | |
| 251 | static void |
| 252 | show_observer_mode (struct ui_file *file, int from_tty, |
| 253 | struct cmd_list_element *c, const char *value) |
| 254 | { |
| 255 | fprintf_filtered (file, _("Observer mode is %s.\n"), value); |
| 256 | } |
| 257 | |
| 258 | /* This updates the value of observer mode based on changes in |
| 259 | permissions. Note that we are deliberately ignoring the values of |
| 260 | may-write-registers and may-write-memory, since the user may have |
| 261 | reason to enable these during a session, for instance to turn on a |
| 262 | debugging-related global. */ |
| 263 | |
| 264 | void |
| 265 | update_observer_mode (void) |
| 266 | { |
| 267 | int newval; |
| 268 | |
| 269 | newval = (!may_insert_breakpoints |
| 270 | && !may_insert_tracepoints |
| 271 | && may_insert_fast_tracepoints |
| 272 | && !may_stop |
| 273 | && non_stop); |
| 274 | |
| 275 | /* Let the user know if things change. */ |
| 276 | if (newval != observer_mode) |
| 277 | printf_filtered (_("Observer mode is now %s.\n"), |
| 278 | (newval ? "on" : "off")); |
| 279 | |
| 280 | observer_mode = observer_mode_1 = newval; |
| 281 | } |
| 282 | |
| 283 | /* Tables of how to react to signals; the user sets them. */ |
| 284 | |
| 285 | static unsigned char *signal_stop; |
| 286 | static unsigned char *signal_print; |
| 287 | static unsigned char *signal_program; |
| 288 | |
| 289 | /* Table of signals that the target may silently handle. |
| 290 | This is automatically determined from the flags above, |
| 291 | and simply cached here. */ |
| 292 | static unsigned char *signal_pass; |
| 293 | |
| 294 | #define SET_SIGS(nsigs,sigs,flags) \ |
| 295 | do { \ |
| 296 | int signum = (nsigs); \ |
| 297 | while (signum-- > 0) \ |
| 298 | if ((sigs)[signum]) \ |
| 299 | (flags)[signum] = 1; \ |
| 300 | } while (0) |
| 301 | |
| 302 | #define UNSET_SIGS(nsigs,sigs,flags) \ |
| 303 | do { \ |
| 304 | int signum = (nsigs); \ |
| 305 | while (signum-- > 0) \ |
| 306 | if ((sigs)[signum]) \ |
| 307 | (flags)[signum] = 0; \ |
| 308 | } while (0) |
| 309 | |
| 310 | /* Value to pass to target_resume() to cause all threads to resume. */ |
| 311 | |
| 312 | #define RESUME_ALL minus_one_ptid |
| 313 | |
| 314 | /* Command list pointer for the "stop" placeholder. */ |
| 315 | |
| 316 | static struct cmd_list_element *stop_command; |
| 317 | |
| 318 | /* Function inferior was in as of last step command. */ |
| 319 | |
| 320 | static struct symbol *step_start_function; |
| 321 | |
| 322 | /* Nonzero if we want to give control to the user when we're notified |
| 323 | of shared library events by the dynamic linker. */ |
| 324 | int stop_on_solib_events; |
| 325 | static void |
| 326 | show_stop_on_solib_events (struct ui_file *file, int from_tty, |
| 327 | struct cmd_list_element *c, const char *value) |
| 328 | { |
| 329 | fprintf_filtered (file, _("Stopping for shared library events is %s.\n"), |
| 330 | value); |
| 331 | } |
| 332 | |
| 333 | /* Nonzero means expecting a trace trap |
| 334 | and should stop the inferior and return silently when it happens. */ |
| 335 | |
| 336 | int stop_after_trap; |
| 337 | |
| 338 | /* Save register contents here when executing a "finish" command or are |
| 339 | about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set. |
| 340 | Thus this contains the return value from the called function (assuming |
| 341 | values are returned in a register). */ |
| 342 | |
| 343 | struct regcache *stop_registers; |
| 344 | |
| 345 | /* Nonzero after stop if current stack frame should be printed. */ |
| 346 | |
| 347 | static int stop_print_frame; |
| 348 | |
| 349 | /* This is a cached copy of the pid/waitstatus of the last event |
| 350 | returned by target_wait()/deprecated_target_wait_hook(). This |
| 351 | information is returned by get_last_target_status(). */ |
| 352 | static ptid_t target_last_wait_ptid; |
| 353 | static struct target_waitstatus target_last_waitstatus; |
| 354 | |
| 355 | static void context_switch (ptid_t ptid); |
| 356 | |
| 357 | void init_thread_stepping_state (struct thread_info *tss); |
| 358 | |
| 359 | void init_infwait_state (void); |
| 360 | |
| 361 | static const char follow_fork_mode_child[] = "child"; |
| 362 | static const char follow_fork_mode_parent[] = "parent"; |
| 363 | |
| 364 | static const char *follow_fork_mode_kind_names[] = { |
| 365 | follow_fork_mode_child, |
| 366 | follow_fork_mode_parent, |
| 367 | NULL |
| 368 | }; |
| 369 | |
| 370 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
| 371 | static void |
| 372 | show_follow_fork_mode_string (struct ui_file *file, int from_tty, |
| 373 | struct cmd_list_element *c, const char *value) |
| 374 | { |
| 375 | fprintf_filtered (file, |
| 376 | _("Debugger response to a program " |
| 377 | "call of fork or vfork is \"%s\".\n"), |
| 378 | value); |
| 379 | } |
| 380 | \f |
| 381 | |
| 382 | /* Tell the target to follow the fork we're stopped at. Returns true |
| 383 | if the inferior should be resumed; false, if the target for some |
| 384 | reason decided it's best not to resume. */ |
| 385 | |
| 386 | static int |
| 387 | follow_fork (void) |
| 388 | { |
| 389 | int follow_child = (follow_fork_mode_string == follow_fork_mode_child); |
| 390 | int should_resume = 1; |
| 391 | struct thread_info *tp; |
| 392 | |
| 393 | /* Copy user stepping state to the new inferior thread. FIXME: the |
| 394 | followed fork child thread should have a copy of most of the |
| 395 | parent thread structure's run control related fields, not just these. |
| 396 | Initialized to avoid "may be used uninitialized" warnings from gcc. */ |
| 397 | struct breakpoint *step_resume_breakpoint = NULL; |
| 398 | struct breakpoint *exception_resume_breakpoint = NULL; |
| 399 | CORE_ADDR step_range_start = 0; |
| 400 | CORE_ADDR step_range_end = 0; |
| 401 | struct frame_id step_frame_id = { 0 }; |
| 402 | |
| 403 | if (!non_stop) |
| 404 | { |
| 405 | ptid_t wait_ptid; |
| 406 | struct target_waitstatus wait_status; |
| 407 | |
| 408 | /* Get the last target status returned by target_wait(). */ |
| 409 | get_last_target_status (&wait_ptid, &wait_status); |
| 410 | |
| 411 | /* If not stopped at a fork event, then there's nothing else to |
| 412 | do. */ |
| 413 | if (wait_status.kind != TARGET_WAITKIND_FORKED |
| 414 | && wait_status.kind != TARGET_WAITKIND_VFORKED) |
| 415 | return 1; |
| 416 | |
| 417 | /* Check if we switched over from WAIT_PTID, since the event was |
| 418 | reported. */ |
| 419 | if (!ptid_equal (wait_ptid, minus_one_ptid) |
| 420 | && !ptid_equal (inferior_ptid, wait_ptid)) |
| 421 | { |
| 422 | /* We did. Switch back to WAIT_PTID thread, to tell the |
| 423 | target to follow it (in either direction). We'll |
| 424 | afterwards refuse to resume, and inform the user what |
| 425 | happened. */ |
| 426 | switch_to_thread (wait_ptid); |
| 427 | should_resume = 0; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | tp = inferior_thread (); |
| 432 | |
| 433 | /* If there were any forks/vforks that were caught and are now to be |
| 434 | followed, then do so now. */ |
| 435 | switch (tp->pending_follow.kind) |
| 436 | { |
| 437 | case TARGET_WAITKIND_FORKED: |
| 438 | case TARGET_WAITKIND_VFORKED: |
| 439 | { |
| 440 | ptid_t parent, child; |
| 441 | |
| 442 | /* If the user did a next/step, etc, over a fork call, |
| 443 | preserve the stepping state in the fork child. */ |
| 444 | if (follow_child && should_resume) |
| 445 | { |
| 446 | step_resume_breakpoint = clone_momentary_breakpoint |
| 447 | (tp->control.step_resume_breakpoint); |
| 448 | step_range_start = tp->control.step_range_start; |
| 449 | step_range_end = tp->control.step_range_end; |
| 450 | step_frame_id = tp->control.step_frame_id; |
| 451 | exception_resume_breakpoint |
| 452 | = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint); |
| 453 | |
| 454 | /* For now, delete the parent's sr breakpoint, otherwise, |
| 455 | parent/child sr breakpoints are considered duplicates, |
| 456 | and the child version will not be installed. Remove |
| 457 | this when the breakpoints module becomes aware of |
| 458 | inferiors and address spaces. */ |
| 459 | delete_step_resume_breakpoint (tp); |
| 460 | tp->control.step_range_start = 0; |
| 461 | tp->control.step_range_end = 0; |
| 462 | tp->control.step_frame_id = null_frame_id; |
| 463 | delete_exception_resume_breakpoint (tp); |
| 464 | } |
| 465 | |
| 466 | parent = inferior_ptid; |
| 467 | child = tp->pending_follow.value.related_pid; |
| 468 | |
| 469 | /* Tell the target to do whatever is necessary to follow |
| 470 | either parent or child. */ |
| 471 | if (target_follow_fork (follow_child)) |
| 472 | { |
| 473 | /* Target refused to follow, or there's some other reason |
| 474 | we shouldn't resume. */ |
| 475 | should_resume = 0; |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | /* This pending follow fork event is now handled, one way |
| 480 | or another. The previous selected thread may be gone |
| 481 | from the lists by now, but if it is still around, need |
| 482 | to clear the pending follow request. */ |
| 483 | tp = find_thread_ptid (parent); |
| 484 | if (tp) |
| 485 | tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
| 486 | |
| 487 | /* This makes sure we don't try to apply the "Switched |
| 488 | over from WAIT_PID" logic above. */ |
| 489 | nullify_last_target_wait_ptid (); |
| 490 | |
| 491 | /* If we followed the child, switch to it... */ |
| 492 | if (follow_child) |
| 493 | { |
| 494 | switch_to_thread (child); |
| 495 | |
| 496 | /* ... and preserve the stepping state, in case the |
| 497 | user was stepping over the fork call. */ |
| 498 | if (should_resume) |
| 499 | { |
| 500 | tp = inferior_thread (); |
| 501 | tp->control.step_resume_breakpoint |
| 502 | = step_resume_breakpoint; |
| 503 | tp->control.step_range_start = step_range_start; |
| 504 | tp->control.step_range_end = step_range_end; |
| 505 | tp->control.step_frame_id = step_frame_id; |
| 506 | tp->control.exception_resume_breakpoint |
| 507 | = exception_resume_breakpoint; |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | /* If we get here, it was because we're trying to |
| 512 | resume from a fork catchpoint, but, the user |
| 513 | has switched threads away from the thread that |
| 514 | forked. In that case, the resume command |
| 515 | issued is most likely not applicable to the |
| 516 | child, so just warn, and refuse to resume. */ |
| 517 | warning (_("Not resuming: switched threads " |
| 518 | "before following fork child.\n")); |
| 519 | } |
| 520 | |
| 521 | /* Reset breakpoints in the child as appropriate. */ |
| 522 | follow_inferior_reset_breakpoints (); |
| 523 | } |
| 524 | else |
| 525 | switch_to_thread (parent); |
| 526 | } |
| 527 | } |
| 528 | break; |
| 529 | case TARGET_WAITKIND_SPURIOUS: |
| 530 | /* Nothing to follow. */ |
| 531 | break; |
| 532 | default: |
| 533 | internal_error (__FILE__, __LINE__, |
| 534 | "Unexpected pending_follow.kind %d\n", |
| 535 | tp->pending_follow.kind); |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | return should_resume; |
| 540 | } |
| 541 | |
| 542 | void |
| 543 | follow_inferior_reset_breakpoints (void) |
| 544 | { |
| 545 | struct thread_info *tp = inferior_thread (); |
| 546 | |
| 547 | /* Was there a step_resume breakpoint? (There was if the user |
| 548 | did a "next" at the fork() call.) If so, explicitly reset its |
| 549 | thread number. |
| 550 | |
| 551 | step_resumes are a form of bp that are made to be per-thread. |
| 552 | Since we created the step_resume bp when the parent process |
| 553 | was being debugged, and now are switching to the child process, |
| 554 | from the breakpoint package's viewpoint, that's a switch of |
| 555 | "threads". We must update the bp's notion of which thread |
| 556 | it is for, or it'll be ignored when it triggers. */ |
| 557 | |
| 558 | if (tp->control.step_resume_breakpoint) |
| 559 | breakpoint_re_set_thread (tp->control.step_resume_breakpoint); |
| 560 | |
| 561 | if (tp->control.exception_resume_breakpoint) |
| 562 | breakpoint_re_set_thread (tp->control.exception_resume_breakpoint); |
| 563 | |
| 564 | /* Reinsert all breakpoints in the child. The user may have set |
| 565 | breakpoints after catching the fork, in which case those |
| 566 | were never set in the child, but only in the parent. This makes |
| 567 | sure the inserted breakpoints match the breakpoint list. */ |
| 568 | |
| 569 | breakpoint_re_set (); |
| 570 | insert_breakpoints (); |
| 571 | } |
| 572 | |
| 573 | /* The child has exited or execed: resume threads of the parent the |
| 574 | user wanted to be executing. */ |
| 575 | |
| 576 | static int |
| 577 | proceed_after_vfork_done (struct thread_info *thread, |
| 578 | void *arg) |
| 579 | { |
| 580 | int pid = * (int *) arg; |
| 581 | |
| 582 | if (ptid_get_pid (thread->ptid) == pid |
| 583 | && is_running (thread->ptid) |
| 584 | && !is_executing (thread->ptid) |
| 585 | && !thread->stop_requested |
| 586 | && thread->suspend.stop_signal == TARGET_SIGNAL_0) |
| 587 | { |
| 588 | if (debug_infrun) |
| 589 | fprintf_unfiltered (gdb_stdlog, |
| 590 | "infrun: resuming vfork parent thread %s\n", |
| 591 | target_pid_to_str (thread->ptid)); |
| 592 | |
| 593 | switch_to_thread (thread->ptid); |
| 594 | clear_proceed_status (); |
| 595 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); |
| 596 | } |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | /* Called whenever we notice an exec or exit event, to handle |
| 602 | detaching or resuming a vfork parent. */ |
| 603 | |
| 604 | static void |
| 605 | handle_vfork_child_exec_or_exit (int exec) |
| 606 | { |
| 607 | struct inferior *inf = current_inferior (); |
| 608 | |
| 609 | if (inf->vfork_parent) |
| 610 | { |
| 611 | int resume_parent = -1; |
| 612 | |
| 613 | /* This exec or exit marks the end of the shared memory region |
| 614 | between the parent and the child. If the user wanted to |
| 615 | detach from the parent, now is the time. */ |
| 616 | |
| 617 | if (inf->vfork_parent->pending_detach) |
| 618 | { |
| 619 | struct thread_info *tp; |
| 620 | struct cleanup *old_chain; |
| 621 | struct program_space *pspace; |
| 622 | struct address_space *aspace; |
| 623 | |
| 624 | /* follow-fork child, detach-on-fork on. */ |
| 625 | |
| 626 | old_chain = make_cleanup_restore_current_thread (); |
| 627 | |
| 628 | /* We're letting loose of the parent. */ |
| 629 | tp = any_live_thread_of_process (inf->vfork_parent->pid); |
| 630 | switch_to_thread (tp->ptid); |
| 631 | |
| 632 | /* We're about to detach from the parent, which implicitly |
| 633 | removes breakpoints from its address space. There's a |
| 634 | catch here: we want to reuse the spaces for the child, |
| 635 | but, parent/child are still sharing the pspace at this |
| 636 | point, although the exec in reality makes the kernel give |
| 637 | the child a fresh set of new pages. The problem here is |
| 638 | that the breakpoints module being unaware of this, would |
| 639 | likely chose the child process to write to the parent |
| 640 | address space. Swapping the child temporarily away from |
| 641 | the spaces has the desired effect. Yes, this is "sort |
| 642 | of" a hack. */ |
| 643 | |
| 644 | pspace = inf->pspace; |
| 645 | aspace = inf->aspace; |
| 646 | inf->aspace = NULL; |
| 647 | inf->pspace = NULL; |
| 648 | |
| 649 | if (debug_infrun || info_verbose) |
| 650 | { |
| 651 | target_terminal_ours (); |
| 652 | |
| 653 | if (exec) |
| 654 | fprintf_filtered (gdb_stdlog, |
| 655 | "Detaching vfork parent process " |
| 656 | "%d after child exec.\n", |
| 657 | inf->vfork_parent->pid); |
| 658 | else |
| 659 | fprintf_filtered (gdb_stdlog, |
| 660 | "Detaching vfork parent process " |
| 661 | "%d after child exit.\n", |
| 662 | inf->vfork_parent->pid); |
| 663 | } |
| 664 | |
| 665 | target_detach (NULL, 0); |
| 666 | |
| 667 | /* Put it back. */ |
| 668 | inf->pspace = pspace; |
| 669 | inf->aspace = aspace; |
| 670 | |
| 671 | do_cleanups (old_chain); |
| 672 | } |
| 673 | else if (exec) |
| 674 | { |
| 675 | /* We're staying attached to the parent, so, really give the |
| 676 | child a new address space. */ |
| 677 | inf->pspace = add_program_space (maybe_new_address_space ()); |
| 678 | inf->aspace = inf->pspace->aspace; |
| 679 | inf->removable = 1; |
| 680 | set_current_program_space (inf->pspace); |
| 681 | |
| 682 | resume_parent = inf->vfork_parent->pid; |
| 683 | |
| 684 | /* Break the bonds. */ |
| 685 | inf->vfork_parent->vfork_child = NULL; |
| 686 | } |
| 687 | else |
| 688 | { |
| 689 | struct cleanup *old_chain; |
| 690 | struct program_space *pspace; |
| 691 | |
| 692 | /* If this is a vfork child exiting, then the pspace and |
| 693 | aspaces were shared with the parent. Since we're |
| 694 | reporting the process exit, we'll be mourning all that is |
| 695 | found in the address space, and switching to null_ptid, |
| 696 | preparing to start a new inferior. But, since we don't |
| 697 | want to clobber the parent's address/program spaces, we |
| 698 | go ahead and create a new one for this exiting |
| 699 | inferior. */ |
| 700 | |
| 701 | /* Switch to null_ptid, so that clone_program_space doesn't want |
| 702 | to read the selected frame of a dead process. */ |
| 703 | old_chain = save_inferior_ptid (); |
| 704 | inferior_ptid = null_ptid; |
| 705 | |
| 706 | /* This inferior is dead, so avoid giving the breakpoints |
| 707 | module the option to write through to it (cloning a |
| 708 | program space resets breakpoints). */ |
| 709 | inf->aspace = NULL; |
| 710 | inf->pspace = NULL; |
| 711 | pspace = add_program_space (maybe_new_address_space ()); |
| 712 | set_current_program_space (pspace); |
| 713 | inf->removable = 1; |
| 714 | clone_program_space (pspace, inf->vfork_parent->pspace); |
| 715 | inf->pspace = pspace; |
| 716 | inf->aspace = pspace->aspace; |
| 717 | |
| 718 | /* Put back inferior_ptid. We'll continue mourning this |
| 719 | inferior. */ |
| 720 | do_cleanups (old_chain); |
| 721 | |
| 722 | resume_parent = inf->vfork_parent->pid; |
| 723 | /* Break the bonds. */ |
| 724 | inf->vfork_parent->vfork_child = NULL; |
| 725 | } |
| 726 | |
| 727 | inf->vfork_parent = NULL; |
| 728 | |
| 729 | gdb_assert (current_program_space == inf->pspace); |
| 730 | |
| 731 | if (non_stop && resume_parent != -1) |
| 732 | { |
| 733 | /* If the user wanted the parent to be running, let it go |
| 734 | free now. */ |
| 735 | struct cleanup *old_chain = make_cleanup_restore_current_thread (); |
| 736 | |
| 737 | if (debug_infrun) |
| 738 | fprintf_unfiltered (gdb_stdlog, |
| 739 | "infrun: resuming vfork parent process %d\n", |
| 740 | resume_parent); |
| 741 | |
| 742 | iterate_over_threads (proceed_after_vfork_done, &resume_parent); |
| 743 | |
| 744 | do_cleanups (old_chain); |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | /* Enum strings for "set|show displaced-stepping". */ |
| 750 | |
| 751 | static const char follow_exec_mode_new[] = "new"; |
| 752 | static const char follow_exec_mode_same[] = "same"; |
| 753 | static const char *follow_exec_mode_names[] = |
| 754 | { |
| 755 | follow_exec_mode_new, |
| 756 | follow_exec_mode_same, |
| 757 | NULL, |
| 758 | }; |
| 759 | |
| 760 | static const char *follow_exec_mode_string = follow_exec_mode_same; |
| 761 | static void |
| 762 | show_follow_exec_mode_string (struct ui_file *file, int from_tty, |
| 763 | struct cmd_list_element *c, const char *value) |
| 764 | { |
| 765 | fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value); |
| 766 | } |
| 767 | |
| 768 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
| 769 | |
| 770 | static void |
| 771 | follow_exec (ptid_t pid, char *execd_pathname) |
| 772 | { |
| 773 | struct thread_info *th = inferior_thread (); |
| 774 | struct inferior *inf = current_inferior (); |
| 775 | |
| 776 | /* This is an exec event that we actually wish to pay attention to. |
| 777 | Refresh our symbol table to the newly exec'd program, remove any |
| 778 | momentary bp's, etc. |
| 779 | |
| 780 | If there are breakpoints, they aren't really inserted now, |
| 781 | since the exec() transformed our inferior into a fresh set |
| 782 | of instructions. |
| 783 | |
| 784 | We want to preserve symbolic breakpoints on the list, since |
| 785 | we have hopes that they can be reset after the new a.out's |
| 786 | symbol table is read. |
| 787 | |
| 788 | However, any "raw" breakpoints must be removed from the list |
| 789 | (e.g., the solib bp's), since their address is probably invalid |
| 790 | now. |
| 791 | |
| 792 | And, we DON'T want to call delete_breakpoints() here, since |
| 793 | that may write the bp's "shadow contents" (the instruction |
| 794 | value that was overwritten witha TRAP instruction). Since |
| 795 | we now have a new a.out, those shadow contents aren't valid. */ |
| 796 | |
| 797 | mark_breakpoints_out (); |
| 798 | |
| 799 | update_breakpoints_after_exec (); |
| 800 | |
| 801 | /* If there was one, it's gone now. We cannot truly step-to-next |
| 802 | statement through an exec(). */ |
| 803 | th->control.step_resume_breakpoint = NULL; |
| 804 | th->control.exception_resume_breakpoint = NULL; |
| 805 | th->control.step_range_start = 0; |
| 806 | th->control.step_range_end = 0; |
| 807 | |
| 808 | /* The target reports the exec event to the main thread, even if |
| 809 | some other thread does the exec, and even if the main thread was |
| 810 | already stopped --- if debugging in non-stop mode, it's possible |
| 811 | the user had the main thread held stopped in the previous image |
| 812 | --- release it now. This is the same behavior as step-over-exec |
| 813 | with scheduler-locking on in all-stop mode. */ |
| 814 | th->stop_requested = 0; |
| 815 | |
| 816 | /* What is this a.out's name? */ |
| 817 | printf_unfiltered (_("%s is executing new program: %s\n"), |
| 818 | target_pid_to_str (inferior_ptid), |
| 819 | execd_pathname); |
| 820 | |
| 821 | /* We've followed the inferior through an exec. Therefore, the |
| 822 | inferior has essentially been killed & reborn. */ |
| 823 | |
| 824 | gdb_flush (gdb_stdout); |
| 825 | |
| 826 | breakpoint_init_inferior (inf_execd); |
| 827 | |
| 828 | if (gdb_sysroot && *gdb_sysroot) |
| 829 | { |
| 830 | char *name = alloca (strlen (gdb_sysroot) |
| 831 | + strlen (execd_pathname) |
| 832 | + 1); |
| 833 | |
| 834 | strcpy (name, gdb_sysroot); |
| 835 | strcat (name, execd_pathname); |
| 836 | execd_pathname = name; |
| 837 | } |
| 838 | |
| 839 | /* Reset the shared library package. This ensures that we get a |
| 840 | shlib event when the child reaches "_start", at which point the |
| 841 | dld will have had a chance to initialize the child. */ |
| 842 | /* Also, loading a symbol file below may trigger symbol lookups, and |
| 843 | we don't want those to be satisfied by the libraries of the |
| 844 | previous incarnation of this process. */ |
| 845 | no_shared_libraries (NULL, 0); |
| 846 | |
| 847 | if (follow_exec_mode_string == follow_exec_mode_new) |
| 848 | { |
| 849 | struct program_space *pspace; |
| 850 | |
| 851 | /* The user wants to keep the old inferior and program spaces |
| 852 | around. Create a new fresh one, and switch to it. */ |
| 853 | |
| 854 | inf = add_inferior (current_inferior ()->pid); |
| 855 | pspace = add_program_space (maybe_new_address_space ()); |
| 856 | inf->pspace = pspace; |
| 857 | inf->aspace = pspace->aspace; |
| 858 | |
| 859 | exit_inferior_num_silent (current_inferior ()->num); |
| 860 | |
| 861 | set_current_inferior (inf); |
| 862 | set_current_program_space (pspace); |
| 863 | } |
| 864 | |
| 865 | gdb_assert (current_program_space == inf->pspace); |
| 866 | |
| 867 | /* That a.out is now the one to use. */ |
| 868 | exec_file_attach (execd_pathname, 0); |
| 869 | |
| 870 | /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE |
| 871 | (Position Independent Executable) main symbol file will get applied by |
| 872 | solib_create_inferior_hook below. breakpoint_re_set would fail to insert |
| 873 | the breakpoints with the zero displacement. */ |
| 874 | |
| 875 | symbol_file_add (execd_pathname, SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET, |
| 876 | NULL, 0); |
| 877 | |
| 878 | set_initial_language (); |
| 879 | |
| 880 | #ifdef SOLIB_CREATE_INFERIOR_HOOK |
| 881 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
| 882 | #else |
| 883 | solib_create_inferior_hook (0); |
| 884 | #endif |
| 885 | |
| 886 | jit_inferior_created_hook (); |
| 887 | |
| 888 | breakpoint_re_set (); |
| 889 | |
| 890 | /* Reinsert all breakpoints. (Those which were symbolic have |
| 891 | been reset to the proper address in the new a.out, thanks |
| 892 | to symbol_file_command...). */ |
| 893 | insert_breakpoints (); |
| 894 | |
| 895 | /* The next resume of this inferior should bring it to the shlib |
| 896 | startup breakpoints. (If the user had also set bp's on |
| 897 | "main" from the old (parent) process, then they'll auto- |
| 898 | matically get reset there in the new process.). */ |
| 899 | } |
| 900 | |
| 901 | /* Non-zero if we just simulating a single-step. This is needed |
| 902 | because we cannot remove the breakpoints in the inferior process |
| 903 | until after the `wait' in `wait_for_inferior'. */ |
| 904 | static int singlestep_breakpoints_inserted_p = 0; |
| 905 | |
| 906 | /* The thread we inserted single-step breakpoints for. */ |
| 907 | static ptid_t singlestep_ptid; |
| 908 | |
| 909 | /* PC when we started this single-step. */ |
| 910 | static CORE_ADDR singlestep_pc; |
| 911 | |
| 912 | /* If another thread hit the singlestep breakpoint, we save the original |
| 913 | thread here so that we can resume single-stepping it later. */ |
| 914 | static ptid_t saved_singlestep_ptid; |
| 915 | static int stepping_past_singlestep_breakpoint; |
| 916 | |
| 917 | /* If not equal to null_ptid, this means that after stepping over breakpoint |
| 918 | is finished, we need to switch to deferred_step_ptid, and step it. |
| 919 | |
| 920 | The use case is when one thread has hit a breakpoint, and then the user |
| 921 | has switched to another thread and issued 'step'. We need to step over |
| 922 | breakpoint in the thread which hit the breakpoint, but then continue |
| 923 | stepping the thread user has selected. */ |
| 924 | static ptid_t deferred_step_ptid; |
| 925 | \f |
| 926 | /* Displaced stepping. */ |
| 927 | |
| 928 | /* In non-stop debugging mode, we must take special care to manage |
| 929 | breakpoints properly; in particular, the traditional strategy for |
| 930 | stepping a thread past a breakpoint it has hit is unsuitable. |
| 931 | 'Displaced stepping' is a tactic for stepping one thread past a |
| 932 | breakpoint it has hit while ensuring that other threads running |
| 933 | concurrently will hit the breakpoint as they should. |
| 934 | |
| 935 | The traditional way to step a thread T off a breakpoint in a |
| 936 | multi-threaded program in all-stop mode is as follows: |
| 937 | |
| 938 | a0) Initially, all threads are stopped, and breakpoints are not |
| 939 | inserted. |
| 940 | a1) We single-step T, leaving breakpoints uninserted. |
| 941 | a2) We insert breakpoints, and resume all threads. |
| 942 | |
| 943 | In non-stop debugging, however, this strategy is unsuitable: we |
| 944 | don't want to have to stop all threads in the system in order to |
| 945 | continue or step T past a breakpoint. Instead, we use displaced |
| 946 | stepping: |
| 947 | |
| 948 | n0) Initially, T is stopped, other threads are running, and |
| 949 | breakpoints are inserted. |
| 950 | n1) We copy the instruction "under" the breakpoint to a separate |
| 951 | location, outside the main code stream, making any adjustments |
| 952 | to the instruction, register, and memory state as directed by |
| 953 | T's architecture. |
| 954 | n2) We single-step T over the instruction at its new location. |
| 955 | n3) We adjust the resulting register and memory state as directed |
| 956 | by T's architecture. This includes resetting T's PC to point |
| 957 | back into the main instruction stream. |
| 958 | n4) We resume T. |
| 959 | |
| 960 | This approach depends on the following gdbarch methods: |
| 961 | |
| 962 | - gdbarch_max_insn_length and gdbarch_displaced_step_location |
| 963 | indicate where to copy the instruction, and how much space must |
| 964 | be reserved there. We use these in step n1. |
| 965 | |
| 966 | - gdbarch_displaced_step_copy_insn copies a instruction to a new |
| 967 | address, and makes any necessary adjustments to the instruction, |
| 968 | register contents, and memory. We use this in step n1. |
| 969 | |
| 970 | - gdbarch_displaced_step_fixup adjusts registers and memory after |
| 971 | we have successfuly single-stepped the instruction, to yield the |
| 972 | same effect the instruction would have had if we had executed it |
| 973 | at its original address. We use this in step n3. |
| 974 | |
| 975 | - gdbarch_displaced_step_free_closure provides cleanup. |
| 976 | |
| 977 | The gdbarch_displaced_step_copy_insn and |
| 978 | gdbarch_displaced_step_fixup functions must be written so that |
| 979 | copying an instruction with gdbarch_displaced_step_copy_insn, |
| 980 | single-stepping across the copied instruction, and then applying |
| 981 | gdbarch_displaced_insn_fixup should have the same effects on the |
| 982 | thread's memory and registers as stepping the instruction in place |
| 983 | would have. Exactly which responsibilities fall to the copy and |
| 984 | which fall to the fixup is up to the author of those functions. |
| 985 | |
| 986 | See the comments in gdbarch.sh for details. |
| 987 | |
| 988 | Note that displaced stepping and software single-step cannot |
| 989 | currently be used in combination, although with some care I think |
| 990 | they could be made to. Software single-step works by placing |
| 991 | breakpoints on all possible subsequent instructions; if the |
| 992 | displaced instruction is a PC-relative jump, those breakpoints |
| 993 | could fall in very strange places --- on pages that aren't |
| 994 | executable, or at addresses that are not proper instruction |
| 995 | boundaries. (We do generally let other threads run while we wait |
| 996 | to hit the software single-step breakpoint, and they might |
| 997 | encounter such a corrupted instruction.) One way to work around |
| 998 | this would be to have gdbarch_displaced_step_copy_insn fully |
| 999 | simulate the effect of PC-relative instructions (and return NULL) |
| 1000 | on architectures that use software single-stepping. |
| 1001 | |
| 1002 | In non-stop mode, we can have independent and simultaneous step |
| 1003 | requests, so more than one thread may need to simultaneously step |
| 1004 | over a breakpoint. The current implementation assumes there is |
| 1005 | only one scratch space per process. In this case, we have to |
| 1006 | serialize access to the scratch space. If thread A wants to step |
| 1007 | over a breakpoint, but we are currently waiting for some other |
| 1008 | thread to complete a displaced step, we leave thread A stopped and |
| 1009 | place it in the displaced_step_request_queue. Whenever a displaced |
| 1010 | step finishes, we pick the next thread in the queue and start a new |
| 1011 | displaced step operation on it. See displaced_step_prepare and |
| 1012 | displaced_step_fixup for details. */ |
| 1013 | |
| 1014 | struct displaced_step_request |
| 1015 | { |
| 1016 | ptid_t ptid; |
| 1017 | struct displaced_step_request *next; |
| 1018 | }; |
| 1019 | |
| 1020 | /* Per-inferior displaced stepping state. */ |
| 1021 | struct displaced_step_inferior_state |
| 1022 | { |
| 1023 | /* Pointer to next in linked list. */ |
| 1024 | struct displaced_step_inferior_state *next; |
| 1025 | |
| 1026 | /* The process this displaced step state refers to. */ |
| 1027 | int pid; |
| 1028 | |
| 1029 | /* A queue of pending displaced stepping requests. One entry per |
| 1030 | thread that needs to do a displaced step. */ |
| 1031 | struct displaced_step_request *step_request_queue; |
| 1032 | |
| 1033 | /* If this is not null_ptid, this is the thread carrying out a |
| 1034 | displaced single-step in process PID. This thread's state will |
| 1035 | require fixing up once it has completed its step. */ |
| 1036 | ptid_t step_ptid; |
| 1037 | |
| 1038 | /* The architecture the thread had when we stepped it. */ |
| 1039 | struct gdbarch *step_gdbarch; |
| 1040 | |
| 1041 | /* The closure provided gdbarch_displaced_step_copy_insn, to be used |
| 1042 | for post-step cleanup. */ |
| 1043 | struct displaced_step_closure *step_closure; |
| 1044 | |
| 1045 | /* The address of the original instruction, and the copy we |
| 1046 | made. */ |
| 1047 | CORE_ADDR step_original, step_copy; |
| 1048 | |
| 1049 | /* Saved contents of copy area. */ |
| 1050 | gdb_byte *step_saved_copy; |
| 1051 | }; |
| 1052 | |
| 1053 | /* The list of states of processes involved in displaced stepping |
| 1054 | presently. */ |
| 1055 | static struct displaced_step_inferior_state *displaced_step_inferior_states; |
| 1056 | |
| 1057 | /* Get the displaced stepping state of process PID. */ |
| 1058 | |
| 1059 | static struct displaced_step_inferior_state * |
| 1060 | get_displaced_stepping_state (int pid) |
| 1061 | { |
| 1062 | struct displaced_step_inferior_state *state; |
| 1063 | |
| 1064 | for (state = displaced_step_inferior_states; |
| 1065 | state != NULL; |
| 1066 | state = state->next) |
| 1067 | if (state->pid == pid) |
| 1068 | return state; |
| 1069 | |
| 1070 | return NULL; |
| 1071 | } |
| 1072 | |
| 1073 | /* Add a new displaced stepping state for process PID to the displaced |
| 1074 | stepping state list, or return a pointer to an already existing |
| 1075 | entry, if it already exists. Never returns NULL. */ |
| 1076 | |
| 1077 | static struct displaced_step_inferior_state * |
| 1078 | add_displaced_stepping_state (int pid) |
| 1079 | { |
| 1080 | struct displaced_step_inferior_state *state; |
| 1081 | |
| 1082 | for (state = displaced_step_inferior_states; |
| 1083 | state != NULL; |
| 1084 | state = state->next) |
| 1085 | if (state->pid == pid) |
| 1086 | return state; |
| 1087 | |
| 1088 | state = xcalloc (1, sizeof (*state)); |
| 1089 | state->pid = pid; |
| 1090 | state->next = displaced_step_inferior_states; |
| 1091 | displaced_step_inferior_states = state; |
| 1092 | |
| 1093 | return state; |
| 1094 | } |
| 1095 | |
| 1096 | /* If inferior is in displaced stepping, and ADDR equals to starting address |
| 1097 | of copy area, return corresponding displaced_step_closure. Otherwise, |
| 1098 | return NULL. */ |
| 1099 | |
| 1100 | struct displaced_step_closure* |
| 1101 | get_displaced_step_closure_by_addr (CORE_ADDR addr) |
| 1102 | { |
| 1103 | struct displaced_step_inferior_state *displaced |
| 1104 | = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); |
| 1105 | |
| 1106 | /* If checking the mode of displaced instruction in copy area. */ |
| 1107 | if (displaced && !ptid_equal (displaced->step_ptid, null_ptid) |
| 1108 | && (displaced->step_copy == addr)) |
| 1109 | return displaced->step_closure; |
| 1110 | |
| 1111 | return NULL; |
| 1112 | } |
| 1113 | |
| 1114 | /* Remove the displaced stepping state of process PID. */ |
| 1115 | |
| 1116 | static void |
| 1117 | remove_displaced_stepping_state (int pid) |
| 1118 | { |
| 1119 | struct displaced_step_inferior_state *it, **prev_next_p; |
| 1120 | |
| 1121 | gdb_assert (pid != 0); |
| 1122 | |
| 1123 | it = displaced_step_inferior_states; |
| 1124 | prev_next_p = &displaced_step_inferior_states; |
| 1125 | while (it) |
| 1126 | { |
| 1127 | if (it->pid == pid) |
| 1128 | { |
| 1129 | *prev_next_p = it->next; |
| 1130 | xfree (it); |
| 1131 | return; |
| 1132 | } |
| 1133 | |
| 1134 | prev_next_p = &it->next; |
| 1135 | it = *prev_next_p; |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | static void |
| 1140 | infrun_inferior_exit (struct inferior *inf) |
| 1141 | { |
| 1142 | remove_displaced_stepping_state (inf->pid); |
| 1143 | } |
| 1144 | |
| 1145 | /* Enum strings for "set|show displaced-stepping". */ |
| 1146 | |
| 1147 | static const char can_use_displaced_stepping_auto[] = "auto"; |
| 1148 | static const char can_use_displaced_stepping_on[] = "on"; |
| 1149 | static const char can_use_displaced_stepping_off[] = "off"; |
| 1150 | static const char *can_use_displaced_stepping_enum[] = |
| 1151 | { |
| 1152 | can_use_displaced_stepping_auto, |
| 1153 | can_use_displaced_stepping_on, |
| 1154 | can_use_displaced_stepping_off, |
| 1155 | NULL, |
| 1156 | }; |
| 1157 | |
| 1158 | /* If ON, and the architecture supports it, GDB will use displaced |
| 1159 | stepping to step over breakpoints. If OFF, or if the architecture |
| 1160 | doesn't support it, GDB will instead use the traditional |
| 1161 | hold-and-step approach. If AUTO (which is the default), GDB will |
| 1162 | decide which technique to use to step over breakpoints depending on |
| 1163 | which of all-stop or non-stop mode is active --- displaced stepping |
| 1164 | in non-stop mode; hold-and-step in all-stop mode. */ |
| 1165 | |
| 1166 | static const char *can_use_displaced_stepping = |
| 1167 | can_use_displaced_stepping_auto; |
| 1168 | |
| 1169 | static void |
| 1170 | show_can_use_displaced_stepping (struct ui_file *file, int from_tty, |
| 1171 | struct cmd_list_element *c, |
| 1172 | const char *value) |
| 1173 | { |
| 1174 | if (can_use_displaced_stepping == can_use_displaced_stepping_auto) |
| 1175 | fprintf_filtered (file, |
| 1176 | _("Debugger's willingness to use displaced stepping " |
| 1177 | "to step over breakpoints is %s (currently %s).\n"), |
| 1178 | value, non_stop ? "on" : "off"); |
| 1179 | else |
| 1180 | fprintf_filtered (file, |
| 1181 | _("Debugger's willingness to use displaced stepping " |
| 1182 | "to step over breakpoints is %s.\n"), value); |
| 1183 | } |
| 1184 | |
| 1185 | /* Return non-zero if displaced stepping can/should be used to step |
| 1186 | over breakpoints. */ |
| 1187 | |
| 1188 | static int |
| 1189 | use_displaced_stepping (struct gdbarch *gdbarch) |
| 1190 | { |
| 1191 | return (((can_use_displaced_stepping == can_use_displaced_stepping_auto |
| 1192 | && non_stop) |
| 1193 | || can_use_displaced_stepping == can_use_displaced_stepping_on) |
| 1194 | && gdbarch_displaced_step_copy_insn_p (gdbarch) |
| 1195 | && !RECORD_IS_USED); |
| 1196 | } |
| 1197 | |
| 1198 | /* Clean out any stray displaced stepping state. */ |
| 1199 | static void |
| 1200 | displaced_step_clear (struct displaced_step_inferior_state *displaced) |
| 1201 | { |
| 1202 | /* Indicate that there is no cleanup pending. */ |
| 1203 | displaced->step_ptid = null_ptid; |
| 1204 | |
| 1205 | if (displaced->step_closure) |
| 1206 | { |
| 1207 | gdbarch_displaced_step_free_closure (displaced->step_gdbarch, |
| 1208 | displaced->step_closure); |
| 1209 | displaced->step_closure = NULL; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | static void |
| 1214 | displaced_step_clear_cleanup (void *arg) |
| 1215 | { |
| 1216 | struct displaced_step_inferior_state *state = arg; |
| 1217 | |
| 1218 | displaced_step_clear (state); |
| 1219 | } |
| 1220 | |
| 1221 | /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ |
| 1222 | void |
| 1223 | displaced_step_dump_bytes (struct ui_file *file, |
| 1224 | const gdb_byte *buf, |
| 1225 | size_t len) |
| 1226 | { |
| 1227 | int i; |
| 1228 | |
| 1229 | for (i = 0; i < len; i++) |
| 1230 | fprintf_unfiltered (file, "%02x ", buf[i]); |
| 1231 | fputs_unfiltered ("\n", file); |
| 1232 | } |
| 1233 | |
| 1234 | /* Prepare to single-step, using displaced stepping. |
| 1235 | |
| 1236 | Note that we cannot use displaced stepping when we have a signal to |
| 1237 | deliver. If we have a signal to deliver and an instruction to step |
| 1238 | over, then after the step, there will be no indication from the |
| 1239 | target whether the thread entered a signal handler or ignored the |
| 1240 | signal and stepped over the instruction successfully --- both cases |
| 1241 | result in a simple SIGTRAP. In the first case we mustn't do a |
| 1242 | fixup, and in the second case we must --- but we can't tell which. |
| 1243 | Comments in the code for 'random signals' in handle_inferior_event |
| 1244 | explain how we handle this case instead. |
| 1245 | |
| 1246 | Returns 1 if preparing was successful -- this thread is going to be |
| 1247 | stepped now; or 0 if displaced stepping this thread got queued. */ |
| 1248 | static int |
| 1249 | displaced_step_prepare (ptid_t ptid) |
| 1250 | { |
| 1251 | struct cleanup *old_cleanups, *ignore_cleanups; |
| 1252 | struct regcache *regcache = get_thread_regcache (ptid); |
| 1253 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 1254 | CORE_ADDR original, copy; |
| 1255 | ULONGEST len; |
| 1256 | struct displaced_step_closure *closure; |
| 1257 | struct displaced_step_inferior_state *displaced; |
| 1258 | |
| 1259 | /* We should never reach this function if the architecture does not |
| 1260 | support displaced stepping. */ |
| 1261 | gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch)); |
| 1262 | |
| 1263 | /* We have to displaced step one thread at a time, as we only have |
| 1264 | access to a single scratch space per inferior. */ |
| 1265 | |
| 1266 | displaced = add_displaced_stepping_state (ptid_get_pid (ptid)); |
| 1267 | |
| 1268 | if (!ptid_equal (displaced->step_ptid, null_ptid)) |
| 1269 | { |
| 1270 | /* Already waiting for a displaced step to finish. Defer this |
| 1271 | request and place in queue. */ |
| 1272 | struct displaced_step_request *req, *new_req; |
| 1273 | |
| 1274 | if (debug_displaced) |
| 1275 | fprintf_unfiltered (gdb_stdlog, |
| 1276 | "displaced: defering step of %s\n", |
| 1277 | target_pid_to_str (ptid)); |
| 1278 | |
| 1279 | new_req = xmalloc (sizeof (*new_req)); |
| 1280 | new_req->ptid = ptid; |
| 1281 | new_req->next = NULL; |
| 1282 | |
| 1283 | if (displaced->step_request_queue) |
| 1284 | { |
| 1285 | for (req = displaced->step_request_queue; |
| 1286 | req && req->next; |
| 1287 | req = req->next) |
| 1288 | ; |
| 1289 | req->next = new_req; |
| 1290 | } |
| 1291 | else |
| 1292 | displaced->step_request_queue = new_req; |
| 1293 | |
| 1294 | return 0; |
| 1295 | } |
| 1296 | else |
| 1297 | { |
| 1298 | if (debug_displaced) |
| 1299 | fprintf_unfiltered (gdb_stdlog, |
| 1300 | "displaced: stepping %s now\n", |
| 1301 | target_pid_to_str (ptid)); |
| 1302 | } |
| 1303 | |
| 1304 | displaced_step_clear (displaced); |
| 1305 | |
| 1306 | old_cleanups = save_inferior_ptid (); |
| 1307 | inferior_ptid = ptid; |
| 1308 | |
| 1309 | original = regcache_read_pc (regcache); |
| 1310 | |
| 1311 | copy = gdbarch_displaced_step_location (gdbarch); |
| 1312 | len = gdbarch_max_insn_length (gdbarch); |
| 1313 | |
| 1314 | /* Save the original contents of the copy area. */ |
| 1315 | displaced->step_saved_copy = xmalloc (len); |
| 1316 | ignore_cleanups = make_cleanup (free_current_contents, |
| 1317 | &displaced->step_saved_copy); |
| 1318 | read_memory (copy, displaced->step_saved_copy, len); |
| 1319 | if (debug_displaced) |
| 1320 | { |
| 1321 | fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ", |
| 1322 | paddress (gdbarch, copy)); |
| 1323 | displaced_step_dump_bytes (gdb_stdlog, |
| 1324 | displaced->step_saved_copy, |
| 1325 | len); |
| 1326 | }; |
| 1327 | |
| 1328 | closure = gdbarch_displaced_step_copy_insn (gdbarch, |
| 1329 | original, copy, regcache); |
| 1330 | |
| 1331 | /* We don't support the fully-simulated case at present. */ |
| 1332 | gdb_assert (closure); |
| 1333 | |
| 1334 | /* Save the information we need to fix things up if the step |
| 1335 | succeeds. */ |
| 1336 | displaced->step_ptid = ptid; |
| 1337 | displaced->step_gdbarch = gdbarch; |
| 1338 | displaced->step_closure = closure; |
| 1339 | displaced->step_original = original; |
| 1340 | displaced->step_copy = copy; |
| 1341 | |
| 1342 | make_cleanup (displaced_step_clear_cleanup, displaced); |
| 1343 | |
| 1344 | /* Resume execution at the copy. */ |
| 1345 | regcache_write_pc (regcache, copy); |
| 1346 | |
| 1347 | discard_cleanups (ignore_cleanups); |
| 1348 | |
| 1349 | do_cleanups (old_cleanups); |
| 1350 | |
| 1351 | if (debug_displaced) |
| 1352 | fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n", |
| 1353 | paddress (gdbarch, copy)); |
| 1354 | |
| 1355 | return 1; |
| 1356 | } |
| 1357 | |
| 1358 | static void |
| 1359 | write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, |
| 1360 | const gdb_byte *myaddr, int len) |
| 1361 | { |
| 1362 | struct cleanup *ptid_cleanup = save_inferior_ptid (); |
| 1363 | |
| 1364 | inferior_ptid = ptid; |
| 1365 | write_memory (memaddr, myaddr, len); |
| 1366 | do_cleanups (ptid_cleanup); |
| 1367 | } |
| 1368 | |
| 1369 | static void |
| 1370 | displaced_step_fixup (ptid_t event_ptid, enum target_signal signal) |
| 1371 | { |
| 1372 | struct cleanup *old_cleanups; |
| 1373 | struct displaced_step_inferior_state *displaced |
| 1374 | = get_displaced_stepping_state (ptid_get_pid (event_ptid)); |
| 1375 | |
| 1376 | /* Was any thread of this process doing a displaced step? */ |
| 1377 | if (displaced == NULL) |
| 1378 | return; |
| 1379 | |
| 1380 | /* Was this event for the pid we displaced? */ |
| 1381 | if (ptid_equal (displaced->step_ptid, null_ptid) |
| 1382 | || ! ptid_equal (displaced->step_ptid, event_ptid)) |
| 1383 | return; |
| 1384 | |
| 1385 | old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced); |
| 1386 | |
| 1387 | /* Restore the contents of the copy area. */ |
| 1388 | { |
| 1389 | ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch); |
| 1390 | |
| 1391 | write_memory_ptid (displaced->step_ptid, displaced->step_copy, |
| 1392 | displaced->step_saved_copy, len); |
| 1393 | if (debug_displaced) |
| 1394 | fprintf_unfiltered (gdb_stdlog, "displaced: restored %s\n", |
| 1395 | paddress (displaced->step_gdbarch, |
| 1396 | displaced->step_copy)); |
| 1397 | } |
| 1398 | |
| 1399 | /* Did the instruction complete successfully? */ |
| 1400 | if (signal == TARGET_SIGNAL_TRAP) |
| 1401 | { |
| 1402 | /* Fix up the resulting state. */ |
| 1403 | gdbarch_displaced_step_fixup (displaced->step_gdbarch, |
| 1404 | displaced->step_closure, |
| 1405 | displaced->step_original, |
| 1406 | displaced->step_copy, |
| 1407 | get_thread_regcache (displaced->step_ptid)); |
| 1408 | } |
| 1409 | else |
| 1410 | { |
| 1411 | /* Since the instruction didn't complete, all we can do is |
| 1412 | relocate the PC. */ |
| 1413 | struct regcache *regcache = get_thread_regcache (event_ptid); |
| 1414 | CORE_ADDR pc = regcache_read_pc (regcache); |
| 1415 | |
| 1416 | pc = displaced->step_original + (pc - displaced->step_copy); |
| 1417 | regcache_write_pc (regcache, pc); |
| 1418 | } |
| 1419 | |
| 1420 | do_cleanups (old_cleanups); |
| 1421 | |
| 1422 | displaced->step_ptid = null_ptid; |
| 1423 | |
| 1424 | /* Are there any pending displaced stepping requests? If so, run |
| 1425 | one now. Leave the state object around, since we're likely to |
| 1426 | need it again soon. */ |
| 1427 | while (displaced->step_request_queue) |
| 1428 | { |
| 1429 | struct displaced_step_request *head; |
| 1430 | ptid_t ptid; |
| 1431 | struct regcache *regcache; |
| 1432 | struct gdbarch *gdbarch; |
| 1433 | CORE_ADDR actual_pc; |
| 1434 | struct address_space *aspace; |
| 1435 | |
| 1436 | head = displaced->step_request_queue; |
| 1437 | ptid = head->ptid; |
| 1438 | displaced->step_request_queue = head->next; |
| 1439 | xfree (head); |
| 1440 | |
| 1441 | context_switch (ptid); |
| 1442 | |
| 1443 | regcache = get_thread_regcache (ptid); |
| 1444 | actual_pc = regcache_read_pc (regcache); |
| 1445 | aspace = get_regcache_aspace (regcache); |
| 1446 | |
| 1447 | if (breakpoint_here_p (aspace, actual_pc)) |
| 1448 | { |
| 1449 | if (debug_displaced) |
| 1450 | fprintf_unfiltered (gdb_stdlog, |
| 1451 | "displaced: stepping queued %s now\n", |
| 1452 | target_pid_to_str (ptid)); |
| 1453 | |
| 1454 | displaced_step_prepare (ptid); |
| 1455 | |
| 1456 | gdbarch = get_regcache_arch (regcache); |
| 1457 | |
| 1458 | if (debug_displaced) |
| 1459 | { |
| 1460 | CORE_ADDR actual_pc = regcache_read_pc (regcache); |
| 1461 | gdb_byte buf[4]; |
| 1462 | |
| 1463 | fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", |
| 1464 | paddress (gdbarch, actual_pc)); |
| 1465 | read_memory (actual_pc, buf, sizeof (buf)); |
| 1466 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); |
| 1467 | } |
| 1468 | |
| 1469 | if (gdbarch_displaced_step_hw_singlestep (gdbarch, |
| 1470 | displaced->step_closure)) |
| 1471 | target_resume (ptid, 1, TARGET_SIGNAL_0); |
| 1472 | else |
| 1473 | target_resume (ptid, 0, TARGET_SIGNAL_0); |
| 1474 | |
| 1475 | /* Done, we're stepping a thread. */ |
| 1476 | break; |
| 1477 | } |
| 1478 | else |
| 1479 | { |
| 1480 | int step; |
| 1481 | struct thread_info *tp = inferior_thread (); |
| 1482 | |
| 1483 | /* The breakpoint we were sitting under has since been |
| 1484 | removed. */ |
| 1485 | tp->control.trap_expected = 0; |
| 1486 | |
| 1487 | /* Go back to what we were trying to do. */ |
| 1488 | step = currently_stepping (tp); |
| 1489 | |
| 1490 | if (debug_displaced) |
| 1491 | fprintf_unfiltered (gdb_stdlog, |
| 1492 | "breakpoint is gone %s: step(%d)\n", |
| 1493 | target_pid_to_str (tp->ptid), step); |
| 1494 | |
| 1495 | target_resume (ptid, step, TARGET_SIGNAL_0); |
| 1496 | tp->suspend.stop_signal = TARGET_SIGNAL_0; |
| 1497 | |
| 1498 | /* This request was discarded. See if there's any other |
| 1499 | thread waiting for its turn. */ |
| 1500 | } |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | /* Update global variables holding ptids to hold NEW_PTID if they were |
| 1505 | holding OLD_PTID. */ |
| 1506 | static void |
| 1507 | infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) |
| 1508 | { |
| 1509 | struct displaced_step_request *it; |
| 1510 | struct displaced_step_inferior_state *displaced; |
| 1511 | |
| 1512 | if (ptid_equal (inferior_ptid, old_ptid)) |
| 1513 | inferior_ptid = new_ptid; |
| 1514 | |
| 1515 | if (ptid_equal (singlestep_ptid, old_ptid)) |
| 1516 | singlestep_ptid = new_ptid; |
| 1517 | |
| 1518 | if (ptid_equal (deferred_step_ptid, old_ptid)) |
| 1519 | deferred_step_ptid = new_ptid; |
| 1520 | |
| 1521 | for (displaced = displaced_step_inferior_states; |
| 1522 | displaced; |
| 1523 | displaced = displaced->next) |
| 1524 | { |
| 1525 | if (ptid_equal (displaced->step_ptid, old_ptid)) |
| 1526 | displaced->step_ptid = new_ptid; |
| 1527 | |
| 1528 | for (it = displaced->step_request_queue; it; it = it->next) |
| 1529 | if (ptid_equal (it->ptid, old_ptid)) |
| 1530 | it->ptid = new_ptid; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | \f |
| 1535 | /* Resuming. */ |
| 1536 | |
| 1537 | /* Things to clean up if we QUIT out of resume (). */ |
| 1538 | static void |
| 1539 | resume_cleanups (void *ignore) |
| 1540 | { |
| 1541 | normal_stop (); |
| 1542 | } |
| 1543 | |
| 1544 | static const char schedlock_off[] = "off"; |
| 1545 | static const char schedlock_on[] = "on"; |
| 1546 | static const char schedlock_step[] = "step"; |
| 1547 | static const char *scheduler_enums[] = { |
| 1548 | schedlock_off, |
| 1549 | schedlock_on, |
| 1550 | schedlock_step, |
| 1551 | NULL |
| 1552 | }; |
| 1553 | static const char *scheduler_mode = schedlock_off; |
| 1554 | static void |
| 1555 | show_scheduler_mode (struct ui_file *file, int from_tty, |
| 1556 | struct cmd_list_element *c, const char *value) |
| 1557 | { |
| 1558 | fprintf_filtered (file, |
| 1559 | _("Mode for locking scheduler " |
| 1560 | "during execution is \"%s\".\n"), |
| 1561 | value); |
| 1562 | } |
| 1563 | |
| 1564 | static void |
| 1565 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
| 1566 | { |
| 1567 | if (!target_can_lock_scheduler) |
| 1568 | { |
| 1569 | scheduler_mode = schedlock_off; |
| 1570 | error (_("Target '%s' cannot support this command."), target_shortname); |
| 1571 | } |
| 1572 | } |
| 1573 | |
| 1574 | /* True if execution commands resume all threads of all processes by |
| 1575 | default; otherwise, resume only threads of the current inferior |
| 1576 | process. */ |
| 1577 | int sched_multi = 0; |
| 1578 | |
| 1579 | /* Try to setup for software single stepping over the specified location. |
| 1580 | Return 1 if target_resume() should use hardware single step. |
| 1581 | |
| 1582 | GDBARCH the current gdbarch. |
| 1583 | PC the location to step over. */ |
| 1584 | |
| 1585 | static int |
| 1586 | maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 1587 | { |
| 1588 | int hw_step = 1; |
| 1589 | |
| 1590 | if (execution_direction == EXEC_FORWARD |
| 1591 | && gdbarch_software_single_step_p (gdbarch) |
| 1592 | && gdbarch_software_single_step (gdbarch, get_current_frame ())) |
| 1593 | { |
| 1594 | hw_step = 0; |
| 1595 | /* Do not pull these breakpoints until after a `wait' in |
| 1596 | `wait_for_inferior'. */ |
| 1597 | singlestep_breakpoints_inserted_p = 1; |
| 1598 | singlestep_ptid = inferior_ptid; |
| 1599 | singlestep_pc = pc; |
| 1600 | } |
| 1601 | return hw_step; |
| 1602 | } |
| 1603 | |
| 1604 | /* Resume the inferior, but allow a QUIT. This is useful if the user |
| 1605 | wants to interrupt some lengthy single-stepping operation |
| 1606 | (for child processes, the SIGINT goes to the inferior, and so |
| 1607 | we get a SIGINT random_signal, but for remote debugging and perhaps |
| 1608 | other targets, that's not true). |
| 1609 | |
| 1610 | STEP nonzero if we should step (zero to continue instead). |
| 1611 | SIG is the signal to give the inferior (zero for none). */ |
| 1612 | void |
| 1613 | resume (int step, enum target_signal sig) |
| 1614 | { |
| 1615 | int should_resume = 1; |
| 1616 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
| 1617 | struct regcache *regcache = get_current_regcache (); |
| 1618 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 1619 | struct thread_info *tp = inferior_thread (); |
| 1620 | CORE_ADDR pc = regcache_read_pc (regcache); |
| 1621 | struct address_space *aspace = get_regcache_aspace (regcache); |
| 1622 | |
| 1623 | QUIT; |
| 1624 | |
| 1625 | if (current_inferior ()->waiting_for_vfork_done) |
| 1626 | { |
| 1627 | /* Don't try to single-step a vfork parent that is waiting for |
| 1628 | the child to get out of the shared memory region (by exec'ing |
| 1629 | or exiting). This is particularly important on software |
| 1630 | single-step archs, as the child process would trip on the |
| 1631 | software single step breakpoint inserted for the parent |
| 1632 | process. Since the parent will not actually execute any |
| 1633 | instruction until the child is out of the shared region (such |
| 1634 | are vfork's semantics), it is safe to simply continue it. |
| 1635 | Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for |
| 1636 | the parent, and tell it to `keep_going', which automatically |
| 1637 | re-sets it stepping. */ |
| 1638 | if (debug_infrun) |
| 1639 | fprintf_unfiltered (gdb_stdlog, |
| 1640 | "infrun: resume : clear step\n"); |
| 1641 | step = 0; |
| 1642 | } |
| 1643 | |
| 1644 | if (debug_infrun) |
| 1645 | fprintf_unfiltered (gdb_stdlog, |
| 1646 | "infrun: resume (step=%d, signal=%d), " |
| 1647 | "trap_expected=%d, current thread [%s] at %s\n", |
| 1648 | step, sig, tp->control.trap_expected, |
| 1649 | target_pid_to_str (inferior_ptid), |
| 1650 | paddress (gdbarch, pc)); |
| 1651 | |
| 1652 | /* Normally, by the time we reach `resume', the breakpoints are either |
| 1653 | removed or inserted, as appropriate. The exception is if we're sitting |
| 1654 | at a permanent breakpoint; we need to step over it, but permanent |
| 1655 | breakpoints can't be removed. So we have to test for it here. */ |
| 1656 | if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here) |
| 1657 | { |
| 1658 | if (gdbarch_skip_permanent_breakpoint_p (gdbarch)) |
| 1659 | gdbarch_skip_permanent_breakpoint (gdbarch, regcache); |
| 1660 | else |
| 1661 | error (_("\ |
| 1662 | The program is stopped at a permanent breakpoint, but GDB does not know\n\ |
| 1663 | how to step past a permanent breakpoint on this architecture. Try using\n\ |
| 1664 | a command like `return' or `jump' to continue execution.")); |
| 1665 | } |
| 1666 | |
| 1667 | /* If enabled, step over breakpoints by executing a copy of the |
| 1668 | instruction at a different address. |
| 1669 | |
| 1670 | We can't use displaced stepping when we have a signal to deliver; |
| 1671 | the comments for displaced_step_prepare explain why. The |
| 1672 | comments in the handle_inferior event for dealing with 'random |
| 1673 | signals' explain what we do instead. |
| 1674 | |
| 1675 | We can't use displaced stepping when we are waiting for vfork_done |
| 1676 | event, displaced stepping breaks the vfork child similarly as single |
| 1677 | step software breakpoint. */ |
| 1678 | if (use_displaced_stepping (gdbarch) |
| 1679 | && (tp->control.trap_expected |
| 1680 | || (step && gdbarch_software_single_step_p (gdbarch))) |
| 1681 | && sig == TARGET_SIGNAL_0 |
| 1682 | && !current_inferior ()->waiting_for_vfork_done) |
| 1683 | { |
| 1684 | struct displaced_step_inferior_state *displaced; |
| 1685 | |
| 1686 | if (!displaced_step_prepare (inferior_ptid)) |
| 1687 | { |
| 1688 | /* Got placed in displaced stepping queue. Will be resumed |
| 1689 | later when all the currently queued displaced stepping |
| 1690 | requests finish. The thread is not executing at this point, |
| 1691 | and the call to set_executing will be made later. But we |
| 1692 | need to call set_running here, since from frontend point of view, |
| 1693 | the thread is running. */ |
| 1694 | set_running (inferior_ptid, 1); |
| 1695 | discard_cleanups (old_cleanups); |
| 1696 | return; |
| 1697 | } |
| 1698 | |
| 1699 | displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); |
| 1700 | step = gdbarch_displaced_step_hw_singlestep (gdbarch, |
| 1701 | displaced->step_closure); |
| 1702 | } |
| 1703 | |
| 1704 | /* Do we need to do it the hard way, w/temp breakpoints? */ |
| 1705 | else if (step) |
| 1706 | step = maybe_software_singlestep (gdbarch, pc); |
| 1707 | |
| 1708 | /* Currently, our software single-step implementation leads to different |
| 1709 | results than hardware single-stepping in one situation: when stepping |
| 1710 | into delivering a signal which has an associated signal handler, |
| 1711 | hardware single-step will stop at the first instruction of the handler, |
| 1712 | while software single-step will simply skip execution of the handler. |
| 1713 | |
| 1714 | For now, this difference in behavior is accepted since there is no |
| 1715 | easy way to actually implement single-stepping into a signal handler |
| 1716 | without kernel support. |
| 1717 | |
| 1718 | However, there is one scenario where this difference leads to follow-on |
| 1719 | problems: if we're stepping off a breakpoint by removing all breakpoints |
| 1720 | and then single-stepping. In this case, the software single-step |
| 1721 | behavior means that even if there is a *breakpoint* in the signal |
| 1722 | handler, GDB still would not stop. |
| 1723 | |
| 1724 | Fortunately, we can at least fix this particular issue. We detect |
| 1725 | here the case where we are about to deliver a signal while software |
| 1726 | single-stepping with breakpoints removed. In this situation, we |
| 1727 | revert the decisions to remove all breakpoints and insert single- |
| 1728 | step breakpoints, and instead we install a step-resume breakpoint |
| 1729 | at the current address, deliver the signal without stepping, and |
| 1730 | once we arrive back at the step-resume breakpoint, actually step |
| 1731 | over the breakpoint we originally wanted to step over. */ |
| 1732 | if (singlestep_breakpoints_inserted_p |
| 1733 | && tp->control.trap_expected && sig != TARGET_SIGNAL_0) |
| 1734 | { |
| 1735 | /* If we have nested signals or a pending signal is delivered |
| 1736 | immediately after a handler returns, might might already have |
| 1737 | a step-resume breakpoint set on the earlier handler. We cannot |
| 1738 | set another step-resume breakpoint; just continue on until the |
| 1739 | original breakpoint is hit. */ |
| 1740 | if (tp->control.step_resume_breakpoint == NULL) |
| 1741 | { |
| 1742 | insert_step_resume_breakpoint_at_frame (get_current_frame ()); |
| 1743 | tp->step_after_step_resume_breakpoint = 1; |
| 1744 | } |
| 1745 | |
| 1746 | remove_single_step_breakpoints (); |
| 1747 | singlestep_breakpoints_inserted_p = 0; |
| 1748 | |
| 1749 | insert_breakpoints (); |
| 1750 | tp->control.trap_expected = 0; |
| 1751 | } |
| 1752 | |
| 1753 | if (should_resume) |
| 1754 | { |
| 1755 | ptid_t resume_ptid; |
| 1756 | |
| 1757 | /* If STEP is set, it's a request to use hardware stepping |
| 1758 | facilities. But in that case, we should never |
| 1759 | use singlestep breakpoint. */ |
| 1760 | gdb_assert (!(singlestep_breakpoints_inserted_p && step)); |
| 1761 | |
| 1762 | /* Decide the set of threads to ask the target to resume. Start |
| 1763 | by assuming everything will be resumed, than narrow the set |
| 1764 | by applying increasingly restricting conditions. */ |
| 1765 | |
| 1766 | /* By default, resume all threads of all processes. */ |
| 1767 | resume_ptid = RESUME_ALL; |
| 1768 | |
| 1769 | /* Maybe resume only all threads of the current process. */ |
| 1770 | if (!sched_multi && target_supports_multi_process ()) |
| 1771 | { |
| 1772 | resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); |
| 1773 | } |
| 1774 | |
| 1775 | /* Maybe resume a single thread after all. */ |
| 1776 | if (singlestep_breakpoints_inserted_p |
| 1777 | && stepping_past_singlestep_breakpoint) |
| 1778 | { |
| 1779 | /* The situation here is as follows. In thread T1 we wanted to |
| 1780 | single-step. Lacking hardware single-stepping we've |
| 1781 | set breakpoint at the PC of the next instruction -- call it |
| 1782 | P. After resuming, we've hit that breakpoint in thread T2. |
| 1783 | Now we've removed original breakpoint, inserted breakpoint |
| 1784 | at P+1, and try to step to advance T2 past breakpoint. |
| 1785 | We need to step only T2, as if T1 is allowed to freely run, |
| 1786 | it can run past P, and if other threads are allowed to run, |
| 1787 | they can hit breakpoint at P+1, and nested hits of single-step |
| 1788 | breakpoints is not something we'd want -- that's complicated |
| 1789 | to support, and has no value. */ |
| 1790 | resume_ptid = inferior_ptid; |
| 1791 | } |
| 1792 | else if ((step || singlestep_breakpoints_inserted_p) |
| 1793 | && tp->control.trap_expected) |
| 1794 | { |
| 1795 | /* We're allowing a thread to run past a breakpoint it has |
| 1796 | hit, by single-stepping the thread with the breakpoint |
| 1797 | removed. In which case, we need to single-step only this |
| 1798 | thread, and keep others stopped, as they can miss this |
| 1799 | breakpoint if allowed to run. |
| 1800 | |
| 1801 | The current code actually removes all breakpoints when |
| 1802 | doing this, not just the one being stepped over, so if we |
| 1803 | let other threads run, we can actually miss any |
| 1804 | breakpoint, not just the one at PC. */ |
| 1805 | resume_ptid = inferior_ptid; |
| 1806 | } |
| 1807 | else if (non_stop) |
| 1808 | { |
| 1809 | /* With non-stop mode on, threads are always handled |
| 1810 | individually. */ |
| 1811 | resume_ptid = inferior_ptid; |
| 1812 | } |
| 1813 | else if ((scheduler_mode == schedlock_on) |
| 1814 | || (scheduler_mode == schedlock_step |
| 1815 | && (step || singlestep_breakpoints_inserted_p))) |
| 1816 | { |
| 1817 | /* User-settable 'scheduler' mode requires solo thread resume. */ |
| 1818 | resume_ptid = inferior_ptid; |
| 1819 | } |
| 1820 | |
| 1821 | if (gdbarch_cannot_step_breakpoint (gdbarch)) |
| 1822 | { |
| 1823 | /* Most targets can step a breakpoint instruction, thus |
| 1824 | executing it normally. But if this one cannot, just |
| 1825 | continue and we will hit it anyway. */ |
| 1826 | if (step && breakpoint_inserted_here_p (aspace, pc)) |
| 1827 | step = 0; |
| 1828 | } |
| 1829 | |
| 1830 | if (debug_displaced |
| 1831 | && use_displaced_stepping (gdbarch) |
| 1832 | && tp->control.trap_expected) |
| 1833 | { |
| 1834 | struct regcache *resume_regcache = get_thread_regcache (resume_ptid); |
| 1835 | struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache); |
| 1836 | CORE_ADDR actual_pc = regcache_read_pc (resume_regcache); |
| 1837 | gdb_byte buf[4]; |
| 1838 | |
| 1839 | fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", |
| 1840 | paddress (resume_gdbarch, actual_pc)); |
| 1841 | read_memory (actual_pc, buf, sizeof (buf)); |
| 1842 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); |
| 1843 | } |
| 1844 | |
| 1845 | /* Install inferior's terminal modes. */ |
| 1846 | target_terminal_inferior (); |
| 1847 | |
| 1848 | /* Avoid confusing the next resume, if the next stop/resume |
| 1849 | happens to apply to another thread. */ |
| 1850 | tp->suspend.stop_signal = TARGET_SIGNAL_0; |
| 1851 | |
| 1852 | /* Advise target which signals may be handled silently. If we have |
| 1853 | removed breakpoints because we are stepping over one (which can |
| 1854 | happen only if we are not using displaced stepping), we need to |
| 1855 | receive all signals to avoid accidentally skipping a breakpoint |
| 1856 | during execution of a signal handler. */ |
| 1857 | if ((step || singlestep_breakpoints_inserted_p) |
| 1858 | && tp->control.trap_expected |
| 1859 | && !use_displaced_stepping (gdbarch)) |
| 1860 | target_pass_signals (0, NULL); |
| 1861 | else |
| 1862 | target_pass_signals ((int) TARGET_SIGNAL_LAST, signal_pass); |
| 1863 | |
| 1864 | target_resume (resume_ptid, step, sig); |
| 1865 | } |
| 1866 | |
| 1867 | discard_cleanups (old_cleanups); |
| 1868 | } |
| 1869 | \f |
| 1870 | /* Proceeding. */ |
| 1871 | |
| 1872 | /* Clear out all variables saying what to do when inferior is continued. |
| 1873 | First do this, then set the ones you want, then call `proceed'. */ |
| 1874 | |
| 1875 | static void |
| 1876 | clear_proceed_status_thread (struct thread_info *tp) |
| 1877 | { |
| 1878 | if (debug_infrun) |
| 1879 | fprintf_unfiltered (gdb_stdlog, |
| 1880 | "infrun: clear_proceed_status_thread (%s)\n", |
| 1881 | target_pid_to_str (tp->ptid)); |
| 1882 | |
| 1883 | tp->control.trap_expected = 0; |
| 1884 | tp->control.step_range_start = 0; |
| 1885 | tp->control.step_range_end = 0; |
| 1886 | tp->control.step_frame_id = null_frame_id; |
| 1887 | tp->control.step_stack_frame_id = null_frame_id; |
| 1888 | tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE; |
| 1889 | tp->stop_requested = 0; |
| 1890 | |
| 1891 | tp->control.stop_step = 0; |
| 1892 | |
| 1893 | tp->control.proceed_to_finish = 0; |
| 1894 | |
| 1895 | /* Discard any remaining commands or status from previous stop. */ |
| 1896 | bpstat_clear (&tp->control.stop_bpstat); |
| 1897 | } |
| 1898 | |
| 1899 | static int |
| 1900 | clear_proceed_status_callback (struct thread_info *tp, void *data) |
| 1901 | { |
| 1902 | if (is_exited (tp->ptid)) |
| 1903 | return 0; |
| 1904 | |
| 1905 | clear_proceed_status_thread (tp); |
| 1906 | return 0; |
| 1907 | } |
| 1908 | |
| 1909 | void |
| 1910 | clear_proceed_status (void) |
| 1911 | { |
| 1912 | if (!non_stop) |
| 1913 | { |
| 1914 | /* In all-stop mode, delete the per-thread status of all |
| 1915 | threads, even if inferior_ptid is null_ptid, there may be |
| 1916 | threads on the list. E.g., we may be launching a new |
| 1917 | process, while selecting the executable. */ |
| 1918 | iterate_over_threads (clear_proceed_status_callback, NULL); |
| 1919 | } |
| 1920 | |
| 1921 | if (!ptid_equal (inferior_ptid, null_ptid)) |
| 1922 | { |
| 1923 | struct inferior *inferior; |
| 1924 | |
| 1925 | if (non_stop) |
| 1926 | { |
| 1927 | /* If in non-stop mode, only delete the per-thread status of |
| 1928 | the current thread. */ |
| 1929 | clear_proceed_status_thread (inferior_thread ()); |
| 1930 | } |
| 1931 | |
| 1932 | inferior = current_inferior (); |
| 1933 | inferior->control.stop_soon = NO_STOP_QUIETLY; |
| 1934 | } |
| 1935 | |
| 1936 | stop_after_trap = 0; |
| 1937 | |
| 1938 | observer_notify_about_to_proceed (); |
| 1939 | |
| 1940 | if (stop_registers) |
| 1941 | { |
| 1942 | regcache_xfree (stop_registers); |
| 1943 | stop_registers = NULL; |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | /* Check the current thread against the thread that reported the most recent |
| 1948 | event. If a step-over is required return TRUE and set the current thread |
| 1949 | to the old thread. Otherwise return FALSE. |
| 1950 | |
| 1951 | This should be suitable for any targets that support threads. */ |
| 1952 | |
| 1953 | static int |
| 1954 | prepare_to_proceed (int step) |
| 1955 | { |
| 1956 | ptid_t wait_ptid; |
| 1957 | struct target_waitstatus wait_status; |
| 1958 | int schedlock_enabled; |
| 1959 | |
| 1960 | /* With non-stop mode on, threads are always handled individually. */ |
| 1961 | gdb_assert (! non_stop); |
| 1962 | |
| 1963 | /* Get the last target status returned by target_wait(). */ |
| 1964 | get_last_target_status (&wait_ptid, &wait_status); |
| 1965 | |
| 1966 | /* Make sure we were stopped at a breakpoint. */ |
| 1967 | if (wait_status.kind != TARGET_WAITKIND_STOPPED |
| 1968 | || (wait_status.value.sig != TARGET_SIGNAL_TRAP |
| 1969 | && wait_status.value.sig != TARGET_SIGNAL_ILL |
| 1970 | && wait_status.value.sig != TARGET_SIGNAL_SEGV |
| 1971 | && wait_status.value.sig != TARGET_SIGNAL_EMT)) |
| 1972 | { |
| 1973 | return 0; |
| 1974 | } |
| 1975 | |
| 1976 | schedlock_enabled = (scheduler_mode == schedlock_on |
| 1977 | || (scheduler_mode == schedlock_step |
| 1978 | && step)); |
| 1979 | |
| 1980 | /* Don't switch over to WAIT_PTID if scheduler locking is on. */ |
| 1981 | if (schedlock_enabled) |
| 1982 | return 0; |
| 1983 | |
| 1984 | /* Don't switch over if we're about to resume some other process |
| 1985 | other than WAIT_PTID's, and schedule-multiple is off. */ |
| 1986 | if (!sched_multi |
| 1987 | && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid)) |
| 1988 | return 0; |
| 1989 | |
| 1990 | /* Switched over from WAIT_PID. */ |
| 1991 | if (!ptid_equal (wait_ptid, minus_one_ptid) |
| 1992 | && !ptid_equal (inferior_ptid, wait_ptid)) |
| 1993 | { |
| 1994 | struct regcache *regcache = get_thread_regcache (wait_ptid); |
| 1995 | |
| 1996 | if (breakpoint_here_p (get_regcache_aspace (regcache), |
| 1997 | regcache_read_pc (regcache))) |
| 1998 | { |
| 1999 | /* If stepping, remember current thread to switch back to. */ |
| 2000 | if (step) |
| 2001 | deferred_step_ptid = inferior_ptid; |
| 2002 | |
| 2003 | /* Switch back to WAIT_PID thread. */ |
| 2004 | switch_to_thread (wait_ptid); |
| 2005 | |
| 2006 | if (debug_infrun) |
| 2007 | fprintf_unfiltered (gdb_stdlog, |
| 2008 | "infrun: prepare_to_proceed (step=%d), " |
| 2009 | "switched to [%s]\n", |
| 2010 | step, target_pid_to_str (inferior_ptid)); |
| 2011 | |
| 2012 | /* We return 1 to indicate that there is a breakpoint here, |
| 2013 | so we need to step over it before continuing to avoid |
| 2014 | hitting it straight away. */ |
| 2015 | return 1; |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | return 0; |
| 2020 | } |
| 2021 | |
| 2022 | /* Basic routine for continuing the program in various fashions. |
| 2023 | |
| 2024 | ADDR is the address to resume at, or -1 for resume where stopped. |
| 2025 | SIGGNAL is the signal to give it, or 0 for none, |
| 2026 | or -1 for act according to how it stopped. |
| 2027 | STEP is nonzero if should trap after one instruction. |
| 2028 | -1 means return after that and print nothing. |
| 2029 | You should probably set various step_... variables |
| 2030 | before calling here, if you are stepping. |
| 2031 | |
| 2032 | You should call clear_proceed_status before calling proceed. */ |
| 2033 | |
| 2034 | void |
| 2035 | proceed (CORE_ADDR addr, enum target_signal siggnal, int step) |
| 2036 | { |
| 2037 | struct regcache *regcache; |
| 2038 | struct gdbarch *gdbarch; |
| 2039 | struct thread_info *tp; |
| 2040 | CORE_ADDR pc; |
| 2041 | struct address_space *aspace; |
| 2042 | int oneproc = 0; |
| 2043 | |
| 2044 | /* If we're stopped at a fork/vfork, follow the branch set by the |
| 2045 | "set follow-fork-mode" command; otherwise, we'll just proceed |
| 2046 | resuming the current thread. */ |
| 2047 | if (!follow_fork ()) |
| 2048 | { |
| 2049 | /* The target for some reason decided not to resume. */ |
| 2050 | normal_stop (); |
| 2051 | return; |
| 2052 | } |
| 2053 | |
| 2054 | regcache = get_current_regcache (); |
| 2055 | gdbarch = get_regcache_arch (regcache); |
| 2056 | aspace = get_regcache_aspace (regcache); |
| 2057 | pc = regcache_read_pc (regcache); |
| 2058 | |
| 2059 | if (step > 0) |
| 2060 | step_start_function = find_pc_function (pc); |
| 2061 | if (step < 0) |
| 2062 | stop_after_trap = 1; |
| 2063 | |
| 2064 | if (addr == (CORE_ADDR) -1) |
| 2065 | { |
| 2066 | if (pc == stop_pc && breakpoint_here_p (aspace, pc) |
| 2067 | && execution_direction != EXEC_REVERSE) |
| 2068 | /* There is a breakpoint at the address we will resume at, |
| 2069 | step one instruction before inserting breakpoints so that |
| 2070 | we do not stop right away (and report a second hit at this |
| 2071 | breakpoint). |
| 2072 | |
| 2073 | Note, we don't do this in reverse, because we won't |
| 2074 | actually be executing the breakpoint insn anyway. |
| 2075 | We'll be (un-)executing the previous instruction. */ |
| 2076 | |
| 2077 | oneproc = 1; |
| 2078 | else if (gdbarch_single_step_through_delay_p (gdbarch) |
| 2079 | && gdbarch_single_step_through_delay (gdbarch, |
| 2080 | get_current_frame ())) |
| 2081 | /* We stepped onto an instruction that needs to be stepped |
| 2082 | again before re-inserting the breakpoint, do so. */ |
| 2083 | oneproc = 1; |
| 2084 | } |
| 2085 | else |
| 2086 | { |
| 2087 | regcache_write_pc (regcache, addr); |
| 2088 | } |
| 2089 | |
| 2090 | if (debug_infrun) |
| 2091 | fprintf_unfiltered (gdb_stdlog, |
| 2092 | "infrun: proceed (addr=%s, signal=%d, step=%d)\n", |
| 2093 | paddress (gdbarch, addr), siggnal, step); |
| 2094 | |
| 2095 | if (non_stop) |
| 2096 | /* In non-stop, each thread is handled individually. The context |
| 2097 | must already be set to the right thread here. */ |
| 2098 | ; |
| 2099 | else |
| 2100 | { |
| 2101 | /* In a multi-threaded task we may select another thread and |
| 2102 | then continue or step. |
| 2103 | |
| 2104 | But if the old thread was stopped at a breakpoint, it will |
| 2105 | immediately cause another breakpoint stop without any |
| 2106 | execution (i.e. it will report a breakpoint hit incorrectly). |
| 2107 | So we must step over it first. |
| 2108 | |
| 2109 | prepare_to_proceed checks the current thread against the |
| 2110 | thread that reported the most recent event. If a step-over |
| 2111 | is required it returns TRUE and sets the current thread to |
| 2112 | the old thread. */ |
| 2113 | if (prepare_to_proceed (step)) |
| 2114 | oneproc = 1; |
| 2115 | } |
| 2116 | |
| 2117 | /* prepare_to_proceed may change the current thread. */ |
| 2118 | tp = inferior_thread (); |
| 2119 | |
| 2120 | if (oneproc) |
| 2121 | { |
| 2122 | tp->control.trap_expected = 1; |
| 2123 | /* If displaced stepping is enabled, we can step over the |
| 2124 | breakpoint without hitting it, so leave all breakpoints |
| 2125 | inserted. Otherwise we need to disable all breakpoints, step |
| 2126 | one instruction, and then re-add them when that step is |
| 2127 | finished. */ |
| 2128 | if (!use_displaced_stepping (gdbarch)) |
| 2129 | remove_breakpoints (); |
| 2130 | } |
| 2131 | |
| 2132 | /* We can insert breakpoints if we're not trying to step over one, |
| 2133 | or if we are stepping over one but we're using displaced stepping |
| 2134 | to do so. */ |
| 2135 | if (! tp->control.trap_expected || use_displaced_stepping (gdbarch)) |
| 2136 | insert_breakpoints (); |
| 2137 | |
| 2138 | if (!non_stop) |
| 2139 | { |
| 2140 | /* Pass the last stop signal to the thread we're resuming, |
| 2141 | irrespective of whether the current thread is the thread that |
| 2142 | got the last event or not. This was historically GDB's |
| 2143 | behaviour before keeping a stop_signal per thread. */ |
| 2144 | |
| 2145 | struct thread_info *last_thread; |
| 2146 | ptid_t last_ptid; |
| 2147 | struct target_waitstatus last_status; |
| 2148 | |
| 2149 | get_last_target_status (&last_ptid, &last_status); |
| 2150 | if (!ptid_equal (inferior_ptid, last_ptid) |
| 2151 | && !ptid_equal (last_ptid, null_ptid) |
| 2152 | && !ptid_equal (last_ptid, minus_one_ptid)) |
| 2153 | { |
| 2154 | last_thread = find_thread_ptid (last_ptid); |
| 2155 | if (last_thread) |
| 2156 | { |
| 2157 | tp->suspend.stop_signal = last_thread->suspend.stop_signal; |
| 2158 | last_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 2159 | } |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | if (siggnal != TARGET_SIGNAL_DEFAULT) |
| 2164 | tp->suspend.stop_signal = siggnal; |
| 2165 | /* If this signal should not be seen by program, |
| 2166 | give it zero. Used for debugging signals. */ |
| 2167 | else if (!signal_program[tp->suspend.stop_signal]) |
| 2168 | tp->suspend.stop_signal = TARGET_SIGNAL_0; |
| 2169 | |
| 2170 | annotate_starting (); |
| 2171 | |
| 2172 | /* Make sure that output from GDB appears before output from the |
| 2173 | inferior. */ |
| 2174 | gdb_flush (gdb_stdout); |
| 2175 | |
| 2176 | /* Refresh prev_pc value just prior to resuming. This used to be |
| 2177 | done in stop_stepping, however, setting prev_pc there did not handle |
| 2178 | scenarios such as inferior function calls or returning from |
| 2179 | a function via the return command. In those cases, the prev_pc |
| 2180 | value was not set properly for subsequent commands. The prev_pc value |
| 2181 | is used to initialize the starting line number in the ecs. With an |
| 2182 | invalid value, the gdb next command ends up stopping at the position |
| 2183 | represented by the next line table entry past our start position. |
| 2184 | On platforms that generate one line table entry per line, this |
| 2185 | is not a problem. However, on the ia64, the compiler generates |
| 2186 | extraneous line table entries that do not increase the line number. |
| 2187 | When we issue the gdb next command on the ia64 after an inferior call |
| 2188 | or a return command, we often end up a few instructions forward, still |
| 2189 | within the original line we started. |
| 2190 | |
| 2191 | An attempt was made to refresh the prev_pc at the same time the |
| 2192 | execution_control_state is initialized (for instance, just before |
| 2193 | waiting for an inferior event). But this approach did not work |
| 2194 | because of platforms that use ptrace, where the pc register cannot |
| 2195 | be read unless the inferior is stopped. At that point, we are not |
| 2196 | guaranteed the inferior is stopped and so the regcache_read_pc() call |
| 2197 | can fail. Setting the prev_pc value here ensures the value is updated |
| 2198 | correctly when the inferior is stopped. */ |
| 2199 | tp->prev_pc = regcache_read_pc (get_current_regcache ()); |
| 2200 | |
| 2201 | /* Fill in with reasonable starting values. */ |
| 2202 | init_thread_stepping_state (tp); |
| 2203 | |
| 2204 | /* Reset to normal state. */ |
| 2205 | init_infwait_state (); |
| 2206 | |
| 2207 | /* Resume inferior. */ |
| 2208 | resume (oneproc || step || bpstat_should_step (), tp->suspend.stop_signal); |
| 2209 | |
| 2210 | /* Wait for it to stop (if not standalone) |
| 2211 | and in any case decode why it stopped, and act accordingly. */ |
| 2212 | /* Do this only if we are not using the event loop, or if the target |
| 2213 | does not support asynchronous execution. */ |
| 2214 | if (!target_can_async_p ()) |
| 2215 | { |
| 2216 | wait_for_inferior (); |
| 2217 | normal_stop (); |
| 2218 | } |
| 2219 | } |
| 2220 | \f |
| 2221 | |
| 2222 | /* Start remote-debugging of a machine over a serial link. */ |
| 2223 | |
| 2224 | void |
| 2225 | start_remote (int from_tty) |
| 2226 | { |
| 2227 | struct inferior *inferior; |
| 2228 | |
| 2229 | init_wait_for_inferior (); |
| 2230 | inferior = current_inferior (); |
| 2231 | inferior->control.stop_soon = STOP_QUIETLY_REMOTE; |
| 2232 | |
| 2233 | /* Always go on waiting for the target, regardless of the mode. */ |
| 2234 | /* FIXME: cagney/1999-09-23: At present it isn't possible to |
| 2235 | indicate to wait_for_inferior that a target should timeout if |
| 2236 | nothing is returned (instead of just blocking). Because of this, |
| 2237 | targets expecting an immediate response need to, internally, set |
| 2238 | things up so that the target_wait() is forced to eventually |
| 2239 | timeout. */ |
| 2240 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to |
| 2241 | differentiate to its caller what the state of the target is after |
| 2242 | the initial open has been performed. Here we're assuming that |
| 2243 | the target has stopped. It should be possible to eventually have |
| 2244 | target_open() return to the caller an indication that the target |
| 2245 | is currently running and GDB state should be set to the same as |
| 2246 | for an async run. */ |
| 2247 | wait_for_inferior (); |
| 2248 | |
| 2249 | /* Now that the inferior has stopped, do any bookkeeping like |
| 2250 | loading shared libraries. We want to do this before normal_stop, |
| 2251 | so that the displayed frame is up to date. */ |
| 2252 | post_create_inferior (¤t_target, from_tty); |
| 2253 | |
| 2254 | normal_stop (); |
| 2255 | } |
| 2256 | |
| 2257 | /* Initialize static vars when a new inferior begins. */ |
| 2258 | |
| 2259 | void |
| 2260 | init_wait_for_inferior (void) |
| 2261 | { |
| 2262 | /* These are meaningless until the first time through wait_for_inferior. */ |
| 2263 | |
| 2264 | breakpoint_init_inferior (inf_starting); |
| 2265 | |
| 2266 | clear_proceed_status (); |
| 2267 | |
| 2268 | stepping_past_singlestep_breakpoint = 0; |
| 2269 | deferred_step_ptid = null_ptid; |
| 2270 | |
| 2271 | target_last_wait_ptid = minus_one_ptid; |
| 2272 | |
| 2273 | previous_inferior_ptid = null_ptid; |
| 2274 | init_infwait_state (); |
| 2275 | |
| 2276 | /* Discard any skipped inlined frames. */ |
| 2277 | clear_inline_frame_state (minus_one_ptid); |
| 2278 | } |
| 2279 | |
| 2280 | \f |
| 2281 | /* This enum encodes possible reasons for doing a target_wait, so that |
| 2282 | wfi can call target_wait in one place. (Ultimately the call will be |
| 2283 | moved out of the infinite loop entirely.) */ |
| 2284 | |
| 2285 | enum infwait_states |
| 2286 | { |
| 2287 | infwait_normal_state, |
| 2288 | infwait_thread_hop_state, |
| 2289 | infwait_step_watch_state, |
| 2290 | infwait_nonstep_watch_state |
| 2291 | }; |
| 2292 | |
| 2293 | /* The PTID we'll do a target_wait on.*/ |
| 2294 | ptid_t waiton_ptid; |
| 2295 | |
| 2296 | /* Current inferior wait state. */ |
| 2297 | enum infwait_states infwait_state; |
| 2298 | |
| 2299 | /* Data to be passed around while handling an event. This data is |
| 2300 | discarded between events. */ |
| 2301 | struct execution_control_state |
| 2302 | { |
| 2303 | ptid_t ptid; |
| 2304 | /* The thread that got the event, if this was a thread event; NULL |
| 2305 | otherwise. */ |
| 2306 | struct thread_info *event_thread; |
| 2307 | |
| 2308 | struct target_waitstatus ws; |
| 2309 | int random_signal; |
| 2310 | CORE_ADDR stop_func_start; |
| 2311 | CORE_ADDR stop_func_end; |
| 2312 | char *stop_func_name; |
| 2313 | int new_thread_event; |
| 2314 | int wait_some_more; |
| 2315 | }; |
| 2316 | |
| 2317 | static void handle_inferior_event (struct execution_control_state *ecs); |
| 2318 | |
| 2319 | static void handle_step_into_function (struct gdbarch *gdbarch, |
| 2320 | struct execution_control_state *ecs); |
| 2321 | static void handle_step_into_function_backward (struct gdbarch *gdbarch, |
| 2322 | struct execution_control_state *ecs); |
| 2323 | static void check_exception_resume (struct execution_control_state *, |
| 2324 | struct frame_info *, struct symbol *); |
| 2325 | |
| 2326 | static void stop_stepping (struct execution_control_state *ecs); |
| 2327 | static void prepare_to_wait (struct execution_control_state *ecs); |
| 2328 | static void keep_going (struct execution_control_state *ecs); |
| 2329 | |
| 2330 | /* Callback for iterate over threads. If the thread is stopped, but |
| 2331 | the user/frontend doesn't know about that yet, go through |
| 2332 | normal_stop, as if the thread had just stopped now. ARG points at |
| 2333 | a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If |
| 2334 | ptid_is_pid(PTID) is true, applies to all threads of the process |
| 2335 | pointed at by PTID. Otherwise, apply only to the thread pointed by |
| 2336 | PTID. */ |
| 2337 | |
| 2338 | static int |
| 2339 | infrun_thread_stop_requested_callback (struct thread_info *info, void *arg) |
| 2340 | { |
| 2341 | ptid_t ptid = * (ptid_t *) arg; |
| 2342 | |
| 2343 | if ((ptid_equal (info->ptid, ptid) |
| 2344 | || ptid_equal (minus_one_ptid, ptid) |
| 2345 | || (ptid_is_pid (ptid) |
| 2346 | && ptid_get_pid (ptid) == ptid_get_pid (info->ptid))) |
| 2347 | && is_running (info->ptid) |
| 2348 | && !is_executing (info->ptid)) |
| 2349 | { |
| 2350 | struct cleanup *old_chain; |
| 2351 | struct execution_control_state ecss; |
| 2352 | struct execution_control_state *ecs = &ecss; |
| 2353 | |
| 2354 | memset (ecs, 0, sizeof (*ecs)); |
| 2355 | |
| 2356 | old_chain = make_cleanup_restore_current_thread (); |
| 2357 | |
| 2358 | switch_to_thread (info->ptid); |
| 2359 | |
| 2360 | /* Go through handle_inferior_event/normal_stop, so we always |
| 2361 | have consistent output as if the stop event had been |
| 2362 | reported. */ |
| 2363 | ecs->ptid = info->ptid; |
| 2364 | ecs->event_thread = find_thread_ptid (info->ptid); |
| 2365 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; |
| 2366 | ecs->ws.value.sig = TARGET_SIGNAL_0; |
| 2367 | |
| 2368 | handle_inferior_event (ecs); |
| 2369 | |
| 2370 | if (!ecs->wait_some_more) |
| 2371 | { |
| 2372 | struct thread_info *tp; |
| 2373 | |
| 2374 | normal_stop (); |
| 2375 | |
| 2376 | /* Finish off the continuations. The continations |
| 2377 | themselves are responsible for realising the thread |
| 2378 | didn't finish what it was supposed to do. */ |
| 2379 | tp = inferior_thread (); |
| 2380 | do_all_intermediate_continuations_thread (tp); |
| 2381 | do_all_continuations_thread (tp); |
| 2382 | } |
| 2383 | |
| 2384 | do_cleanups (old_chain); |
| 2385 | } |
| 2386 | |
| 2387 | return 0; |
| 2388 | } |
| 2389 | |
| 2390 | /* This function is attached as a "thread_stop_requested" observer. |
| 2391 | Cleanup local state that assumed the PTID was to be resumed, and |
| 2392 | report the stop to the frontend. */ |
| 2393 | |
| 2394 | static void |
| 2395 | infrun_thread_stop_requested (ptid_t ptid) |
| 2396 | { |
| 2397 | struct displaced_step_inferior_state *displaced; |
| 2398 | |
| 2399 | /* PTID was requested to stop. Remove it from the displaced |
| 2400 | stepping queue, so we don't try to resume it automatically. */ |
| 2401 | |
| 2402 | for (displaced = displaced_step_inferior_states; |
| 2403 | displaced; |
| 2404 | displaced = displaced->next) |
| 2405 | { |
| 2406 | struct displaced_step_request *it, **prev_next_p; |
| 2407 | |
| 2408 | it = displaced->step_request_queue; |
| 2409 | prev_next_p = &displaced->step_request_queue; |
| 2410 | while (it) |
| 2411 | { |
| 2412 | if (ptid_match (it->ptid, ptid)) |
| 2413 | { |
| 2414 | *prev_next_p = it->next; |
| 2415 | it->next = NULL; |
| 2416 | xfree (it); |
| 2417 | } |
| 2418 | else |
| 2419 | { |
| 2420 | prev_next_p = &it->next; |
| 2421 | } |
| 2422 | |
| 2423 | it = *prev_next_p; |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | iterate_over_threads (infrun_thread_stop_requested_callback, &ptid); |
| 2428 | } |
| 2429 | |
| 2430 | static void |
| 2431 | infrun_thread_thread_exit (struct thread_info *tp, int silent) |
| 2432 | { |
| 2433 | if (ptid_equal (target_last_wait_ptid, tp->ptid)) |
| 2434 | nullify_last_target_wait_ptid (); |
| 2435 | } |
| 2436 | |
| 2437 | /* Callback for iterate_over_threads. */ |
| 2438 | |
| 2439 | static int |
| 2440 | delete_step_resume_breakpoint_callback (struct thread_info *info, void *data) |
| 2441 | { |
| 2442 | if (is_exited (info->ptid)) |
| 2443 | return 0; |
| 2444 | |
| 2445 | delete_step_resume_breakpoint (info); |
| 2446 | delete_exception_resume_breakpoint (info); |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
| 2450 | /* In all-stop, delete the step resume breakpoint of any thread that |
| 2451 | had one. In non-stop, delete the step resume breakpoint of the |
| 2452 | thread that just stopped. */ |
| 2453 | |
| 2454 | static void |
| 2455 | delete_step_thread_step_resume_breakpoint (void) |
| 2456 | { |
| 2457 | if (!target_has_execution |
| 2458 | || ptid_equal (inferior_ptid, null_ptid)) |
| 2459 | /* If the inferior has exited, we have already deleted the step |
| 2460 | resume breakpoints out of GDB's lists. */ |
| 2461 | return; |
| 2462 | |
| 2463 | if (non_stop) |
| 2464 | { |
| 2465 | /* If in non-stop mode, only delete the step-resume or |
| 2466 | longjmp-resume breakpoint of the thread that just stopped |
| 2467 | stepping. */ |
| 2468 | struct thread_info *tp = inferior_thread (); |
| 2469 | |
| 2470 | delete_step_resume_breakpoint (tp); |
| 2471 | delete_exception_resume_breakpoint (tp); |
| 2472 | } |
| 2473 | else |
| 2474 | /* In all-stop mode, delete all step-resume and longjmp-resume |
| 2475 | breakpoints of any thread that had them. */ |
| 2476 | iterate_over_threads (delete_step_resume_breakpoint_callback, NULL); |
| 2477 | } |
| 2478 | |
| 2479 | /* A cleanup wrapper. */ |
| 2480 | |
| 2481 | static void |
| 2482 | delete_step_thread_step_resume_breakpoint_cleanup (void *arg) |
| 2483 | { |
| 2484 | delete_step_thread_step_resume_breakpoint (); |
| 2485 | } |
| 2486 | |
| 2487 | /* Pretty print the results of target_wait, for debugging purposes. */ |
| 2488 | |
| 2489 | static void |
| 2490 | print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, |
| 2491 | const struct target_waitstatus *ws) |
| 2492 | { |
| 2493 | char *status_string = target_waitstatus_to_string (ws); |
| 2494 | struct ui_file *tmp_stream = mem_fileopen (); |
| 2495 | char *text; |
| 2496 | |
| 2497 | /* The text is split over several lines because it was getting too long. |
| 2498 | Call fprintf_unfiltered (gdb_stdlog) once so that the text is still |
| 2499 | output as a unit; we want only one timestamp printed if debug_timestamp |
| 2500 | is set. */ |
| 2501 | |
| 2502 | fprintf_unfiltered (tmp_stream, |
| 2503 | "infrun: target_wait (%d", PIDGET (waiton_ptid)); |
| 2504 | if (PIDGET (waiton_ptid) != -1) |
| 2505 | fprintf_unfiltered (tmp_stream, |
| 2506 | " [%s]", target_pid_to_str (waiton_ptid)); |
| 2507 | fprintf_unfiltered (tmp_stream, ", status) =\n"); |
| 2508 | fprintf_unfiltered (tmp_stream, |
| 2509 | "infrun: %d [%s],\n", |
| 2510 | PIDGET (result_ptid), target_pid_to_str (result_ptid)); |
| 2511 | fprintf_unfiltered (tmp_stream, |
| 2512 | "infrun: %s\n", |
| 2513 | status_string); |
| 2514 | |
| 2515 | text = ui_file_xstrdup (tmp_stream, NULL); |
| 2516 | |
| 2517 | /* This uses %s in part to handle %'s in the text, but also to avoid |
| 2518 | a gcc error: the format attribute requires a string literal. */ |
| 2519 | fprintf_unfiltered (gdb_stdlog, "%s", text); |
| 2520 | |
| 2521 | xfree (status_string); |
| 2522 | xfree (text); |
| 2523 | ui_file_delete (tmp_stream); |
| 2524 | } |
| 2525 | |
| 2526 | /* Prepare and stabilize the inferior for detaching it. E.g., |
| 2527 | detaching while a thread is displaced stepping is a recipe for |
| 2528 | crashing it, as nothing would readjust the PC out of the scratch |
| 2529 | pad. */ |
| 2530 | |
| 2531 | void |
| 2532 | prepare_for_detach (void) |
| 2533 | { |
| 2534 | struct inferior *inf = current_inferior (); |
| 2535 | ptid_t pid_ptid = pid_to_ptid (inf->pid); |
| 2536 | struct cleanup *old_chain_1; |
| 2537 | struct displaced_step_inferior_state *displaced; |
| 2538 | |
| 2539 | displaced = get_displaced_stepping_state (inf->pid); |
| 2540 | |
| 2541 | /* Is any thread of this process displaced stepping? If not, |
| 2542 | there's nothing else to do. */ |
| 2543 | if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid)) |
| 2544 | return; |
| 2545 | |
| 2546 | if (debug_infrun) |
| 2547 | fprintf_unfiltered (gdb_stdlog, |
| 2548 | "displaced-stepping in-process while detaching"); |
| 2549 | |
| 2550 | old_chain_1 = make_cleanup_restore_integer (&inf->detaching); |
| 2551 | inf->detaching = 1; |
| 2552 | |
| 2553 | while (!ptid_equal (displaced->step_ptid, null_ptid)) |
| 2554 | { |
| 2555 | struct cleanup *old_chain_2; |
| 2556 | struct execution_control_state ecss; |
| 2557 | struct execution_control_state *ecs; |
| 2558 | |
| 2559 | ecs = &ecss; |
| 2560 | memset (ecs, 0, sizeof (*ecs)); |
| 2561 | |
| 2562 | overlay_cache_invalid = 1; |
| 2563 | |
| 2564 | /* We have to invalidate the registers BEFORE calling |
| 2565 | target_wait because they can be loaded from the target while |
| 2566 | in target_wait. This makes remote debugging a bit more |
| 2567 | efficient for those targets that provide critical registers |
| 2568 | as part of their normal status mechanism. */ |
| 2569 | |
| 2570 | registers_changed (); |
| 2571 | |
| 2572 | if (deprecated_target_wait_hook) |
| 2573 | ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0); |
| 2574 | else |
| 2575 | ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0); |
| 2576 | |
| 2577 | if (debug_infrun) |
| 2578 | print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws); |
| 2579 | |
| 2580 | /* If an error happens while handling the event, propagate GDB's |
| 2581 | knowledge of the executing state to the frontend/user running |
| 2582 | state. */ |
| 2583 | old_chain_2 = make_cleanup (finish_thread_state_cleanup, |
| 2584 | &minus_one_ptid); |
| 2585 | |
| 2586 | /* In non-stop mode, each thread is handled individually. |
| 2587 | Switch early, so the global state is set correctly for this |
| 2588 | thread. */ |
| 2589 | if (non_stop |
| 2590 | && ecs->ws.kind != TARGET_WAITKIND_EXITED |
| 2591 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) |
| 2592 | context_switch (ecs->ptid); |
| 2593 | |
| 2594 | /* Now figure out what to do with the result of the result. */ |
| 2595 | handle_inferior_event (ecs); |
| 2596 | |
| 2597 | /* No error, don't finish the state yet. */ |
| 2598 | discard_cleanups (old_chain_2); |
| 2599 | |
| 2600 | /* Breakpoints and watchpoints are not installed on the target |
| 2601 | at this point, and signals are passed directly to the |
| 2602 | inferior, so this must mean the process is gone. */ |
| 2603 | if (!ecs->wait_some_more) |
| 2604 | { |
| 2605 | discard_cleanups (old_chain_1); |
| 2606 | error (_("Program exited while detaching")); |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | discard_cleanups (old_chain_1); |
| 2611 | } |
| 2612 | |
| 2613 | /* Wait for control to return from inferior to debugger. |
| 2614 | |
| 2615 | If inferior gets a signal, we may decide to start it up again |
| 2616 | instead of returning. That is why there is a loop in this function. |
| 2617 | When this function actually returns it means the inferior |
| 2618 | should be left stopped and GDB should read more commands. */ |
| 2619 | |
| 2620 | void |
| 2621 | wait_for_inferior (void) |
| 2622 | { |
| 2623 | struct cleanup *old_cleanups; |
| 2624 | struct execution_control_state ecss; |
| 2625 | struct execution_control_state *ecs; |
| 2626 | |
| 2627 | if (debug_infrun) |
| 2628 | fprintf_unfiltered |
| 2629 | (gdb_stdlog, "infrun: wait_for_inferior ()\n"); |
| 2630 | |
| 2631 | old_cleanups = |
| 2632 | make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL); |
| 2633 | |
| 2634 | ecs = &ecss; |
| 2635 | memset (ecs, 0, sizeof (*ecs)); |
| 2636 | |
| 2637 | /* We'll update this if & when we switch to a new thread. */ |
| 2638 | previous_inferior_ptid = inferior_ptid; |
| 2639 | |
| 2640 | while (1) |
| 2641 | { |
| 2642 | struct cleanup *old_chain; |
| 2643 | |
| 2644 | /* We have to invalidate the registers BEFORE calling target_wait |
| 2645 | because they can be loaded from the target while in target_wait. |
| 2646 | This makes remote debugging a bit more efficient for those |
| 2647 | targets that provide critical registers as part of their normal |
| 2648 | status mechanism. */ |
| 2649 | |
| 2650 | overlay_cache_invalid = 1; |
| 2651 | registers_changed (); |
| 2652 | |
| 2653 | if (deprecated_target_wait_hook) |
| 2654 | ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0); |
| 2655 | else |
| 2656 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0); |
| 2657 | |
| 2658 | if (debug_infrun) |
| 2659 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
| 2660 | |
| 2661 | /* If an error happens while handling the event, propagate GDB's |
| 2662 | knowledge of the executing state to the frontend/user running |
| 2663 | state. */ |
| 2664 | old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); |
| 2665 | |
| 2666 | if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY |
| 2667 | || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN) |
| 2668 | ecs->ws.value.syscall_number = UNKNOWN_SYSCALL; |
| 2669 | |
| 2670 | /* Now figure out what to do with the result of the result. */ |
| 2671 | handle_inferior_event (ecs); |
| 2672 | |
| 2673 | /* No error, don't finish the state yet. */ |
| 2674 | discard_cleanups (old_chain); |
| 2675 | |
| 2676 | if (!ecs->wait_some_more) |
| 2677 | break; |
| 2678 | } |
| 2679 | |
| 2680 | do_cleanups (old_cleanups); |
| 2681 | } |
| 2682 | |
| 2683 | /* Asynchronous version of wait_for_inferior. It is called by the |
| 2684 | event loop whenever a change of state is detected on the file |
| 2685 | descriptor corresponding to the target. It can be called more than |
| 2686 | once to complete a single execution command. In such cases we need |
| 2687 | to keep the state in a global variable ECSS. If it is the last time |
| 2688 | that this function is called for a single execution command, then |
| 2689 | report to the user that the inferior has stopped, and do the |
| 2690 | necessary cleanups. */ |
| 2691 | |
| 2692 | void |
| 2693 | fetch_inferior_event (void *client_data) |
| 2694 | { |
| 2695 | struct execution_control_state ecss; |
| 2696 | struct execution_control_state *ecs = &ecss; |
| 2697 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
| 2698 | struct cleanup *ts_old_chain; |
| 2699 | int was_sync = sync_execution; |
| 2700 | |
| 2701 | memset (ecs, 0, sizeof (*ecs)); |
| 2702 | |
| 2703 | /* We'll update this if & when we switch to a new thread. */ |
| 2704 | previous_inferior_ptid = inferior_ptid; |
| 2705 | |
| 2706 | /* We're handling a live event, so make sure we're doing live |
| 2707 | debugging. If we're looking at traceframes while the target is |
| 2708 | running, we're going to need to get back to that mode after |
| 2709 | handling the event. */ |
| 2710 | if (non_stop) |
| 2711 | { |
| 2712 | make_cleanup_restore_current_traceframe (); |
| 2713 | set_current_traceframe (-1); |
| 2714 | } |
| 2715 | |
| 2716 | if (non_stop) |
| 2717 | /* In non-stop mode, the user/frontend should not notice a thread |
| 2718 | switch due to internal events. Make sure we reverse to the |
| 2719 | user selected thread and frame after handling the event and |
| 2720 | running any breakpoint commands. */ |
| 2721 | make_cleanup_restore_current_thread (); |
| 2722 | |
| 2723 | /* We have to invalidate the registers BEFORE calling target_wait |
| 2724 | because they can be loaded from the target while in target_wait. |
| 2725 | This makes remote debugging a bit more efficient for those |
| 2726 | targets that provide critical registers as part of their normal |
| 2727 | status mechanism. */ |
| 2728 | |
| 2729 | overlay_cache_invalid = 1; |
| 2730 | registers_changed (); |
| 2731 | |
| 2732 | if (deprecated_target_wait_hook) |
| 2733 | ecs->ptid = |
| 2734 | deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
| 2735 | else |
| 2736 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
| 2737 | |
| 2738 | if (debug_infrun) |
| 2739 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
| 2740 | |
| 2741 | if (non_stop |
| 2742 | && ecs->ws.kind != TARGET_WAITKIND_IGNORE |
| 2743 | && ecs->ws.kind != TARGET_WAITKIND_EXITED |
| 2744 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) |
| 2745 | /* In non-stop mode, each thread is handled individually. Switch |
| 2746 | early, so the global state is set correctly for this |
| 2747 | thread. */ |
| 2748 | context_switch (ecs->ptid); |
| 2749 | |
| 2750 | /* If an error happens while handling the event, propagate GDB's |
| 2751 | knowledge of the executing state to the frontend/user running |
| 2752 | state. */ |
| 2753 | if (!non_stop) |
| 2754 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); |
| 2755 | else |
| 2756 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid); |
| 2757 | |
| 2758 | /* Now figure out what to do with the result of the result. */ |
| 2759 | handle_inferior_event (ecs); |
| 2760 | |
| 2761 | if (!ecs->wait_some_more) |
| 2762 | { |
| 2763 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); |
| 2764 | |
| 2765 | delete_step_thread_step_resume_breakpoint (); |
| 2766 | |
| 2767 | /* We may not find an inferior if this was a process exit. */ |
| 2768 | if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY) |
| 2769 | normal_stop (); |
| 2770 | |
| 2771 | if (target_has_execution |
| 2772 | && ecs->ws.kind != TARGET_WAITKIND_EXITED |
| 2773 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED |
| 2774 | && ecs->event_thread->step_multi |
| 2775 | && ecs->event_thread->control.stop_step) |
| 2776 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); |
| 2777 | else |
| 2778 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); |
| 2779 | } |
| 2780 | |
| 2781 | /* No error, don't finish the thread states yet. */ |
| 2782 | discard_cleanups (ts_old_chain); |
| 2783 | |
| 2784 | /* Revert thread and frame. */ |
| 2785 | do_cleanups (old_chain); |
| 2786 | |
| 2787 | /* If the inferior was in sync execution mode, and now isn't, |
| 2788 | restore the prompt. */ |
| 2789 | if (was_sync && !sync_execution) |
| 2790 | display_gdb_prompt (0); |
| 2791 | } |
| 2792 | |
| 2793 | /* Record the frame and location we're currently stepping through. */ |
| 2794 | void |
| 2795 | set_step_info (struct frame_info *frame, struct symtab_and_line sal) |
| 2796 | { |
| 2797 | struct thread_info *tp = inferior_thread (); |
| 2798 | |
| 2799 | tp->control.step_frame_id = get_frame_id (frame); |
| 2800 | tp->control.step_stack_frame_id = get_stack_frame_id (frame); |
| 2801 | |
| 2802 | tp->current_symtab = sal.symtab; |
| 2803 | tp->current_line = sal.line; |
| 2804 | } |
| 2805 | |
| 2806 | /* Clear context switchable stepping state. */ |
| 2807 | |
| 2808 | void |
| 2809 | init_thread_stepping_state (struct thread_info *tss) |
| 2810 | { |
| 2811 | tss->stepping_over_breakpoint = 0; |
| 2812 | tss->step_after_step_resume_breakpoint = 0; |
| 2813 | tss->stepping_through_solib_after_catch = 0; |
| 2814 | tss->stepping_through_solib_catchpoints = NULL; |
| 2815 | } |
| 2816 | |
| 2817 | /* Return the cached copy of the last pid/waitstatus returned by |
| 2818 | target_wait()/deprecated_target_wait_hook(). The data is actually |
| 2819 | cached by handle_inferior_event(), which gets called immediately |
| 2820 | after target_wait()/deprecated_target_wait_hook(). */ |
| 2821 | |
| 2822 | void |
| 2823 | get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) |
| 2824 | { |
| 2825 | *ptidp = target_last_wait_ptid; |
| 2826 | *status = target_last_waitstatus; |
| 2827 | } |
| 2828 | |
| 2829 | void |
| 2830 | nullify_last_target_wait_ptid (void) |
| 2831 | { |
| 2832 | target_last_wait_ptid = minus_one_ptid; |
| 2833 | } |
| 2834 | |
| 2835 | /* Switch thread contexts. */ |
| 2836 | |
| 2837 | static void |
| 2838 | context_switch (ptid_t ptid) |
| 2839 | { |
| 2840 | if (debug_infrun) |
| 2841 | { |
| 2842 | fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", |
| 2843 | target_pid_to_str (inferior_ptid)); |
| 2844 | fprintf_unfiltered (gdb_stdlog, "to %s\n", |
| 2845 | target_pid_to_str (ptid)); |
| 2846 | } |
| 2847 | |
| 2848 | switch_to_thread (ptid); |
| 2849 | } |
| 2850 | |
| 2851 | static void |
| 2852 | adjust_pc_after_break (struct execution_control_state *ecs) |
| 2853 | { |
| 2854 | struct regcache *regcache; |
| 2855 | struct gdbarch *gdbarch; |
| 2856 | struct address_space *aspace; |
| 2857 | CORE_ADDR breakpoint_pc; |
| 2858 | |
| 2859 | /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If |
| 2860 | we aren't, just return. |
| 2861 | |
| 2862 | We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not |
| 2863 | affected by gdbarch_decr_pc_after_break. Other waitkinds which are |
| 2864 | implemented by software breakpoints should be handled through the normal |
| 2865 | breakpoint layer. |
| 2866 | |
| 2867 | NOTE drow/2004-01-31: On some targets, breakpoints may generate |
| 2868 | different signals (SIGILL or SIGEMT for instance), but it is less |
| 2869 | clear where the PC is pointing afterwards. It may not match |
| 2870 | gdbarch_decr_pc_after_break. I don't know any specific target that |
| 2871 | generates these signals at breakpoints (the code has been in GDB since at |
| 2872 | least 1992) so I can not guess how to handle them here. |
| 2873 | |
| 2874 | In earlier versions of GDB, a target with |
| 2875 | gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a |
| 2876 | watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any |
| 2877 | target with both of these set in GDB history, and it seems unlikely to be |
| 2878 | correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ |
| 2879 | |
| 2880 | if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) |
| 2881 | return; |
| 2882 | |
| 2883 | if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP) |
| 2884 | return; |
| 2885 | |
| 2886 | /* In reverse execution, when a breakpoint is hit, the instruction |
| 2887 | under it has already been de-executed. The reported PC always |
| 2888 | points at the breakpoint address, so adjusting it further would |
| 2889 | be wrong. E.g., consider this case on a decr_pc_after_break == 1 |
| 2890 | architecture: |
| 2891 | |
| 2892 | B1 0x08000000 : INSN1 |
| 2893 | B2 0x08000001 : INSN2 |
| 2894 | 0x08000002 : INSN3 |
| 2895 | PC -> 0x08000003 : INSN4 |
| 2896 | |
| 2897 | Say you're stopped at 0x08000003 as above. Reverse continuing |
| 2898 | from that point should hit B2 as below. Reading the PC when the |
| 2899 | SIGTRAP is reported should read 0x08000001 and INSN2 should have |
| 2900 | been de-executed already. |
| 2901 | |
| 2902 | B1 0x08000000 : INSN1 |
| 2903 | B2 PC -> 0x08000001 : INSN2 |
| 2904 | 0x08000002 : INSN3 |
| 2905 | 0x08000003 : INSN4 |
| 2906 | |
| 2907 | We can't apply the same logic as for forward execution, because |
| 2908 | we would wrongly adjust the PC to 0x08000000, since there's a |
| 2909 | breakpoint at PC - 1. We'd then report a hit on B1, although |
| 2910 | INSN1 hadn't been de-executed yet. Doing nothing is the correct |
| 2911 | behaviour. */ |
| 2912 | if (execution_direction == EXEC_REVERSE) |
| 2913 | return; |
| 2914 | |
| 2915 | /* If this target does not decrement the PC after breakpoints, then |
| 2916 | we have nothing to do. */ |
| 2917 | regcache = get_thread_regcache (ecs->ptid); |
| 2918 | gdbarch = get_regcache_arch (regcache); |
| 2919 | if (gdbarch_decr_pc_after_break (gdbarch) == 0) |
| 2920 | return; |
| 2921 | |
| 2922 | aspace = get_regcache_aspace (regcache); |
| 2923 | |
| 2924 | /* Find the location where (if we've hit a breakpoint) the |
| 2925 | breakpoint would be. */ |
| 2926 | breakpoint_pc = regcache_read_pc (regcache) |
| 2927 | - gdbarch_decr_pc_after_break (gdbarch); |
| 2928 | |
| 2929 | /* Check whether there actually is a software breakpoint inserted at |
| 2930 | that location. |
| 2931 | |
| 2932 | If in non-stop mode, a race condition is possible where we've |
| 2933 | removed a breakpoint, but stop events for that breakpoint were |
| 2934 | already queued and arrive later. To suppress those spurious |
| 2935 | SIGTRAPs, we keep a list of such breakpoint locations for a bit, |
| 2936 | and retire them after a number of stop events are reported. */ |
| 2937 | if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc) |
| 2938 | || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc))) |
| 2939 | { |
| 2940 | struct cleanup *old_cleanups = NULL; |
| 2941 | |
| 2942 | if (RECORD_IS_USED) |
| 2943 | old_cleanups = record_gdb_operation_disable_set (); |
| 2944 | |
| 2945 | /* When using hardware single-step, a SIGTRAP is reported for both |
| 2946 | a completed single-step and a software breakpoint. Need to |
| 2947 | differentiate between the two, as the latter needs adjusting |
| 2948 | but the former does not. |
| 2949 | |
| 2950 | The SIGTRAP can be due to a completed hardware single-step only if |
| 2951 | - we didn't insert software single-step breakpoints |
| 2952 | - the thread to be examined is still the current thread |
| 2953 | - this thread is currently being stepped |
| 2954 | |
| 2955 | If any of these events did not occur, we must have stopped due |
| 2956 | to hitting a software breakpoint, and have to back up to the |
| 2957 | breakpoint address. |
| 2958 | |
| 2959 | As a special case, we could have hardware single-stepped a |
| 2960 | software breakpoint. In this case (prev_pc == breakpoint_pc), |
| 2961 | we also need to back up to the breakpoint address. */ |
| 2962 | |
| 2963 | if (singlestep_breakpoints_inserted_p |
| 2964 | || !ptid_equal (ecs->ptid, inferior_ptid) |
| 2965 | || !currently_stepping (ecs->event_thread) |
| 2966 | || ecs->event_thread->prev_pc == breakpoint_pc) |
| 2967 | regcache_write_pc (regcache, breakpoint_pc); |
| 2968 | |
| 2969 | if (RECORD_IS_USED) |
| 2970 | do_cleanups (old_cleanups); |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | void |
| 2975 | init_infwait_state (void) |
| 2976 | { |
| 2977 | waiton_ptid = pid_to_ptid (-1); |
| 2978 | infwait_state = infwait_normal_state; |
| 2979 | } |
| 2980 | |
| 2981 | void |
| 2982 | error_is_running (void) |
| 2983 | { |
| 2984 | error (_("Cannot execute this command while " |
| 2985 | "the selected thread is running.")); |
| 2986 | } |
| 2987 | |
| 2988 | void |
| 2989 | ensure_not_running (void) |
| 2990 | { |
| 2991 | if (is_running (inferior_ptid)) |
| 2992 | error_is_running (); |
| 2993 | } |
| 2994 | |
| 2995 | static int |
| 2996 | stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id) |
| 2997 | { |
| 2998 | for (frame = get_prev_frame (frame); |
| 2999 | frame != NULL; |
| 3000 | frame = get_prev_frame (frame)) |
| 3001 | { |
| 3002 | if (frame_id_eq (get_frame_id (frame), step_frame_id)) |
| 3003 | return 1; |
| 3004 | if (get_frame_type (frame) != INLINE_FRAME) |
| 3005 | break; |
| 3006 | } |
| 3007 | |
| 3008 | return 0; |
| 3009 | } |
| 3010 | |
| 3011 | /* Auxiliary function that handles syscall entry/return events. |
| 3012 | It returns 1 if the inferior should keep going (and GDB |
| 3013 | should ignore the event), or 0 if the event deserves to be |
| 3014 | processed. */ |
| 3015 | |
| 3016 | static int |
| 3017 | handle_syscall_event (struct execution_control_state *ecs) |
| 3018 | { |
| 3019 | struct regcache *regcache; |
| 3020 | struct gdbarch *gdbarch; |
| 3021 | int syscall_number; |
| 3022 | |
| 3023 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
| 3024 | context_switch (ecs->ptid); |
| 3025 | |
| 3026 | regcache = get_thread_regcache (ecs->ptid); |
| 3027 | gdbarch = get_regcache_arch (regcache); |
| 3028 | syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid); |
| 3029 | stop_pc = regcache_read_pc (regcache); |
| 3030 | |
| 3031 | target_last_waitstatus.value.syscall_number = syscall_number; |
| 3032 | |
| 3033 | if (catch_syscall_enabled () > 0 |
| 3034 | && catching_syscall_number (syscall_number) > 0) |
| 3035 | { |
| 3036 | if (debug_infrun) |
| 3037 | fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n", |
| 3038 | syscall_number); |
| 3039 | |
| 3040 | ecs->event_thread->control.stop_bpstat |
| 3041 | = bpstat_stop_status (get_regcache_aspace (regcache), |
| 3042 | stop_pc, ecs->ptid); |
| 3043 | ecs->random_signal |
| 3044 | = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat); |
| 3045 | |
| 3046 | if (!ecs->random_signal) |
| 3047 | { |
| 3048 | /* Catchpoint hit. */ |
| 3049 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
| 3050 | return 0; |
| 3051 | } |
| 3052 | } |
| 3053 | |
| 3054 | /* If no catchpoint triggered for this, then keep going. */ |
| 3055 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 3056 | keep_going (ecs); |
| 3057 | return 1; |
| 3058 | } |
| 3059 | |
| 3060 | /* Given an execution control state that has been freshly filled in |
| 3061 | by an event from the inferior, figure out what it means and take |
| 3062 | appropriate action. */ |
| 3063 | |
| 3064 | static void |
| 3065 | handle_inferior_event (struct execution_control_state *ecs) |
| 3066 | { |
| 3067 | struct frame_info *frame; |
| 3068 | struct gdbarch *gdbarch; |
| 3069 | int sw_single_step_trap_p = 0; |
| 3070 | int stopped_by_watchpoint; |
| 3071 | int stepped_after_stopped_by_watchpoint = 0; |
| 3072 | struct symtab_and_line stop_pc_sal; |
| 3073 | enum stop_kind stop_soon; |
| 3074 | |
| 3075 | if (ecs->ws.kind == TARGET_WAITKIND_IGNORE) |
| 3076 | { |
| 3077 | /* We had an event in the inferior, but we are not interested in |
| 3078 | handling it at this level. The lower layers have already |
| 3079 | done what needs to be done, if anything. |
| 3080 | |
| 3081 | One of the possible circumstances for this is when the |
| 3082 | inferior produces output for the console. The inferior has |
| 3083 | not stopped, and we are ignoring the event. Another possible |
| 3084 | circumstance is any event which the lower level knows will be |
| 3085 | reported multiple times without an intervening resume. */ |
| 3086 | if (debug_infrun) |
| 3087 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); |
| 3088 | prepare_to_wait (ecs); |
| 3089 | return; |
| 3090 | } |
| 3091 | |
| 3092 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
| 3093 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) |
| 3094 | { |
| 3095 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); |
| 3096 | |
| 3097 | gdb_assert (inf); |
| 3098 | stop_soon = inf->control.stop_soon; |
| 3099 | } |
| 3100 | else |
| 3101 | stop_soon = NO_STOP_QUIETLY; |
| 3102 | |
| 3103 | /* Cache the last pid/waitstatus. */ |
| 3104 | target_last_wait_ptid = ecs->ptid; |
| 3105 | target_last_waitstatus = ecs->ws; |
| 3106 | |
| 3107 | /* Always clear state belonging to the previous time we stopped. */ |
| 3108 | stop_stack_dummy = STOP_NONE; |
| 3109 | |
| 3110 | /* If it's a new process, add it to the thread database. */ |
| 3111 | |
| 3112 | ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) |
| 3113 | && !ptid_equal (ecs->ptid, minus_one_ptid) |
| 3114 | && !in_thread_list (ecs->ptid)); |
| 3115 | |
| 3116 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
| 3117 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) |
| 3118 | add_thread (ecs->ptid); |
| 3119 | |
| 3120 | ecs->event_thread = find_thread_ptid (ecs->ptid); |
| 3121 | |
| 3122 | /* Dependent on valid ECS->EVENT_THREAD. */ |
| 3123 | adjust_pc_after_break (ecs); |
| 3124 | |
| 3125 | /* Dependent on the current PC value modified by adjust_pc_after_break. */ |
| 3126 | reinit_frame_cache (); |
| 3127 | |
| 3128 | breakpoint_retire_moribund (); |
| 3129 | |
| 3130 | /* First, distinguish signals caused by the debugger from signals |
| 3131 | that have to do with the program's own actions. Note that |
| 3132 | breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending |
| 3133 | on the operating system version. Here we detect when a SIGILL or |
| 3134 | SIGEMT is really a breakpoint and change it to SIGTRAP. We do |
| 3135 | something similar for SIGSEGV, since a SIGSEGV will be generated |
| 3136 | when we're trying to execute a breakpoint instruction on a |
| 3137 | non-executable stack. This happens for call dummy breakpoints |
| 3138 | for architectures like SPARC that place call dummies on the |
| 3139 | stack. */ |
| 3140 | if (ecs->ws.kind == TARGET_WAITKIND_STOPPED |
| 3141 | && (ecs->ws.value.sig == TARGET_SIGNAL_ILL |
| 3142 | || ecs->ws.value.sig == TARGET_SIGNAL_SEGV |
| 3143 | || ecs->ws.value.sig == TARGET_SIGNAL_EMT)) |
| 3144 | { |
| 3145 | struct regcache *regcache = get_thread_regcache (ecs->ptid); |
| 3146 | |
| 3147 | if (breakpoint_inserted_here_p (get_regcache_aspace (regcache), |
| 3148 | regcache_read_pc (regcache))) |
| 3149 | { |
| 3150 | if (debug_infrun) |
| 3151 | fprintf_unfiltered (gdb_stdlog, |
| 3152 | "infrun: Treating signal as SIGTRAP\n"); |
| 3153 | ecs->ws.value.sig = TARGET_SIGNAL_TRAP; |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | /* Mark the non-executing threads accordingly. In all-stop, all |
| 3158 | threads of all processes are stopped when we get any event |
| 3159 | reported. In non-stop mode, only the event thread stops. If |
| 3160 | we're handling a process exit in non-stop mode, there's nothing |
| 3161 | to do, as threads of the dead process are gone, and threads of |
| 3162 | any other process were left running. */ |
| 3163 | if (!non_stop) |
| 3164 | set_executing (minus_one_ptid, 0); |
| 3165 | else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED |
| 3166 | && ecs->ws.kind != TARGET_WAITKIND_EXITED) |
| 3167 | set_executing (inferior_ptid, 0); |
| 3168 | |
| 3169 | switch (infwait_state) |
| 3170 | { |
| 3171 | case infwait_thread_hop_state: |
| 3172 | if (debug_infrun) |
| 3173 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n"); |
| 3174 | break; |
| 3175 | |
| 3176 | case infwait_normal_state: |
| 3177 | if (debug_infrun) |
| 3178 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n"); |
| 3179 | break; |
| 3180 | |
| 3181 | case infwait_step_watch_state: |
| 3182 | if (debug_infrun) |
| 3183 | fprintf_unfiltered (gdb_stdlog, |
| 3184 | "infrun: infwait_step_watch_state\n"); |
| 3185 | |
| 3186 | stepped_after_stopped_by_watchpoint = 1; |
| 3187 | break; |
| 3188 | |
| 3189 | case infwait_nonstep_watch_state: |
| 3190 | if (debug_infrun) |
| 3191 | fprintf_unfiltered (gdb_stdlog, |
| 3192 | "infrun: infwait_nonstep_watch_state\n"); |
| 3193 | insert_breakpoints (); |
| 3194 | |
| 3195 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
| 3196 | handle things like signals arriving and other things happening |
| 3197 | in combination correctly? */ |
| 3198 | stepped_after_stopped_by_watchpoint = 1; |
| 3199 | break; |
| 3200 | |
| 3201 | default: |
| 3202 | internal_error (__FILE__, __LINE__, _("bad switch")); |
| 3203 | } |
| 3204 | |
| 3205 | infwait_state = infwait_normal_state; |
| 3206 | waiton_ptid = pid_to_ptid (-1); |
| 3207 | |
| 3208 | switch (ecs->ws.kind) |
| 3209 | { |
| 3210 | case TARGET_WAITKIND_LOADED: |
| 3211 | if (debug_infrun) |
| 3212 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); |
| 3213 | /* Ignore gracefully during startup of the inferior, as it might |
| 3214 | be the shell which has just loaded some objects, otherwise |
| 3215 | add the symbols for the newly loaded objects. Also ignore at |
| 3216 | the beginning of an attach or remote session; we will query |
| 3217 | the full list of libraries once the connection is |
| 3218 | established. */ |
| 3219 | if (stop_soon == NO_STOP_QUIETLY) |
| 3220 | { |
| 3221 | /* Check for any newly added shared libraries if we're |
| 3222 | supposed to be adding them automatically. Switch |
| 3223 | terminal for any messages produced by |
| 3224 | breakpoint_re_set. */ |
| 3225 | target_terminal_ours_for_output (); |
| 3226 | /* NOTE: cagney/2003-11-25: Make certain that the target |
| 3227 | stack's section table is kept up-to-date. Architectures, |
| 3228 | (e.g., PPC64), use the section table to perform |
| 3229 | operations such as address => section name and hence |
| 3230 | require the table to contain all sections (including |
| 3231 | those found in shared libraries). */ |
| 3232 | #ifdef SOLIB_ADD |
| 3233 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
| 3234 | #else |
| 3235 | solib_add (NULL, 0, ¤t_target, auto_solib_add); |
| 3236 | #endif |
| 3237 | target_terminal_inferior (); |
| 3238 | |
| 3239 | /* If requested, stop when the dynamic linker notifies |
| 3240 | gdb of events. This allows the user to get control |
| 3241 | and place breakpoints in initializer routines for |
| 3242 | dynamically loaded objects (among other things). */ |
| 3243 | if (stop_on_solib_events) |
| 3244 | { |
| 3245 | /* Make sure we print "Stopped due to solib-event" in |
| 3246 | normal_stop. */ |
| 3247 | stop_print_frame = 1; |
| 3248 | |
| 3249 | stop_stepping (ecs); |
| 3250 | return; |
| 3251 | } |
| 3252 | |
| 3253 | /* NOTE drow/2007-05-11: This might be a good place to check |
| 3254 | for "catch load". */ |
| 3255 | } |
| 3256 | |
| 3257 | /* If we are skipping through a shell, or through shared library |
| 3258 | loading that we aren't interested in, resume the program. If |
| 3259 | we're running the program normally, also resume. But stop if |
| 3260 | we're attaching or setting up a remote connection. */ |
| 3261 | if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) |
| 3262 | { |
| 3263 | /* Loading of shared libraries might have changed breakpoint |
| 3264 | addresses. Make sure new breakpoints are inserted. */ |
| 3265 | if (stop_soon == NO_STOP_QUIETLY |
| 3266 | && !breakpoints_always_inserted_mode ()) |
| 3267 | insert_breakpoints (); |
| 3268 | resume (0, TARGET_SIGNAL_0); |
| 3269 | prepare_to_wait (ecs); |
| 3270 | return; |
| 3271 | } |
| 3272 | |
| 3273 | break; |
| 3274 | |
| 3275 | case TARGET_WAITKIND_SPURIOUS: |
| 3276 | if (debug_infrun) |
| 3277 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); |
| 3278 | resume (0, TARGET_SIGNAL_0); |
| 3279 | prepare_to_wait (ecs); |
| 3280 | return; |
| 3281 | |
| 3282 | case TARGET_WAITKIND_EXITED: |
| 3283 | if (debug_infrun) |
| 3284 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n"); |
| 3285 | inferior_ptid = ecs->ptid; |
| 3286 | set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid))); |
| 3287 | set_current_program_space (current_inferior ()->pspace); |
| 3288 | handle_vfork_child_exec_or_exit (0); |
| 3289 | target_terminal_ours (); /* Must do this before mourn anyway. */ |
| 3290 | print_exited_reason (ecs->ws.value.integer); |
| 3291 | |
| 3292 | /* Record the exit code in the convenience variable $_exitcode, so |
| 3293 | that the user can inspect this again later. */ |
| 3294 | set_internalvar_integer (lookup_internalvar ("_exitcode"), |
| 3295 | (LONGEST) ecs->ws.value.integer); |
| 3296 | gdb_flush (gdb_stdout); |
| 3297 | target_mourn_inferior (); |
| 3298 | singlestep_breakpoints_inserted_p = 0; |
| 3299 | cancel_single_step_breakpoints (); |
| 3300 | stop_print_frame = 0; |
| 3301 | stop_stepping (ecs); |
| 3302 | return; |
| 3303 | |
| 3304 | case TARGET_WAITKIND_SIGNALLED: |
| 3305 | if (debug_infrun) |
| 3306 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n"); |
| 3307 | inferior_ptid = ecs->ptid; |
| 3308 | set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid))); |
| 3309 | set_current_program_space (current_inferior ()->pspace); |
| 3310 | handle_vfork_child_exec_or_exit (0); |
| 3311 | stop_print_frame = 0; |
| 3312 | target_terminal_ours (); /* Must do this before mourn anyway. */ |
| 3313 | |
| 3314 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
| 3315 | reach here unless the inferior is dead. However, for years |
| 3316 | target_kill() was called here, which hints that fatal signals aren't |
| 3317 | really fatal on some systems. If that's true, then some changes |
| 3318 | may be needed. */ |
| 3319 | target_mourn_inferior (); |
| 3320 | |
| 3321 | print_signal_exited_reason (ecs->ws.value.sig); |
| 3322 | singlestep_breakpoints_inserted_p = 0; |
| 3323 | cancel_single_step_breakpoints (); |
| 3324 | stop_stepping (ecs); |
| 3325 | return; |
| 3326 | |
| 3327 | /* The following are the only cases in which we keep going; |
| 3328 | the above cases end in a continue or goto. */ |
| 3329 | case TARGET_WAITKIND_FORKED: |
| 3330 | case TARGET_WAITKIND_VFORKED: |
| 3331 | if (debug_infrun) |
| 3332 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); |
| 3333 | |
| 3334 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
| 3335 | { |
| 3336 | context_switch (ecs->ptid); |
| 3337 | reinit_frame_cache (); |
| 3338 | } |
| 3339 | |
| 3340 | /* Immediately detach breakpoints from the child before there's |
| 3341 | any chance of letting the user delete breakpoints from the |
| 3342 | breakpoint lists. If we don't do this early, it's easy to |
| 3343 | leave left over traps in the child, vis: "break foo; catch |
| 3344 | fork; c; <fork>; del; c; <child calls foo>". We only follow |
| 3345 | the fork on the last `continue', and by that time the |
| 3346 | breakpoint at "foo" is long gone from the breakpoint table. |
| 3347 | If we vforked, then we don't need to unpatch here, since both |
| 3348 | parent and child are sharing the same memory pages; we'll |
| 3349 | need to unpatch at follow/detach time instead to be certain |
| 3350 | that new breakpoints added between catchpoint hit time and |
| 3351 | vfork follow are detached. */ |
| 3352 | if (ecs->ws.kind != TARGET_WAITKIND_VFORKED) |
| 3353 | { |
| 3354 | int child_pid = ptid_get_pid (ecs->ws.value.related_pid); |
| 3355 | |
| 3356 | /* This won't actually modify the breakpoint list, but will |
| 3357 | physically remove the breakpoints from the child. */ |
| 3358 | detach_breakpoints (child_pid); |
| 3359 | } |
| 3360 | |
| 3361 | if (singlestep_breakpoints_inserted_p) |
| 3362 | { |
| 3363 | /* Pull the single step breakpoints out of the target. */ |
| 3364 | remove_single_step_breakpoints (); |
| 3365 | singlestep_breakpoints_inserted_p = 0; |
| 3366 | } |
| 3367 | |
| 3368 | /* In case the event is caught by a catchpoint, remember that |
| 3369 | the event is to be followed at the next resume of the thread, |
| 3370 | and not immediately. */ |
| 3371 | ecs->event_thread->pending_follow = ecs->ws; |
| 3372 | |
| 3373 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
| 3374 | |
| 3375 | ecs->event_thread->control.stop_bpstat |
| 3376 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
| 3377 | stop_pc, ecs->ptid); |
| 3378 | |
| 3379 | /* Note that we're interested in knowing the bpstat actually |
| 3380 | causes a stop, not just if it may explain the signal. |
| 3381 | Software watchpoints, for example, always appear in the |
| 3382 | bpstat. */ |
| 3383 | ecs->random_signal |
| 3384 | = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat); |
| 3385 | |
| 3386 | /* If no catchpoint triggered for this, then keep going. */ |
| 3387 | if (ecs->random_signal) |
| 3388 | { |
| 3389 | ptid_t parent; |
| 3390 | ptid_t child; |
| 3391 | int should_resume; |
| 3392 | int follow_child |
| 3393 | = (follow_fork_mode_string == follow_fork_mode_child); |
| 3394 | |
| 3395 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 3396 | |
| 3397 | should_resume = follow_fork (); |
| 3398 | |
| 3399 | parent = ecs->ptid; |
| 3400 | child = ecs->ws.value.related_pid; |
| 3401 | |
| 3402 | /* In non-stop mode, also resume the other branch. */ |
| 3403 | if (non_stop && !detach_fork) |
| 3404 | { |
| 3405 | if (follow_child) |
| 3406 | switch_to_thread (parent); |
| 3407 | else |
| 3408 | switch_to_thread (child); |
| 3409 | |
| 3410 | ecs->event_thread = inferior_thread (); |
| 3411 | ecs->ptid = inferior_ptid; |
| 3412 | keep_going (ecs); |
| 3413 | } |
| 3414 | |
| 3415 | if (follow_child) |
| 3416 | switch_to_thread (child); |
| 3417 | else |
| 3418 | switch_to_thread (parent); |
| 3419 | |
| 3420 | ecs->event_thread = inferior_thread (); |
| 3421 | ecs->ptid = inferior_ptid; |
| 3422 | |
| 3423 | if (should_resume) |
| 3424 | keep_going (ecs); |
| 3425 | else |
| 3426 | stop_stepping (ecs); |
| 3427 | return; |
| 3428 | } |
| 3429 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
| 3430 | goto process_event_stop_test; |
| 3431 | |
| 3432 | case TARGET_WAITKIND_VFORK_DONE: |
| 3433 | /* Done with the shared memory region. Re-insert breakpoints in |
| 3434 | the parent, and keep going. */ |
| 3435 | |
| 3436 | if (debug_infrun) |
| 3437 | fprintf_unfiltered (gdb_stdlog, |
| 3438 | "infrun: TARGET_WAITKIND_VFORK_DONE\n"); |
| 3439 | |
| 3440 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
| 3441 | context_switch (ecs->ptid); |
| 3442 | |
| 3443 | current_inferior ()->waiting_for_vfork_done = 0; |
| 3444 | current_inferior ()->pspace->breakpoints_not_allowed = 0; |
| 3445 | /* This also takes care of reinserting breakpoints in the |
| 3446 | previously locked inferior. */ |
| 3447 | keep_going (ecs); |
| 3448 | return; |
| 3449 | |
| 3450 | case TARGET_WAITKIND_EXECD: |
| 3451 | if (debug_infrun) |
| 3452 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); |
| 3453 | |
| 3454 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
| 3455 | { |
| 3456 | context_switch (ecs->ptid); |
| 3457 | reinit_frame_cache (); |
| 3458 | } |
| 3459 | |
| 3460 | singlestep_breakpoints_inserted_p = 0; |
| 3461 | cancel_single_step_breakpoints (); |
| 3462 | |
| 3463 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
| 3464 | |
| 3465 | /* Do whatever is necessary to the parent branch of the vfork. */ |
| 3466 | handle_vfork_child_exec_or_exit (1); |
| 3467 | |
| 3468 | /* This causes the eventpoints and symbol table to be reset. |
| 3469 | Must do this now, before trying to determine whether to |
| 3470 | stop. */ |
| 3471 | follow_exec (inferior_ptid, ecs->ws.value.execd_pathname); |
| 3472 | |
| 3473 | ecs->event_thread->control.stop_bpstat |
| 3474 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
| 3475 | stop_pc, ecs->ptid); |
| 3476 | ecs->random_signal |
| 3477 | = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat); |
| 3478 | |
| 3479 | /* Note that this may be referenced from inside |
| 3480 | bpstat_stop_status above, through inferior_has_execd. */ |
| 3481 | xfree (ecs->ws.value.execd_pathname); |
| 3482 | ecs->ws.value.execd_pathname = NULL; |
| 3483 | |
| 3484 | /* If no catchpoint triggered for this, then keep going. */ |
| 3485 | if (ecs->random_signal) |
| 3486 | { |
| 3487 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 3488 | keep_going (ecs); |
| 3489 | return; |
| 3490 | } |
| 3491 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
| 3492 | goto process_event_stop_test; |
| 3493 | |
| 3494 | /* Be careful not to try to gather much state about a thread |
| 3495 | that's in a syscall. It's frequently a losing proposition. */ |
| 3496 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
| 3497 | if (debug_infrun) |
| 3498 | fprintf_unfiltered (gdb_stdlog, |
| 3499 | "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); |
| 3500 | /* Getting the current syscall number. */ |
| 3501 | if (handle_syscall_event (ecs) != 0) |
| 3502 | return; |
| 3503 | goto process_event_stop_test; |
| 3504 | |
| 3505 | /* Before examining the threads further, step this thread to |
| 3506 | get it entirely out of the syscall. (We get notice of the |
| 3507 | event when the thread is just on the verge of exiting a |
| 3508 | syscall. Stepping one instruction seems to get it back |
| 3509 | into user code.) */ |
| 3510 | case TARGET_WAITKIND_SYSCALL_RETURN: |
| 3511 | if (debug_infrun) |
| 3512 | fprintf_unfiltered (gdb_stdlog, |
| 3513 | "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); |
| 3514 | if (handle_syscall_event (ecs) != 0) |
| 3515 | return; |
| 3516 | goto process_event_stop_test; |
| 3517 | |
| 3518 | case TARGET_WAITKIND_STOPPED: |
| 3519 | if (debug_infrun) |
| 3520 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); |
| 3521 | ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig; |
| 3522 | break; |
| 3523 | |
| 3524 | case TARGET_WAITKIND_NO_HISTORY: |
| 3525 | /* Reverse execution: target ran out of history info. */ |
| 3526 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
| 3527 | print_no_history_reason (); |
| 3528 | stop_stepping (ecs); |
| 3529 | return; |
| 3530 | } |
| 3531 | |
| 3532 | if (ecs->new_thread_event) |
| 3533 | { |
| 3534 | if (non_stop) |
| 3535 | /* Non-stop assumes that the target handles adding new threads |
| 3536 | to the thread list. */ |
| 3537 | internal_error (__FILE__, __LINE__, |
| 3538 | "targets should add new threads to the thread " |
| 3539 | "list themselves in non-stop mode."); |
| 3540 | |
| 3541 | /* We may want to consider not doing a resume here in order to |
| 3542 | give the user a chance to play with the new thread. It might |
| 3543 | be good to make that a user-settable option. */ |
| 3544 | |
| 3545 | /* At this point, all threads are stopped (happens automatically |
| 3546 | in either the OS or the native code). Therefore we need to |
| 3547 | continue all threads in order to make progress. */ |
| 3548 | |
| 3549 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
| 3550 | context_switch (ecs->ptid); |
| 3551 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); |
| 3552 | prepare_to_wait (ecs); |
| 3553 | return; |
| 3554 | } |
| 3555 | |
| 3556 | if (ecs->ws.kind == TARGET_WAITKIND_STOPPED) |
| 3557 | { |
| 3558 | /* Do we need to clean up the state of a thread that has |
| 3559 | completed a displaced single-step? (Doing so usually affects |
| 3560 | the PC, so do it here, before we set stop_pc.) */ |
| 3561 | displaced_step_fixup (ecs->ptid, |
| 3562 | ecs->event_thread->suspend.stop_signal); |
| 3563 | |
| 3564 | /* If we either finished a single-step or hit a breakpoint, but |
| 3565 | the user wanted this thread to be stopped, pretend we got a |
| 3566 | SIG0 (generic unsignaled stop). */ |
| 3567 | |
| 3568 | if (ecs->event_thread->stop_requested |
| 3569 | && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
| 3570 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 3571 | } |
| 3572 | |
| 3573 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
| 3574 | |
| 3575 | if (debug_infrun) |
| 3576 | { |
| 3577 | struct regcache *regcache = get_thread_regcache (ecs->ptid); |
| 3578 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 3579 | struct cleanup *old_chain = save_inferior_ptid (); |
| 3580 | |
| 3581 | inferior_ptid = ecs->ptid; |
| 3582 | |
| 3583 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n", |
| 3584 | paddress (gdbarch, stop_pc)); |
| 3585 | if (target_stopped_by_watchpoint ()) |
| 3586 | { |
| 3587 | CORE_ADDR addr; |
| 3588 | |
| 3589 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n"); |
| 3590 | |
| 3591 | if (target_stopped_data_address (¤t_target, &addr)) |
| 3592 | fprintf_unfiltered (gdb_stdlog, |
| 3593 | "infrun: stopped data address = %s\n", |
| 3594 | paddress (gdbarch, addr)); |
| 3595 | else |
| 3596 | fprintf_unfiltered (gdb_stdlog, |
| 3597 | "infrun: (no data address available)\n"); |
| 3598 | } |
| 3599 | |
| 3600 | do_cleanups (old_chain); |
| 3601 | } |
| 3602 | |
| 3603 | if (stepping_past_singlestep_breakpoint) |
| 3604 | { |
| 3605 | gdb_assert (singlestep_breakpoints_inserted_p); |
| 3606 | gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); |
| 3607 | gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); |
| 3608 | |
| 3609 | stepping_past_singlestep_breakpoint = 0; |
| 3610 | |
| 3611 | /* We've either finished single-stepping past the single-step |
| 3612 | breakpoint, or stopped for some other reason. It would be nice if |
| 3613 | we could tell, but we can't reliably. */ |
| 3614 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
| 3615 | { |
| 3616 | if (debug_infrun) |
| 3617 | fprintf_unfiltered (gdb_stdlog, |
| 3618 | "infrun: stepping_past_" |
| 3619 | "singlestep_breakpoint\n"); |
| 3620 | /* Pull the single step breakpoints out of the target. */ |
| 3621 | remove_single_step_breakpoints (); |
| 3622 | singlestep_breakpoints_inserted_p = 0; |
| 3623 | |
| 3624 | ecs->random_signal = 0; |
| 3625 | ecs->event_thread->control.trap_expected = 0; |
| 3626 | |
| 3627 | context_switch (saved_singlestep_ptid); |
| 3628 | if (deprecated_context_hook) |
| 3629 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); |
| 3630 | |
| 3631 | resume (1, TARGET_SIGNAL_0); |
| 3632 | prepare_to_wait (ecs); |
| 3633 | return; |
| 3634 | } |
| 3635 | } |
| 3636 | |
| 3637 | if (!ptid_equal (deferred_step_ptid, null_ptid)) |
| 3638 | { |
| 3639 | /* In non-stop mode, there's never a deferred_step_ptid set. */ |
| 3640 | gdb_assert (!non_stop); |
| 3641 | |
| 3642 | /* If we stopped for some other reason than single-stepping, ignore |
| 3643 | the fact that we were supposed to switch back. */ |
| 3644 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
| 3645 | { |
| 3646 | if (debug_infrun) |
| 3647 | fprintf_unfiltered (gdb_stdlog, |
| 3648 | "infrun: handling deferred step\n"); |
| 3649 | |
| 3650 | /* Pull the single step breakpoints out of the target. */ |
| 3651 | if (singlestep_breakpoints_inserted_p) |
| 3652 | { |
| 3653 | remove_single_step_breakpoints (); |
| 3654 | singlestep_breakpoints_inserted_p = 0; |
| 3655 | } |
| 3656 | |
| 3657 | ecs->event_thread->control.trap_expected = 0; |
| 3658 | |
| 3659 | /* Note: We do not call context_switch at this point, as the |
| 3660 | context is already set up for stepping the original thread. */ |
| 3661 | switch_to_thread (deferred_step_ptid); |
| 3662 | deferred_step_ptid = null_ptid; |
| 3663 | /* Suppress spurious "Switching to ..." message. */ |
| 3664 | previous_inferior_ptid = inferior_ptid; |
| 3665 | |
| 3666 | resume (1, TARGET_SIGNAL_0); |
| 3667 | prepare_to_wait (ecs); |
| 3668 | return; |
| 3669 | } |
| 3670 | |
| 3671 | deferred_step_ptid = null_ptid; |
| 3672 | } |
| 3673 | |
| 3674 | /* See if a thread hit a thread-specific breakpoint that was meant for |
| 3675 | another thread. If so, then step that thread past the breakpoint, |
| 3676 | and continue it. */ |
| 3677 | |
| 3678 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
| 3679 | { |
| 3680 | int thread_hop_needed = 0; |
| 3681 | struct address_space *aspace = |
| 3682 | get_regcache_aspace (get_thread_regcache (ecs->ptid)); |
| 3683 | |
| 3684 | /* Check if a regular breakpoint has been hit before checking |
| 3685 | for a potential single step breakpoint. Otherwise, GDB will |
| 3686 | not see this breakpoint hit when stepping onto breakpoints. */ |
| 3687 | if (regular_breakpoint_inserted_here_p (aspace, stop_pc)) |
| 3688 | { |
| 3689 | ecs->random_signal = 0; |
| 3690 | if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid)) |
| 3691 | thread_hop_needed = 1; |
| 3692 | } |
| 3693 | else if (singlestep_breakpoints_inserted_p) |
| 3694 | { |
| 3695 | /* We have not context switched yet, so this should be true |
| 3696 | no matter which thread hit the singlestep breakpoint. */ |
| 3697 | gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid)); |
| 3698 | if (debug_infrun) |
| 3699 | fprintf_unfiltered (gdb_stdlog, "infrun: software single step " |
| 3700 | "trap for %s\n", |
| 3701 | target_pid_to_str (ecs->ptid)); |
| 3702 | |
| 3703 | ecs->random_signal = 0; |
| 3704 | /* The call to in_thread_list is necessary because PTIDs sometimes |
| 3705 | change when we go from single-threaded to multi-threaded. If |
| 3706 | the singlestep_ptid is still in the list, assume that it is |
| 3707 | really different from ecs->ptid. */ |
| 3708 | if (!ptid_equal (singlestep_ptid, ecs->ptid) |
| 3709 | && in_thread_list (singlestep_ptid)) |
| 3710 | { |
| 3711 | /* If the PC of the thread we were trying to single-step |
| 3712 | has changed, discard this event (which we were going |
| 3713 | to ignore anyway), and pretend we saw that thread |
| 3714 | trap. This prevents us continuously moving the |
| 3715 | single-step breakpoint forward, one instruction at a |
| 3716 | time. If the PC has changed, then the thread we were |
| 3717 | trying to single-step has trapped or been signalled, |
| 3718 | but the event has not been reported to GDB yet. |
| 3719 | |
| 3720 | There might be some cases where this loses signal |
| 3721 | information, if a signal has arrived at exactly the |
| 3722 | same time that the PC changed, but this is the best |
| 3723 | we can do with the information available. Perhaps we |
| 3724 | should arrange to report all events for all threads |
| 3725 | when they stop, or to re-poll the remote looking for |
| 3726 | this particular thread (i.e. temporarily enable |
| 3727 | schedlock). */ |
| 3728 | |
| 3729 | CORE_ADDR new_singlestep_pc |
| 3730 | = regcache_read_pc (get_thread_regcache (singlestep_ptid)); |
| 3731 | |
| 3732 | if (new_singlestep_pc != singlestep_pc) |
| 3733 | { |
| 3734 | enum target_signal stop_signal; |
| 3735 | |
| 3736 | if (debug_infrun) |
| 3737 | fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread," |
| 3738 | " but expected thread advanced also\n"); |
| 3739 | |
| 3740 | /* The current context still belongs to |
| 3741 | singlestep_ptid. Don't swap here, since that's |
| 3742 | the context we want to use. Just fudge our |
| 3743 | state and continue. */ |
| 3744 | stop_signal = ecs->event_thread->suspend.stop_signal; |
| 3745 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 3746 | ecs->ptid = singlestep_ptid; |
| 3747 | ecs->event_thread = find_thread_ptid (ecs->ptid); |
| 3748 | ecs->event_thread->suspend.stop_signal = stop_signal; |
| 3749 | stop_pc = new_singlestep_pc; |
| 3750 | } |
| 3751 | else |
| 3752 | { |
| 3753 | if (debug_infrun) |
| 3754 | fprintf_unfiltered (gdb_stdlog, |
| 3755 | "infrun: unexpected thread\n"); |
| 3756 | |
| 3757 | thread_hop_needed = 1; |
| 3758 | stepping_past_singlestep_breakpoint = 1; |
| 3759 | saved_singlestep_ptid = singlestep_ptid; |
| 3760 | } |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | if (thread_hop_needed) |
| 3765 | { |
| 3766 | struct regcache *thread_regcache; |
| 3767 | int remove_status = 0; |
| 3768 | |
| 3769 | if (debug_infrun) |
| 3770 | fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n"); |
| 3771 | |
| 3772 | /* Switch context before touching inferior memory, the |
| 3773 | previous thread may have exited. */ |
| 3774 | if (!ptid_equal (inferior_ptid, ecs->ptid)) |
| 3775 | context_switch (ecs->ptid); |
| 3776 | |
| 3777 | /* Saw a breakpoint, but it was hit by the wrong thread. |
| 3778 | Just continue. */ |
| 3779 | |
| 3780 | if (singlestep_breakpoints_inserted_p) |
| 3781 | { |
| 3782 | /* Pull the single step breakpoints out of the target. */ |
| 3783 | remove_single_step_breakpoints (); |
| 3784 | singlestep_breakpoints_inserted_p = 0; |
| 3785 | } |
| 3786 | |
| 3787 | /* If the arch can displace step, don't remove the |
| 3788 | breakpoints. */ |
| 3789 | thread_regcache = get_thread_regcache (ecs->ptid); |
| 3790 | if (!use_displaced_stepping (get_regcache_arch (thread_regcache))) |
| 3791 | remove_status = remove_breakpoints (); |
| 3792 | |
| 3793 | /* Did we fail to remove breakpoints? If so, try |
| 3794 | to set the PC past the bp. (There's at least |
| 3795 | one situation in which we can fail to remove |
| 3796 | the bp's: On HP-UX's that use ttrace, we can't |
| 3797 | change the address space of a vforking child |
| 3798 | process until the child exits (well, okay, not |
| 3799 | then either :-) or execs. */ |
| 3800 | if (remove_status != 0) |
| 3801 | error (_("Cannot step over breakpoint hit in wrong thread")); |
| 3802 | else |
| 3803 | { /* Single step */ |
| 3804 | if (!non_stop) |
| 3805 | { |
| 3806 | /* Only need to require the next event from this |
| 3807 | thread in all-stop mode. */ |
| 3808 | waiton_ptid = ecs->ptid; |
| 3809 | infwait_state = infwait_thread_hop_state; |
| 3810 | } |
| 3811 | |
| 3812 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 3813 | keep_going (ecs); |
| 3814 | return; |
| 3815 | } |
| 3816 | } |
| 3817 | else if (singlestep_breakpoints_inserted_p) |
| 3818 | { |
| 3819 | sw_single_step_trap_p = 1; |
| 3820 | ecs->random_signal = 0; |
| 3821 | } |
| 3822 | } |
| 3823 | else |
| 3824 | ecs->random_signal = 1; |
| 3825 | |
| 3826 | /* See if something interesting happened to the non-current thread. If |
| 3827 | so, then switch to that thread. */ |
| 3828 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
| 3829 | { |
| 3830 | if (debug_infrun) |
| 3831 | fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); |
| 3832 | |
| 3833 | context_switch (ecs->ptid); |
| 3834 | |
| 3835 | if (deprecated_context_hook) |
| 3836 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); |
| 3837 | } |
| 3838 | |
| 3839 | /* At this point, get hold of the now-current thread's frame. */ |
| 3840 | frame = get_current_frame (); |
| 3841 | gdbarch = get_frame_arch (frame); |
| 3842 | |
| 3843 | if (singlestep_breakpoints_inserted_p) |
| 3844 | { |
| 3845 | /* Pull the single step breakpoints out of the target. */ |
| 3846 | remove_single_step_breakpoints (); |
| 3847 | singlestep_breakpoints_inserted_p = 0; |
| 3848 | } |
| 3849 | |
| 3850 | if (stepped_after_stopped_by_watchpoint) |
| 3851 | stopped_by_watchpoint = 0; |
| 3852 | else |
| 3853 | stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); |
| 3854 | |
| 3855 | /* If necessary, step over this watchpoint. We'll be back to display |
| 3856 | it in a moment. */ |
| 3857 | if (stopped_by_watchpoint |
| 3858 | && (target_have_steppable_watchpoint |
| 3859 | || gdbarch_have_nonsteppable_watchpoint (gdbarch))) |
| 3860 | { |
| 3861 | /* At this point, we are stopped at an instruction which has |
| 3862 | attempted to write to a piece of memory under control of |
| 3863 | a watchpoint. The instruction hasn't actually executed |
| 3864 | yet. If we were to evaluate the watchpoint expression |
| 3865 | now, we would get the old value, and therefore no change |
| 3866 | would seem to have occurred. |
| 3867 | |
| 3868 | In order to make watchpoints work `right', we really need |
| 3869 | to complete the memory write, and then evaluate the |
| 3870 | watchpoint expression. We do this by single-stepping the |
| 3871 | target. |
| 3872 | |
| 3873 | It may not be necessary to disable the watchpoint to stop over |
| 3874 | it. For example, the PA can (with some kernel cooperation) |
| 3875 | single step over a watchpoint without disabling the watchpoint. |
| 3876 | |
| 3877 | It is far more common to need to disable a watchpoint to step |
| 3878 | the inferior over it. If we have non-steppable watchpoints, |
| 3879 | we must disable the current watchpoint; it's simplest to |
| 3880 | disable all watchpoints and breakpoints. */ |
| 3881 | int hw_step = 1; |
| 3882 | |
| 3883 | if (!target_have_steppable_watchpoint) |
| 3884 | { |
| 3885 | remove_breakpoints (); |
| 3886 | /* See comment in resume why we need to stop bypassing signals |
| 3887 | while breakpoints have been removed. */ |
| 3888 | target_pass_signals (0, NULL); |
| 3889 | } |
| 3890 | /* Single step */ |
| 3891 | hw_step = maybe_software_singlestep (gdbarch, stop_pc); |
| 3892 | target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0); |
| 3893 | waiton_ptid = ecs->ptid; |
| 3894 | if (target_have_steppable_watchpoint) |
| 3895 | infwait_state = infwait_step_watch_state; |
| 3896 | else |
| 3897 | infwait_state = infwait_nonstep_watch_state; |
| 3898 | prepare_to_wait (ecs); |
| 3899 | return; |
| 3900 | } |
| 3901 | |
| 3902 | ecs->stop_func_start = 0; |
| 3903 | ecs->stop_func_end = 0; |
| 3904 | ecs->stop_func_name = 0; |
| 3905 | /* Don't care about return value; stop_func_start and stop_func_name |
| 3906 | will both be 0 if it doesn't work. */ |
| 3907 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, |
| 3908 | &ecs->stop_func_start, &ecs->stop_func_end); |
| 3909 | ecs->stop_func_start |
| 3910 | += gdbarch_deprecated_function_start_offset (gdbarch); |
| 3911 | ecs->event_thread->stepping_over_breakpoint = 0; |
| 3912 | bpstat_clear (&ecs->event_thread->control.stop_bpstat); |
| 3913 | ecs->event_thread->control.stop_step = 0; |
| 3914 | stop_print_frame = 1; |
| 3915 | ecs->random_signal = 0; |
| 3916 | stopped_by_random_signal = 0; |
| 3917 | |
| 3918 | /* Hide inlined functions starting here, unless we just performed stepi or |
| 3919 | nexti. After stepi and nexti, always show the innermost frame (not any |
| 3920 | inline function call sites). */ |
| 3921 | if (ecs->event_thread->control.step_range_end != 1) |
| 3922 | skip_inline_frames (ecs->ptid); |
| 3923 | |
| 3924 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
| 3925 | && ecs->event_thread->control.trap_expected |
| 3926 | && gdbarch_single_step_through_delay_p (gdbarch) |
| 3927 | && currently_stepping (ecs->event_thread)) |
| 3928 | { |
| 3929 | /* We're trying to step off a breakpoint. Turns out that we're |
| 3930 | also on an instruction that needs to be stepped multiple |
| 3931 | times before it's been fully executing. E.g., architectures |
| 3932 | with a delay slot. It needs to be stepped twice, once for |
| 3933 | the instruction and once for the delay slot. */ |
| 3934 | int step_through_delay |
| 3935 | = gdbarch_single_step_through_delay (gdbarch, frame); |
| 3936 | |
| 3937 | if (debug_infrun && step_through_delay) |
| 3938 | fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); |
| 3939 | if (ecs->event_thread->control.step_range_end == 0 |
| 3940 | && step_through_delay) |
| 3941 | { |
| 3942 | /* The user issued a continue when stopped at a breakpoint. |
| 3943 | Set up for another trap and get out of here. */ |
| 3944 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 3945 | keep_going (ecs); |
| 3946 | return; |
| 3947 | } |
| 3948 | else if (step_through_delay) |
| 3949 | { |
| 3950 | /* The user issued a step when stopped at a breakpoint. |
| 3951 | Maybe we should stop, maybe we should not - the delay |
| 3952 | slot *might* correspond to a line of source. In any |
| 3953 | case, don't decide that here, just set |
| 3954 | ecs->stepping_over_breakpoint, making sure we |
| 3955 | single-step again before breakpoints are re-inserted. */ |
| 3956 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 3957 | } |
| 3958 | } |
| 3959 | |
| 3960 | /* Look at the cause of the stop, and decide what to do. |
| 3961 | The alternatives are: |
| 3962 | 1) stop_stepping and return; to really stop and return to the debugger, |
| 3963 | 2) keep_going and return to start up again |
| 3964 | (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once) |
| 3965 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 |
| 3966 | will be made according to the signal handling tables. */ |
| 3967 | |
| 3968 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
| 3969 | || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP |
| 3970 | || stop_soon == STOP_QUIETLY_REMOTE) |
| 3971 | { |
| 3972 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
| 3973 | && stop_after_trap) |
| 3974 | { |
| 3975 | if (debug_infrun) |
| 3976 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); |
| 3977 | stop_print_frame = 0; |
| 3978 | stop_stepping (ecs); |
| 3979 | return; |
| 3980 | } |
| 3981 | |
| 3982 | /* This is originated from start_remote(), start_inferior() and |
| 3983 | shared libraries hook functions. */ |
| 3984 | if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) |
| 3985 | { |
| 3986 | if (debug_infrun) |
| 3987 | fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); |
| 3988 | stop_stepping (ecs); |
| 3989 | return; |
| 3990 | } |
| 3991 | |
| 3992 | /* This originates from attach_command(). We need to overwrite |
| 3993 | the stop_signal here, because some kernels don't ignore a |
| 3994 | SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call. |
| 3995 | See more comments in inferior.h. On the other hand, if we |
| 3996 | get a non-SIGSTOP, report it to the user - assume the backend |
| 3997 | will handle the SIGSTOP if it should show up later. |
| 3998 | |
| 3999 | Also consider that the attach is complete when we see a |
| 4000 | SIGTRAP. Some systems (e.g. Windows), and stubs supporting |
| 4001 | target extended-remote report it instead of a SIGSTOP |
| 4002 | (e.g. gdbserver). We already rely on SIGTRAP being our |
| 4003 | signal, so this is no exception. |
| 4004 | |
| 4005 | Also consider that the attach is complete when we see a |
| 4006 | TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell |
| 4007 | the target to stop all threads of the inferior, in case the |
| 4008 | low level attach operation doesn't stop them implicitly. If |
| 4009 | they weren't stopped implicitly, then the stub will report a |
| 4010 | TARGET_SIGNAL_0, meaning: stopped for no particular reason |
| 4011 | other than GDB's request. */ |
| 4012 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP |
| 4013 | && (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_STOP |
| 4014 | || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
| 4015 | || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_0)) |
| 4016 | { |
| 4017 | stop_stepping (ecs); |
| 4018 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 4019 | return; |
| 4020 | } |
| 4021 | |
| 4022 | /* See if there is a breakpoint at the current PC. */ |
| 4023 | ecs->event_thread->control.stop_bpstat |
| 4024 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
| 4025 | stop_pc, ecs->ptid); |
| 4026 | |
| 4027 | /* Following in case break condition called a |
| 4028 | function. */ |
| 4029 | stop_print_frame = 1; |
| 4030 | |
| 4031 | /* This is where we handle "moribund" watchpoints. Unlike |
| 4032 | software breakpoints traps, hardware watchpoint traps are |
| 4033 | always distinguishable from random traps. If no high-level |
| 4034 | watchpoint is associated with the reported stop data address |
| 4035 | anymore, then the bpstat does not explain the signal --- |
| 4036 | simply make sure to ignore it if `stopped_by_watchpoint' is |
| 4037 | set. */ |
| 4038 | |
| 4039 | if (debug_infrun |
| 4040 | && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
| 4041 | && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat) |
| 4042 | && stopped_by_watchpoint) |
| 4043 | fprintf_unfiltered (gdb_stdlog, |
| 4044 | "infrun: no user watchpoint explains " |
| 4045 | "watchpoint SIGTRAP, ignoring\n"); |
| 4046 | |
| 4047 | /* NOTE: cagney/2003-03-29: These two checks for a random signal |
| 4048 | at one stage in the past included checks for an inferior |
| 4049 | function call's call dummy's return breakpoint. The original |
| 4050 | comment, that went with the test, read: |
| 4051 | |
| 4052 | ``End of a stack dummy. Some systems (e.g. Sony news) give |
| 4053 | another signal besides SIGTRAP, so check here as well as |
| 4054 | above.'' |
| 4055 | |
| 4056 | If someone ever tries to get call dummys on a |
| 4057 | non-executable stack to work (where the target would stop |
| 4058 | with something like a SIGSEGV), then those tests might need |
| 4059 | to be re-instated. Given, however, that the tests were only |
| 4060 | enabled when momentary breakpoints were not being used, I |
| 4061 | suspect that it won't be the case. |
| 4062 | |
| 4063 | NOTE: kettenis/2004-02-05: Indeed such checks don't seem to |
| 4064 | be necessary for call dummies on a non-executable stack on |
| 4065 | SPARC. */ |
| 4066 | |
| 4067 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
| 4068 | ecs->random_signal |
| 4069 | = !(bpstat_explains_signal (ecs->event_thread->control.stop_bpstat) |
| 4070 | || stopped_by_watchpoint |
| 4071 | || ecs->event_thread->control.trap_expected |
| 4072 | || (ecs->event_thread->control.step_range_end |
| 4073 | && (ecs->event_thread->control.step_resume_breakpoint |
| 4074 | == NULL))); |
| 4075 | else |
| 4076 | { |
| 4077 | ecs->random_signal = !bpstat_explains_signal |
| 4078 | (ecs->event_thread->control.stop_bpstat); |
| 4079 | if (!ecs->random_signal) |
| 4080 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
| 4081 | } |
| 4082 | } |
| 4083 | |
| 4084 | /* When we reach this point, we've pretty much decided |
| 4085 | that the reason for stopping must've been a random |
| 4086 | (unexpected) signal. */ |
| 4087 | |
| 4088 | else |
| 4089 | ecs->random_signal = 1; |
| 4090 | |
| 4091 | process_event_stop_test: |
| 4092 | |
| 4093 | /* Re-fetch current thread's frame in case we did a |
| 4094 | "goto process_event_stop_test" above. */ |
| 4095 | frame = get_current_frame (); |
| 4096 | gdbarch = get_frame_arch (frame); |
| 4097 | |
| 4098 | /* For the program's own signals, act according to |
| 4099 | the signal handling tables. */ |
| 4100 | |
| 4101 | if (ecs->random_signal) |
| 4102 | { |
| 4103 | /* Signal not for debugging purposes. */ |
| 4104 | int printed = 0; |
| 4105 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); |
| 4106 | |
| 4107 | if (debug_infrun) |
| 4108 | fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", |
| 4109 | ecs->event_thread->suspend.stop_signal); |
| 4110 | |
| 4111 | stopped_by_random_signal = 1; |
| 4112 | |
| 4113 | if (signal_print[ecs->event_thread->suspend.stop_signal]) |
| 4114 | { |
| 4115 | printed = 1; |
| 4116 | target_terminal_ours_for_output (); |
| 4117 | print_signal_received_reason |
| 4118 | (ecs->event_thread->suspend.stop_signal); |
| 4119 | } |
| 4120 | /* Always stop on signals if we're either just gaining control |
| 4121 | of the program, or the user explicitly requested this thread |
| 4122 | to remain stopped. */ |
| 4123 | if (stop_soon != NO_STOP_QUIETLY |
| 4124 | || ecs->event_thread->stop_requested |
| 4125 | || (!inf->detaching |
| 4126 | && signal_stop_state (ecs->event_thread->suspend.stop_signal))) |
| 4127 | { |
| 4128 | stop_stepping (ecs); |
| 4129 | return; |
| 4130 | } |
| 4131 | /* If not going to stop, give terminal back |
| 4132 | if we took it away. */ |
| 4133 | else if (printed) |
| 4134 | target_terminal_inferior (); |
| 4135 | |
| 4136 | /* Clear the signal if it should not be passed. */ |
| 4137 | if (signal_program[ecs->event_thread->suspend.stop_signal] == 0) |
| 4138 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 4139 | |
| 4140 | if (ecs->event_thread->prev_pc == stop_pc |
| 4141 | && ecs->event_thread->control.trap_expected |
| 4142 | && ecs->event_thread->control.step_resume_breakpoint == NULL) |
| 4143 | { |
| 4144 | /* We were just starting a new sequence, attempting to |
| 4145 | single-step off of a breakpoint and expecting a SIGTRAP. |
| 4146 | Instead this signal arrives. This signal will take us out |
| 4147 | of the stepping range so GDB needs to remember to, when |
| 4148 | the signal handler returns, resume stepping off that |
| 4149 | breakpoint. */ |
| 4150 | /* To simplify things, "continue" is forced to use the same |
| 4151 | code paths as single-step - set a breakpoint at the |
| 4152 | signal return address and then, once hit, step off that |
| 4153 | breakpoint. */ |
| 4154 | if (debug_infrun) |
| 4155 | fprintf_unfiltered (gdb_stdlog, |
| 4156 | "infrun: signal arrived while stepping over " |
| 4157 | "breakpoint\n"); |
| 4158 | |
| 4159 | insert_step_resume_breakpoint_at_frame (frame); |
| 4160 | ecs->event_thread->step_after_step_resume_breakpoint = 1; |
| 4161 | /* Reset trap_expected to ensure breakpoints are re-inserted. */ |
| 4162 | ecs->event_thread->control.trap_expected = 0; |
| 4163 | keep_going (ecs); |
| 4164 | return; |
| 4165 | } |
| 4166 | |
| 4167 | if (ecs->event_thread->control.step_range_end != 0 |
| 4168 | && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_0 |
| 4169 | && (ecs->event_thread->control.step_range_start <= stop_pc |
| 4170 | && stop_pc < ecs->event_thread->control.step_range_end) |
| 4171 | && frame_id_eq (get_stack_frame_id (frame), |
| 4172 | ecs->event_thread->control.step_stack_frame_id) |
| 4173 | && ecs->event_thread->control.step_resume_breakpoint == NULL) |
| 4174 | { |
| 4175 | /* The inferior is about to take a signal that will take it |
| 4176 | out of the single step range. Set a breakpoint at the |
| 4177 | current PC (which is presumably where the signal handler |
| 4178 | will eventually return) and then allow the inferior to |
| 4179 | run free. |
| 4180 | |
| 4181 | Note that this is only needed for a signal delivered |
| 4182 | while in the single-step range. Nested signals aren't a |
| 4183 | problem as they eventually all return. */ |
| 4184 | if (debug_infrun) |
| 4185 | fprintf_unfiltered (gdb_stdlog, |
| 4186 | "infrun: signal may take us out of " |
| 4187 | "single-step range\n"); |
| 4188 | |
| 4189 | insert_step_resume_breakpoint_at_frame (frame); |
| 4190 | /* Reset trap_expected to ensure breakpoints are re-inserted. */ |
| 4191 | ecs->event_thread->control.trap_expected = 0; |
| 4192 | keep_going (ecs); |
| 4193 | return; |
| 4194 | } |
| 4195 | |
| 4196 | /* Note: step_resume_breakpoint may be non-NULL. This occures |
| 4197 | when either there's a nested signal, or when there's a |
| 4198 | pending signal enabled just as the signal handler returns |
| 4199 | (leaving the inferior at the step-resume-breakpoint without |
| 4200 | actually executing it). Either way continue until the |
| 4201 | breakpoint is really hit. */ |
| 4202 | keep_going (ecs); |
| 4203 | return; |
| 4204 | } |
| 4205 | |
| 4206 | /* Handle cases caused by hitting a breakpoint. */ |
| 4207 | { |
| 4208 | CORE_ADDR jmp_buf_pc; |
| 4209 | struct bpstat_what what; |
| 4210 | |
| 4211 | what = bpstat_what (ecs->event_thread->control.stop_bpstat); |
| 4212 | |
| 4213 | if (what.call_dummy) |
| 4214 | { |
| 4215 | stop_stack_dummy = what.call_dummy; |
| 4216 | } |
| 4217 | |
| 4218 | /* If we hit an internal event that triggers symbol changes, the |
| 4219 | current frame will be invalidated within bpstat_what (e.g., if |
| 4220 | we hit an internal solib event). Re-fetch it. */ |
| 4221 | frame = get_current_frame (); |
| 4222 | gdbarch = get_frame_arch (frame); |
| 4223 | |
| 4224 | switch (what.main_action) |
| 4225 | { |
| 4226 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
| 4227 | /* If we hit the breakpoint at longjmp while stepping, we |
| 4228 | install a momentary breakpoint at the target of the |
| 4229 | jmp_buf. */ |
| 4230 | |
| 4231 | if (debug_infrun) |
| 4232 | fprintf_unfiltered (gdb_stdlog, |
| 4233 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); |
| 4234 | |
| 4235 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 4236 | |
| 4237 | if (what.is_longjmp) |
| 4238 | { |
| 4239 | if (!gdbarch_get_longjmp_target_p (gdbarch) |
| 4240 | || !gdbarch_get_longjmp_target (gdbarch, |
| 4241 | frame, &jmp_buf_pc)) |
| 4242 | { |
| 4243 | if (debug_infrun) |
| 4244 | fprintf_unfiltered (gdb_stdlog, |
| 4245 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME " |
| 4246 | "(!gdbarch_get_longjmp_target)\n"); |
| 4247 | keep_going (ecs); |
| 4248 | return; |
| 4249 | } |
| 4250 | |
| 4251 | /* We're going to replace the current step-resume breakpoint |
| 4252 | with a longjmp-resume breakpoint. */ |
| 4253 | delete_step_resume_breakpoint (ecs->event_thread); |
| 4254 | |
| 4255 | /* Insert a breakpoint at resume address. */ |
| 4256 | insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc); |
| 4257 | } |
| 4258 | else |
| 4259 | { |
| 4260 | struct symbol *func = get_frame_function (frame); |
| 4261 | |
| 4262 | if (func) |
| 4263 | check_exception_resume (ecs, frame, func); |
| 4264 | } |
| 4265 | keep_going (ecs); |
| 4266 | return; |
| 4267 | |
| 4268 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
| 4269 | if (debug_infrun) |
| 4270 | fprintf_unfiltered (gdb_stdlog, |
| 4271 | "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); |
| 4272 | |
| 4273 | if (what.is_longjmp) |
| 4274 | { |
| 4275 | gdb_assert (ecs->event_thread->control.step_resume_breakpoint |
| 4276 | != NULL); |
| 4277 | delete_step_resume_breakpoint (ecs->event_thread); |
| 4278 | } |
| 4279 | else |
| 4280 | { |
| 4281 | /* There are several cases to consider. |
| 4282 | |
| 4283 | 1. The initiating frame no longer exists. In this case |
| 4284 | we must stop, because the exception has gone too far. |
| 4285 | |
| 4286 | 2. The initiating frame exists, and is the same as the |
| 4287 | current frame. We stop, because the exception has been |
| 4288 | caught. |
| 4289 | |
| 4290 | 3. The initiating frame exists and is different from |
| 4291 | the current frame. This means the exception has been |
| 4292 | caught beneath the initiating frame, so keep going. */ |
| 4293 | struct frame_info *init_frame |
| 4294 | = frame_find_by_id (ecs->event_thread->initiating_frame); |
| 4295 | |
| 4296 | gdb_assert (ecs->event_thread->control.exception_resume_breakpoint |
| 4297 | != NULL); |
| 4298 | delete_exception_resume_breakpoint (ecs->event_thread); |
| 4299 | |
| 4300 | if (init_frame) |
| 4301 | { |
| 4302 | struct frame_id current_id |
| 4303 | = get_frame_id (get_current_frame ()); |
| 4304 | if (frame_id_eq (current_id, |
| 4305 | ecs->event_thread->initiating_frame)) |
| 4306 | { |
| 4307 | /* Case 2. Fall through. */ |
| 4308 | } |
| 4309 | else |
| 4310 | { |
| 4311 | /* Case 3. */ |
| 4312 | keep_going (ecs); |
| 4313 | return; |
| 4314 | } |
| 4315 | } |
| 4316 | |
| 4317 | /* For Cases 1 and 2, remove the step-resume breakpoint, |
| 4318 | if it exists. */ |
| 4319 | delete_step_resume_breakpoint (ecs->event_thread); |
| 4320 | } |
| 4321 | |
| 4322 | ecs->event_thread->control.stop_step = 1; |
| 4323 | print_end_stepping_range_reason (); |
| 4324 | stop_stepping (ecs); |
| 4325 | return; |
| 4326 | |
| 4327 | case BPSTAT_WHAT_SINGLE: |
| 4328 | if (debug_infrun) |
| 4329 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); |
| 4330 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 4331 | /* Still need to check other stuff, at least the case |
| 4332 | where we are stepping and step out of the right range. */ |
| 4333 | break; |
| 4334 | |
| 4335 | case BPSTAT_WHAT_STOP_NOISY: |
| 4336 | if (debug_infrun) |
| 4337 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); |
| 4338 | stop_print_frame = 1; |
| 4339 | |
| 4340 | /* We are about to nuke the step_resume_breakpointt via the |
| 4341 | cleanup chain, so no need to worry about it here. */ |
| 4342 | |
| 4343 | stop_stepping (ecs); |
| 4344 | return; |
| 4345 | |
| 4346 | case BPSTAT_WHAT_STOP_SILENT: |
| 4347 | if (debug_infrun) |
| 4348 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); |
| 4349 | stop_print_frame = 0; |
| 4350 | |
| 4351 | /* We are about to nuke the step_resume_breakpoin via the |
| 4352 | cleanup chain, so no need to worry about it here. */ |
| 4353 | |
| 4354 | stop_stepping (ecs); |
| 4355 | return; |
| 4356 | |
| 4357 | case BPSTAT_WHAT_STEP_RESUME: |
| 4358 | if (debug_infrun) |
| 4359 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); |
| 4360 | |
| 4361 | delete_step_resume_breakpoint (ecs->event_thread); |
| 4362 | if (ecs->event_thread->step_after_step_resume_breakpoint) |
| 4363 | { |
| 4364 | /* Back when the step-resume breakpoint was inserted, we |
| 4365 | were trying to single-step off a breakpoint. Go back |
| 4366 | to doing that. */ |
| 4367 | ecs->event_thread->step_after_step_resume_breakpoint = 0; |
| 4368 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 4369 | keep_going (ecs); |
| 4370 | return; |
| 4371 | } |
| 4372 | if (stop_pc == ecs->stop_func_start |
| 4373 | && execution_direction == EXEC_REVERSE) |
| 4374 | { |
| 4375 | /* We are stepping over a function call in reverse, and |
| 4376 | just hit the step-resume breakpoint at the start |
| 4377 | address of the function. Go back to single-stepping, |
| 4378 | which should take us back to the function call. */ |
| 4379 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 4380 | keep_going (ecs); |
| 4381 | return; |
| 4382 | } |
| 4383 | break; |
| 4384 | |
| 4385 | case BPSTAT_WHAT_KEEP_CHECKING: |
| 4386 | break; |
| 4387 | } |
| 4388 | } |
| 4389 | |
| 4390 | /* We come here if we hit a breakpoint but should not |
| 4391 | stop for it. Possibly we also were stepping |
| 4392 | and should stop for that. So fall through and |
| 4393 | test for stepping. But, if not stepping, |
| 4394 | do not stop. */ |
| 4395 | |
| 4396 | /* In all-stop mode, if we're currently stepping but have stopped in |
| 4397 | some other thread, we need to switch back to the stepped thread. */ |
| 4398 | if (!non_stop) |
| 4399 | { |
| 4400 | struct thread_info *tp; |
| 4401 | |
| 4402 | tp = iterate_over_threads (currently_stepping_or_nexting_callback, |
| 4403 | ecs->event_thread); |
| 4404 | if (tp) |
| 4405 | { |
| 4406 | /* However, if the current thread is blocked on some internal |
| 4407 | breakpoint, and we simply need to step over that breakpoint |
| 4408 | to get it going again, do that first. */ |
| 4409 | if ((ecs->event_thread->control.trap_expected |
| 4410 | && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP) |
| 4411 | || ecs->event_thread->stepping_over_breakpoint) |
| 4412 | { |
| 4413 | keep_going (ecs); |
| 4414 | return; |
| 4415 | } |
| 4416 | |
| 4417 | /* If the stepping thread exited, then don't try to switch |
| 4418 | back and resume it, which could fail in several different |
| 4419 | ways depending on the target. Instead, just keep going. |
| 4420 | |
| 4421 | We can find a stepping dead thread in the thread list in |
| 4422 | two cases: |
| 4423 | |
| 4424 | - The target supports thread exit events, and when the |
| 4425 | target tries to delete the thread from the thread list, |
| 4426 | inferior_ptid pointed at the exiting thread. In such |
| 4427 | case, calling delete_thread does not really remove the |
| 4428 | thread from the list; instead, the thread is left listed, |
| 4429 | with 'exited' state. |
| 4430 | |
| 4431 | - The target's debug interface does not support thread |
| 4432 | exit events, and so we have no idea whatsoever if the |
| 4433 | previously stepping thread is still alive. For that |
| 4434 | reason, we need to synchronously query the target |
| 4435 | now. */ |
| 4436 | if (is_exited (tp->ptid) |
| 4437 | || !target_thread_alive (tp->ptid)) |
| 4438 | { |
| 4439 | if (debug_infrun) |
| 4440 | fprintf_unfiltered (gdb_stdlog, |
| 4441 | "infrun: not switching back to " |
| 4442 | "stepped thread, it has vanished\n"); |
| 4443 | |
| 4444 | delete_thread (tp->ptid); |
| 4445 | keep_going (ecs); |
| 4446 | return; |
| 4447 | } |
| 4448 | |
| 4449 | /* Otherwise, we no longer expect a trap in the current thread. |
| 4450 | Clear the trap_expected flag before switching back -- this is |
| 4451 | what keep_going would do as well, if we called it. */ |
| 4452 | ecs->event_thread->control.trap_expected = 0; |
| 4453 | |
| 4454 | if (debug_infrun) |
| 4455 | fprintf_unfiltered (gdb_stdlog, |
| 4456 | "infrun: switching back to stepped thread\n"); |
| 4457 | |
| 4458 | ecs->event_thread = tp; |
| 4459 | ecs->ptid = tp->ptid; |
| 4460 | context_switch (ecs->ptid); |
| 4461 | keep_going (ecs); |
| 4462 | return; |
| 4463 | } |
| 4464 | } |
| 4465 | |
| 4466 | /* Are we stepping to get the inferior out of the dynamic linker's |
| 4467 | hook (and possibly the dld itself) after catching a shlib |
| 4468 | event? */ |
| 4469 | if (ecs->event_thread->stepping_through_solib_after_catch) |
| 4470 | { |
| 4471 | #if defined(SOLIB_ADD) |
| 4472 | /* Have we reached our destination? If not, keep going. */ |
| 4473 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) |
| 4474 | { |
| 4475 | if (debug_infrun) |
| 4476 | fprintf_unfiltered (gdb_stdlog, |
| 4477 | "infrun: stepping in dynamic linker\n"); |
| 4478 | ecs->event_thread->stepping_over_breakpoint = 1; |
| 4479 | keep_going (ecs); |
| 4480 | return; |
| 4481 | } |
| 4482 | #endif |
| 4483 | if (debug_infrun) |
| 4484 | fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n"); |
| 4485 | /* Else, stop and report the catchpoint(s) whose triggering |
| 4486 | caused us to begin stepping. */ |
| 4487 | ecs->event_thread->stepping_through_solib_after_catch = 0; |
| 4488 | bpstat_clear (&ecs->event_thread->control.stop_bpstat); |
| 4489 | ecs->event_thread->control.stop_bpstat |
| 4490 | = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints); |
| 4491 | bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints); |
| 4492 | stop_print_frame = 1; |
| 4493 | stop_stepping (ecs); |
| 4494 | return; |
| 4495 | } |
| 4496 | |
| 4497 | if (ecs->event_thread->control.step_resume_breakpoint) |
| 4498 | { |
| 4499 | if (debug_infrun) |
| 4500 | fprintf_unfiltered (gdb_stdlog, |
| 4501 | "infrun: step-resume breakpoint is inserted\n"); |
| 4502 | |
| 4503 | /* Having a step-resume breakpoint overrides anything |
| 4504 | else having to do with stepping commands until |
| 4505 | that breakpoint is reached. */ |
| 4506 | keep_going (ecs); |
| 4507 | return; |
| 4508 | } |
| 4509 | |
| 4510 | if (ecs->event_thread->control.step_range_end == 0) |
| 4511 | { |
| 4512 | if (debug_infrun) |
| 4513 | fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); |
| 4514 | /* Likewise if we aren't even stepping. */ |
| 4515 | keep_going (ecs); |
| 4516 | return; |
| 4517 | } |
| 4518 | |
| 4519 | /* Re-fetch current thread's frame in case the code above caused |
| 4520 | the frame cache to be re-initialized, making our FRAME variable |
| 4521 | a dangling pointer. */ |
| 4522 | frame = get_current_frame (); |
| 4523 | gdbarch = get_frame_arch (frame); |
| 4524 | |
| 4525 | /* If stepping through a line, keep going if still within it. |
| 4526 | |
| 4527 | Note that step_range_end is the address of the first instruction |
| 4528 | beyond the step range, and NOT the address of the last instruction |
| 4529 | within it! |
| 4530 | |
| 4531 | Note also that during reverse execution, we may be stepping |
| 4532 | through a function epilogue and therefore must detect when |
| 4533 | the current-frame changes in the middle of a line. */ |
| 4534 | |
| 4535 | if (stop_pc >= ecs->event_thread->control.step_range_start |
| 4536 | && stop_pc < ecs->event_thread->control.step_range_end |
| 4537 | && (execution_direction != EXEC_REVERSE |
| 4538 | || frame_id_eq (get_frame_id (frame), |
| 4539 | ecs->event_thread->control.step_frame_id))) |
| 4540 | { |
| 4541 | if (debug_infrun) |
| 4542 | fprintf_unfiltered |
| 4543 | (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n", |
| 4544 | paddress (gdbarch, ecs->event_thread->control.step_range_start), |
| 4545 | paddress (gdbarch, ecs->event_thread->control.step_range_end)); |
| 4546 | |
| 4547 | /* When stepping backward, stop at beginning of line range |
| 4548 | (unless it's the function entry point, in which case |
| 4549 | keep going back to the call point). */ |
| 4550 | if (stop_pc == ecs->event_thread->control.step_range_start |
| 4551 | && stop_pc != ecs->stop_func_start |
| 4552 | && execution_direction == EXEC_REVERSE) |
| 4553 | { |
| 4554 | ecs->event_thread->control.stop_step = 1; |
| 4555 | print_end_stepping_range_reason (); |
| 4556 | stop_stepping (ecs); |
| 4557 | } |
| 4558 | else |
| 4559 | keep_going (ecs); |
| 4560 | |
| 4561 | return; |
| 4562 | } |
| 4563 | |
| 4564 | /* We stepped out of the stepping range. */ |
| 4565 | |
| 4566 | /* If we are stepping at the source level and entered the runtime |
| 4567 | loader dynamic symbol resolution code... |
| 4568 | |
| 4569 | EXEC_FORWARD: we keep on single stepping until we exit the run |
| 4570 | time loader code and reach the callee's address. |
| 4571 | |
| 4572 | EXEC_REVERSE: we've already executed the callee (backward), and |
| 4573 | the runtime loader code is handled just like any other |
| 4574 | undebuggable function call. Now we need only keep stepping |
| 4575 | backward through the trampoline code, and that's handled further |
| 4576 | down, so there is nothing for us to do here. */ |
| 4577 | |
| 4578 | if (execution_direction != EXEC_REVERSE |
| 4579 | && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
| 4580 | && in_solib_dynsym_resolve_code (stop_pc)) |
| 4581 | { |
| 4582 | CORE_ADDR pc_after_resolver = |
| 4583 | gdbarch_skip_solib_resolver (gdbarch, stop_pc); |
| 4584 | |
| 4585 | if (debug_infrun) |
| 4586 | fprintf_unfiltered (gdb_stdlog, |
| 4587 | "infrun: stepped into dynsym resolve code\n"); |
| 4588 | |
| 4589 | if (pc_after_resolver) |
| 4590 | { |
| 4591 | /* Set up a step-resume breakpoint at the address |
| 4592 | indicated by SKIP_SOLIB_RESOLVER. */ |
| 4593 | struct symtab_and_line sr_sal; |
| 4594 | |
| 4595 | init_sal (&sr_sal); |
| 4596 | sr_sal.pc = pc_after_resolver; |
| 4597 | sr_sal.pspace = get_frame_program_space (frame); |
| 4598 | |
| 4599 | insert_step_resume_breakpoint_at_sal (gdbarch, |
| 4600 | sr_sal, null_frame_id); |
| 4601 | } |
| 4602 | |
| 4603 | keep_going (ecs); |
| 4604 | return; |
| 4605 | } |
| 4606 | |
| 4607 | if (ecs->event_thread->control.step_range_end != 1 |
| 4608 | && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
| 4609 | || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) |
| 4610 | && get_frame_type (frame) == SIGTRAMP_FRAME) |
| 4611 | { |
| 4612 | if (debug_infrun) |
| 4613 | fprintf_unfiltered (gdb_stdlog, |
| 4614 | "infrun: stepped into signal trampoline\n"); |
| 4615 | /* The inferior, while doing a "step" or "next", has ended up in |
| 4616 | a signal trampoline (either by a signal being delivered or by |
| 4617 | the signal handler returning). Just single-step until the |
| 4618 | inferior leaves the trampoline (either by calling the handler |
| 4619 | or returning). */ |
| 4620 | keep_going (ecs); |
| 4621 | return; |
| 4622 | } |
| 4623 | |
| 4624 | /* Check for subroutine calls. The check for the current frame |
| 4625 | equalling the step ID is not necessary - the check of the |
| 4626 | previous frame's ID is sufficient - but it is a common case and |
| 4627 | cheaper than checking the previous frame's ID. |
| 4628 | |
| 4629 | NOTE: frame_id_eq will never report two invalid frame IDs as |
| 4630 | being equal, so to get into this block, both the current and |
| 4631 | previous frame must have valid frame IDs. */ |
| 4632 | /* The outer_frame_id check is a heuristic to detect stepping |
| 4633 | through startup code. If we step over an instruction which |
| 4634 | sets the stack pointer from an invalid value to a valid value, |
| 4635 | we may detect that as a subroutine call from the mythical |
| 4636 | "outermost" function. This could be fixed by marking |
| 4637 | outermost frames as !stack_p,code_p,special_p. Then the |
| 4638 | initial outermost frame, before sp was valid, would |
| 4639 | have code_addr == &_start. See the comment in frame_id_eq |
| 4640 | for more. */ |
| 4641 | if (!frame_id_eq (get_stack_frame_id (frame), |
| 4642 | ecs->event_thread->control.step_stack_frame_id) |
| 4643 | && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()), |
| 4644 | ecs->event_thread->control.step_stack_frame_id) |
| 4645 | && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id, |
| 4646 | outer_frame_id) |
| 4647 | || step_start_function != find_pc_function (stop_pc)))) |
| 4648 | { |
| 4649 | CORE_ADDR real_stop_pc; |
| 4650 | |
| 4651 | if (debug_infrun) |
| 4652 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); |
| 4653 | |
| 4654 | if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE) |
| 4655 | || ((ecs->event_thread->control.step_range_end == 1) |
| 4656 | && in_prologue (gdbarch, ecs->event_thread->prev_pc, |
| 4657 | ecs->stop_func_start))) |
| 4658 | { |
| 4659 | /* I presume that step_over_calls is only 0 when we're |
| 4660 | supposed to be stepping at the assembly language level |
| 4661 | ("stepi"). Just stop. */ |
| 4662 | /* Also, maybe we just did a "nexti" inside a prolog, so we |
| 4663 | thought it was a subroutine call but it was not. Stop as |
| 4664 | well. FENN */ |
| 4665 | /* And this works the same backward as frontward. MVS */ |
| 4666 | ecs->event_thread->control.stop_step = 1; |
| 4667 | print_end_stepping_range_reason (); |
| 4668 | stop_stepping (ecs); |
| 4669 | return; |
| 4670 | } |
| 4671 | |
| 4672 | /* Reverse stepping through solib trampolines. */ |
| 4673 | |
| 4674 | if (execution_direction == EXEC_REVERSE |
| 4675 | && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE |
| 4676 | && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) |
| 4677 | || (ecs->stop_func_start == 0 |
| 4678 | && in_solib_dynsym_resolve_code (stop_pc)))) |
| 4679 | { |
| 4680 | /* Any solib trampoline code can be handled in reverse |
| 4681 | by simply continuing to single-step. We have already |
| 4682 | executed the solib function (backwards), and a few |
| 4683 | steps will take us back through the trampoline to the |
| 4684 | caller. */ |
| 4685 | keep_going (ecs); |
| 4686 | return; |
| 4687 | } |
| 4688 | |
| 4689 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) |
| 4690 | { |
| 4691 | /* We're doing a "next". |
| 4692 | |
| 4693 | Normal (forward) execution: set a breakpoint at the |
| 4694 | callee's return address (the address at which the caller |
| 4695 | will resume). |
| 4696 | |
| 4697 | Reverse (backward) execution. set the step-resume |
| 4698 | breakpoint at the start of the function that we just |
| 4699 | stepped into (backwards), and continue to there. When we |
| 4700 | get there, we'll need to single-step back to the caller. */ |
| 4701 | |
| 4702 | if (execution_direction == EXEC_REVERSE) |
| 4703 | { |
| 4704 | struct symtab_and_line sr_sal; |
| 4705 | |
| 4706 | /* Normal function call return (static or dynamic). */ |
| 4707 | init_sal (&sr_sal); |
| 4708 | sr_sal.pc = ecs->stop_func_start; |
| 4709 | sr_sal.pspace = get_frame_program_space (frame); |
| 4710 | insert_step_resume_breakpoint_at_sal (gdbarch, |
| 4711 | sr_sal, null_frame_id); |
| 4712 | } |
| 4713 | else |
| 4714 | insert_step_resume_breakpoint_at_caller (frame); |
| 4715 | |
| 4716 | keep_going (ecs); |
| 4717 | return; |
| 4718 | } |
| 4719 | |
| 4720 | /* If we are in a function call trampoline (a stub between the |
| 4721 | calling routine and the real function), locate the real |
| 4722 | function. That's what tells us (a) whether we want to step |
| 4723 | into it at all, and (b) what prologue we want to run to the |
| 4724 | end of, if we do step into it. */ |
| 4725 | real_stop_pc = skip_language_trampoline (frame, stop_pc); |
| 4726 | if (real_stop_pc == 0) |
| 4727 | real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); |
| 4728 | if (real_stop_pc != 0) |
| 4729 | ecs->stop_func_start = real_stop_pc; |
| 4730 | |
| 4731 | if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc)) |
| 4732 | { |
| 4733 | struct symtab_and_line sr_sal; |
| 4734 | |
| 4735 | init_sal (&sr_sal); |
| 4736 | sr_sal.pc = ecs->stop_func_start; |
| 4737 | sr_sal.pspace = get_frame_program_space (frame); |
| 4738 | |
| 4739 | insert_step_resume_breakpoint_at_sal (gdbarch, |
| 4740 | sr_sal, null_frame_id); |
| 4741 | keep_going (ecs); |
| 4742 | return; |
| 4743 | } |
| 4744 | |
| 4745 | /* If we have line number information for the function we are |
| 4746 | thinking of stepping into, step into it. |
| 4747 | |
| 4748 | If there are several symtabs at that PC (e.g. with include |
| 4749 | files), just want to know whether *any* of them have line |
| 4750 | numbers. find_pc_line handles this. */ |
| 4751 | { |
| 4752 | struct symtab_and_line tmp_sal; |
| 4753 | |
| 4754 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
| 4755 | if (tmp_sal.line != 0) |
| 4756 | { |
| 4757 | if (execution_direction == EXEC_REVERSE) |
| 4758 | handle_step_into_function_backward (gdbarch, ecs); |
| 4759 | else |
| 4760 | handle_step_into_function (gdbarch, ecs); |
| 4761 | return; |
| 4762 | } |
| 4763 | } |
| 4764 | |
| 4765 | /* If we have no line number and the step-stop-if-no-debug is |
| 4766 | set, we stop the step so that the user has a chance to switch |
| 4767 | in assembly mode. */ |
| 4768 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
| 4769 | && step_stop_if_no_debug) |
| 4770 | { |
| 4771 | ecs->event_thread->control.stop_step = 1; |
| 4772 | print_end_stepping_range_reason (); |
| 4773 | stop_stepping (ecs); |
| 4774 | return; |
| 4775 | } |
| 4776 | |
| 4777 | if (execution_direction == EXEC_REVERSE) |
| 4778 | { |
| 4779 | /* Set a breakpoint at callee's start address. |
| 4780 | From there we can step once and be back in the caller. */ |
| 4781 | struct symtab_and_line sr_sal; |
| 4782 | |
| 4783 | init_sal (&sr_sal); |
| 4784 | sr_sal.pc = ecs->stop_func_start; |
| 4785 | sr_sal.pspace = get_frame_program_space (frame); |
| 4786 | insert_step_resume_breakpoint_at_sal (gdbarch, |
| 4787 | sr_sal, null_frame_id); |
| 4788 | } |
| 4789 | else |
| 4790 | /* Set a breakpoint at callee's return address (the address |
| 4791 | at which the caller will resume). */ |
| 4792 | insert_step_resume_breakpoint_at_caller (frame); |
| 4793 | |
| 4794 | keep_going (ecs); |
| 4795 | return; |
| 4796 | } |
| 4797 | |
| 4798 | /* Reverse stepping through solib trampolines. */ |
| 4799 | |
| 4800 | if (execution_direction == EXEC_REVERSE |
| 4801 | && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE) |
| 4802 | { |
| 4803 | if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) |
| 4804 | || (ecs->stop_func_start == 0 |
| 4805 | && in_solib_dynsym_resolve_code (stop_pc))) |
| 4806 | { |
| 4807 | /* Any solib trampoline code can be handled in reverse |
| 4808 | by simply continuing to single-step. We have already |
| 4809 | executed the solib function (backwards), and a few |
| 4810 | steps will take us back through the trampoline to the |
| 4811 | caller. */ |
| 4812 | keep_going (ecs); |
| 4813 | return; |
| 4814 | } |
| 4815 | else if (in_solib_dynsym_resolve_code (stop_pc)) |
| 4816 | { |
| 4817 | /* Stepped backward into the solib dynsym resolver. |
| 4818 | Set a breakpoint at its start and continue, then |
| 4819 | one more step will take us out. */ |
| 4820 | struct symtab_and_line sr_sal; |
| 4821 | |
| 4822 | init_sal (&sr_sal); |
| 4823 | sr_sal.pc = ecs->stop_func_start; |
| 4824 | sr_sal.pspace = get_frame_program_space (frame); |
| 4825 | insert_step_resume_breakpoint_at_sal (gdbarch, |
| 4826 | sr_sal, null_frame_id); |
| 4827 | keep_going (ecs); |
| 4828 | return; |
| 4829 | } |
| 4830 | } |
| 4831 | |
| 4832 | /* If we're in the return path from a shared library trampoline, |
| 4833 | we want to proceed through the trampoline when stepping. */ |
| 4834 | if (gdbarch_in_solib_return_trampoline (gdbarch, |
| 4835 | stop_pc, ecs->stop_func_name)) |
| 4836 | { |
| 4837 | /* Determine where this trampoline returns. */ |
| 4838 | CORE_ADDR real_stop_pc; |
| 4839 | |
| 4840 | real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); |
| 4841 | |
| 4842 | if (debug_infrun) |
| 4843 | fprintf_unfiltered (gdb_stdlog, |
| 4844 | "infrun: stepped into solib return tramp\n"); |
| 4845 | |
| 4846 | /* Only proceed through if we know where it's going. */ |
| 4847 | if (real_stop_pc) |
| 4848 | { |
| 4849 | /* And put the step-breakpoint there and go until there. */ |
| 4850 | struct symtab_and_line sr_sal; |
| 4851 | |
| 4852 | init_sal (&sr_sal); /* initialize to zeroes */ |
| 4853 | sr_sal.pc = real_stop_pc; |
| 4854 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
| 4855 | sr_sal.pspace = get_frame_program_space (frame); |
| 4856 | |
| 4857 | /* Do not specify what the fp should be when we stop since |
| 4858 | on some machines the prologue is where the new fp value |
| 4859 | is established. */ |
| 4860 | insert_step_resume_breakpoint_at_sal (gdbarch, |
| 4861 | sr_sal, null_frame_id); |
| 4862 | |
| 4863 | /* Restart without fiddling with the step ranges or |
| 4864 | other state. */ |
| 4865 | keep_going (ecs); |
| 4866 | return; |
| 4867 | } |
| 4868 | } |
| 4869 | |
| 4870 | stop_pc_sal = find_pc_line (stop_pc, 0); |
| 4871 | |
| 4872 | /* NOTE: tausq/2004-05-24: This if block used to be done before all |
| 4873 | the trampoline processing logic, however, there are some trampolines |
| 4874 | that have no names, so we should do trampoline handling first. */ |
| 4875 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
| 4876 | && ecs->stop_func_name == NULL |
| 4877 | && stop_pc_sal.line == 0) |
| 4878 | { |
| 4879 | if (debug_infrun) |
| 4880 | fprintf_unfiltered (gdb_stdlog, |
| 4881 | "infrun: stepped into undebuggable function\n"); |
| 4882 | |
| 4883 | /* The inferior just stepped into, or returned to, an |
| 4884 | undebuggable function (where there is no debugging information |
| 4885 | and no line number corresponding to the address where the |
| 4886 | inferior stopped). Since we want to skip this kind of code, |
| 4887 | we keep going until the inferior returns from this |
| 4888 | function - unless the user has asked us not to (via |
| 4889 | set step-mode) or we no longer know how to get back |
| 4890 | to the call site. */ |
| 4891 | if (step_stop_if_no_debug |
| 4892 | || !frame_id_p (frame_unwind_caller_id (frame))) |
| 4893 | { |
| 4894 | /* If we have no line number and the step-stop-if-no-debug |
| 4895 | is set, we stop the step so that the user has a chance to |
| 4896 | switch in assembly mode. */ |
| 4897 | ecs->event_thread->control.stop_step = 1; |
| 4898 | print_end_stepping_range_reason (); |
| 4899 | stop_stepping (ecs); |
| 4900 | return; |
| 4901 | } |
| 4902 | else |
| 4903 | { |
| 4904 | /* Set a breakpoint at callee's return address (the address |
| 4905 | at which the caller will resume). */ |
| 4906 | insert_step_resume_breakpoint_at_caller (frame); |
| 4907 | keep_going (ecs); |
| 4908 | return; |
| 4909 | } |
| 4910 | } |
| 4911 | |
| 4912 | if (ecs->event_thread->control.step_range_end == 1) |
| 4913 | { |
| 4914 | /* It is stepi or nexti. We always want to stop stepping after |
| 4915 | one instruction. */ |
| 4916 | if (debug_infrun) |
| 4917 | fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); |
| 4918 | ecs->event_thread->control.stop_step = 1; |
| 4919 | print_end_stepping_range_reason (); |
| 4920 | stop_stepping (ecs); |
| 4921 | return; |
| 4922 | } |
| 4923 | |
| 4924 | if (stop_pc_sal.line == 0) |
| 4925 | { |
| 4926 | /* We have no line number information. That means to stop |
| 4927 | stepping (does this always happen right after one instruction, |
| 4928 | when we do "s" in a function with no line numbers, |
| 4929 | or can this happen as a result of a return or longjmp?). */ |
| 4930 | if (debug_infrun) |
| 4931 | fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); |
| 4932 | ecs->event_thread->control.stop_step = 1; |
| 4933 | print_end_stepping_range_reason (); |
| 4934 | stop_stepping (ecs); |
| 4935 | return; |
| 4936 | } |
| 4937 | |
| 4938 | /* Look for "calls" to inlined functions, part one. If the inline |
| 4939 | frame machinery detected some skipped call sites, we have entered |
| 4940 | a new inline function. */ |
| 4941 | |
| 4942 | if (frame_id_eq (get_frame_id (get_current_frame ()), |
| 4943 | ecs->event_thread->control.step_frame_id) |
| 4944 | && inline_skipped_frames (ecs->ptid)) |
| 4945 | { |
| 4946 | struct symtab_and_line call_sal; |
| 4947 | |
| 4948 | if (debug_infrun) |
| 4949 | fprintf_unfiltered (gdb_stdlog, |
| 4950 | "infrun: stepped into inlined function\n"); |
| 4951 | |
| 4952 | find_frame_sal (get_current_frame (), &call_sal); |
| 4953 | |
| 4954 | if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL) |
| 4955 | { |
| 4956 | /* For "step", we're going to stop. But if the call site |
| 4957 | for this inlined function is on the same source line as |
| 4958 | we were previously stepping, go down into the function |
| 4959 | first. Otherwise stop at the call site. */ |
| 4960 | |
| 4961 | if (call_sal.line == ecs->event_thread->current_line |
| 4962 | && call_sal.symtab == ecs->event_thread->current_symtab) |
| 4963 | step_into_inline_frame (ecs->ptid); |
| 4964 | |
| 4965 | ecs->event_thread->control.stop_step = 1; |
| 4966 | print_end_stepping_range_reason (); |
| 4967 | stop_stepping (ecs); |
| 4968 | return; |
| 4969 | } |
| 4970 | else |
| 4971 | { |
| 4972 | /* For "next", we should stop at the call site if it is on a |
| 4973 | different source line. Otherwise continue through the |
| 4974 | inlined function. */ |
| 4975 | if (call_sal.line == ecs->event_thread->current_line |
| 4976 | && call_sal.symtab == ecs->event_thread->current_symtab) |
| 4977 | keep_going (ecs); |
| 4978 | else |
| 4979 | { |
| 4980 | ecs->event_thread->control.stop_step = 1; |
| 4981 | print_end_stepping_range_reason (); |
| 4982 | stop_stepping (ecs); |
| 4983 | } |
| 4984 | return; |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | /* Look for "calls" to inlined functions, part two. If we are still |
| 4989 | in the same real function we were stepping through, but we have |
| 4990 | to go further up to find the exact frame ID, we are stepping |
| 4991 | through a more inlined call beyond its call site. */ |
| 4992 | |
| 4993 | if (get_frame_type (get_current_frame ()) == INLINE_FRAME |
| 4994 | && !frame_id_eq (get_frame_id (get_current_frame ()), |
| 4995 | ecs->event_thread->control.step_frame_id) |
| 4996 | && stepped_in_from (get_current_frame (), |
| 4997 | ecs->event_thread->control.step_frame_id)) |
| 4998 | { |
| 4999 | if (debug_infrun) |
| 5000 | fprintf_unfiltered (gdb_stdlog, |
| 5001 | "infrun: stepping through inlined function\n"); |
| 5002 | |
| 5003 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) |
| 5004 | keep_going (ecs); |
| 5005 | else |
| 5006 | { |
| 5007 | ecs->event_thread->control.stop_step = 1; |
| 5008 | print_end_stepping_range_reason (); |
| 5009 | stop_stepping (ecs); |
| 5010 | } |
| 5011 | return; |
| 5012 | } |
| 5013 | |
| 5014 | if ((stop_pc == stop_pc_sal.pc) |
| 5015 | && (ecs->event_thread->current_line != stop_pc_sal.line |
| 5016 | || ecs->event_thread->current_symtab != stop_pc_sal.symtab)) |
| 5017 | { |
| 5018 | /* We are at the start of a different line. So stop. Note that |
| 5019 | we don't stop if we step into the middle of a different line. |
| 5020 | That is said to make things like for (;;) statements work |
| 5021 | better. */ |
| 5022 | if (debug_infrun) |
| 5023 | fprintf_unfiltered (gdb_stdlog, |
| 5024 | "infrun: stepped to a different line\n"); |
| 5025 | ecs->event_thread->control.stop_step = 1; |
| 5026 | print_end_stepping_range_reason (); |
| 5027 | stop_stepping (ecs); |
| 5028 | return; |
| 5029 | } |
| 5030 | |
| 5031 | /* We aren't done stepping. |
| 5032 | |
| 5033 | Optimize by setting the stepping range to the line. |
| 5034 | (We might not be in the original line, but if we entered a |
| 5035 | new line in mid-statement, we continue stepping. This makes |
| 5036 | things like for(;;) statements work better.) */ |
| 5037 | |
| 5038 | ecs->event_thread->control.step_range_start = stop_pc_sal.pc; |
| 5039 | ecs->event_thread->control.step_range_end = stop_pc_sal.end; |
| 5040 | set_step_info (frame, stop_pc_sal); |
| 5041 | |
| 5042 | if (debug_infrun) |
| 5043 | fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); |
| 5044 | keep_going (ecs); |
| 5045 | } |
| 5046 | |
| 5047 | /* Is thread TP in the middle of single-stepping? */ |
| 5048 | |
| 5049 | static int |
| 5050 | currently_stepping (struct thread_info *tp) |
| 5051 | { |
| 5052 | return ((tp->control.step_range_end |
| 5053 | && tp->control.step_resume_breakpoint == NULL) |
| 5054 | || tp->control.trap_expected |
| 5055 | || tp->stepping_through_solib_after_catch |
| 5056 | || bpstat_should_step ()); |
| 5057 | } |
| 5058 | |
| 5059 | /* Returns true if any thread *but* the one passed in "data" is in the |
| 5060 | middle of stepping or of handling a "next". */ |
| 5061 | |
| 5062 | static int |
| 5063 | currently_stepping_or_nexting_callback (struct thread_info *tp, void *data) |
| 5064 | { |
| 5065 | if (tp == data) |
| 5066 | return 0; |
| 5067 | |
| 5068 | return (tp->control.step_range_end |
| 5069 | || tp->control.trap_expected |
| 5070 | || tp->stepping_through_solib_after_catch); |
| 5071 | } |
| 5072 | |
| 5073 | /* Inferior has stepped into a subroutine call with source code that |
| 5074 | we should not step over. Do step to the first line of code in |
| 5075 | it. */ |
| 5076 | |
| 5077 | static void |
| 5078 | handle_step_into_function (struct gdbarch *gdbarch, |
| 5079 | struct execution_control_state *ecs) |
| 5080 | { |
| 5081 | struct symtab *s; |
| 5082 | struct symtab_and_line stop_func_sal, sr_sal; |
| 5083 | |
| 5084 | s = find_pc_symtab (stop_pc); |
| 5085 | if (s && s->language != language_asm) |
| 5086 | ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, |
| 5087 | ecs->stop_func_start); |
| 5088 | |
| 5089 | stop_func_sal = find_pc_line (ecs->stop_func_start, 0); |
| 5090 | /* Use the step_resume_break to step until the end of the prologue, |
| 5091 | even if that involves jumps (as it seems to on the vax under |
| 5092 | 4.2). */ |
| 5093 | /* If the prologue ends in the middle of a source line, continue to |
| 5094 | the end of that source line (if it is still within the function). |
| 5095 | Otherwise, just go to end of prologue. */ |
| 5096 | if (stop_func_sal.end |
| 5097 | && stop_func_sal.pc != ecs->stop_func_start |
| 5098 | && stop_func_sal.end < ecs->stop_func_end) |
| 5099 | ecs->stop_func_start = stop_func_sal.end; |
| 5100 | |
| 5101 | /* Architectures which require breakpoint adjustment might not be able |
| 5102 | to place a breakpoint at the computed address. If so, the test |
| 5103 | ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust |
| 5104 | ecs->stop_func_start to an address at which a breakpoint may be |
| 5105 | legitimately placed. |
| 5106 | |
| 5107 | Note: kevinb/2004-01-19: On FR-V, if this adjustment is not |
| 5108 | made, GDB will enter an infinite loop when stepping through |
| 5109 | optimized code consisting of VLIW instructions which contain |
| 5110 | subinstructions corresponding to different source lines. On |
| 5111 | FR-V, it's not permitted to place a breakpoint on any but the |
| 5112 | first subinstruction of a VLIW instruction. When a breakpoint is |
| 5113 | set, GDB will adjust the breakpoint address to the beginning of |
| 5114 | the VLIW instruction. Thus, we need to make the corresponding |
| 5115 | adjustment here when computing the stop address. */ |
| 5116 | |
| 5117 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) |
| 5118 | { |
| 5119 | ecs->stop_func_start |
| 5120 | = gdbarch_adjust_breakpoint_address (gdbarch, |
| 5121 | ecs->stop_func_start); |
| 5122 | } |
| 5123 | |
| 5124 | if (ecs->stop_func_start == stop_pc) |
| 5125 | { |
| 5126 | /* We are already there: stop now. */ |
| 5127 | ecs->event_thread->control.stop_step = 1; |
| 5128 | print_end_stepping_range_reason (); |
| 5129 | stop_stepping (ecs); |
| 5130 | return; |
| 5131 | } |
| 5132 | else |
| 5133 | { |
| 5134 | /* Put the step-breakpoint there and go until there. */ |
| 5135 | init_sal (&sr_sal); /* initialize to zeroes */ |
| 5136 | sr_sal.pc = ecs->stop_func_start; |
| 5137 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); |
| 5138 | sr_sal.pspace = get_frame_program_space (get_current_frame ()); |
| 5139 | |
| 5140 | /* Do not specify what the fp should be when we stop since on |
| 5141 | some machines the prologue is where the new fp value is |
| 5142 | established. */ |
| 5143 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id); |
| 5144 | |
| 5145 | /* And make sure stepping stops right away then. */ |
| 5146 | ecs->event_thread->control.step_range_end |
| 5147 | = ecs->event_thread->control.step_range_start; |
| 5148 | } |
| 5149 | keep_going (ecs); |
| 5150 | } |
| 5151 | |
| 5152 | /* Inferior has stepped backward into a subroutine call with source |
| 5153 | code that we should not step over. Do step to the beginning of the |
| 5154 | last line of code in it. */ |
| 5155 | |
| 5156 | static void |
| 5157 | handle_step_into_function_backward (struct gdbarch *gdbarch, |
| 5158 | struct execution_control_state *ecs) |
| 5159 | { |
| 5160 | struct symtab *s; |
| 5161 | struct symtab_and_line stop_func_sal; |
| 5162 | |
| 5163 | s = find_pc_symtab (stop_pc); |
| 5164 | if (s && s->language != language_asm) |
| 5165 | ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, |
| 5166 | ecs->stop_func_start); |
| 5167 | |
| 5168 | stop_func_sal = find_pc_line (stop_pc, 0); |
| 5169 | |
| 5170 | /* OK, we're just going to keep stepping here. */ |
| 5171 | if (stop_func_sal.pc == stop_pc) |
| 5172 | { |
| 5173 | /* We're there already. Just stop stepping now. */ |
| 5174 | ecs->event_thread->control.stop_step = 1; |
| 5175 | print_end_stepping_range_reason (); |
| 5176 | stop_stepping (ecs); |
| 5177 | } |
| 5178 | else |
| 5179 | { |
| 5180 | /* Else just reset the step range and keep going. |
| 5181 | No step-resume breakpoint, they don't work for |
| 5182 | epilogues, which can have multiple entry paths. */ |
| 5183 | ecs->event_thread->control.step_range_start = stop_func_sal.pc; |
| 5184 | ecs->event_thread->control.step_range_end = stop_func_sal.end; |
| 5185 | keep_going (ecs); |
| 5186 | } |
| 5187 | return; |
| 5188 | } |
| 5189 | |
| 5190 | /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. |
| 5191 | This is used to both functions and to skip over code. */ |
| 5192 | |
| 5193 | static void |
| 5194 | insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch, |
| 5195 | struct symtab_and_line sr_sal, |
| 5196 | struct frame_id sr_id) |
| 5197 | { |
| 5198 | /* There should never be more than one step-resume or longjmp-resume |
| 5199 | breakpoint per thread, so we should never be setting a new |
| 5200 | step_resume_breakpoint when one is already active. */ |
| 5201 | gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL); |
| 5202 | |
| 5203 | if (debug_infrun) |
| 5204 | fprintf_unfiltered (gdb_stdlog, |
| 5205 | "infrun: inserting step-resume breakpoint at %s\n", |
| 5206 | paddress (gdbarch, sr_sal.pc)); |
| 5207 | |
| 5208 | inferior_thread ()->control.step_resume_breakpoint |
| 5209 | = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, bp_step_resume); |
| 5210 | } |
| 5211 | |
| 5212 | /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used |
| 5213 | to skip a potential signal handler. |
| 5214 | |
| 5215 | This is called with the interrupted function's frame. The signal |
| 5216 | handler, when it returns, will resume the interrupted function at |
| 5217 | RETURN_FRAME.pc. */ |
| 5218 | |
| 5219 | static void |
| 5220 | insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame) |
| 5221 | { |
| 5222 | struct symtab_and_line sr_sal; |
| 5223 | struct gdbarch *gdbarch; |
| 5224 | |
| 5225 | gdb_assert (return_frame != NULL); |
| 5226 | init_sal (&sr_sal); /* initialize to zeros */ |
| 5227 | |
| 5228 | gdbarch = get_frame_arch (return_frame); |
| 5229 | sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame)); |
| 5230 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
| 5231 | sr_sal.pspace = get_frame_program_space (return_frame); |
| 5232 | |
| 5233 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, |
| 5234 | get_stack_frame_id (return_frame)); |
| 5235 | } |
| 5236 | |
| 5237 | /* Similar to insert_step_resume_breakpoint_at_frame, except |
| 5238 | but a breakpoint at the previous frame's PC. This is used to |
| 5239 | skip a function after stepping into it (for "next" or if the called |
| 5240 | function has no debugging information). |
| 5241 | |
| 5242 | The current function has almost always been reached by single |
| 5243 | stepping a call or return instruction. NEXT_FRAME belongs to the |
| 5244 | current function, and the breakpoint will be set at the caller's |
| 5245 | resume address. |
| 5246 | |
| 5247 | This is a separate function rather than reusing |
| 5248 | insert_step_resume_breakpoint_at_frame in order to avoid |
| 5249 | get_prev_frame, which may stop prematurely (see the implementation |
| 5250 | of frame_unwind_caller_id for an example). */ |
| 5251 | |
| 5252 | static void |
| 5253 | insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) |
| 5254 | { |
| 5255 | struct symtab_and_line sr_sal; |
| 5256 | struct gdbarch *gdbarch; |
| 5257 | |
| 5258 | /* We shouldn't have gotten here if we don't know where the call site |
| 5259 | is. */ |
| 5260 | gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame))); |
| 5261 | |
| 5262 | init_sal (&sr_sal); /* initialize to zeros */ |
| 5263 | |
| 5264 | gdbarch = frame_unwind_caller_arch (next_frame); |
| 5265 | sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, |
| 5266 | frame_unwind_caller_pc (next_frame)); |
| 5267 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
| 5268 | sr_sal.pspace = frame_unwind_program_space (next_frame); |
| 5269 | |
| 5270 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, |
| 5271 | frame_unwind_caller_id (next_frame)); |
| 5272 | } |
| 5273 | |
| 5274 | /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a |
| 5275 | new breakpoint at the target of a jmp_buf. The handling of |
| 5276 | longjmp-resume uses the same mechanisms used for handling |
| 5277 | "step-resume" breakpoints. */ |
| 5278 | |
| 5279 | static void |
| 5280 | insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 5281 | { |
| 5282 | /* There should never be more than one step-resume or longjmp-resume |
| 5283 | breakpoint per thread, so we should never be setting a new |
| 5284 | longjmp_resume_breakpoint when one is already active. */ |
| 5285 | gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL); |
| 5286 | |
| 5287 | if (debug_infrun) |
| 5288 | fprintf_unfiltered (gdb_stdlog, |
| 5289 | "infrun: inserting longjmp-resume breakpoint at %s\n", |
| 5290 | paddress (gdbarch, pc)); |
| 5291 | |
| 5292 | inferior_thread ()->control.step_resume_breakpoint = |
| 5293 | set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume); |
| 5294 | } |
| 5295 | |
| 5296 | /* Insert an exception resume breakpoint. TP is the thread throwing |
| 5297 | the exception. The block B is the block of the unwinder debug hook |
| 5298 | function. FRAME is the frame corresponding to the call to this |
| 5299 | function. SYM is the symbol of the function argument holding the |
| 5300 | target PC of the exception. */ |
| 5301 | |
| 5302 | static void |
| 5303 | insert_exception_resume_breakpoint (struct thread_info *tp, |
| 5304 | struct block *b, |
| 5305 | struct frame_info *frame, |
| 5306 | struct symbol *sym) |
| 5307 | { |
| 5308 | struct gdb_exception e; |
| 5309 | |
| 5310 | /* We want to ignore errors here. */ |
| 5311 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 5312 | { |
| 5313 | struct symbol *vsym; |
| 5314 | struct value *value; |
| 5315 | CORE_ADDR handler; |
| 5316 | struct breakpoint *bp; |
| 5317 | |
| 5318 | vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL); |
| 5319 | value = read_var_value (vsym, frame); |
| 5320 | /* If the value was optimized out, revert to the old behavior. */ |
| 5321 | if (! value_optimized_out (value)) |
| 5322 | { |
| 5323 | handler = value_as_address (value); |
| 5324 | |
| 5325 | if (debug_infrun) |
| 5326 | fprintf_unfiltered (gdb_stdlog, |
| 5327 | "infrun: exception resume at %lx\n", |
| 5328 | (unsigned long) handler); |
| 5329 | |
| 5330 | bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), |
| 5331 | handler, bp_exception_resume); |
| 5332 | bp->thread = tp->num; |
| 5333 | inferior_thread ()->control.exception_resume_breakpoint = bp; |
| 5334 | } |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | /* This is called when an exception has been intercepted. Check to |
| 5339 | see whether the exception's destination is of interest, and if so, |
| 5340 | set an exception resume breakpoint there. */ |
| 5341 | |
| 5342 | static void |
| 5343 | check_exception_resume (struct execution_control_state *ecs, |
| 5344 | struct frame_info *frame, struct symbol *func) |
| 5345 | { |
| 5346 | struct gdb_exception e; |
| 5347 | |
| 5348 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 5349 | { |
| 5350 | struct block *b; |
| 5351 | struct dict_iterator iter; |
| 5352 | struct symbol *sym; |
| 5353 | int argno = 0; |
| 5354 | |
| 5355 | /* The exception breakpoint is a thread-specific breakpoint on |
| 5356 | the unwinder's debug hook, declared as: |
| 5357 | |
| 5358 | void _Unwind_DebugHook (void *cfa, void *handler); |
| 5359 | |
| 5360 | The CFA argument indicates the frame to which control is |
| 5361 | about to be transferred. HANDLER is the destination PC. |
| 5362 | |
| 5363 | We ignore the CFA and set a temporary breakpoint at HANDLER. |
| 5364 | This is not extremely efficient but it avoids issues in gdb |
| 5365 | with computing the DWARF CFA, and it also works even in weird |
| 5366 | cases such as throwing an exception from inside a signal |
| 5367 | handler. */ |
| 5368 | |
| 5369 | b = SYMBOL_BLOCK_VALUE (func); |
| 5370 | ALL_BLOCK_SYMBOLS (b, iter, sym) |
| 5371 | { |
| 5372 | if (!SYMBOL_IS_ARGUMENT (sym)) |
| 5373 | continue; |
| 5374 | |
| 5375 | if (argno == 0) |
| 5376 | ++argno; |
| 5377 | else |
| 5378 | { |
| 5379 | insert_exception_resume_breakpoint (ecs->event_thread, |
| 5380 | b, frame, sym); |
| 5381 | break; |
| 5382 | } |
| 5383 | } |
| 5384 | } |
| 5385 | } |
| 5386 | |
| 5387 | static void |
| 5388 | stop_stepping (struct execution_control_state *ecs) |
| 5389 | { |
| 5390 | if (debug_infrun) |
| 5391 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n"); |
| 5392 | |
| 5393 | /* Let callers know we don't want to wait for the inferior anymore. */ |
| 5394 | ecs->wait_some_more = 0; |
| 5395 | } |
| 5396 | |
| 5397 | /* This function handles various cases where we need to continue |
| 5398 | waiting for the inferior. */ |
| 5399 | /* (Used to be the keep_going: label in the old wait_for_inferior). */ |
| 5400 | |
| 5401 | static void |
| 5402 | keep_going (struct execution_control_state *ecs) |
| 5403 | { |
| 5404 | /* Make sure normal_stop is called if we get a QUIT handled before |
| 5405 | reaching resume. */ |
| 5406 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
| 5407 | |
| 5408 | /* Save the pc before execution, to compare with pc after stop. */ |
| 5409 | ecs->event_thread->prev_pc |
| 5410 | = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
| 5411 | |
| 5412 | /* If we did not do break;, it means we should keep running the |
| 5413 | inferior and not return to debugger. */ |
| 5414 | |
| 5415 | if (ecs->event_thread->control.trap_expected |
| 5416 | && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP) |
| 5417 | { |
| 5418 | /* We took a signal (which we are supposed to pass through to |
| 5419 | the inferior, else we'd not get here) and we haven't yet |
| 5420 | gotten our trap. Simply continue. */ |
| 5421 | |
| 5422 | discard_cleanups (old_cleanups); |
| 5423 | resume (currently_stepping (ecs->event_thread), |
| 5424 | ecs->event_thread->suspend.stop_signal); |
| 5425 | } |
| 5426 | else |
| 5427 | { |
| 5428 | /* Either the trap was not expected, but we are continuing |
| 5429 | anyway (the user asked that this signal be passed to the |
| 5430 | child) |
| 5431 | -- or -- |
| 5432 | The signal was SIGTRAP, e.g. it was our signal, but we |
| 5433 | decided we should resume from it. |
| 5434 | |
| 5435 | We're going to run this baby now! |
| 5436 | |
| 5437 | Note that insert_breakpoints won't try to re-insert |
| 5438 | already inserted breakpoints. Therefore, we don't |
| 5439 | care if breakpoints were already inserted, or not. */ |
| 5440 | |
| 5441 | if (ecs->event_thread->stepping_over_breakpoint) |
| 5442 | { |
| 5443 | struct regcache *thread_regcache = get_thread_regcache (ecs->ptid); |
| 5444 | |
| 5445 | if (!use_displaced_stepping (get_regcache_arch (thread_regcache))) |
| 5446 | /* Since we can't do a displaced step, we have to remove |
| 5447 | the breakpoint while we step it. To keep things |
| 5448 | simple, we remove them all. */ |
| 5449 | remove_breakpoints (); |
| 5450 | } |
| 5451 | else |
| 5452 | { |
| 5453 | struct gdb_exception e; |
| 5454 | |
| 5455 | /* Stop stepping when inserting breakpoints |
| 5456 | has failed. */ |
| 5457 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 5458 | { |
| 5459 | insert_breakpoints (); |
| 5460 | } |
| 5461 | if (e.reason < 0) |
| 5462 | { |
| 5463 | exception_print (gdb_stderr, e); |
| 5464 | stop_stepping (ecs); |
| 5465 | return; |
| 5466 | } |
| 5467 | } |
| 5468 | |
| 5469 | ecs->event_thread->control.trap_expected |
| 5470 | = ecs->event_thread->stepping_over_breakpoint; |
| 5471 | |
| 5472 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly |
| 5473 | specifies that such a signal should be delivered to the |
| 5474 | target program). |
| 5475 | |
| 5476 | Typically, this would occure when a user is debugging a |
| 5477 | target monitor on a simulator: the target monitor sets a |
| 5478 | breakpoint; the simulator encounters this break-point and |
| 5479 | halts the simulation handing control to GDB; GDB, noteing |
| 5480 | that the break-point isn't valid, returns control back to the |
| 5481 | simulator; the simulator then delivers the hardware |
| 5482 | equivalent of a SIGNAL_TRAP to the program being debugged. */ |
| 5483 | |
| 5484 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
| 5485 | && !signal_program[ecs->event_thread->suspend.stop_signal]) |
| 5486 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
| 5487 | |
| 5488 | discard_cleanups (old_cleanups); |
| 5489 | resume (currently_stepping (ecs->event_thread), |
| 5490 | ecs->event_thread->suspend.stop_signal); |
| 5491 | } |
| 5492 | |
| 5493 | prepare_to_wait (ecs); |
| 5494 | } |
| 5495 | |
| 5496 | /* This function normally comes after a resume, before |
| 5497 | handle_inferior_event exits. It takes care of any last bits of |
| 5498 | housekeeping, and sets the all-important wait_some_more flag. */ |
| 5499 | |
| 5500 | static void |
| 5501 | prepare_to_wait (struct execution_control_state *ecs) |
| 5502 | { |
| 5503 | if (debug_infrun) |
| 5504 | fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); |
| 5505 | |
| 5506 | /* This is the old end of the while loop. Let everybody know we |
| 5507 | want to wait for the inferior some more and get called again |
| 5508 | soon. */ |
| 5509 | ecs->wait_some_more = 1; |
| 5510 | } |
| 5511 | |
| 5512 | /* Several print_*_reason functions to print why the inferior has stopped. |
| 5513 | We always print something when the inferior exits, or receives a signal. |
| 5514 | The rest of the cases are dealt with later on in normal_stop and |
| 5515 | print_it_typical. Ideally there should be a call to one of these |
| 5516 | print_*_reason functions functions from handle_inferior_event each time |
| 5517 | stop_stepping is called. */ |
| 5518 | |
| 5519 | /* Print why the inferior has stopped. |
| 5520 | We are done with a step/next/si/ni command, print why the inferior has |
| 5521 | stopped. For now print nothing. Print a message only if not in the middle |
| 5522 | of doing a "step n" operation for n > 1. */ |
| 5523 | |
| 5524 | static void |
| 5525 | print_end_stepping_range_reason (void) |
| 5526 | { |
| 5527 | if ((!inferior_thread ()->step_multi |
| 5528 | || !inferior_thread ()->control.stop_step) |
| 5529 | && ui_out_is_mi_like_p (uiout)) |
| 5530 | ui_out_field_string (uiout, "reason", |
| 5531 | async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); |
| 5532 | } |
| 5533 | |
| 5534 | /* The inferior was terminated by a signal, print why it stopped. */ |
| 5535 | |
| 5536 | static void |
| 5537 | print_signal_exited_reason (enum target_signal siggnal) |
| 5538 | { |
| 5539 | annotate_signalled (); |
| 5540 | if (ui_out_is_mi_like_p (uiout)) |
| 5541 | ui_out_field_string |
| 5542 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); |
| 5543 | ui_out_text (uiout, "\nProgram terminated with signal "); |
| 5544 | annotate_signal_name (); |
| 5545 | ui_out_field_string (uiout, "signal-name", |
| 5546 | target_signal_to_name (siggnal)); |
| 5547 | annotate_signal_name_end (); |
| 5548 | ui_out_text (uiout, ", "); |
| 5549 | annotate_signal_string (); |
| 5550 | ui_out_field_string (uiout, "signal-meaning", |
| 5551 | target_signal_to_string (siggnal)); |
| 5552 | annotate_signal_string_end (); |
| 5553 | ui_out_text (uiout, ".\n"); |
| 5554 | ui_out_text (uiout, "The program no longer exists.\n"); |
| 5555 | } |
| 5556 | |
| 5557 | /* The inferior program is finished, print why it stopped. */ |
| 5558 | |
| 5559 | static void |
| 5560 | print_exited_reason (int exitstatus) |
| 5561 | { |
| 5562 | struct inferior *inf = current_inferior (); |
| 5563 | const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid)); |
| 5564 | |
| 5565 | annotate_exited (exitstatus); |
| 5566 | if (exitstatus) |
| 5567 | { |
| 5568 | if (ui_out_is_mi_like_p (uiout)) |
| 5569 | ui_out_field_string (uiout, "reason", |
| 5570 | async_reason_lookup (EXEC_ASYNC_EXITED)); |
| 5571 | ui_out_text (uiout, "[Inferior "); |
| 5572 | ui_out_text (uiout, plongest (inf->num)); |
| 5573 | ui_out_text (uiout, " ("); |
| 5574 | ui_out_text (uiout, pidstr); |
| 5575 | ui_out_text (uiout, ") exited with code "); |
| 5576 | ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus); |
| 5577 | ui_out_text (uiout, "]\n"); |
| 5578 | } |
| 5579 | else |
| 5580 | { |
| 5581 | if (ui_out_is_mi_like_p (uiout)) |
| 5582 | ui_out_field_string |
| 5583 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); |
| 5584 | ui_out_text (uiout, "[Inferior "); |
| 5585 | ui_out_text (uiout, plongest (inf->num)); |
| 5586 | ui_out_text (uiout, " ("); |
| 5587 | ui_out_text (uiout, pidstr); |
| 5588 | ui_out_text (uiout, ") exited normally]\n"); |
| 5589 | } |
| 5590 | /* Support the --return-child-result option. */ |
| 5591 | return_child_result_value = exitstatus; |
| 5592 | } |
| 5593 | |
| 5594 | /* Signal received, print why the inferior has stopped. The signal table |
| 5595 | tells us to print about it. */ |
| 5596 | |
| 5597 | static void |
| 5598 | print_signal_received_reason (enum target_signal siggnal) |
| 5599 | { |
| 5600 | annotate_signal (); |
| 5601 | |
| 5602 | if (siggnal == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout)) |
| 5603 | { |
| 5604 | struct thread_info *t = inferior_thread (); |
| 5605 | |
| 5606 | ui_out_text (uiout, "\n["); |
| 5607 | ui_out_field_string (uiout, "thread-name", |
| 5608 | target_pid_to_str (t->ptid)); |
| 5609 | ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num); |
| 5610 | ui_out_text (uiout, " stopped"); |
| 5611 | } |
| 5612 | else |
| 5613 | { |
| 5614 | ui_out_text (uiout, "\nProgram received signal "); |
| 5615 | annotate_signal_name (); |
| 5616 | if (ui_out_is_mi_like_p (uiout)) |
| 5617 | ui_out_field_string |
| 5618 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); |
| 5619 | ui_out_field_string (uiout, "signal-name", |
| 5620 | target_signal_to_name (siggnal)); |
| 5621 | annotate_signal_name_end (); |
| 5622 | ui_out_text (uiout, ", "); |
| 5623 | annotate_signal_string (); |
| 5624 | ui_out_field_string (uiout, "signal-meaning", |
| 5625 | target_signal_to_string (siggnal)); |
| 5626 | annotate_signal_string_end (); |
| 5627 | } |
| 5628 | ui_out_text (uiout, ".\n"); |
| 5629 | } |
| 5630 | |
| 5631 | /* Reverse execution: target ran out of history info, print why the inferior |
| 5632 | has stopped. */ |
| 5633 | |
| 5634 | static void |
| 5635 | print_no_history_reason (void) |
| 5636 | { |
| 5637 | ui_out_text (uiout, "\nNo more reverse-execution history.\n"); |
| 5638 | } |
| 5639 | |
| 5640 | /* Here to return control to GDB when the inferior stops for real. |
| 5641 | Print appropriate messages, remove breakpoints, give terminal our modes. |
| 5642 | |
| 5643 | STOP_PRINT_FRAME nonzero means print the executing frame |
| 5644 | (pc, function, args, file, line number and line text). |
| 5645 | BREAKPOINTS_FAILED nonzero means stop was due to error |
| 5646 | attempting to insert breakpoints. */ |
| 5647 | |
| 5648 | void |
| 5649 | normal_stop (void) |
| 5650 | { |
| 5651 | struct target_waitstatus last; |
| 5652 | ptid_t last_ptid; |
| 5653 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
| 5654 | |
| 5655 | get_last_target_status (&last_ptid, &last); |
| 5656 | |
| 5657 | /* If an exception is thrown from this point on, make sure to |
| 5658 | propagate GDB's knowledge of the executing state to the |
| 5659 | frontend/user running state. A QUIT is an easy exception to see |
| 5660 | here, so do this before any filtered output. */ |
| 5661 | if (!non_stop) |
| 5662 | make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); |
| 5663 | else if (last.kind != TARGET_WAITKIND_SIGNALLED |
| 5664 | && last.kind != TARGET_WAITKIND_EXITED) |
| 5665 | make_cleanup (finish_thread_state_cleanup, &inferior_ptid); |
| 5666 | |
| 5667 | /* In non-stop mode, we don't want GDB to switch threads behind the |
| 5668 | user's back, to avoid races where the user is typing a command to |
| 5669 | apply to thread x, but GDB switches to thread y before the user |
| 5670 | finishes entering the command. */ |
| 5671 | |
| 5672 | /* As with the notification of thread events, we want to delay |
| 5673 | notifying the user that we've switched thread context until |
| 5674 | the inferior actually stops. |
| 5675 | |
| 5676 | There's no point in saying anything if the inferior has exited. |
| 5677 | Note that SIGNALLED here means "exited with a signal", not |
| 5678 | "received a signal". */ |
| 5679 | if (!non_stop |
| 5680 | && !ptid_equal (previous_inferior_ptid, inferior_ptid) |
| 5681 | && target_has_execution |
| 5682 | && last.kind != TARGET_WAITKIND_SIGNALLED |
| 5683 | && last.kind != TARGET_WAITKIND_EXITED) |
| 5684 | { |
| 5685 | target_terminal_ours_for_output (); |
| 5686 | printf_filtered (_("[Switching to %s]\n"), |
| 5687 | target_pid_to_str (inferior_ptid)); |
| 5688 | annotate_thread_changed (); |
| 5689 | previous_inferior_ptid = inferior_ptid; |
| 5690 | } |
| 5691 | |
| 5692 | if (!breakpoints_always_inserted_mode () && target_has_execution) |
| 5693 | { |
| 5694 | if (remove_breakpoints ()) |
| 5695 | { |
| 5696 | target_terminal_ours_for_output (); |
| 5697 | printf_filtered (_("Cannot remove breakpoints because " |
| 5698 | "program is no longer writable.\nFurther " |
| 5699 | "execution is probably impossible.\n")); |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | /* If an auto-display called a function and that got a signal, |
| 5704 | delete that auto-display to avoid an infinite recursion. */ |
| 5705 | |
| 5706 | if (stopped_by_random_signal) |
| 5707 | disable_current_display (); |
| 5708 | |
| 5709 | /* Don't print a message if in the middle of doing a "step n" |
| 5710 | operation for n > 1 */ |
| 5711 | if (target_has_execution |
| 5712 | && last.kind != TARGET_WAITKIND_SIGNALLED |
| 5713 | && last.kind != TARGET_WAITKIND_EXITED |
| 5714 | && inferior_thread ()->step_multi |
| 5715 | && inferior_thread ()->control.stop_step) |
| 5716 | goto done; |
| 5717 | |
| 5718 | target_terminal_ours (); |
| 5719 | |
| 5720 | /* Set the current source location. This will also happen if we |
| 5721 | display the frame below, but the current SAL will be incorrect |
| 5722 | during a user hook-stop function. */ |
| 5723 | if (has_stack_frames () && !stop_stack_dummy) |
| 5724 | set_current_sal_from_frame (get_current_frame (), 1); |
| 5725 | |
| 5726 | /* Let the user/frontend see the threads as stopped. */ |
| 5727 | do_cleanups (old_chain); |
| 5728 | |
| 5729 | /* Look up the hook_stop and run it (CLI internally handles problem |
| 5730 | of stop_command's pre-hook not existing). */ |
| 5731 | if (stop_command) |
| 5732 | catch_errors (hook_stop_stub, stop_command, |
| 5733 | "Error while running hook_stop:\n", RETURN_MASK_ALL); |
| 5734 | |
| 5735 | if (!has_stack_frames ()) |
| 5736 | goto done; |
| 5737 | |
| 5738 | if (last.kind == TARGET_WAITKIND_SIGNALLED |
| 5739 | || last.kind == TARGET_WAITKIND_EXITED) |
| 5740 | goto done; |
| 5741 | |
| 5742 | /* Select innermost stack frame - i.e., current frame is frame 0, |
| 5743 | and current location is based on that. |
| 5744 | Don't do this on return from a stack dummy routine, |
| 5745 | or if the program has exited. */ |
| 5746 | |
| 5747 | if (!stop_stack_dummy) |
| 5748 | { |
| 5749 | select_frame (get_current_frame ()); |
| 5750 | |
| 5751 | /* Print current location without a level number, if |
| 5752 | we have changed functions or hit a breakpoint. |
| 5753 | Print source line if we have one. |
| 5754 | bpstat_print() contains the logic deciding in detail |
| 5755 | what to print, based on the event(s) that just occurred. */ |
| 5756 | |
| 5757 | /* If --batch-silent is enabled then there's no need to print the current |
| 5758 | source location, and to try risks causing an error message about |
| 5759 | missing source files. */ |
| 5760 | if (stop_print_frame && !batch_silent) |
| 5761 | { |
| 5762 | int bpstat_ret; |
| 5763 | int source_flag; |
| 5764 | int do_frame_printing = 1; |
| 5765 | struct thread_info *tp = inferior_thread (); |
| 5766 | |
| 5767 | bpstat_ret = bpstat_print (tp->control.stop_bpstat); |
| 5768 | switch (bpstat_ret) |
| 5769 | { |
| 5770 | case PRINT_UNKNOWN: |
| 5771 | /* If we had hit a shared library event breakpoint, |
| 5772 | bpstat_print would print out this message. If we hit |
| 5773 | an OS-level shared library event, do the same |
| 5774 | thing. */ |
| 5775 | if (last.kind == TARGET_WAITKIND_LOADED) |
| 5776 | { |
| 5777 | printf_filtered (_("Stopped due to shared library event\n")); |
| 5778 | source_flag = SRC_LINE; /* something bogus */ |
| 5779 | do_frame_printing = 0; |
| 5780 | break; |
| 5781 | } |
| 5782 | |
| 5783 | /* FIXME: cagney/2002-12-01: Given that a frame ID does |
| 5784 | (or should) carry around the function and does (or |
| 5785 | should) use that when doing a frame comparison. */ |
| 5786 | if (tp->control.stop_step |
| 5787 | && frame_id_eq (tp->control.step_frame_id, |
| 5788 | get_frame_id (get_current_frame ())) |
| 5789 | && step_start_function == find_pc_function (stop_pc)) |
| 5790 | source_flag = SRC_LINE; /* Finished step, just |
| 5791 | print source line. */ |
| 5792 | else |
| 5793 | source_flag = SRC_AND_LOC; /* Print location and |
| 5794 | source line. */ |
| 5795 | break; |
| 5796 | case PRINT_SRC_AND_LOC: |
| 5797 | source_flag = SRC_AND_LOC; /* Print location and |
| 5798 | source line. */ |
| 5799 | break; |
| 5800 | case PRINT_SRC_ONLY: |
| 5801 | source_flag = SRC_LINE; |
| 5802 | break; |
| 5803 | case PRINT_NOTHING: |
| 5804 | source_flag = SRC_LINE; /* something bogus */ |
| 5805 | do_frame_printing = 0; |
| 5806 | break; |
| 5807 | default: |
| 5808 | internal_error (__FILE__, __LINE__, _("Unknown value.")); |
| 5809 | } |
| 5810 | |
| 5811 | /* The behavior of this routine with respect to the source |
| 5812 | flag is: |
| 5813 | SRC_LINE: Print only source line |
| 5814 | LOCATION: Print only location |
| 5815 | SRC_AND_LOC: Print location and source line. */ |
| 5816 | if (do_frame_printing) |
| 5817 | print_stack_frame (get_selected_frame (NULL), 0, source_flag); |
| 5818 | |
| 5819 | /* Display the auto-display expressions. */ |
| 5820 | do_displays (); |
| 5821 | } |
| 5822 | } |
| 5823 | |
| 5824 | /* Save the function value return registers, if we care. |
| 5825 | We might be about to restore their previous contents. */ |
| 5826 | if (inferior_thread ()->control.proceed_to_finish) |
| 5827 | { |
| 5828 | /* This should not be necessary. */ |
| 5829 | if (stop_registers) |
| 5830 | regcache_xfree (stop_registers); |
| 5831 | |
| 5832 | /* NB: The copy goes through to the target picking up the value of |
| 5833 | all the registers. */ |
| 5834 | stop_registers = regcache_dup (get_current_regcache ()); |
| 5835 | } |
| 5836 | |
| 5837 | if (stop_stack_dummy == STOP_STACK_DUMMY) |
| 5838 | { |
| 5839 | /* Pop the empty frame that contains the stack dummy. |
| 5840 | This also restores inferior state prior to the call |
| 5841 | (struct infcall_suspend_state). */ |
| 5842 | struct frame_info *frame = get_current_frame (); |
| 5843 | |
| 5844 | gdb_assert (get_frame_type (frame) == DUMMY_FRAME); |
| 5845 | frame_pop (frame); |
| 5846 | /* frame_pop() calls reinit_frame_cache as the last thing it |
| 5847 | does which means there's currently no selected frame. We |
| 5848 | don't need to re-establish a selected frame if the dummy call |
| 5849 | returns normally, that will be done by |
| 5850 | restore_infcall_control_state. However, we do have to handle |
| 5851 | the case where the dummy call is returning after being |
| 5852 | stopped (e.g. the dummy call previously hit a breakpoint). |
| 5853 | We can't know which case we have so just always re-establish |
| 5854 | a selected frame here. */ |
| 5855 | select_frame (get_current_frame ()); |
| 5856 | } |
| 5857 | |
| 5858 | done: |
| 5859 | annotate_stopped (); |
| 5860 | |
| 5861 | /* Suppress the stop observer if we're in the middle of: |
| 5862 | |
| 5863 | - a step n (n > 1), as there still more steps to be done. |
| 5864 | |
| 5865 | - a "finish" command, as the observer will be called in |
| 5866 | finish_command_continuation, so it can include the inferior |
| 5867 | function's return value. |
| 5868 | |
| 5869 | - calling an inferior function, as we pretend we inferior didn't |
| 5870 | run at all. The return value of the call is handled by the |
| 5871 | expression evaluator, through call_function_by_hand. */ |
| 5872 | |
| 5873 | if (!target_has_execution |
| 5874 | || last.kind == TARGET_WAITKIND_SIGNALLED |
| 5875 | || last.kind == TARGET_WAITKIND_EXITED |
| 5876 | || (!inferior_thread ()->step_multi |
| 5877 | && !(inferior_thread ()->control.stop_bpstat |
| 5878 | && inferior_thread ()->control.proceed_to_finish) |
| 5879 | && !inferior_thread ()->control.in_infcall)) |
| 5880 | { |
| 5881 | if (!ptid_equal (inferior_ptid, null_ptid)) |
| 5882 | observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat, |
| 5883 | stop_print_frame); |
| 5884 | else |
| 5885 | observer_notify_normal_stop (NULL, stop_print_frame); |
| 5886 | } |
| 5887 | |
| 5888 | if (target_has_execution) |
| 5889 | { |
| 5890 | if (last.kind != TARGET_WAITKIND_SIGNALLED |
| 5891 | && last.kind != TARGET_WAITKIND_EXITED) |
| 5892 | /* Delete the breakpoint we stopped at, if it wants to be deleted. |
| 5893 | Delete any breakpoint that is to be deleted at the next stop. */ |
| 5894 | breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat); |
| 5895 | } |
| 5896 | |
| 5897 | /* Try to get rid of automatically added inferiors that are no |
| 5898 | longer needed. Keeping those around slows down things linearly. |
| 5899 | Note that this never removes the current inferior. */ |
| 5900 | prune_inferiors (); |
| 5901 | } |
| 5902 | |
| 5903 | static int |
| 5904 | hook_stop_stub (void *cmd) |
| 5905 | { |
| 5906 | execute_cmd_pre_hook ((struct cmd_list_element *) cmd); |
| 5907 | return (0); |
| 5908 | } |
| 5909 | \f |
| 5910 | int |
| 5911 | signal_stop_state (int signo) |
| 5912 | { |
| 5913 | return signal_stop[signo]; |
| 5914 | } |
| 5915 | |
| 5916 | int |
| 5917 | signal_print_state (int signo) |
| 5918 | { |
| 5919 | return signal_print[signo]; |
| 5920 | } |
| 5921 | |
| 5922 | int |
| 5923 | signal_pass_state (int signo) |
| 5924 | { |
| 5925 | return signal_program[signo]; |
| 5926 | } |
| 5927 | |
| 5928 | static void |
| 5929 | signal_cache_update (int signo) |
| 5930 | { |
| 5931 | if (signo == -1) |
| 5932 | { |
| 5933 | for (signo = 0; signo < (int) TARGET_SIGNAL_LAST; signo++) |
| 5934 | signal_cache_update (signo); |
| 5935 | |
| 5936 | return; |
| 5937 | } |
| 5938 | |
| 5939 | signal_pass[signo] = (signal_stop[signo] == 0 |
| 5940 | && signal_print[signo] == 0 |
| 5941 | && signal_program[signo] == 1); |
| 5942 | } |
| 5943 | |
| 5944 | int |
| 5945 | signal_stop_update (int signo, int state) |
| 5946 | { |
| 5947 | int ret = signal_stop[signo]; |
| 5948 | |
| 5949 | signal_stop[signo] = state; |
| 5950 | signal_cache_update (signo); |
| 5951 | return ret; |
| 5952 | } |
| 5953 | |
| 5954 | int |
| 5955 | signal_print_update (int signo, int state) |
| 5956 | { |
| 5957 | int ret = signal_print[signo]; |
| 5958 | |
| 5959 | signal_print[signo] = state; |
| 5960 | signal_cache_update (signo); |
| 5961 | return ret; |
| 5962 | } |
| 5963 | |
| 5964 | int |
| 5965 | signal_pass_update (int signo, int state) |
| 5966 | { |
| 5967 | int ret = signal_program[signo]; |
| 5968 | |
| 5969 | signal_program[signo] = state; |
| 5970 | signal_cache_update (signo); |
| 5971 | return ret; |
| 5972 | } |
| 5973 | |
| 5974 | static void |
| 5975 | sig_print_header (void) |
| 5976 | { |
| 5977 | printf_filtered (_("Signal Stop\tPrint\tPass " |
| 5978 | "to program\tDescription\n")); |
| 5979 | } |
| 5980 | |
| 5981 | static void |
| 5982 | sig_print_info (enum target_signal oursig) |
| 5983 | { |
| 5984 | const char *name = target_signal_to_name (oursig); |
| 5985 | int name_padding = 13 - strlen (name); |
| 5986 | |
| 5987 | if (name_padding <= 0) |
| 5988 | name_padding = 0; |
| 5989 | |
| 5990 | printf_filtered ("%s", name); |
| 5991 | printf_filtered ("%*.*s ", name_padding, name_padding, " "); |
| 5992 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
| 5993 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); |
| 5994 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); |
| 5995 | printf_filtered ("%s\n", target_signal_to_string (oursig)); |
| 5996 | } |
| 5997 | |
| 5998 | /* Specify how various signals in the inferior should be handled. */ |
| 5999 | |
| 6000 | static void |
| 6001 | handle_command (char *args, int from_tty) |
| 6002 | { |
| 6003 | char **argv; |
| 6004 | int digits, wordlen; |
| 6005 | int sigfirst, signum, siglast; |
| 6006 | enum target_signal oursig; |
| 6007 | int allsigs; |
| 6008 | int nsigs; |
| 6009 | unsigned char *sigs; |
| 6010 | struct cleanup *old_chain; |
| 6011 | |
| 6012 | if (args == NULL) |
| 6013 | { |
| 6014 | error_no_arg (_("signal to handle")); |
| 6015 | } |
| 6016 | |
| 6017 | /* Allocate and zero an array of flags for which signals to handle. */ |
| 6018 | |
| 6019 | nsigs = (int) TARGET_SIGNAL_LAST; |
| 6020 | sigs = (unsigned char *) alloca (nsigs); |
| 6021 | memset (sigs, 0, nsigs); |
| 6022 | |
| 6023 | /* Break the command line up into args. */ |
| 6024 | |
| 6025 | argv = gdb_buildargv (args); |
| 6026 | old_chain = make_cleanup_freeargv (argv); |
| 6027 | |
| 6028 | /* Walk through the args, looking for signal oursigs, signal names, and |
| 6029 | actions. Signal numbers and signal names may be interspersed with |
| 6030 | actions, with the actions being performed for all signals cumulatively |
| 6031 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ |
| 6032 | |
| 6033 | while (*argv != NULL) |
| 6034 | { |
| 6035 | wordlen = strlen (*argv); |
| 6036 | for (digits = 0; isdigit ((*argv)[digits]); digits++) |
| 6037 | {; |
| 6038 | } |
| 6039 | allsigs = 0; |
| 6040 | sigfirst = siglast = -1; |
| 6041 | |
| 6042 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) |
| 6043 | { |
| 6044 | /* Apply action to all signals except those used by the |
| 6045 | debugger. Silently skip those. */ |
| 6046 | allsigs = 1; |
| 6047 | sigfirst = 0; |
| 6048 | siglast = nsigs - 1; |
| 6049 | } |
| 6050 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) |
| 6051 | { |
| 6052 | SET_SIGS (nsigs, sigs, signal_stop); |
| 6053 | SET_SIGS (nsigs, sigs, signal_print); |
| 6054 | } |
| 6055 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) |
| 6056 | { |
| 6057 | UNSET_SIGS (nsigs, sigs, signal_program); |
| 6058 | } |
| 6059 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) |
| 6060 | { |
| 6061 | SET_SIGS (nsigs, sigs, signal_print); |
| 6062 | } |
| 6063 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) |
| 6064 | { |
| 6065 | SET_SIGS (nsigs, sigs, signal_program); |
| 6066 | } |
| 6067 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) |
| 6068 | { |
| 6069 | UNSET_SIGS (nsigs, sigs, signal_stop); |
| 6070 | } |
| 6071 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) |
| 6072 | { |
| 6073 | SET_SIGS (nsigs, sigs, signal_program); |
| 6074 | } |
| 6075 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) |
| 6076 | { |
| 6077 | UNSET_SIGS (nsigs, sigs, signal_print); |
| 6078 | UNSET_SIGS (nsigs, sigs, signal_stop); |
| 6079 | } |
| 6080 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) |
| 6081 | { |
| 6082 | UNSET_SIGS (nsigs, sigs, signal_program); |
| 6083 | } |
| 6084 | else if (digits > 0) |
| 6085 | { |
| 6086 | /* It is numeric. The numeric signal refers to our own |
| 6087 | internal signal numbering from target.h, not to host/target |
| 6088 | signal number. This is a feature; users really should be |
| 6089 | using symbolic names anyway, and the common ones like |
| 6090 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ |
| 6091 | |
| 6092 | sigfirst = siglast = (int) |
| 6093 | target_signal_from_command (atoi (*argv)); |
| 6094 | if ((*argv)[digits] == '-') |
| 6095 | { |
| 6096 | siglast = (int) |
| 6097 | target_signal_from_command (atoi ((*argv) + digits + 1)); |
| 6098 | } |
| 6099 | if (sigfirst > siglast) |
| 6100 | { |
| 6101 | /* Bet he didn't figure we'd think of this case... */ |
| 6102 | signum = sigfirst; |
| 6103 | sigfirst = siglast; |
| 6104 | siglast = signum; |
| 6105 | } |
| 6106 | } |
| 6107 | else |
| 6108 | { |
| 6109 | oursig = target_signal_from_name (*argv); |
| 6110 | if (oursig != TARGET_SIGNAL_UNKNOWN) |
| 6111 | { |
| 6112 | sigfirst = siglast = (int) oursig; |
| 6113 | } |
| 6114 | else |
| 6115 | { |
| 6116 | /* Not a number and not a recognized flag word => complain. */ |
| 6117 | error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); |
| 6118 | } |
| 6119 | } |
| 6120 | |
| 6121 | /* If any signal numbers or symbol names were found, set flags for |
| 6122 | which signals to apply actions to. */ |
| 6123 | |
| 6124 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) |
| 6125 | { |
| 6126 | switch ((enum target_signal) signum) |
| 6127 | { |
| 6128 | case TARGET_SIGNAL_TRAP: |
| 6129 | case TARGET_SIGNAL_INT: |
| 6130 | if (!allsigs && !sigs[signum]) |
| 6131 | { |
| 6132 | if (query (_("%s is used by the debugger.\n\ |
| 6133 | Are you sure you want to change it? "), |
| 6134 | target_signal_to_name ((enum target_signal) signum))) |
| 6135 | { |
| 6136 | sigs[signum] = 1; |
| 6137 | } |
| 6138 | else |
| 6139 | { |
| 6140 | printf_unfiltered (_("Not confirmed, unchanged.\n")); |
| 6141 | gdb_flush (gdb_stdout); |
| 6142 | } |
| 6143 | } |
| 6144 | break; |
| 6145 | case TARGET_SIGNAL_0: |
| 6146 | case TARGET_SIGNAL_DEFAULT: |
| 6147 | case TARGET_SIGNAL_UNKNOWN: |
| 6148 | /* Make sure that "all" doesn't print these. */ |
| 6149 | break; |
| 6150 | default: |
| 6151 | sigs[signum] = 1; |
| 6152 | break; |
| 6153 | } |
| 6154 | } |
| 6155 | |
| 6156 | argv++; |
| 6157 | } |
| 6158 | |
| 6159 | for (signum = 0; signum < nsigs; signum++) |
| 6160 | if (sigs[signum]) |
| 6161 | { |
| 6162 | signal_cache_update (-1); |
| 6163 | target_pass_signals ((int) TARGET_SIGNAL_LAST, signal_pass); |
| 6164 | |
| 6165 | if (from_tty) |
| 6166 | { |
| 6167 | /* Show the results. */ |
| 6168 | sig_print_header (); |
| 6169 | for (; signum < nsigs; signum++) |
| 6170 | if (sigs[signum]) |
| 6171 | sig_print_info (signum); |
| 6172 | } |
| 6173 | |
| 6174 | break; |
| 6175 | } |
| 6176 | |
| 6177 | do_cleanups (old_chain); |
| 6178 | } |
| 6179 | |
| 6180 | static void |
| 6181 | xdb_handle_command (char *args, int from_tty) |
| 6182 | { |
| 6183 | char **argv; |
| 6184 | struct cleanup *old_chain; |
| 6185 | |
| 6186 | if (args == NULL) |
| 6187 | error_no_arg (_("xdb command")); |
| 6188 | |
| 6189 | /* Break the command line up into args. */ |
| 6190 | |
| 6191 | argv = gdb_buildargv (args); |
| 6192 | old_chain = make_cleanup_freeargv (argv); |
| 6193 | if (argv[1] != (char *) NULL) |
| 6194 | { |
| 6195 | char *argBuf; |
| 6196 | int bufLen; |
| 6197 | |
| 6198 | bufLen = strlen (argv[0]) + 20; |
| 6199 | argBuf = (char *) xmalloc (bufLen); |
| 6200 | if (argBuf) |
| 6201 | { |
| 6202 | int validFlag = 1; |
| 6203 | enum target_signal oursig; |
| 6204 | |
| 6205 | oursig = target_signal_from_name (argv[0]); |
| 6206 | memset (argBuf, 0, bufLen); |
| 6207 | if (strcmp (argv[1], "Q") == 0) |
| 6208 | sprintf (argBuf, "%s %s", argv[0], "noprint"); |
| 6209 | else |
| 6210 | { |
| 6211 | if (strcmp (argv[1], "s") == 0) |
| 6212 | { |
| 6213 | if (!signal_stop[oursig]) |
| 6214 | sprintf (argBuf, "%s %s", argv[0], "stop"); |
| 6215 | else |
| 6216 | sprintf (argBuf, "%s %s", argv[0], "nostop"); |
| 6217 | } |
| 6218 | else if (strcmp (argv[1], "i") == 0) |
| 6219 | { |
| 6220 | if (!signal_program[oursig]) |
| 6221 | sprintf (argBuf, "%s %s", argv[0], "pass"); |
| 6222 | else |
| 6223 | sprintf (argBuf, "%s %s", argv[0], "nopass"); |
| 6224 | } |
| 6225 | else if (strcmp (argv[1], "r") == 0) |
| 6226 | { |
| 6227 | if (!signal_print[oursig]) |
| 6228 | sprintf (argBuf, "%s %s", argv[0], "print"); |
| 6229 | else |
| 6230 | sprintf (argBuf, "%s %s", argv[0], "noprint"); |
| 6231 | } |
| 6232 | else |
| 6233 | validFlag = 0; |
| 6234 | } |
| 6235 | if (validFlag) |
| 6236 | handle_command (argBuf, from_tty); |
| 6237 | else |
| 6238 | printf_filtered (_("Invalid signal handling flag.\n")); |
| 6239 | if (argBuf) |
| 6240 | xfree (argBuf); |
| 6241 | } |
| 6242 | } |
| 6243 | do_cleanups (old_chain); |
| 6244 | } |
| 6245 | |
| 6246 | /* Print current contents of the tables set by the handle command. |
| 6247 | It is possible we should just be printing signals actually used |
| 6248 | by the current target (but for things to work right when switching |
| 6249 | targets, all signals should be in the signal tables). */ |
| 6250 | |
| 6251 | static void |
| 6252 | signals_info (char *signum_exp, int from_tty) |
| 6253 | { |
| 6254 | enum target_signal oursig; |
| 6255 | |
| 6256 | sig_print_header (); |
| 6257 | |
| 6258 | if (signum_exp) |
| 6259 | { |
| 6260 | /* First see if this is a symbol name. */ |
| 6261 | oursig = target_signal_from_name (signum_exp); |
| 6262 | if (oursig == TARGET_SIGNAL_UNKNOWN) |
| 6263 | { |
| 6264 | /* No, try numeric. */ |
| 6265 | oursig = |
| 6266 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
| 6267 | } |
| 6268 | sig_print_info (oursig); |
| 6269 | return; |
| 6270 | } |
| 6271 | |
| 6272 | printf_filtered ("\n"); |
| 6273 | /* These ugly casts brought to you by the native VAX compiler. */ |
| 6274 | for (oursig = TARGET_SIGNAL_FIRST; |
| 6275 | (int) oursig < (int) TARGET_SIGNAL_LAST; |
| 6276 | oursig = (enum target_signal) ((int) oursig + 1)) |
| 6277 | { |
| 6278 | QUIT; |
| 6279 | |
| 6280 | if (oursig != TARGET_SIGNAL_UNKNOWN |
| 6281 | && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) |
| 6282 | sig_print_info (oursig); |
| 6283 | } |
| 6284 | |
| 6285 | printf_filtered (_("\nUse the \"handle\" command " |
| 6286 | "to change these tables.\n")); |
| 6287 | } |
| 6288 | |
| 6289 | /* The $_siginfo convenience variable is a bit special. We don't know |
| 6290 | for sure the type of the value until we actually have a chance to |
| 6291 | fetch the data. The type can change depending on gdbarch, so it is |
| 6292 | also dependent on which thread you have selected. |
| 6293 | |
| 6294 | 1. making $_siginfo be an internalvar that creates a new value on |
| 6295 | access. |
| 6296 | |
| 6297 | 2. making the value of $_siginfo be an lval_computed value. */ |
| 6298 | |
| 6299 | /* This function implements the lval_computed support for reading a |
| 6300 | $_siginfo value. */ |
| 6301 | |
| 6302 | static void |
| 6303 | siginfo_value_read (struct value *v) |
| 6304 | { |
| 6305 | LONGEST transferred; |
| 6306 | |
| 6307 | transferred = |
| 6308 | target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, |
| 6309 | NULL, |
| 6310 | value_contents_all_raw (v), |
| 6311 | value_offset (v), |
| 6312 | TYPE_LENGTH (value_type (v))); |
| 6313 | |
| 6314 | if (transferred != TYPE_LENGTH (value_type (v))) |
| 6315 | error (_("Unable to read siginfo")); |
| 6316 | } |
| 6317 | |
| 6318 | /* This function implements the lval_computed support for writing a |
| 6319 | $_siginfo value. */ |
| 6320 | |
| 6321 | static void |
| 6322 | siginfo_value_write (struct value *v, struct value *fromval) |
| 6323 | { |
| 6324 | LONGEST transferred; |
| 6325 | |
| 6326 | transferred = target_write (¤t_target, |
| 6327 | TARGET_OBJECT_SIGNAL_INFO, |
| 6328 | NULL, |
| 6329 | value_contents_all_raw (fromval), |
| 6330 | value_offset (v), |
| 6331 | TYPE_LENGTH (value_type (fromval))); |
| 6332 | |
| 6333 | if (transferred != TYPE_LENGTH (value_type (fromval))) |
| 6334 | error (_("Unable to write siginfo")); |
| 6335 | } |
| 6336 | |
| 6337 | static struct lval_funcs siginfo_value_funcs = |
| 6338 | { |
| 6339 | siginfo_value_read, |
| 6340 | siginfo_value_write |
| 6341 | }; |
| 6342 | |
| 6343 | /* Return a new value with the correct type for the siginfo object of |
| 6344 | the current thread using architecture GDBARCH. Return a void value |
| 6345 | if there's no object available. */ |
| 6346 | |
| 6347 | static struct value * |
| 6348 | siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var) |
| 6349 | { |
| 6350 | if (target_has_stack |
| 6351 | && !ptid_equal (inferior_ptid, null_ptid) |
| 6352 | && gdbarch_get_siginfo_type_p (gdbarch)) |
| 6353 | { |
| 6354 | struct type *type = gdbarch_get_siginfo_type (gdbarch); |
| 6355 | |
| 6356 | return allocate_computed_value (type, &siginfo_value_funcs, NULL); |
| 6357 | } |
| 6358 | |
| 6359 | return allocate_value (builtin_type (gdbarch)->builtin_void); |
| 6360 | } |
| 6361 | |
| 6362 | \f |
| 6363 | /* infcall_suspend_state contains state about the program itself like its |
| 6364 | registers and any signal it received when it last stopped. |
| 6365 | This state must be restored regardless of how the inferior function call |
| 6366 | ends (either successfully, or after it hits a breakpoint or signal) |
| 6367 | if the program is to properly continue where it left off. */ |
| 6368 | |
| 6369 | struct infcall_suspend_state |
| 6370 | { |
| 6371 | struct thread_suspend_state thread_suspend; |
| 6372 | struct inferior_suspend_state inferior_suspend; |
| 6373 | |
| 6374 | /* Other fields: */ |
| 6375 | CORE_ADDR stop_pc; |
| 6376 | struct regcache *registers; |
| 6377 | |
| 6378 | /* Format of SIGINFO_DATA or NULL if it is not present. */ |
| 6379 | struct gdbarch *siginfo_gdbarch; |
| 6380 | |
| 6381 | /* The inferior format depends on SIGINFO_GDBARCH and it has a length of |
| 6382 | TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the |
| 6383 | content would be invalid. */ |
| 6384 | gdb_byte *siginfo_data; |
| 6385 | }; |
| 6386 | |
| 6387 | struct infcall_suspend_state * |
| 6388 | save_infcall_suspend_state (void) |
| 6389 | { |
| 6390 | struct infcall_suspend_state *inf_state; |
| 6391 | struct thread_info *tp = inferior_thread (); |
| 6392 | struct inferior *inf = current_inferior (); |
| 6393 | struct regcache *regcache = get_current_regcache (); |
| 6394 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 6395 | gdb_byte *siginfo_data = NULL; |
| 6396 | |
| 6397 | if (gdbarch_get_siginfo_type_p (gdbarch)) |
| 6398 | { |
| 6399 | struct type *type = gdbarch_get_siginfo_type (gdbarch); |
| 6400 | size_t len = TYPE_LENGTH (type); |
| 6401 | struct cleanup *back_to; |
| 6402 | |
| 6403 | siginfo_data = xmalloc (len); |
| 6404 | back_to = make_cleanup (xfree, siginfo_data); |
| 6405 | |
| 6406 | if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, |
| 6407 | siginfo_data, 0, len) == len) |
| 6408 | discard_cleanups (back_to); |
| 6409 | else |
| 6410 | { |
| 6411 | /* Errors ignored. */ |
| 6412 | do_cleanups (back_to); |
| 6413 | siginfo_data = NULL; |
| 6414 | } |
| 6415 | } |
| 6416 | |
| 6417 | inf_state = XZALLOC (struct infcall_suspend_state); |
| 6418 | |
| 6419 | if (siginfo_data) |
| 6420 | { |
| 6421 | inf_state->siginfo_gdbarch = gdbarch; |
| 6422 | inf_state->siginfo_data = siginfo_data; |
| 6423 | } |
| 6424 | |
| 6425 | inf_state->thread_suspend = tp->suspend; |
| 6426 | inf_state->inferior_suspend = inf->suspend; |
| 6427 | |
| 6428 | /* run_inferior_call will not use the signal due to its `proceed' call with |
| 6429 | TARGET_SIGNAL_0 anyway. */ |
| 6430 | tp->suspend.stop_signal = TARGET_SIGNAL_0; |
| 6431 | |
| 6432 | inf_state->stop_pc = stop_pc; |
| 6433 | |
| 6434 | inf_state->registers = regcache_dup (regcache); |
| 6435 | |
| 6436 | return inf_state; |
| 6437 | } |
| 6438 | |
| 6439 | /* Restore inferior session state to INF_STATE. */ |
| 6440 | |
| 6441 | void |
| 6442 | restore_infcall_suspend_state (struct infcall_suspend_state *inf_state) |
| 6443 | { |
| 6444 | struct thread_info *tp = inferior_thread (); |
| 6445 | struct inferior *inf = current_inferior (); |
| 6446 | struct regcache *regcache = get_current_regcache (); |
| 6447 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
| 6448 | |
| 6449 | tp->suspend = inf_state->thread_suspend; |
| 6450 | inf->suspend = inf_state->inferior_suspend; |
| 6451 | |
| 6452 | stop_pc = inf_state->stop_pc; |
| 6453 | |
| 6454 | if (inf_state->siginfo_gdbarch == gdbarch) |
| 6455 | { |
| 6456 | struct type *type = gdbarch_get_siginfo_type (gdbarch); |
| 6457 | size_t len = TYPE_LENGTH (type); |
| 6458 | |
| 6459 | /* Errors ignored. */ |
| 6460 | target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, |
| 6461 | inf_state->siginfo_data, 0, len); |
| 6462 | } |
| 6463 | |
| 6464 | /* The inferior can be gone if the user types "print exit(0)" |
| 6465 | (and perhaps other times). */ |
| 6466 | if (target_has_execution) |
| 6467 | /* NB: The register write goes through to the target. */ |
| 6468 | regcache_cpy (regcache, inf_state->registers); |
| 6469 | |
| 6470 | discard_infcall_suspend_state (inf_state); |
| 6471 | } |
| 6472 | |
| 6473 | static void |
| 6474 | do_restore_infcall_suspend_state_cleanup (void *state) |
| 6475 | { |
| 6476 | restore_infcall_suspend_state (state); |
| 6477 | } |
| 6478 | |
| 6479 | struct cleanup * |
| 6480 | make_cleanup_restore_infcall_suspend_state |
| 6481 | (struct infcall_suspend_state *inf_state) |
| 6482 | { |
| 6483 | return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state); |
| 6484 | } |
| 6485 | |
| 6486 | void |
| 6487 | discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) |
| 6488 | { |
| 6489 | regcache_xfree (inf_state->registers); |
| 6490 | xfree (inf_state->siginfo_data); |
| 6491 | xfree (inf_state); |
| 6492 | } |
| 6493 | |
| 6494 | struct regcache * |
| 6495 | get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state) |
| 6496 | { |
| 6497 | return inf_state->registers; |
| 6498 | } |
| 6499 | |
| 6500 | /* infcall_control_state contains state regarding gdb's control of the |
| 6501 | inferior itself like stepping control. It also contains session state like |
| 6502 | the user's currently selected frame. */ |
| 6503 | |
| 6504 | struct infcall_control_state |
| 6505 | { |
| 6506 | struct thread_control_state thread_control; |
| 6507 | struct inferior_control_state inferior_control; |
| 6508 | |
| 6509 | /* Other fields: */ |
| 6510 | enum stop_stack_kind stop_stack_dummy; |
| 6511 | int stopped_by_random_signal; |
| 6512 | int stop_after_trap; |
| 6513 | |
| 6514 | /* ID if the selected frame when the inferior function call was made. */ |
| 6515 | struct frame_id selected_frame_id; |
| 6516 | }; |
| 6517 | |
| 6518 | /* Save all of the information associated with the inferior<==>gdb |
| 6519 | connection. */ |
| 6520 | |
| 6521 | struct infcall_control_state * |
| 6522 | save_infcall_control_state (void) |
| 6523 | { |
| 6524 | struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status)); |
| 6525 | struct thread_info *tp = inferior_thread (); |
| 6526 | struct inferior *inf = current_inferior (); |
| 6527 | |
| 6528 | inf_status->thread_control = tp->control; |
| 6529 | inf_status->inferior_control = inf->control; |
| 6530 | |
| 6531 | tp->control.step_resume_breakpoint = NULL; |
| 6532 | tp->control.exception_resume_breakpoint = NULL; |
| 6533 | |
| 6534 | /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of |
| 6535 | chain. If caller's caller is walking the chain, they'll be happier if we |
| 6536 | hand them back the original chain when restore_infcall_control_state is |
| 6537 | called. */ |
| 6538 | tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat); |
| 6539 | |
| 6540 | /* Other fields: */ |
| 6541 | inf_status->stop_stack_dummy = stop_stack_dummy; |
| 6542 | inf_status->stopped_by_random_signal = stopped_by_random_signal; |
| 6543 | inf_status->stop_after_trap = stop_after_trap; |
| 6544 | |
| 6545 | inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); |
| 6546 | |
| 6547 | return inf_status; |
| 6548 | } |
| 6549 | |
| 6550 | static int |
| 6551 | restore_selected_frame (void *args) |
| 6552 | { |
| 6553 | struct frame_id *fid = (struct frame_id *) args; |
| 6554 | struct frame_info *frame; |
| 6555 | |
| 6556 | frame = frame_find_by_id (*fid); |
| 6557 | |
| 6558 | /* If inf_status->selected_frame_id is NULL, there was no previously |
| 6559 | selected frame. */ |
| 6560 | if (frame == NULL) |
| 6561 | { |
| 6562 | warning (_("Unable to restore previously selected frame.")); |
| 6563 | return 0; |
| 6564 | } |
| 6565 | |
| 6566 | select_frame (frame); |
| 6567 | |
| 6568 | return (1); |
| 6569 | } |
| 6570 | |
| 6571 | /* Restore inferior session state to INF_STATUS. */ |
| 6572 | |
| 6573 | void |
| 6574 | restore_infcall_control_state (struct infcall_control_state *inf_status) |
| 6575 | { |
| 6576 | struct thread_info *tp = inferior_thread (); |
| 6577 | struct inferior *inf = current_inferior (); |
| 6578 | |
| 6579 | if (tp->control.step_resume_breakpoint) |
| 6580 | tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop; |
| 6581 | |
| 6582 | if (tp->control.exception_resume_breakpoint) |
| 6583 | tp->control.exception_resume_breakpoint->disposition |
| 6584 | = disp_del_at_next_stop; |
| 6585 | |
| 6586 | /* Handle the bpstat_copy of the chain. */ |
| 6587 | bpstat_clear (&tp->control.stop_bpstat); |
| 6588 | |
| 6589 | tp->control = inf_status->thread_control; |
| 6590 | inf->control = inf_status->inferior_control; |
| 6591 | |
| 6592 | /* Other fields: */ |
| 6593 | stop_stack_dummy = inf_status->stop_stack_dummy; |
| 6594 | stopped_by_random_signal = inf_status->stopped_by_random_signal; |
| 6595 | stop_after_trap = inf_status->stop_after_trap; |
| 6596 | |
| 6597 | if (target_has_stack) |
| 6598 | { |
| 6599 | /* The point of catch_errors is that if the stack is clobbered, |
| 6600 | walking the stack might encounter a garbage pointer and |
| 6601 | error() trying to dereference it. */ |
| 6602 | if (catch_errors |
| 6603 | (restore_selected_frame, &inf_status->selected_frame_id, |
| 6604 | "Unable to restore previously selected frame:\n", |
| 6605 | RETURN_MASK_ERROR) == 0) |
| 6606 | /* Error in restoring the selected frame. Select the innermost |
| 6607 | frame. */ |
| 6608 | select_frame (get_current_frame ()); |
| 6609 | } |
| 6610 | |
| 6611 | xfree (inf_status); |
| 6612 | } |
| 6613 | |
| 6614 | static void |
| 6615 | do_restore_infcall_control_state_cleanup (void *sts) |
| 6616 | { |
| 6617 | restore_infcall_control_state (sts); |
| 6618 | } |
| 6619 | |
| 6620 | struct cleanup * |
| 6621 | make_cleanup_restore_infcall_control_state |
| 6622 | (struct infcall_control_state *inf_status) |
| 6623 | { |
| 6624 | return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status); |
| 6625 | } |
| 6626 | |
| 6627 | void |
| 6628 | discard_infcall_control_state (struct infcall_control_state *inf_status) |
| 6629 | { |
| 6630 | if (inf_status->thread_control.step_resume_breakpoint) |
| 6631 | inf_status->thread_control.step_resume_breakpoint->disposition |
| 6632 | = disp_del_at_next_stop; |
| 6633 | |
| 6634 | if (inf_status->thread_control.exception_resume_breakpoint) |
| 6635 | inf_status->thread_control.exception_resume_breakpoint->disposition |
| 6636 | = disp_del_at_next_stop; |
| 6637 | |
| 6638 | /* See save_infcall_control_state for info on stop_bpstat. */ |
| 6639 | bpstat_clear (&inf_status->thread_control.stop_bpstat); |
| 6640 | |
| 6641 | xfree (inf_status); |
| 6642 | } |
| 6643 | \f |
| 6644 | int |
| 6645 | inferior_has_forked (ptid_t pid, ptid_t *child_pid) |
| 6646 | { |
| 6647 | struct target_waitstatus last; |
| 6648 | ptid_t last_ptid; |
| 6649 | |
| 6650 | get_last_target_status (&last_ptid, &last); |
| 6651 | |
| 6652 | if (last.kind != TARGET_WAITKIND_FORKED) |
| 6653 | return 0; |
| 6654 | |
| 6655 | if (!ptid_equal (last_ptid, pid)) |
| 6656 | return 0; |
| 6657 | |
| 6658 | *child_pid = last.value.related_pid; |
| 6659 | return 1; |
| 6660 | } |
| 6661 | |
| 6662 | int |
| 6663 | inferior_has_vforked (ptid_t pid, ptid_t *child_pid) |
| 6664 | { |
| 6665 | struct target_waitstatus last; |
| 6666 | ptid_t last_ptid; |
| 6667 | |
| 6668 | get_last_target_status (&last_ptid, &last); |
| 6669 | |
| 6670 | if (last.kind != TARGET_WAITKIND_VFORKED) |
| 6671 | return 0; |
| 6672 | |
| 6673 | if (!ptid_equal (last_ptid, pid)) |
| 6674 | return 0; |
| 6675 | |
| 6676 | *child_pid = last.value.related_pid; |
| 6677 | return 1; |
| 6678 | } |
| 6679 | |
| 6680 | int |
| 6681 | inferior_has_execd (ptid_t pid, char **execd_pathname) |
| 6682 | { |
| 6683 | struct target_waitstatus last; |
| 6684 | ptid_t last_ptid; |
| 6685 | |
| 6686 | get_last_target_status (&last_ptid, &last); |
| 6687 | |
| 6688 | if (last.kind != TARGET_WAITKIND_EXECD) |
| 6689 | return 0; |
| 6690 | |
| 6691 | if (!ptid_equal (last_ptid, pid)) |
| 6692 | return 0; |
| 6693 | |
| 6694 | *execd_pathname = xstrdup (last.value.execd_pathname); |
| 6695 | return 1; |
| 6696 | } |
| 6697 | |
| 6698 | int |
| 6699 | inferior_has_called_syscall (ptid_t pid, int *syscall_number) |
| 6700 | { |
| 6701 | struct target_waitstatus last; |
| 6702 | ptid_t last_ptid; |
| 6703 | |
| 6704 | get_last_target_status (&last_ptid, &last); |
| 6705 | |
| 6706 | if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY && |
| 6707 | last.kind != TARGET_WAITKIND_SYSCALL_RETURN) |
| 6708 | return 0; |
| 6709 | |
| 6710 | if (!ptid_equal (last_ptid, pid)) |
| 6711 | return 0; |
| 6712 | |
| 6713 | *syscall_number = last.value.syscall_number; |
| 6714 | return 1; |
| 6715 | } |
| 6716 | |
| 6717 | /* Oft used ptids */ |
| 6718 | ptid_t null_ptid; |
| 6719 | ptid_t minus_one_ptid; |
| 6720 | |
| 6721 | /* Create a ptid given the necessary PID, LWP, and TID components. */ |
| 6722 | |
| 6723 | ptid_t |
| 6724 | ptid_build (int pid, long lwp, long tid) |
| 6725 | { |
| 6726 | ptid_t ptid; |
| 6727 | |
| 6728 | ptid.pid = pid; |
| 6729 | ptid.lwp = lwp; |
| 6730 | ptid.tid = tid; |
| 6731 | return ptid; |
| 6732 | } |
| 6733 | |
| 6734 | /* Create a ptid from just a pid. */ |
| 6735 | |
| 6736 | ptid_t |
| 6737 | pid_to_ptid (int pid) |
| 6738 | { |
| 6739 | return ptid_build (pid, 0, 0); |
| 6740 | } |
| 6741 | |
| 6742 | /* Fetch the pid (process id) component from a ptid. */ |
| 6743 | |
| 6744 | int |
| 6745 | ptid_get_pid (ptid_t ptid) |
| 6746 | { |
| 6747 | return ptid.pid; |
| 6748 | } |
| 6749 | |
| 6750 | /* Fetch the lwp (lightweight process) component from a ptid. */ |
| 6751 | |
| 6752 | long |
| 6753 | ptid_get_lwp (ptid_t ptid) |
| 6754 | { |
| 6755 | return ptid.lwp; |
| 6756 | } |
| 6757 | |
| 6758 | /* Fetch the tid (thread id) component from a ptid. */ |
| 6759 | |
| 6760 | long |
| 6761 | ptid_get_tid (ptid_t ptid) |
| 6762 | { |
| 6763 | return ptid.tid; |
| 6764 | } |
| 6765 | |
| 6766 | /* ptid_equal() is used to test equality of two ptids. */ |
| 6767 | |
| 6768 | int |
| 6769 | ptid_equal (ptid_t ptid1, ptid_t ptid2) |
| 6770 | { |
| 6771 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp |
| 6772 | && ptid1.tid == ptid2.tid); |
| 6773 | } |
| 6774 | |
| 6775 | /* Returns true if PTID represents a process. */ |
| 6776 | |
| 6777 | int |
| 6778 | ptid_is_pid (ptid_t ptid) |
| 6779 | { |
| 6780 | if (ptid_equal (minus_one_ptid, ptid)) |
| 6781 | return 0; |
| 6782 | if (ptid_equal (null_ptid, ptid)) |
| 6783 | return 0; |
| 6784 | |
| 6785 | return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0); |
| 6786 | } |
| 6787 | |
| 6788 | int |
| 6789 | ptid_match (ptid_t ptid, ptid_t filter) |
| 6790 | { |
| 6791 | if (ptid_equal (filter, minus_one_ptid)) |
| 6792 | return 1; |
| 6793 | if (ptid_is_pid (filter) |
| 6794 | && ptid_get_pid (ptid) == ptid_get_pid (filter)) |
| 6795 | return 1; |
| 6796 | else if (ptid_equal (ptid, filter)) |
| 6797 | return 1; |
| 6798 | |
| 6799 | return 0; |
| 6800 | } |
| 6801 | |
| 6802 | /* restore_inferior_ptid() will be used by the cleanup machinery |
| 6803 | to restore the inferior_ptid value saved in a call to |
| 6804 | save_inferior_ptid(). */ |
| 6805 | |
| 6806 | static void |
| 6807 | restore_inferior_ptid (void *arg) |
| 6808 | { |
| 6809 | ptid_t *saved_ptid_ptr = arg; |
| 6810 | |
| 6811 | inferior_ptid = *saved_ptid_ptr; |
| 6812 | xfree (arg); |
| 6813 | } |
| 6814 | |
| 6815 | /* Save the value of inferior_ptid so that it may be restored by a |
| 6816 | later call to do_cleanups(). Returns the struct cleanup pointer |
| 6817 | needed for later doing the cleanup. */ |
| 6818 | |
| 6819 | struct cleanup * |
| 6820 | save_inferior_ptid (void) |
| 6821 | { |
| 6822 | ptid_t *saved_ptid_ptr; |
| 6823 | |
| 6824 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); |
| 6825 | *saved_ptid_ptr = inferior_ptid; |
| 6826 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); |
| 6827 | } |
| 6828 | \f |
| 6829 | |
| 6830 | /* User interface for reverse debugging: |
| 6831 | Set exec-direction / show exec-direction commands |
| 6832 | (returns error unless target implements to_set_exec_direction method). */ |
| 6833 | |
| 6834 | enum exec_direction_kind execution_direction = EXEC_FORWARD; |
| 6835 | static const char exec_forward[] = "forward"; |
| 6836 | static const char exec_reverse[] = "reverse"; |
| 6837 | static const char *exec_direction = exec_forward; |
| 6838 | static const char *exec_direction_names[] = { |
| 6839 | exec_forward, |
| 6840 | exec_reverse, |
| 6841 | NULL |
| 6842 | }; |
| 6843 | |
| 6844 | static void |
| 6845 | set_exec_direction_func (char *args, int from_tty, |
| 6846 | struct cmd_list_element *cmd) |
| 6847 | { |
| 6848 | if (target_can_execute_reverse) |
| 6849 | { |
| 6850 | if (!strcmp (exec_direction, exec_forward)) |
| 6851 | execution_direction = EXEC_FORWARD; |
| 6852 | else if (!strcmp (exec_direction, exec_reverse)) |
| 6853 | execution_direction = EXEC_REVERSE; |
| 6854 | } |
| 6855 | else |
| 6856 | { |
| 6857 | exec_direction = exec_forward; |
| 6858 | error (_("Target does not support this operation.")); |
| 6859 | } |
| 6860 | } |
| 6861 | |
| 6862 | static void |
| 6863 | show_exec_direction_func (struct ui_file *out, int from_tty, |
| 6864 | struct cmd_list_element *cmd, const char *value) |
| 6865 | { |
| 6866 | switch (execution_direction) { |
| 6867 | case EXEC_FORWARD: |
| 6868 | fprintf_filtered (out, _("Forward.\n")); |
| 6869 | break; |
| 6870 | case EXEC_REVERSE: |
| 6871 | fprintf_filtered (out, _("Reverse.\n")); |
| 6872 | break; |
| 6873 | case EXEC_ERROR: |
| 6874 | default: |
| 6875 | fprintf_filtered (out, _("Forward (target `%s' does not " |
| 6876 | "support exec-direction).\n"), |
| 6877 | target_shortname); |
| 6878 | break; |
| 6879 | } |
| 6880 | } |
| 6881 | |
| 6882 | /* User interface for non-stop mode. */ |
| 6883 | |
| 6884 | int non_stop = 0; |
| 6885 | |
| 6886 | static void |
| 6887 | set_non_stop (char *args, int from_tty, |
| 6888 | struct cmd_list_element *c) |
| 6889 | { |
| 6890 | if (target_has_execution) |
| 6891 | { |
| 6892 | non_stop_1 = non_stop; |
| 6893 | error (_("Cannot change this setting while the inferior is running.")); |
| 6894 | } |
| 6895 | |
| 6896 | non_stop = non_stop_1; |
| 6897 | } |
| 6898 | |
| 6899 | static void |
| 6900 | show_non_stop (struct ui_file *file, int from_tty, |
| 6901 | struct cmd_list_element *c, const char *value) |
| 6902 | { |
| 6903 | fprintf_filtered (file, |
| 6904 | _("Controlling the inferior in non-stop mode is %s.\n"), |
| 6905 | value); |
| 6906 | } |
| 6907 | |
| 6908 | static void |
| 6909 | show_schedule_multiple (struct ui_file *file, int from_tty, |
| 6910 | struct cmd_list_element *c, const char *value) |
| 6911 | { |
| 6912 | fprintf_filtered (file, _("Resuming the execution of threads " |
| 6913 | "of all processes is %s.\n"), value); |
| 6914 | } |
| 6915 | |
| 6916 | void |
| 6917 | _initialize_infrun (void) |
| 6918 | { |
| 6919 | int i; |
| 6920 | int numsigs; |
| 6921 | |
| 6922 | add_info ("signals", signals_info, _("\ |
| 6923 | What debugger does when program gets various signals.\n\ |
| 6924 | Specify a signal as argument to print info on that signal only.")); |
| 6925 | add_info_alias ("handle", "signals", 0); |
| 6926 | |
| 6927 | add_com ("handle", class_run, handle_command, _("\ |
| 6928 | Specify how to handle a signal.\n\ |
| 6929 | Args are signals and actions to apply to those signals.\n\ |
| 6930 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ |
| 6931 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ |
| 6932 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ |
| 6933 | The special arg \"all\" is recognized to mean all signals except those\n\ |
| 6934 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
| 6935 | Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ |
| 6936 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
| 6937 | Stop means reenter debugger if this signal happens (implies print).\n\ |
| 6938 | Print means print a message if this signal happens.\n\ |
| 6939 | Pass means let program see this signal; otherwise program doesn't know.\n\ |
| 6940 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ |
| 6941 | Pass and Stop may be combined.")); |
| 6942 | if (xdb_commands) |
| 6943 | { |
| 6944 | add_com ("lz", class_info, signals_info, _("\ |
| 6945 | What debugger does when program gets various signals.\n\ |
| 6946 | Specify a signal as argument to print info on that signal only.")); |
| 6947 | add_com ("z", class_run, xdb_handle_command, _("\ |
| 6948 | Specify how to handle a signal.\n\ |
| 6949 | Args are signals and actions to apply to those signals.\n\ |
| 6950 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ |
| 6951 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ |
| 6952 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ |
| 6953 | The special arg \"all\" is recognized to mean all signals except those\n\ |
| 6954 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
| 6955 | Recognized actions include \"s\" (toggles between stop and nostop),\n\ |
| 6956 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ |
| 6957 | nopass), \"Q\" (noprint)\n\ |
| 6958 | Stop means reenter debugger if this signal happens (implies print).\n\ |
| 6959 | Print means print a message if this signal happens.\n\ |
| 6960 | Pass means let program see this signal; otherwise program doesn't know.\n\ |
| 6961 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ |
| 6962 | Pass and Stop may be combined.")); |
| 6963 | } |
| 6964 | |
| 6965 | if (!dbx_commands) |
| 6966 | stop_command = add_cmd ("stop", class_obscure, |
| 6967 | not_just_help_class_command, _("\ |
| 6968 | There is no `stop' command, but you can set a hook on `stop'.\n\ |
| 6969 | This allows you to set a list of commands to be run each time execution\n\ |
| 6970 | of the program stops."), &cmdlist); |
| 6971 | |
| 6972 | add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ |
| 6973 | Set inferior debugging."), _("\ |
| 6974 | Show inferior debugging."), _("\ |
| 6975 | When non-zero, inferior specific debugging is enabled."), |
| 6976 | NULL, |
| 6977 | show_debug_infrun, |
| 6978 | &setdebuglist, &showdebuglist); |
| 6979 | |
| 6980 | add_setshow_boolean_cmd ("displaced", class_maintenance, |
| 6981 | &debug_displaced, _("\ |
| 6982 | Set displaced stepping debugging."), _("\ |
| 6983 | Show displaced stepping debugging."), _("\ |
| 6984 | When non-zero, displaced stepping specific debugging is enabled."), |
| 6985 | NULL, |
| 6986 | show_debug_displaced, |
| 6987 | &setdebuglist, &showdebuglist); |
| 6988 | |
| 6989 | add_setshow_boolean_cmd ("non-stop", no_class, |
| 6990 | &non_stop_1, _("\ |
| 6991 | Set whether gdb controls the inferior in non-stop mode."), _("\ |
| 6992 | Show whether gdb controls the inferior in non-stop mode."), _("\ |
| 6993 | When debugging a multi-threaded program and this setting is\n\ |
| 6994 | off (the default, also called all-stop mode), when one thread stops\n\ |
| 6995 | (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\ |
| 6996 | all other threads in the program while you interact with the thread of\n\ |
| 6997 | interest. When you continue or step a thread, you can allow the other\n\ |
| 6998 | threads to run, or have them remain stopped, but while you inspect any\n\ |
| 6999 | thread's state, all threads stop.\n\ |
| 7000 | \n\ |
| 7001 | In non-stop mode, when one thread stops, other threads can continue\n\ |
| 7002 | to run freely. You'll be able to step each thread independently,\n\ |
| 7003 | leave it stopped or free to run as needed."), |
| 7004 | set_non_stop, |
| 7005 | show_non_stop, |
| 7006 | &setlist, |
| 7007 | &showlist); |
| 7008 | |
| 7009 | numsigs = (int) TARGET_SIGNAL_LAST; |
| 7010 | signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); |
| 7011 | signal_print = (unsigned char *) |
| 7012 | xmalloc (sizeof (signal_print[0]) * numsigs); |
| 7013 | signal_program = (unsigned char *) |
| 7014 | xmalloc (sizeof (signal_program[0]) * numsigs); |
| 7015 | signal_pass = (unsigned char *) |
| 7016 | xmalloc (sizeof (signal_program[0]) * numsigs); |
| 7017 | for (i = 0; i < numsigs; i++) |
| 7018 | { |
| 7019 | signal_stop[i] = 1; |
| 7020 | signal_print[i] = 1; |
| 7021 | signal_program[i] = 1; |
| 7022 | } |
| 7023 | |
| 7024 | /* Signals caused by debugger's own actions |
| 7025 | should not be given to the program afterwards. */ |
| 7026 | signal_program[TARGET_SIGNAL_TRAP] = 0; |
| 7027 | signal_program[TARGET_SIGNAL_INT] = 0; |
| 7028 | |
| 7029 | /* Signals that are not errors should not normally enter the debugger. */ |
| 7030 | signal_stop[TARGET_SIGNAL_ALRM] = 0; |
| 7031 | signal_print[TARGET_SIGNAL_ALRM] = 0; |
| 7032 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; |
| 7033 | signal_print[TARGET_SIGNAL_VTALRM] = 0; |
| 7034 | signal_stop[TARGET_SIGNAL_PROF] = 0; |
| 7035 | signal_print[TARGET_SIGNAL_PROF] = 0; |
| 7036 | signal_stop[TARGET_SIGNAL_CHLD] = 0; |
| 7037 | signal_print[TARGET_SIGNAL_CHLD] = 0; |
| 7038 | signal_stop[TARGET_SIGNAL_IO] = 0; |
| 7039 | signal_print[TARGET_SIGNAL_IO] = 0; |
| 7040 | signal_stop[TARGET_SIGNAL_POLL] = 0; |
| 7041 | signal_print[TARGET_SIGNAL_POLL] = 0; |
| 7042 | signal_stop[TARGET_SIGNAL_URG] = 0; |
| 7043 | signal_print[TARGET_SIGNAL_URG] = 0; |
| 7044 | signal_stop[TARGET_SIGNAL_WINCH] = 0; |
| 7045 | signal_print[TARGET_SIGNAL_WINCH] = 0; |
| 7046 | signal_stop[TARGET_SIGNAL_PRIO] = 0; |
| 7047 | signal_print[TARGET_SIGNAL_PRIO] = 0; |
| 7048 | |
| 7049 | /* These signals are used internally by user-level thread |
| 7050 | implementations. (See signal(5) on Solaris.) Like the above |
| 7051 | signals, a healthy program receives and handles them as part of |
| 7052 | its normal operation. */ |
| 7053 | signal_stop[TARGET_SIGNAL_LWP] = 0; |
| 7054 | signal_print[TARGET_SIGNAL_LWP] = 0; |
| 7055 | signal_stop[TARGET_SIGNAL_WAITING] = 0; |
| 7056 | signal_print[TARGET_SIGNAL_WAITING] = 0; |
| 7057 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; |
| 7058 | signal_print[TARGET_SIGNAL_CANCEL] = 0; |
| 7059 | |
| 7060 | /* Update cached state. */ |
| 7061 | signal_cache_update (-1); |
| 7062 | |
| 7063 | add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, |
| 7064 | &stop_on_solib_events, _("\ |
| 7065 | Set stopping for shared library events."), _("\ |
| 7066 | Show stopping for shared library events."), _("\ |
| 7067 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
| 7068 | notifies gdb of shared library events. The most common event of interest\n\ |
| 7069 | to the user would be loading/unloading of a new library."), |
| 7070 | NULL, |
| 7071 | show_stop_on_solib_events, |
| 7072 | &setlist, &showlist); |
| 7073 | |
| 7074 | add_setshow_enum_cmd ("follow-fork-mode", class_run, |
| 7075 | follow_fork_mode_kind_names, |
| 7076 | &follow_fork_mode_string, _("\ |
| 7077 | Set debugger response to a program call of fork or vfork."), _("\ |
| 7078 | Show debugger response to a program call of fork or vfork."), _("\ |
| 7079 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
| 7080 | parent - the original process is debugged after a fork\n\ |
| 7081 | child - the new process is debugged after a fork\n\ |
| 7082 | The unfollowed process will continue to run.\n\ |
| 7083 | By default, the debugger will follow the parent process."), |
| 7084 | NULL, |
| 7085 | show_follow_fork_mode_string, |
| 7086 | &setlist, &showlist); |
| 7087 | |
| 7088 | add_setshow_enum_cmd ("follow-exec-mode", class_run, |
| 7089 | follow_exec_mode_names, |
| 7090 | &follow_exec_mode_string, _("\ |
| 7091 | Set debugger response to a program call of exec."), _("\ |
| 7092 | Show debugger response to a program call of exec."), _("\ |
| 7093 | An exec call replaces the program image of a process.\n\ |
| 7094 | \n\ |
| 7095 | follow-exec-mode can be:\n\ |
| 7096 | \n\ |
| 7097 | new - the debugger creates a new inferior and rebinds the process\n\ |
| 7098 | to this new inferior. The program the process was running before\n\ |
| 7099 | the exec call can be restarted afterwards by restarting the original\n\ |
| 7100 | inferior.\n\ |
| 7101 | \n\ |
| 7102 | same - the debugger keeps the process bound to the same inferior.\n\ |
| 7103 | The new executable image replaces the previous executable loaded in\n\ |
| 7104 | the inferior. Restarting the inferior after the exec call restarts\n\ |
| 7105 | the executable the process was running after the exec call.\n\ |
| 7106 | \n\ |
| 7107 | By default, the debugger will use the same inferior."), |
| 7108 | NULL, |
| 7109 | show_follow_exec_mode_string, |
| 7110 | &setlist, &showlist); |
| 7111 | |
| 7112 | add_setshow_enum_cmd ("scheduler-locking", class_run, |
| 7113 | scheduler_enums, &scheduler_mode, _("\ |
| 7114 | Set mode for locking scheduler during execution."), _("\ |
| 7115 | Show mode for locking scheduler during execution."), _("\ |
| 7116 | off == no locking (threads may preempt at any time)\n\ |
| 7117 | on == full locking (no thread except the current thread may run)\n\ |
| 7118 | step == scheduler locked during every single-step operation.\n\ |
| 7119 | In this mode, no other thread may run during a step command.\n\ |
| 7120 | Other threads may run while stepping over a function call ('next')."), |
| 7121 | set_schedlock_func, /* traps on target vector */ |
| 7122 | show_scheduler_mode, |
| 7123 | &setlist, &showlist); |
| 7124 | |
| 7125 | add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\ |
| 7126 | Set mode for resuming threads of all processes."), _("\ |
| 7127 | Show mode for resuming threads of all processes."), _("\ |
| 7128 | When on, execution commands (such as 'continue' or 'next') resume all\n\ |
| 7129 | threads of all processes. When off (which is the default), execution\n\ |
| 7130 | commands only resume the threads of the current process. The set of\n\ |
| 7131 | threads that are resumed is further refined by the scheduler-locking\n\ |
| 7132 | mode (see help set scheduler-locking)."), |
| 7133 | NULL, |
| 7134 | show_schedule_multiple, |
| 7135 | &setlist, &showlist); |
| 7136 | |
| 7137 | add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ |
| 7138 | Set mode of the step operation."), _("\ |
| 7139 | Show mode of the step operation."), _("\ |
| 7140 | When set, doing a step over a function without debug line information\n\ |
| 7141 | will stop at the first instruction of that function. Otherwise, the\n\ |
| 7142 | function is skipped and the step command stops at a different source line."), |
| 7143 | NULL, |
| 7144 | show_step_stop_if_no_debug, |
| 7145 | &setlist, &showlist); |
| 7146 | |
| 7147 | add_setshow_enum_cmd ("displaced-stepping", class_run, |
| 7148 | can_use_displaced_stepping_enum, |
| 7149 | &can_use_displaced_stepping, _("\ |
| 7150 | Set debugger's willingness to use displaced stepping."), _("\ |
| 7151 | Show debugger's willingness to use displaced stepping."), _("\ |
| 7152 | If on, gdb will use displaced stepping to step over breakpoints if it is\n\ |
| 7153 | supported by the target architecture. If off, gdb will not use displaced\n\ |
| 7154 | stepping to step over breakpoints, even if such is supported by the target\n\ |
| 7155 | architecture. If auto (which is the default), gdb will use displaced stepping\n\ |
| 7156 | if the target architecture supports it and non-stop mode is active, but will not\n\ |
| 7157 | use it in all-stop mode (see help set non-stop)."), |
| 7158 | NULL, |
| 7159 | show_can_use_displaced_stepping, |
| 7160 | &setlist, &showlist); |
| 7161 | |
| 7162 | add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names, |
| 7163 | &exec_direction, _("Set direction of execution.\n\ |
| 7164 | Options are 'forward' or 'reverse'."), |
| 7165 | _("Show direction of execution (forward/reverse)."), |
| 7166 | _("Tells gdb whether to execute forward or backward."), |
| 7167 | set_exec_direction_func, show_exec_direction_func, |
| 7168 | &setlist, &showlist); |
| 7169 | |
| 7170 | /* Set/show detach-on-fork: user-settable mode. */ |
| 7171 | |
| 7172 | add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\ |
| 7173 | Set whether gdb will detach the child of a fork."), _("\ |
| 7174 | Show whether gdb will detach the child of a fork."), _("\ |
| 7175 | Tells gdb whether to detach the child of a fork."), |
| 7176 | NULL, NULL, &setlist, &showlist); |
| 7177 | |
| 7178 | /* ptid initializations */ |
| 7179 | null_ptid = ptid_build (0, 0, 0); |
| 7180 | minus_one_ptid = ptid_build (-1, 0, 0); |
| 7181 | inferior_ptid = null_ptid; |
| 7182 | target_last_wait_ptid = minus_one_ptid; |
| 7183 | |
| 7184 | observer_attach_thread_ptid_changed (infrun_thread_ptid_changed); |
| 7185 | observer_attach_thread_stop_requested (infrun_thread_stop_requested); |
| 7186 | observer_attach_thread_exit (infrun_thread_thread_exit); |
| 7187 | observer_attach_inferior_exit (infrun_inferior_exit); |
| 7188 | |
| 7189 | /* Explicitly create without lookup, since that tries to create a |
| 7190 | value with a void typed value, and when we get here, gdbarch |
| 7191 | isn't initialized yet. At this point, we're quite sure there |
| 7192 | isn't another convenience variable of the same name. */ |
| 7193 | create_internalvar_type_lazy ("_siginfo", siginfo_make_value); |
| 7194 | |
| 7195 | add_setshow_boolean_cmd ("observer", no_class, |
| 7196 | &observer_mode_1, _("\ |
| 7197 | Set whether gdb controls the inferior in observer mode."), _("\ |
| 7198 | Show whether gdb controls the inferior in observer mode."), _("\ |
| 7199 | In observer mode, GDB can get data from the inferior, but not\n\ |
| 7200 | affect its execution. Registers and memory may not be changed,\n\ |
| 7201 | breakpoints may not be set, and the program cannot be interrupted\n\ |
| 7202 | or signalled."), |
| 7203 | set_observer_mode, |
| 7204 | show_observer_mode, |
| 7205 | &setlist, |
| 7206 | &showlist); |
| 7207 | } |