GDB (API)
|
00001 /* Target-struct-independent code to start (run) and stop an inferior 00002 process. 00003 00004 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00005 00006 This file is part of GDB. 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 This program is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00020 00021 #include "defs.h" 00022 #include "gdb_string.h" 00023 #include <ctype.h> 00024 #include "symtab.h" 00025 #include "frame.h" 00026 #include "inferior.h" 00027 #include "exceptions.h" 00028 #include "breakpoint.h" 00029 #include "gdb_wait.h" 00030 #include "gdbcore.h" 00031 #include "gdbcmd.h" 00032 #include "cli/cli-script.h" 00033 #include "target.h" 00034 #include "gdbthread.h" 00035 #include "annotate.h" 00036 #include "symfile.h" 00037 #include "top.h" 00038 #include <signal.h> 00039 #include "inf-loop.h" 00040 #include "regcache.h" 00041 #include "value.h" 00042 #include "observer.h" 00043 #include "language.h" 00044 #include "solib.h" 00045 #include "main.h" 00046 #include "dictionary.h" 00047 #include "block.h" 00048 #include "gdb_assert.h" 00049 #include "mi/mi-common.h" 00050 #include "event-top.h" 00051 #include "record.h" 00052 #include "record-full.h" 00053 #include "inline-frame.h" 00054 #include "jit.h" 00055 #include "tracepoint.h" 00056 #include "continuations.h" 00057 #include "interps.h" 00058 #include "skip.h" 00059 #include "probe.h" 00060 #include "objfiles.h" 00061 #include "completer.h" 00062 #include "target-descriptions.h" 00063 00064 /* Prototypes for local functions */ 00065 00066 static void signals_info (char *, int); 00067 00068 static void handle_command (char *, int); 00069 00070 static void sig_print_info (enum gdb_signal); 00071 00072 static void sig_print_header (void); 00073 00074 static void resume_cleanups (void *); 00075 00076 static int hook_stop_stub (void *); 00077 00078 static int restore_selected_frame (void *); 00079 00080 static int follow_fork (void); 00081 00082 static void set_schedlock_func (char *args, int from_tty, 00083 struct cmd_list_element *c); 00084 00085 static int currently_stepping (struct thread_info *tp); 00086 00087 static int currently_stepping_or_nexting_callback (struct thread_info *tp, 00088 void *data); 00089 00090 static void xdb_handle_command (char *args, int from_tty); 00091 00092 static int prepare_to_proceed (int); 00093 00094 static void print_exited_reason (int exitstatus); 00095 00096 static void print_signal_exited_reason (enum gdb_signal siggnal); 00097 00098 static void print_no_history_reason (void); 00099 00100 static void print_signal_received_reason (enum gdb_signal siggnal); 00101 00102 static void print_end_stepping_range_reason (void); 00103 00104 void _initialize_infrun (void); 00105 00106 void nullify_last_target_wait_ptid (void); 00107 00108 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *); 00109 00110 static void insert_step_resume_breakpoint_at_caller (struct frame_info *); 00111 00112 static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR); 00113 00114 /* When set, stop the 'step' command if we enter a function which has 00115 no line number information. The normal behavior is that we step 00116 over such function. */ 00117 int step_stop_if_no_debug = 0; 00118 static void 00119 show_step_stop_if_no_debug (struct ui_file *file, int from_tty, 00120 struct cmd_list_element *c, const char *value) 00121 { 00122 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value); 00123 } 00124 00125 /* In asynchronous mode, but simulating synchronous execution. */ 00126 00127 int sync_execution = 0; 00128 00129 /* wait_for_inferior and normal_stop use this to notify the user 00130 when the inferior stopped in a different thread than it had been 00131 running in. */ 00132 00133 static ptid_t previous_inferior_ptid; 00134 00135 /* If set (default for legacy reasons), when following a fork, GDB 00136 will detach from one of the fork branches, child or parent. 00137 Exactly which branch is detached depends on 'set follow-fork-mode' 00138 setting. */ 00139 00140 static int detach_fork = 1; 00141 00142 int debug_displaced = 0; 00143 static void 00144 show_debug_displaced (struct ui_file *file, int from_tty, 00145 struct cmd_list_element *c, const char *value) 00146 { 00147 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value); 00148 } 00149 00150 unsigned int debug_infrun = 0; 00151 static void 00152 show_debug_infrun (struct ui_file *file, int from_tty, 00153 struct cmd_list_element *c, const char *value) 00154 { 00155 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); 00156 } 00157 00158 00159 /* Support for disabling address space randomization. */ 00160 00161 int disable_randomization = 1; 00162 00163 static void 00164 show_disable_randomization (struct ui_file *file, int from_tty, 00165 struct cmd_list_element *c, const char *value) 00166 { 00167 if (target_supports_disable_randomization ()) 00168 fprintf_filtered (file, 00169 _("Disabling randomization of debuggee's " 00170 "virtual address space is %s.\n"), 00171 value); 00172 else 00173 fputs_filtered (_("Disabling randomization of debuggee's " 00174 "virtual address space is unsupported on\n" 00175 "this platform.\n"), file); 00176 } 00177 00178 static void 00179 set_disable_randomization (char *args, int from_tty, 00180 struct cmd_list_element *c) 00181 { 00182 if (!target_supports_disable_randomization ()) 00183 error (_("Disabling randomization of debuggee's " 00184 "virtual address space is unsupported on\n" 00185 "this platform.")); 00186 } 00187 00188 /* User interface for non-stop mode. */ 00189 00190 int non_stop = 0; 00191 static int non_stop_1 = 0; 00192 00193 static void 00194 set_non_stop (char *args, int from_tty, 00195 struct cmd_list_element *c) 00196 { 00197 if (target_has_execution) 00198 { 00199 non_stop_1 = non_stop; 00200 error (_("Cannot change this setting while the inferior is running.")); 00201 } 00202 00203 non_stop = non_stop_1; 00204 } 00205 00206 static void 00207 show_non_stop (struct ui_file *file, int from_tty, 00208 struct cmd_list_element *c, const char *value) 00209 { 00210 fprintf_filtered (file, 00211 _("Controlling the inferior in non-stop mode is %s.\n"), 00212 value); 00213 } 00214 00215 /* "Observer mode" is somewhat like a more extreme version of 00216 non-stop, in which all GDB operations that might affect the 00217 target's execution have been disabled. */ 00218 00219 int observer_mode = 0; 00220 static int observer_mode_1 = 0; 00221 00222 static void 00223 set_observer_mode (char *args, int from_tty, 00224 struct cmd_list_element *c) 00225 { 00226 if (target_has_execution) 00227 { 00228 observer_mode_1 = observer_mode; 00229 error (_("Cannot change this setting while the inferior is running.")); 00230 } 00231 00232 observer_mode = observer_mode_1; 00233 00234 may_write_registers = !observer_mode; 00235 may_write_memory = !observer_mode; 00236 may_insert_breakpoints = !observer_mode; 00237 may_insert_tracepoints = !observer_mode; 00238 /* We can insert fast tracepoints in or out of observer mode, 00239 but enable them if we're going into this mode. */ 00240 if (observer_mode) 00241 may_insert_fast_tracepoints = 1; 00242 may_stop = !observer_mode; 00243 update_target_permissions (); 00244 00245 /* Going *into* observer mode we must force non-stop, then 00246 going out we leave it that way. */ 00247 if (observer_mode) 00248 { 00249 target_async_permitted = 1; 00250 pagination_enabled = 0; 00251 non_stop = non_stop_1 = 1; 00252 } 00253 00254 if (from_tty) 00255 printf_filtered (_("Observer mode is now %s.\n"), 00256 (observer_mode ? "on" : "off")); 00257 } 00258 00259 static void 00260 show_observer_mode (struct ui_file *file, int from_tty, 00261 struct cmd_list_element *c, const char *value) 00262 { 00263 fprintf_filtered (file, _("Observer mode is %s.\n"), value); 00264 } 00265 00266 /* This updates the value of observer mode based on changes in 00267 permissions. Note that we are deliberately ignoring the values of 00268 may-write-registers and may-write-memory, since the user may have 00269 reason to enable these during a session, for instance to turn on a 00270 debugging-related global. */ 00271 00272 void 00273 update_observer_mode (void) 00274 { 00275 int newval; 00276 00277 newval = (!may_insert_breakpoints 00278 && !may_insert_tracepoints 00279 && may_insert_fast_tracepoints 00280 && !may_stop 00281 && non_stop); 00282 00283 /* Let the user know if things change. */ 00284 if (newval != observer_mode) 00285 printf_filtered (_("Observer mode is now %s.\n"), 00286 (newval ? "on" : "off")); 00287 00288 observer_mode = observer_mode_1 = newval; 00289 } 00290 00291 /* Tables of how to react to signals; the user sets them. */ 00292 00293 static unsigned char *signal_stop; 00294 static unsigned char *signal_print; 00295 static unsigned char *signal_program; 00296 00297 /* Table of signals that are registered with "catch signal". A 00298 non-zero entry indicates that the signal is caught by some "catch 00299 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all 00300 signals. */ 00301 static unsigned char *signal_catch; 00302 00303 /* Table of signals that the target may silently handle. 00304 This is automatically determined from the flags above, 00305 and simply cached here. */ 00306 static unsigned char *signal_pass; 00307 00308 #define SET_SIGS(nsigs,sigs,flags) \ 00309 do { \ 00310 int signum = (nsigs); \ 00311 while (signum-- > 0) \ 00312 if ((sigs)[signum]) \ 00313 (flags)[signum] = 1; \ 00314 } while (0) 00315 00316 #define UNSET_SIGS(nsigs,sigs,flags) \ 00317 do { \ 00318 int signum = (nsigs); \ 00319 while (signum-- > 0) \ 00320 if ((sigs)[signum]) \ 00321 (flags)[signum] = 0; \ 00322 } while (0) 00323 00324 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of 00325 this function is to avoid exporting `signal_program'. */ 00326 00327 void 00328 update_signals_program_target (void) 00329 { 00330 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program); 00331 } 00332 00333 /* Value to pass to target_resume() to cause all threads to resume. */ 00334 00335 #define RESUME_ALL minus_one_ptid 00336 00337 /* Command list pointer for the "stop" placeholder. */ 00338 00339 static struct cmd_list_element *stop_command; 00340 00341 /* Function inferior was in as of last step command. */ 00342 00343 static struct symbol *step_start_function; 00344 00345 /* Nonzero if we want to give control to the user when we're notified 00346 of shared library events by the dynamic linker. */ 00347 int stop_on_solib_events; 00348 00349 /* Enable or disable optional shared library event breakpoints 00350 as appropriate when the above flag is changed. */ 00351 00352 static void 00353 set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c) 00354 { 00355 update_solib_breakpoints (); 00356 } 00357 00358 static void 00359 show_stop_on_solib_events (struct ui_file *file, int from_tty, 00360 struct cmd_list_element *c, const char *value) 00361 { 00362 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"), 00363 value); 00364 } 00365 00366 /* Nonzero means expecting a trace trap 00367 and should stop the inferior and return silently when it happens. */ 00368 00369 int stop_after_trap; 00370 00371 /* Save register contents here when executing a "finish" command or are 00372 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set. 00373 Thus this contains the return value from the called function (assuming 00374 values are returned in a register). */ 00375 00376 struct regcache *stop_registers; 00377 00378 /* Nonzero after stop if current stack frame should be printed. */ 00379 00380 static int stop_print_frame; 00381 00382 /* This is a cached copy of the pid/waitstatus of the last event 00383 returned by target_wait()/deprecated_target_wait_hook(). This 00384 information is returned by get_last_target_status(). */ 00385 static ptid_t target_last_wait_ptid; 00386 static struct target_waitstatus target_last_waitstatus; 00387 00388 static void context_switch (ptid_t ptid); 00389 00390 void init_thread_stepping_state (struct thread_info *tss); 00391 00392 static void init_infwait_state (void); 00393 00394 static const char follow_fork_mode_child[] = "child"; 00395 static const char follow_fork_mode_parent[] = "parent"; 00396 00397 static const char *const follow_fork_mode_kind_names[] = { 00398 follow_fork_mode_child, 00399 follow_fork_mode_parent, 00400 NULL 00401 }; 00402 00403 static const char *follow_fork_mode_string = follow_fork_mode_parent; 00404 static void 00405 show_follow_fork_mode_string (struct ui_file *file, int from_tty, 00406 struct cmd_list_element *c, const char *value) 00407 { 00408 fprintf_filtered (file, 00409 _("Debugger response to a program " 00410 "call of fork or vfork is \"%s\".\n"), 00411 value); 00412 } 00413 00414 00415 /* Tell the target to follow the fork we're stopped at. Returns true 00416 if the inferior should be resumed; false, if the target for some 00417 reason decided it's best not to resume. */ 00418 00419 static int 00420 follow_fork (void) 00421 { 00422 int follow_child = (follow_fork_mode_string == follow_fork_mode_child); 00423 int should_resume = 1; 00424 struct thread_info *tp; 00425 00426 /* Copy user stepping state to the new inferior thread. FIXME: the 00427 followed fork child thread should have a copy of most of the 00428 parent thread structure's run control related fields, not just these. 00429 Initialized to avoid "may be used uninitialized" warnings from gcc. */ 00430 struct breakpoint *step_resume_breakpoint = NULL; 00431 struct breakpoint *exception_resume_breakpoint = NULL; 00432 CORE_ADDR step_range_start = 0; 00433 CORE_ADDR step_range_end = 0; 00434 struct frame_id step_frame_id = { 0 }; 00435 00436 if (!non_stop) 00437 { 00438 ptid_t wait_ptid; 00439 struct target_waitstatus wait_status; 00440 00441 /* Get the last target status returned by target_wait(). */ 00442 get_last_target_status (&wait_ptid, &wait_status); 00443 00444 /* If not stopped at a fork event, then there's nothing else to 00445 do. */ 00446 if (wait_status.kind != TARGET_WAITKIND_FORKED 00447 && wait_status.kind != TARGET_WAITKIND_VFORKED) 00448 return 1; 00449 00450 /* Check if we switched over from WAIT_PTID, since the event was 00451 reported. */ 00452 if (!ptid_equal (wait_ptid, minus_one_ptid) 00453 && !ptid_equal (inferior_ptid, wait_ptid)) 00454 { 00455 /* We did. Switch back to WAIT_PTID thread, to tell the 00456 target to follow it (in either direction). We'll 00457 afterwards refuse to resume, and inform the user what 00458 happened. */ 00459 switch_to_thread (wait_ptid); 00460 should_resume = 0; 00461 } 00462 } 00463 00464 tp = inferior_thread (); 00465 00466 /* If there were any forks/vforks that were caught and are now to be 00467 followed, then do so now. */ 00468 switch (tp->pending_follow.kind) 00469 { 00470 case TARGET_WAITKIND_FORKED: 00471 case TARGET_WAITKIND_VFORKED: 00472 { 00473 ptid_t parent, child; 00474 00475 /* If the user did a next/step, etc, over a fork call, 00476 preserve the stepping state in the fork child. */ 00477 if (follow_child && should_resume) 00478 { 00479 step_resume_breakpoint = clone_momentary_breakpoint 00480 (tp->control.step_resume_breakpoint); 00481 step_range_start = tp->control.step_range_start; 00482 step_range_end = tp->control.step_range_end; 00483 step_frame_id = tp->control.step_frame_id; 00484 exception_resume_breakpoint 00485 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint); 00486 00487 /* For now, delete the parent's sr breakpoint, otherwise, 00488 parent/child sr breakpoints are considered duplicates, 00489 and the child version will not be installed. Remove 00490 this when the breakpoints module becomes aware of 00491 inferiors and address spaces. */ 00492 delete_step_resume_breakpoint (tp); 00493 tp->control.step_range_start = 0; 00494 tp->control.step_range_end = 0; 00495 tp->control.step_frame_id = null_frame_id; 00496 delete_exception_resume_breakpoint (tp); 00497 } 00498 00499 parent = inferior_ptid; 00500 child = tp->pending_follow.value.related_pid; 00501 00502 /* Tell the target to do whatever is necessary to follow 00503 either parent or child. */ 00504 if (target_follow_fork (follow_child, detach_fork)) 00505 { 00506 /* Target refused to follow, or there's some other reason 00507 we shouldn't resume. */ 00508 should_resume = 0; 00509 } 00510 else 00511 { 00512 /* This pending follow fork event is now handled, one way 00513 or another. The previous selected thread may be gone 00514 from the lists by now, but if it is still around, need 00515 to clear the pending follow request. */ 00516 tp = find_thread_ptid (parent); 00517 if (tp) 00518 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS; 00519 00520 /* This makes sure we don't try to apply the "Switched 00521 over from WAIT_PID" logic above. */ 00522 nullify_last_target_wait_ptid (); 00523 00524 /* If we followed the child, switch to it... */ 00525 if (follow_child) 00526 { 00527 switch_to_thread (child); 00528 00529 /* ... and preserve the stepping state, in case the 00530 user was stepping over the fork call. */ 00531 if (should_resume) 00532 { 00533 tp = inferior_thread (); 00534 tp->control.step_resume_breakpoint 00535 = step_resume_breakpoint; 00536 tp->control.step_range_start = step_range_start; 00537 tp->control.step_range_end = step_range_end; 00538 tp->control.step_frame_id = step_frame_id; 00539 tp->control.exception_resume_breakpoint 00540 = exception_resume_breakpoint; 00541 } 00542 else 00543 { 00544 /* If we get here, it was because we're trying to 00545 resume from a fork catchpoint, but, the user 00546 has switched threads away from the thread that 00547 forked. In that case, the resume command 00548 issued is most likely not applicable to the 00549 child, so just warn, and refuse to resume. */ 00550 warning (_("Not resuming: switched threads " 00551 "before following fork child.\n")); 00552 } 00553 00554 /* Reset breakpoints in the child as appropriate. */ 00555 follow_inferior_reset_breakpoints (); 00556 } 00557 else 00558 switch_to_thread (parent); 00559 } 00560 } 00561 break; 00562 case TARGET_WAITKIND_SPURIOUS: 00563 /* Nothing to follow. */ 00564 break; 00565 default: 00566 internal_error (__FILE__, __LINE__, 00567 "Unexpected pending_follow.kind %d\n", 00568 tp->pending_follow.kind); 00569 break; 00570 } 00571 00572 return should_resume; 00573 } 00574 00575 void 00576 follow_inferior_reset_breakpoints (void) 00577 { 00578 struct thread_info *tp = inferior_thread (); 00579 00580 /* Was there a step_resume breakpoint? (There was if the user 00581 did a "next" at the fork() call.) If so, explicitly reset its 00582 thread number. 00583 00584 step_resumes are a form of bp that are made to be per-thread. 00585 Since we created the step_resume bp when the parent process 00586 was being debugged, and now are switching to the child process, 00587 from the breakpoint package's viewpoint, that's a switch of 00588 "threads". We must update the bp's notion of which thread 00589 it is for, or it'll be ignored when it triggers. */ 00590 00591 if (tp->control.step_resume_breakpoint) 00592 breakpoint_re_set_thread (tp->control.step_resume_breakpoint); 00593 00594 if (tp->control.exception_resume_breakpoint) 00595 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint); 00596 00597 /* Reinsert all breakpoints in the child. The user may have set 00598 breakpoints after catching the fork, in which case those 00599 were never set in the child, but only in the parent. This makes 00600 sure the inserted breakpoints match the breakpoint list. */ 00601 00602 breakpoint_re_set (); 00603 insert_breakpoints (); 00604 } 00605 00606 /* The child has exited or execed: resume threads of the parent the 00607 user wanted to be executing. */ 00608 00609 static int 00610 proceed_after_vfork_done (struct thread_info *thread, 00611 void *arg) 00612 { 00613 int pid = * (int *) arg; 00614 00615 if (ptid_get_pid (thread->ptid) == pid 00616 && is_running (thread->ptid) 00617 && !is_executing (thread->ptid) 00618 && !thread->stop_requested 00619 && thread->suspend.stop_signal == GDB_SIGNAL_0) 00620 { 00621 if (debug_infrun) 00622 fprintf_unfiltered (gdb_stdlog, 00623 "infrun: resuming vfork parent thread %s\n", 00624 target_pid_to_str (thread->ptid)); 00625 00626 switch_to_thread (thread->ptid); 00627 clear_proceed_status (); 00628 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT, 0); 00629 } 00630 00631 return 0; 00632 } 00633 00634 /* Called whenever we notice an exec or exit event, to handle 00635 detaching or resuming a vfork parent. */ 00636 00637 static void 00638 handle_vfork_child_exec_or_exit (int exec) 00639 { 00640 struct inferior *inf = current_inferior (); 00641 00642 if (inf->vfork_parent) 00643 { 00644 int resume_parent = -1; 00645 00646 /* This exec or exit marks the end of the shared memory region 00647 between the parent and the child. If the user wanted to 00648 detach from the parent, now is the time. */ 00649 00650 if (inf->vfork_parent->pending_detach) 00651 { 00652 struct thread_info *tp; 00653 struct cleanup *old_chain; 00654 struct program_space *pspace; 00655 struct address_space *aspace; 00656 00657 /* follow-fork child, detach-on-fork on. */ 00658 00659 inf->vfork_parent->pending_detach = 0; 00660 00661 if (!exec) 00662 { 00663 /* If we're handling a child exit, then inferior_ptid 00664 points at the inferior's pid, not to a thread. */ 00665 old_chain = save_inferior_ptid (); 00666 save_current_program_space (); 00667 save_current_inferior (); 00668 } 00669 else 00670 old_chain = save_current_space_and_thread (); 00671 00672 /* We're letting loose of the parent. */ 00673 tp = any_live_thread_of_process (inf->vfork_parent->pid); 00674 switch_to_thread (tp->ptid); 00675 00676 /* We're about to detach from the parent, which implicitly 00677 removes breakpoints from its address space. There's a 00678 catch here: we want to reuse the spaces for the child, 00679 but, parent/child are still sharing the pspace at this 00680 point, although the exec in reality makes the kernel give 00681 the child a fresh set of new pages. The problem here is 00682 that the breakpoints module being unaware of this, would 00683 likely chose the child process to write to the parent 00684 address space. Swapping the child temporarily away from 00685 the spaces has the desired effect. Yes, this is "sort 00686 of" a hack. */ 00687 00688 pspace = inf->pspace; 00689 aspace = inf->aspace; 00690 inf->aspace = NULL; 00691 inf->pspace = NULL; 00692 00693 if (debug_infrun || info_verbose) 00694 { 00695 target_terminal_ours (); 00696 00697 if (exec) 00698 fprintf_filtered (gdb_stdlog, 00699 "Detaching vfork parent process " 00700 "%d after child exec.\n", 00701 inf->vfork_parent->pid); 00702 else 00703 fprintf_filtered (gdb_stdlog, 00704 "Detaching vfork parent process " 00705 "%d after child exit.\n", 00706 inf->vfork_parent->pid); 00707 } 00708 00709 target_detach (NULL, 0); 00710 00711 /* Put it back. */ 00712 inf->pspace = pspace; 00713 inf->aspace = aspace; 00714 00715 do_cleanups (old_chain); 00716 } 00717 else if (exec) 00718 { 00719 /* We're staying attached to the parent, so, really give the 00720 child a new address space. */ 00721 inf->pspace = add_program_space (maybe_new_address_space ()); 00722 inf->aspace = inf->pspace->aspace; 00723 inf->removable = 1; 00724 set_current_program_space (inf->pspace); 00725 00726 resume_parent = inf->vfork_parent->pid; 00727 00728 /* Break the bonds. */ 00729 inf->vfork_parent->vfork_child = NULL; 00730 } 00731 else 00732 { 00733 struct cleanup *old_chain; 00734 struct program_space *pspace; 00735 00736 /* If this is a vfork child exiting, then the pspace and 00737 aspaces were shared with the parent. Since we're 00738 reporting the process exit, we'll be mourning all that is 00739 found in the address space, and switching to null_ptid, 00740 preparing to start a new inferior. But, since we don't 00741 want to clobber the parent's address/program spaces, we 00742 go ahead and create a new one for this exiting 00743 inferior. */ 00744 00745 /* Switch to null_ptid, so that clone_program_space doesn't want 00746 to read the selected frame of a dead process. */ 00747 old_chain = save_inferior_ptid (); 00748 inferior_ptid = null_ptid; 00749 00750 /* This inferior is dead, so avoid giving the breakpoints 00751 module the option to write through to it (cloning a 00752 program space resets breakpoints). */ 00753 inf->aspace = NULL; 00754 inf->pspace = NULL; 00755 pspace = add_program_space (maybe_new_address_space ()); 00756 set_current_program_space (pspace); 00757 inf->removable = 1; 00758 inf->symfile_flags = SYMFILE_NO_READ; 00759 clone_program_space (pspace, inf->vfork_parent->pspace); 00760 inf->pspace = pspace; 00761 inf->aspace = pspace->aspace; 00762 00763 /* Put back inferior_ptid. We'll continue mourning this 00764 inferior. */ 00765 do_cleanups (old_chain); 00766 00767 resume_parent = inf->vfork_parent->pid; 00768 /* Break the bonds. */ 00769 inf->vfork_parent->vfork_child = NULL; 00770 } 00771 00772 inf->vfork_parent = NULL; 00773 00774 gdb_assert (current_program_space == inf->pspace); 00775 00776 if (non_stop && resume_parent != -1) 00777 { 00778 /* If the user wanted the parent to be running, let it go 00779 free now. */ 00780 struct cleanup *old_chain = make_cleanup_restore_current_thread (); 00781 00782 if (debug_infrun) 00783 fprintf_unfiltered (gdb_stdlog, 00784 "infrun: resuming vfork parent process %d\n", 00785 resume_parent); 00786 00787 iterate_over_threads (proceed_after_vfork_done, &resume_parent); 00788 00789 do_cleanups (old_chain); 00790 } 00791 } 00792 } 00793 00794 /* Enum strings for "set|show follow-exec-mode". */ 00795 00796 static const char follow_exec_mode_new[] = "new"; 00797 static const char follow_exec_mode_same[] = "same"; 00798 static const char *const follow_exec_mode_names[] = 00799 { 00800 follow_exec_mode_new, 00801 follow_exec_mode_same, 00802 NULL, 00803 }; 00804 00805 static const char *follow_exec_mode_string = follow_exec_mode_same; 00806 static void 00807 show_follow_exec_mode_string (struct ui_file *file, int from_tty, 00808 struct cmd_list_element *c, const char *value) 00809 { 00810 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value); 00811 } 00812 00813 /* EXECD_PATHNAME is assumed to be non-NULL. */ 00814 00815 static void 00816 follow_exec (ptid_t pid, char *execd_pathname) 00817 { 00818 struct thread_info *th = inferior_thread (); 00819 struct inferior *inf = current_inferior (); 00820 00821 /* This is an exec event that we actually wish to pay attention to. 00822 Refresh our symbol table to the newly exec'd program, remove any 00823 momentary bp's, etc. 00824 00825 If there are breakpoints, they aren't really inserted now, 00826 since the exec() transformed our inferior into a fresh set 00827 of instructions. 00828 00829 We want to preserve symbolic breakpoints on the list, since 00830 we have hopes that they can be reset after the new a.out's 00831 symbol table is read. 00832 00833 However, any "raw" breakpoints must be removed from the list 00834 (e.g., the solib bp's), since their address is probably invalid 00835 now. 00836 00837 And, we DON'T want to call delete_breakpoints() here, since 00838 that may write the bp's "shadow contents" (the instruction 00839 value that was overwritten witha TRAP instruction). Since 00840 we now have a new a.out, those shadow contents aren't valid. */ 00841 00842 mark_breakpoints_out (); 00843 00844 update_breakpoints_after_exec (); 00845 00846 /* If there was one, it's gone now. We cannot truly step-to-next 00847 statement through an exec(). */ 00848 th->control.step_resume_breakpoint = NULL; 00849 th->control.exception_resume_breakpoint = NULL; 00850 th->control.step_range_start = 0; 00851 th->control.step_range_end = 0; 00852 00853 /* The target reports the exec event to the main thread, even if 00854 some other thread does the exec, and even if the main thread was 00855 already stopped --- if debugging in non-stop mode, it's possible 00856 the user had the main thread held stopped in the previous image 00857 --- release it now. This is the same behavior as step-over-exec 00858 with scheduler-locking on in all-stop mode. */ 00859 th->stop_requested = 0; 00860 00861 /* What is this a.out's name? */ 00862 printf_unfiltered (_("%s is executing new program: %s\n"), 00863 target_pid_to_str (inferior_ptid), 00864 execd_pathname); 00865 00866 /* We've followed the inferior through an exec. Therefore, the 00867 inferior has essentially been killed & reborn. */ 00868 00869 gdb_flush (gdb_stdout); 00870 00871 breakpoint_init_inferior (inf_execd); 00872 00873 if (gdb_sysroot && *gdb_sysroot) 00874 { 00875 char *name = alloca (strlen (gdb_sysroot) 00876 + strlen (execd_pathname) 00877 + 1); 00878 00879 strcpy (name, gdb_sysroot); 00880 strcat (name, execd_pathname); 00881 execd_pathname = name; 00882 } 00883 00884 /* Reset the shared library package. This ensures that we get a 00885 shlib event when the child reaches "_start", at which point the 00886 dld will have had a chance to initialize the child. */ 00887 /* Also, loading a symbol file below may trigger symbol lookups, and 00888 we don't want those to be satisfied by the libraries of the 00889 previous incarnation of this process. */ 00890 no_shared_libraries (NULL, 0); 00891 00892 if (follow_exec_mode_string == follow_exec_mode_new) 00893 { 00894 struct program_space *pspace; 00895 00896 /* The user wants to keep the old inferior and program spaces 00897 around. Create a new fresh one, and switch to it. */ 00898 00899 inf = add_inferior (current_inferior ()->pid); 00900 pspace = add_program_space (maybe_new_address_space ()); 00901 inf->pspace = pspace; 00902 inf->aspace = pspace->aspace; 00903 00904 exit_inferior_num_silent (current_inferior ()->num); 00905 00906 set_current_inferior (inf); 00907 set_current_program_space (pspace); 00908 } 00909 else 00910 { 00911 /* The old description may no longer be fit for the new image. 00912 E.g, a 64-bit process exec'ed a 32-bit process. Clear the 00913 old description; we'll read a new one below. No need to do 00914 this on "follow-exec-mode new", as the old inferior stays 00915 around (its description is later cleared/refetched on 00916 restart). */ 00917 target_clear_description (); 00918 } 00919 00920 gdb_assert (current_program_space == inf->pspace); 00921 00922 /* That a.out is now the one to use. */ 00923 exec_file_attach (execd_pathname, 0); 00924 00925 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE 00926 (Position Independent Executable) main symbol file will get applied by 00927 solib_create_inferior_hook below. breakpoint_re_set would fail to insert 00928 the breakpoints with the zero displacement. */ 00929 00930 symbol_file_add (execd_pathname, 00931 (inf->symfile_flags 00932 | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET), 00933 NULL, 0); 00934 00935 if ((inf->symfile_flags & SYMFILE_NO_READ) == 0) 00936 set_initial_language (); 00937 00938 /* If the target can specify a description, read it. Must do this 00939 after flipping to the new executable (because the target supplied 00940 description must be compatible with the executable's 00941 architecture, and the old executable may e.g., be 32-bit, while 00942 the new one 64-bit), and before anything involving memory or 00943 registers. */ 00944 target_find_description (); 00945 00946 solib_create_inferior_hook (0); 00947 00948 jit_inferior_created_hook (); 00949 00950 breakpoint_re_set (); 00951 00952 /* Reinsert all breakpoints. (Those which were symbolic have 00953 been reset to the proper address in the new a.out, thanks 00954 to symbol_file_command...). */ 00955 insert_breakpoints (); 00956 00957 /* The next resume of this inferior should bring it to the shlib 00958 startup breakpoints. (If the user had also set bp's on 00959 "main" from the old (parent) process, then they'll auto- 00960 matically get reset there in the new process.). */ 00961 } 00962 00963 /* Non-zero if we just simulating a single-step. This is needed 00964 because we cannot remove the breakpoints in the inferior process 00965 until after the `wait' in `wait_for_inferior'. */ 00966 static int singlestep_breakpoints_inserted_p = 0; 00967 00968 /* The thread we inserted single-step breakpoints for. */ 00969 static ptid_t singlestep_ptid; 00970 00971 /* PC when we started this single-step. */ 00972 static CORE_ADDR singlestep_pc; 00973 00974 /* If another thread hit the singlestep breakpoint, we save the original 00975 thread here so that we can resume single-stepping it later. */ 00976 static ptid_t saved_singlestep_ptid; 00977 static int stepping_past_singlestep_breakpoint; 00978 00979 /* If not equal to null_ptid, this means that after stepping over breakpoint 00980 is finished, we need to switch to deferred_step_ptid, and step it. 00981 00982 The use case is when one thread has hit a breakpoint, and then the user 00983 has switched to another thread and issued 'step'. We need to step over 00984 breakpoint in the thread which hit the breakpoint, but then continue 00985 stepping the thread user has selected. */ 00986 static ptid_t deferred_step_ptid; 00987 00988 /* Displaced stepping. */ 00989 00990 /* In non-stop debugging mode, we must take special care to manage 00991 breakpoints properly; in particular, the traditional strategy for 00992 stepping a thread past a breakpoint it has hit is unsuitable. 00993 'Displaced stepping' is a tactic for stepping one thread past a 00994 breakpoint it has hit while ensuring that other threads running 00995 concurrently will hit the breakpoint as they should. 00996 00997 The traditional way to step a thread T off a breakpoint in a 00998 multi-threaded program in all-stop mode is as follows: 00999 01000 a0) Initially, all threads are stopped, and breakpoints are not 01001 inserted. 01002 a1) We single-step T, leaving breakpoints uninserted. 01003 a2) We insert breakpoints, and resume all threads. 01004 01005 In non-stop debugging, however, this strategy is unsuitable: we 01006 don't want to have to stop all threads in the system in order to 01007 continue or step T past a breakpoint. Instead, we use displaced 01008 stepping: 01009 01010 n0) Initially, T is stopped, other threads are running, and 01011 breakpoints are inserted. 01012 n1) We copy the instruction "under" the breakpoint to a separate 01013 location, outside the main code stream, making any adjustments 01014 to the instruction, register, and memory state as directed by 01015 T's architecture. 01016 n2) We single-step T over the instruction at its new location. 01017 n3) We adjust the resulting register and memory state as directed 01018 by T's architecture. This includes resetting T's PC to point 01019 back into the main instruction stream. 01020 n4) We resume T. 01021 01022 This approach depends on the following gdbarch methods: 01023 01024 - gdbarch_max_insn_length and gdbarch_displaced_step_location 01025 indicate where to copy the instruction, and how much space must 01026 be reserved there. We use these in step n1. 01027 01028 - gdbarch_displaced_step_copy_insn copies a instruction to a new 01029 address, and makes any necessary adjustments to the instruction, 01030 register contents, and memory. We use this in step n1. 01031 01032 - gdbarch_displaced_step_fixup adjusts registers and memory after 01033 we have successfuly single-stepped the instruction, to yield the 01034 same effect the instruction would have had if we had executed it 01035 at its original address. We use this in step n3. 01036 01037 - gdbarch_displaced_step_free_closure provides cleanup. 01038 01039 The gdbarch_displaced_step_copy_insn and 01040 gdbarch_displaced_step_fixup functions must be written so that 01041 copying an instruction with gdbarch_displaced_step_copy_insn, 01042 single-stepping across the copied instruction, and then applying 01043 gdbarch_displaced_insn_fixup should have the same effects on the 01044 thread's memory and registers as stepping the instruction in place 01045 would have. Exactly which responsibilities fall to the copy and 01046 which fall to the fixup is up to the author of those functions. 01047 01048 See the comments in gdbarch.sh for details. 01049 01050 Note that displaced stepping and software single-step cannot 01051 currently be used in combination, although with some care I think 01052 they could be made to. Software single-step works by placing 01053 breakpoints on all possible subsequent instructions; if the 01054 displaced instruction is a PC-relative jump, those breakpoints 01055 could fall in very strange places --- on pages that aren't 01056 executable, or at addresses that are not proper instruction 01057 boundaries. (We do generally let other threads run while we wait 01058 to hit the software single-step breakpoint, and they might 01059 encounter such a corrupted instruction.) One way to work around 01060 this would be to have gdbarch_displaced_step_copy_insn fully 01061 simulate the effect of PC-relative instructions (and return NULL) 01062 on architectures that use software single-stepping. 01063 01064 In non-stop mode, we can have independent and simultaneous step 01065 requests, so more than one thread may need to simultaneously step 01066 over a breakpoint. The current implementation assumes there is 01067 only one scratch space per process. In this case, we have to 01068 serialize access to the scratch space. If thread A wants to step 01069 over a breakpoint, but we are currently waiting for some other 01070 thread to complete a displaced step, we leave thread A stopped and 01071 place it in the displaced_step_request_queue. Whenever a displaced 01072 step finishes, we pick the next thread in the queue and start a new 01073 displaced step operation on it. See displaced_step_prepare and 01074 displaced_step_fixup for details. */ 01075 01076 struct displaced_step_request 01077 { 01078 ptid_t ptid; 01079 struct displaced_step_request *next; 01080 }; 01081 01082 /* Per-inferior displaced stepping state. */ 01083 struct displaced_step_inferior_state 01084 { 01085 /* Pointer to next in linked list. */ 01086 struct displaced_step_inferior_state *next; 01087 01088 /* The process this displaced step state refers to. */ 01089 int pid; 01090 01091 /* A queue of pending displaced stepping requests. One entry per 01092 thread that needs to do a displaced step. */ 01093 struct displaced_step_request *step_request_queue; 01094 01095 /* If this is not null_ptid, this is the thread carrying out a 01096 displaced single-step in process PID. This thread's state will 01097 require fixing up once it has completed its step. */ 01098 ptid_t step_ptid; 01099 01100 /* The architecture the thread had when we stepped it. */ 01101 struct gdbarch *step_gdbarch; 01102 01103 /* The closure provided gdbarch_displaced_step_copy_insn, to be used 01104 for post-step cleanup. */ 01105 struct displaced_step_closure *step_closure; 01106 01107 /* The address of the original instruction, and the copy we 01108 made. */ 01109 CORE_ADDR step_original, step_copy; 01110 01111 /* Saved contents of copy area. */ 01112 gdb_byte *step_saved_copy; 01113 }; 01114 01115 /* The list of states of processes involved in displaced stepping 01116 presently. */ 01117 static struct displaced_step_inferior_state *displaced_step_inferior_states; 01118 01119 /* Get the displaced stepping state of process PID. */ 01120 01121 static struct displaced_step_inferior_state * 01122 get_displaced_stepping_state (int pid) 01123 { 01124 struct displaced_step_inferior_state *state; 01125 01126 for (state = displaced_step_inferior_states; 01127 state != NULL; 01128 state = state->next) 01129 if (state->pid == pid) 01130 return state; 01131 01132 return NULL; 01133 } 01134 01135 /* Add a new displaced stepping state for process PID to the displaced 01136 stepping state list, or return a pointer to an already existing 01137 entry, if it already exists. Never returns NULL. */ 01138 01139 static struct displaced_step_inferior_state * 01140 add_displaced_stepping_state (int pid) 01141 { 01142 struct displaced_step_inferior_state *state; 01143 01144 for (state = displaced_step_inferior_states; 01145 state != NULL; 01146 state = state->next) 01147 if (state->pid == pid) 01148 return state; 01149 01150 state = xcalloc (1, sizeof (*state)); 01151 state->pid = pid; 01152 state->next = displaced_step_inferior_states; 01153 displaced_step_inferior_states = state; 01154 01155 return state; 01156 } 01157 01158 /* If inferior is in displaced stepping, and ADDR equals to starting address 01159 of copy area, return corresponding displaced_step_closure. Otherwise, 01160 return NULL. */ 01161 01162 struct displaced_step_closure* 01163 get_displaced_step_closure_by_addr (CORE_ADDR addr) 01164 { 01165 struct displaced_step_inferior_state *displaced 01166 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); 01167 01168 /* If checking the mode of displaced instruction in copy area. */ 01169 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid) 01170 && (displaced->step_copy == addr)) 01171 return displaced->step_closure; 01172 01173 return NULL; 01174 } 01175 01176 /* Remove the displaced stepping state of process PID. */ 01177 01178 static void 01179 remove_displaced_stepping_state (int pid) 01180 { 01181 struct displaced_step_inferior_state *it, **prev_next_p; 01182 01183 gdb_assert (pid != 0); 01184 01185 it = displaced_step_inferior_states; 01186 prev_next_p = &displaced_step_inferior_states; 01187 while (it) 01188 { 01189 if (it->pid == pid) 01190 { 01191 *prev_next_p = it->next; 01192 xfree (it); 01193 return; 01194 } 01195 01196 prev_next_p = &it->next; 01197 it = *prev_next_p; 01198 } 01199 } 01200 01201 static void 01202 infrun_inferior_exit (struct inferior *inf) 01203 { 01204 remove_displaced_stepping_state (inf->pid); 01205 } 01206 01207 /* If ON, and the architecture supports it, GDB will use displaced 01208 stepping to step over breakpoints. If OFF, or if the architecture 01209 doesn't support it, GDB will instead use the traditional 01210 hold-and-step approach. If AUTO (which is the default), GDB will 01211 decide which technique to use to step over breakpoints depending on 01212 which of all-stop or non-stop mode is active --- displaced stepping 01213 in non-stop mode; hold-and-step in all-stop mode. */ 01214 01215 static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO; 01216 01217 static void 01218 show_can_use_displaced_stepping (struct ui_file *file, int from_tty, 01219 struct cmd_list_element *c, 01220 const char *value) 01221 { 01222 if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO) 01223 fprintf_filtered (file, 01224 _("Debugger's willingness to use displaced stepping " 01225 "to step over breakpoints is %s (currently %s).\n"), 01226 value, non_stop ? "on" : "off"); 01227 else 01228 fprintf_filtered (file, 01229 _("Debugger's willingness to use displaced stepping " 01230 "to step over breakpoints is %s.\n"), value); 01231 } 01232 01233 /* Return non-zero if displaced stepping can/should be used to step 01234 over breakpoints. */ 01235 01236 static int 01237 use_displaced_stepping (struct gdbarch *gdbarch) 01238 { 01239 return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop) 01240 || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE) 01241 && gdbarch_displaced_step_copy_insn_p (gdbarch) 01242 && !RECORD_IS_USED); 01243 } 01244 01245 /* Clean out any stray displaced stepping state. */ 01246 static void 01247 displaced_step_clear (struct displaced_step_inferior_state *displaced) 01248 { 01249 /* Indicate that there is no cleanup pending. */ 01250 displaced->step_ptid = null_ptid; 01251 01252 if (displaced->step_closure) 01253 { 01254 gdbarch_displaced_step_free_closure (displaced->step_gdbarch, 01255 displaced->step_closure); 01256 displaced->step_closure = NULL; 01257 } 01258 } 01259 01260 static void 01261 displaced_step_clear_cleanup (void *arg) 01262 { 01263 struct displaced_step_inferior_state *state = arg; 01264 01265 displaced_step_clear (state); 01266 } 01267 01268 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ 01269 void 01270 displaced_step_dump_bytes (struct ui_file *file, 01271 const gdb_byte *buf, 01272 size_t len) 01273 { 01274 int i; 01275 01276 for (i = 0; i < len; i++) 01277 fprintf_unfiltered (file, "%02x ", buf[i]); 01278 fputs_unfiltered ("\n", file); 01279 } 01280 01281 /* Prepare to single-step, using displaced stepping. 01282 01283 Note that we cannot use displaced stepping when we have a signal to 01284 deliver. If we have a signal to deliver and an instruction to step 01285 over, then after the step, there will be no indication from the 01286 target whether the thread entered a signal handler or ignored the 01287 signal and stepped over the instruction successfully --- both cases 01288 result in a simple SIGTRAP. In the first case we mustn't do a 01289 fixup, and in the second case we must --- but we can't tell which. 01290 Comments in the code for 'random signals' in handle_inferior_event 01291 explain how we handle this case instead. 01292 01293 Returns 1 if preparing was successful -- this thread is going to be 01294 stepped now; or 0 if displaced stepping this thread got queued. */ 01295 static int 01296 displaced_step_prepare (ptid_t ptid) 01297 { 01298 struct cleanup *old_cleanups, *ignore_cleanups; 01299 struct thread_info *tp = find_thread_ptid (ptid); 01300 struct regcache *regcache = get_thread_regcache (ptid); 01301 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01302 CORE_ADDR original, copy; 01303 ULONGEST len; 01304 struct displaced_step_closure *closure; 01305 struct displaced_step_inferior_state *displaced; 01306 int status; 01307 01308 /* We should never reach this function if the architecture does not 01309 support displaced stepping. */ 01310 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch)); 01311 01312 /* Disable range stepping while executing in the scratch pad. We 01313 want a single-step even if executing the displaced instruction in 01314 the scratch buffer lands within the stepping range (e.g., a 01315 jump/branch). */ 01316 tp->control.may_range_step = 0; 01317 01318 /* We have to displaced step one thread at a time, as we only have 01319 access to a single scratch space per inferior. */ 01320 01321 displaced = add_displaced_stepping_state (ptid_get_pid (ptid)); 01322 01323 if (!ptid_equal (displaced->step_ptid, null_ptid)) 01324 { 01325 /* Already waiting for a displaced step to finish. Defer this 01326 request and place in queue. */ 01327 struct displaced_step_request *req, *new_req; 01328 01329 if (debug_displaced) 01330 fprintf_unfiltered (gdb_stdlog, 01331 "displaced: defering step of %s\n", 01332 target_pid_to_str (ptid)); 01333 01334 new_req = xmalloc (sizeof (*new_req)); 01335 new_req->ptid = ptid; 01336 new_req->next = NULL; 01337 01338 if (displaced->step_request_queue) 01339 { 01340 for (req = displaced->step_request_queue; 01341 req && req->next; 01342 req = req->next) 01343 ; 01344 req->next = new_req; 01345 } 01346 else 01347 displaced->step_request_queue = new_req; 01348 01349 return 0; 01350 } 01351 else 01352 { 01353 if (debug_displaced) 01354 fprintf_unfiltered (gdb_stdlog, 01355 "displaced: stepping %s now\n", 01356 target_pid_to_str (ptid)); 01357 } 01358 01359 displaced_step_clear (displaced); 01360 01361 old_cleanups = save_inferior_ptid (); 01362 inferior_ptid = ptid; 01363 01364 original = regcache_read_pc (regcache); 01365 01366 copy = gdbarch_displaced_step_location (gdbarch); 01367 len = gdbarch_max_insn_length (gdbarch); 01368 01369 /* Save the original contents of the copy area. */ 01370 displaced->step_saved_copy = xmalloc (len); 01371 ignore_cleanups = make_cleanup (free_current_contents, 01372 &displaced->step_saved_copy); 01373 status = target_read_memory (copy, displaced->step_saved_copy, len); 01374 if (status != 0) 01375 throw_error (MEMORY_ERROR, 01376 _("Error accessing memory address %s (%s) for " 01377 "displaced-stepping scratch space."), 01378 paddress (gdbarch, copy), safe_strerror (status)); 01379 if (debug_displaced) 01380 { 01381 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ", 01382 paddress (gdbarch, copy)); 01383 displaced_step_dump_bytes (gdb_stdlog, 01384 displaced->step_saved_copy, 01385 len); 01386 }; 01387 01388 closure = gdbarch_displaced_step_copy_insn (gdbarch, 01389 original, copy, regcache); 01390 01391 /* We don't support the fully-simulated case at present. */ 01392 gdb_assert (closure); 01393 01394 /* Save the information we need to fix things up if the step 01395 succeeds. */ 01396 displaced->step_ptid = ptid; 01397 displaced->step_gdbarch = gdbarch; 01398 displaced->step_closure = closure; 01399 displaced->step_original = original; 01400 displaced->step_copy = copy; 01401 01402 make_cleanup (displaced_step_clear_cleanup, displaced); 01403 01404 /* Resume execution at the copy. */ 01405 regcache_write_pc (regcache, copy); 01406 01407 discard_cleanups (ignore_cleanups); 01408 01409 do_cleanups (old_cleanups); 01410 01411 if (debug_displaced) 01412 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n", 01413 paddress (gdbarch, copy)); 01414 01415 return 1; 01416 } 01417 01418 static void 01419 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, 01420 const gdb_byte *myaddr, int len) 01421 { 01422 struct cleanup *ptid_cleanup = save_inferior_ptid (); 01423 01424 inferior_ptid = ptid; 01425 write_memory (memaddr, myaddr, len); 01426 do_cleanups (ptid_cleanup); 01427 } 01428 01429 /* Restore the contents of the copy area for thread PTID. */ 01430 01431 static void 01432 displaced_step_restore (struct displaced_step_inferior_state *displaced, 01433 ptid_t ptid) 01434 { 01435 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch); 01436 01437 write_memory_ptid (ptid, displaced->step_copy, 01438 displaced->step_saved_copy, len); 01439 if (debug_displaced) 01440 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n", 01441 target_pid_to_str (ptid), 01442 paddress (displaced->step_gdbarch, 01443 displaced->step_copy)); 01444 } 01445 01446 static void 01447 displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal) 01448 { 01449 struct cleanup *old_cleanups; 01450 struct displaced_step_inferior_state *displaced 01451 = get_displaced_stepping_state (ptid_get_pid (event_ptid)); 01452 01453 /* Was any thread of this process doing a displaced step? */ 01454 if (displaced == NULL) 01455 return; 01456 01457 /* Was this event for the pid we displaced? */ 01458 if (ptid_equal (displaced->step_ptid, null_ptid) 01459 || ! ptid_equal (displaced->step_ptid, event_ptid)) 01460 return; 01461 01462 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced); 01463 01464 displaced_step_restore (displaced, displaced->step_ptid); 01465 01466 /* Did the instruction complete successfully? */ 01467 if (signal == GDB_SIGNAL_TRAP) 01468 { 01469 /* Fix up the resulting state. */ 01470 gdbarch_displaced_step_fixup (displaced->step_gdbarch, 01471 displaced->step_closure, 01472 displaced->step_original, 01473 displaced->step_copy, 01474 get_thread_regcache (displaced->step_ptid)); 01475 } 01476 else 01477 { 01478 /* Since the instruction didn't complete, all we can do is 01479 relocate the PC. */ 01480 struct regcache *regcache = get_thread_regcache (event_ptid); 01481 CORE_ADDR pc = regcache_read_pc (regcache); 01482 01483 pc = displaced->step_original + (pc - displaced->step_copy); 01484 regcache_write_pc (regcache, pc); 01485 } 01486 01487 do_cleanups (old_cleanups); 01488 01489 displaced->step_ptid = null_ptid; 01490 01491 /* Are there any pending displaced stepping requests? If so, run 01492 one now. Leave the state object around, since we're likely to 01493 need it again soon. */ 01494 while (displaced->step_request_queue) 01495 { 01496 struct displaced_step_request *head; 01497 ptid_t ptid; 01498 struct regcache *regcache; 01499 struct gdbarch *gdbarch; 01500 CORE_ADDR actual_pc; 01501 struct address_space *aspace; 01502 01503 head = displaced->step_request_queue; 01504 ptid = head->ptid; 01505 displaced->step_request_queue = head->next; 01506 xfree (head); 01507 01508 context_switch (ptid); 01509 01510 regcache = get_thread_regcache (ptid); 01511 actual_pc = regcache_read_pc (regcache); 01512 aspace = get_regcache_aspace (regcache); 01513 01514 if (breakpoint_here_p (aspace, actual_pc)) 01515 { 01516 if (debug_displaced) 01517 fprintf_unfiltered (gdb_stdlog, 01518 "displaced: stepping queued %s now\n", 01519 target_pid_to_str (ptid)); 01520 01521 displaced_step_prepare (ptid); 01522 01523 gdbarch = get_regcache_arch (regcache); 01524 01525 if (debug_displaced) 01526 { 01527 CORE_ADDR actual_pc = regcache_read_pc (regcache); 01528 gdb_byte buf[4]; 01529 01530 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", 01531 paddress (gdbarch, actual_pc)); 01532 read_memory (actual_pc, buf, sizeof (buf)); 01533 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); 01534 } 01535 01536 if (gdbarch_displaced_step_hw_singlestep (gdbarch, 01537 displaced->step_closure)) 01538 target_resume (ptid, 1, GDB_SIGNAL_0); 01539 else 01540 target_resume (ptid, 0, GDB_SIGNAL_0); 01541 01542 /* Done, we're stepping a thread. */ 01543 break; 01544 } 01545 else 01546 { 01547 int step; 01548 struct thread_info *tp = inferior_thread (); 01549 01550 /* The breakpoint we were sitting under has since been 01551 removed. */ 01552 tp->control.trap_expected = 0; 01553 01554 /* Go back to what we were trying to do. */ 01555 step = currently_stepping (tp); 01556 01557 if (debug_displaced) 01558 fprintf_unfiltered (gdb_stdlog, 01559 "displaced: breakpoint is gone: %s, step(%d)\n", 01560 target_pid_to_str (tp->ptid), step); 01561 01562 target_resume (ptid, step, GDB_SIGNAL_0); 01563 tp->suspend.stop_signal = GDB_SIGNAL_0; 01564 01565 /* This request was discarded. See if there's any other 01566 thread waiting for its turn. */ 01567 } 01568 } 01569 } 01570 01571 /* Update global variables holding ptids to hold NEW_PTID if they were 01572 holding OLD_PTID. */ 01573 static void 01574 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) 01575 { 01576 struct displaced_step_request *it; 01577 struct displaced_step_inferior_state *displaced; 01578 01579 if (ptid_equal (inferior_ptid, old_ptid)) 01580 inferior_ptid = new_ptid; 01581 01582 if (ptid_equal (singlestep_ptid, old_ptid)) 01583 singlestep_ptid = new_ptid; 01584 01585 if (ptid_equal (deferred_step_ptid, old_ptid)) 01586 deferred_step_ptid = new_ptid; 01587 01588 for (displaced = displaced_step_inferior_states; 01589 displaced; 01590 displaced = displaced->next) 01591 { 01592 if (ptid_equal (displaced->step_ptid, old_ptid)) 01593 displaced->step_ptid = new_ptid; 01594 01595 for (it = displaced->step_request_queue; it; it = it->next) 01596 if (ptid_equal (it->ptid, old_ptid)) 01597 it->ptid = new_ptid; 01598 } 01599 } 01600 01601 01602 /* Resuming. */ 01603 01604 /* Things to clean up if we QUIT out of resume (). */ 01605 static void 01606 resume_cleanups (void *ignore) 01607 { 01608 normal_stop (); 01609 } 01610 01611 static const char schedlock_off[] = "off"; 01612 static const char schedlock_on[] = "on"; 01613 static const char schedlock_step[] = "step"; 01614 static const char *const scheduler_enums[] = { 01615 schedlock_off, 01616 schedlock_on, 01617 schedlock_step, 01618 NULL 01619 }; 01620 static const char *scheduler_mode = schedlock_off; 01621 static void 01622 show_scheduler_mode (struct ui_file *file, int from_tty, 01623 struct cmd_list_element *c, const char *value) 01624 { 01625 fprintf_filtered (file, 01626 _("Mode for locking scheduler " 01627 "during execution is \"%s\".\n"), 01628 value); 01629 } 01630 01631 static void 01632 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) 01633 { 01634 if (!target_can_lock_scheduler) 01635 { 01636 scheduler_mode = schedlock_off; 01637 error (_("Target '%s' cannot support this command."), target_shortname); 01638 } 01639 } 01640 01641 /* True if execution commands resume all threads of all processes by 01642 default; otherwise, resume only threads of the current inferior 01643 process. */ 01644 int sched_multi = 0; 01645 01646 /* Try to setup for software single stepping over the specified location. 01647 Return 1 if target_resume() should use hardware single step. 01648 01649 GDBARCH the current gdbarch. 01650 PC the location to step over. */ 01651 01652 static int 01653 maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc) 01654 { 01655 int hw_step = 1; 01656 01657 if (execution_direction == EXEC_FORWARD 01658 && gdbarch_software_single_step_p (gdbarch) 01659 && gdbarch_software_single_step (gdbarch, get_current_frame ())) 01660 { 01661 hw_step = 0; 01662 /* Do not pull these breakpoints until after a `wait' in 01663 `wait_for_inferior'. */ 01664 singlestep_breakpoints_inserted_p = 1; 01665 singlestep_ptid = inferior_ptid; 01666 singlestep_pc = pc; 01667 } 01668 return hw_step; 01669 } 01670 01671 /* Return a ptid representing the set of threads that we will proceed, 01672 in the perspective of the user/frontend. We may actually resume 01673 fewer threads at first, e.g., if a thread is stopped at a 01674 breakpoint that needs stepping-off, but that should not be visible 01675 to the user/frontend, and neither should the frontend/user be 01676 allowed to proceed any of the threads that happen to be stopped for 01677 internal run control handling, if a previous command wanted them 01678 resumed. */ 01679 01680 ptid_t 01681 user_visible_resume_ptid (int step) 01682 { 01683 /* By default, resume all threads of all processes. */ 01684 ptid_t resume_ptid = RESUME_ALL; 01685 01686 /* Maybe resume only all threads of the current process. */ 01687 if (!sched_multi && target_supports_multi_process ()) 01688 { 01689 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); 01690 } 01691 01692 /* Maybe resume a single thread after all. */ 01693 if (non_stop) 01694 { 01695 /* With non-stop mode on, threads are always handled 01696 individually. */ 01697 resume_ptid = inferior_ptid; 01698 } 01699 else if ((scheduler_mode == schedlock_on) 01700 || (scheduler_mode == schedlock_step 01701 && (step || singlestep_breakpoints_inserted_p))) 01702 { 01703 /* User-settable 'scheduler' mode requires solo thread resume. */ 01704 resume_ptid = inferior_ptid; 01705 } 01706 01707 return resume_ptid; 01708 } 01709 01710 /* Resume the inferior, but allow a QUIT. This is useful if the user 01711 wants to interrupt some lengthy single-stepping operation 01712 (for child processes, the SIGINT goes to the inferior, and so 01713 we get a SIGINT random_signal, but for remote debugging and perhaps 01714 other targets, that's not true). 01715 01716 STEP nonzero if we should step (zero to continue instead). 01717 SIG is the signal to give the inferior (zero for none). */ 01718 void 01719 resume (int step, enum gdb_signal sig) 01720 { 01721 int should_resume = 1; 01722 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); 01723 struct regcache *regcache = get_current_regcache (); 01724 struct gdbarch *gdbarch = get_regcache_arch (regcache); 01725 struct thread_info *tp = inferior_thread (); 01726 CORE_ADDR pc = regcache_read_pc (regcache); 01727 struct address_space *aspace = get_regcache_aspace (regcache); 01728 01729 QUIT; 01730 01731 if (current_inferior ()->waiting_for_vfork_done) 01732 { 01733 /* Don't try to single-step a vfork parent that is waiting for 01734 the child to get out of the shared memory region (by exec'ing 01735 or exiting). This is particularly important on software 01736 single-step archs, as the child process would trip on the 01737 software single step breakpoint inserted for the parent 01738 process. Since the parent will not actually execute any 01739 instruction until the child is out of the shared region (such 01740 are vfork's semantics), it is safe to simply continue it. 01741 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for 01742 the parent, and tell it to `keep_going', which automatically 01743 re-sets it stepping. */ 01744 if (debug_infrun) 01745 fprintf_unfiltered (gdb_stdlog, 01746 "infrun: resume : clear step\n"); 01747 step = 0; 01748 } 01749 01750 if (debug_infrun) 01751 fprintf_unfiltered (gdb_stdlog, 01752 "infrun: resume (step=%d, signal=%d), " 01753 "trap_expected=%d, current thread [%s] at %s\n", 01754 step, sig, tp->control.trap_expected, 01755 target_pid_to_str (inferior_ptid), 01756 paddress (gdbarch, pc)); 01757 01758 /* Normally, by the time we reach `resume', the breakpoints are either 01759 removed or inserted, as appropriate. The exception is if we're sitting 01760 at a permanent breakpoint; we need to step over it, but permanent 01761 breakpoints can't be removed. So we have to test for it here. */ 01762 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here) 01763 { 01764 if (gdbarch_skip_permanent_breakpoint_p (gdbarch)) 01765 gdbarch_skip_permanent_breakpoint (gdbarch, regcache); 01766 else 01767 error (_("\ 01768 The program is stopped at a permanent breakpoint, but GDB does not know\n\ 01769 how to step past a permanent breakpoint on this architecture. Try using\n\ 01770 a command like `return' or `jump' to continue execution.")); 01771 } 01772 01773 /* If we have a breakpoint to step over, make sure to do a single 01774 step only. Same if we have software watchpoints. */ 01775 if (tp->control.trap_expected || bpstat_should_step ()) 01776 tp->control.may_range_step = 0; 01777 01778 /* If enabled, step over breakpoints by executing a copy of the 01779 instruction at a different address. 01780 01781 We can't use displaced stepping when we have a signal to deliver; 01782 the comments for displaced_step_prepare explain why. The 01783 comments in the handle_inferior event for dealing with 'random 01784 signals' explain what we do instead. 01785 01786 We can't use displaced stepping when we are waiting for vfork_done 01787 event, displaced stepping breaks the vfork child similarly as single 01788 step software breakpoint. */ 01789 if (use_displaced_stepping (gdbarch) 01790 && (tp->control.trap_expected 01791 || (step && gdbarch_software_single_step_p (gdbarch))) 01792 && sig == GDB_SIGNAL_0 01793 && !current_inferior ()->waiting_for_vfork_done) 01794 { 01795 struct displaced_step_inferior_state *displaced; 01796 01797 if (!displaced_step_prepare (inferior_ptid)) 01798 { 01799 /* Got placed in displaced stepping queue. Will be resumed 01800 later when all the currently queued displaced stepping 01801 requests finish. The thread is not executing at this point, 01802 and the call to set_executing will be made later. But we 01803 need to call set_running here, since from frontend point of view, 01804 the thread is running. */ 01805 set_running (inferior_ptid, 1); 01806 discard_cleanups (old_cleanups); 01807 return; 01808 } 01809 01810 /* Update pc to reflect the new address from which we will execute 01811 instructions due to displaced stepping. */ 01812 pc = regcache_read_pc (get_thread_regcache (inferior_ptid)); 01813 01814 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); 01815 step = gdbarch_displaced_step_hw_singlestep (gdbarch, 01816 displaced->step_closure); 01817 } 01818 01819 /* Do we need to do it the hard way, w/temp breakpoints? */ 01820 else if (step) 01821 step = maybe_software_singlestep (gdbarch, pc); 01822 01823 /* Currently, our software single-step implementation leads to different 01824 results than hardware single-stepping in one situation: when stepping 01825 into delivering a signal which has an associated signal handler, 01826 hardware single-step will stop at the first instruction of the handler, 01827 while software single-step will simply skip execution of the handler. 01828 01829 For now, this difference in behavior is accepted since there is no 01830 easy way to actually implement single-stepping into a signal handler 01831 without kernel support. 01832 01833 However, there is one scenario where this difference leads to follow-on 01834 problems: if we're stepping off a breakpoint by removing all breakpoints 01835 and then single-stepping. In this case, the software single-step 01836 behavior means that even if there is a *breakpoint* in the signal 01837 handler, GDB still would not stop. 01838 01839 Fortunately, we can at least fix this particular issue. We detect 01840 here the case where we are about to deliver a signal while software 01841 single-stepping with breakpoints removed. In this situation, we 01842 revert the decisions to remove all breakpoints and insert single- 01843 step breakpoints, and instead we install a step-resume breakpoint 01844 at the current address, deliver the signal without stepping, and 01845 once we arrive back at the step-resume breakpoint, actually step 01846 over the breakpoint we originally wanted to step over. */ 01847 if (singlestep_breakpoints_inserted_p 01848 && tp->control.trap_expected && sig != GDB_SIGNAL_0) 01849 { 01850 /* If we have nested signals or a pending signal is delivered 01851 immediately after a handler returns, might might already have 01852 a step-resume breakpoint set on the earlier handler. We cannot 01853 set another step-resume breakpoint; just continue on until the 01854 original breakpoint is hit. */ 01855 if (tp->control.step_resume_breakpoint == NULL) 01856 { 01857 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ()); 01858 tp->step_after_step_resume_breakpoint = 1; 01859 } 01860 01861 remove_single_step_breakpoints (); 01862 singlestep_breakpoints_inserted_p = 0; 01863 01864 insert_breakpoints (); 01865 tp->control.trap_expected = 0; 01866 } 01867 01868 if (should_resume) 01869 { 01870 ptid_t resume_ptid; 01871 01872 /* If STEP is set, it's a request to use hardware stepping 01873 facilities. But in that case, we should never 01874 use singlestep breakpoint. */ 01875 gdb_assert (!(singlestep_breakpoints_inserted_p && step)); 01876 01877 /* Decide the set of threads to ask the target to resume. Start 01878 by assuming everything will be resumed, than narrow the set 01879 by applying increasingly restricting conditions. */ 01880 resume_ptid = user_visible_resume_ptid (step); 01881 01882 /* Maybe resume a single thread after all. */ 01883 if (singlestep_breakpoints_inserted_p 01884 && stepping_past_singlestep_breakpoint) 01885 { 01886 /* The situation here is as follows. In thread T1 we wanted to 01887 single-step. Lacking hardware single-stepping we've 01888 set breakpoint at the PC of the next instruction -- call it 01889 P. After resuming, we've hit that breakpoint in thread T2. 01890 Now we've removed original breakpoint, inserted breakpoint 01891 at P+1, and try to step to advance T2 past breakpoint. 01892 We need to step only T2, as if T1 is allowed to freely run, 01893 it can run past P, and if other threads are allowed to run, 01894 they can hit breakpoint at P+1, and nested hits of single-step 01895 breakpoints is not something we'd want -- that's complicated 01896 to support, and has no value. */ 01897 resume_ptid = inferior_ptid; 01898 } 01899 else if ((step || singlestep_breakpoints_inserted_p) 01900 && tp->control.trap_expected) 01901 { 01902 /* We're allowing a thread to run past a breakpoint it has 01903 hit, by single-stepping the thread with the breakpoint 01904 removed. In which case, we need to single-step only this 01905 thread, and keep others stopped, as they can miss this 01906 breakpoint if allowed to run. 01907 01908 The current code actually removes all breakpoints when 01909 doing this, not just the one being stepped over, so if we 01910 let other threads run, we can actually miss any 01911 breakpoint, not just the one at PC. */ 01912 resume_ptid = inferior_ptid; 01913 } 01914 01915 if (gdbarch_cannot_step_breakpoint (gdbarch)) 01916 { 01917 /* Most targets can step a breakpoint instruction, thus 01918 executing it normally. But if this one cannot, just 01919 continue and we will hit it anyway. */ 01920 if (step && breakpoint_inserted_here_p (aspace, pc)) 01921 step = 0; 01922 } 01923 01924 if (debug_displaced 01925 && use_displaced_stepping (gdbarch) 01926 && tp->control.trap_expected) 01927 { 01928 struct regcache *resume_regcache = get_thread_regcache (resume_ptid); 01929 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache); 01930 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache); 01931 gdb_byte buf[4]; 01932 01933 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", 01934 paddress (resume_gdbarch, actual_pc)); 01935 read_memory (actual_pc, buf, sizeof (buf)); 01936 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); 01937 } 01938 01939 if (tp->control.may_range_step) 01940 { 01941 /* If we're resuming a thread with the PC out of the step 01942 range, then we're doing some nested/finer run control 01943 operation, like stepping the thread out of the dynamic 01944 linker or the displaced stepping scratch pad. We 01945 shouldn't have allowed a range step then. */ 01946 gdb_assert (pc_in_thread_step_range (pc, tp)); 01947 } 01948 01949 /* Install inferior's terminal modes. */ 01950 target_terminal_inferior (); 01951 01952 /* Avoid confusing the next resume, if the next stop/resume 01953 happens to apply to another thread. */ 01954 tp->suspend.stop_signal = GDB_SIGNAL_0; 01955 01956 /* Advise target which signals may be handled silently. If we have 01957 removed breakpoints because we are stepping over one (which can 01958 happen only if we are not using displaced stepping), we need to 01959 receive all signals to avoid accidentally skipping a breakpoint 01960 during execution of a signal handler. */ 01961 if ((step || singlestep_breakpoints_inserted_p) 01962 && tp->control.trap_expected 01963 && !use_displaced_stepping (gdbarch)) 01964 target_pass_signals (0, NULL); 01965 else 01966 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass); 01967 01968 target_resume (resume_ptid, step, sig); 01969 } 01970 01971 discard_cleanups (old_cleanups); 01972 } 01973 01974 /* Proceeding. */ 01975 01976 /* Clear out all variables saying what to do when inferior is continued. 01977 First do this, then set the ones you want, then call `proceed'. */ 01978 01979 static void 01980 clear_proceed_status_thread (struct thread_info *tp) 01981 { 01982 if (debug_infrun) 01983 fprintf_unfiltered (gdb_stdlog, 01984 "infrun: clear_proceed_status_thread (%s)\n", 01985 target_pid_to_str (tp->ptid)); 01986 01987 tp->control.trap_expected = 0; 01988 tp->control.step_range_start = 0; 01989 tp->control.step_range_end = 0; 01990 tp->control.may_range_step = 0; 01991 tp->control.step_frame_id = null_frame_id; 01992 tp->control.step_stack_frame_id = null_frame_id; 01993 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE; 01994 tp->stop_requested = 0; 01995 01996 tp->control.stop_step = 0; 01997 01998 tp->control.proceed_to_finish = 0; 01999 02000 /* Discard any remaining commands or status from previous stop. */ 02001 bpstat_clear (&tp->control.stop_bpstat); 02002 } 02003 02004 static int 02005 clear_proceed_status_callback (struct thread_info *tp, void *data) 02006 { 02007 if (is_exited (tp->ptid)) 02008 return 0; 02009 02010 clear_proceed_status_thread (tp); 02011 return 0; 02012 } 02013 02014 void 02015 clear_proceed_status (void) 02016 { 02017 if (!non_stop) 02018 { 02019 /* In all-stop mode, delete the per-thread status of all 02020 threads, even if inferior_ptid is null_ptid, there may be 02021 threads on the list. E.g., we may be launching a new 02022 process, while selecting the executable. */ 02023 iterate_over_threads (clear_proceed_status_callback, NULL); 02024 } 02025 02026 if (!ptid_equal (inferior_ptid, null_ptid)) 02027 { 02028 struct inferior *inferior; 02029 02030 if (non_stop) 02031 { 02032 /* If in non-stop mode, only delete the per-thread status of 02033 the current thread. */ 02034 clear_proceed_status_thread (inferior_thread ()); 02035 } 02036 02037 inferior = current_inferior (); 02038 inferior->control.stop_soon = NO_STOP_QUIETLY; 02039 } 02040 02041 stop_after_trap = 0; 02042 02043 observer_notify_about_to_proceed (); 02044 02045 if (stop_registers) 02046 { 02047 regcache_xfree (stop_registers); 02048 stop_registers = NULL; 02049 } 02050 } 02051 02052 /* Check the current thread against the thread that reported the most recent 02053 event. If a step-over is required return TRUE and set the current thread 02054 to the old thread. Otherwise return FALSE. 02055 02056 This should be suitable for any targets that support threads. */ 02057 02058 static int 02059 prepare_to_proceed (int step) 02060 { 02061 ptid_t wait_ptid; 02062 struct target_waitstatus wait_status; 02063 int schedlock_enabled; 02064 02065 /* With non-stop mode on, threads are always handled individually. */ 02066 gdb_assert (! non_stop); 02067 02068 /* Get the last target status returned by target_wait(). */ 02069 get_last_target_status (&wait_ptid, &wait_status); 02070 02071 /* Make sure we were stopped at a breakpoint. */ 02072 if (wait_status.kind != TARGET_WAITKIND_STOPPED 02073 || (wait_status.value.sig != GDB_SIGNAL_TRAP 02074 && wait_status.value.sig != GDB_SIGNAL_ILL 02075 && wait_status.value.sig != GDB_SIGNAL_SEGV 02076 && wait_status.value.sig != GDB_SIGNAL_EMT)) 02077 { 02078 return 0; 02079 } 02080 02081 schedlock_enabled = (scheduler_mode == schedlock_on 02082 || (scheduler_mode == schedlock_step 02083 && step)); 02084 02085 /* Don't switch over to WAIT_PTID if scheduler locking is on. */ 02086 if (schedlock_enabled) 02087 return 0; 02088 02089 /* Don't switch over if we're about to resume some other process 02090 other than WAIT_PTID's, and schedule-multiple is off. */ 02091 if (!sched_multi 02092 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid)) 02093 return 0; 02094 02095 /* Switched over from WAIT_PID. */ 02096 if (!ptid_equal (wait_ptid, minus_one_ptid) 02097 && !ptid_equal (inferior_ptid, wait_ptid)) 02098 { 02099 struct regcache *regcache = get_thread_regcache (wait_ptid); 02100 02101 if (breakpoint_here_p (get_regcache_aspace (regcache), 02102 regcache_read_pc (regcache))) 02103 { 02104 /* If stepping, remember current thread to switch back to. */ 02105 if (step) 02106 deferred_step_ptid = inferior_ptid; 02107 02108 /* Switch back to WAIT_PID thread. */ 02109 switch_to_thread (wait_ptid); 02110 02111 if (debug_infrun) 02112 fprintf_unfiltered (gdb_stdlog, 02113 "infrun: prepare_to_proceed (step=%d), " 02114 "switched to [%s]\n", 02115 step, target_pid_to_str (inferior_ptid)); 02116 02117 /* We return 1 to indicate that there is a breakpoint here, 02118 so we need to step over it before continuing to avoid 02119 hitting it straight away. */ 02120 return 1; 02121 } 02122 } 02123 02124 return 0; 02125 } 02126 02127 /* Basic routine for continuing the program in various fashions. 02128 02129 ADDR is the address to resume at, or -1 for resume where stopped. 02130 SIGGNAL is the signal to give it, or 0 for none, 02131 or -1 for act according to how it stopped. 02132 STEP is nonzero if should trap after one instruction. 02133 -1 means return after that and print nothing. 02134 You should probably set various step_... variables 02135 before calling here, if you are stepping. 02136 02137 You should call clear_proceed_status before calling proceed. */ 02138 02139 void 02140 proceed (CORE_ADDR addr, enum gdb_signal siggnal, int step) 02141 { 02142 struct regcache *regcache; 02143 struct gdbarch *gdbarch; 02144 struct thread_info *tp; 02145 CORE_ADDR pc; 02146 struct address_space *aspace; 02147 /* GDB may force the inferior to step due to various reasons. */ 02148 int force_step = 0; 02149 02150 /* If we're stopped at a fork/vfork, follow the branch set by the 02151 "set follow-fork-mode" command; otherwise, we'll just proceed 02152 resuming the current thread. */ 02153 if (!follow_fork ()) 02154 { 02155 /* The target for some reason decided not to resume. */ 02156 normal_stop (); 02157 if (target_can_async_p ()) 02158 inferior_event_handler (INF_EXEC_COMPLETE, NULL); 02159 return; 02160 } 02161 02162 /* We'll update this if & when we switch to a new thread. */ 02163 previous_inferior_ptid = inferior_ptid; 02164 02165 regcache = get_current_regcache (); 02166 gdbarch = get_regcache_arch (regcache); 02167 aspace = get_regcache_aspace (regcache); 02168 pc = regcache_read_pc (regcache); 02169 02170 if (step > 0) 02171 step_start_function = find_pc_function (pc); 02172 if (step < 0) 02173 stop_after_trap = 1; 02174 02175 if (addr == (CORE_ADDR) -1) 02176 { 02177 if (pc == stop_pc && breakpoint_here_p (aspace, pc) 02178 && execution_direction != EXEC_REVERSE) 02179 /* There is a breakpoint at the address we will resume at, 02180 step one instruction before inserting breakpoints so that 02181 we do not stop right away (and report a second hit at this 02182 breakpoint). 02183 02184 Note, we don't do this in reverse, because we won't 02185 actually be executing the breakpoint insn anyway. 02186 We'll be (un-)executing the previous instruction. */ 02187 02188 force_step = 1; 02189 else if (gdbarch_single_step_through_delay_p (gdbarch) 02190 && gdbarch_single_step_through_delay (gdbarch, 02191 get_current_frame ())) 02192 /* We stepped onto an instruction that needs to be stepped 02193 again before re-inserting the breakpoint, do so. */ 02194 force_step = 1; 02195 } 02196 else 02197 { 02198 regcache_write_pc (regcache, addr); 02199 } 02200 02201 if (debug_infrun) 02202 fprintf_unfiltered (gdb_stdlog, 02203 "infrun: proceed (addr=%s, signal=%d, step=%d)\n", 02204 paddress (gdbarch, addr), siggnal, step); 02205 02206 if (non_stop) 02207 /* In non-stop, each thread is handled individually. The context 02208 must already be set to the right thread here. */ 02209 ; 02210 else 02211 { 02212 /* In a multi-threaded task we may select another thread and 02213 then continue or step. 02214 02215 But if the old thread was stopped at a breakpoint, it will 02216 immediately cause another breakpoint stop without any 02217 execution (i.e. it will report a breakpoint hit incorrectly). 02218 So we must step over it first. 02219 02220 prepare_to_proceed checks the current thread against the 02221 thread that reported the most recent event. If a step-over 02222 is required it returns TRUE and sets the current thread to 02223 the old thread. */ 02224 if (prepare_to_proceed (step)) 02225 force_step = 1; 02226 } 02227 02228 /* prepare_to_proceed may change the current thread. */ 02229 tp = inferior_thread (); 02230 02231 if (force_step) 02232 { 02233 tp->control.trap_expected = 1; 02234 /* If displaced stepping is enabled, we can step over the 02235 breakpoint without hitting it, so leave all breakpoints 02236 inserted. Otherwise we need to disable all breakpoints, step 02237 one instruction, and then re-add them when that step is 02238 finished. */ 02239 if (!use_displaced_stepping (gdbarch)) 02240 remove_breakpoints (); 02241 } 02242 02243 /* We can insert breakpoints if we're not trying to step over one, 02244 or if we are stepping over one but we're using displaced stepping 02245 to do so. */ 02246 if (! tp->control.trap_expected || use_displaced_stepping (gdbarch)) 02247 insert_breakpoints (); 02248 02249 if (!non_stop) 02250 { 02251 /* Pass the last stop signal to the thread we're resuming, 02252 irrespective of whether the current thread is the thread that 02253 got the last event or not. This was historically GDB's 02254 behaviour before keeping a stop_signal per thread. */ 02255 02256 struct thread_info *last_thread; 02257 ptid_t last_ptid; 02258 struct target_waitstatus last_status; 02259 02260 get_last_target_status (&last_ptid, &last_status); 02261 if (!ptid_equal (inferior_ptid, last_ptid) 02262 && !ptid_equal (last_ptid, null_ptid) 02263 && !ptid_equal (last_ptid, minus_one_ptid)) 02264 { 02265 last_thread = find_thread_ptid (last_ptid); 02266 if (last_thread) 02267 { 02268 tp->suspend.stop_signal = last_thread->suspend.stop_signal; 02269 last_thread->suspend.stop_signal = GDB_SIGNAL_0; 02270 } 02271 } 02272 } 02273 02274 if (siggnal != GDB_SIGNAL_DEFAULT) 02275 tp->suspend.stop_signal = siggnal; 02276 /* If this signal should not be seen by program, 02277 give it zero. Used for debugging signals. */ 02278 else if (!signal_program[tp->suspend.stop_signal]) 02279 tp->suspend.stop_signal = GDB_SIGNAL_0; 02280 02281 annotate_starting (); 02282 02283 /* Make sure that output from GDB appears before output from the 02284 inferior. */ 02285 gdb_flush (gdb_stdout); 02286 02287 /* Refresh prev_pc value just prior to resuming. This used to be 02288 done in stop_stepping, however, setting prev_pc there did not handle 02289 scenarios such as inferior function calls or returning from 02290 a function via the return command. In those cases, the prev_pc 02291 value was not set properly for subsequent commands. The prev_pc value 02292 is used to initialize the starting line number in the ecs. With an 02293 invalid value, the gdb next command ends up stopping at the position 02294 represented by the next line table entry past our start position. 02295 On platforms that generate one line table entry per line, this 02296 is not a problem. However, on the ia64, the compiler generates 02297 extraneous line table entries that do not increase the line number. 02298 When we issue the gdb next command on the ia64 after an inferior call 02299 or a return command, we often end up a few instructions forward, still 02300 within the original line we started. 02301 02302 An attempt was made to refresh the prev_pc at the same time the 02303 execution_control_state is initialized (for instance, just before 02304 waiting for an inferior event). But this approach did not work 02305 because of platforms that use ptrace, where the pc register cannot 02306 be read unless the inferior is stopped. At that point, we are not 02307 guaranteed the inferior is stopped and so the regcache_read_pc() call 02308 can fail. Setting the prev_pc value here ensures the value is updated 02309 correctly when the inferior is stopped. */ 02310 tp->prev_pc = regcache_read_pc (get_current_regcache ()); 02311 02312 /* Fill in with reasonable starting values. */ 02313 init_thread_stepping_state (tp); 02314 02315 /* Reset to normal state. */ 02316 init_infwait_state (); 02317 02318 /* Resume inferior. */ 02319 resume (force_step || step || bpstat_should_step (), 02320 tp->suspend.stop_signal); 02321 02322 /* Wait for it to stop (if not standalone) 02323 and in any case decode why it stopped, and act accordingly. */ 02324 /* Do this only if we are not using the event loop, or if the target 02325 does not support asynchronous execution. */ 02326 if (!target_can_async_p ()) 02327 { 02328 wait_for_inferior (); 02329 normal_stop (); 02330 } 02331 } 02332 02333 02334 /* Start remote-debugging of a machine over a serial link. */ 02335 02336 void 02337 start_remote (int from_tty) 02338 { 02339 struct inferior *inferior; 02340 02341 inferior = current_inferior (); 02342 inferior->control.stop_soon = STOP_QUIETLY_REMOTE; 02343 02344 /* Always go on waiting for the target, regardless of the mode. */ 02345 /* FIXME: cagney/1999-09-23: At present it isn't possible to 02346 indicate to wait_for_inferior that a target should timeout if 02347 nothing is returned (instead of just blocking). Because of this, 02348 targets expecting an immediate response need to, internally, set 02349 things up so that the target_wait() is forced to eventually 02350 timeout. */ 02351 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to 02352 differentiate to its caller what the state of the target is after 02353 the initial open has been performed. Here we're assuming that 02354 the target has stopped. It should be possible to eventually have 02355 target_open() return to the caller an indication that the target 02356 is currently running and GDB state should be set to the same as 02357 for an async run. */ 02358 wait_for_inferior (); 02359 02360 /* Now that the inferior has stopped, do any bookkeeping like 02361 loading shared libraries. We want to do this before normal_stop, 02362 so that the displayed frame is up to date. */ 02363 post_create_inferior (¤t_target, from_tty); 02364 02365 normal_stop (); 02366 } 02367 02368 /* Initialize static vars when a new inferior begins. */ 02369 02370 void 02371 init_wait_for_inferior (void) 02372 { 02373 /* These are meaningless until the first time through wait_for_inferior. */ 02374 02375 breakpoint_init_inferior (inf_starting); 02376 02377 clear_proceed_status (); 02378 02379 stepping_past_singlestep_breakpoint = 0; 02380 deferred_step_ptid = null_ptid; 02381 02382 target_last_wait_ptid = minus_one_ptid; 02383 02384 previous_inferior_ptid = inferior_ptid; 02385 init_infwait_state (); 02386 02387 /* Discard any skipped inlined frames. */ 02388 clear_inline_frame_state (minus_one_ptid); 02389 } 02390 02391 02392 /* This enum encodes possible reasons for doing a target_wait, so that 02393 wfi can call target_wait in one place. (Ultimately the call will be 02394 moved out of the infinite loop entirely.) */ 02395 02396 enum infwait_states 02397 { 02398 infwait_normal_state, 02399 infwait_thread_hop_state, 02400 infwait_step_watch_state, 02401 infwait_nonstep_watch_state 02402 }; 02403 02404 /* The PTID we'll do a target_wait on.*/ 02405 ptid_t waiton_ptid; 02406 02407 /* Current inferior wait state. */ 02408 static enum infwait_states infwait_state; 02409 02410 /* Data to be passed around while handling an event. This data is 02411 discarded between events. */ 02412 struct execution_control_state 02413 { 02414 ptid_t ptid; 02415 /* The thread that got the event, if this was a thread event; NULL 02416 otherwise. */ 02417 struct thread_info *event_thread; 02418 02419 struct target_waitstatus ws; 02420 int random_signal; 02421 int stop_func_filled_in; 02422 CORE_ADDR stop_func_start; 02423 CORE_ADDR stop_func_end; 02424 const char *stop_func_name; 02425 int wait_some_more; 02426 }; 02427 02428 static void handle_inferior_event (struct execution_control_state *ecs); 02429 02430 static void handle_step_into_function (struct gdbarch *gdbarch, 02431 struct execution_control_state *ecs); 02432 static void handle_step_into_function_backward (struct gdbarch *gdbarch, 02433 struct execution_control_state *ecs); 02434 static void check_exception_resume (struct execution_control_state *, 02435 struct frame_info *); 02436 02437 static void stop_stepping (struct execution_control_state *ecs); 02438 static void prepare_to_wait (struct execution_control_state *ecs); 02439 static void keep_going (struct execution_control_state *ecs); 02440 02441 /* Callback for iterate over threads. If the thread is stopped, but 02442 the user/frontend doesn't know about that yet, go through 02443 normal_stop, as if the thread had just stopped now. ARG points at 02444 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If 02445 ptid_is_pid(PTID) is true, applies to all threads of the process 02446 pointed at by PTID. Otherwise, apply only to the thread pointed by 02447 PTID. */ 02448 02449 static int 02450 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg) 02451 { 02452 ptid_t ptid = * (ptid_t *) arg; 02453 02454 if ((ptid_equal (info->ptid, ptid) 02455 || ptid_equal (minus_one_ptid, ptid) 02456 || (ptid_is_pid (ptid) 02457 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid))) 02458 && is_running (info->ptid) 02459 && !is_executing (info->ptid)) 02460 { 02461 struct cleanup *old_chain; 02462 struct execution_control_state ecss; 02463 struct execution_control_state *ecs = &ecss; 02464 02465 memset (ecs, 0, sizeof (*ecs)); 02466 02467 old_chain = make_cleanup_restore_current_thread (); 02468 02469 /* Go through handle_inferior_event/normal_stop, so we always 02470 have consistent output as if the stop event had been 02471 reported. */ 02472 ecs->ptid = info->ptid; 02473 ecs->event_thread = find_thread_ptid (info->ptid); 02474 ecs->ws.kind = TARGET_WAITKIND_STOPPED; 02475 ecs->ws.value.sig = GDB_SIGNAL_0; 02476 02477 handle_inferior_event (ecs); 02478 02479 if (!ecs->wait_some_more) 02480 { 02481 struct thread_info *tp; 02482 02483 normal_stop (); 02484 02485 /* Finish off the continuations. */ 02486 tp = inferior_thread (); 02487 do_all_intermediate_continuations_thread (tp, 1); 02488 do_all_continuations_thread (tp, 1); 02489 } 02490 02491 do_cleanups (old_chain); 02492 } 02493 02494 return 0; 02495 } 02496 02497 /* This function is attached as a "thread_stop_requested" observer. 02498 Cleanup local state that assumed the PTID was to be resumed, and 02499 report the stop to the frontend. */ 02500 02501 static void 02502 infrun_thread_stop_requested (ptid_t ptid) 02503 { 02504 struct displaced_step_inferior_state *displaced; 02505 02506 /* PTID was requested to stop. Remove it from the displaced 02507 stepping queue, so we don't try to resume it automatically. */ 02508 02509 for (displaced = displaced_step_inferior_states; 02510 displaced; 02511 displaced = displaced->next) 02512 { 02513 struct displaced_step_request *it, **prev_next_p; 02514 02515 it = displaced->step_request_queue; 02516 prev_next_p = &displaced->step_request_queue; 02517 while (it) 02518 { 02519 if (ptid_match (it->ptid, ptid)) 02520 { 02521 *prev_next_p = it->next; 02522 it->next = NULL; 02523 xfree (it); 02524 } 02525 else 02526 { 02527 prev_next_p = &it->next; 02528 } 02529 02530 it = *prev_next_p; 02531 } 02532 } 02533 02534 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid); 02535 } 02536 02537 static void 02538 infrun_thread_thread_exit (struct thread_info *tp, int silent) 02539 { 02540 if (ptid_equal (target_last_wait_ptid, tp->ptid)) 02541 nullify_last_target_wait_ptid (); 02542 } 02543 02544 /* Callback for iterate_over_threads. */ 02545 02546 static int 02547 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data) 02548 { 02549 if (is_exited (info->ptid)) 02550 return 0; 02551 02552 delete_step_resume_breakpoint (info); 02553 delete_exception_resume_breakpoint (info); 02554 return 0; 02555 } 02556 02557 /* In all-stop, delete the step resume breakpoint of any thread that 02558 had one. In non-stop, delete the step resume breakpoint of the 02559 thread that just stopped. */ 02560 02561 static void 02562 delete_step_thread_step_resume_breakpoint (void) 02563 { 02564 if (!target_has_execution 02565 || ptid_equal (inferior_ptid, null_ptid)) 02566 /* If the inferior has exited, we have already deleted the step 02567 resume breakpoints out of GDB's lists. */ 02568 return; 02569 02570 if (non_stop) 02571 { 02572 /* If in non-stop mode, only delete the step-resume or 02573 longjmp-resume breakpoint of the thread that just stopped 02574 stepping. */ 02575 struct thread_info *tp = inferior_thread (); 02576 02577 delete_step_resume_breakpoint (tp); 02578 delete_exception_resume_breakpoint (tp); 02579 } 02580 else 02581 /* In all-stop mode, delete all step-resume and longjmp-resume 02582 breakpoints of any thread that had them. */ 02583 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL); 02584 } 02585 02586 /* A cleanup wrapper. */ 02587 02588 static void 02589 delete_step_thread_step_resume_breakpoint_cleanup (void *arg) 02590 { 02591 delete_step_thread_step_resume_breakpoint (); 02592 } 02593 02594 /* Pretty print the results of target_wait, for debugging purposes. */ 02595 02596 static void 02597 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, 02598 const struct target_waitstatus *ws) 02599 { 02600 char *status_string = target_waitstatus_to_string (ws); 02601 struct ui_file *tmp_stream = mem_fileopen (); 02602 char *text; 02603 02604 /* The text is split over several lines because it was getting too long. 02605 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still 02606 output as a unit; we want only one timestamp printed if debug_timestamp 02607 is set. */ 02608 02609 fprintf_unfiltered (tmp_stream, 02610 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid)); 02611 if (ptid_get_pid (waiton_ptid) != -1) 02612 fprintf_unfiltered (tmp_stream, 02613 " [%s]", target_pid_to_str (waiton_ptid)); 02614 fprintf_unfiltered (tmp_stream, ", status) =\n"); 02615 fprintf_unfiltered (tmp_stream, 02616 "infrun: %d [%s],\n", 02617 ptid_get_pid (result_ptid), 02618 target_pid_to_str (result_ptid)); 02619 fprintf_unfiltered (tmp_stream, 02620 "infrun: %s\n", 02621 status_string); 02622 02623 text = ui_file_xstrdup (tmp_stream, NULL); 02624 02625 /* This uses %s in part to handle %'s in the text, but also to avoid 02626 a gcc error: the format attribute requires a string literal. */ 02627 fprintf_unfiltered (gdb_stdlog, "%s", text); 02628 02629 xfree (status_string); 02630 xfree (text); 02631 ui_file_delete (tmp_stream); 02632 } 02633 02634 /* Prepare and stabilize the inferior for detaching it. E.g., 02635 detaching while a thread is displaced stepping is a recipe for 02636 crashing it, as nothing would readjust the PC out of the scratch 02637 pad. */ 02638 02639 void 02640 prepare_for_detach (void) 02641 { 02642 struct inferior *inf = current_inferior (); 02643 ptid_t pid_ptid = pid_to_ptid (inf->pid); 02644 struct cleanup *old_chain_1; 02645 struct displaced_step_inferior_state *displaced; 02646 02647 displaced = get_displaced_stepping_state (inf->pid); 02648 02649 /* Is any thread of this process displaced stepping? If not, 02650 there's nothing else to do. */ 02651 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid)) 02652 return; 02653 02654 if (debug_infrun) 02655 fprintf_unfiltered (gdb_stdlog, 02656 "displaced-stepping in-process while detaching"); 02657 02658 old_chain_1 = make_cleanup_restore_integer (&inf->detaching); 02659 inf->detaching = 1; 02660 02661 while (!ptid_equal (displaced->step_ptid, null_ptid)) 02662 { 02663 struct cleanup *old_chain_2; 02664 struct execution_control_state ecss; 02665 struct execution_control_state *ecs; 02666 02667 ecs = &ecss; 02668 memset (ecs, 0, sizeof (*ecs)); 02669 02670 overlay_cache_invalid = 1; 02671 02672 if (deprecated_target_wait_hook) 02673 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0); 02674 else 02675 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0); 02676 02677 if (debug_infrun) 02678 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws); 02679 02680 /* If an error happens while handling the event, propagate GDB's 02681 knowledge of the executing state to the frontend/user running 02682 state. */ 02683 old_chain_2 = make_cleanup (finish_thread_state_cleanup, 02684 &minus_one_ptid); 02685 02686 /* Now figure out what to do with the result of the result. */ 02687 handle_inferior_event (ecs); 02688 02689 /* No error, don't finish the state yet. */ 02690 discard_cleanups (old_chain_2); 02691 02692 /* Breakpoints and watchpoints are not installed on the target 02693 at this point, and signals are passed directly to the 02694 inferior, so this must mean the process is gone. */ 02695 if (!ecs->wait_some_more) 02696 { 02697 discard_cleanups (old_chain_1); 02698 error (_("Program exited while detaching")); 02699 } 02700 } 02701 02702 discard_cleanups (old_chain_1); 02703 } 02704 02705 /* Wait for control to return from inferior to debugger. 02706 02707 If inferior gets a signal, we may decide to start it up again 02708 instead of returning. That is why there is a loop in this function. 02709 When this function actually returns it means the inferior 02710 should be left stopped and GDB should read more commands. */ 02711 02712 void 02713 wait_for_inferior (void) 02714 { 02715 struct cleanup *old_cleanups; 02716 02717 if (debug_infrun) 02718 fprintf_unfiltered 02719 (gdb_stdlog, "infrun: wait_for_inferior ()\n"); 02720 02721 old_cleanups = 02722 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL); 02723 02724 while (1) 02725 { 02726 struct execution_control_state ecss; 02727 struct execution_control_state *ecs = &ecss; 02728 struct cleanup *old_chain; 02729 02730 memset (ecs, 0, sizeof (*ecs)); 02731 02732 overlay_cache_invalid = 1; 02733 02734 if (deprecated_target_wait_hook) 02735 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0); 02736 else 02737 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0); 02738 02739 if (debug_infrun) 02740 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); 02741 02742 /* If an error happens while handling the event, propagate GDB's 02743 knowledge of the executing state to the frontend/user running 02744 state. */ 02745 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); 02746 02747 /* Now figure out what to do with the result of the result. */ 02748 handle_inferior_event (ecs); 02749 02750 /* No error, don't finish the state yet. */ 02751 discard_cleanups (old_chain); 02752 02753 if (!ecs->wait_some_more) 02754 break; 02755 } 02756 02757 do_cleanups (old_cleanups); 02758 } 02759 02760 /* Asynchronous version of wait_for_inferior. It is called by the 02761 event loop whenever a change of state is detected on the file 02762 descriptor corresponding to the target. It can be called more than 02763 once to complete a single execution command. In such cases we need 02764 to keep the state in a global variable ECSS. If it is the last time 02765 that this function is called for a single execution command, then 02766 report to the user that the inferior has stopped, and do the 02767 necessary cleanups. */ 02768 02769 void 02770 fetch_inferior_event (void *client_data) 02771 { 02772 struct execution_control_state ecss; 02773 struct execution_control_state *ecs = &ecss; 02774 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); 02775 struct cleanup *ts_old_chain; 02776 int was_sync = sync_execution; 02777 int cmd_done = 0; 02778 02779 memset (ecs, 0, sizeof (*ecs)); 02780 02781 /* We're handling a live event, so make sure we're doing live 02782 debugging. If we're looking at traceframes while the target is 02783 running, we're going to need to get back to that mode after 02784 handling the event. */ 02785 if (non_stop) 02786 { 02787 make_cleanup_restore_current_traceframe (); 02788 set_current_traceframe (-1); 02789 } 02790 02791 if (non_stop) 02792 /* In non-stop mode, the user/frontend should not notice a thread 02793 switch due to internal events. Make sure we reverse to the 02794 user selected thread and frame after handling the event and 02795 running any breakpoint commands. */ 02796 make_cleanup_restore_current_thread (); 02797 02798 overlay_cache_invalid = 1; 02799 02800 make_cleanup_restore_integer (&execution_direction); 02801 execution_direction = target_execution_direction (); 02802 02803 if (deprecated_target_wait_hook) 02804 ecs->ptid = 02805 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG); 02806 else 02807 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG); 02808 02809 if (debug_infrun) 02810 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); 02811 02812 /* If an error happens while handling the event, propagate GDB's 02813 knowledge of the executing state to the frontend/user running 02814 state. */ 02815 if (!non_stop) 02816 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); 02817 else 02818 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid); 02819 02820 /* Get executed before make_cleanup_restore_current_thread above to apply 02821 still for the thread which has thrown the exception. */ 02822 make_bpstat_clear_actions_cleanup (); 02823 02824 /* Now figure out what to do with the result of the result. */ 02825 handle_inferior_event (ecs); 02826 02827 if (!ecs->wait_some_more) 02828 { 02829 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); 02830 02831 delete_step_thread_step_resume_breakpoint (); 02832 02833 /* We may not find an inferior if this was a process exit. */ 02834 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY) 02835 normal_stop (); 02836 02837 if (target_has_execution 02838 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED 02839 && ecs->ws.kind != TARGET_WAITKIND_EXITED 02840 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED 02841 && ecs->event_thread->step_multi 02842 && ecs->event_thread->control.stop_step) 02843 inferior_event_handler (INF_EXEC_CONTINUE, NULL); 02844 else 02845 { 02846 inferior_event_handler (INF_EXEC_COMPLETE, NULL); 02847 cmd_done = 1; 02848 } 02849 } 02850 02851 /* No error, don't finish the thread states yet. */ 02852 discard_cleanups (ts_old_chain); 02853 02854 /* Revert thread and frame. */ 02855 do_cleanups (old_chain); 02856 02857 /* If the inferior was in sync execution mode, and now isn't, 02858 restore the prompt (a synchronous execution command has finished, 02859 and we're ready for input). */ 02860 if (interpreter_async && was_sync && !sync_execution) 02861 display_gdb_prompt (0); 02862 02863 if (cmd_done 02864 && !was_sync 02865 && exec_done_display_p 02866 && (ptid_equal (inferior_ptid, null_ptid) 02867 || !is_running (inferior_ptid))) 02868 printf_unfiltered (_("completed.\n")); 02869 } 02870 02871 /* Record the frame and location we're currently stepping through. */ 02872 void 02873 set_step_info (struct frame_info *frame, struct symtab_and_line sal) 02874 { 02875 struct thread_info *tp = inferior_thread (); 02876 02877 tp->control.step_frame_id = get_frame_id (frame); 02878 tp->control.step_stack_frame_id = get_stack_frame_id (frame); 02879 02880 tp->current_symtab = sal.symtab; 02881 tp->current_line = sal.line; 02882 } 02883 02884 /* Clear context switchable stepping state. */ 02885 02886 void 02887 init_thread_stepping_state (struct thread_info *tss) 02888 { 02889 tss->stepping_over_breakpoint = 0; 02890 tss->step_after_step_resume_breakpoint = 0; 02891 } 02892 02893 /* Return the cached copy of the last pid/waitstatus returned by 02894 target_wait()/deprecated_target_wait_hook(). The data is actually 02895 cached by handle_inferior_event(), which gets called immediately 02896 after target_wait()/deprecated_target_wait_hook(). */ 02897 02898 void 02899 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) 02900 { 02901 *ptidp = target_last_wait_ptid; 02902 *status = target_last_waitstatus; 02903 } 02904 02905 void 02906 nullify_last_target_wait_ptid (void) 02907 { 02908 target_last_wait_ptid = minus_one_ptid; 02909 } 02910 02911 /* Switch thread contexts. */ 02912 02913 static void 02914 context_switch (ptid_t ptid) 02915 { 02916 if (debug_infrun && !ptid_equal (ptid, inferior_ptid)) 02917 { 02918 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", 02919 target_pid_to_str (inferior_ptid)); 02920 fprintf_unfiltered (gdb_stdlog, "to %s\n", 02921 target_pid_to_str (ptid)); 02922 } 02923 02924 switch_to_thread (ptid); 02925 } 02926 02927 static void 02928 adjust_pc_after_break (struct execution_control_state *ecs) 02929 { 02930 struct regcache *regcache; 02931 struct gdbarch *gdbarch; 02932 struct address_space *aspace; 02933 CORE_ADDR breakpoint_pc; 02934 02935 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If 02936 we aren't, just return. 02937 02938 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not 02939 affected by gdbarch_decr_pc_after_break. Other waitkinds which are 02940 implemented by software breakpoints should be handled through the normal 02941 breakpoint layer. 02942 02943 NOTE drow/2004-01-31: On some targets, breakpoints may generate 02944 different signals (SIGILL or SIGEMT for instance), but it is less 02945 clear where the PC is pointing afterwards. It may not match 02946 gdbarch_decr_pc_after_break. I don't know any specific target that 02947 generates these signals at breakpoints (the code has been in GDB since at 02948 least 1992) so I can not guess how to handle them here. 02949 02950 In earlier versions of GDB, a target with 02951 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a 02952 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any 02953 target with both of these set in GDB history, and it seems unlikely to be 02954 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ 02955 02956 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) 02957 return; 02958 02959 if (ecs->ws.value.sig != GDB_SIGNAL_TRAP) 02960 return; 02961 02962 /* In reverse execution, when a breakpoint is hit, the instruction 02963 under it has already been de-executed. The reported PC always 02964 points at the breakpoint address, so adjusting it further would 02965 be wrong. E.g., consider this case on a decr_pc_after_break == 1 02966 architecture: 02967 02968 B1 0x08000000 : INSN1 02969 B2 0x08000001 : INSN2 02970 0x08000002 : INSN3 02971 PC -> 0x08000003 : INSN4 02972 02973 Say you're stopped at 0x08000003 as above. Reverse continuing 02974 from that point should hit B2 as below. Reading the PC when the 02975 SIGTRAP is reported should read 0x08000001 and INSN2 should have 02976 been de-executed already. 02977 02978 B1 0x08000000 : INSN1 02979 B2 PC -> 0x08000001 : INSN2 02980 0x08000002 : INSN3 02981 0x08000003 : INSN4 02982 02983 We can't apply the same logic as for forward execution, because 02984 we would wrongly adjust the PC to 0x08000000, since there's a 02985 breakpoint at PC - 1. We'd then report a hit on B1, although 02986 INSN1 hadn't been de-executed yet. Doing nothing is the correct 02987 behaviour. */ 02988 if (execution_direction == EXEC_REVERSE) 02989 return; 02990 02991 /* If this target does not decrement the PC after breakpoints, then 02992 we have nothing to do. */ 02993 regcache = get_thread_regcache (ecs->ptid); 02994 gdbarch = get_regcache_arch (regcache); 02995 if (gdbarch_decr_pc_after_break (gdbarch) == 0) 02996 return; 02997 02998 aspace = get_regcache_aspace (regcache); 02999 03000 /* Find the location where (if we've hit a breakpoint) the 03001 breakpoint would be. */ 03002 breakpoint_pc = regcache_read_pc (regcache) 03003 - gdbarch_decr_pc_after_break (gdbarch); 03004 03005 /* Check whether there actually is a software breakpoint inserted at 03006 that location. 03007 03008 If in non-stop mode, a race condition is possible where we've 03009 removed a breakpoint, but stop events for that breakpoint were 03010 already queued and arrive later. To suppress those spurious 03011 SIGTRAPs, we keep a list of such breakpoint locations for a bit, 03012 and retire them after a number of stop events are reported. */ 03013 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc) 03014 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc))) 03015 { 03016 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL); 03017 03018 if (RECORD_IS_USED) 03019 record_full_gdb_operation_disable_set (); 03020 03021 /* When using hardware single-step, a SIGTRAP is reported for both 03022 a completed single-step and a software breakpoint. Need to 03023 differentiate between the two, as the latter needs adjusting 03024 but the former does not. 03025 03026 The SIGTRAP can be due to a completed hardware single-step only if 03027 - we didn't insert software single-step breakpoints 03028 - the thread to be examined is still the current thread 03029 - this thread is currently being stepped 03030 03031 If any of these events did not occur, we must have stopped due 03032 to hitting a software breakpoint, and have to back up to the 03033 breakpoint address. 03034 03035 As a special case, we could have hardware single-stepped a 03036 software breakpoint. In this case (prev_pc == breakpoint_pc), 03037 we also need to back up to the breakpoint address. */ 03038 03039 if (singlestep_breakpoints_inserted_p 03040 || !ptid_equal (ecs->ptid, inferior_ptid) 03041 || !currently_stepping (ecs->event_thread) 03042 || ecs->event_thread->prev_pc == breakpoint_pc) 03043 regcache_write_pc (regcache, breakpoint_pc); 03044 03045 do_cleanups (old_cleanups); 03046 } 03047 } 03048 03049 static void 03050 init_infwait_state (void) 03051 { 03052 waiton_ptid = pid_to_ptid (-1); 03053 infwait_state = infwait_normal_state; 03054 } 03055 03056 static int 03057 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id) 03058 { 03059 for (frame = get_prev_frame (frame); 03060 frame != NULL; 03061 frame = get_prev_frame (frame)) 03062 { 03063 if (frame_id_eq (get_frame_id (frame), step_frame_id)) 03064 return 1; 03065 if (get_frame_type (frame) != INLINE_FRAME) 03066 break; 03067 } 03068 03069 return 0; 03070 } 03071 03072 /* Auxiliary function that handles syscall entry/return events. 03073 It returns 1 if the inferior should keep going (and GDB 03074 should ignore the event), or 0 if the event deserves to be 03075 processed. */ 03076 03077 static int 03078 handle_syscall_event (struct execution_control_state *ecs) 03079 { 03080 struct regcache *regcache; 03081 int syscall_number; 03082 03083 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03084 context_switch (ecs->ptid); 03085 03086 regcache = get_thread_regcache (ecs->ptid); 03087 syscall_number = ecs->ws.value.syscall_number; 03088 stop_pc = regcache_read_pc (regcache); 03089 03090 if (catch_syscall_enabled () > 0 03091 && catching_syscall_number (syscall_number) > 0) 03092 { 03093 enum bpstat_signal_value sval; 03094 03095 if (debug_infrun) 03096 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n", 03097 syscall_number); 03098 03099 ecs->event_thread->control.stop_bpstat 03100 = bpstat_stop_status (get_regcache_aspace (regcache), 03101 stop_pc, ecs->ptid, &ecs->ws); 03102 03103 sval = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, 03104 GDB_SIGNAL_TRAP); 03105 ecs->random_signal = sval == BPSTAT_SIGNAL_NO; 03106 03107 if (!ecs->random_signal) 03108 { 03109 /* Catchpoint hit. */ 03110 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP; 03111 return 0; 03112 } 03113 } 03114 03115 /* If no catchpoint triggered for this, then keep going. */ 03116 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 03117 keep_going (ecs); 03118 return 1; 03119 } 03120 03121 /* Clear the supplied execution_control_state's stop_func_* fields. */ 03122 03123 static void 03124 clear_stop_func (struct execution_control_state *ecs) 03125 { 03126 ecs->stop_func_filled_in = 0; 03127 ecs->stop_func_start = 0; 03128 ecs->stop_func_end = 0; 03129 ecs->stop_func_name = NULL; 03130 } 03131 03132 /* Lazily fill in the execution_control_state's stop_func_* fields. */ 03133 03134 static void 03135 fill_in_stop_func (struct gdbarch *gdbarch, 03136 struct execution_control_state *ecs) 03137 { 03138 if (!ecs->stop_func_filled_in) 03139 { 03140 /* Don't care about return value; stop_func_start and stop_func_name 03141 will both be 0 if it doesn't work. */ 03142 find_pc_partial_function (stop_pc, &ecs->stop_func_name, 03143 &ecs->stop_func_start, &ecs->stop_func_end); 03144 ecs->stop_func_start 03145 += gdbarch_deprecated_function_start_offset (gdbarch); 03146 03147 ecs->stop_func_filled_in = 1; 03148 } 03149 } 03150 03151 /* Given an execution control state that has been freshly filled in 03152 by an event from the inferior, figure out what it means and take 03153 appropriate action. */ 03154 03155 static void 03156 handle_inferior_event (struct execution_control_state *ecs) 03157 { 03158 struct frame_info *frame; 03159 struct gdbarch *gdbarch; 03160 int stopped_by_watchpoint; 03161 int stepped_after_stopped_by_watchpoint = 0; 03162 struct symtab_and_line stop_pc_sal; 03163 enum stop_kind stop_soon; 03164 03165 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE) 03166 { 03167 /* We had an event in the inferior, but we are not interested in 03168 handling it at this level. The lower layers have already 03169 done what needs to be done, if anything. 03170 03171 One of the possible circumstances for this is when the 03172 inferior produces output for the console. The inferior has 03173 not stopped, and we are ignoring the event. Another possible 03174 circumstance is any event which the lower level knows will be 03175 reported multiple times without an intervening resume. */ 03176 if (debug_infrun) 03177 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); 03178 prepare_to_wait (ecs); 03179 return; 03180 } 03181 03182 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED 03183 && target_can_async_p () && !sync_execution) 03184 { 03185 /* There were no unwaited-for children left in the target, but, 03186 we're not synchronously waiting for events either. Just 03187 ignore. Otherwise, if we were running a synchronous 03188 execution command, we need to cancel it and give the user 03189 back the terminal. */ 03190 if (debug_infrun) 03191 fprintf_unfiltered (gdb_stdlog, 03192 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n"); 03193 prepare_to_wait (ecs); 03194 return; 03195 } 03196 03197 if (ecs->ws.kind != TARGET_WAITKIND_EXITED 03198 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED 03199 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED) 03200 { 03201 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); 03202 03203 gdb_assert (inf); 03204 stop_soon = inf->control.stop_soon; 03205 } 03206 else 03207 stop_soon = NO_STOP_QUIETLY; 03208 03209 /* Cache the last pid/waitstatus. */ 03210 target_last_wait_ptid = ecs->ptid; 03211 target_last_waitstatus = ecs->ws; 03212 03213 /* Always clear state belonging to the previous time we stopped. */ 03214 stop_stack_dummy = STOP_NONE; 03215 03216 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED) 03217 { 03218 /* No unwaited-for children left. IOW, all resumed children 03219 have exited. */ 03220 if (debug_infrun) 03221 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n"); 03222 03223 stop_print_frame = 0; 03224 stop_stepping (ecs); 03225 return; 03226 } 03227 03228 if (ecs->ws.kind != TARGET_WAITKIND_EXITED 03229 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) 03230 { 03231 ecs->event_thread = find_thread_ptid (ecs->ptid); 03232 /* If it's a new thread, add it to the thread database. */ 03233 if (ecs->event_thread == NULL) 03234 ecs->event_thread = add_thread (ecs->ptid); 03235 03236 /* Disable range stepping. If the next step request could use a 03237 range, this will be end up re-enabled then. */ 03238 ecs->event_thread->control.may_range_step = 0; 03239 } 03240 03241 /* Dependent on valid ECS->EVENT_THREAD. */ 03242 adjust_pc_after_break (ecs); 03243 03244 /* Dependent on the current PC value modified by adjust_pc_after_break. */ 03245 reinit_frame_cache (); 03246 03247 breakpoint_retire_moribund (); 03248 03249 /* First, distinguish signals caused by the debugger from signals 03250 that have to do with the program's own actions. Note that 03251 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending 03252 on the operating system version. Here we detect when a SIGILL or 03253 SIGEMT is really a breakpoint and change it to SIGTRAP. We do 03254 something similar for SIGSEGV, since a SIGSEGV will be generated 03255 when we're trying to execute a breakpoint instruction on a 03256 non-executable stack. This happens for call dummy breakpoints 03257 for architectures like SPARC that place call dummies on the 03258 stack. */ 03259 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED 03260 && (ecs->ws.value.sig == GDB_SIGNAL_ILL 03261 || ecs->ws.value.sig == GDB_SIGNAL_SEGV 03262 || ecs->ws.value.sig == GDB_SIGNAL_EMT)) 03263 { 03264 struct regcache *regcache = get_thread_regcache (ecs->ptid); 03265 03266 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache), 03267 regcache_read_pc (regcache))) 03268 { 03269 if (debug_infrun) 03270 fprintf_unfiltered (gdb_stdlog, 03271 "infrun: Treating signal as SIGTRAP\n"); 03272 ecs->ws.value.sig = GDB_SIGNAL_TRAP; 03273 } 03274 } 03275 03276 /* Mark the non-executing threads accordingly. In all-stop, all 03277 threads of all processes are stopped when we get any event 03278 reported. In non-stop mode, only the event thread stops. If 03279 we're handling a process exit in non-stop mode, there's nothing 03280 to do, as threads of the dead process are gone, and threads of 03281 any other process were left running. */ 03282 if (!non_stop) 03283 set_executing (minus_one_ptid, 0); 03284 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED 03285 && ecs->ws.kind != TARGET_WAITKIND_EXITED) 03286 set_executing (ecs->ptid, 0); 03287 03288 switch (infwait_state) 03289 { 03290 case infwait_thread_hop_state: 03291 if (debug_infrun) 03292 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n"); 03293 break; 03294 03295 case infwait_normal_state: 03296 if (debug_infrun) 03297 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n"); 03298 break; 03299 03300 case infwait_step_watch_state: 03301 if (debug_infrun) 03302 fprintf_unfiltered (gdb_stdlog, 03303 "infrun: infwait_step_watch_state\n"); 03304 03305 stepped_after_stopped_by_watchpoint = 1; 03306 break; 03307 03308 case infwait_nonstep_watch_state: 03309 if (debug_infrun) 03310 fprintf_unfiltered (gdb_stdlog, 03311 "infrun: infwait_nonstep_watch_state\n"); 03312 insert_breakpoints (); 03313 03314 /* FIXME-maybe: is this cleaner than setting a flag? Does it 03315 handle things like signals arriving and other things happening 03316 in combination correctly? */ 03317 stepped_after_stopped_by_watchpoint = 1; 03318 break; 03319 03320 default: 03321 internal_error (__FILE__, __LINE__, _("bad switch")); 03322 } 03323 03324 infwait_state = infwait_normal_state; 03325 waiton_ptid = pid_to_ptid (-1); 03326 03327 switch (ecs->ws.kind) 03328 { 03329 case TARGET_WAITKIND_LOADED: 03330 if (debug_infrun) 03331 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); 03332 /* Ignore gracefully during startup of the inferior, as it might 03333 be the shell which has just loaded some objects, otherwise 03334 add the symbols for the newly loaded objects. Also ignore at 03335 the beginning of an attach or remote session; we will query 03336 the full list of libraries once the connection is 03337 established. */ 03338 if (stop_soon == NO_STOP_QUIETLY) 03339 { 03340 struct regcache *regcache; 03341 enum bpstat_signal_value sval; 03342 03343 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03344 context_switch (ecs->ptid); 03345 regcache = get_thread_regcache (ecs->ptid); 03346 03347 handle_solib_event (); 03348 03349 ecs->event_thread->control.stop_bpstat 03350 = bpstat_stop_status (get_regcache_aspace (regcache), 03351 stop_pc, ecs->ptid, &ecs->ws); 03352 03353 sval 03354 = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, 03355 GDB_SIGNAL_TRAP); 03356 ecs->random_signal = sval == BPSTAT_SIGNAL_NO; 03357 03358 if (!ecs->random_signal) 03359 { 03360 /* A catchpoint triggered. */ 03361 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP; 03362 goto process_event_stop_test; 03363 } 03364 03365 /* If requested, stop when the dynamic linker notifies 03366 gdb of events. This allows the user to get control 03367 and place breakpoints in initializer routines for 03368 dynamically loaded objects (among other things). */ 03369 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 03370 if (stop_on_solib_events) 03371 { 03372 /* Make sure we print "Stopped due to solib-event" in 03373 normal_stop. */ 03374 stop_print_frame = 1; 03375 03376 stop_stepping (ecs); 03377 return; 03378 } 03379 } 03380 03381 /* If we are skipping through a shell, or through shared library 03382 loading that we aren't interested in, resume the program. If 03383 we're running the program normally, also resume. But stop if 03384 we're attaching or setting up a remote connection. */ 03385 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) 03386 { 03387 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03388 context_switch (ecs->ptid); 03389 03390 /* Loading of shared libraries might have changed breakpoint 03391 addresses. Make sure new breakpoints are inserted. */ 03392 if (stop_soon == NO_STOP_QUIETLY 03393 && !breakpoints_always_inserted_mode ()) 03394 insert_breakpoints (); 03395 resume (0, GDB_SIGNAL_0); 03396 prepare_to_wait (ecs); 03397 return; 03398 } 03399 03400 break; 03401 03402 case TARGET_WAITKIND_SPURIOUS: 03403 if (debug_infrun) 03404 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); 03405 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03406 context_switch (ecs->ptid); 03407 resume (0, GDB_SIGNAL_0); 03408 prepare_to_wait (ecs); 03409 return; 03410 03411 case TARGET_WAITKIND_EXITED: 03412 case TARGET_WAITKIND_SIGNALLED: 03413 if (debug_infrun) 03414 { 03415 if (ecs->ws.kind == TARGET_WAITKIND_EXITED) 03416 fprintf_unfiltered (gdb_stdlog, 03417 "infrun: TARGET_WAITKIND_EXITED\n"); 03418 else 03419 fprintf_unfiltered (gdb_stdlog, 03420 "infrun: TARGET_WAITKIND_SIGNALLED\n"); 03421 } 03422 03423 inferior_ptid = ecs->ptid; 03424 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid))); 03425 set_current_program_space (current_inferior ()->pspace); 03426 handle_vfork_child_exec_or_exit (0); 03427 target_terminal_ours (); /* Must do this before mourn anyway. */ 03428 03429 /* Clearing any previous state of convenience variables. */ 03430 clear_exit_convenience_vars (); 03431 03432 if (ecs->ws.kind == TARGET_WAITKIND_EXITED) 03433 { 03434 /* Record the exit code in the convenience variable $_exitcode, so 03435 that the user can inspect this again later. */ 03436 set_internalvar_integer (lookup_internalvar ("_exitcode"), 03437 (LONGEST) ecs->ws.value.integer); 03438 03439 /* Also record this in the inferior itself. */ 03440 current_inferior ()->has_exit_code = 1; 03441 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer; 03442 03443 print_exited_reason (ecs->ws.value.integer); 03444 } 03445 else 03446 { 03447 struct regcache *regcache = get_thread_regcache (ecs->ptid); 03448 struct gdbarch *gdbarch = get_regcache_arch (regcache); 03449 03450 if (gdbarch_gdb_signal_to_target_p (gdbarch)) 03451 { 03452 /* Set the value of the internal variable $_exitsignal, 03453 which holds the signal uncaught by the inferior. */ 03454 set_internalvar_integer (lookup_internalvar ("_exitsignal"), 03455 gdbarch_gdb_signal_to_target (gdbarch, 03456 ecs->ws.value.sig)); 03457 } 03458 else 03459 { 03460 /* We don't have access to the target's method used for 03461 converting between signal numbers (GDB's internal 03462 representation <-> target's representation). 03463 Therefore, we cannot do a good job at displaying this 03464 information to the user. It's better to just warn 03465 her about it (if infrun debugging is enabled), and 03466 give up. */ 03467 if (debug_infrun) 03468 fprintf_filtered (gdb_stdlog, _("\ 03469 Cannot fill $_exitsignal with the correct signal number.\n")); 03470 } 03471 03472 print_signal_exited_reason (ecs->ws.value.sig); 03473 } 03474 03475 gdb_flush (gdb_stdout); 03476 target_mourn_inferior (); 03477 singlestep_breakpoints_inserted_p = 0; 03478 cancel_single_step_breakpoints (); 03479 stop_print_frame = 0; 03480 stop_stepping (ecs); 03481 return; 03482 03483 /* The following are the only cases in which we keep going; 03484 the above cases end in a continue or goto. */ 03485 case TARGET_WAITKIND_FORKED: 03486 case TARGET_WAITKIND_VFORKED: 03487 if (debug_infrun) 03488 { 03489 if (ecs->ws.kind == TARGET_WAITKIND_FORKED) 03490 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); 03491 else 03492 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n"); 03493 } 03494 03495 /* Check whether the inferior is displaced stepping. */ 03496 { 03497 struct regcache *regcache = get_thread_regcache (ecs->ptid); 03498 struct gdbarch *gdbarch = get_regcache_arch (regcache); 03499 struct displaced_step_inferior_state *displaced 03500 = get_displaced_stepping_state (ptid_get_pid (ecs->ptid)); 03501 03502 /* If checking displaced stepping is supported, and thread 03503 ecs->ptid is displaced stepping. */ 03504 if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid)) 03505 { 03506 struct inferior *parent_inf 03507 = find_inferior_pid (ptid_get_pid (ecs->ptid)); 03508 struct regcache *child_regcache; 03509 CORE_ADDR parent_pc; 03510 03511 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED, 03512 indicating that the displaced stepping of syscall instruction 03513 has been done. Perform cleanup for parent process here. Note 03514 that this operation also cleans up the child process for vfork, 03515 because their pages are shared. */ 03516 displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP); 03517 03518 if (ecs->ws.kind == TARGET_WAITKIND_FORKED) 03519 { 03520 /* Restore scratch pad for child process. */ 03521 displaced_step_restore (displaced, ecs->ws.value.related_pid); 03522 } 03523 03524 /* Since the vfork/fork syscall instruction was executed in the scratchpad, 03525 the child's PC is also within the scratchpad. Set the child's PC 03526 to the parent's PC value, which has already been fixed up. 03527 FIXME: we use the parent's aspace here, although we're touching 03528 the child, because the child hasn't been added to the inferior 03529 list yet at this point. */ 03530 03531 child_regcache 03532 = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid, 03533 gdbarch, 03534 parent_inf->aspace); 03535 /* Read PC value of parent process. */ 03536 parent_pc = regcache_read_pc (regcache); 03537 03538 if (debug_displaced) 03539 fprintf_unfiltered (gdb_stdlog, 03540 "displaced: write child pc from %s to %s\n", 03541 paddress (gdbarch, 03542 regcache_read_pc (child_regcache)), 03543 paddress (gdbarch, parent_pc)); 03544 03545 regcache_write_pc (child_regcache, parent_pc); 03546 } 03547 } 03548 03549 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03550 context_switch (ecs->ptid); 03551 03552 /* Immediately detach breakpoints from the child before there's 03553 any chance of letting the user delete breakpoints from the 03554 breakpoint lists. If we don't do this early, it's easy to 03555 leave left over traps in the child, vis: "break foo; catch 03556 fork; c; <fork>; del; c; <child calls foo>". We only follow 03557 the fork on the last `continue', and by that time the 03558 breakpoint at "foo" is long gone from the breakpoint table. 03559 If we vforked, then we don't need to unpatch here, since both 03560 parent and child are sharing the same memory pages; we'll 03561 need to unpatch at follow/detach time instead to be certain 03562 that new breakpoints added between catchpoint hit time and 03563 vfork follow are detached. */ 03564 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED) 03565 { 03566 /* This won't actually modify the breakpoint list, but will 03567 physically remove the breakpoints from the child. */ 03568 detach_breakpoints (ecs->ws.value.related_pid); 03569 } 03570 03571 if (singlestep_breakpoints_inserted_p) 03572 { 03573 /* Pull the single step breakpoints out of the target. */ 03574 remove_single_step_breakpoints (); 03575 singlestep_breakpoints_inserted_p = 0; 03576 } 03577 03578 /* In case the event is caught by a catchpoint, remember that 03579 the event is to be followed at the next resume of the thread, 03580 and not immediately. */ 03581 ecs->event_thread->pending_follow = ecs->ws; 03582 03583 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); 03584 03585 ecs->event_thread->control.stop_bpstat 03586 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), 03587 stop_pc, ecs->ptid, &ecs->ws); 03588 03589 /* Note that we're interested in knowing the bpstat actually 03590 causes a stop, not just if it may explain the signal. 03591 Software watchpoints, for example, always appear in the 03592 bpstat. */ 03593 ecs->random_signal 03594 = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat); 03595 03596 /* If no catchpoint triggered for this, then keep going. */ 03597 if (ecs->random_signal) 03598 { 03599 ptid_t parent; 03600 ptid_t child; 03601 int should_resume; 03602 int follow_child 03603 = (follow_fork_mode_string == follow_fork_mode_child); 03604 03605 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 03606 03607 should_resume = follow_fork (); 03608 03609 parent = ecs->ptid; 03610 child = ecs->ws.value.related_pid; 03611 03612 /* In non-stop mode, also resume the other branch. */ 03613 if (non_stop && !detach_fork) 03614 { 03615 if (follow_child) 03616 switch_to_thread (parent); 03617 else 03618 switch_to_thread (child); 03619 03620 ecs->event_thread = inferior_thread (); 03621 ecs->ptid = inferior_ptid; 03622 keep_going (ecs); 03623 } 03624 03625 if (follow_child) 03626 switch_to_thread (child); 03627 else 03628 switch_to_thread (parent); 03629 03630 ecs->event_thread = inferior_thread (); 03631 ecs->ptid = inferior_ptid; 03632 03633 if (should_resume) 03634 keep_going (ecs); 03635 else 03636 stop_stepping (ecs); 03637 return; 03638 } 03639 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP; 03640 goto process_event_stop_test; 03641 03642 case TARGET_WAITKIND_VFORK_DONE: 03643 /* Done with the shared memory region. Re-insert breakpoints in 03644 the parent, and keep going. */ 03645 03646 if (debug_infrun) 03647 fprintf_unfiltered (gdb_stdlog, 03648 "infrun: TARGET_WAITKIND_VFORK_DONE\n"); 03649 03650 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03651 context_switch (ecs->ptid); 03652 03653 current_inferior ()->waiting_for_vfork_done = 0; 03654 current_inferior ()->pspace->breakpoints_not_allowed = 0; 03655 /* This also takes care of reinserting breakpoints in the 03656 previously locked inferior. */ 03657 keep_going (ecs); 03658 return; 03659 03660 case TARGET_WAITKIND_EXECD: 03661 if (debug_infrun) 03662 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); 03663 03664 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03665 context_switch (ecs->ptid); 03666 03667 singlestep_breakpoints_inserted_p = 0; 03668 cancel_single_step_breakpoints (); 03669 03670 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); 03671 03672 /* Do whatever is necessary to the parent branch of the vfork. */ 03673 handle_vfork_child_exec_or_exit (1); 03674 03675 /* This causes the eventpoints and symbol table to be reset. 03676 Must do this now, before trying to determine whether to 03677 stop. */ 03678 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname); 03679 03680 ecs->event_thread->control.stop_bpstat 03681 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), 03682 stop_pc, ecs->ptid, &ecs->ws); 03683 ecs->random_signal 03684 = (bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, 03685 GDB_SIGNAL_TRAP) 03686 == BPSTAT_SIGNAL_NO); 03687 03688 /* Note that this may be referenced from inside 03689 bpstat_stop_status above, through inferior_has_execd. */ 03690 xfree (ecs->ws.value.execd_pathname); 03691 ecs->ws.value.execd_pathname = NULL; 03692 03693 /* If no catchpoint triggered for this, then keep going. */ 03694 if (ecs->random_signal) 03695 { 03696 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 03697 keep_going (ecs); 03698 return; 03699 } 03700 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP; 03701 goto process_event_stop_test; 03702 03703 /* Be careful not to try to gather much state about a thread 03704 that's in a syscall. It's frequently a losing proposition. */ 03705 case TARGET_WAITKIND_SYSCALL_ENTRY: 03706 if (debug_infrun) 03707 fprintf_unfiltered (gdb_stdlog, 03708 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); 03709 /* Getting the current syscall number. */ 03710 if (handle_syscall_event (ecs) != 0) 03711 return; 03712 goto process_event_stop_test; 03713 03714 /* Before examining the threads further, step this thread to 03715 get it entirely out of the syscall. (We get notice of the 03716 event when the thread is just on the verge of exiting a 03717 syscall. Stepping one instruction seems to get it back 03718 into user code.) */ 03719 case TARGET_WAITKIND_SYSCALL_RETURN: 03720 if (debug_infrun) 03721 fprintf_unfiltered (gdb_stdlog, 03722 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); 03723 if (handle_syscall_event (ecs) != 0) 03724 return; 03725 goto process_event_stop_test; 03726 03727 case TARGET_WAITKIND_STOPPED: 03728 if (debug_infrun) 03729 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); 03730 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig; 03731 break; 03732 03733 case TARGET_WAITKIND_NO_HISTORY: 03734 if (debug_infrun) 03735 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n"); 03736 /* Reverse execution: target ran out of history info. */ 03737 03738 /* Pull the single step breakpoints out of the target. */ 03739 if (singlestep_breakpoints_inserted_p) 03740 { 03741 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03742 context_switch (ecs->ptid); 03743 remove_single_step_breakpoints (); 03744 singlestep_breakpoints_inserted_p = 0; 03745 } 03746 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); 03747 print_no_history_reason (); 03748 stop_stepping (ecs); 03749 return; 03750 } 03751 03752 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED) 03753 { 03754 /* Do we need to clean up the state of a thread that has 03755 completed a displaced single-step? (Doing so usually affects 03756 the PC, so do it here, before we set stop_pc.) */ 03757 displaced_step_fixup (ecs->ptid, 03758 ecs->event_thread->suspend.stop_signal); 03759 03760 /* If we either finished a single-step or hit a breakpoint, but 03761 the user wanted this thread to be stopped, pretend we got a 03762 SIG0 (generic unsignaled stop). */ 03763 03764 if (ecs->event_thread->stop_requested 03765 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP) 03766 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 03767 } 03768 03769 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); 03770 03771 if (debug_infrun) 03772 { 03773 struct regcache *regcache = get_thread_regcache (ecs->ptid); 03774 struct gdbarch *gdbarch = get_regcache_arch (regcache); 03775 struct cleanup *old_chain = save_inferior_ptid (); 03776 03777 inferior_ptid = ecs->ptid; 03778 03779 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n", 03780 paddress (gdbarch, stop_pc)); 03781 if (target_stopped_by_watchpoint ()) 03782 { 03783 CORE_ADDR addr; 03784 03785 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n"); 03786 03787 if (target_stopped_data_address (¤t_target, &addr)) 03788 fprintf_unfiltered (gdb_stdlog, 03789 "infrun: stopped data address = %s\n", 03790 paddress (gdbarch, addr)); 03791 else 03792 fprintf_unfiltered (gdb_stdlog, 03793 "infrun: (no data address available)\n"); 03794 } 03795 03796 do_cleanups (old_chain); 03797 } 03798 03799 if (stepping_past_singlestep_breakpoint) 03800 { 03801 gdb_assert (singlestep_breakpoints_inserted_p); 03802 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); 03803 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); 03804 03805 stepping_past_singlestep_breakpoint = 0; 03806 03807 /* We've either finished single-stepping past the single-step 03808 breakpoint, or stopped for some other reason. It would be nice if 03809 we could tell, but we can't reliably. */ 03810 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP) 03811 { 03812 if (debug_infrun) 03813 fprintf_unfiltered (gdb_stdlog, 03814 "infrun: stepping_past_" 03815 "singlestep_breakpoint\n"); 03816 /* Pull the single step breakpoints out of the target. */ 03817 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03818 context_switch (ecs->ptid); 03819 remove_single_step_breakpoints (); 03820 singlestep_breakpoints_inserted_p = 0; 03821 03822 ecs->random_signal = 0; 03823 ecs->event_thread->control.trap_expected = 0; 03824 03825 context_switch (saved_singlestep_ptid); 03826 if (deprecated_context_hook) 03827 deprecated_context_hook (pid_to_thread_id (saved_singlestep_ptid)); 03828 03829 resume (1, GDB_SIGNAL_0); 03830 prepare_to_wait (ecs); 03831 return; 03832 } 03833 } 03834 03835 if (!ptid_equal (deferred_step_ptid, null_ptid)) 03836 { 03837 /* In non-stop mode, there's never a deferred_step_ptid set. */ 03838 gdb_assert (!non_stop); 03839 03840 /* If we stopped for some other reason than single-stepping, ignore 03841 the fact that we were supposed to switch back. */ 03842 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP) 03843 { 03844 if (debug_infrun) 03845 fprintf_unfiltered (gdb_stdlog, 03846 "infrun: handling deferred step\n"); 03847 03848 /* Pull the single step breakpoints out of the target. */ 03849 if (singlestep_breakpoints_inserted_p) 03850 { 03851 if (!ptid_equal (ecs->ptid, inferior_ptid)) 03852 context_switch (ecs->ptid); 03853 remove_single_step_breakpoints (); 03854 singlestep_breakpoints_inserted_p = 0; 03855 } 03856 03857 ecs->event_thread->control.trap_expected = 0; 03858 03859 context_switch (deferred_step_ptid); 03860 deferred_step_ptid = null_ptid; 03861 /* Suppress spurious "Switching to ..." message. */ 03862 previous_inferior_ptid = inferior_ptid; 03863 03864 resume (1, GDB_SIGNAL_0); 03865 prepare_to_wait (ecs); 03866 return; 03867 } 03868 03869 deferred_step_ptid = null_ptid; 03870 } 03871 03872 /* See if a thread hit a thread-specific breakpoint that was meant for 03873 another thread. If so, then step that thread past the breakpoint, 03874 and continue it. */ 03875 03876 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP) 03877 { 03878 int thread_hop_needed = 0; 03879 struct address_space *aspace = 03880 get_regcache_aspace (get_thread_regcache (ecs->ptid)); 03881 03882 /* Check if a regular breakpoint has been hit before checking 03883 for a potential single step breakpoint. Otherwise, GDB will 03884 not see this breakpoint hit when stepping onto breakpoints. */ 03885 if (regular_breakpoint_inserted_here_p (aspace, stop_pc)) 03886 { 03887 ecs->random_signal = 0; 03888 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid)) 03889 thread_hop_needed = 1; 03890 } 03891 else if (singlestep_breakpoints_inserted_p) 03892 { 03893 /* We have not context switched yet, so this should be true 03894 no matter which thread hit the singlestep breakpoint. */ 03895 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid)); 03896 if (debug_infrun) 03897 fprintf_unfiltered (gdb_stdlog, "infrun: software single step " 03898 "trap for %s\n", 03899 target_pid_to_str (ecs->ptid)); 03900 03901 ecs->random_signal = 0; 03902 /* The call to in_thread_list is necessary because PTIDs sometimes 03903 change when we go from single-threaded to multi-threaded. If 03904 the singlestep_ptid is still in the list, assume that it is 03905 really different from ecs->ptid. */ 03906 if (!ptid_equal (singlestep_ptid, ecs->ptid) 03907 && in_thread_list (singlestep_ptid)) 03908 { 03909 /* If the PC of the thread we were trying to single-step 03910 has changed, discard this event (which we were going 03911 to ignore anyway), and pretend we saw that thread 03912 trap. This prevents us continuously moving the 03913 single-step breakpoint forward, one instruction at a 03914 time. If the PC has changed, then the thread we were 03915 trying to single-step has trapped or been signalled, 03916 but the event has not been reported to GDB yet. 03917 03918 There might be some cases where this loses signal 03919 information, if a signal has arrived at exactly the 03920 same time that the PC changed, but this is the best 03921 we can do with the information available. Perhaps we 03922 should arrange to report all events for all threads 03923 when they stop, or to re-poll the remote looking for 03924 this particular thread (i.e. temporarily enable 03925 schedlock). */ 03926 03927 CORE_ADDR new_singlestep_pc 03928 = regcache_read_pc (get_thread_regcache (singlestep_ptid)); 03929 03930 if (new_singlestep_pc != singlestep_pc) 03931 { 03932 enum gdb_signal stop_signal; 03933 03934 if (debug_infrun) 03935 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread," 03936 " but expected thread advanced also\n"); 03937 03938 /* The current context still belongs to 03939 singlestep_ptid. Don't swap here, since that's 03940 the context we want to use. Just fudge our 03941 state and continue. */ 03942 stop_signal = ecs->event_thread->suspend.stop_signal; 03943 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 03944 ecs->ptid = singlestep_ptid; 03945 ecs->event_thread = find_thread_ptid (ecs->ptid); 03946 ecs->event_thread->suspend.stop_signal = stop_signal; 03947 stop_pc = new_singlestep_pc; 03948 } 03949 else 03950 { 03951 if (debug_infrun) 03952 fprintf_unfiltered (gdb_stdlog, 03953 "infrun: unexpected thread\n"); 03954 03955 thread_hop_needed = 1; 03956 stepping_past_singlestep_breakpoint = 1; 03957 saved_singlestep_ptid = singlestep_ptid; 03958 } 03959 } 03960 } 03961 03962 if (thread_hop_needed) 03963 { 03964 struct regcache *thread_regcache; 03965 int remove_status = 0; 03966 03967 if (debug_infrun) 03968 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n"); 03969 03970 /* Switch context before touching inferior memory, the 03971 previous thread may have exited. */ 03972 if (!ptid_equal (inferior_ptid, ecs->ptid)) 03973 context_switch (ecs->ptid); 03974 03975 /* Saw a breakpoint, but it was hit by the wrong thread. 03976 Just continue. */ 03977 03978 if (singlestep_breakpoints_inserted_p) 03979 { 03980 /* Pull the single step breakpoints out of the target. */ 03981 remove_single_step_breakpoints (); 03982 singlestep_breakpoints_inserted_p = 0; 03983 } 03984 03985 /* If the arch can displace step, don't remove the 03986 breakpoints. */ 03987 thread_regcache = get_thread_regcache (ecs->ptid); 03988 if (!use_displaced_stepping (get_regcache_arch (thread_regcache))) 03989 remove_status = remove_breakpoints (); 03990 03991 /* Did we fail to remove breakpoints? If so, try 03992 to set the PC past the bp. (There's at least 03993 one situation in which we can fail to remove 03994 the bp's: On HP-UX's that use ttrace, we can't 03995 change the address space of a vforking child 03996 process until the child exits (well, okay, not 03997 then either :-) or execs. */ 03998 if (remove_status != 0) 03999 error (_("Cannot step over breakpoint hit in wrong thread")); 04000 else 04001 { /* Single step */ 04002 if (!non_stop) 04003 { 04004 /* Only need to require the next event from this 04005 thread in all-stop mode. */ 04006 waiton_ptid = ecs->ptid; 04007 infwait_state = infwait_thread_hop_state; 04008 } 04009 04010 ecs->event_thread->stepping_over_breakpoint = 1; 04011 keep_going (ecs); 04012 return; 04013 } 04014 } 04015 else if (singlestep_breakpoints_inserted_p) 04016 { 04017 ecs->random_signal = 0; 04018 } 04019 } 04020 else 04021 ecs->random_signal = 1; 04022 04023 /* See if something interesting happened to the non-current thread. If 04024 so, then switch to that thread. */ 04025 if (!ptid_equal (ecs->ptid, inferior_ptid)) 04026 { 04027 if (debug_infrun) 04028 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); 04029 04030 context_switch (ecs->ptid); 04031 04032 if (deprecated_context_hook) 04033 deprecated_context_hook (pid_to_thread_id (ecs->ptid)); 04034 } 04035 04036 /* At this point, get hold of the now-current thread's frame. */ 04037 frame = get_current_frame (); 04038 gdbarch = get_frame_arch (frame); 04039 04040 if (singlestep_breakpoints_inserted_p) 04041 { 04042 /* Pull the single step breakpoints out of the target. */ 04043 remove_single_step_breakpoints (); 04044 singlestep_breakpoints_inserted_p = 0; 04045 } 04046 04047 if (stepped_after_stopped_by_watchpoint) 04048 stopped_by_watchpoint = 0; 04049 else 04050 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); 04051 04052 /* If necessary, step over this watchpoint. We'll be back to display 04053 it in a moment. */ 04054 if (stopped_by_watchpoint 04055 && (target_have_steppable_watchpoint 04056 || gdbarch_have_nonsteppable_watchpoint (gdbarch))) 04057 { 04058 /* At this point, we are stopped at an instruction which has 04059 attempted to write to a piece of memory under control of 04060 a watchpoint. The instruction hasn't actually executed 04061 yet. If we were to evaluate the watchpoint expression 04062 now, we would get the old value, and therefore no change 04063 would seem to have occurred. 04064 04065 In order to make watchpoints work `right', we really need 04066 to complete the memory write, and then evaluate the 04067 watchpoint expression. We do this by single-stepping the 04068 target. 04069 04070 It may not be necessary to disable the watchpoint to stop over 04071 it. For example, the PA can (with some kernel cooperation) 04072 single step over a watchpoint without disabling the watchpoint. 04073 04074 It is far more common to need to disable a watchpoint to step 04075 the inferior over it. If we have non-steppable watchpoints, 04076 we must disable the current watchpoint; it's simplest to 04077 disable all watchpoints and breakpoints. */ 04078 int hw_step = 1; 04079 04080 if (!target_have_steppable_watchpoint) 04081 { 04082 remove_breakpoints (); 04083 /* See comment in resume why we need to stop bypassing signals 04084 while breakpoints have been removed. */ 04085 target_pass_signals (0, NULL); 04086 } 04087 /* Single step */ 04088 hw_step = maybe_software_singlestep (gdbarch, stop_pc); 04089 target_resume (ecs->ptid, hw_step, GDB_SIGNAL_0); 04090 waiton_ptid = ecs->ptid; 04091 if (target_have_steppable_watchpoint) 04092 infwait_state = infwait_step_watch_state; 04093 else 04094 infwait_state = infwait_nonstep_watch_state; 04095 prepare_to_wait (ecs); 04096 return; 04097 } 04098 04099 clear_stop_func (ecs); 04100 ecs->event_thread->stepping_over_breakpoint = 0; 04101 bpstat_clear (&ecs->event_thread->control.stop_bpstat); 04102 ecs->event_thread->control.stop_step = 0; 04103 stop_print_frame = 1; 04104 ecs->random_signal = 0; 04105 stopped_by_random_signal = 0; 04106 04107 /* Hide inlined functions starting here, unless we just performed stepi or 04108 nexti. After stepi and nexti, always show the innermost frame (not any 04109 inline function call sites). */ 04110 if (ecs->event_thread->control.step_range_end != 1) 04111 { 04112 struct address_space *aspace = 04113 get_regcache_aspace (get_thread_regcache (ecs->ptid)); 04114 04115 /* skip_inline_frames is expensive, so we avoid it if we can 04116 determine that the address is one where functions cannot have 04117 been inlined. This improves performance with inferiors that 04118 load a lot of shared libraries, because the solib event 04119 breakpoint is defined as the address of a function (i.e. not 04120 inline). Note that we have to check the previous PC as well 04121 as the current one to catch cases when we have just 04122 single-stepped off a breakpoint prior to reinstating it. 04123 Note that we're assuming that the code we single-step to is 04124 not inline, but that's not definitive: there's nothing 04125 preventing the event breakpoint function from containing 04126 inlined code, and the single-step ending up there. If the 04127 user had set a breakpoint on that inlined code, the missing 04128 skip_inline_frames call would break things. Fortunately 04129 that's an extremely unlikely scenario. */ 04130 if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws) 04131 && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP 04132 && ecs->event_thread->control.trap_expected 04133 && pc_at_non_inline_function (aspace, 04134 ecs->event_thread->prev_pc, 04135 &ecs->ws))) 04136 { 04137 skip_inline_frames (ecs->ptid); 04138 04139 /* Re-fetch current thread's frame in case that invalidated 04140 the frame cache. */ 04141 frame = get_current_frame (); 04142 gdbarch = get_frame_arch (frame); 04143 } 04144 } 04145 04146 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP 04147 && ecs->event_thread->control.trap_expected 04148 && gdbarch_single_step_through_delay_p (gdbarch) 04149 && currently_stepping (ecs->event_thread)) 04150 { 04151 /* We're trying to step off a breakpoint. Turns out that we're 04152 also on an instruction that needs to be stepped multiple 04153 times before it's been fully executing. E.g., architectures 04154 with a delay slot. It needs to be stepped twice, once for 04155 the instruction and once for the delay slot. */ 04156 int step_through_delay 04157 = gdbarch_single_step_through_delay (gdbarch, frame); 04158 04159 if (debug_infrun && step_through_delay) 04160 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); 04161 if (ecs->event_thread->control.step_range_end == 0 04162 && step_through_delay) 04163 { 04164 /* The user issued a continue when stopped at a breakpoint. 04165 Set up for another trap and get out of here. */ 04166 ecs->event_thread->stepping_over_breakpoint = 1; 04167 keep_going (ecs); 04168 return; 04169 } 04170 else if (step_through_delay) 04171 { 04172 /* The user issued a step when stopped at a breakpoint. 04173 Maybe we should stop, maybe we should not - the delay 04174 slot *might* correspond to a line of source. In any 04175 case, don't decide that here, just set 04176 ecs->stepping_over_breakpoint, making sure we 04177 single-step again before breakpoints are re-inserted. */ 04178 ecs->event_thread->stepping_over_breakpoint = 1; 04179 } 04180 } 04181 04182 /* Look at the cause of the stop, and decide what to do. 04183 The alternatives are: 04184 1) stop_stepping and return; to really stop and return to the debugger, 04185 2) keep_going and return to start up again 04186 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once) 04187 3) set ecs->random_signal to 1, and the decision between 1 and 2 04188 will be made according to the signal handling tables. */ 04189 04190 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP 04191 && stop_after_trap) 04192 { 04193 if (debug_infrun) 04194 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); 04195 stop_print_frame = 0; 04196 stop_stepping (ecs); 04197 return; 04198 } 04199 04200 /* This is originated from start_remote(), start_inferior() and 04201 shared libraries hook functions. */ 04202 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) 04203 { 04204 if (debug_infrun) 04205 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); 04206 stop_stepping (ecs); 04207 return; 04208 } 04209 04210 /* This originates from attach_command(). We need to overwrite 04211 the stop_signal here, because some kernels don't ignore a 04212 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call. 04213 See more comments in inferior.h. On the other hand, if we 04214 get a non-SIGSTOP, report it to the user - assume the backend 04215 will handle the SIGSTOP if it should show up later. 04216 04217 Also consider that the attach is complete when we see a 04218 SIGTRAP. Some systems (e.g. Windows), and stubs supporting 04219 target extended-remote report it instead of a SIGSTOP 04220 (e.g. gdbserver). We already rely on SIGTRAP being our 04221 signal, so this is no exception. 04222 04223 Also consider that the attach is complete when we see a 04224 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell 04225 the target to stop all threads of the inferior, in case the 04226 low level attach operation doesn't stop them implicitly. If 04227 they weren't stopped implicitly, then the stub will report a 04228 GDB_SIGNAL_0, meaning: stopped for no particular reason 04229 other than GDB's request. */ 04230 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP 04231 && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP 04232 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP 04233 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0)) 04234 { 04235 stop_stepping (ecs); 04236 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 04237 return; 04238 } 04239 04240 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that 04241 handles this event. */ 04242 ecs->event_thread->control.stop_bpstat 04243 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), 04244 stop_pc, ecs->ptid, &ecs->ws); 04245 04246 /* Following in case break condition called a 04247 function. */ 04248 stop_print_frame = 1; 04249 04250 /* This is where we handle "moribund" watchpoints. Unlike 04251 software breakpoints traps, hardware watchpoint traps are 04252 always distinguishable from random traps. If no high-level 04253 watchpoint is associated with the reported stop data address 04254 anymore, then the bpstat does not explain the signal --- 04255 simply make sure to ignore it if `stopped_by_watchpoint' is 04256 set. */ 04257 04258 if (debug_infrun 04259 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP 04260 && (bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, 04261 GDB_SIGNAL_TRAP) 04262 == BPSTAT_SIGNAL_NO) 04263 && stopped_by_watchpoint) 04264 fprintf_unfiltered (gdb_stdlog, 04265 "infrun: no user watchpoint explains " 04266 "watchpoint SIGTRAP, ignoring\n"); 04267 04268 /* NOTE: cagney/2003-03-29: These two checks for a random signal 04269 at one stage in the past included checks for an inferior 04270 function call's call dummy's return breakpoint. The original 04271 comment, that went with the test, read: 04272 04273 ``End of a stack dummy. Some systems (e.g. Sony news) give 04274 another signal besides SIGTRAP, so check here as well as 04275 above.'' 04276 04277 If someone ever tries to get call dummys on a 04278 non-executable stack to work (where the target would stop 04279 with something like a SIGSEGV), then those tests might need 04280 to be re-instated. Given, however, that the tests were only 04281 enabled when momentary breakpoints were not being used, I 04282 suspect that it won't be the case. 04283 04284 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to 04285 be necessary for call dummies on a non-executable stack on 04286 SPARC. */ 04287 04288 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP) 04289 ecs->random_signal 04290 = !((bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, 04291 GDB_SIGNAL_TRAP) 04292 != BPSTAT_SIGNAL_NO) 04293 || stopped_by_watchpoint 04294 || ecs->event_thread->control.trap_expected 04295 || (ecs->event_thread->control.step_range_end 04296 && (ecs->event_thread->control.step_resume_breakpoint 04297 == NULL))); 04298 else 04299 { 04300 enum bpstat_signal_value sval; 04301 04302 sval = bpstat_explains_signal (ecs->event_thread->control.stop_bpstat, 04303 ecs->event_thread->suspend.stop_signal); 04304 ecs->random_signal = (sval == BPSTAT_SIGNAL_NO); 04305 04306 if (sval == BPSTAT_SIGNAL_HIDE) 04307 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_TRAP; 04308 } 04309 04310 process_event_stop_test: 04311 04312 /* Re-fetch current thread's frame in case we did a 04313 "goto process_event_stop_test" above. */ 04314 frame = get_current_frame (); 04315 gdbarch = get_frame_arch (frame); 04316 04317 /* For the program's own signals, act according to 04318 the signal handling tables. */ 04319 04320 if (ecs->random_signal) 04321 { 04322 /* Signal not for debugging purposes. */ 04323 int printed = 0; 04324 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); 04325 04326 if (debug_infrun) 04327 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", 04328 ecs->event_thread->suspend.stop_signal); 04329 04330 stopped_by_random_signal = 1; 04331 04332 if (signal_print[ecs->event_thread->suspend.stop_signal]) 04333 { 04334 printed = 1; 04335 target_terminal_ours_for_output (); 04336 print_signal_received_reason 04337 (ecs->event_thread->suspend.stop_signal); 04338 } 04339 /* Always stop on signals if we're either just gaining control 04340 of the program, or the user explicitly requested this thread 04341 to remain stopped. */ 04342 if (stop_soon != NO_STOP_QUIETLY 04343 || ecs->event_thread->stop_requested 04344 || (!inf->detaching 04345 && signal_stop_state (ecs->event_thread->suspend.stop_signal))) 04346 { 04347 stop_stepping (ecs); 04348 return; 04349 } 04350 /* If not going to stop, give terminal back 04351 if we took it away. */ 04352 else if (printed) 04353 target_terminal_inferior (); 04354 04355 /* Clear the signal if it should not be passed. */ 04356 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0) 04357 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 04358 04359 if (ecs->event_thread->prev_pc == stop_pc 04360 && ecs->event_thread->control.trap_expected 04361 && ecs->event_thread->control.step_resume_breakpoint == NULL) 04362 { 04363 /* We were just starting a new sequence, attempting to 04364 single-step off of a breakpoint and expecting a SIGTRAP. 04365 Instead this signal arrives. This signal will take us out 04366 of the stepping range so GDB needs to remember to, when 04367 the signal handler returns, resume stepping off that 04368 breakpoint. */ 04369 /* To simplify things, "continue" is forced to use the same 04370 code paths as single-step - set a breakpoint at the 04371 signal return address and then, once hit, step off that 04372 breakpoint. */ 04373 if (debug_infrun) 04374 fprintf_unfiltered (gdb_stdlog, 04375 "infrun: signal arrived while stepping over " 04376 "breakpoint\n"); 04377 04378 insert_hp_step_resume_breakpoint_at_frame (frame); 04379 ecs->event_thread->step_after_step_resume_breakpoint = 1; 04380 /* Reset trap_expected to ensure breakpoints are re-inserted. */ 04381 ecs->event_thread->control.trap_expected = 0; 04382 keep_going (ecs); 04383 return; 04384 } 04385 04386 if (ecs->event_thread->control.step_range_end != 0 04387 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0 04388 && pc_in_thread_step_range (stop_pc, ecs->event_thread) 04389 && frame_id_eq (get_stack_frame_id (frame), 04390 ecs->event_thread->control.step_stack_frame_id) 04391 && ecs->event_thread->control.step_resume_breakpoint == NULL) 04392 { 04393 /* The inferior is about to take a signal that will take it 04394 out of the single step range. Set a breakpoint at the 04395 current PC (which is presumably where the signal handler 04396 will eventually return) and then allow the inferior to 04397 run free. 04398 04399 Note that this is only needed for a signal delivered 04400 while in the single-step range. Nested signals aren't a 04401 problem as they eventually all return. */ 04402 if (debug_infrun) 04403 fprintf_unfiltered (gdb_stdlog, 04404 "infrun: signal may take us out of " 04405 "single-step range\n"); 04406 04407 insert_hp_step_resume_breakpoint_at_frame (frame); 04408 /* Reset trap_expected to ensure breakpoints are re-inserted. */ 04409 ecs->event_thread->control.trap_expected = 0; 04410 keep_going (ecs); 04411 return; 04412 } 04413 04414 /* Note: step_resume_breakpoint may be non-NULL. This occures 04415 when either there's a nested signal, or when there's a 04416 pending signal enabled just as the signal handler returns 04417 (leaving the inferior at the step-resume-breakpoint without 04418 actually executing it). Either way continue until the 04419 breakpoint is really hit. */ 04420 } 04421 else 04422 { 04423 /* Handle cases caused by hitting a breakpoint. */ 04424 04425 CORE_ADDR jmp_buf_pc; 04426 struct bpstat_what what; 04427 04428 what = bpstat_what (ecs->event_thread->control.stop_bpstat); 04429 04430 if (what.call_dummy) 04431 { 04432 stop_stack_dummy = what.call_dummy; 04433 } 04434 04435 /* If we hit an internal event that triggers symbol changes, the 04436 current frame will be invalidated within bpstat_what (e.g., 04437 if we hit an internal solib event). Re-fetch it. */ 04438 frame = get_current_frame (); 04439 gdbarch = get_frame_arch (frame); 04440 04441 switch (what.main_action) 04442 { 04443 case BPSTAT_WHAT_SET_LONGJMP_RESUME: 04444 /* If we hit the breakpoint at longjmp while stepping, we 04445 install a momentary breakpoint at the target of the 04446 jmp_buf. */ 04447 04448 if (debug_infrun) 04449 fprintf_unfiltered (gdb_stdlog, 04450 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); 04451 04452 ecs->event_thread->stepping_over_breakpoint = 1; 04453 04454 if (what.is_longjmp) 04455 { 04456 struct value *arg_value; 04457 04458 /* If we set the longjmp breakpoint via a SystemTap 04459 probe, then use it to extract the arguments. The 04460 destination PC is the third argument to the 04461 probe. */ 04462 arg_value = probe_safe_evaluate_at_pc (frame, 2); 04463 if (arg_value) 04464 jmp_buf_pc = value_as_address (arg_value); 04465 else if (!gdbarch_get_longjmp_target_p (gdbarch) 04466 || !gdbarch_get_longjmp_target (gdbarch, 04467 frame, &jmp_buf_pc)) 04468 { 04469 if (debug_infrun) 04470 fprintf_unfiltered (gdb_stdlog, 04471 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME " 04472 "(!gdbarch_get_longjmp_target)\n"); 04473 keep_going (ecs); 04474 return; 04475 } 04476 04477 /* Insert a breakpoint at resume address. */ 04478 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc); 04479 } 04480 else 04481 check_exception_resume (ecs, frame); 04482 keep_going (ecs); 04483 return; 04484 04485 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: 04486 { 04487 struct frame_info *init_frame; 04488 04489 /* There are several cases to consider. 04490 04491 1. The initiating frame no longer exists. In this case 04492 we must stop, because the exception or longjmp has gone 04493 too far. 04494 04495 2. The initiating frame exists, and is the same as the 04496 current frame. We stop, because the exception or 04497 longjmp has been caught. 04498 04499 3. The initiating frame exists and is different from 04500 the current frame. This means the exception or longjmp 04501 has been caught beneath the initiating frame, so keep 04502 going. 04503 04504 4. longjmp breakpoint has been placed just to protect 04505 against stale dummy frames and user is not interested 04506 in stopping around longjmps. */ 04507 04508 if (debug_infrun) 04509 fprintf_unfiltered (gdb_stdlog, 04510 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); 04511 04512 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint 04513 != NULL); 04514 delete_exception_resume_breakpoint (ecs->event_thread); 04515 04516 if (what.is_longjmp) 04517 { 04518 check_longjmp_breakpoint_for_call_dummy (ecs->event_thread->num); 04519 04520 if (!frame_id_p (ecs->event_thread->initiating_frame)) 04521 { 04522 /* Case 4. */ 04523 keep_going (ecs); 04524 return; 04525 } 04526 } 04527 04528 init_frame = frame_find_by_id (ecs->event_thread->initiating_frame); 04529 04530 if (init_frame) 04531 { 04532 struct frame_id current_id 04533 = get_frame_id (get_current_frame ()); 04534 if (frame_id_eq (current_id, 04535 ecs->event_thread->initiating_frame)) 04536 { 04537 /* Case 2. Fall through. */ 04538 } 04539 else 04540 { 04541 /* Case 3. */ 04542 keep_going (ecs); 04543 return; 04544 } 04545 } 04546 04547 /* For Cases 1 and 2, remove the step-resume breakpoint, 04548 if it exists. */ 04549 delete_step_resume_breakpoint (ecs->event_thread); 04550 04551 ecs->event_thread->control.stop_step = 1; 04552 print_end_stepping_range_reason (); 04553 stop_stepping (ecs); 04554 } 04555 return; 04556 04557 case BPSTAT_WHAT_SINGLE: 04558 if (debug_infrun) 04559 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); 04560 ecs->event_thread->stepping_over_breakpoint = 1; 04561 /* Still need to check other stuff, at least the case where 04562 we are stepping and step out of the right range. */ 04563 break; 04564 04565 case BPSTAT_WHAT_STEP_RESUME: 04566 if (debug_infrun) 04567 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); 04568 04569 delete_step_resume_breakpoint (ecs->event_thread); 04570 if (ecs->event_thread->control.proceed_to_finish 04571 && execution_direction == EXEC_REVERSE) 04572 { 04573 struct thread_info *tp = ecs->event_thread; 04574 04575 /* We are finishing a function in reverse, and just hit 04576 the step-resume breakpoint at the start address of 04577 the function, and we're almost there -- just need to 04578 back up by one more single-step, which should take us 04579 back to the function call. */ 04580 tp->control.step_range_start = tp->control.step_range_end = 1; 04581 keep_going (ecs); 04582 return; 04583 } 04584 fill_in_stop_func (gdbarch, ecs); 04585 if (stop_pc == ecs->stop_func_start 04586 && execution_direction == EXEC_REVERSE) 04587 { 04588 /* We are stepping over a function call in reverse, and 04589 just hit the step-resume breakpoint at the start 04590 address of the function. Go back to single-stepping, 04591 which should take us back to the function call. */ 04592 ecs->event_thread->stepping_over_breakpoint = 1; 04593 keep_going (ecs); 04594 return; 04595 } 04596 break; 04597 04598 case BPSTAT_WHAT_STOP_NOISY: 04599 if (debug_infrun) 04600 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); 04601 stop_print_frame = 1; 04602 04603 /* We are about to nuke the step_resume_breakpointt via the 04604 cleanup chain, so no need to worry about it here. */ 04605 04606 stop_stepping (ecs); 04607 return; 04608 04609 case BPSTAT_WHAT_STOP_SILENT: 04610 if (debug_infrun) 04611 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); 04612 stop_print_frame = 0; 04613 04614 /* We are about to nuke the step_resume_breakpoin via the 04615 cleanup chain, so no need to worry about it here. */ 04616 04617 stop_stepping (ecs); 04618 return; 04619 04620 case BPSTAT_WHAT_HP_STEP_RESUME: 04621 if (debug_infrun) 04622 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n"); 04623 04624 delete_step_resume_breakpoint (ecs->event_thread); 04625 if (ecs->event_thread->step_after_step_resume_breakpoint) 04626 { 04627 /* Back when the step-resume breakpoint was inserted, we 04628 were trying to single-step off a breakpoint. Go back 04629 to doing that. */ 04630 ecs->event_thread->step_after_step_resume_breakpoint = 0; 04631 ecs->event_thread->stepping_over_breakpoint = 1; 04632 keep_going (ecs); 04633 return; 04634 } 04635 break; 04636 04637 case BPSTAT_WHAT_KEEP_CHECKING: 04638 break; 04639 } 04640 } 04641 04642 /* We come here if we hit a breakpoint but should not 04643 stop for it. Possibly we also were stepping 04644 and should stop for that. So fall through and 04645 test for stepping. But, if not stepping, 04646 do not stop. */ 04647 04648 /* In all-stop mode, if we're currently stepping but have stopped in 04649 some other thread, we need to switch back to the stepped thread. */ 04650 if (!non_stop) 04651 { 04652 struct thread_info *tp; 04653 04654 tp = iterate_over_threads (currently_stepping_or_nexting_callback, 04655 ecs->event_thread); 04656 if (tp) 04657 { 04658 /* However, if the current thread is blocked on some internal 04659 breakpoint, and we simply need to step over that breakpoint 04660 to get it going again, do that first. */ 04661 if ((ecs->event_thread->control.trap_expected 04662 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP) 04663 || ecs->event_thread->stepping_over_breakpoint) 04664 { 04665 keep_going (ecs); 04666 return; 04667 } 04668 04669 /* If the stepping thread exited, then don't try to switch 04670 back and resume it, which could fail in several different 04671 ways depending on the target. Instead, just keep going. 04672 04673 We can find a stepping dead thread in the thread list in 04674 two cases: 04675 04676 - The target supports thread exit events, and when the 04677 target tries to delete the thread from the thread list, 04678 inferior_ptid pointed at the exiting thread. In such 04679 case, calling delete_thread does not really remove the 04680 thread from the list; instead, the thread is left listed, 04681 with 'exited' state. 04682 04683 - The target's debug interface does not support thread 04684 exit events, and so we have no idea whatsoever if the 04685 previously stepping thread is still alive. For that 04686 reason, we need to synchronously query the target 04687 now. */ 04688 if (is_exited (tp->ptid) 04689 || !target_thread_alive (tp->ptid)) 04690 { 04691 if (debug_infrun) 04692 fprintf_unfiltered (gdb_stdlog, 04693 "infrun: not switching back to " 04694 "stepped thread, it has vanished\n"); 04695 04696 delete_thread (tp->ptid); 04697 keep_going (ecs); 04698 return; 04699 } 04700 04701 /* Otherwise, we no longer expect a trap in the current thread. 04702 Clear the trap_expected flag before switching back -- this is 04703 what keep_going would do as well, if we called it. */ 04704 ecs->event_thread->control.trap_expected = 0; 04705 04706 if (debug_infrun) 04707 fprintf_unfiltered (gdb_stdlog, 04708 "infrun: switching back to stepped thread\n"); 04709 04710 ecs->event_thread = tp; 04711 ecs->ptid = tp->ptid; 04712 context_switch (ecs->ptid); 04713 keep_going (ecs); 04714 return; 04715 } 04716 } 04717 04718 if (ecs->event_thread->control.step_resume_breakpoint) 04719 { 04720 if (debug_infrun) 04721 fprintf_unfiltered (gdb_stdlog, 04722 "infrun: step-resume breakpoint is inserted\n"); 04723 04724 /* Having a step-resume breakpoint overrides anything 04725 else having to do with stepping commands until 04726 that breakpoint is reached. */ 04727 keep_going (ecs); 04728 return; 04729 } 04730 04731 if (ecs->event_thread->control.step_range_end == 0) 04732 { 04733 if (debug_infrun) 04734 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); 04735 /* Likewise if we aren't even stepping. */ 04736 keep_going (ecs); 04737 return; 04738 } 04739 04740 /* Re-fetch current thread's frame in case the code above caused 04741 the frame cache to be re-initialized, making our FRAME variable 04742 a dangling pointer. */ 04743 frame = get_current_frame (); 04744 gdbarch = get_frame_arch (frame); 04745 fill_in_stop_func (gdbarch, ecs); 04746 04747 /* If stepping through a line, keep going if still within it. 04748 04749 Note that step_range_end is the address of the first instruction 04750 beyond the step range, and NOT the address of the last instruction 04751 within it! 04752 04753 Note also that during reverse execution, we may be stepping 04754 through a function epilogue and therefore must detect when 04755 the current-frame changes in the middle of a line. */ 04756 04757 if (pc_in_thread_step_range (stop_pc, ecs->event_thread) 04758 && (execution_direction != EXEC_REVERSE 04759 || frame_id_eq (get_frame_id (frame), 04760 ecs->event_thread->control.step_frame_id))) 04761 { 04762 if (debug_infrun) 04763 fprintf_unfiltered 04764 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n", 04765 paddress (gdbarch, ecs->event_thread->control.step_range_start), 04766 paddress (gdbarch, ecs->event_thread->control.step_range_end)); 04767 04768 /* Tentatively re-enable range stepping; `resume' disables it if 04769 necessary (e.g., if we're stepping over a breakpoint or we 04770 have software watchpoints). */ 04771 ecs->event_thread->control.may_range_step = 1; 04772 04773 /* When stepping backward, stop at beginning of line range 04774 (unless it's the function entry point, in which case 04775 keep going back to the call point). */ 04776 if (stop_pc == ecs->event_thread->control.step_range_start 04777 && stop_pc != ecs->stop_func_start 04778 && execution_direction == EXEC_REVERSE) 04779 { 04780 ecs->event_thread->control.stop_step = 1; 04781 print_end_stepping_range_reason (); 04782 stop_stepping (ecs); 04783 } 04784 else 04785 keep_going (ecs); 04786 04787 return; 04788 } 04789 04790 /* We stepped out of the stepping range. */ 04791 04792 /* If we are stepping at the source level and entered the runtime 04793 loader dynamic symbol resolution code... 04794 04795 EXEC_FORWARD: we keep on single stepping until we exit the run 04796 time loader code and reach the callee's address. 04797 04798 EXEC_REVERSE: we've already executed the callee (backward), and 04799 the runtime loader code is handled just like any other 04800 undebuggable function call. Now we need only keep stepping 04801 backward through the trampoline code, and that's handled further 04802 down, so there is nothing for us to do here. */ 04803 04804 if (execution_direction != EXEC_REVERSE 04805 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE 04806 && in_solib_dynsym_resolve_code (stop_pc)) 04807 { 04808 CORE_ADDR pc_after_resolver = 04809 gdbarch_skip_solib_resolver (gdbarch, stop_pc); 04810 04811 if (debug_infrun) 04812 fprintf_unfiltered (gdb_stdlog, 04813 "infrun: stepped into dynsym resolve code\n"); 04814 04815 if (pc_after_resolver) 04816 { 04817 /* Set up a step-resume breakpoint at the address 04818 indicated by SKIP_SOLIB_RESOLVER. */ 04819 struct symtab_and_line sr_sal; 04820 04821 init_sal (&sr_sal); 04822 sr_sal.pc = pc_after_resolver; 04823 sr_sal.pspace = get_frame_program_space (frame); 04824 04825 insert_step_resume_breakpoint_at_sal (gdbarch, 04826 sr_sal, null_frame_id); 04827 } 04828 04829 keep_going (ecs); 04830 return; 04831 } 04832 04833 if (ecs->event_thread->control.step_range_end != 1 04834 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE 04835 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) 04836 && get_frame_type (frame) == SIGTRAMP_FRAME) 04837 { 04838 if (debug_infrun) 04839 fprintf_unfiltered (gdb_stdlog, 04840 "infrun: stepped into signal trampoline\n"); 04841 /* The inferior, while doing a "step" or "next", has ended up in 04842 a signal trampoline (either by a signal being delivered or by 04843 the signal handler returning). Just single-step until the 04844 inferior leaves the trampoline (either by calling the handler 04845 or returning). */ 04846 keep_going (ecs); 04847 return; 04848 } 04849 04850 /* If we're in the return path from a shared library trampoline, 04851 we want to proceed through the trampoline when stepping. */ 04852 /* macro/2012-04-25: This needs to come before the subroutine 04853 call check below as on some targets return trampolines look 04854 like subroutine calls (MIPS16 return thunks). */ 04855 if (gdbarch_in_solib_return_trampoline (gdbarch, 04856 stop_pc, ecs->stop_func_name) 04857 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE) 04858 { 04859 /* Determine where this trampoline returns. */ 04860 CORE_ADDR real_stop_pc; 04861 04862 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); 04863 04864 if (debug_infrun) 04865 fprintf_unfiltered (gdb_stdlog, 04866 "infrun: stepped into solib return tramp\n"); 04867 04868 /* Only proceed through if we know where it's going. */ 04869 if (real_stop_pc) 04870 { 04871 /* And put the step-breakpoint there and go until there. */ 04872 struct symtab_and_line sr_sal; 04873 04874 init_sal (&sr_sal); /* initialize to zeroes */ 04875 sr_sal.pc = real_stop_pc; 04876 sr_sal.section = find_pc_overlay (sr_sal.pc); 04877 sr_sal.pspace = get_frame_program_space (frame); 04878 04879 /* Do not specify what the fp should be when we stop since 04880 on some machines the prologue is where the new fp value 04881 is established. */ 04882 insert_step_resume_breakpoint_at_sal (gdbarch, 04883 sr_sal, null_frame_id); 04884 04885 /* Restart without fiddling with the step ranges or 04886 other state. */ 04887 keep_going (ecs); 04888 return; 04889 } 04890 } 04891 04892 /* Check for subroutine calls. The check for the current frame 04893 equalling the step ID is not necessary - the check of the 04894 previous frame's ID is sufficient - but it is a common case and 04895 cheaper than checking the previous frame's ID. 04896 04897 NOTE: frame_id_eq will never report two invalid frame IDs as 04898 being equal, so to get into this block, both the current and 04899 previous frame must have valid frame IDs. */ 04900 /* The outer_frame_id check is a heuristic to detect stepping 04901 through startup code. If we step over an instruction which 04902 sets the stack pointer from an invalid value to a valid value, 04903 we may detect that as a subroutine call from the mythical 04904 "outermost" function. This could be fixed by marking 04905 outermost frames as !stack_p,code_p,special_p. Then the 04906 initial outermost frame, before sp was valid, would 04907 have code_addr == &_start. See the comment in frame_id_eq 04908 for more. */ 04909 if (!frame_id_eq (get_stack_frame_id (frame), 04910 ecs->event_thread->control.step_stack_frame_id) 04911 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()), 04912 ecs->event_thread->control.step_stack_frame_id) 04913 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id, 04914 outer_frame_id) 04915 || step_start_function != find_pc_function (stop_pc)))) 04916 { 04917 CORE_ADDR real_stop_pc; 04918 04919 if (debug_infrun) 04920 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); 04921 04922 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE) 04923 || ((ecs->event_thread->control.step_range_end == 1) 04924 && in_prologue (gdbarch, ecs->event_thread->prev_pc, 04925 ecs->stop_func_start))) 04926 { 04927 /* I presume that step_over_calls is only 0 when we're 04928 supposed to be stepping at the assembly language level 04929 ("stepi"). Just stop. */ 04930 /* Also, maybe we just did a "nexti" inside a prolog, so we 04931 thought it was a subroutine call but it was not. Stop as 04932 well. FENN */ 04933 /* And this works the same backward as frontward. MVS */ 04934 ecs->event_thread->control.stop_step = 1; 04935 print_end_stepping_range_reason (); 04936 stop_stepping (ecs); 04937 return; 04938 } 04939 04940 /* Reverse stepping through solib trampolines. */ 04941 04942 if (execution_direction == EXEC_REVERSE 04943 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE 04944 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) 04945 || (ecs->stop_func_start == 0 04946 && in_solib_dynsym_resolve_code (stop_pc)))) 04947 { 04948 /* Any solib trampoline code can be handled in reverse 04949 by simply continuing to single-step. We have already 04950 executed the solib function (backwards), and a few 04951 steps will take us back through the trampoline to the 04952 caller. */ 04953 keep_going (ecs); 04954 return; 04955 } 04956 04957 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) 04958 { 04959 /* We're doing a "next". 04960 04961 Normal (forward) execution: set a breakpoint at the 04962 callee's return address (the address at which the caller 04963 will resume). 04964 04965 Reverse (backward) execution. set the step-resume 04966 breakpoint at the start of the function that we just 04967 stepped into (backwards), and continue to there. When we 04968 get there, we'll need to single-step back to the caller. */ 04969 04970 if (execution_direction == EXEC_REVERSE) 04971 { 04972 /* If we're already at the start of the function, we've either 04973 just stepped backward into a single instruction function, 04974 or stepped back out of a signal handler to the first instruction 04975 of the function. Just keep going, which will single-step back 04976 to the caller. */ 04977 if (ecs->stop_func_start != stop_pc && ecs->stop_func_start != 0) 04978 { 04979 struct symtab_and_line sr_sal; 04980 04981 /* Normal function call return (static or dynamic). */ 04982 init_sal (&sr_sal); 04983 sr_sal.pc = ecs->stop_func_start; 04984 sr_sal.pspace = get_frame_program_space (frame); 04985 insert_step_resume_breakpoint_at_sal (gdbarch, 04986 sr_sal, null_frame_id); 04987 } 04988 } 04989 else 04990 insert_step_resume_breakpoint_at_caller (frame); 04991 04992 keep_going (ecs); 04993 return; 04994 } 04995 04996 /* If we are in a function call trampoline (a stub between the 04997 calling routine and the real function), locate the real 04998 function. That's what tells us (a) whether we want to step 04999 into it at all, and (b) what prologue we want to run to the 05000 end of, if we do step into it. */ 05001 real_stop_pc = skip_language_trampoline (frame, stop_pc); 05002 if (real_stop_pc == 0) 05003 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); 05004 if (real_stop_pc != 0) 05005 ecs->stop_func_start = real_stop_pc; 05006 05007 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc)) 05008 { 05009 struct symtab_and_line sr_sal; 05010 05011 init_sal (&sr_sal); 05012 sr_sal.pc = ecs->stop_func_start; 05013 sr_sal.pspace = get_frame_program_space (frame); 05014 05015 insert_step_resume_breakpoint_at_sal (gdbarch, 05016 sr_sal, null_frame_id); 05017 keep_going (ecs); 05018 return; 05019 } 05020 05021 /* If we have line number information for the function we are 05022 thinking of stepping into and the function isn't on the skip 05023 list, step into it. 05024 05025 If there are several symtabs at that PC (e.g. with include 05026 files), just want to know whether *any* of them have line 05027 numbers. find_pc_line handles this. */ 05028 { 05029 struct symtab_and_line tmp_sal; 05030 05031 tmp_sal = find_pc_line (ecs->stop_func_start, 0); 05032 if (tmp_sal.line != 0 05033 && !function_name_is_marked_for_skip (ecs->stop_func_name, 05034 &tmp_sal)) 05035 { 05036 if (execution_direction == EXEC_REVERSE) 05037 handle_step_into_function_backward (gdbarch, ecs); 05038 else 05039 handle_step_into_function (gdbarch, ecs); 05040 return; 05041 } 05042 } 05043 05044 /* If we have no line number and the step-stop-if-no-debug is 05045 set, we stop the step so that the user has a chance to switch 05046 in assembly mode. */ 05047 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE 05048 && step_stop_if_no_debug) 05049 { 05050 ecs->event_thread->control.stop_step = 1; 05051 print_end_stepping_range_reason (); 05052 stop_stepping (ecs); 05053 return; 05054 } 05055 05056 if (execution_direction == EXEC_REVERSE) 05057 { 05058 /* If we're already at the start of the function, we've either just 05059 stepped backward into a single instruction function without line 05060 number info, or stepped back out of a signal handler to the first 05061 instruction of the function without line number info. Just keep 05062 going, which will single-step back to the caller. */ 05063 if (ecs->stop_func_start != stop_pc) 05064 { 05065 /* Set a breakpoint at callee's start address. 05066 From there we can step once and be back in the caller. */ 05067 struct symtab_and_line sr_sal; 05068 05069 init_sal (&sr_sal); 05070 sr_sal.pc = ecs->stop_func_start; 05071 sr_sal.pspace = get_frame_program_space (frame); 05072 insert_step_resume_breakpoint_at_sal (gdbarch, 05073 sr_sal, null_frame_id); 05074 } 05075 } 05076 else 05077 /* Set a breakpoint at callee's return address (the address 05078 at which the caller will resume). */ 05079 insert_step_resume_breakpoint_at_caller (frame); 05080 05081 keep_going (ecs); 05082 return; 05083 } 05084 05085 /* Reverse stepping through solib trampolines. */ 05086 05087 if (execution_direction == EXEC_REVERSE 05088 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE) 05089 { 05090 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) 05091 || (ecs->stop_func_start == 0 05092 && in_solib_dynsym_resolve_code (stop_pc))) 05093 { 05094 /* Any solib trampoline code can be handled in reverse 05095 by simply continuing to single-step. We have already 05096 executed the solib function (backwards), and a few 05097 steps will take us back through the trampoline to the 05098 caller. */ 05099 keep_going (ecs); 05100 return; 05101 } 05102 else if (in_solib_dynsym_resolve_code (stop_pc)) 05103 { 05104 /* Stepped backward into the solib dynsym resolver. 05105 Set a breakpoint at its start and continue, then 05106 one more step will take us out. */ 05107 struct symtab_and_line sr_sal; 05108 05109 init_sal (&sr_sal); 05110 sr_sal.pc = ecs->stop_func_start; 05111 sr_sal.pspace = get_frame_program_space (frame); 05112 insert_step_resume_breakpoint_at_sal (gdbarch, 05113 sr_sal, null_frame_id); 05114 keep_going (ecs); 05115 return; 05116 } 05117 } 05118 05119 stop_pc_sal = find_pc_line (stop_pc, 0); 05120 05121 /* NOTE: tausq/2004-05-24: This if block used to be done before all 05122 the trampoline processing logic, however, there are some trampolines 05123 that have no names, so we should do trampoline handling first. */ 05124 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE 05125 && ecs->stop_func_name == NULL 05126 && stop_pc_sal.line == 0) 05127 { 05128 if (debug_infrun) 05129 fprintf_unfiltered (gdb_stdlog, 05130 "infrun: stepped into undebuggable function\n"); 05131 05132 /* The inferior just stepped into, or returned to, an 05133 undebuggable function (where there is no debugging information 05134 and no line number corresponding to the address where the 05135 inferior stopped). Since we want to skip this kind of code, 05136 we keep going until the inferior returns from this 05137 function - unless the user has asked us not to (via 05138 set step-mode) or we no longer know how to get back 05139 to the call site. */ 05140 if (step_stop_if_no_debug 05141 || !frame_id_p (frame_unwind_caller_id (frame))) 05142 { 05143 /* If we have no line number and the step-stop-if-no-debug 05144 is set, we stop the step so that the user has a chance to 05145 switch in assembly mode. */ 05146 ecs->event_thread->control.stop_step = 1; 05147 print_end_stepping_range_reason (); 05148 stop_stepping (ecs); 05149 return; 05150 } 05151 else 05152 { 05153 /* Set a breakpoint at callee's return address (the address 05154 at which the caller will resume). */ 05155 insert_step_resume_breakpoint_at_caller (frame); 05156 keep_going (ecs); 05157 return; 05158 } 05159 } 05160 05161 if (ecs->event_thread->control.step_range_end == 1) 05162 { 05163 /* It is stepi or nexti. We always want to stop stepping after 05164 one instruction. */ 05165 if (debug_infrun) 05166 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); 05167 ecs->event_thread->control.stop_step = 1; 05168 print_end_stepping_range_reason (); 05169 stop_stepping (ecs); 05170 return; 05171 } 05172 05173 if (stop_pc_sal.line == 0) 05174 { 05175 /* We have no line number information. That means to stop 05176 stepping (does this always happen right after one instruction, 05177 when we do "s" in a function with no line numbers, 05178 or can this happen as a result of a return or longjmp?). */ 05179 if (debug_infrun) 05180 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); 05181 ecs->event_thread->control.stop_step = 1; 05182 print_end_stepping_range_reason (); 05183 stop_stepping (ecs); 05184 return; 05185 } 05186 05187 /* Look for "calls" to inlined functions, part one. If the inline 05188 frame machinery detected some skipped call sites, we have entered 05189 a new inline function. */ 05190 05191 if (frame_id_eq (get_frame_id (get_current_frame ()), 05192 ecs->event_thread->control.step_frame_id) 05193 && inline_skipped_frames (ecs->ptid)) 05194 { 05195 struct symtab_and_line call_sal; 05196 05197 if (debug_infrun) 05198 fprintf_unfiltered (gdb_stdlog, 05199 "infrun: stepped into inlined function\n"); 05200 05201 find_frame_sal (get_current_frame (), &call_sal); 05202 05203 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL) 05204 { 05205 /* For "step", we're going to stop. But if the call site 05206 for this inlined function is on the same source line as 05207 we were previously stepping, go down into the function 05208 first. Otherwise stop at the call site. */ 05209 05210 if (call_sal.line == ecs->event_thread->current_line 05211 && call_sal.symtab == ecs->event_thread->current_symtab) 05212 step_into_inline_frame (ecs->ptid); 05213 05214 ecs->event_thread->control.stop_step = 1; 05215 print_end_stepping_range_reason (); 05216 stop_stepping (ecs); 05217 return; 05218 } 05219 else 05220 { 05221 /* For "next", we should stop at the call site if it is on a 05222 different source line. Otherwise continue through the 05223 inlined function. */ 05224 if (call_sal.line == ecs->event_thread->current_line 05225 && call_sal.symtab == ecs->event_thread->current_symtab) 05226 keep_going (ecs); 05227 else 05228 { 05229 ecs->event_thread->control.stop_step = 1; 05230 print_end_stepping_range_reason (); 05231 stop_stepping (ecs); 05232 } 05233 return; 05234 } 05235 } 05236 05237 /* Look for "calls" to inlined functions, part two. If we are still 05238 in the same real function we were stepping through, but we have 05239 to go further up to find the exact frame ID, we are stepping 05240 through a more inlined call beyond its call site. */ 05241 05242 if (get_frame_type (get_current_frame ()) == INLINE_FRAME 05243 && !frame_id_eq (get_frame_id (get_current_frame ()), 05244 ecs->event_thread->control.step_frame_id) 05245 && stepped_in_from (get_current_frame (), 05246 ecs->event_thread->control.step_frame_id)) 05247 { 05248 if (debug_infrun) 05249 fprintf_unfiltered (gdb_stdlog, 05250 "infrun: stepping through inlined function\n"); 05251 05252 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) 05253 keep_going (ecs); 05254 else 05255 { 05256 ecs->event_thread->control.stop_step = 1; 05257 print_end_stepping_range_reason (); 05258 stop_stepping (ecs); 05259 } 05260 return; 05261 } 05262 05263 if ((stop_pc == stop_pc_sal.pc) 05264 && (ecs->event_thread->current_line != stop_pc_sal.line 05265 || ecs->event_thread->current_symtab != stop_pc_sal.symtab)) 05266 { 05267 /* We are at the start of a different line. So stop. Note that 05268 we don't stop if we step into the middle of a different line. 05269 That is said to make things like for (;;) statements work 05270 better. */ 05271 if (debug_infrun) 05272 fprintf_unfiltered (gdb_stdlog, 05273 "infrun: stepped to a different line\n"); 05274 ecs->event_thread->control.stop_step = 1; 05275 print_end_stepping_range_reason (); 05276 stop_stepping (ecs); 05277 return; 05278 } 05279 05280 /* We aren't done stepping. 05281 05282 Optimize by setting the stepping range to the line. 05283 (We might not be in the original line, but if we entered a 05284 new line in mid-statement, we continue stepping. This makes 05285 things like for(;;) statements work better.) */ 05286 05287 ecs->event_thread->control.step_range_start = stop_pc_sal.pc; 05288 ecs->event_thread->control.step_range_end = stop_pc_sal.end; 05289 ecs->event_thread->control.may_range_step = 1; 05290 set_step_info (frame, stop_pc_sal); 05291 05292 if (debug_infrun) 05293 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); 05294 keep_going (ecs); 05295 } 05296 05297 /* Is thread TP in the middle of single-stepping? */ 05298 05299 static int 05300 currently_stepping (struct thread_info *tp) 05301 { 05302 return ((tp->control.step_range_end 05303 && tp->control.step_resume_breakpoint == NULL) 05304 || tp->control.trap_expected 05305 || bpstat_should_step ()); 05306 } 05307 05308 /* Returns true if any thread *but* the one passed in "data" is in the 05309 middle of stepping or of handling a "next". */ 05310 05311 static int 05312 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data) 05313 { 05314 if (tp == data) 05315 return 0; 05316 05317 return (tp->control.step_range_end 05318 || tp->control.trap_expected); 05319 } 05320 05321 /* Inferior has stepped into a subroutine call with source code that 05322 we should not step over. Do step to the first line of code in 05323 it. */ 05324 05325 static void 05326 handle_step_into_function (struct gdbarch *gdbarch, 05327 struct execution_control_state *ecs) 05328 { 05329 struct symtab *s; 05330 struct symtab_and_line stop_func_sal, sr_sal; 05331 05332 fill_in_stop_func (gdbarch, ecs); 05333 05334 s = find_pc_symtab (stop_pc); 05335 if (s && s->language != language_asm) 05336 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, 05337 ecs->stop_func_start); 05338 05339 stop_func_sal = find_pc_line (ecs->stop_func_start, 0); 05340 /* Use the step_resume_break to step until the end of the prologue, 05341 even if that involves jumps (as it seems to on the vax under 05342 4.2). */ 05343 /* If the prologue ends in the middle of a source line, continue to 05344 the end of that source line (if it is still within the function). 05345 Otherwise, just go to end of prologue. */ 05346 if (stop_func_sal.end 05347 && stop_func_sal.pc != ecs->stop_func_start 05348 && stop_func_sal.end < ecs->stop_func_end) 05349 ecs->stop_func_start = stop_func_sal.end; 05350 05351 /* Architectures which require breakpoint adjustment might not be able 05352 to place a breakpoint at the computed address. If so, the test 05353 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust 05354 ecs->stop_func_start to an address at which a breakpoint may be 05355 legitimately placed. 05356 05357 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not 05358 made, GDB will enter an infinite loop when stepping through 05359 optimized code consisting of VLIW instructions which contain 05360 subinstructions corresponding to different source lines. On 05361 FR-V, it's not permitted to place a breakpoint on any but the 05362 first subinstruction of a VLIW instruction. When a breakpoint is 05363 set, GDB will adjust the breakpoint address to the beginning of 05364 the VLIW instruction. Thus, we need to make the corresponding 05365 adjustment here when computing the stop address. */ 05366 05367 if (gdbarch_adjust_breakpoint_address_p (gdbarch)) 05368 { 05369 ecs->stop_func_start 05370 = gdbarch_adjust_breakpoint_address (gdbarch, 05371 ecs->stop_func_start); 05372 } 05373 05374 if (ecs->stop_func_start == stop_pc) 05375 { 05376 /* We are already there: stop now. */ 05377 ecs->event_thread->control.stop_step = 1; 05378 print_end_stepping_range_reason (); 05379 stop_stepping (ecs); 05380 return; 05381 } 05382 else 05383 { 05384 /* Put the step-breakpoint there and go until there. */ 05385 init_sal (&sr_sal); /* initialize to zeroes */ 05386 sr_sal.pc = ecs->stop_func_start; 05387 sr_sal.section = find_pc_overlay (ecs->stop_func_start); 05388 sr_sal.pspace = get_frame_program_space (get_current_frame ()); 05389 05390 /* Do not specify what the fp should be when we stop since on 05391 some machines the prologue is where the new fp value is 05392 established. */ 05393 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id); 05394 05395 /* And make sure stepping stops right away then. */ 05396 ecs->event_thread->control.step_range_end 05397 = ecs->event_thread->control.step_range_start; 05398 } 05399 keep_going (ecs); 05400 } 05401 05402 /* Inferior has stepped backward into a subroutine call with source 05403 code that we should not step over. Do step to the beginning of the 05404 last line of code in it. */ 05405 05406 static void 05407 handle_step_into_function_backward (struct gdbarch *gdbarch, 05408 struct execution_control_state *ecs) 05409 { 05410 struct symtab *s; 05411 struct symtab_and_line stop_func_sal; 05412 05413 fill_in_stop_func (gdbarch, ecs); 05414 05415 s = find_pc_symtab (stop_pc); 05416 if (s && s->language != language_asm) 05417 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, 05418 ecs->stop_func_start); 05419 05420 stop_func_sal = find_pc_line (stop_pc, 0); 05421 05422 /* OK, we're just going to keep stepping here. */ 05423 if (stop_func_sal.pc == stop_pc) 05424 { 05425 /* We're there already. Just stop stepping now. */ 05426 ecs->event_thread->control.stop_step = 1; 05427 print_end_stepping_range_reason (); 05428 stop_stepping (ecs); 05429 } 05430 else 05431 { 05432 /* Else just reset the step range and keep going. 05433 No step-resume breakpoint, they don't work for 05434 epilogues, which can have multiple entry paths. */ 05435 ecs->event_thread->control.step_range_start = stop_func_sal.pc; 05436 ecs->event_thread->control.step_range_end = stop_func_sal.end; 05437 keep_going (ecs); 05438 } 05439 return; 05440 } 05441 05442 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. 05443 This is used to both functions and to skip over code. */ 05444 05445 static void 05446 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch, 05447 struct symtab_and_line sr_sal, 05448 struct frame_id sr_id, 05449 enum bptype sr_type) 05450 { 05451 /* There should never be more than one step-resume or longjmp-resume 05452 breakpoint per thread, so we should never be setting a new 05453 step_resume_breakpoint when one is already active. */ 05454 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL); 05455 gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume); 05456 05457 if (debug_infrun) 05458 fprintf_unfiltered (gdb_stdlog, 05459 "infrun: inserting step-resume breakpoint at %s\n", 05460 paddress (gdbarch, sr_sal.pc)); 05461 05462 inferior_thread ()->control.step_resume_breakpoint 05463 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type); 05464 } 05465 05466 void 05467 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch, 05468 struct symtab_and_line sr_sal, 05469 struct frame_id sr_id) 05470 { 05471 insert_step_resume_breakpoint_at_sal_1 (gdbarch, 05472 sr_sal, sr_id, 05473 bp_step_resume); 05474 } 05475 05476 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc. 05477 This is used to skip a potential signal handler. 05478 05479 This is called with the interrupted function's frame. The signal 05480 handler, when it returns, will resume the interrupted function at 05481 RETURN_FRAME.pc. */ 05482 05483 static void 05484 insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame) 05485 { 05486 struct symtab_and_line sr_sal; 05487 struct gdbarch *gdbarch; 05488 05489 gdb_assert (return_frame != NULL); 05490 init_sal (&sr_sal); /* initialize to zeros */ 05491 05492 gdbarch = get_frame_arch (return_frame); 05493 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame)); 05494 sr_sal.section = find_pc_overlay (sr_sal.pc); 05495 sr_sal.pspace = get_frame_program_space (return_frame); 05496 05497 insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal, 05498 get_stack_frame_id (return_frame), 05499 bp_hp_step_resume); 05500 } 05501 05502 /* Insert a "step-resume breakpoint" at the previous frame's PC. This 05503 is used to skip a function after stepping into it (for "next" or if 05504 the called function has no debugging information). 05505 05506 The current function has almost always been reached by single 05507 stepping a call or return instruction. NEXT_FRAME belongs to the 05508 current function, and the breakpoint will be set at the caller's 05509 resume address. 05510 05511 This is a separate function rather than reusing 05512 insert_hp_step_resume_breakpoint_at_frame in order to avoid 05513 get_prev_frame, which may stop prematurely (see the implementation 05514 of frame_unwind_caller_id for an example). */ 05515 05516 static void 05517 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) 05518 { 05519 struct symtab_and_line sr_sal; 05520 struct gdbarch *gdbarch; 05521 05522 /* We shouldn't have gotten here if we don't know where the call site 05523 is. */ 05524 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame))); 05525 05526 init_sal (&sr_sal); /* initialize to zeros */ 05527 05528 gdbarch = frame_unwind_caller_arch (next_frame); 05529 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, 05530 frame_unwind_caller_pc (next_frame)); 05531 sr_sal.section = find_pc_overlay (sr_sal.pc); 05532 sr_sal.pspace = frame_unwind_program_space (next_frame); 05533 05534 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, 05535 frame_unwind_caller_id (next_frame)); 05536 } 05537 05538 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a 05539 new breakpoint at the target of a jmp_buf. The handling of 05540 longjmp-resume uses the same mechanisms used for handling 05541 "step-resume" breakpoints. */ 05542 05543 static void 05544 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) 05545 { 05546 /* There should never be more than one longjmp-resume breakpoint per 05547 thread, so we should never be setting a new 05548 longjmp_resume_breakpoint when one is already active. */ 05549 gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL); 05550 05551 if (debug_infrun) 05552 fprintf_unfiltered (gdb_stdlog, 05553 "infrun: inserting longjmp-resume breakpoint at %s\n", 05554 paddress (gdbarch, pc)); 05555 05556 inferior_thread ()->control.exception_resume_breakpoint = 05557 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume); 05558 } 05559 05560 /* Insert an exception resume breakpoint. TP is the thread throwing 05561 the exception. The block B is the block of the unwinder debug hook 05562 function. FRAME is the frame corresponding to the call to this 05563 function. SYM is the symbol of the function argument holding the 05564 target PC of the exception. */ 05565 05566 static void 05567 insert_exception_resume_breakpoint (struct thread_info *tp, 05568 struct block *b, 05569 struct frame_info *frame, 05570 struct symbol *sym) 05571 { 05572 volatile struct gdb_exception e; 05573 05574 /* We want to ignore errors here. */ 05575 TRY_CATCH (e, RETURN_MASK_ERROR) 05576 { 05577 struct symbol *vsym; 05578 struct value *value; 05579 CORE_ADDR handler; 05580 struct breakpoint *bp; 05581 05582 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL); 05583 value = read_var_value (vsym, frame); 05584 /* If the value was optimized out, revert to the old behavior. */ 05585 if (! value_optimized_out (value)) 05586 { 05587 handler = value_as_address (value); 05588 05589 if (debug_infrun) 05590 fprintf_unfiltered (gdb_stdlog, 05591 "infrun: exception resume at %lx\n", 05592 (unsigned long) handler); 05593 05594 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), 05595 handler, bp_exception_resume); 05596 05597 /* set_momentary_breakpoint_at_pc invalidates FRAME. */ 05598 frame = NULL; 05599 05600 bp->thread = tp->num; 05601 inferior_thread ()->control.exception_resume_breakpoint = bp; 05602 } 05603 } 05604 } 05605 05606 /* A helper for check_exception_resume that sets an 05607 exception-breakpoint based on a SystemTap probe. */ 05608 05609 static void 05610 insert_exception_resume_from_probe (struct thread_info *tp, 05611 const struct probe *probe, 05612 struct frame_info *frame) 05613 { 05614 struct value *arg_value; 05615 CORE_ADDR handler; 05616 struct breakpoint *bp; 05617 05618 arg_value = probe_safe_evaluate_at_pc (frame, 1); 05619 if (!arg_value) 05620 return; 05621 05622 handler = value_as_address (arg_value); 05623 05624 if (debug_infrun) 05625 fprintf_unfiltered (gdb_stdlog, 05626 "infrun: exception resume at %s\n", 05627 paddress (get_objfile_arch (probe->objfile), 05628 handler)); 05629 05630 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), 05631 handler, bp_exception_resume); 05632 bp->thread = tp->num; 05633 inferior_thread ()->control.exception_resume_breakpoint = bp; 05634 } 05635 05636 /* This is called when an exception has been intercepted. Check to 05637 see whether the exception's destination is of interest, and if so, 05638 set an exception resume breakpoint there. */ 05639 05640 static void 05641 check_exception_resume (struct execution_control_state *ecs, 05642 struct frame_info *frame) 05643 { 05644 volatile struct gdb_exception e; 05645 const struct probe *probe; 05646 struct symbol *func; 05647 05648 /* First see if this exception unwinding breakpoint was set via a 05649 SystemTap probe point. If so, the probe has two arguments: the 05650 CFA and the HANDLER. We ignore the CFA, extract the handler, and 05651 set a breakpoint there. */ 05652 probe = find_probe_by_pc (get_frame_pc (frame)); 05653 if (probe) 05654 { 05655 insert_exception_resume_from_probe (ecs->event_thread, probe, frame); 05656 return; 05657 } 05658 05659 func = get_frame_function (frame); 05660 if (!func) 05661 return; 05662 05663 TRY_CATCH (e, RETURN_MASK_ERROR) 05664 { 05665 struct block *b; 05666 struct block_iterator iter; 05667 struct symbol *sym; 05668 int argno = 0; 05669 05670 /* The exception breakpoint is a thread-specific breakpoint on 05671 the unwinder's debug hook, declared as: 05672 05673 void _Unwind_DebugHook (void *cfa, void *handler); 05674 05675 The CFA argument indicates the frame to which control is 05676 about to be transferred. HANDLER is the destination PC. 05677 05678 We ignore the CFA and set a temporary breakpoint at HANDLER. 05679 This is not extremely efficient but it avoids issues in gdb 05680 with computing the DWARF CFA, and it also works even in weird 05681 cases such as throwing an exception from inside a signal 05682 handler. */ 05683 05684 b = SYMBOL_BLOCK_VALUE (func); 05685 ALL_BLOCK_SYMBOLS (b, iter, sym) 05686 { 05687 if (!SYMBOL_IS_ARGUMENT (sym)) 05688 continue; 05689 05690 if (argno == 0) 05691 ++argno; 05692 else 05693 { 05694 insert_exception_resume_breakpoint (ecs->event_thread, 05695 b, frame, sym); 05696 break; 05697 } 05698 } 05699 } 05700 } 05701 05702 static void 05703 stop_stepping (struct execution_control_state *ecs) 05704 { 05705 if (debug_infrun) 05706 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n"); 05707 05708 /* Let callers know we don't want to wait for the inferior anymore. */ 05709 ecs->wait_some_more = 0; 05710 } 05711 05712 /* This function handles various cases where we need to continue 05713 waiting for the inferior. */ 05714 /* (Used to be the keep_going: label in the old wait_for_inferior). */ 05715 05716 static void 05717 keep_going (struct execution_control_state *ecs) 05718 { 05719 /* Make sure normal_stop is called if we get a QUIT handled before 05720 reaching resume. */ 05721 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); 05722 05723 /* Save the pc before execution, to compare with pc after stop. */ 05724 ecs->event_thread->prev_pc 05725 = regcache_read_pc (get_thread_regcache (ecs->ptid)); 05726 05727 /* If we did not do break;, it means we should keep running the 05728 inferior and not return to debugger. */ 05729 05730 if (ecs->event_thread->control.trap_expected 05731 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP) 05732 { 05733 /* We took a signal (which we are supposed to pass through to 05734 the inferior, else we'd not get here) and we haven't yet 05735 gotten our trap. Simply continue. */ 05736 05737 discard_cleanups (old_cleanups); 05738 resume (currently_stepping (ecs->event_thread), 05739 ecs->event_thread->suspend.stop_signal); 05740 } 05741 else 05742 { 05743 /* Either the trap was not expected, but we are continuing 05744 anyway (the user asked that this signal be passed to the 05745 child) 05746 -- or -- 05747 The signal was SIGTRAP, e.g. it was our signal, but we 05748 decided we should resume from it. 05749 05750 We're going to run this baby now! 05751 05752 Note that insert_breakpoints won't try to re-insert 05753 already inserted breakpoints. Therefore, we don't 05754 care if breakpoints were already inserted, or not. */ 05755 05756 if (ecs->event_thread->stepping_over_breakpoint) 05757 { 05758 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid); 05759 05760 if (!use_displaced_stepping (get_regcache_arch (thread_regcache))) 05761 /* Since we can't do a displaced step, we have to remove 05762 the breakpoint while we step it. To keep things 05763 simple, we remove them all. */ 05764 remove_breakpoints (); 05765 } 05766 else 05767 { 05768 volatile struct gdb_exception e; 05769 05770 /* Stop stepping when inserting breakpoints 05771 has failed. */ 05772 TRY_CATCH (e, RETURN_MASK_ERROR) 05773 { 05774 insert_breakpoints (); 05775 } 05776 if (e.reason < 0) 05777 { 05778 exception_print (gdb_stderr, e); 05779 stop_stepping (ecs); 05780 return; 05781 } 05782 } 05783 05784 ecs->event_thread->control.trap_expected 05785 = ecs->event_thread->stepping_over_breakpoint; 05786 05787 /* Do not deliver SIGNAL_TRAP (except when the user explicitly 05788 specifies that such a signal should be delivered to the 05789 target program). 05790 05791 Typically, this would occure when a user is debugging a 05792 target monitor on a simulator: the target monitor sets a 05793 breakpoint; the simulator encounters this break-point and 05794 halts the simulation handing control to GDB; GDB, noteing 05795 that the break-point isn't valid, returns control back to the 05796 simulator; the simulator then delivers the hardware 05797 equivalent of a SIGNAL_TRAP to the program being debugged. */ 05798 05799 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP 05800 && !signal_program[ecs->event_thread->suspend.stop_signal]) 05801 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0; 05802 05803 discard_cleanups (old_cleanups); 05804 resume (currently_stepping (ecs->event_thread), 05805 ecs->event_thread->suspend.stop_signal); 05806 } 05807 05808 prepare_to_wait (ecs); 05809 } 05810 05811 /* This function normally comes after a resume, before 05812 handle_inferior_event exits. It takes care of any last bits of 05813 housekeeping, and sets the all-important wait_some_more flag. */ 05814 05815 static void 05816 prepare_to_wait (struct execution_control_state *ecs) 05817 { 05818 if (debug_infrun) 05819 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); 05820 05821 /* This is the old end of the while loop. Let everybody know we 05822 want to wait for the inferior some more and get called again 05823 soon. */ 05824 ecs->wait_some_more = 1; 05825 } 05826 05827 /* Several print_*_reason functions to print why the inferior has stopped. 05828 We always print something when the inferior exits, or receives a signal. 05829 The rest of the cases are dealt with later on in normal_stop and 05830 print_it_typical. Ideally there should be a call to one of these 05831 print_*_reason functions functions from handle_inferior_event each time 05832 stop_stepping is called. */ 05833 05834 /* Print why the inferior has stopped. 05835 We are done with a step/next/si/ni command, print why the inferior has 05836 stopped. For now print nothing. Print a message only if not in the middle 05837 of doing a "step n" operation for n > 1. */ 05838 05839 static void 05840 print_end_stepping_range_reason (void) 05841 { 05842 if ((!inferior_thread ()->step_multi 05843 || !inferior_thread ()->control.stop_step) 05844 && ui_out_is_mi_like_p (current_uiout)) 05845 ui_out_field_string (current_uiout, "reason", 05846 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); 05847 } 05848 05849 /* The inferior was terminated by a signal, print why it stopped. */ 05850 05851 static void 05852 print_signal_exited_reason (enum gdb_signal siggnal) 05853 { 05854 struct ui_out *uiout = current_uiout; 05855 05856 annotate_signalled (); 05857 if (ui_out_is_mi_like_p (uiout)) 05858 ui_out_field_string 05859 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); 05860 ui_out_text (uiout, "\nProgram terminated with signal "); 05861 annotate_signal_name (); 05862 ui_out_field_string (uiout, "signal-name", 05863 gdb_signal_to_name (siggnal)); 05864 annotate_signal_name_end (); 05865 ui_out_text (uiout, ", "); 05866 annotate_signal_string (); 05867 ui_out_field_string (uiout, "signal-meaning", 05868 gdb_signal_to_string (siggnal)); 05869 annotate_signal_string_end (); 05870 ui_out_text (uiout, ".\n"); 05871 ui_out_text (uiout, "The program no longer exists.\n"); 05872 } 05873 05874 /* The inferior program is finished, print why it stopped. */ 05875 05876 static void 05877 print_exited_reason (int exitstatus) 05878 { 05879 struct inferior *inf = current_inferior (); 05880 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid)); 05881 struct ui_out *uiout = current_uiout; 05882 05883 annotate_exited (exitstatus); 05884 if (exitstatus) 05885 { 05886 if (ui_out_is_mi_like_p (uiout)) 05887 ui_out_field_string (uiout, "reason", 05888 async_reason_lookup (EXEC_ASYNC_EXITED)); 05889 ui_out_text (uiout, "[Inferior "); 05890 ui_out_text (uiout, plongest (inf->num)); 05891 ui_out_text (uiout, " ("); 05892 ui_out_text (uiout, pidstr); 05893 ui_out_text (uiout, ") exited with code "); 05894 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus); 05895 ui_out_text (uiout, "]\n"); 05896 } 05897 else 05898 { 05899 if (ui_out_is_mi_like_p (uiout)) 05900 ui_out_field_string 05901 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); 05902 ui_out_text (uiout, "[Inferior "); 05903 ui_out_text (uiout, plongest (inf->num)); 05904 ui_out_text (uiout, " ("); 05905 ui_out_text (uiout, pidstr); 05906 ui_out_text (uiout, ") exited normally]\n"); 05907 } 05908 /* Support the --return-child-result option. */ 05909 return_child_result_value = exitstatus; 05910 } 05911 05912 /* Signal received, print why the inferior has stopped. The signal table 05913 tells us to print about it. */ 05914 05915 static void 05916 print_signal_received_reason (enum gdb_signal siggnal) 05917 { 05918 struct ui_out *uiout = current_uiout; 05919 05920 annotate_signal (); 05921 05922 if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout)) 05923 { 05924 struct thread_info *t = inferior_thread (); 05925 05926 ui_out_text (uiout, "\n["); 05927 ui_out_field_string (uiout, "thread-name", 05928 target_pid_to_str (t->ptid)); 05929 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num); 05930 ui_out_text (uiout, " stopped"); 05931 } 05932 else 05933 { 05934 ui_out_text (uiout, "\nProgram received signal "); 05935 annotate_signal_name (); 05936 if (ui_out_is_mi_like_p (uiout)) 05937 ui_out_field_string 05938 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); 05939 ui_out_field_string (uiout, "signal-name", 05940 gdb_signal_to_name (siggnal)); 05941 annotate_signal_name_end (); 05942 ui_out_text (uiout, ", "); 05943 annotate_signal_string (); 05944 ui_out_field_string (uiout, "signal-meaning", 05945 gdb_signal_to_string (siggnal)); 05946 annotate_signal_string_end (); 05947 } 05948 ui_out_text (uiout, ".\n"); 05949 } 05950 05951 /* Reverse execution: target ran out of history info, print why the inferior 05952 has stopped. */ 05953 05954 static void 05955 print_no_history_reason (void) 05956 { 05957 ui_out_text (current_uiout, "\nNo more reverse-execution history.\n"); 05958 } 05959 05960 /* Here to return control to GDB when the inferior stops for real. 05961 Print appropriate messages, remove breakpoints, give terminal our modes. 05962 05963 STOP_PRINT_FRAME nonzero means print the executing frame 05964 (pc, function, args, file, line number and line text). 05965 BREAKPOINTS_FAILED nonzero means stop was due to error 05966 attempting to insert breakpoints. */ 05967 05968 void 05969 normal_stop (void) 05970 { 05971 struct target_waitstatus last; 05972 ptid_t last_ptid; 05973 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); 05974 05975 get_last_target_status (&last_ptid, &last); 05976 05977 /* If an exception is thrown from this point on, make sure to 05978 propagate GDB's knowledge of the executing state to the 05979 frontend/user running state. A QUIT is an easy exception to see 05980 here, so do this before any filtered output. */ 05981 if (!non_stop) 05982 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); 05983 else if (last.kind != TARGET_WAITKIND_SIGNALLED 05984 && last.kind != TARGET_WAITKIND_EXITED 05985 && last.kind != TARGET_WAITKIND_NO_RESUMED) 05986 make_cleanup (finish_thread_state_cleanup, &inferior_ptid); 05987 05988 /* In non-stop mode, we don't want GDB to switch threads behind the 05989 user's back, to avoid races where the user is typing a command to 05990 apply to thread x, but GDB switches to thread y before the user 05991 finishes entering the command. */ 05992 05993 /* As with the notification of thread events, we want to delay 05994 notifying the user that we've switched thread context until 05995 the inferior actually stops. 05996 05997 There's no point in saying anything if the inferior has exited. 05998 Note that SIGNALLED here means "exited with a signal", not 05999 "received a signal". */ 06000 if (!non_stop 06001 && !ptid_equal (previous_inferior_ptid, inferior_ptid) 06002 && target_has_execution 06003 && last.kind != TARGET_WAITKIND_SIGNALLED 06004 && last.kind != TARGET_WAITKIND_EXITED 06005 && last.kind != TARGET_WAITKIND_NO_RESUMED) 06006 { 06007 target_terminal_ours_for_output (); 06008 printf_filtered (_("[Switching to %s]\n"), 06009 target_pid_to_str (inferior_ptid)); 06010 annotate_thread_changed (); 06011 previous_inferior_ptid = inferior_ptid; 06012 } 06013 06014 if (last.kind == TARGET_WAITKIND_NO_RESUMED) 06015 { 06016 gdb_assert (sync_execution || !target_can_async_p ()); 06017 06018 target_terminal_ours_for_output (); 06019 printf_filtered (_("No unwaited-for children left.\n")); 06020 } 06021 06022 if (!breakpoints_always_inserted_mode () && target_has_execution) 06023 { 06024 if (remove_breakpoints ()) 06025 { 06026 target_terminal_ours_for_output (); 06027 printf_filtered (_("Cannot remove breakpoints because " 06028 "program is no longer writable.\nFurther " 06029 "execution is probably impossible.\n")); 06030 } 06031 } 06032 06033 /* If an auto-display called a function and that got a signal, 06034 delete that auto-display to avoid an infinite recursion. */ 06035 06036 if (stopped_by_random_signal) 06037 disable_current_display (); 06038 06039 /* Don't print a message if in the middle of doing a "step n" 06040 operation for n > 1 */ 06041 if (target_has_execution 06042 && last.kind != TARGET_WAITKIND_SIGNALLED 06043 && last.kind != TARGET_WAITKIND_EXITED 06044 && inferior_thread ()->step_multi 06045 && inferior_thread ()->control.stop_step) 06046 goto done; 06047 06048 target_terminal_ours (); 06049 async_enable_stdin (); 06050 06051 /* Set the current source location. This will also happen if we 06052 display the frame below, but the current SAL will be incorrect 06053 during a user hook-stop function. */ 06054 if (has_stack_frames () && !stop_stack_dummy) 06055 set_current_sal_from_frame (get_current_frame (), 1); 06056 06057 /* Let the user/frontend see the threads as stopped. */ 06058 do_cleanups (old_chain); 06059 06060 /* Look up the hook_stop and run it (CLI internally handles problem 06061 of stop_command's pre-hook not existing). */ 06062 if (stop_command) 06063 catch_errors (hook_stop_stub, stop_command, 06064 "Error while running hook_stop:\n", RETURN_MASK_ALL); 06065 06066 if (!has_stack_frames ()) 06067 goto done; 06068 06069 if (last.kind == TARGET_WAITKIND_SIGNALLED 06070 || last.kind == TARGET_WAITKIND_EXITED) 06071 goto done; 06072 06073 /* Select innermost stack frame - i.e., current frame is frame 0, 06074 and current location is based on that. 06075 Don't do this on return from a stack dummy routine, 06076 or if the program has exited. */ 06077 06078 if (!stop_stack_dummy) 06079 { 06080 select_frame (get_current_frame ()); 06081 06082 /* Print current location without a level number, if 06083 we have changed functions or hit a breakpoint. 06084 Print source line if we have one. 06085 bpstat_print() contains the logic deciding in detail 06086 what to print, based on the event(s) that just occurred. */ 06087 06088 /* If --batch-silent is enabled then there's no need to print the current 06089 source location, and to try risks causing an error message about 06090 missing source files. */ 06091 if (stop_print_frame && !batch_silent) 06092 { 06093 int bpstat_ret; 06094 int source_flag; 06095 int do_frame_printing = 1; 06096 struct thread_info *tp = inferior_thread (); 06097 06098 bpstat_ret = bpstat_print (tp->control.stop_bpstat, last.kind); 06099 switch (bpstat_ret) 06100 { 06101 case PRINT_UNKNOWN: 06102 /* FIXME: cagney/2002-12-01: Given that a frame ID does 06103 (or should) carry around the function and does (or 06104 should) use that when doing a frame comparison. */ 06105 if (tp->control.stop_step 06106 && frame_id_eq (tp->control.step_frame_id, 06107 get_frame_id (get_current_frame ())) 06108 && step_start_function == find_pc_function (stop_pc)) 06109 source_flag = SRC_LINE; /* Finished step, just 06110 print source line. */ 06111 else 06112 source_flag = SRC_AND_LOC; /* Print location and 06113 source line. */ 06114 break; 06115 case PRINT_SRC_AND_LOC: 06116 source_flag = SRC_AND_LOC; /* Print location and 06117 source line. */ 06118 break; 06119 case PRINT_SRC_ONLY: 06120 source_flag = SRC_LINE; 06121 break; 06122 case PRINT_NOTHING: 06123 source_flag = SRC_LINE; /* something bogus */ 06124 do_frame_printing = 0; 06125 break; 06126 default: 06127 internal_error (__FILE__, __LINE__, _("Unknown value.")); 06128 } 06129 06130 /* The behavior of this routine with respect to the source 06131 flag is: 06132 SRC_LINE: Print only source line 06133 LOCATION: Print only location 06134 SRC_AND_LOC: Print location and source line. */ 06135 if (do_frame_printing) 06136 print_stack_frame (get_selected_frame (NULL), 0, source_flag, 1); 06137 06138 /* Display the auto-display expressions. */ 06139 do_displays (); 06140 } 06141 } 06142 06143 /* Save the function value return registers, if we care. 06144 We might be about to restore their previous contents. */ 06145 if (inferior_thread ()->control.proceed_to_finish 06146 && execution_direction != EXEC_REVERSE) 06147 { 06148 /* This should not be necessary. */ 06149 if (stop_registers) 06150 regcache_xfree (stop_registers); 06151 06152 /* NB: The copy goes through to the target picking up the value of 06153 all the registers. */ 06154 stop_registers = regcache_dup (get_current_regcache ()); 06155 } 06156 06157 if (stop_stack_dummy == STOP_STACK_DUMMY) 06158 { 06159 /* Pop the empty frame that contains the stack dummy. 06160 This also restores inferior state prior to the call 06161 (struct infcall_suspend_state). */ 06162 struct frame_info *frame = get_current_frame (); 06163 06164 gdb_assert (get_frame_type (frame) == DUMMY_FRAME); 06165 frame_pop (frame); 06166 /* frame_pop() calls reinit_frame_cache as the last thing it 06167 does which means there's currently no selected frame. We 06168 don't need to re-establish a selected frame if the dummy call 06169 returns normally, that will be done by 06170 restore_infcall_control_state. However, we do have to handle 06171 the case where the dummy call is returning after being 06172 stopped (e.g. the dummy call previously hit a breakpoint). 06173 We can't know which case we have so just always re-establish 06174 a selected frame here. */ 06175 select_frame (get_current_frame ()); 06176 } 06177 06178 done: 06179 annotate_stopped (); 06180 06181 /* Suppress the stop observer if we're in the middle of: 06182 06183 - a step n (n > 1), as there still more steps to be done. 06184 06185 - a "finish" command, as the observer will be called in 06186 finish_command_continuation, so it can include the inferior 06187 function's return value. 06188 06189 - calling an inferior function, as we pretend we inferior didn't 06190 run at all. The return value of the call is handled by the 06191 expression evaluator, through call_function_by_hand. */ 06192 06193 if (!target_has_execution 06194 || last.kind == TARGET_WAITKIND_SIGNALLED 06195 || last.kind == TARGET_WAITKIND_EXITED 06196 || last.kind == TARGET_WAITKIND_NO_RESUMED 06197 || (!(inferior_thread ()->step_multi 06198 && inferior_thread ()->control.stop_step) 06199 && !(inferior_thread ()->control.stop_bpstat 06200 && inferior_thread ()->control.proceed_to_finish) 06201 && !inferior_thread ()->control.in_infcall)) 06202 { 06203 if (!ptid_equal (inferior_ptid, null_ptid)) 06204 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat, 06205 stop_print_frame); 06206 else 06207 observer_notify_normal_stop (NULL, stop_print_frame); 06208 } 06209 06210 if (target_has_execution) 06211 { 06212 if (last.kind != TARGET_WAITKIND_SIGNALLED 06213 && last.kind != TARGET_WAITKIND_EXITED) 06214 /* Delete the breakpoint we stopped at, if it wants to be deleted. 06215 Delete any breakpoint that is to be deleted at the next stop. */ 06216 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat); 06217 } 06218 06219 /* Try to get rid of automatically added inferiors that are no 06220 longer needed. Keeping those around slows down things linearly. 06221 Note that this never removes the current inferior. */ 06222 prune_inferiors (); 06223 } 06224 06225 static int 06226 hook_stop_stub (void *cmd) 06227 { 06228 execute_cmd_pre_hook ((struct cmd_list_element *) cmd); 06229 return (0); 06230 } 06231 06232 int 06233 signal_stop_state (int signo) 06234 { 06235 return signal_stop[signo]; 06236 } 06237 06238 int 06239 signal_print_state (int signo) 06240 { 06241 return signal_print[signo]; 06242 } 06243 06244 int 06245 signal_pass_state (int signo) 06246 { 06247 return signal_program[signo]; 06248 } 06249 06250 static void 06251 signal_cache_update (int signo) 06252 { 06253 if (signo == -1) 06254 { 06255 for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++) 06256 signal_cache_update (signo); 06257 06258 return; 06259 } 06260 06261 signal_pass[signo] = (signal_stop[signo] == 0 06262 && signal_print[signo] == 0 06263 && signal_program[signo] == 1 06264 && signal_catch[signo] == 0); 06265 } 06266 06267 int 06268 signal_stop_update (int signo, int state) 06269 { 06270 int ret = signal_stop[signo]; 06271 06272 signal_stop[signo] = state; 06273 signal_cache_update (signo); 06274 return ret; 06275 } 06276 06277 int 06278 signal_print_update (int signo, int state) 06279 { 06280 int ret = signal_print[signo]; 06281 06282 signal_print[signo] = state; 06283 signal_cache_update (signo); 06284 return ret; 06285 } 06286 06287 int 06288 signal_pass_update (int signo, int state) 06289 { 06290 int ret = signal_program[signo]; 06291 06292 signal_program[signo] = state; 06293 signal_cache_update (signo); 06294 return ret; 06295 } 06296 06297 /* Update the global 'signal_catch' from INFO and notify the 06298 target. */ 06299 06300 void 06301 signal_catch_update (const unsigned int *info) 06302 { 06303 int i; 06304 06305 for (i = 0; i < GDB_SIGNAL_LAST; ++i) 06306 signal_catch[i] = info[i] > 0; 06307 signal_cache_update (-1); 06308 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass); 06309 } 06310 06311 static void 06312 sig_print_header (void) 06313 { 06314 printf_filtered (_("Signal Stop\tPrint\tPass " 06315 "to program\tDescription\n")); 06316 } 06317 06318 static void 06319 sig_print_info (enum gdb_signal oursig) 06320 { 06321 const char *name = gdb_signal_to_name (oursig); 06322 int name_padding = 13 - strlen (name); 06323 06324 if (name_padding <= 0) 06325 name_padding = 0; 06326 06327 printf_filtered ("%s", name); 06328 printf_filtered ("%*.*s ", name_padding, name_padding, " "); 06329 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); 06330 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); 06331 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); 06332 printf_filtered ("%s\n", gdb_signal_to_string (oursig)); 06333 } 06334 06335 /* Specify how various signals in the inferior should be handled. */ 06336 06337 static void 06338 handle_command (char *args, int from_tty) 06339 { 06340 char **argv; 06341 int digits, wordlen; 06342 int sigfirst, signum, siglast; 06343 enum gdb_signal oursig; 06344 int allsigs; 06345 int nsigs; 06346 unsigned char *sigs; 06347 struct cleanup *old_chain; 06348 06349 if (args == NULL) 06350 { 06351 error_no_arg (_("signal to handle")); 06352 } 06353 06354 /* Allocate and zero an array of flags for which signals to handle. */ 06355 06356 nsigs = (int) GDB_SIGNAL_LAST; 06357 sigs = (unsigned char *) alloca (nsigs); 06358 memset (sigs, 0, nsigs); 06359 06360 /* Break the command line up into args. */ 06361 06362 argv = gdb_buildargv (args); 06363 old_chain = make_cleanup_freeargv (argv); 06364 06365 /* Walk through the args, looking for signal oursigs, signal names, and 06366 actions. Signal numbers and signal names may be interspersed with 06367 actions, with the actions being performed for all signals cumulatively 06368 specified. Signal ranges can be specified as <LOW>-<HIGH>. */ 06369 06370 while (*argv != NULL) 06371 { 06372 wordlen = strlen (*argv); 06373 for (digits = 0; isdigit ((*argv)[digits]); digits++) 06374 {; 06375 } 06376 allsigs = 0; 06377 sigfirst = siglast = -1; 06378 06379 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) 06380 { 06381 /* Apply action to all signals except those used by the 06382 debugger. Silently skip those. */ 06383 allsigs = 1; 06384 sigfirst = 0; 06385 siglast = nsigs - 1; 06386 } 06387 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) 06388 { 06389 SET_SIGS (nsigs, sigs, signal_stop); 06390 SET_SIGS (nsigs, sigs, signal_print); 06391 } 06392 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) 06393 { 06394 UNSET_SIGS (nsigs, sigs, signal_program); 06395 } 06396 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) 06397 { 06398 SET_SIGS (nsigs, sigs, signal_print); 06399 } 06400 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) 06401 { 06402 SET_SIGS (nsigs, sigs, signal_program); 06403 } 06404 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) 06405 { 06406 UNSET_SIGS (nsigs, sigs, signal_stop); 06407 } 06408 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) 06409 { 06410 SET_SIGS (nsigs, sigs, signal_program); 06411 } 06412 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) 06413 { 06414 UNSET_SIGS (nsigs, sigs, signal_print); 06415 UNSET_SIGS (nsigs, sigs, signal_stop); 06416 } 06417 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) 06418 { 06419 UNSET_SIGS (nsigs, sigs, signal_program); 06420 } 06421 else if (digits > 0) 06422 { 06423 /* It is numeric. The numeric signal refers to our own 06424 internal signal numbering from target.h, not to host/target 06425 signal number. This is a feature; users really should be 06426 using symbolic names anyway, and the common ones like 06427 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ 06428 06429 sigfirst = siglast = (int) 06430 gdb_signal_from_command (atoi (*argv)); 06431 if ((*argv)[digits] == '-') 06432 { 06433 siglast = (int) 06434 gdb_signal_from_command (atoi ((*argv) + digits + 1)); 06435 } 06436 if (sigfirst > siglast) 06437 { 06438 /* Bet he didn't figure we'd think of this case... */ 06439 signum = sigfirst; 06440 sigfirst = siglast; 06441 siglast = signum; 06442 } 06443 } 06444 else 06445 { 06446 oursig = gdb_signal_from_name (*argv); 06447 if (oursig != GDB_SIGNAL_UNKNOWN) 06448 { 06449 sigfirst = siglast = (int) oursig; 06450 } 06451 else 06452 { 06453 /* Not a number and not a recognized flag word => complain. */ 06454 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); 06455 } 06456 } 06457 06458 /* If any signal numbers or symbol names were found, set flags for 06459 which signals to apply actions to. */ 06460 06461 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) 06462 { 06463 switch ((enum gdb_signal) signum) 06464 { 06465 case GDB_SIGNAL_TRAP: 06466 case GDB_SIGNAL_INT: 06467 if (!allsigs && !sigs[signum]) 06468 { 06469 if (query (_("%s is used by the debugger.\n\ 06470 Are you sure you want to change it? "), 06471 gdb_signal_to_name ((enum gdb_signal) signum))) 06472 { 06473 sigs[signum] = 1; 06474 } 06475 else 06476 { 06477 printf_unfiltered (_("Not confirmed, unchanged.\n")); 06478 gdb_flush (gdb_stdout); 06479 } 06480 } 06481 break; 06482 case GDB_SIGNAL_0: 06483 case GDB_SIGNAL_DEFAULT: 06484 case GDB_SIGNAL_UNKNOWN: 06485 /* Make sure that "all" doesn't print these. */ 06486 break; 06487 default: 06488 sigs[signum] = 1; 06489 break; 06490 } 06491 } 06492 06493 argv++; 06494 } 06495 06496 for (signum = 0; signum < nsigs; signum++) 06497 if (sigs[signum]) 06498 { 06499 signal_cache_update (-1); 06500 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass); 06501 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program); 06502 06503 if (from_tty) 06504 { 06505 /* Show the results. */ 06506 sig_print_header (); 06507 for (; signum < nsigs; signum++) 06508 if (sigs[signum]) 06509 sig_print_info (signum); 06510 } 06511 06512 break; 06513 } 06514 06515 do_cleanups (old_chain); 06516 } 06517 06518 /* Complete the "handle" command. */ 06519 06520 static VEC (char_ptr) * 06521 handle_completer (struct cmd_list_element *ignore, 06522 const char *text, const char *word) 06523 { 06524 VEC (char_ptr) *vec_signals, *vec_keywords, *return_val; 06525 static const char * const keywords[] = 06526 { 06527 "all", 06528 "stop", 06529 "ignore", 06530 "print", 06531 "pass", 06532 "nostop", 06533 "noignore", 06534 "noprint", 06535 "nopass", 06536 NULL, 06537 }; 06538 06539 vec_signals = signal_completer (ignore, text, word); 06540 vec_keywords = complete_on_enum (keywords, word, word); 06541 06542 return_val = VEC_merge (char_ptr, vec_signals, vec_keywords); 06543 VEC_free (char_ptr, vec_signals); 06544 VEC_free (char_ptr, vec_keywords); 06545 return return_val; 06546 } 06547 06548 static void 06549 xdb_handle_command (char *args, int from_tty) 06550 { 06551 char **argv; 06552 struct cleanup *old_chain; 06553 06554 if (args == NULL) 06555 error_no_arg (_("xdb command")); 06556 06557 /* Break the command line up into args. */ 06558 06559 argv = gdb_buildargv (args); 06560 old_chain = make_cleanup_freeargv (argv); 06561 if (argv[1] != (char *) NULL) 06562 { 06563 char *argBuf; 06564 int bufLen; 06565 06566 bufLen = strlen (argv[0]) + 20; 06567 argBuf = (char *) xmalloc (bufLen); 06568 if (argBuf) 06569 { 06570 int validFlag = 1; 06571 enum gdb_signal oursig; 06572 06573 oursig = gdb_signal_from_name (argv[0]); 06574 memset (argBuf, 0, bufLen); 06575 if (strcmp (argv[1], "Q") == 0) 06576 sprintf (argBuf, "%s %s", argv[0], "noprint"); 06577 else 06578 { 06579 if (strcmp (argv[1], "s") == 0) 06580 { 06581 if (!signal_stop[oursig]) 06582 sprintf (argBuf, "%s %s", argv[0], "stop"); 06583 else 06584 sprintf (argBuf, "%s %s", argv[0], "nostop"); 06585 } 06586 else if (strcmp (argv[1], "i") == 0) 06587 { 06588 if (!signal_program[oursig]) 06589 sprintf (argBuf, "%s %s", argv[0], "pass"); 06590 else 06591 sprintf (argBuf, "%s %s", argv[0], "nopass"); 06592 } 06593 else if (strcmp (argv[1], "r") == 0) 06594 { 06595 if (!signal_print[oursig]) 06596 sprintf (argBuf, "%s %s", argv[0], "print"); 06597 else 06598 sprintf (argBuf, "%s %s", argv[0], "noprint"); 06599 } 06600 else 06601 validFlag = 0; 06602 } 06603 if (validFlag) 06604 handle_command (argBuf, from_tty); 06605 else 06606 printf_filtered (_("Invalid signal handling flag.\n")); 06607 if (argBuf) 06608 xfree (argBuf); 06609 } 06610 } 06611 do_cleanups (old_chain); 06612 } 06613 06614 enum gdb_signal 06615 gdb_signal_from_command (int num) 06616 { 06617 if (num >= 1 && num <= 15) 06618 return (enum gdb_signal) num; 06619 error (_("Only signals 1-15 are valid as numeric signals.\n\ 06620 Use \"info signals\" for a list of symbolic signals.")); 06621 } 06622 06623 /* Print current contents of the tables set by the handle command. 06624 It is possible we should just be printing signals actually used 06625 by the current target (but for things to work right when switching 06626 targets, all signals should be in the signal tables). */ 06627 06628 static void 06629 signals_info (char *signum_exp, int from_tty) 06630 { 06631 enum gdb_signal oursig; 06632 06633 sig_print_header (); 06634 06635 if (signum_exp) 06636 { 06637 /* First see if this is a symbol name. */ 06638 oursig = gdb_signal_from_name (signum_exp); 06639 if (oursig == GDB_SIGNAL_UNKNOWN) 06640 { 06641 /* No, try numeric. */ 06642 oursig = 06643 gdb_signal_from_command (parse_and_eval_long (signum_exp)); 06644 } 06645 sig_print_info (oursig); 06646 return; 06647 } 06648 06649 printf_filtered ("\n"); 06650 /* These ugly casts brought to you by the native VAX compiler. */ 06651 for (oursig = GDB_SIGNAL_FIRST; 06652 (int) oursig < (int) GDB_SIGNAL_LAST; 06653 oursig = (enum gdb_signal) ((int) oursig + 1)) 06654 { 06655 QUIT; 06656 06657 if (oursig != GDB_SIGNAL_UNKNOWN 06658 && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0) 06659 sig_print_info (oursig); 06660 } 06661 06662 printf_filtered (_("\nUse the \"handle\" command " 06663 "to change these tables.\n")); 06664 } 06665 06666 /* Check if it makes sense to read $_siginfo from the current thread 06667 at this point. If not, throw an error. */ 06668 06669 static void 06670 validate_siginfo_access (void) 06671 { 06672 /* No current inferior, no siginfo. */ 06673 if (ptid_equal (inferior_ptid, null_ptid)) 06674 error (_("No thread selected.")); 06675 06676 /* Don't try to read from a dead thread. */ 06677 if (is_exited (inferior_ptid)) 06678 error (_("The current thread has terminated")); 06679 06680 /* ... or from a spinning thread. */ 06681 if (is_running (inferior_ptid)) 06682 error (_("Selected thread is running.")); 06683 } 06684 06685 /* The $_siginfo convenience variable is a bit special. We don't know 06686 for sure the type of the value until we actually have a chance to 06687 fetch the data. The type can change depending on gdbarch, so it is 06688 also dependent on which thread you have selected. 06689 06690 1. making $_siginfo be an internalvar that creates a new value on 06691 access. 06692 06693 2. making the value of $_siginfo be an lval_computed value. */ 06694 06695 /* This function implements the lval_computed support for reading a 06696 $_siginfo value. */ 06697 06698 static void 06699 siginfo_value_read (struct value *v) 06700 { 06701 LONGEST transferred; 06702 06703 validate_siginfo_access (); 06704 06705 transferred = 06706 target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, 06707 NULL, 06708 value_contents_all_raw (v), 06709 value_offset (v), 06710 TYPE_LENGTH (value_type (v))); 06711 06712 if (transferred != TYPE_LENGTH (value_type (v))) 06713 error (_("Unable to read siginfo")); 06714 } 06715 06716 /* This function implements the lval_computed support for writing a 06717 $_siginfo value. */ 06718 06719 static void 06720 siginfo_value_write (struct value *v, struct value *fromval) 06721 { 06722 LONGEST transferred; 06723 06724 validate_siginfo_access (); 06725 06726 transferred = target_write (¤t_target, 06727 TARGET_OBJECT_SIGNAL_INFO, 06728 NULL, 06729 value_contents_all_raw (fromval), 06730 value_offset (v), 06731 TYPE_LENGTH (value_type (fromval))); 06732 06733 if (transferred != TYPE_LENGTH (value_type (fromval))) 06734 error (_("Unable to write siginfo")); 06735 } 06736 06737 static const struct lval_funcs siginfo_value_funcs = 06738 { 06739 siginfo_value_read, 06740 siginfo_value_write 06741 }; 06742 06743 /* Return a new value with the correct type for the siginfo object of 06744 the current thread using architecture GDBARCH. Return a void value 06745 if there's no object available. */ 06746 06747 static struct value * 06748 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var, 06749 void *ignore) 06750 { 06751 if (target_has_stack 06752 && !ptid_equal (inferior_ptid, null_ptid) 06753 && gdbarch_get_siginfo_type_p (gdbarch)) 06754 { 06755 struct type *type = gdbarch_get_siginfo_type (gdbarch); 06756 06757 return allocate_computed_value (type, &siginfo_value_funcs, NULL); 06758 } 06759 06760 return allocate_value (builtin_type (gdbarch)->builtin_void); 06761 } 06762 06763 06764 /* infcall_suspend_state contains state about the program itself like its 06765 registers and any signal it received when it last stopped. 06766 This state must be restored regardless of how the inferior function call 06767 ends (either successfully, or after it hits a breakpoint or signal) 06768 if the program is to properly continue where it left off. */ 06769 06770 struct infcall_suspend_state 06771 { 06772 struct thread_suspend_state thread_suspend; 06773 #if 0 /* Currently unused and empty structures are not valid C. */ 06774 struct inferior_suspend_state inferior_suspend; 06775 #endif 06776 06777 /* Other fields: */ 06778 CORE_ADDR stop_pc; 06779 struct regcache *registers; 06780 06781 /* Format of SIGINFO_DATA or NULL if it is not present. */ 06782 struct gdbarch *siginfo_gdbarch; 06783 06784 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of 06785 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the 06786 content would be invalid. */ 06787 gdb_byte *siginfo_data; 06788 }; 06789 06790 struct infcall_suspend_state * 06791 save_infcall_suspend_state (void) 06792 { 06793 struct infcall_suspend_state *inf_state; 06794 struct thread_info *tp = inferior_thread (); 06795 #if 0 06796 struct inferior *inf = current_inferior (); 06797 #endif 06798 struct regcache *regcache = get_current_regcache (); 06799 struct gdbarch *gdbarch = get_regcache_arch (regcache); 06800 gdb_byte *siginfo_data = NULL; 06801 06802 if (gdbarch_get_siginfo_type_p (gdbarch)) 06803 { 06804 struct type *type = gdbarch_get_siginfo_type (gdbarch); 06805 size_t len = TYPE_LENGTH (type); 06806 struct cleanup *back_to; 06807 06808 siginfo_data = xmalloc (len); 06809 back_to = make_cleanup (xfree, siginfo_data); 06810 06811 if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, 06812 siginfo_data, 0, len) == len) 06813 discard_cleanups (back_to); 06814 else 06815 { 06816 /* Errors ignored. */ 06817 do_cleanups (back_to); 06818 siginfo_data = NULL; 06819 } 06820 } 06821 06822 inf_state = XZALLOC (struct infcall_suspend_state); 06823 06824 if (siginfo_data) 06825 { 06826 inf_state->siginfo_gdbarch = gdbarch; 06827 inf_state->siginfo_data = siginfo_data; 06828 } 06829 06830 inf_state->thread_suspend = tp->suspend; 06831 #if 0 /* Currently unused and empty structures are not valid C. */ 06832 inf_state->inferior_suspend = inf->suspend; 06833 #endif 06834 06835 /* run_inferior_call will not use the signal due to its `proceed' call with 06836 GDB_SIGNAL_0 anyway. */ 06837 tp->suspend.stop_signal = GDB_SIGNAL_0; 06838 06839 inf_state->stop_pc = stop_pc; 06840 06841 inf_state->registers = regcache_dup (regcache); 06842 06843 return inf_state; 06844 } 06845 06846 /* Restore inferior session state to INF_STATE. */ 06847 06848 void 06849 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state) 06850 { 06851 struct thread_info *tp = inferior_thread (); 06852 #if 0 06853 struct inferior *inf = current_inferior (); 06854 #endif 06855 struct regcache *regcache = get_current_regcache (); 06856 struct gdbarch *gdbarch = get_regcache_arch (regcache); 06857 06858 tp->suspend = inf_state->thread_suspend; 06859 #if 0 /* Currently unused and empty structures are not valid C. */ 06860 inf->suspend = inf_state->inferior_suspend; 06861 #endif 06862 06863 stop_pc = inf_state->stop_pc; 06864 06865 if (inf_state->siginfo_gdbarch == gdbarch) 06866 { 06867 struct type *type = gdbarch_get_siginfo_type (gdbarch); 06868 06869 /* Errors ignored. */ 06870 target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, 06871 inf_state->siginfo_data, 0, TYPE_LENGTH (type)); 06872 } 06873 06874 /* The inferior can be gone if the user types "print exit(0)" 06875 (and perhaps other times). */ 06876 if (target_has_execution) 06877 /* NB: The register write goes through to the target. */ 06878 regcache_cpy (regcache, inf_state->registers); 06879 06880 discard_infcall_suspend_state (inf_state); 06881 } 06882 06883 static void 06884 do_restore_infcall_suspend_state_cleanup (void *state) 06885 { 06886 restore_infcall_suspend_state (state); 06887 } 06888 06889 struct cleanup * 06890 make_cleanup_restore_infcall_suspend_state 06891 (struct infcall_suspend_state *inf_state) 06892 { 06893 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state); 06894 } 06895 06896 void 06897 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) 06898 { 06899 regcache_xfree (inf_state->registers); 06900 xfree (inf_state->siginfo_data); 06901 xfree (inf_state); 06902 } 06903 06904 struct regcache * 06905 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state) 06906 { 06907 return inf_state->registers; 06908 } 06909 06910 /* infcall_control_state contains state regarding gdb's control of the 06911 inferior itself like stepping control. It also contains session state like 06912 the user's currently selected frame. */ 06913 06914 struct infcall_control_state 06915 { 06916 struct thread_control_state thread_control; 06917 struct inferior_control_state inferior_control; 06918 06919 /* Other fields: */ 06920 enum stop_stack_kind stop_stack_dummy; 06921 int stopped_by_random_signal; 06922 int stop_after_trap; 06923 06924 /* ID if the selected frame when the inferior function call was made. */ 06925 struct frame_id selected_frame_id; 06926 }; 06927 06928 /* Save all of the information associated with the inferior<==>gdb 06929 connection. */ 06930 06931 struct infcall_control_state * 06932 save_infcall_control_state (void) 06933 { 06934 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status)); 06935 struct thread_info *tp = inferior_thread (); 06936 struct inferior *inf = current_inferior (); 06937 06938 inf_status->thread_control = tp->control; 06939 inf_status->inferior_control = inf->control; 06940 06941 tp->control.step_resume_breakpoint = NULL; 06942 tp->control.exception_resume_breakpoint = NULL; 06943 06944 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of 06945 chain. If caller's caller is walking the chain, they'll be happier if we 06946 hand them back the original chain when restore_infcall_control_state is 06947 called. */ 06948 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat); 06949 06950 /* Other fields: */ 06951 inf_status->stop_stack_dummy = stop_stack_dummy; 06952 inf_status->stopped_by_random_signal = stopped_by_random_signal; 06953 inf_status->stop_after_trap = stop_after_trap; 06954 06955 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); 06956 06957 return inf_status; 06958 } 06959 06960 static int 06961 restore_selected_frame (void *args) 06962 { 06963 struct frame_id *fid = (struct frame_id *) args; 06964 struct frame_info *frame; 06965 06966 frame = frame_find_by_id (*fid); 06967 06968 /* If inf_status->selected_frame_id is NULL, there was no previously 06969 selected frame. */ 06970 if (frame == NULL) 06971 { 06972 warning (_("Unable to restore previously selected frame.")); 06973 return 0; 06974 } 06975 06976 select_frame (frame); 06977 06978 return (1); 06979 } 06980 06981 /* Restore inferior session state to INF_STATUS. */ 06982 06983 void 06984 restore_infcall_control_state (struct infcall_control_state *inf_status) 06985 { 06986 struct thread_info *tp = inferior_thread (); 06987 struct inferior *inf = current_inferior (); 06988 06989 if (tp->control.step_resume_breakpoint) 06990 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop; 06991 06992 if (tp->control.exception_resume_breakpoint) 06993 tp->control.exception_resume_breakpoint->disposition 06994 = disp_del_at_next_stop; 06995 06996 /* Handle the bpstat_copy of the chain. */ 06997 bpstat_clear (&tp->control.stop_bpstat); 06998 06999 tp->control = inf_status->thread_control; 07000 inf->control = inf_status->inferior_control; 07001 07002 /* Other fields: */ 07003 stop_stack_dummy = inf_status->stop_stack_dummy; 07004 stopped_by_random_signal = inf_status->stopped_by_random_signal; 07005 stop_after_trap = inf_status->stop_after_trap; 07006 07007 if (target_has_stack) 07008 { 07009 /* The point of catch_errors is that if the stack is clobbered, 07010 walking the stack might encounter a garbage pointer and 07011 error() trying to dereference it. */ 07012 if (catch_errors 07013 (restore_selected_frame, &inf_status->selected_frame_id, 07014 "Unable to restore previously selected frame:\n", 07015 RETURN_MASK_ERROR) == 0) 07016 /* Error in restoring the selected frame. Select the innermost 07017 frame. */ 07018 select_frame (get_current_frame ()); 07019 } 07020 07021 xfree (inf_status); 07022 } 07023 07024 static void 07025 do_restore_infcall_control_state_cleanup (void *sts) 07026 { 07027 restore_infcall_control_state (sts); 07028 } 07029 07030 struct cleanup * 07031 make_cleanup_restore_infcall_control_state 07032 (struct infcall_control_state *inf_status) 07033 { 07034 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status); 07035 } 07036 07037 void 07038 discard_infcall_control_state (struct infcall_control_state *inf_status) 07039 { 07040 if (inf_status->thread_control.step_resume_breakpoint) 07041 inf_status->thread_control.step_resume_breakpoint->disposition 07042 = disp_del_at_next_stop; 07043 07044 if (inf_status->thread_control.exception_resume_breakpoint) 07045 inf_status->thread_control.exception_resume_breakpoint->disposition 07046 = disp_del_at_next_stop; 07047 07048 /* See save_infcall_control_state for info on stop_bpstat. */ 07049 bpstat_clear (&inf_status->thread_control.stop_bpstat); 07050 07051 xfree (inf_status); 07052 } 07053 07054 int 07055 ptid_match (ptid_t ptid, ptid_t filter) 07056 { 07057 if (ptid_equal (filter, minus_one_ptid)) 07058 return 1; 07059 if (ptid_is_pid (filter) 07060 && ptid_get_pid (ptid) == ptid_get_pid (filter)) 07061 return 1; 07062 else if (ptid_equal (ptid, filter)) 07063 return 1; 07064 07065 return 0; 07066 } 07067 07068 /* restore_inferior_ptid() will be used by the cleanup machinery 07069 to restore the inferior_ptid value saved in a call to 07070 save_inferior_ptid(). */ 07071 07072 static void 07073 restore_inferior_ptid (void *arg) 07074 { 07075 ptid_t *saved_ptid_ptr = arg; 07076 07077 inferior_ptid = *saved_ptid_ptr; 07078 xfree (arg); 07079 } 07080 07081 /* Save the value of inferior_ptid so that it may be restored by a 07082 later call to do_cleanups(). Returns the struct cleanup pointer 07083 needed for later doing the cleanup. */ 07084 07085 struct cleanup * 07086 save_inferior_ptid (void) 07087 { 07088 ptid_t *saved_ptid_ptr; 07089 07090 saved_ptid_ptr = xmalloc (sizeof (ptid_t)); 07091 *saved_ptid_ptr = inferior_ptid; 07092 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); 07093 } 07094 07095 /* See inferior.h. */ 07096 07097 void 07098 clear_exit_convenience_vars (void) 07099 { 07100 clear_internalvar (lookup_internalvar ("_exitsignal")); 07101 clear_internalvar (lookup_internalvar ("_exitcode")); 07102 } 07103 07104 07105 /* User interface for reverse debugging: 07106 Set exec-direction / show exec-direction commands 07107 (returns error unless target implements to_set_exec_direction method). */ 07108 07109 int execution_direction = EXEC_FORWARD; 07110 static const char exec_forward[] = "forward"; 07111 static const char exec_reverse[] = "reverse"; 07112 static const char *exec_direction = exec_forward; 07113 static const char *const exec_direction_names[] = { 07114 exec_forward, 07115 exec_reverse, 07116 NULL 07117 }; 07118 07119 static void 07120 set_exec_direction_func (char *args, int from_tty, 07121 struct cmd_list_element *cmd) 07122 { 07123 if (target_can_execute_reverse) 07124 { 07125 if (!strcmp (exec_direction, exec_forward)) 07126 execution_direction = EXEC_FORWARD; 07127 else if (!strcmp (exec_direction, exec_reverse)) 07128 execution_direction = EXEC_REVERSE; 07129 } 07130 else 07131 { 07132 exec_direction = exec_forward; 07133 error (_("Target does not support this operation.")); 07134 } 07135 } 07136 07137 static void 07138 show_exec_direction_func (struct ui_file *out, int from_tty, 07139 struct cmd_list_element *cmd, const char *value) 07140 { 07141 switch (execution_direction) { 07142 case EXEC_FORWARD: 07143 fprintf_filtered (out, _("Forward.\n")); 07144 break; 07145 case EXEC_REVERSE: 07146 fprintf_filtered (out, _("Reverse.\n")); 07147 break; 07148 default: 07149 internal_error (__FILE__, __LINE__, 07150 _("bogus execution_direction value: %d"), 07151 (int) execution_direction); 07152 } 07153 } 07154 07155 static void 07156 show_schedule_multiple (struct ui_file *file, int from_tty, 07157 struct cmd_list_element *c, const char *value) 07158 { 07159 fprintf_filtered (file, _("Resuming the execution of threads " 07160 "of all processes is %s.\n"), value); 07161 } 07162 07163 /* Implementation of `siginfo' variable. */ 07164 07165 static const struct internalvar_funcs siginfo_funcs = 07166 { 07167 siginfo_make_value, 07168 NULL, 07169 NULL 07170 }; 07171 07172 void 07173 _initialize_infrun (void) 07174 { 07175 int i; 07176 int numsigs; 07177 struct cmd_list_element *c; 07178 07179 add_info ("signals", signals_info, _("\ 07180 What debugger does when program gets various signals.\n\ 07181 Specify a signal as argument to print info on that signal only.")); 07182 add_info_alias ("handle", "signals", 0); 07183 07184 c = add_com ("handle", class_run, handle_command, _("\ 07185 Specify how to handle signals.\n\ 07186 Usage: handle SIGNAL [ACTIONS]\n\ 07187 Args are signals and actions to apply to those signals.\n\ 07188 If no actions are specified, the current settings for the specified signals\n\ 07189 will be displayed instead.\n\ 07190 \n\ 07191 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ 07192 from 1-15 are allowed for compatibility with old versions of GDB.\n\ 07193 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ 07194 The special arg \"all\" is recognized to mean all signals except those\n\ 07195 used by the debugger, typically SIGTRAP and SIGINT.\n\ 07196 \n\ 07197 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ 07198 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ 07199 Stop means reenter debugger if this signal happens (implies print).\n\ 07200 Print means print a message if this signal happens.\n\ 07201 Pass means let program see this signal; otherwise program doesn't know.\n\ 07202 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ 07203 Pass and Stop may be combined.\n\ 07204 \n\ 07205 Multiple signals may be specified. Signal numbers and signal names\n\ 07206 may be interspersed with actions, with the actions being performed for\n\ 07207 all signals cumulatively specified.")); 07208 set_cmd_completer (c, handle_completer); 07209 07210 if (xdb_commands) 07211 { 07212 add_com ("lz", class_info, signals_info, _("\ 07213 What debugger does when program gets various signals.\n\ 07214 Specify a signal as argument to print info on that signal only.")); 07215 add_com ("z", class_run, xdb_handle_command, _("\ 07216 Specify how to handle a signal.\n\ 07217 Args are signals and actions to apply to those signals.\n\ 07218 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ 07219 from 1-15 are allowed for compatibility with old versions of GDB.\n\ 07220 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ 07221 The special arg \"all\" is recognized to mean all signals except those\n\ 07222 used by the debugger, typically SIGTRAP and SIGINT.\n\ 07223 Recognized actions include \"s\" (toggles between stop and nostop),\n\ 07224 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ 07225 nopass), \"Q\" (noprint)\n\ 07226 Stop means reenter debugger if this signal happens (implies print).\n\ 07227 Print means print a message if this signal happens.\n\ 07228 Pass means let program see this signal; otherwise program doesn't know.\n\ 07229 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ 07230 Pass and Stop may be combined.")); 07231 } 07232 07233 if (!dbx_commands) 07234 stop_command = add_cmd ("stop", class_obscure, 07235 not_just_help_class_command, _("\ 07236 There is no `stop' command, but you can set a hook on `stop'.\n\ 07237 This allows you to set a list of commands to be run each time execution\n\ 07238 of the program stops."), &cmdlist); 07239 07240 add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ 07241 Set inferior debugging."), _("\ 07242 Show inferior debugging."), _("\ 07243 When non-zero, inferior specific debugging is enabled."), 07244 NULL, 07245 show_debug_infrun, 07246 &setdebuglist, &showdebuglist); 07247 07248 add_setshow_boolean_cmd ("displaced", class_maintenance, 07249 &debug_displaced, _("\ 07250 Set displaced stepping debugging."), _("\ 07251 Show displaced stepping debugging."), _("\ 07252 When non-zero, displaced stepping specific debugging is enabled."), 07253 NULL, 07254 show_debug_displaced, 07255 &setdebuglist, &showdebuglist); 07256 07257 add_setshow_boolean_cmd ("non-stop", no_class, 07258 &non_stop_1, _("\ 07259 Set whether gdb controls the inferior in non-stop mode."), _("\ 07260 Show whether gdb controls the inferior in non-stop mode."), _("\ 07261 When debugging a multi-threaded program and this setting is\n\ 07262 off (the default, also called all-stop mode), when one thread stops\n\ 07263 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\ 07264 all other threads in the program while you interact with the thread of\n\ 07265 interest. When you continue or step a thread, you can allow the other\n\ 07266 threads to run, or have them remain stopped, but while you inspect any\n\ 07267 thread's state, all threads stop.\n\ 07268 \n\ 07269 In non-stop mode, when one thread stops, other threads can continue\n\ 07270 to run freely. You'll be able to step each thread independently,\n\ 07271 leave it stopped or free to run as needed."), 07272 set_non_stop, 07273 show_non_stop, 07274 &setlist, 07275 &showlist); 07276 07277 numsigs = (int) GDB_SIGNAL_LAST; 07278 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); 07279 signal_print = (unsigned char *) 07280 xmalloc (sizeof (signal_print[0]) * numsigs); 07281 signal_program = (unsigned char *) 07282 xmalloc (sizeof (signal_program[0]) * numsigs); 07283 signal_catch = (unsigned char *) 07284 xmalloc (sizeof (signal_catch[0]) * numsigs); 07285 signal_pass = (unsigned char *) 07286 xmalloc (sizeof (signal_program[0]) * numsigs); 07287 for (i = 0; i < numsigs; i++) 07288 { 07289 signal_stop[i] = 1; 07290 signal_print[i] = 1; 07291 signal_program[i] = 1; 07292 signal_catch[i] = 0; 07293 } 07294 07295 /* Signals caused by debugger's own actions 07296 should not be given to the program afterwards. */ 07297 signal_program[GDB_SIGNAL_TRAP] = 0; 07298 signal_program[GDB_SIGNAL_INT] = 0; 07299 07300 /* Signals that are not errors should not normally enter the debugger. */ 07301 signal_stop[GDB_SIGNAL_ALRM] = 0; 07302 signal_print[GDB_SIGNAL_ALRM] = 0; 07303 signal_stop[GDB_SIGNAL_VTALRM] = 0; 07304 signal_print[GDB_SIGNAL_VTALRM] = 0; 07305 signal_stop[GDB_SIGNAL_PROF] = 0; 07306 signal_print[GDB_SIGNAL_PROF] = 0; 07307 signal_stop[GDB_SIGNAL_CHLD] = 0; 07308 signal_print[GDB_SIGNAL_CHLD] = 0; 07309 signal_stop[GDB_SIGNAL_IO] = 0; 07310 signal_print[GDB_SIGNAL_IO] = 0; 07311 signal_stop[GDB_SIGNAL_POLL] = 0; 07312 signal_print[GDB_SIGNAL_POLL] = 0; 07313 signal_stop[GDB_SIGNAL_URG] = 0; 07314 signal_print[GDB_SIGNAL_URG] = 0; 07315 signal_stop[GDB_SIGNAL_WINCH] = 0; 07316 signal_print[GDB_SIGNAL_WINCH] = 0; 07317 signal_stop[GDB_SIGNAL_PRIO] = 0; 07318 signal_print[GDB_SIGNAL_PRIO] = 0; 07319 07320 /* These signals are used internally by user-level thread 07321 implementations. (See signal(5) on Solaris.) Like the above 07322 signals, a healthy program receives and handles them as part of 07323 its normal operation. */ 07324 signal_stop[GDB_SIGNAL_LWP] = 0; 07325 signal_print[GDB_SIGNAL_LWP] = 0; 07326 signal_stop[GDB_SIGNAL_WAITING] = 0; 07327 signal_print[GDB_SIGNAL_WAITING] = 0; 07328 signal_stop[GDB_SIGNAL_CANCEL] = 0; 07329 signal_print[GDB_SIGNAL_CANCEL] = 0; 07330 07331 /* Update cached state. */ 07332 signal_cache_update (-1); 07333 07334 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, 07335 &stop_on_solib_events, _("\ 07336 Set stopping for shared library events."), _("\ 07337 Show stopping for shared library events."), _("\ 07338 If nonzero, gdb will give control to the user when the dynamic linker\n\ 07339 notifies gdb of shared library events. The most common event of interest\n\ 07340 to the user would be loading/unloading of a new library."), 07341 set_stop_on_solib_events, 07342 show_stop_on_solib_events, 07343 &setlist, &showlist); 07344 07345 add_setshow_enum_cmd ("follow-fork-mode", class_run, 07346 follow_fork_mode_kind_names, 07347 &follow_fork_mode_string, _("\ 07348 Set debugger response to a program call of fork or vfork."), _("\ 07349 Show debugger response to a program call of fork or vfork."), _("\ 07350 A fork or vfork creates a new process. follow-fork-mode can be:\n\ 07351 parent - the original process is debugged after a fork\n\ 07352 child - the new process is debugged after a fork\n\ 07353 The unfollowed process will continue to run.\n\ 07354 By default, the debugger will follow the parent process."), 07355 NULL, 07356 show_follow_fork_mode_string, 07357 &setlist, &showlist); 07358 07359 add_setshow_enum_cmd ("follow-exec-mode", class_run, 07360 follow_exec_mode_names, 07361 &follow_exec_mode_string, _("\ 07362 Set debugger response to a program call of exec."), _("\ 07363 Show debugger response to a program call of exec."), _("\ 07364 An exec call replaces the program image of a process.\n\ 07365 \n\ 07366 follow-exec-mode can be:\n\ 07367 \n\ 07368 new - the debugger creates a new inferior and rebinds the process\n\ 07369 to this new inferior. The program the process was running before\n\ 07370 the exec call can be restarted afterwards by restarting the original\n\ 07371 inferior.\n\ 07372 \n\ 07373 same - the debugger keeps the process bound to the same inferior.\n\ 07374 The new executable image replaces the previous executable loaded in\n\ 07375 the inferior. Restarting the inferior after the exec call restarts\n\ 07376 the executable the process was running after the exec call.\n\ 07377 \n\ 07378 By default, the debugger will use the same inferior."), 07379 NULL, 07380 show_follow_exec_mode_string, 07381 &setlist, &showlist); 07382 07383 add_setshow_enum_cmd ("scheduler-locking", class_run, 07384 scheduler_enums, &scheduler_mode, _("\ 07385 Set mode for locking scheduler during execution."), _("\ 07386 Show mode for locking scheduler during execution."), _("\ 07387 off == no locking (threads may preempt at any time)\n\ 07388 on == full locking (no thread except the current thread may run)\n\ 07389 step == scheduler locked during every single-step operation.\n\ 07390 In this mode, no other thread may run during a step command.\n\ 07391 Other threads may run while stepping over a function call ('next')."), 07392 set_schedlock_func, /* traps on target vector */ 07393 show_scheduler_mode, 07394 &setlist, &showlist); 07395 07396 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\ 07397 Set mode for resuming threads of all processes."), _("\ 07398 Show mode for resuming threads of all processes."), _("\ 07399 When on, execution commands (such as 'continue' or 'next') resume all\n\ 07400 threads of all processes. When off (which is the default), execution\n\ 07401 commands only resume the threads of the current process. The set of\n\ 07402 threads that are resumed is further refined by the scheduler-locking\n\ 07403 mode (see help set scheduler-locking)."), 07404 NULL, 07405 show_schedule_multiple, 07406 &setlist, &showlist); 07407 07408 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ 07409 Set mode of the step operation."), _("\ 07410 Show mode of the step operation."), _("\ 07411 When set, doing a step over a function without debug line information\n\ 07412 will stop at the first instruction of that function. Otherwise, the\n\ 07413 function is skipped and the step command stops at a different source line."), 07414 NULL, 07415 show_step_stop_if_no_debug, 07416 &setlist, &showlist); 07417 07418 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run, 07419 &can_use_displaced_stepping, _("\ 07420 Set debugger's willingness to use displaced stepping."), _("\ 07421 Show debugger's willingness to use displaced stepping."), _("\ 07422 If on, gdb will use displaced stepping to step over breakpoints if it is\n\ 07423 supported by the target architecture. If off, gdb will not use displaced\n\ 07424 stepping to step over breakpoints, even if such is supported by the target\n\ 07425 architecture. If auto (which is the default), gdb will use displaced stepping\n\ 07426 if the target architecture supports it and non-stop mode is active, but will not\n\ 07427 use it in all-stop mode (see help set non-stop)."), 07428 NULL, 07429 show_can_use_displaced_stepping, 07430 &setlist, &showlist); 07431 07432 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names, 07433 &exec_direction, _("Set direction of execution.\n\ 07434 Options are 'forward' or 'reverse'."), 07435 _("Show direction of execution (forward/reverse)."), 07436 _("Tells gdb whether to execute forward or backward."), 07437 set_exec_direction_func, show_exec_direction_func, 07438 &setlist, &showlist); 07439 07440 /* Set/show detach-on-fork: user-settable mode. */ 07441 07442 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\ 07443 Set whether gdb will detach the child of a fork."), _("\ 07444 Show whether gdb will detach the child of a fork."), _("\ 07445 Tells gdb whether to detach the child of a fork."), 07446 NULL, NULL, &setlist, &showlist); 07447 07448 /* Set/show disable address space randomization mode. */ 07449 07450 add_setshow_boolean_cmd ("disable-randomization", class_support, 07451 &disable_randomization, _("\ 07452 Set disabling of debuggee's virtual address space randomization."), _("\ 07453 Show disabling of debuggee's virtual address space randomization."), _("\ 07454 When this mode is on (which is the default), randomization of the virtual\n\ 07455 address space is disabled. Standalone programs run with the randomization\n\ 07456 enabled by default on some platforms."), 07457 &set_disable_randomization, 07458 &show_disable_randomization, 07459 &setlist, &showlist); 07460 07461 /* ptid initializations */ 07462 inferior_ptid = null_ptid; 07463 target_last_wait_ptid = minus_one_ptid; 07464 07465 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed); 07466 observer_attach_thread_stop_requested (infrun_thread_stop_requested); 07467 observer_attach_thread_exit (infrun_thread_thread_exit); 07468 observer_attach_inferior_exit (infrun_inferior_exit); 07469 07470 /* Explicitly create without lookup, since that tries to create a 07471 value with a void typed value, and when we get here, gdbarch 07472 isn't initialized yet. At this point, we're quite sure there 07473 isn't another convenience variable of the same name. */ 07474 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL); 07475 07476 add_setshow_boolean_cmd ("observer", no_class, 07477 &observer_mode_1, _("\ 07478 Set whether gdb controls the inferior in observer mode."), _("\ 07479 Show whether gdb controls the inferior in observer mode."), _("\ 07480 In observer mode, GDB can get data from the inferior, but not\n\ 07481 affect its execution. Registers and memory may not be changed,\n\ 07482 breakpoints may not be set, and the program cannot be interrupted\n\ 07483 or signalled."), 07484 set_observer_mode, 07485 show_observer_mode, 07486 &setlist, 07487 &showlist); 07488 }