1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
6 2008 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
49 #include "gdb_assert.h"
50 #include "mi/mi-common.h"
51 #include "event-top.h"
53 /* Prototypes for local functions */
55 static void signals_info (char *, int);
57 static void handle_command (char *, int);
59 static void sig_print_info (enum target_signal);
61 static void sig_print_header (void);
63 static void resume_cleanups (void *);
65 static int hook_stop_stub (void *);
67 static int restore_selected_frame (void *);
69 static void build_infrun (void);
71 static int follow_fork (void);
73 static void set_schedlock_func (char *args, int from_tty,
74 struct cmd_list_element *c);
76 static int currently_stepping (struct thread_info *tp);
78 static void xdb_handle_command (char *args, int from_tty);
80 static int prepare_to_proceed (int);
82 void _initialize_infrun (void);
84 /* When set, stop the 'step' command if we enter a function which has
85 no line number information. The normal behavior is that we step
86 over such function. */
87 int step_stop_if_no_debug = 0;
89 show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
90 struct cmd_list_element *c, const char *value)
92 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
95 /* In asynchronous mode, but simulating synchronous execution. */
97 int sync_execution = 0;
99 /* wait_for_inferior and normal_stop use this to notify the user
100 when the inferior stopped in a different thread than it had been
103 static ptid_t previous_inferior_ptid;
105 int debug_displaced = 0;
107 show_debug_displaced (struct ui_file *file, int from_tty,
108 struct cmd_list_element *c, const char *value)
110 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
113 static int debug_infrun = 0;
115 show_debug_infrun (struct ui_file *file, int from_tty,
116 struct cmd_list_element *c, const char *value)
118 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
121 /* If the program uses ELF-style shared libraries, then calls to
122 functions in shared libraries go through stubs, which live in a
123 table called the PLT (Procedure Linkage Table). The first time the
124 function is called, the stub sends control to the dynamic linker,
125 which looks up the function's real address, patches the stub so
126 that future calls will go directly to the function, and then passes
127 control to the function.
129 If we are stepping at the source level, we don't want to see any of
130 this --- we just want to skip over the stub and the dynamic linker.
131 The simple approach is to single-step until control leaves the
134 However, on some systems (e.g., Red Hat's 5.2 distribution) the
135 dynamic linker calls functions in the shared C library, so you
136 can't tell from the PC alone whether the dynamic linker is still
137 running. In this case, we use a step-resume breakpoint to get us
138 past the dynamic linker, as if we were using "next" to step over a
141 in_solib_dynsym_resolve_code() says whether we're in the dynamic
142 linker code or not. Normally, this means we single-step. However,
143 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
144 address where we can place a step-resume breakpoint to get past the
145 linker's symbol resolution function.
147 in_solib_dynsym_resolve_code() can generally be implemented in a
148 pretty portable way, by comparing the PC against the address ranges
149 of the dynamic linker's sections.
151 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
152 it depends on internal details of the dynamic linker. It's usually
153 not too hard to figure out where to put a breakpoint, but it
154 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
155 sanity checking. If it can't figure things out, returning zero and
156 getting the (possibly confusing) stepping behavior is better than
157 signalling an error, which will obscure the change in the
160 /* This function returns TRUE if pc is the address of an instruction
161 that lies within the dynamic linker (such as the event hook, or the
164 This function must be used only when a dynamic linker event has
165 been caught, and the inferior is being stepped out of the hook, or
166 undefined results are guaranteed. */
168 #ifndef SOLIB_IN_DYNAMIC_LINKER
169 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
173 /* Convert the #defines into values. This is temporary until wfi control
174 flow is completely sorted out. */
176 #ifndef CANNOT_STEP_HW_WATCHPOINTS
177 #define CANNOT_STEP_HW_WATCHPOINTS 0
179 #undef CANNOT_STEP_HW_WATCHPOINTS
180 #define CANNOT_STEP_HW_WATCHPOINTS 1
183 /* Tables of how to react to signals; the user sets them. */
185 static unsigned char *signal_stop;
186 static unsigned char *signal_print;
187 static unsigned char *signal_program;
189 #define SET_SIGS(nsigs,sigs,flags) \
191 int signum = (nsigs); \
192 while (signum-- > 0) \
193 if ((sigs)[signum]) \
194 (flags)[signum] = 1; \
197 #define UNSET_SIGS(nsigs,sigs,flags) \
199 int signum = (nsigs); \
200 while (signum-- > 0) \
201 if ((sigs)[signum]) \
202 (flags)[signum] = 0; \
205 /* Value to pass to target_resume() to cause all threads to resume */
207 #define RESUME_ALL (pid_to_ptid (-1))
209 /* Command list pointer for the "stop" placeholder. */
211 static struct cmd_list_element *stop_command;
213 /* Function inferior was in as of last step command. */
215 static struct symbol *step_start_function;
217 /* Nonzero if we want to give control to the user when we're notified
218 of shared library events by the dynamic linker. */
219 static int stop_on_solib_events;
221 show_stop_on_solib_events (struct ui_file *file, int from_tty,
222 struct cmd_list_element *c, const char *value)
224 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
228 /* Nonzero means expecting a trace trap
229 and should stop the inferior and return silently when it happens. */
233 /* Save register contents here when about to pop a stack dummy frame,
234 if-and-only-if proceed_to_finish is set.
235 Thus this contains the return value from the called function (assuming
236 values are returned in a register). */
238 struct regcache *stop_registers;
240 /* Nonzero after stop if current stack frame should be printed. */
242 static int stop_print_frame;
244 /* This is a cached copy of the pid/waitstatus of the last event
245 returned by target_wait()/deprecated_target_wait_hook(). This
246 information is returned by get_last_target_status(). */
247 static ptid_t target_last_wait_ptid;
248 static struct target_waitstatus target_last_waitstatus;
250 static void context_switch (ptid_t ptid);
252 void init_thread_stepping_state (struct thread_info *tss);
254 void init_infwait_state (void);
256 /* This is used to remember when a fork, vfork or exec event
257 was caught by a catchpoint, and thus the event is to be
258 followed at the next resume of the inferior, and not
262 enum target_waitkind kind;
269 char *execd_pathname;
273 static const char follow_fork_mode_child[] = "child";
274 static const char follow_fork_mode_parent[] = "parent";
276 static const char *follow_fork_mode_kind_names[] = {
277 follow_fork_mode_child,
278 follow_fork_mode_parent,
282 static const char *follow_fork_mode_string = follow_fork_mode_parent;
284 show_follow_fork_mode_string (struct ui_file *file, int from_tty,
285 struct cmd_list_element *c, const char *value)
287 fprintf_filtered (file, _("\
288 Debugger response to a program call of fork or vfork is \"%s\".\n"),
296 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
298 return target_follow_fork (follow_child);
302 follow_inferior_reset_breakpoints (void)
304 struct thread_info *tp = inferior_thread ();
306 /* Was there a step_resume breakpoint? (There was if the user
307 did a "next" at the fork() call.) If so, explicitly reset its
310 step_resumes are a form of bp that are made to be per-thread.
311 Since we created the step_resume bp when the parent process
312 was being debugged, and now are switching to the child process,
313 from the breakpoint package's viewpoint, that's a switch of
314 "threads". We must update the bp's notion of which thread
315 it is for, or it'll be ignored when it triggers. */
317 if (tp->step_resume_breakpoint)
318 breakpoint_re_set_thread (tp->step_resume_breakpoint);
320 /* Reinsert all breakpoints in the child. The user may have set
321 breakpoints after catching the fork, in which case those
322 were never set in the child, but only in the parent. This makes
323 sure the inserted breakpoints match the breakpoint list. */
325 breakpoint_re_set ();
326 insert_breakpoints ();
329 /* EXECD_PATHNAME is assumed to be non-NULL. */
332 follow_exec (ptid_t pid, char *execd_pathname)
334 struct target_ops *tgt;
335 struct thread_info *th = inferior_thread ();
337 /* This is an exec event that we actually wish to pay attention to.
338 Refresh our symbol table to the newly exec'd program, remove any
341 If there are breakpoints, they aren't really inserted now,
342 since the exec() transformed our inferior into a fresh set
345 We want to preserve symbolic breakpoints on the list, since
346 we have hopes that they can be reset after the new a.out's
347 symbol table is read.
349 However, any "raw" breakpoints must be removed from the list
350 (e.g., the solib bp's), since their address is probably invalid
353 And, we DON'T want to call delete_breakpoints() here, since
354 that may write the bp's "shadow contents" (the instruction
355 value that was overwritten witha TRAP instruction). Since
356 we now have a new a.out, those shadow contents aren't valid. */
357 update_breakpoints_after_exec ();
359 /* If there was one, it's gone now. We cannot truly step-to-next
360 statement through an exec(). */
361 th->step_resume_breakpoint = NULL;
362 th->step_range_start = 0;
363 th->step_range_end = 0;
365 /* What is this a.out's name? */
366 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname);
368 /* We've followed the inferior through an exec. Therefore, the
369 inferior has essentially been killed & reborn. */
371 gdb_flush (gdb_stdout);
373 breakpoint_init_inferior (inf_execd);
375 if (gdb_sysroot && *gdb_sysroot)
377 char *name = alloca (strlen (gdb_sysroot)
378 + strlen (execd_pathname)
380 strcpy (name, gdb_sysroot);
381 strcat (name, execd_pathname);
382 execd_pathname = name;
385 /* That a.out is now the one to use. */
386 exec_file_attach (execd_pathname, 0);
388 /* Reset the shared library package. This ensures that we get a
389 shlib event when the child reaches "_start", at which point the
390 dld will have had a chance to initialize the child. */
391 /* Also, loading a symbol file below may trigger symbol lookups, and
392 we don't want those to be satisfied by the libraries of the
393 previous incarnation of this process. */
394 no_shared_libraries (NULL, 0);
396 /* Load the main file's symbols. */
397 symbol_file_add_main (execd_pathname, 0);
399 #ifdef SOLIB_CREATE_INFERIOR_HOOK
400 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
402 solib_create_inferior_hook ();
405 /* Reinsert all breakpoints. (Those which were symbolic have
406 been reset to the proper address in the new a.out, thanks
407 to symbol_file_command...) */
408 insert_breakpoints ();
410 /* The next resume of this inferior should bring it to the shlib
411 startup breakpoints. (If the user had also set bp's on
412 "main" from the old (parent) process, then they'll auto-
413 matically get reset there in the new process.) */
416 /* Non-zero if we just simulating a single-step. This is needed
417 because we cannot remove the breakpoints in the inferior process
418 until after the `wait' in `wait_for_inferior'. */
419 static int singlestep_breakpoints_inserted_p = 0;
421 /* The thread we inserted single-step breakpoints for. */
422 static ptid_t singlestep_ptid;
424 /* PC when we started this single-step. */
425 static CORE_ADDR singlestep_pc;
427 /* If another thread hit the singlestep breakpoint, we save the original
428 thread here so that we can resume single-stepping it later. */
429 static ptid_t saved_singlestep_ptid;
430 static int stepping_past_singlestep_breakpoint;
432 /* If not equal to null_ptid, this means that after stepping over breakpoint
433 is finished, we need to switch to deferred_step_ptid, and step it.
435 The use case is when one thread has hit a breakpoint, and then the user
436 has switched to another thread and issued 'step'. We need to step over
437 breakpoint in the thread which hit the breakpoint, but then continue
438 stepping the thread user has selected. */
439 static ptid_t deferred_step_ptid;
441 /* Displaced stepping. */
443 /* In non-stop debugging mode, we must take special care to manage
444 breakpoints properly; in particular, the traditional strategy for
445 stepping a thread past a breakpoint it has hit is unsuitable.
446 'Displaced stepping' is a tactic for stepping one thread past a
447 breakpoint it has hit while ensuring that other threads running
448 concurrently will hit the breakpoint as they should.
450 The traditional way to step a thread T off a breakpoint in a
451 multi-threaded program in all-stop mode is as follows:
453 a0) Initially, all threads are stopped, and breakpoints are not
455 a1) We single-step T, leaving breakpoints uninserted.
456 a2) We insert breakpoints, and resume all threads.
458 In non-stop debugging, however, this strategy is unsuitable: we
459 don't want to have to stop all threads in the system in order to
460 continue or step T past a breakpoint. Instead, we use displaced
463 n0) Initially, T is stopped, other threads are running, and
464 breakpoints are inserted.
465 n1) We copy the instruction "under" the breakpoint to a separate
466 location, outside the main code stream, making any adjustments
467 to the instruction, register, and memory state as directed by
469 n2) We single-step T over the instruction at its new location.
470 n3) We adjust the resulting register and memory state as directed
471 by T's architecture. This includes resetting T's PC to point
472 back into the main instruction stream.
475 This approach depends on the following gdbarch methods:
477 - gdbarch_max_insn_length and gdbarch_displaced_step_location
478 indicate where to copy the instruction, and how much space must
479 be reserved there. We use these in step n1.
481 - gdbarch_displaced_step_copy_insn copies a instruction to a new
482 address, and makes any necessary adjustments to the instruction,
483 register contents, and memory. We use this in step n1.
485 - gdbarch_displaced_step_fixup adjusts registers and memory after
486 we have successfuly single-stepped the instruction, to yield the
487 same effect the instruction would have had if we had executed it
488 at its original address. We use this in step n3.
490 - gdbarch_displaced_step_free_closure provides cleanup.
492 The gdbarch_displaced_step_copy_insn and
493 gdbarch_displaced_step_fixup functions must be written so that
494 copying an instruction with gdbarch_displaced_step_copy_insn,
495 single-stepping across the copied instruction, and then applying
496 gdbarch_displaced_insn_fixup should have the same effects on the
497 thread's memory and registers as stepping the instruction in place
498 would have. Exactly which responsibilities fall to the copy and
499 which fall to the fixup is up to the author of those functions.
501 See the comments in gdbarch.sh for details.
503 Note that displaced stepping and software single-step cannot
504 currently be used in combination, although with some care I think
505 they could be made to. Software single-step works by placing
506 breakpoints on all possible subsequent instructions; if the
507 displaced instruction is a PC-relative jump, those breakpoints
508 could fall in very strange places --- on pages that aren't
509 executable, or at addresses that are not proper instruction
510 boundaries. (We do generally let other threads run while we wait
511 to hit the software single-step breakpoint, and they might
512 encounter such a corrupted instruction.) One way to work around
513 this would be to have gdbarch_displaced_step_copy_insn fully
514 simulate the effect of PC-relative instructions (and return NULL)
515 on architectures that use software single-stepping.
517 In non-stop mode, we can have independent and simultaneous step
518 requests, so more than one thread may need to simultaneously step
519 over a breakpoint. The current implementation assumes there is
520 only one scratch space per process. In this case, we have to
521 serialize access to the scratch space. If thread A wants to step
522 over a breakpoint, but we are currently waiting for some other
523 thread to complete a displaced step, we leave thread A stopped and
524 place it in the displaced_step_request_queue. Whenever a displaced
525 step finishes, we pick the next thread in the queue and start a new
526 displaced step operation on it. See displaced_step_prepare and
527 displaced_step_fixup for details. */
529 /* If this is not null_ptid, this is the thread carrying out a
530 displaced single-step. This thread's state will require fixing up
531 once it has completed its step. */
532 static ptid_t displaced_step_ptid;
534 struct displaced_step_request
537 struct displaced_step_request *next;
540 /* A queue of pending displaced stepping requests. */
541 struct displaced_step_request *displaced_step_request_queue;
543 /* The architecture the thread had when we stepped it. */
544 static struct gdbarch *displaced_step_gdbarch;
546 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
547 for post-step cleanup. */
548 static struct displaced_step_closure *displaced_step_closure;
550 /* The address of the original instruction, and the copy we made. */
551 static CORE_ADDR displaced_step_original, displaced_step_copy;
553 /* Saved contents of copy area. */
554 static gdb_byte *displaced_step_saved_copy;
556 /* When this is non-zero, we are allowed to use displaced stepping, if
557 the architecture supports it. When this is zero, we use
558 traditional the hold-and-step approach. */
559 int can_use_displaced_stepping = 1;
561 show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
562 struct cmd_list_element *c,
565 fprintf_filtered (file, _("\
566 Debugger's willingness to use displaced stepping to step over "
567 "breakpoints is %s.\n"), value);
570 /* Return non-zero if displaced stepping is enabled, and can be used
573 use_displaced_stepping (struct gdbarch *gdbarch)
575 return (can_use_displaced_stepping
576 && gdbarch_displaced_step_copy_insn_p (gdbarch));
579 /* Clean out any stray displaced stepping state. */
581 displaced_step_clear (void)
583 /* Indicate that there is no cleanup pending. */
584 displaced_step_ptid = null_ptid;
586 if (displaced_step_closure)
588 gdbarch_displaced_step_free_closure (displaced_step_gdbarch,
589 displaced_step_closure);
590 displaced_step_closure = NULL;
595 cleanup_displaced_step_closure (void *ptr)
597 struct displaced_step_closure *closure = ptr;
599 gdbarch_displaced_step_free_closure (current_gdbarch, closure);
602 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
604 displaced_step_dump_bytes (struct ui_file *file,
610 for (i = 0; i < len; i++)
611 fprintf_unfiltered (file, "%02x ", buf[i]);
612 fputs_unfiltered ("\n", file);
615 /* Prepare to single-step, using displaced stepping.
617 Note that we cannot use displaced stepping when we have a signal to
618 deliver. If we have a signal to deliver and an instruction to step
619 over, then after the step, there will be no indication from the
620 target whether the thread entered a signal handler or ignored the
621 signal and stepped over the instruction successfully --- both cases
622 result in a simple SIGTRAP. In the first case we mustn't do a
623 fixup, and in the second case we must --- but we can't tell which.
624 Comments in the code for 'random signals' in handle_inferior_event
625 explain how we handle this case instead.
627 Returns 1 if preparing was successful -- this thread is going to be
628 stepped now; or 0 if displaced stepping this thread got queued. */
630 displaced_step_prepare (ptid_t ptid)
632 struct cleanup *old_cleanups, *ignore_cleanups;
633 struct regcache *regcache = get_thread_regcache (ptid);
634 struct gdbarch *gdbarch = get_regcache_arch (regcache);
635 CORE_ADDR original, copy;
637 struct displaced_step_closure *closure;
639 /* We should never reach this function if the architecture does not
640 support displaced stepping. */
641 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
643 /* For the first cut, we're displaced stepping one thread at a
646 if (!ptid_equal (displaced_step_ptid, null_ptid))
648 /* Already waiting for a displaced step to finish. Defer this
649 request and place in queue. */
650 struct displaced_step_request *req, *new_req;
653 fprintf_unfiltered (gdb_stdlog,
654 "displaced: defering step of %s\n",
655 target_pid_to_str (ptid));
657 new_req = xmalloc (sizeof (*new_req));
658 new_req->ptid = ptid;
659 new_req->next = NULL;
661 if (displaced_step_request_queue)
663 for (req = displaced_step_request_queue;
670 displaced_step_request_queue = new_req;
677 fprintf_unfiltered (gdb_stdlog,
678 "displaced: stepping %s now\n",
679 target_pid_to_str (ptid));
682 displaced_step_clear ();
684 old_cleanups = save_inferior_ptid ();
685 inferior_ptid = ptid;
687 original = regcache_read_pc (regcache);
689 copy = gdbarch_displaced_step_location (gdbarch);
690 len = gdbarch_max_insn_length (gdbarch);
692 /* Save the original contents of the copy area. */
693 displaced_step_saved_copy = xmalloc (len);
694 ignore_cleanups = make_cleanup (free_current_contents,
695 &displaced_step_saved_copy);
696 read_memory (copy, displaced_step_saved_copy, len);
699 fprintf_unfiltered (gdb_stdlog, "displaced: saved 0x%s: ",
701 displaced_step_dump_bytes (gdb_stdlog, displaced_step_saved_copy, len);
704 closure = gdbarch_displaced_step_copy_insn (gdbarch,
705 original, copy, regcache);
707 /* We don't support the fully-simulated case at present. */
708 gdb_assert (closure);
710 make_cleanup (cleanup_displaced_step_closure, closure);
712 /* Resume execution at the copy. */
713 regcache_write_pc (regcache, copy);
715 discard_cleanups (ignore_cleanups);
717 do_cleanups (old_cleanups);
720 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to 0x%s\n",
723 /* Save the information we need to fix things up if the step
725 displaced_step_ptid = ptid;
726 displaced_step_gdbarch = gdbarch;
727 displaced_step_closure = closure;
728 displaced_step_original = original;
729 displaced_step_copy = copy;
734 displaced_step_clear_cleanup (void *ignore)
736 displaced_step_clear ();
740 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
742 struct cleanup *ptid_cleanup = save_inferior_ptid ();
743 inferior_ptid = ptid;
744 write_memory (memaddr, myaddr, len);
745 do_cleanups (ptid_cleanup);
749 displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
751 struct cleanup *old_cleanups;
753 /* Was this event for the pid we displaced? */
754 if (ptid_equal (displaced_step_ptid, null_ptid)
755 || ! ptid_equal (displaced_step_ptid, event_ptid))
758 old_cleanups = make_cleanup (displaced_step_clear_cleanup, 0);
760 /* Restore the contents of the copy area. */
762 ULONGEST len = gdbarch_max_insn_length (displaced_step_gdbarch);
763 write_memory_ptid (displaced_step_ptid, displaced_step_copy,
764 displaced_step_saved_copy, len);
766 fprintf_unfiltered (gdb_stdlog, "displaced: restored 0x%s\n",
767 paddr_nz (displaced_step_copy));
770 /* Did the instruction complete successfully? */
771 if (signal == TARGET_SIGNAL_TRAP)
773 /* Fix up the resulting state. */
774 gdbarch_displaced_step_fixup (displaced_step_gdbarch,
775 displaced_step_closure,
776 displaced_step_original,
778 get_thread_regcache (displaced_step_ptid));
782 /* Since the instruction didn't complete, all we can do is
784 struct regcache *regcache = get_thread_regcache (event_ptid);
785 CORE_ADDR pc = regcache_read_pc (regcache);
786 pc = displaced_step_original + (pc - displaced_step_copy);
787 regcache_write_pc (regcache, pc);
790 do_cleanups (old_cleanups);
792 displaced_step_ptid = null_ptid;
794 /* Are there any pending displaced stepping requests? If so, run
796 while (displaced_step_request_queue)
798 struct displaced_step_request *head;
802 head = displaced_step_request_queue;
804 displaced_step_request_queue = head->next;
807 context_switch (ptid);
809 actual_pc = read_pc ();
811 if (breakpoint_here_p (actual_pc))
814 fprintf_unfiltered (gdb_stdlog,
815 "displaced: stepping queued %s now\n",
816 target_pid_to_str (ptid));
818 displaced_step_prepare (ptid);
824 fprintf_unfiltered (gdb_stdlog, "displaced: run 0x%s: ",
825 paddr_nz (actual_pc));
826 read_memory (actual_pc, buf, sizeof (buf));
827 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
830 target_resume (ptid, 1, TARGET_SIGNAL_0);
832 /* Done, we're stepping a thread. */
838 struct thread_info *tp = inferior_thread ();
840 /* The breakpoint we were sitting under has since been
842 tp->trap_expected = 0;
844 /* Go back to what we were trying to do. */
845 step = currently_stepping (tp);
848 fprintf_unfiltered (gdb_stdlog, "breakpoint is gone %s: step(%d)\n",
849 target_pid_to_str (tp->ptid), step);
851 target_resume (ptid, step, TARGET_SIGNAL_0);
852 tp->stop_signal = TARGET_SIGNAL_0;
854 /* This request was discarded. See if there's any other
855 thread waiting for its turn. */
860 /* Update global variables holding ptids to hold NEW_PTID if they were
863 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
865 struct displaced_step_request *it;
867 if (ptid_equal (inferior_ptid, old_ptid))
868 inferior_ptid = new_ptid;
870 if (ptid_equal (singlestep_ptid, old_ptid))
871 singlestep_ptid = new_ptid;
873 if (ptid_equal (displaced_step_ptid, old_ptid))
874 displaced_step_ptid = new_ptid;
876 if (ptid_equal (deferred_step_ptid, old_ptid))
877 deferred_step_ptid = new_ptid;
879 for (it = displaced_step_request_queue; it; it = it->next)
880 if (ptid_equal (it->ptid, old_ptid))
887 /* Things to clean up if we QUIT out of resume (). */
889 resume_cleanups (void *ignore)
894 static const char schedlock_off[] = "off";
895 static const char schedlock_on[] = "on";
896 static const char schedlock_step[] = "step";
897 static const char *scheduler_enums[] = {
903 static const char *scheduler_mode = schedlock_off;
905 show_scheduler_mode (struct ui_file *file, int from_tty,
906 struct cmd_list_element *c, const char *value)
908 fprintf_filtered (file, _("\
909 Mode for locking scheduler during execution is \"%s\".\n"),
914 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
916 if (!target_can_lock_scheduler)
918 scheduler_mode = schedlock_off;
919 error (_("Target '%s' cannot support this command."), target_shortname);
924 /* Resume the inferior, but allow a QUIT. This is useful if the user
925 wants to interrupt some lengthy single-stepping operation
926 (for child processes, the SIGINT goes to the inferior, and so
927 we get a SIGINT random_signal, but for remote debugging and perhaps
928 other targets, that's not true).
930 STEP nonzero if we should step (zero to continue instead).
931 SIG is the signal to give the inferior (zero for none). */
933 resume (int step, enum target_signal sig)
935 int should_resume = 1;
936 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
937 struct regcache *regcache = get_current_regcache ();
938 struct gdbarch *gdbarch = get_regcache_arch (regcache);
939 struct thread_info *tp = inferior_thread ();
940 CORE_ADDR pc = regcache_read_pc (regcache);
944 fprintf_unfiltered (gdb_stdlog,
945 "infrun: resume (step=%d, signal=%d), "
946 "trap_expected=%d\n",
947 step, sig, tp->trap_expected);
949 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
950 over an instruction that causes a page fault without triggering
951 a hardware watchpoint. The kernel properly notices that it shouldn't
952 stop, because the hardware watchpoint is not triggered, but it forgets
953 the step request and continues the program normally.
954 Work around the problem by removing hardware watchpoints if a step is
955 requested, GDB will check for a hardware watchpoint trigger after the
957 if (CANNOT_STEP_HW_WATCHPOINTS && step)
958 remove_hw_watchpoints ();
961 /* Normally, by the time we reach `resume', the breakpoints are either
962 removed or inserted, as appropriate. The exception is if we're sitting
963 at a permanent breakpoint; we need to step over it, but permanent
964 breakpoints can't be removed. So we have to test for it here. */
965 if (breakpoint_here_p (pc) == permanent_breakpoint_here)
967 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
968 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
971 The program is stopped at a permanent breakpoint, but GDB does not know\n\
972 how to step past a permanent breakpoint on this architecture. Try using\n\
973 a command like `return' or `jump' to continue execution."));
976 /* If enabled, step over breakpoints by executing a copy of the
977 instruction at a different address.
979 We can't use displaced stepping when we have a signal to deliver;
980 the comments for displaced_step_prepare explain why. The
981 comments in the handle_inferior event for dealing with 'random
982 signals' explain what we do instead. */
983 if (use_displaced_stepping (gdbarch)
985 && sig == TARGET_SIGNAL_0)
987 if (!displaced_step_prepare (inferior_ptid))
989 /* Got placed in displaced stepping queue. Will be resumed
990 later when all the currently queued displaced stepping
991 requests finish. The thread is not executing at this point,
992 and the call to set_executing will be made later. But we
993 need to call set_running here, since from frontend point of view,
994 the thread is running. */
995 set_running (inferior_ptid, 1);
996 discard_cleanups (old_cleanups);
1001 if (step && gdbarch_software_single_step_p (gdbarch))
1003 /* Do it the hard way, w/temp breakpoints */
1004 if (gdbarch_software_single_step (gdbarch, get_current_frame ()))
1006 /* ...and don't ask hardware to do it. */
1008 /* and do not pull these breakpoints until after a `wait' in
1009 `wait_for_inferior' */
1010 singlestep_breakpoints_inserted_p = 1;
1011 singlestep_ptid = inferior_ptid;
1016 /* If there were any forks/vforks/execs that were caught and are
1017 now to be followed, then do so. */
1018 switch (pending_follow.kind)
1020 case TARGET_WAITKIND_FORKED:
1021 case TARGET_WAITKIND_VFORKED:
1022 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
1027 case TARGET_WAITKIND_EXECD:
1028 /* follow_exec is called as soon as the exec event is seen. */
1029 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
1036 /* Install inferior's terminal modes. */
1037 target_terminal_inferior ();
1043 resume_ptid = RESUME_ALL; /* Default */
1045 /* If STEP is set, it's a request to use hardware stepping
1046 facilities. But in that case, we should never
1047 use singlestep breakpoint. */
1048 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1050 if (singlestep_breakpoints_inserted_p
1051 && stepping_past_singlestep_breakpoint)
1053 /* The situation here is as follows. In thread T1 we wanted to
1054 single-step. Lacking hardware single-stepping we've
1055 set breakpoint at the PC of the next instruction -- call it
1056 P. After resuming, we've hit that breakpoint in thread T2.
1057 Now we've removed original breakpoint, inserted breakpoint
1058 at P+1, and try to step to advance T2 past breakpoint.
1059 We need to step only T2, as if T1 is allowed to freely run,
1060 it can run past P, and if other threads are allowed to run,
1061 they can hit breakpoint at P+1, and nested hits of single-step
1062 breakpoints is not something we'd want -- that's complicated
1063 to support, and has no value. */
1064 resume_ptid = inferior_ptid;
1067 if ((step || singlestep_breakpoints_inserted_p)
1068 && tp->trap_expected)
1070 /* We're allowing a thread to run past a breakpoint it has
1071 hit, by single-stepping the thread with the breakpoint
1072 removed. In which case, we need to single-step only this
1073 thread, and keep others stopped, as they can miss this
1074 breakpoint if allowed to run.
1076 The current code actually removes all breakpoints when
1077 doing this, not just the one being stepped over, so if we
1078 let other threads run, we can actually miss any
1079 breakpoint, not just the one at PC. */
1080 resume_ptid = inferior_ptid;
1085 /* With non-stop mode on, threads are always handled
1087 resume_ptid = inferior_ptid;
1089 else if ((scheduler_mode == schedlock_on)
1090 || (scheduler_mode == schedlock_step
1091 && (step || singlestep_breakpoints_inserted_p)))
1093 /* User-settable 'scheduler' mode requires solo thread resume. */
1094 resume_ptid = inferior_ptid;
1097 if (gdbarch_cannot_step_breakpoint (gdbarch))
1099 /* Most targets can step a breakpoint instruction, thus
1100 executing it normally. But if this one cannot, just
1101 continue and we will hit it anyway. */
1102 if (step && breakpoint_inserted_here_p (pc))
1107 && use_displaced_stepping (gdbarch)
1108 && tp->trap_expected)
1110 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1111 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1114 fprintf_unfiltered (gdb_stdlog, "displaced: run 0x%s: ",
1115 paddr_nz (actual_pc));
1116 read_memory (actual_pc, buf, sizeof (buf));
1117 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1120 target_resume (resume_ptid, step, sig);
1122 /* Avoid confusing the next resume, if the next stop/resume
1123 happens to apply to another thread. */
1124 tp->stop_signal = TARGET_SIGNAL_0;
1127 discard_cleanups (old_cleanups);
1132 /* Clear out all variables saying what to do when inferior is continued.
1133 First do this, then set the ones you want, then call `proceed'. */
1136 clear_proceed_status (void)
1138 if (!ptid_equal (inferior_ptid, null_ptid))
1140 struct thread_info *tp;
1141 struct inferior *inferior;
1143 tp = inferior_thread ();
1145 tp->trap_expected = 0;
1146 tp->step_range_start = 0;
1147 tp->step_range_end = 0;
1148 tp->step_frame_id = null_frame_id;
1149 tp->step_over_calls = STEP_OVER_UNDEBUGGABLE;
1153 tp->proceed_to_finish = 0;
1155 /* Discard any remaining commands or status from previous
1157 bpstat_clear (&tp->stop_bpstat);
1159 inferior = current_inferior ();
1160 inferior->stop_soon = NO_STOP_QUIETLY;
1163 stop_after_trap = 0;
1164 breakpoint_proceeded = 1; /* We're about to proceed... */
1168 regcache_xfree (stop_registers);
1169 stop_registers = NULL;
1173 /* This should be suitable for any targets that support threads. */
1176 prepare_to_proceed (int step)
1179 struct target_waitstatus wait_status;
1181 /* Get the last target status returned by target_wait(). */
1182 get_last_target_status (&wait_ptid, &wait_status);
1184 /* Make sure we were stopped at a breakpoint. */
1185 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1186 || wait_status.value.sig != TARGET_SIGNAL_TRAP)
1191 /* Switched over from WAIT_PID. */
1192 if (!ptid_equal (wait_ptid, minus_one_ptid)
1193 && !ptid_equal (inferior_ptid, wait_ptid))
1195 struct regcache *regcache = get_thread_regcache (wait_ptid);
1197 if (breakpoint_here_p (regcache_read_pc (regcache)))
1199 /* If stepping, remember current thread to switch back to. */
1201 deferred_step_ptid = inferior_ptid;
1203 /* Switch back to WAIT_PID thread. */
1204 switch_to_thread (wait_ptid);
1206 /* We return 1 to indicate that there is a breakpoint here,
1207 so we need to step over it before continuing to avoid
1208 hitting it straight away. */
1216 /* Basic routine for continuing the program in various fashions.
1218 ADDR is the address to resume at, or -1 for resume where stopped.
1219 SIGGNAL is the signal to give it, or 0 for none,
1220 or -1 for act according to how it stopped.
1221 STEP is nonzero if should trap after one instruction.
1222 -1 means return after that and print nothing.
1223 You should probably set various step_... variables
1224 before calling here, if you are stepping.
1226 You should call clear_proceed_status before calling proceed. */
1229 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
1231 struct regcache *regcache = get_current_regcache ();
1232 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1233 struct thread_info *tp;
1234 CORE_ADDR pc = regcache_read_pc (regcache);
1236 enum target_signal stop_signal;
1239 step_start_function = find_pc_function (pc);
1241 stop_after_trap = 1;
1243 if (addr == (CORE_ADDR) -1)
1245 if (pc == stop_pc && breakpoint_here_p (pc)
1246 && execution_direction != EXEC_REVERSE)
1247 /* There is a breakpoint at the address we will resume at,
1248 step one instruction before inserting breakpoints so that
1249 we do not stop right away (and report a second hit at this
1252 Note, we don't do this in reverse, because we won't
1253 actually be executing the breakpoint insn anyway.
1254 We'll be (un-)executing the previous instruction. */
1257 else if (gdbarch_single_step_through_delay_p (gdbarch)
1258 && gdbarch_single_step_through_delay (gdbarch,
1259 get_current_frame ()))
1260 /* We stepped onto an instruction that needs to be stepped
1261 again before re-inserting the breakpoint, do so. */
1266 regcache_write_pc (regcache, addr);
1270 fprintf_unfiltered (gdb_stdlog,
1271 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1272 paddr_nz (addr), siggnal, step);
1275 /* In non-stop, each thread is handled individually. The context
1276 must already be set to the right thread here. */
1280 /* In a multi-threaded task we may select another thread and
1281 then continue or step.
1283 But if the old thread was stopped at a breakpoint, it will
1284 immediately cause another breakpoint stop without any
1285 execution (i.e. it will report a breakpoint hit incorrectly).
1286 So we must step over it first.
1288 prepare_to_proceed checks the current thread against the
1289 thread that reported the most recent event. If a step-over
1290 is required it returns TRUE and sets the current thread to
1292 if (prepare_to_proceed (step))
1296 /* prepare_to_proceed may change the current thread. */
1297 tp = inferior_thread ();
1301 tp->trap_expected = 1;
1302 /* If displaced stepping is enabled, we can step over the
1303 breakpoint without hitting it, so leave all breakpoints
1304 inserted. Otherwise we need to disable all breakpoints, step
1305 one instruction, and then re-add them when that step is
1307 if (!use_displaced_stepping (gdbarch))
1308 remove_breakpoints ();
1311 /* We can insert breakpoints if we're not trying to step over one,
1312 or if we are stepping over one but we're using displaced stepping
1314 if (! tp->trap_expected || use_displaced_stepping (gdbarch))
1315 insert_breakpoints ();
1319 /* Pass the last stop signal to the thread we're resuming,
1320 irrespective of whether the current thread is the thread that
1321 got the last event or not. This was historically GDB's
1322 behaviour before keeping a stop_signal per thread. */
1324 struct thread_info *last_thread;
1326 struct target_waitstatus last_status;
1328 get_last_target_status (&last_ptid, &last_status);
1329 if (!ptid_equal (inferior_ptid, last_ptid)
1330 && !ptid_equal (last_ptid, null_ptid)
1331 && !ptid_equal (last_ptid, minus_one_ptid))
1333 last_thread = find_thread_pid (last_ptid);
1336 tp->stop_signal = last_thread->stop_signal;
1337 last_thread->stop_signal = TARGET_SIGNAL_0;
1342 if (siggnal != TARGET_SIGNAL_DEFAULT)
1343 tp->stop_signal = siggnal;
1344 /* If this signal should not be seen by program,
1345 give it zero. Used for debugging signals. */
1346 else if (!signal_program[tp->stop_signal])
1347 tp->stop_signal = TARGET_SIGNAL_0;
1349 annotate_starting ();
1351 /* Make sure that output from GDB appears before output from the
1353 gdb_flush (gdb_stdout);
1355 /* Refresh prev_pc value just prior to resuming. This used to be
1356 done in stop_stepping, however, setting prev_pc there did not handle
1357 scenarios such as inferior function calls or returning from
1358 a function via the return command. In those cases, the prev_pc
1359 value was not set properly for subsequent commands. The prev_pc value
1360 is used to initialize the starting line number in the ecs. With an
1361 invalid value, the gdb next command ends up stopping at the position
1362 represented by the next line table entry past our start position.
1363 On platforms that generate one line table entry per line, this
1364 is not a problem. However, on the ia64, the compiler generates
1365 extraneous line table entries that do not increase the line number.
1366 When we issue the gdb next command on the ia64 after an inferior call
1367 or a return command, we often end up a few instructions forward, still
1368 within the original line we started.
1370 An attempt was made to have init_execution_control_state () refresh
1371 the prev_pc value before calculating the line number. This approach
1372 did not work because on platforms that use ptrace, the pc register
1373 cannot be read unless the inferior is stopped. At that point, we
1374 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1375 call can fail. Setting the prev_pc value here ensures the value is
1376 updated correctly when the inferior is stopped. */
1377 tp->prev_pc = regcache_read_pc (get_current_regcache ());
1379 /* Fill in with reasonable starting values. */
1380 init_thread_stepping_state (tp);
1382 /* Reset to normal state. */
1383 init_infwait_state ();
1385 /* Resume inferior. */
1386 resume (oneproc || step || bpstat_should_step (), tp->stop_signal);
1388 /* Wait for it to stop (if not standalone)
1389 and in any case decode why it stopped, and act accordingly. */
1390 /* Do this only if we are not using the event loop, or if the target
1391 does not support asynchronous execution. */
1392 if (!target_can_async_p ())
1394 wait_for_inferior (0);
1400 /* Start remote-debugging of a machine over a serial link. */
1403 start_remote (int from_tty)
1405 struct inferior *inferior;
1406 init_wait_for_inferior ();
1408 inferior = current_inferior ();
1409 inferior->stop_soon = STOP_QUIETLY_REMOTE;
1411 /* Always go on waiting for the target, regardless of the mode. */
1412 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1413 indicate to wait_for_inferior that a target should timeout if
1414 nothing is returned (instead of just blocking). Because of this,
1415 targets expecting an immediate response need to, internally, set
1416 things up so that the target_wait() is forced to eventually
1418 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1419 differentiate to its caller what the state of the target is after
1420 the initial open has been performed. Here we're assuming that
1421 the target has stopped. It should be possible to eventually have
1422 target_open() return to the caller an indication that the target
1423 is currently running and GDB state should be set to the same as
1424 for an async run. */
1425 wait_for_inferior (0);
1427 /* Now that the inferior has stopped, do any bookkeeping like
1428 loading shared libraries. We want to do this before normal_stop,
1429 so that the displayed frame is up to date. */
1430 post_create_inferior (¤t_target, from_tty);
1435 /* Initialize static vars when a new inferior begins. */
1438 init_wait_for_inferior (void)
1440 /* These are meaningless until the first time through wait_for_inferior. */
1442 breakpoint_init_inferior (inf_starting);
1444 /* The first resume is not following a fork/vfork/exec. */
1445 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
1447 clear_proceed_status ();
1449 stepping_past_singlestep_breakpoint = 0;
1450 deferred_step_ptid = null_ptid;
1452 target_last_wait_ptid = minus_one_ptid;
1454 previous_inferior_ptid = null_ptid;
1455 init_infwait_state ();
1457 displaced_step_clear ();
1461 /* This enum encodes possible reasons for doing a target_wait, so that
1462 wfi can call target_wait in one place. (Ultimately the call will be
1463 moved out of the infinite loop entirely.) */
1467 infwait_normal_state,
1468 infwait_thread_hop_state,
1469 infwait_step_watch_state,
1470 infwait_nonstep_watch_state
1473 /* Why did the inferior stop? Used to print the appropriate messages
1474 to the interface from within handle_inferior_event(). */
1475 enum inferior_stop_reason
1477 /* Step, next, nexti, stepi finished. */
1479 /* Inferior terminated by signal. */
1481 /* Inferior exited. */
1483 /* Inferior received signal, and user asked to be notified. */
1485 /* Reverse execution -- target ran out of history info. */
1489 /* The PTID we'll do a target_wait on.*/
1492 /* Current inferior wait state. */
1493 enum infwait_states infwait_state;
1495 /* Data to be passed around while handling an event. This data is
1496 discarded between events. */
1497 struct execution_control_state
1500 /* The thread that got the event, if this was a thread event; NULL
1502 struct thread_info *event_thread;
1504 struct target_waitstatus ws;
1506 CORE_ADDR stop_func_start;
1507 CORE_ADDR stop_func_end;
1508 char *stop_func_name;
1509 int new_thread_event;
1513 void init_execution_control_state (struct execution_control_state *ecs);
1515 void handle_inferior_event (struct execution_control_state *ecs);
1517 static void handle_step_into_function (struct execution_control_state *ecs);
1518 static void handle_step_into_function_backward (struct execution_control_state *ecs);
1519 static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame);
1520 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
1521 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal,
1522 struct frame_id sr_id);
1523 static void insert_longjmp_resume_breakpoint (CORE_ADDR);
1525 static void stop_stepping (struct execution_control_state *ecs);
1526 static void prepare_to_wait (struct execution_control_state *ecs);
1527 static void keep_going (struct execution_control_state *ecs);
1528 static void print_stop_reason (enum inferior_stop_reason stop_reason,
1531 /* Callback for iterate_over_threads. */
1534 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
1536 if (is_exited (info->ptid))
1539 delete_step_resume_breakpoint (info);
1543 /* In all-stop, delete the step resume breakpoint of any thread that
1544 had one. In non-stop, delete the step resume breakpoint of the
1545 thread that just stopped. */
1548 delete_step_thread_step_resume_breakpoint (void)
1550 if (!target_has_execution
1551 || ptid_equal (inferior_ptid, null_ptid))
1552 /* If the inferior has exited, we have already deleted the step
1553 resume breakpoints out of GDB's lists. */
1558 /* If in non-stop mode, only delete the step-resume or
1559 longjmp-resume breakpoint of the thread that just stopped
1561 struct thread_info *tp = inferior_thread ();
1562 delete_step_resume_breakpoint (tp);
1565 /* In all-stop mode, delete all step-resume and longjmp-resume
1566 breakpoints of any thread that had them. */
1567 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
1570 /* A cleanup wrapper. */
1573 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
1575 delete_step_thread_step_resume_breakpoint ();
1578 /* Wait for control to return from inferior to debugger.
1580 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1581 as if they were SIGTRAP signals. This can be useful during
1582 the startup sequence on some targets such as HP/UX, where
1583 we receive an EXEC event instead of the expected SIGTRAP.
1585 If inferior gets a signal, we may decide to start it up again
1586 instead of returning. That is why there is a loop in this function.
1587 When this function actually returns it means the inferior
1588 should be left stopped and GDB should read more commands. */
1591 wait_for_inferior (int treat_exec_as_sigtrap)
1593 struct cleanup *old_cleanups;
1594 struct execution_control_state ecss;
1595 struct execution_control_state *ecs;
1599 (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1600 treat_exec_as_sigtrap);
1603 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
1606 memset (ecs, 0, sizeof (*ecs));
1608 overlay_cache_invalid = 1;
1610 /* We'll update this if & when we switch to a new thread. */
1611 previous_inferior_ptid = inferior_ptid;
1613 /* We have to invalidate the registers BEFORE calling target_wait
1614 because they can be loaded from the target while in target_wait.
1615 This makes remote debugging a bit more efficient for those
1616 targets that provide critical registers as part of their normal
1617 status mechanism. */
1619 registers_changed ();
1623 if (deprecated_target_wait_hook)
1624 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
1626 ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
1628 if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
1630 xfree (ecs->ws.value.execd_pathname);
1631 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
1632 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
1635 /* Now figure out what to do with the result of the result. */
1636 handle_inferior_event (ecs);
1638 if (!ecs->wait_some_more)
1642 do_cleanups (old_cleanups);
1645 /* Asynchronous version of wait_for_inferior. It is called by the
1646 event loop whenever a change of state is detected on the file
1647 descriptor corresponding to the target. It can be called more than
1648 once to complete a single execution command. In such cases we need
1649 to keep the state in a global variable ECSS. If it is the last time
1650 that this function is called for a single execution command, then
1651 report to the user that the inferior has stopped, and do the
1652 necessary cleanups. */
1655 fetch_inferior_event (void *client_data)
1657 struct execution_control_state ecss;
1658 struct execution_control_state *ecs = &ecss;
1659 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
1660 int was_sync = sync_execution;
1662 memset (ecs, 0, sizeof (*ecs));
1664 overlay_cache_invalid = 1;
1666 /* We can only rely on wait_for_more being correct before handling
1667 the event in all-stop, but previous_inferior_ptid isn't used in
1669 if (!ecs->wait_some_more)
1670 /* We'll update this if & when we switch to a new thread. */
1671 previous_inferior_ptid = inferior_ptid;
1674 /* In non-stop mode, the user/frontend should not notice a thread
1675 switch due to internal events. Make sure we reverse to the
1676 user selected thread and frame after handling the event and
1677 running any breakpoint commands. */
1678 make_cleanup_restore_current_thread ();
1680 /* We have to invalidate the registers BEFORE calling target_wait
1681 because they can be loaded from the target while in target_wait.
1682 This makes remote debugging a bit more efficient for those
1683 targets that provide critical registers as part of their normal
1684 status mechanism. */
1686 registers_changed ();
1688 if (deprecated_target_wait_hook)
1690 deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
1692 ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
1695 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
1696 && ecs->ws.kind != TARGET_WAITKIND_EXITED
1697 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
1698 /* In non-stop mode, each thread is handled individually. Switch
1699 early, so the global state is set correctly for this
1701 context_switch (ecs->ptid);
1703 /* Now figure out what to do with the result of the result. */
1704 handle_inferior_event (ecs);
1706 if (!ecs->wait_some_more)
1708 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
1710 delete_step_thread_step_resume_breakpoint ();
1712 /* We may not find an inferior if this was a process exit. */
1713 if (inf == NULL || inf->stop_soon == NO_STOP_QUIETLY)
1716 if (target_has_execution
1717 && ecs->ws.kind != TARGET_WAITKIND_EXITED
1718 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1719 && ecs->event_thread->step_multi
1720 && ecs->event_thread->stop_step)
1721 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1723 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1726 /* Revert thread and frame. */
1727 do_cleanups (old_chain);
1729 /* If the inferior was in sync execution mode, and now isn't,
1730 restore the prompt. */
1731 if (was_sync && !sync_execution)
1732 display_gdb_prompt (0);
1735 /* Prepare an execution control state for looping through a
1736 wait_for_inferior-type loop. */
1739 init_execution_control_state (struct execution_control_state *ecs)
1741 ecs->random_signal = 0;
1744 /* Clear context switchable stepping state. */
1747 init_thread_stepping_state (struct thread_info *tss)
1749 struct symtab_and_line sal;
1751 tss->stepping_over_breakpoint = 0;
1752 tss->step_after_step_resume_breakpoint = 0;
1753 tss->stepping_through_solib_after_catch = 0;
1754 tss->stepping_through_solib_catchpoints = NULL;
1756 sal = find_pc_line (tss->prev_pc, 0);
1757 tss->current_line = sal.line;
1758 tss->current_symtab = sal.symtab;
1761 /* Return the cached copy of the last pid/waitstatus returned by
1762 target_wait()/deprecated_target_wait_hook(). The data is actually
1763 cached by handle_inferior_event(), which gets called immediately
1764 after target_wait()/deprecated_target_wait_hook(). */
1767 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1769 *ptidp = target_last_wait_ptid;
1770 *status = target_last_waitstatus;
1774 nullify_last_target_wait_ptid (void)
1776 target_last_wait_ptid = minus_one_ptid;
1779 /* Switch thread contexts. */
1782 context_switch (ptid_t ptid)
1786 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
1787 target_pid_to_str (inferior_ptid));
1788 fprintf_unfiltered (gdb_stdlog, "to %s\n",
1789 target_pid_to_str (ptid));
1792 switch_to_thread (ptid);
1796 adjust_pc_after_break (struct execution_control_state *ecs)
1798 struct regcache *regcache;
1799 struct gdbarch *gdbarch;
1800 CORE_ADDR breakpoint_pc;
1802 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1803 we aren't, just return.
1805 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1806 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1807 implemented by software breakpoints should be handled through the normal
1810 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1811 different signals (SIGILL or SIGEMT for instance), but it is less
1812 clear where the PC is pointing afterwards. It may not match
1813 gdbarch_decr_pc_after_break. I don't know any specific target that
1814 generates these signals at breakpoints (the code has been in GDB since at
1815 least 1992) so I can not guess how to handle them here.
1817 In earlier versions of GDB, a target with
1818 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1819 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1820 target with both of these set in GDB history, and it seems unlikely to be
1821 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1823 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
1826 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
1829 /* In reverse execution, when a breakpoint is hit, the instruction
1830 under it has already been de-executed. The reported PC always
1831 points at the breakpoint address, so adjusting it further would
1832 be wrong. E.g., consider this case on a decr_pc_after_break == 1
1835 B1 0x08000000 : INSN1
1836 B2 0x08000001 : INSN2
1838 PC -> 0x08000003 : INSN4
1840 Say you're stopped at 0x08000003 as above. Reverse continuing
1841 from that point should hit B2 as below. Reading the PC when the
1842 SIGTRAP is reported should read 0x08000001 and INSN2 should have
1843 been de-executed already.
1845 B1 0x08000000 : INSN1
1846 B2 PC -> 0x08000001 : INSN2
1850 We can't apply the same logic as for forward execution, because
1851 we would wrongly adjust the PC to 0x08000000, since there's a
1852 breakpoint at PC - 1. We'd then report a hit on B1, although
1853 INSN1 hadn't been de-executed yet. Doing nothing is the correct
1855 if (execution_direction == EXEC_REVERSE)
1858 /* If this target does not decrement the PC after breakpoints, then
1859 we have nothing to do. */
1860 regcache = get_thread_regcache (ecs->ptid);
1861 gdbarch = get_regcache_arch (regcache);
1862 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
1865 /* Find the location where (if we've hit a breakpoint) the
1866 breakpoint would be. */
1867 breakpoint_pc = regcache_read_pc (regcache)
1868 - gdbarch_decr_pc_after_break (gdbarch);
1870 /* Check whether there actually is a software breakpoint inserted at
1873 If in non-stop mode, a race condition is possible where we've
1874 removed a breakpoint, but stop events for that breakpoint were
1875 already queued and arrive later. To suppress those spurious
1876 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
1877 and retire them after a number of stop events are reported. */
1878 if (software_breakpoint_inserted_here_p (breakpoint_pc)
1879 || (non_stop && moribund_breakpoint_here_p (breakpoint_pc)))
1881 /* When using hardware single-step, a SIGTRAP is reported for both
1882 a completed single-step and a software breakpoint. Need to
1883 differentiate between the two, as the latter needs adjusting
1884 but the former does not.
1886 The SIGTRAP can be due to a completed hardware single-step only if
1887 - we didn't insert software single-step breakpoints
1888 - the thread to be examined is still the current thread
1889 - this thread is currently being stepped
1891 If any of these events did not occur, we must have stopped due
1892 to hitting a software breakpoint, and have to back up to the
1895 As a special case, we could have hardware single-stepped a
1896 software breakpoint. In this case (prev_pc == breakpoint_pc),
1897 we also need to back up to the breakpoint address. */
1899 if (singlestep_breakpoints_inserted_p
1900 || !ptid_equal (ecs->ptid, inferior_ptid)
1901 || !currently_stepping (ecs->event_thread)
1902 || ecs->event_thread->prev_pc == breakpoint_pc)
1903 regcache_write_pc (regcache, breakpoint_pc);
1908 init_infwait_state (void)
1910 waiton_ptid = pid_to_ptid (-1);
1911 infwait_state = infwait_normal_state;
1915 error_is_running (void)
1918 Cannot execute this command while the selected thread is running."));
1922 ensure_not_running (void)
1924 if (is_running (inferior_ptid))
1925 error_is_running ();
1928 /* Given an execution control state that has been freshly filled in
1929 by an event from the inferior, figure out what it means and take
1930 appropriate action. */
1933 handle_inferior_event (struct execution_control_state *ecs)
1935 int sw_single_step_trap_p = 0;
1936 int stopped_by_watchpoint;
1937 int stepped_after_stopped_by_watchpoint = 0;
1938 struct symtab_and_line stop_pc_sal;
1939 enum stop_kind stop_soon;
1941 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1942 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1943 && ecs->ws.kind != TARGET_WAITKIND_IGNORE)
1945 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
1947 stop_soon = inf->stop_soon;
1950 stop_soon = NO_STOP_QUIETLY;
1952 /* Cache the last pid/waitstatus. */
1953 target_last_wait_ptid = ecs->ptid;
1954 target_last_waitstatus = ecs->ws;
1956 /* Always clear state belonging to the previous time we stopped. */
1957 stop_stack_dummy = 0;
1959 /* If it's a new process, add it to the thread database */
1961 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1962 && !ptid_equal (ecs->ptid, minus_one_ptid)
1963 && !in_thread_list (ecs->ptid));
1965 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1966 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1967 add_thread (ecs->ptid);
1969 ecs->event_thread = find_thread_pid (ecs->ptid);
1971 /* Dependent on valid ECS->EVENT_THREAD. */
1972 adjust_pc_after_break (ecs);
1974 /* Dependent on the current PC value modified by adjust_pc_after_break. */
1975 reinit_frame_cache ();
1977 if (ecs->ws.kind != TARGET_WAITKIND_IGNORE)
1979 breakpoint_retire_moribund ();
1981 /* Mark the non-executing threads accordingly. */
1983 || ecs->ws.kind == TARGET_WAITKIND_EXITED
1984 || ecs->ws.kind == TARGET_WAITKIND_SIGNALLED)
1985 set_executing (pid_to_ptid (-1), 0);
1987 set_executing (ecs->ptid, 0);
1990 switch (infwait_state)
1992 case infwait_thread_hop_state:
1994 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
1995 /* Cancel the waiton_ptid. */
1996 waiton_ptid = pid_to_ptid (-1);
1999 case infwait_normal_state:
2001 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
2004 case infwait_step_watch_state:
2006 fprintf_unfiltered (gdb_stdlog,
2007 "infrun: infwait_step_watch_state\n");
2009 stepped_after_stopped_by_watchpoint = 1;
2012 case infwait_nonstep_watch_state:
2014 fprintf_unfiltered (gdb_stdlog,
2015 "infrun: infwait_nonstep_watch_state\n");
2016 insert_breakpoints ();
2018 /* FIXME-maybe: is this cleaner than setting a flag? Does it
2019 handle things like signals arriving and other things happening
2020 in combination correctly? */
2021 stepped_after_stopped_by_watchpoint = 1;
2025 internal_error (__FILE__, __LINE__, _("bad switch"));
2027 infwait_state = infwait_normal_state;
2029 switch (ecs->ws.kind)
2031 case TARGET_WAITKIND_LOADED:
2033 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
2034 /* Ignore gracefully during startup of the inferior, as it might
2035 be the shell which has just loaded some objects, otherwise
2036 add the symbols for the newly loaded objects. Also ignore at
2037 the beginning of an attach or remote session; we will query
2038 the full list of libraries once the connection is
2040 if (stop_soon == NO_STOP_QUIETLY)
2042 /* Check for any newly added shared libraries if we're
2043 supposed to be adding them automatically. Switch
2044 terminal for any messages produced by
2045 breakpoint_re_set. */
2046 target_terminal_ours_for_output ();
2047 /* NOTE: cagney/2003-11-25: Make certain that the target
2048 stack's section table is kept up-to-date. Architectures,
2049 (e.g., PPC64), use the section table to perform
2050 operations such as address => section name and hence
2051 require the table to contain all sections (including
2052 those found in shared libraries). */
2053 /* NOTE: cagney/2003-11-25: Pass current_target and not
2054 exec_ops to SOLIB_ADD. This is because current GDB is
2055 only tooled to propagate section_table changes out from
2056 the "current_target" (see target_resize_to_sections), and
2057 not up from the exec stratum. This, of course, isn't
2058 right. "infrun.c" should only interact with the
2059 exec/process stratum, instead relying on the target stack
2060 to propagate relevant changes (stop, section table
2061 changed, ...) up to other layers. */
2063 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
2065 solib_add (NULL, 0, ¤t_target, auto_solib_add);
2067 target_terminal_inferior ();
2069 /* If requested, stop when the dynamic linker notifies
2070 gdb of events. This allows the user to get control
2071 and place breakpoints in initializer routines for
2072 dynamically loaded objects (among other things). */
2073 if (stop_on_solib_events)
2075 stop_stepping (ecs);
2079 /* NOTE drow/2007-05-11: This might be a good place to check
2080 for "catch load". */
2083 /* If we are skipping through a shell, or through shared library
2084 loading that we aren't interested in, resume the program. If
2085 we're running the program normally, also resume. But stop if
2086 we're attaching or setting up a remote connection. */
2087 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
2089 /* Loading of shared libraries might have changed breakpoint
2090 addresses. Make sure new breakpoints are inserted. */
2091 if (stop_soon == NO_STOP_QUIETLY
2092 && !breakpoints_always_inserted_mode ())
2093 insert_breakpoints ();
2094 resume (0, TARGET_SIGNAL_0);
2095 prepare_to_wait (ecs);
2101 case TARGET_WAITKIND_SPURIOUS:
2103 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
2104 resume (0, TARGET_SIGNAL_0);
2105 prepare_to_wait (ecs);
2108 case TARGET_WAITKIND_EXITED:
2110 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
2111 target_terminal_ours (); /* Must do this before mourn anyway */
2112 print_stop_reason (EXITED, ecs->ws.value.integer);
2114 /* Record the exit code in the convenience variable $_exitcode, so
2115 that the user can inspect this again later. */
2116 set_internalvar (lookup_internalvar ("_exitcode"),
2117 value_from_longest (builtin_type_int32,
2118 (LONGEST) ecs->ws.value.integer));
2119 gdb_flush (gdb_stdout);
2120 target_mourn_inferior ();
2121 singlestep_breakpoints_inserted_p = 0;
2122 stop_print_frame = 0;
2123 stop_stepping (ecs);
2126 case TARGET_WAITKIND_SIGNALLED:
2128 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2129 stop_print_frame = 0;
2130 target_terminal_ours (); /* Must do this before mourn anyway */
2132 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
2133 reach here unless the inferior is dead. However, for years
2134 target_kill() was called here, which hints that fatal signals aren't
2135 really fatal on some systems. If that's true, then some changes
2137 target_mourn_inferior ();
2139 print_stop_reason (SIGNAL_EXITED, ecs->ws.value.sig);
2140 singlestep_breakpoints_inserted_p = 0;
2141 stop_stepping (ecs);
2144 /* The following are the only cases in which we keep going;
2145 the above cases end in a continue or goto. */
2146 case TARGET_WAITKIND_FORKED:
2147 case TARGET_WAITKIND_VFORKED:
2149 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
2150 pending_follow.kind = ecs->ws.kind;
2152 pending_follow.fork_event.parent_pid = ecs->ptid;
2153 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
2155 if (!ptid_equal (ecs->ptid, inferior_ptid))
2157 context_switch (ecs->ptid);
2158 reinit_frame_cache ();
2161 stop_pc = read_pc ();
2163 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2165 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2167 /* If no catchpoint triggered for this, then keep going. */
2168 if (ecs->random_signal)
2170 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2174 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2175 goto process_event_stop_test;
2177 case TARGET_WAITKIND_EXECD:
2179 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
2180 pending_follow.execd_pathname =
2181 savestring (ecs->ws.value.execd_pathname,
2182 strlen (ecs->ws.value.execd_pathname));
2184 if (!ptid_equal (ecs->ptid, inferior_ptid))
2186 context_switch (ecs->ptid);
2187 reinit_frame_cache ();
2190 stop_pc = read_pc ();
2192 /* This causes the eventpoints and symbol table to be reset.
2193 Must do this now, before trying to determine whether to
2195 follow_exec (inferior_ptid, pending_follow.execd_pathname);
2196 xfree (pending_follow.execd_pathname);
2198 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2199 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2201 /* If no catchpoint triggered for this, then keep going. */
2202 if (ecs->random_signal)
2204 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2208 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2209 goto process_event_stop_test;
2211 /* Be careful not to try to gather much state about a thread
2212 that's in a syscall. It's frequently a losing proposition. */
2213 case TARGET_WAITKIND_SYSCALL_ENTRY:
2215 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2216 resume (0, TARGET_SIGNAL_0);
2217 prepare_to_wait (ecs);
2220 /* Before examining the threads further, step this thread to
2221 get it entirely out of the syscall. (We get notice of the
2222 event when the thread is just on the verge of exiting a
2223 syscall. Stepping one instruction seems to get it back
2225 case TARGET_WAITKIND_SYSCALL_RETURN:
2227 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2228 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
2229 prepare_to_wait (ecs);
2232 case TARGET_WAITKIND_STOPPED:
2234 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
2235 ecs->event_thread->stop_signal = ecs->ws.value.sig;
2238 case TARGET_WAITKIND_NO_HISTORY:
2239 /* Reverse execution: target ran out of history info. */
2240 print_stop_reason (NO_HISTORY, 0);
2241 stop_stepping (ecs);
2244 /* We had an event in the inferior, but we are not interested
2245 in handling it at this level. The lower layers have already
2246 done what needs to be done, if anything.
2248 One of the possible circumstances for this is when the
2249 inferior produces output for the console. The inferior has
2250 not stopped, and we are ignoring the event. Another possible
2251 circumstance is any event which the lower level knows will be
2252 reported multiple times without an intervening resume. */
2253 case TARGET_WAITKIND_IGNORE:
2255 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
2256 prepare_to_wait (ecs);
2260 if (ecs->new_thread_event)
2263 /* Non-stop assumes that the target handles adding new threads
2264 to the thread list. */
2265 internal_error (__FILE__, __LINE__, "\
2266 targets should add new threads to the thread list themselves in non-stop mode.");
2268 /* We may want to consider not doing a resume here in order to
2269 give the user a chance to play with the new thread. It might
2270 be good to make that a user-settable option. */
2272 /* At this point, all threads are stopped (happens automatically
2273 in either the OS or the native code). Therefore we need to
2274 continue all threads in order to make progress. */
2276 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
2277 prepare_to_wait (ecs);
2281 /* Do we need to clean up the state of a thread that has completed a
2282 displaced single-step? (Doing so usually affects the PC, so do
2283 it here, before we set stop_pc.) */
2284 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
2285 displaced_step_fixup (ecs->ptid, ecs->event_thread->stop_signal);
2287 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2291 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n",
2292 paddr_nz (stop_pc));
2293 if (STOPPED_BY_WATCHPOINT (&ecs->ws))
2296 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
2298 if (target_stopped_data_address (¤t_target, &addr))
2299 fprintf_unfiltered (gdb_stdlog,
2300 "infrun: stopped data address = 0x%s\n",
2303 fprintf_unfiltered (gdb_stdlog,
2304 "infrun: (no data address available)\n");
2308 if (stepping_past_singlestep_breakpoint)
2310 gdb_assert (singlestep_breakpoints_inserted_p);
2311 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
2312 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
2314 stepping_past_singlestep_breakpoint = 0;
2316 /* We've either finished single-stepping past the single-step
2317 breakpoint, or stopped for some other reason. It would be nice if
2318 we could tell, but we can't reliably. */
2319 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2322 fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n");
2323 /* Pull the single step breakpoints out of the target. */
2324 remove_single_step_breakpoints ();
2325 singlestep_breakpoints_inserted_p = 0;
2327 ecs->random_signal = 0;
2329 context_switch (saved_singlestep_ptid);
2330 if (deprecated_context_hook)
2331 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
2333 resume (1, TARGET_SIGNAL_0);
2334 prepare_to_wait (ecs);
2339 stepping_past_singlestep_breakpoint = 0;
2341 if (!ptid_equal (deferred_step_ptid, null_ptid))
2343 /* In non-stop mode, there's never a deferred_step_ptid set. */
2344 gdb_assert (!non_stop);
2346 /* If we stopped for some other reason than single-stepping, ignore
2347 the fact that we were supposed to switch back. */
2348 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2350 struct thread_info *tp;
2353 fprintf_unfiltered (gdb_stdlog,
2354 "infrun: handling deferred step\n");
2356 /* Pull the single step breakpoints out of the target. */
2357 if (singlestep_breakpoints_inserted_p)
2359 remove_single_step_breakpoints ();
2360 singlestep_breakpoints_inserted_p = 0;
2363 /* Note: We do not call context_switch at this point, as the
2364 context is already set up for stepping the original thread. */
2365 switch_to_thread (deferred_step_ptid);
2366 deferred_step_ptid = null_ptid;
2367 /* Suppress spurious "Switching to ..." message. */
2368 previous_inferior_ptid = inferior_ptid;
2370 resume (1, TARGET_SIGNAL_0);
2371 prepare_to_wait (ecs);
2375 deferred_step_ptid = null_ptid;
2378 /* See if a thread hit a thread-specific breakpoint that was meant for
2379 another thread. If so, then step that thread past the breakpoint,
2382 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2384 int thread_hop_needed = 0;
2386 /* Check if a regular breakpoint has been hit before checking
2387 for a potential single step breakpoint. Otherwise, GDB will
2388 not see this breakpoint hit when stepping onto breakpoints. */
2389 if (regular_breakpoint_inserted_here_p (stop_pc))
2391 ecs->random_signal = 0;
2392 if (!breakpoint_thread_match (stop_pc, ecs->ptid))
2393 thread_hop_needed = 1;
2395 else if (singlestep_breakpoints_inserted_p)
2397 /* We have not context switched yet, so this should be true
2398 no matter which thread hit the singlestep breakpoint. */
2399 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
2401 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
2403 target_pid_to_str (ecs->ptid));
2405 ecs->random_signal = 0;
2406 /* The call to in_thread_list is necessary because PTIDs sometimes
2407 change when we go from single-threaded to multi-threaded. If
2408 the singlestep_ptid is still in the list, assume that it is
2409 really different from ecs->ptid. */
2410 if (!ptid_equal (singlestep_ptid, ecs->ptid)
2411 && in_thread_list (singlestep_ptid))
2413 /* If the PC of the thread we were trying to single-step
2414 has changed, discard this event (which we were going
2415 to ignore anyway), and pretend we saw that thread
2416 trap. This prevents us continuously moving the
2417 single-step breakpoint forward, one instruction at a
2418 time. If the PC has changed, then the thread we were
2419 trying to single-step has trapped or been signalled,
2420 but the event has not been reported to GDB yet.
2422 There might be some cases where this loses signal
2423 information, if a signal has arrived at exactly the
2424 same time that the PC changed, but this is the best
2425 we can do with the information available. Perhaps we
2426 should arrange to report all events for all threads
2427 when they stop, or to re-poll the remote looking for
2428 this particular thread (i.e. temporarily enable
2431 CORE_ADDR new_singlestep_pc
2432 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
2434 if (new_singlestep_pc != singlestep_pc)
2436 enum target_signal stop_signal;
2439 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
2440 " but expected thread advanced also\n");
2442 /* The current context still belongs to
2443 singlestep_ptid. Don't swap here, since that's
2444 the context we want to use. Just fudge our
2445 state and continue. */
2446 stop_signal = ecs->event_thread->stop_signal;
2447 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2448 ecs->ptid = singlestep_ptid;
2449 ecs->event_thread = find_thread_pid (ecs->ptid);
2450 ecs->event_thread->stop_signal = stop_signal;
2451 stop_pc = new_singlestep_pc;
2456 fprintf_unfiltered (gdb_stdlog,
2457 "infrun: unexpected thread\n");
2459 thread_hop_needed = 1;
2460 stepping_past_singlestep_breakpoint = 1;
2461 saved_singlestep_ptid = singlestep_ptid;
2466 if (thread_hop_needed)
2468 int remove_status = 0;
2471 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
2473 /* Saw a breakpoint, but it was hit by the wrong thread.
2476 if (singlestep_breakpoints_inserted_p)
2478 /* Pull the single step breakpoints out of the target. */
2479 remove_single_step_breakpoints ();
2480 singlestep_breakpoints_inserted_p = 0;
2483 /* If the arch can displace step, don't remove the
2485 if (!use_displaced_stepping (current_gdbarch))
2486 remove_status = remove_breakpoints ();
2488 /* Did we fail to remove breakpoints? If so, try
2489 to set the PC past the bp. (There's at least
2490 one situation in which we can fail to remove
2491 the bp's: On HP-UX's that use ttrace, we can't
2492 change the address space of a vforking child
2493 process until the child exits (well, okay, not
2494 then either :-) or execs. */
2495 if (remove_status != 0)
2496 error (_("Cannot step over breakpoint hit in wrong thread"));
2499 if (!ptid_equal (inferior_ptid, ecs->ptid))
2500 context_switch (ecs->ptid);
2504 /* Only need to require the next event from this
2505 thread in all-stop mode. */
2506 waiton_ptid = ecs->ptid;
2507 infwait_state = infwait_thread_hop_state;
2510 ecs->event_thread->stepping_over_breakpoint = 1;
2512 registers_changed ();
2516 else if (singlestep_breakpoints_inserted_p)
2518 sw_single_step_trap_p = 1;
2519 ecs->random_signal = 0;
2523 ecs->random_signal = 1;
2525 /* See if something interesting happened to the non-current thread. If
2526 so, then switch to that thread. */
2527 if (!ptid_equal (ecs->ptid, inferior_ptid))
2530 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
2532 context_switch (ecs->ptid);
2534 if (deprecated_context_hook)
2535 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
2538 if (singlestep_breakpoints_inserted_p)
2540 /* Pull the single step breakpoints out of the target. */
2541 remove_single_step_breakpoints ();
2542 singlestep_breakpoints_inserted_p = 0;
2545 if (stepped_after_stopped_by_watchpoint)
2546 stopped_by_watchpoint = 0;
2548 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
2550 /* If necessary, step over this watchpoint. We'll be back to display
2552 if (stopped_by_watchpoint
2553 && (HAVE_STEPPABLE_WATCHPOINT
2554 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch)))
2556 /* At this point, we are stopped at an instruction which has
2557 attempted to write to a piece of memory under control of
2558 a watchpoint. The instruction hasn't actually executed
2559 yet. If we were to evaluate the watchpoint expression
2560 now, we would get the old value, and therefore no change
2561 would seem to have occurred.
2563 In order to make watchpoints work `right', we really need
2564 to complete the memory write, and then evaluate the
2565 watchpoint expression. We do this by single-stepping the
2568 It may not be necessary to disable the watchpoint to stop over
2569 it. For example, the PA can (with some kernel cooperation)
2570 single step over a watchpoint without disabling the watchpoint.
2572 It is far more common to need to disable a watchpoint to step
2573 the inferior over it. If we have non-steppable watchpoints,
2574 we must disable the current watchpoint; it's simplest to
2575 disable all watchpoints and breakpoints. */
2577 if (!HAVE_STEPPABLE_WATCHPOINT)
2578 remove_breakpoints ();
2579 registers_changed ();
2580 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
2581 waiton_ptid = ecs->ptid;
2582 if (HAVE_STEPPABLE_WATCHPOINT)
2583 infwait_state = infwait_step_watch_state;
2585 infwait_state = infwait_nonstep_watch_state;
2586 prepare_to_wait (ecs);
2590 ecs->stop_func_start = 0;
2591 ecs->stop_func_end = 0;
2592 ecs->stop_func_name = 0;
2593 /* Don't care about return value; stop_func_start and stop_func_name
2594 will both be 0 if it doesn't work. */
2595 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2596 &ecs->stop_func_start, &ecs->stop_func_end);
2597 ecs->stop_func_start
2598 += gdbarch_deprecated_function_start_offset (current_gdbarch);
2599 ecs->event_thread->stepping_over_breakpoint = 0;
2600 bpstat_clear (&ecs->event_thread->stop_bpstat);
2601 ecs->event_thread->stop_step = 0;
2602 stop_print_frame = 1;
2603 ecs->random_signal = 0;
2604 stopped_by_random_signal = 0;
2606 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
2607 && ecs->event_thread->trap_expected
2608 && gdbarch_single_step_through_delay_p (current_gdbarch)
2609 && currently_stepping (ecs->event_thread))
2611 /* We're trying to step off a breakpoint. Turns out that we're
2612 also on an instruction that needs to be stepped multiple
2613 times before it's been fully executing. E.g., architectures
2614 with a delay slot. It needs to be stepped twice, once for
2615 the instruction and once for the delay slot. */
2616 int step_through_delay
2617 = gdbarch_single_step_through_delay (current_gdbarch,
2618 get_current_frame ());
2619 if (debug_infrun && step_through_delay)
2620 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
2621 if (ecs->event_thread->step_range_end == 0 && step_through_delay)
2623 /* The user issued a continue when stopped at a breakpoint.
2624 Set up for another trap and get out of here. */
2625 ecs->event_thread->stepping_over_breakpoint = 1;
2629 else if (step_through_delay)
2631 /* The user issued a step when stopped at a breakpoint.
2632 Maybe we should stop, maybe we should not - the delay
2633 slot *might* correspond to a line of source. In any
2634 case, don't decide that here, just set
2635 ecs->stepping_over_breakpoint, making sure we
2636 single-step again before breakpoints are re-inserted. */
2637 ecs->event_thread->stepping_over_breakpoint = 1;
2641 /* Look at the cause of the stop, and decide what to do.
2642 The alternatives are:
2643 1) stop_stepping and return; to really stop and return to the debugger,
2644 2) keep_going and return to start up again
2645 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
2646 3) set ecs->random_signal to 1, and the decision between 1 and 2
2647 will be made according to the signal handling tables. */
2649 /* First, distinguish signals caused by the debugger from signals
2650 that have to do with the program's own actions. Note that
2651 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2652 on the operating system version. Here we detect when a SIGILL or
2653 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2654 something similar for SIGSEGV, since a SIGSEGV will be generated
2655 when we're trying to execute a breakpoint instruction on a
2656 non-executable stack. This happens for call dummy breakpoints
2657 for architectures like SPARC that place call dummies on the
2660 If we're doing a displaced step past a breakpoint, then the
2661 breakpoint is always inserted at the original instruction;
2662 non-standard signals can't be explained by the breakpoint. */
2663 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
2664 || (! ecs->event_thread->trap_expected
2665 && breakpoint_inserted_here_p (stop_pc)
2666 && (ecs->event_thread->stop_signal == TARGET_SIGNAL_ILL
2667 || ecs->event_thread->stop_signal == TARGET_SIGNAL_SEGV
2668 || ecs->event_thread->stop_signal == TARGET_SIGNAL_EMT))
2669 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
2670 || stop_soon == STOP_QUIETLY_REMOTE)
2672 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
2675 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
2676 stop_print_frame = 0;
2677 stop_stepping (ecs);
2681 /* This is originated from start_remote(), start_inferior() and
2682 shared libraries hook functions. */
2683 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
2686 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
2687 stop_stepping (ecs);
2691 /* This originates from attach_command(). We need to overwrite
2692 the stop_signal here, because some kernels don't ignore a
2693 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2694 See more comments in inferior.h. On the other hand, if we
2695 get a non-SIGSTOP, report it to the user - assume the backend
2696 will handle the SIGSTOP if it should show up later.
2698 Also consider that the attach is complete when we see a
2699 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
2700 target extended-remote report it instead of a SIGSTOP
2701 (e.g. gdbserver). We already rely on SIGTRAP being our
2702 signal, so this is no exception. */
2703 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
2704 && (ecs->event_thread->stop_signal == TARGET_SIGNAL_STOP
2705 || ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP))
2707 stop_stepping (ecs);
2708 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2712 /* See if there is a breakpoint at the current PC. */
2713 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2715 /* Following in case break condition called a
2717 stop_print_frame = 1;
2719 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2720 at one stage in the past included checks for an inferior
2721 function call's call dummy's return breakpoint. The original
2722 comment, that went with the test, read:
2724 ``End of a stack dummy. Some systems (e.g. Sony news) give
2725 another signal besides SIGTRAP, so check here as well as
2728 If someone ever tries to get call dummys on a
2729 non-executable stack to work (where the target would stop
2730 with something like a SIGSEGV), then those tests might need
2731 to be re-instated. Given, however, that the tests were only
2732 enabled when momentary breakpoints were not being used, I
2733 suspect that it won't be the case.
2735 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2736 be necessary for call dummies on a non-executable stack on
2739 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2741 = !(bpstat_explains_signal (ecs->event_thread->stop_bpstat)
2742 || ecs->event_thread->trap_expected
2743 || (ecs->event_thread->step_range_end
2744 && ecs->event_thread->step_resume_breakpoint == NULL));
2747 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2748 if (!ecs->random_signal)
2749 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2753 /* When we reach this point, we've pretty much decided
2754 that the reason for stopping must've been a random
2755 (unexpected) signal. */
2758 ecs->random_signal = 1;
2760 process_event_stop_test:
2761 /* For the program's own signals, act according to
2762 the signal handling tables. */
2764 if (ecs->random_signal)
2766 /* Signal not for debugging purposes. */
2770 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
2771 ecs->event_thread->stop_signal);
2773 stopped_by_random_signal = 1;
2775 if (signal_print[ecs->event_thread->stop_signal])
2778 target_terminal_ours_for_output ();
2779 print_stop_reason (SIGNAL_RECEIVED, ecs->event_thread->stop_signal);
2781 /* Always stop on signals if we're just gaining control of the
2783 if (stop_soon != NO_STOP_QUIETLY
2784 || signal_stop_state (ecs->event_thread->stop_signal))
2786 stop_stepping (ecs);
2789 /* If not going to stop, give terminal back
2790 if we took it away. */
2792 target_terminal_inferior ();
2794 /* Clear the signal if it should not be passed. */
2795 if (signal_program[ecs->event_thread->stop_signal] == 0)
2796 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2798 if (ecs->event_thread->prev_pc == read_pc ()
2799 && ecs->event_thread->trap_expected
2800 && ecs->event_thread->step_resume_breakpoint == NULL)
2802 /* We were just starting a new sequence, attempting to
2803 single-step off of a breakpoint and expecting a SIGTRAP.
2804 Instead this signal arrives. This signal will take us out
2805 of the stepping range so GDB needs to remember to, when
2806 the signal handler returns, resume stepping off that
2808 /* To simplify things, "continue" is forced to use the same
2809 code paths as single-step - set a breakpoint at the
2810 signal return address and then, once hit, step off that
2813 fprintf_unfiltered (gdb_stdlog,
2814 "infrun: signal arrived while stepping over "
2817 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2818 ecs->event_thread->step_after_step_resume_breakpoint = 1;
2823 if (ecs->event_thread->step_range_end != 0
2824 && ecs->event_thread->stop_signal != TARGET_SIGNAL_0
2825 && (ecs->event_thread->step_range_start <= stop_pc
2826 && stop_pc < ecs->event_thread->step_range_end)
2827 && frame_id_eq (get_frame_id (get_current_frame ()),
2828 ecs->event_thread->step_frame_id)
2829 && ecs->event_thread->step_resume_breakpoint == NULL)
2831 /* The inferior is about to take a signal that will take it
2832 out of the single step range. Set a breakpoint at the
2833 current PC (which is presumably where the signal handler
2834 will eventually return) and then allow the inferior to
2837 Note that this is only needed for a signal delivered
2838 while in the single-step range. Nested signals aren't a
2839 problem as they eventually all return. */
2841 fprintf_unfiltered (gdb_stdlog,
2842 "infrun: signal may take us out of "
2843 "single-step range\n");
2845 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2850 /* Note: step_resume_breakpoint may be non-NULL. This occures
2851 when either there's a nested signal, or when there's a
2852 pending signal enabled just as the signal handler returns
2853 (leaving the inferior at the step-resume-breakpoint without
2854 actually executing it). Either way continue until the
2855 breakpoint is really hit. */
2860 /* Handle cases caused by hitting a breakpoint. */
2862 CORE_ADDR jmp_buf_pc;
2863 struct bpstat_what what;
2865 what = bpstat_what (ecs->event_thread->stop_bpstat);
2867 if (what.call_dummy)
2869 stop_stack_dummy = 1;
2872 switch (what.main_action)
2874 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2875 /* If we hit the breakpoint at longjmp while stepping, we
2876 install a momentary breakpoint at the target of the
2880 fprintf_unfiltered (gdb_stdlog,
2881 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2883 ecs->event_thread->stepping_over_breakpoint = 1;
2885 if (!gdbarch_get_longjmp_target_p (current_gdbarch)
2886 || !gdbarch_get_longjmp_target (current_gdbarch,
2887 get_current_frame (), &jmp_buf_pc))
2890 fprintf_unfiltered (gdb_stdlog, "\
2891 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
2896 /* We're going to replace the current step-resume breakpoint
2897 with a longjmp-resume breakpoint. */
2898 delete_step_resume_breakpoint (ecs->event_thread);
2900 /* Insert a breakpoint at resume address. */
2901 insert_longjmp_resume_breakpoint (jmp_buf_pc);
2906 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2908 fprintf_unfiltered (gdb_stdlog,
2909 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2911 gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
2912 delete_step_resume_breakpoint (ecs->event_thread);
2914 ecs->event_thread->stop_step = 1;
2915 print_stop_reason (END_STEPPING_RANGE, 0);
2916 stop_stepping (ecs);
2919 case BPSTAT_WHAT_SINGLE:
2921 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
2922 ecs->event_thread->stepping_over_breakpoint = 1;
2923 /* Still need to check other stuff, at least the case
2924 where we are stepping and step out of the right range. */
2927 case BPSTAT_WHAT_STOP_NOISY:
2929 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2930 stop_print_frame = 1;
2932 /* We are about to nuke the step_resume_breakpointt via the
2933 cleanup chain, so no need to worry about it here. */
2935 stop_stepping (ecs);
2938 case BPSTAT_WHAT_STOP_SILENT:
2940 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2941 stop_print_frame = 0;
2943 /* We are about to nuke the step_resume_breakpoin via the
2944 cleanup chain, so no need to worry about it here. */
2946 stop_stepping (ecs);
2949 case BPSTAT_WHAT_STEP_RESUME:
2951 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2953 delete_step_resume_breakpoint (ecs->event_thread);
2954 if (ecs->event_thread->step_after_step_resume_breakpoint)
2956 /* Back when the step-resume breakpoint was inserted, we
2957 were trying to single-step off a breakpoint. Go back
2959 ecs->event_thread->step_after_step_resume_breakpoint = 0;
2960 ecs->event_thread->stepping_over_breakpoint = 1;
2964 if (stop_pc == ecs->stop_func_start
2965 && execution_direction == EXEC_REVERSE)
2967 /* We are stepping over a function call in reverse, and
2968 just hit the step-resume breakpoint at the start
2969 address of the function. Go back to single-stepping,
2970 which should take us back to the function call. */
2971 ecs->event_thread->stepping_over_breakpoint = 1;
2977 case BPSTAT_WHAT_CHECK_SHLIBS:
2978 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2981 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2983 /* Check for any newly added shared libraries if we're
2984 supposed to be adding them automatically. Switch
2985 terminal for any messages produced by
2986 breakpoint_re_set. */
2987 target_terminal_ours_for_output ();
2988 /* NOTE: cagney/2003-11-25: Make certain that the target
2989 stack's section table is kept up-to-date. Architectures,
2990 (e.g., PPC64), use the section table to perform
2991 operations such as address => section name and hence
2992 require the table to contain all sections (including
2993 those found in shared libraries). */
2994 /* NOTE: cagney/2003-11-25: Pass current_target and not
2995 exec_ops to SOLIB_ADD. This is because current GDB is
2996 only tooled to propagate section_table changes out from
2997 the "current_target" (see target_resize_to_sections), and
2998 not up from the exec stratum. This, of course, isn't
2999 right. "infrun.c" should only interact with the
3000 exec/process stratum, instead relying on the target stack
3001 to propagate relevant changes (stop, section table
3002 changed, ...) up to other layers. */
3004 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
3006 solib_add (NULL, 0, ¤t_target, auto_solib_add);
3008 target_terminal_inferior ();
3010 /* If requested, stop when the dynamic linker notifies
3011 gdb of events. This allows the user to get control
3012 and place breakpoints in initializer routines for
3013 dynamically loaded objects (among other things). */
3014 if (stop_on_solib_events || stop_stack_dummy)
3016 stop_stepping (ecs);
3020 /* If we stopped due to an explicit catchpoint, then the
3021 (see above) call to SOLIB_ADD pulled in any symbols
3022 from a newly-loaded library, if appropriate.
3024 We do want the inferior to stop, but not where it is
3025 now, which is in the dynamic linker callback. Rather,
3026 we would like it stop in the user's program, just after
3027 the call that caused this catchpoint to trigger. That
3028 gives the user a more useful vantage from which to
3029 examine their program's state. */
3030 else if (what.main_action
3031 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
3033 /* ??rehrauer: If I could figure out how to get the
3034 right return PC from here, we could just set a temp
3035 breakpoint and resume. I'm not sure we can without
3036 cracking open the dld's shared libraries and sniffing
3037 their unwind tables and text/data ranges, and that's
3038 not a terribly portable notion.
3040 Until that time, we must step the inferior out of the
3041 dld callback, and also out of the dld itself (and any
3042 code or stubs in libdld.sl, such as "shl_load" and
3043 friends) until we reach non-dld code. At that point,
3044 we can stop stepping. */
3045 bpstat_get_triggered_catchpoints (ecs->event_thread->stop_bpstat,
3048 stepping_through_solib_catchpoints);
3049 ecs->event_thread->stepping_through_solib_after_catch = 1;
3051 /* Be sure to lift all breakpoints, so the inferior does
3052 actually step past this point... */
3053 ecs->event_thread->stepping_over_breakpoint = 1;
3058 /* We want to step over this breakpoint, then keep going. */
3059 ecs->event_thread->stepping_over_breakpoint = 1;
3065 case BPSTAT_WHAT_LAST:
3066 /* Not a real code, but listed here to shut up gcc -Wall. */
3068 case BPSTAT_WHAT_KEEP_CHECKING:
3073 /* We come here if we hit a breakpoint but should not
3074 stop for it. Possibly we also were stepping
3075 and should stop for that. So fall through and
3076 test for stepping. But, if not stepping,
3079 /* Are we stepping to get the inferior out of the dynamic linker's
3080 hook (and possibly the dld itself) after catching a shlib
3082 if (ecs->event_thread->stepping_through_solib_after_catch)
3084 #if defined(SOLIB_ADD)
3085 /* Have we reached our destination? If not, keep going. */
3086 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
3089 fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n");
3090 ecs->event_thread->stepping_over_breakpoint = 1;
3096 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
3097 /* Else, stop and report the catchpoint(s) whose triggering
3098 caused us to begin stepping. */
3099 ecs->event_thread->stepping_through_solib_after_catch = 0;
3100 bpstat_clear (&ecs->event_thread->stop_bpstat);
3101 ecs->event_thread->stop_bpstat
3102 = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints);
3103 bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints);
3104 stop_print_frame = 1;
3105 stop_stepping (ecs);
3109 if (ecs->event_thread->step_resume_breakpoint)
3112 fprintf_unfiltered (gdb_stdlog,
3113 "infrun: step-resume breakpoint is inserted\n");
3115 /* Having a step-resume breakpoint overrides anything
3116 else having to do with stepping commands until
3117 that breakpoint is reached. */
3122 if (ecs->event_thread->step_range_end == 0)
3125 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
3126 /* Likewise if we aren't even stepping. */
3131 /* If stepping through a line, keep going if still within it.
3133 Note that step_range_end is the address of the first instruction
3134 beyond the step range, and NOT the address of the last instruction
3136 if (stop_pc >= ecs->event_thread->step_range_start
3137 && stop_pc < ecs->event_thread->step_range_end)
3140 fprintf_unfiltered (gdb_stdlog, "infrun: stepping inside range [0x%s-0x%s]\n",
3141 paddr_nz (ecs->event_thread->step_range_start),
3142 paddr_nz (ecs->event_thread->step_range_end));
3144 /* When stepping backward, stop at beginning of line range
3145 (unless it's the function entry point, in which case
3146 keep going back to the call point). */
3147 if (stop_pc == ecs->event_thread->step_range_start
3148 && stop_pc != ecs->stop_func_start
3149 && execution_direction == EXEC_REVERSE)
3151 ecs->event_thread->stop_step = 1;
3152 print_stop_reason (END_STEPPING_RANGE, 0);
3153 stop_stepping (ecs);
3161 /* We stepped out of the stepping range. */
3163 /* If we are stepping at the source level and entered the runtime
3164 loader dynamic symbol resolution code, we keep on single stepping
3165 until we exit the run time loader code and reach the callee's
3167 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3168 && in_solib_dynsym_resolve_code (stop_pc))
3170 CORE_ADDR pc_after_resolver =
3171 gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
3174 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n");
3176 if (pc_after_resolver)
3178 /* Set up a step-resume breakpoint at the address
3179 indicated by SKIP_SOLIB_RESOLVER. */
3180 struct symtab_and_line sr_sal;
3182 sr_sal.pc = pc_after_resolver;
3184 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3191 if (ecs->event_thread->step_range_end != 1
3192 && (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3193 || ecs->event_thread->step_over_calls == STEP_OVER_ALL)
3194 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME)
3197 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n");
3198 /* The inferior, while doing a "step" or "next", has ended up in
3199 a signal trampoline (either by a signal being delivered or by
3200 the signal handler returning). Just single-step until the
3201 inferior leaves the trampoline (either by calling the handler
3207 /* Check for subroutine calls. The check for the current frame
3208 equalling the step ID is not necessary - the check of the
3209 previous frame's ID is sufficient - but it is a common case and
3210 cheaper than checking the previous frame's ID.
3212 NOTE: frame_id_eq will never report two invalid frame IDs as
3213 being equal, so to get into this block, both the current and
3214 previous frame must have valid frame IDs. */
3215 if (!frame_id_eq (get_frame_id (get_current_frame ()),
3216 ecs->event_thread->step_frame_id)
3217 && (frame_id_eq (frame_unwind_id (get_current_frame ()),
3218 ecs->event_thread->step_frame_id)
3219 || execution_direction == EXEC_REVERSE))
3221 CORE_ADDR real_stop_pc;
3224 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
3226 if ((ecs->event_thread->step_over_calls == STEP_OVER_NONE)
3227 || ((ecs->event_thread->step_range_end == 1)
3228 && in_prologue (ecs->event_thread->prev_pc,
3229 ecs->stop_func_start)))
3231 /* I presume that step_over_calls is only 0 when we're
3232 supposed to be stepping at the assembly language level
3233 ("stepi"). Just stop. */
3234 /* Also, maybe we just did a "nexti" inside a prolog, so we
3235 thought it was a subroutine call but it was not. Stop as
3237 ecs->event_thread->stop_step = 1;
3238 print_stop_reason (END_STEPPING_RANGE, 0);
3239 stop_stepping (ecs);
3243 if (ecs->event_thread->step_over_calls == STEP_OVER_ALL)
3245 /* We're doing a "next".
3247 Normal (forward) execution: set a breakpoint at the
3248 callee's return address (the address at which the caller
3251 Reverse (backward) execution. set the step-resume
3252 breakpoint at the start of the function that we just
3253 stepped into (backwards), and continue to there. When we
3254 get there, we'll need to single-step back to the
3257 if (execution_direction == EXEC_REVERSE)
3259 struct symtab_and_line sr_sal;
3261 sr_sal.pc = ecs->stop_func_start;
3262 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3265 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3271 /* If we are in a function call trampoline (a stub between the
3272 calling routine and the real function), locate the real
3273 function. That's what tells us (a) whether we want to step
3274 into it at all, and (b) what prologue we want to run to the
3275 end of, if we do step into it. */
3276 real_stop_pc = skip_language_trampoline (get_current_frame (), stop_pc);
3277 if (real_stop_pc == 0)
3278 real_stop_pc = gdbarch_skip_trampoline_code
3279 (current_gdbarch, get_current_frame (), stop_pc);
3280 if (real_stop_pc != 0)
3281 ecs->stop_func_start = real_stop_pc;
3283 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
3285 struct symtab_and_line sr_sal;
3287 sr_sal.pc = ecs->stop_func_start;
3289 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3294 /* If we have line number information for the function we are
3295 thinking of stepping into, step into it.
3297 If there are several symtabs at that PC (e.g. with include
3298 files), just want to know whether *any* of them have line
3299 numbers. find_pc_line handles this. */
3301 struct symtab_and_line tmp_sal;
3303 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
3304 if (tmp_sal.line != 0)
3306 if (execution_direction == EXEC_REVERSE)
3307 handle_step_into_function_backward (ecs);
3309 handle_step_into_function (ecs);
3314 /* If we have no line number and the step-stop-if-no-debug is
3315 set, we stop the step so that the user has a chance to switch
3316 in assembly mode. */
3317 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3318 && step_stop_if_no_debug)
3320 ecs->event_thread->stop_step = 1;
3321 print_stop_reason (END_STEPPING_RANGE, 0);
3322 stop_stepping (ecs);
3326 if (execution_direction == EXEC_REVERSE)
3328 /* Set a breakpoint at callee's start address.
3329 From there we can step once and be back in the caller. */
3330 struct symtab_and_line sr_sal;
3332 sr_sal.pc = ecs->stop_func_start;
3333 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3336 /* Set a breakpoint at callee's return address (the address
3337 at which the caller will resume). */
3338 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3344 /* If we're in the return path from a shared library trampoline,
3345 we want to proceed through the trampoline when stepping. */
3346 if (gdbarch_in_solib_return_trampoline (current_gdbarch,
3347 stop_pc, ecs->stop_func_name))
3349 /* Determine where this trampoline returns. */
3350 CORE_ADDR real_stop_pc;
3351 real_stop_pc = gdbarch_skip_trampoline_code
3352 (current_gdbarch, get_current_frame (), stop_pc);
3355 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n");
3357 /* Only proceed through if we know where it's going. */
3360 /* And put the step-breakpoint there and go until there. */
3361 struct symtab_and_line sr_sal;
3363 init_sal (&sr_sal); /* initialize to zeroes */
3364 sr_sal.pc = real_stop_pc;
3365 sr_sal.section = find_pc_overlay (sr_sal.pc);
3367 /* Do not specify what the fp should be when we stop since
3368 on some machines the prologue is where the new fp value
3370 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3372 /* Restart without fiddling with the step ranges or
3379 stop_pc_sal = find_pc_line (stop_pc, 0);
3381 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3382 the trampoline processing logic, however, there are some trampolines
3383 that have no names, so we should do trampoline handling first. */
3384 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3385 && ecs->stop_func_name == NULL
3386 && stop_pc_sal.line == 0)
3389 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n");
3391 /* The inferior just stepped into, or returned to, an
3392 undebuggable function (where there is no debugging information
3393 and no line number corresponding to the address where the
3394 inferior stopped). Since we want to skip this kind of code,
3395 we keep going until the inferior returns from this
3396 function - unless the user has asked us not to (via
3397 set step-mode) or we no longer know how to get back
3398 to the call site. */
3399 if (step_stop_if_no_debug
3400 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3402 /* If we have no line number and the step-stop-if-no-debug
3403 is set, we stop the step so that the user has a chance to
3404 switch in assembly mode. */
3405 ecs->event_thread->stop_step = 1;
3406 print_stop_reason (END_STEPPING_RANGE, 0);
3407 stop_stepping (ecs);
3412 /* Set a breakpoint at callee's return address (the address
3413 at which the caller will resume). */
3414 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3420 if (ecs->event_thread->step_range_end == 1)
3422 /* It is stepi or nexti. We always want to stop stepping after
3425 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
3426 ecs->event_thread->stop_step = 1;
3427 print_stop_reason (END_STEPPING_RANGE, 0);
3428 stop_stepping (ecs);
3432 if (stop_pc_sal.line == 0)
3434 /* We have no line number information. That means to stop
3435 stepping (does this always happen right after one instruction,
3436 when we do "s" in a function with no line numbers,
3437 or can this happen as a result of a return or longjmp?). */
3439 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
3440 ecs->event_thread->stop_step = 1;
3441 print_stop_reason (END_STEPPING_RANGE, 0);
3442 stop_stepping (ecs);
3446 if ((stop_pc == stop_pc_sal.pc)
3447 && (ecs->event_thread->current_line != stop_pc_sal.line
3448 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
3450 /* We are at the start of a different line. So stop. Note that
3451 we don't stop if we step into the middle of a different line.
3452 That is said to make things like for (;;) statements work
3455 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n");
3456 ecs->event_thread->stop_step = 1;
3457 print_stop_reason (END_STEPPING_RANGE, 0);
3458 stop_stepping (ecs);
3462 /* We aren't done stepping.
3464 Optimize by setting the stepping range to the line.
3465 (We might not be in the original line, but if we entered a
3466 new line in mid-statement, we continue stepping. This makes
3467 things like for(;;) statements work better.) */
3469 ecs->event_thread->step_range_start = stop_pc_sal.pc;
3470 ecs->event_thread->step_range_end = stop_pc_sal.end;
3471 ecs->event_thread->step_frame_id = get_frame_id (get_current_frame ());
3472 ecs->event_thread->current_line = stop_pc_sal.line;
3473 ecs->event_thread->current_symtab = stop_pc_sal.symtab;
3476 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
3480 /* Are we in the middle of stepping? */
3483 currently_stepping (struct thread_info *tp)
3485 return (((tp->step_range_end && tp->step_resume_breakpoint == NULL)
3486 || tp->trap_expected)
3487 || tp->stepping_through_solib_after_catch
3488 || bpstat_should_step ());
3491 /* Inferior has stepped into a subroutine call with source code that
3492 we should not step over. Do step to the first line of code in
3496 handle_step_into_function (struct execution_control_state *ecs)
3499 struct symtab_and_line stop_func_sal, sr_sal;
3501 s = find_pc_symtab (stop_pc);
3502 if (s && s->language != language_asm)
3503 ecs->stop_func_start = gdbarch_skip_prologue (current_gdbarch,
3504 ecs->stop_func_start);
3506 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
3507 /* Use the step_resume_break to step until the end of the prologue,
3508 even if that involves jumps (as it seems to on the vax under
3510 /* If the prologue ends in the middle of a source line, continue to
3511 the end of that source line (if it is still within the function).
3512 Otherwise, just go to end of prologue. */
3513 if (stop_func_sal.end
3514 && stop_func_sal.pc != ecs->stop_func_start
3515 && stop_func_sal.end < ecs->stop_func_end)
3516 ecs->stop_func_start = stop_func_sal.end;
3518 /* Architectures which require breakpoint adjustment might not be able
3519 to place a breakpoint at the computed address. If so, the test
3520 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3521 ecs->stop_func_start to an address at which a breakpoint may be
3522 legitimately placed.
3524 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3525 made, GDB will enter an infinite loop when stepping through
3526 optimized code consisting of VLIW instructions which contain
3527 subinstructions corresponding to different source lines. On
3528 FR-V, it's not permitted to place a breakpoint on any but the
3529 first subinstruction of a VLIW instruction. When a breakpoint is
3530 set, GDB will adjust the breakpoint address to the beginning of
3531 the VLIW instruction. Thus, we need to make the corresponding
3532 adjustment here when computing the stop address. */
3534 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3536 ecs->stop_func_start
3537 = gdbarch_adjust_breakpoint_address (current_gdbarch,
3538 ecs->stop_func_start);
3541 if (ecs->stop_func_start == stop_pc)
3543 /* We are already there: stop now. */
3544 ecs->event_thread->stop_step = 1;
3545 print_stop_reason (END_STEPPING_RANGE, 0);
3546 stop_stepping (ecs);
3551 /* Put the step-breakpoint there and go until there. */
3552 init_sal (&sr_sal); /* initialize to zeroes */
3553 sr_sal.pc = ecs->stop_func_start;
3554 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
3556 /* Do not specify what the fp should be when we stop since on
3557 some machines the prologue is where the new fp value is
3559 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3561 /* And make sure stepping stops right away then. */
3562 ecs->event_thread->step_range_end = ecs->event_thread->step_range_start;
3567 /* Inferior has stepped backward into a subroutine call with source
3568 code that we should not step over. Do step to the beginning of the
3569 last line of code in it. */
3572 handle_step_into_function_backward (struct execution_control_state *ecs)
3575 struct symtab_and_line stop_func_sal, sr_sal;
3577 s = find_pc_symtab (stop_pc);
3578 if (s && s->language != language_asm)
3579 ecs->stop_func_start = gdbarch_skip_prologue (current_gdbarch,
3580 ecs->stop_func_start);
3582 stop_func_sal = find_pc_line (stop_pc, 0);
3584 /* OK, we're just going to keep stepping here. */
3585 if (stop_func_sal.pc == stop_pc)
3587 /* We're there already. Just stop stepping now. */
3588 ecs->event_thread->stop_step = 1;
3589 print_stop_reason (END_STEPPING_RANGE, 0);
3590 stop_stepping (ecs);
3594 /* Else just reset the step range and keep going.
3595 No step-resume breakpoint, they don't work for
3596 epilogues, which can have multiple entry paths. */
3597 ecs->event_thread->step_range_start = stop_func_sal.pc;
3598 ecs->event_thread->step_range_end = stop_func_sal.end;
3604 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3605 This is used to both functions and to skip over code. */
3608 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal,
3609 struct frame_id sr_id)
3611 /* There should never be more than one step-resume or longjmp-resume
3612 breakpoint per thread, so we should never be setting a new
3613 step_resume_breakpoint when one is already active. */
3614 gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL);
3617 fprintf_unfiltered (gdb_stdlog,
3618 "infrun: inserting step-resume breakpoint at 0x%s\n",
3619 paddr_nz (sr_sal.pc));
3621 inferior_thread ()->step_resume_breakpoint
3622 = set_momentary_breakpoint (sr_sal, sr_id, bp_step_resume);
3625 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3626 to skip a potential signal handler.
3628 This is called with the interrupted function's frame. The signal
3629 handler, when it returns, will resume the interrupted function at
3633 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
3635 struct symtab_and_line sr_sal;
3637 gdb_assert (return_frame != NULL);
3638 init_sal (&sr_sal); /* initialize to zeros */
3640 sr_sal.pc = gdbarch_addr_bits_remove
3641 (current_gdbarch, get_frame_pc (return_frame));
3642 sr_sal.section = find_pc_overlay (sr_sal.pc);
3644 insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame));
3647 /* Similar to insert_step_resume_breakpoint_at_frame, except
3648 but a breakpoint at the previous frame's PC. This is used to
3649 skip a function after stepping into it (for "next" or if the called
3650 function has no debugging information).
3652 The current function has almost always been reached by single
3653 stepping a call or return instruction. NEXT_FRAME belongs to the
3654 current function, and the breakpoint will be set at the caller's
3657 This is a separate function rather than reusing
3658 insert_step_resume_breakpoint_at_frame in order to avoid
3659 get_prev_frame, which may stop prematurely (see the implementation
3660 of frame_unwind_id for an example). */
3663 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
3665 struct symtab_and_line sr_sal;
3667 /* We shouldn't have gotten here if we don't know where the call site
3669 gdb_assert (frame_id_p (frame_unwind_id (next_frame)));
3671 init_sal (&sr_sal); /* initialize to zeros */
3673 sr_sal.pc = gdbarch_addr_bits_remove
3674 (current_gdbarch, frame_pc_unwind (next_frame));
3675 sr_sal.section = find_pc_overlay (sr_sal.pc);
3677 insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame));
3680 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
3681 new breakpoint at the target of a jmp_buf. The handling of
3682 longjmp-resume uses the same mechanisms used for handling
3683 "step-resume" breakpoints. */
3686 insert_longjmp_resume_breakpoint (CORE_ADDR pc)
3688 /* There should never be more than one step-resume or longjmp-resume
3689 breakpoint per thread, so we should never be setting a new
3690 longjmp_resume_breakpoint when one is already active. */
3691 gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL);
3694 fprintf_unfiltered (gdb_stdlog,
3695 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
3698 inferior_thread ()->step_resume_breakpoint =
3699 set_momentary_breakpoint_at_pc (pc, bp_longjmp_resume);
3703 stop_stepping (struct execution_control_state *ecs)
3706 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
3708 /* Let callers know we don't want to wait for the inferior anymore. */
3709 ecs->wait_some_more = 0;
3712 /* This function handles various cases where we need to continue
3713 waiting for the inferior. */
3714 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3717 keep_going (struct execution_control_state *ecs)
3719 /* Save the pc before execution, to compare with pc after stop. */
3720 ecs->event_thread->prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
3722 /* If we did not do break;, it means we should keep running the
3723 inferior and not return to debugger. */
3725 if (ecs->event_thread->trap_expected
3726 && ecs->event_thread->stop_signal != TARGET_SIGNAL_TRAP)
3728 /* We took a signal (which we are supposed to pass through to
3729 the inferior, else we'd not get here) and we haven't yet
3730 gotten our trap. Simply continue. */
3731 resume (currently_stepping (ecs->event_thread),
3732 ecs->event_thread->stop_signal);
3736 /* Either the trap was not expected, but we are continuing
3737 anyway (the user asked that this signal be passed to the
3740 The signal was SIGTRAP, e.g. it was our signal, but we
3741 decided we should resume from it.
3743 We're going to run this baby now!
3745 Note that insert_breakpoints won't try to re-insert
3746 already inserted breakpoints. Therefore, we don't
3747 care if breakpoints were already inserted, or not. */
3749 if (ecs->event_thread->stepping_over_breakpoint)
3751 if (! use_displaced_stepping (current_gdbarch))
3752 /* Since we can't do a displaced step, we have to remove
3753 the breakpoint while we step it. To keep things
3754 simple, we remove them all. */
3755 remove_breakpoints ();
3759 struct gdb_exception e;
3760 /* Stop stepping when inserting breakpoints
3762 TRY_CATCH (e, RETURN_MASK_ERROR)
3764 insert_breakpoints ();
3768 stop_stepping (ecs);
3773 ecs->event_thread->trap_expected = ecs->event_thread->stepping_over_breakpoint;
3775 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3776 specifies that such a signal should be delivered to the
3779 Typically, this would occure when a user is debugging a
3780 target monitor on a simulator: the target monitor sets a
3781 breakpoint; the simulator encounters this break-point and
3782 halts the simulation handing control to GDB; GDB, noteing
3783 that the break-point isn't valid, returns control back to the
3784 simulator; the simulator then delivers the hardware
3785 equivalent of a SIGNAL_TRAP to the program being debugged. */
3787 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3788 && !signal_program[ecs->event_thread->stop_signal])
3789 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
3791 resume (currently_stepping (ecs->event_thread),
3792 ecs->event_thread->stop_signal);
3795 prepare_to_wait (ecs);
3798 /* This function normally comes after a resume, before
3799 handle_inferior_event exits. It takes care of any last bits of
3800 housekeeping, and sets the all-important wait_some_more flag. */
3803 prepare_to_wait (struct execution_control_state *ecs)
3806 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
3807 if (infwait_state == infwait_normal_state)
3809 overlay_cache_invalid = 1;
3811 /* We have to invalidate the registers BEFORE calling
3812 target_wait because they can be loaded from the target while
3813 in target_wait. This makes remote debugging a bit more
3814 efficient for those targets that provide critical registers
3815 as part of their normal status mechanism. */
3817 registers_changed ();
3818 waiton_ptid = pid_to_ptid (-1);
3820 /* This is the old end of the while loop. Let everybody know we
3821 want to wait for the inferior some more and get called again
3823 ecs->wait_some_more = 1;
3826 /* Print why the inferior has stopped. We always print something when
3827 the inferior exits, or receives a signal. The rest of the cases are
3828 dealt with later on in normal_stop() and print_it_typical(). Ideally
3829 there should be a call to this function from handle_inferior_event()
3830 each time stop_stepping() is called.*/
3832 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
3834 switch (stop_reason)
3836 case END_STEPPING_RANGE:
3837 /* We are done with a step/next/si/ni command. */
3838 /* For now print nothing. */
3839 /* Print a message only if not in the middle of doing a "step n"
3840 operation for n > 1 */
3841 if (!inferior_thread ()->step_multi
3842 || !inferior_thread ()->stop_step)
3843 if (ui_out_is_mi_like_p (uiout))
3846 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
3849 /* The inferior was terminated by a signal. */
3850 annotate_signalled ();
3851 if (ui_out_is_mi_like_p (uiout))
3854 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
3855 ui_out_text (uiout, "\nProgram terminated with signal ");
3856 annotate_signal_name ();
3857 ui_out_field_string (uiout, "signal-name",
3858 target_signal_to_name (stop_info));
3859 annotate_signal_name_end ();
3860 ui_out_text (uiout, ", ");
3861 annotate_signal_string ();
3862 ui_out_field_string (uiout, "signal-meaning",
3863 target_signal_to_string (stop_info));
3864 annotate_signal_string_end ();
3865 ui_out_text (uiout, ".\n");
3866 ui_out_text (uiout, "The program no longer exists.\n");
3869 /* The inferior program is finished. */
3870 annotate_exited (stop_info);
3873 if (ui_out_is_mi_like_p (uiout))
3874 ui_out_field_string (uiout, "reason",
3875 async_reason_lookup (EXEC_ASYNC_EXITED));
3876 ui_out_text (uiout, "\nProgram exited with code ");
3877 ui_out_field_fmt (uiout, "exit-code", "0%o",
3878 (unsigned int) stop_info);
3879 ui_out_text (uiout, ".\n");
3883 if (ui_out_is_mi_like_p (uiout))
3886 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
3887 ui_out_text (uiout, "\nProgram exited normally.\n");
3889 /* Support the --return-child-result option. */
3890 return_child_result_value = stop_info;
3892 case SIGNAL_RECEIVED:
3893 /* Signal received. The signal table tells us to print about
3896 ui_out_text (uiout, "\nProgram received signal ");
3897 annotate_signal_name ();
3898 if (ui_out_is_mi_like_p (uiout))
3900 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
3901 ui_out_field_string (uiout, "signal-name",
3902 target_signal_to_name (stop_info));
3903 annotate_signal_name_end ();
3904 ui_out_text (uiout, ", ");
3905 annotate_signal_string ();
3906 ui_out_field_string (uiout, "signal-meaning",
3907 target_signal_to_string (stop_info));
3908 annotate_signal_string_end ();
3909 ui_out_text (uiout, ".\n");
3912 /* Reverse execution: target ran out of history info. */
3913 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
3916 internal_error (__FILE__, __LINE__,
3917 _("print_stop_reason: unrecognized enum value"));
3923 /* Here to return control to GDB when the inferior stops for real.
3924 Print appropriate messages, remove breakpoints, give terminal our modes.
3926 STOP_PRINT_FRAME nonzero means print the executing frame
3927 (pc, function, args, file, line number and line text).
3928 BREAKPOINTS_FAILED nonzero means stop was due to error
3929 attempting to insert breakpoints. */
3934 struct target_waitstatus last;
3937 get_last_target_status (&last_ptid, &last);
3939 /* In non-stop mode, we don't want GDB to switch threads behind the
3940 user's back, to avoid races where the user is typing a command to
3941 apply to thread x, but GDB switches to thread y before the user
3942 finishes entering the command. */
3944 /* As with the notification of thread events, we want to delay
3945 notifying the user that we've switched thread context until
3946 the inferior actually stops.
3948 There's no point in saying anything if the inferior has exited.
3949 Note that SIGNALLED here means "exited with a signal", not
3950 "received a signal". */
3952 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
3953 && target_has_execution
3954 && last.kind != TARGET_WAITKIND_SIGNALLED
3955 && last.kind != TARGET_WAITKIND_EXITED)
3957 target_terminal_ours_for_output ();
3958 printf_filtered (_("[Switching to %s]\n"),
3959 target_pid_to_str (inferior_ptid));
3960 annotate_thread_changed ();
3961 previous_inferior_ptid = inferior_ptid;
3964 /* NOTE drow/2004-01-17: Is this still necessary? */
3965 /* Make sure that the current_frame's pc is correct. This
3966 is a correction for setting up the frame info before doing
3967 gdbarch_decr_pc_after_break */
3968 if (target_has_execution)
3969 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3970 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3971 frame code to check for this and sort out any resultant mess.
3972 gdbarch_decr_pc_after_break needs to just go away. */
3973 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3975 if (!breakpoints_always_inserted_mode () && target_has_execution)
3977 if (remove_breakpoints ())
3979 target_terminal_ours_for_output ();
3980 printf_filtered (_("\
3981 Cannot remove breakpoints because program is no longer writable.\n\
3982 It might be running in another process.\n\
3983 Further execution is probably impossible.\n"));
3987 /* If an auto-display called a function and that got a signal,
3988 delete that auto-display to avoid an infinite recursion. */
3990 if (stopped_by_random_signal)
3991 disable_current_display ();
3993 /* Don't print a message if in the middle of doing a "step n"
3994 operation for n > 1 */
3995 if (target_has_execution
3996 && last.kind != TARGET_WAITKIND_SIGNALLED
3997 && last.kind != TARGET_WAITKIND_EXITED
3998 && inferior_thread ()->step_multi
3999 && inferior_thread ()->stop_step)
4002 target_terminal_ours ();
4004 /* Set the current source location. This will also happen if we
4005 display the frame below, but the current SAL will be incorrect
4006 during a user hook-stop function. */
4007 if (target_has_stack && !stop_stack_dummy)
4008 set_current_sal_from_frame (get_current_frame (), 1);
4010 if (!target_has_stack)
4013 if (last.kind == TARGET_WAITKIND_SIGNALLED
4014 || last.kind == TARGET_WAITKIND_EXITED)
4017 /* Select innermost stack frame - i.e., current frame is frame 0,
4018 and current location is based on that.
4019 Don't do this on return from a stack dummy routine,
4020 or if the program has exited. */
4022 if (!stop_stack_dummy)
4024 select_frame (get_current_frame ());
4026 /* Print current location without a level number, if
4027 we have changed functions or hit a breakpoint.
4028 Print source line if we have one.
4029 bpstat_print() contains the logic deciding in detail
4030 what to print, based on the event(s) that just occurred. */
4032 /* If --batch-silent is enabled then there's no need to print the current
4033 source location, and to try risks causing an error message about
4034 missing source files. */
4035 if (stop_print_frame && !batch_silent)
4039 int do_frame_printing = 1;
4040 struct thread_info *tp = inferior_thread ();
4042 bpstat_ret = bpstat_print (tp->stop_bpstat);
4046 /* If we had hit a shared library event breakpoint,
4047 bpstat_print would print out this message. If we hit
4048 an OS-level shared library event, do the same
4050 if (last.kind == TARGET_WAITKIND_LOADED)
4052 printf_filtered (_("Stopped due to shared library event\n"));
4053 source_flag = SRC_LINE; /* something bogus */
4054 do_frame_printing = 0;
4058 /* FIXME: cagney/2002-12-01: Given that a frame ID does
4059 (or should) carry around the function and does (or
4060 should) use that when doing a frame comparison. */
4062 && frame_id_eq (tp->step_frame_id,
4063 get_frame_id (get_current_frame ()))
4064 && step_start_function == find_pc_function (stop_pc))
4065 source_flag = SRC_LINE; /* finished step, just print source line */
4067 source_flag = SRC_AND_LOC; /* print location and source line */
4069 case PRINT_SRC_AND_LOC:
4070 source_flag = SRC_AND_LOC; /* print location and source line */
4072 case PRINT_SRC_ONLY:
4073 source_flag = SRC_LINE;
4076 source_flag = SRC_LINE; /* something bogus */
4077 do_frame_printing = 0;
4080 internal_error (__FILE__, __LINE__, _("Unknown value."));
4083 if (ui_out_is_mi_like_p (uiout))
4086 ui_out_field_int (uiout, "thread-id",
4087 pid_to_thread_id (inferior_ptid));
4090 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end
4091 (uiout, "stopped-threads");
4092 ui_out_field_int (uiout, NULL,
4093 pid_to_thread_id (inferior_ptid));
4094 do_cleanups (back_to);
4097 ui_out_field_string (uiout, "stopped-threads", "all");
4099 /* The behavior of this routine with respect to the source
4101 SRC_LINE: Print only source line
4102 LOCATION: Print only location
4103 SRC_AND_LOC: Print location and source line */
4104 if (do_frame_printing)
4105 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
4107 /* Display the auto-display expressions. */
4112 /* Save the function value return registers, if we care.
4113 We might be about to restore their previous contents. */
4114 if (inferior_thread ()->proceed_to_finish)
4116 /* This should not be necessary. */
4118 regcache_xfree (stop_registers);
4120 /* NB: The copy goes through to the target picking up the value of
4121 all the registers. */
4122 stop_registers = regcache_dup (get_current_regcache ());
4125 if (stop_stack_dummy)
4127 /* Pop the empty frame that contains the stack dummy. POP_FRAME
4128 ends with a setting of the current frame, so we can use that
4130 frame_pop (get_current_frame ());
4131 /* Set stop_pc to what it was before we called the function.
4132 Can't rely on restore_inferior_status because that only gets
4133 called if we don't stop in the called function. */
4134 stop_pc = read_pc ();
4135 select_frame (get_current_frame ());
4139 annotate_stopped ();
4140 if (!suppress_stop_observer
4141 && !(target_has_execution
4142 && last.kind != TARGET_WAITKIND_SIGNALLED
4143 && last.kind != TARGET_WAITKIND_EXITED
4144 && inferior_thread ()->step_multi))
4146 if (!ptid_equal (inferior_ptid, null_ptid))
4147 observer_notify_normal_stop (inferior_thread ()->stop_bpstat);
4149 observer_notify_normal_stop (NULL);
4151 if (target_has_execution
4152 && last.kind != TARGET_WAITKIND_SIGNALLED
4153 && last.kind != TARGET_WAITKIND_EXITED)
4155 /* Delete the breakpoint we stopped at, if it wants to be deleted.
4156 Delete any breakpoint that is to be deleted at the next stop. */
4157 breakpoint_auto_delete (inferior_thread ()->stop_bpstat);
4160 set_running (pid_to_ptid (-1), 0);
4162 set_running (inferior_ptid, 0);
4165 /* Look up the hook_stop and run it (CLI internally handles problem
4166 of stop_command's pre-hook not existing). */
4168 catch_errors (hook_stop_stub, stop_command,
4169 "Error while running hook_stop:\n", RETURN_MASK_ALL);
4174 hook_stop_stub (void *cmd)
4176 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
4181 signal_stop_state (int signo)
4183 return signal_stop[signo];
4187 signal_print_state (int signo)
4189 return signal_print[signo];
4193 signal_pass_state (int signo)
4195 return signal_program[signo];
4199 signal_stop_update (int signo, int state)
4201 int ret = signal_stop[signo];
4202 signal_stop[signo] = state;
4207 signal_print_update (int signo, int state)
4209 int ret = signal_print[signo];
4210 signal_print[signo] = state;
4215 signal_pass_update (int signo, int state)
4217 int ret = signal_program[signo];
4218 signal_program[signo] = state;
4223 sig_print_header (void)
4225 printf_filtered (_("\
4226 Signal Stop\tPrint\tPass to program\tDescription\n"));
4230 sig_print_info (enum target_signal oursig)
4232 char *name = target_signal_to_name (oursig);
4233 int name_padding = 13 - strlen (name);
4235 if (name_padding <= 0)
4238 printf_filtered ("%s", name);
4239 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
4240 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
4241 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
4242 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
4243 printf_filtered ("%s\n", target_signal_to_string (oursig));
4246 /* Specify how various signals in the inferior should be handled. */
4249 handle_command (char *args, int from_tty)
4252 int digits, wordlen;
4253 int sigfirst, signum, siglast;
4254 enum target_signal oursig;
4257 unsigned char *sigs;
4258 struct cleanup *old_chain;
4262 error_no_arg (_("signal to handle"));
4265 /* Allocate and zero an array of flags for which signals to handle. */
4267 nsigs = (int) TARGET_SIGNAL_LAST;
4268 sigs = (unsigned char *) alloca (nsigs);
4269 memset (sigs, 0, nsigs);
4271 /* Break the command line up into args. */
4273 argv = gdb_buildargv (args);
4274 old_chain = make_cleanup_freeargv (argv);
4276 /* Walk through the args, looking for signal oursigs, signal names, and
4277 actions. Signal numbers and signal names may be interspersed with
4278 actions, with the actions being performed for all signals cumulatively
4279 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4281 while (*argv != NULL)
4283 wordlen = strlen (*argv);
4284 for (digits = 0; isdigit ((*argv)[digits]); digits++)
4288 sigfirst = siglast = -1;
4290 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
4292 /* Apply action to all signals except those used by the
4293 debugger. Silently skip those. */
4296 siglast = nsigs - 1;
4298 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
4300 SET_SIGS (nsigs, sigs, signal_stop);
4301 SET_SIGS (nsigs, sigs, signal_print);
4303 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
4305 UNSET_SIGS (nsigs, sigs, signal_program);
4307 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
4309 SET_SIGS (nsigs, sigs, signal_print);
4311 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
4313 SET_SIGS (nsigs, sigs, signal_program);
4315 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
4317 UNSET_SIGS (nsigs, sigs, signal_stop);
4319 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
4321 SET_SIGS (nsigs, sigs, signal_program);
4323 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
4325 UNSET_SIGS (nsigs, sigs, signal_print);
4326 UNSET_SIGS (nsigs, sigs, signal_stop);
4328 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
4330 UNSET_SIGS (nsigs, sigs, signal_program);
4332 else if (digits > 0)
4334 /* It is numeric. The numeric signal refers to our own
4335 internal signal numbering from target.h, not to host/target
4336 signal number. This is a feature; users really should be
4337 using symbolic names anyway, and the common ones like
4338 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
4340 sigfirst = siglast = (int)
4341 target_signal_from_command (atoi (*argv));
4342 if ((*argv)[digits] == '-')
4345 target_signal_from_command (atoi ((*argv) + digits + 1));
4347 if (sigfirst > siglast)
4349 /* Bet he didn't figure we'd think of this case... */
4357 oursig = target_signal_from_name (*argv);
4358 if (oursig != TARGET_SIGNAL_UNKNOWN)
4360 sigfirst = siglast = (int) oursig;
4364 /* Not a number and not a recognized flag word => complain. */
4365 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
4369 /* If any signal numbers or symbol names were found, set flags for
4370 which signals to apply actions to. */
4372 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
4374 switch ((enum target_signal) signum)
4376 case TARGET_SIGNAL_TRAP:
4377 case TARGET_SIGNAL_INT:
4378 if (!allsigs && !sigs[signum])
4380 if (query ("%s is used by the debugger.\n\
4381 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
4387 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4388 gdb_flush (gdb_stdout);
4392 case TARGET_SIGNAL_0:
4393 case TARGET_SIGNAL_DEFAULT:
4394 case TARGET_SIGNAL_UNKNOWN:
4395 /* Make sure that "all" doesn't print these. */
4406 target_notice_signals (inferior_ptid);
4410 /* Show the results. */
4411 sig_print_header ();
4412 for (signum = 0; signum < nsigs; signum++)
4416 sig_print_info (signum);
4421 do_cleanups (old_chain);
4425 xdb_handle_command (char *args, int from_tty)
4428 struct cleanup *old_chain;
4431 error_no_arg (_("xdb command"));
4433 /* Break the command line up into args. */
4435 argv = gdb_buildargv (args);
4436 old_chain = make_cleanup_freeargv (argv);
4437 if (argv[1] != (char *) NULL)
4442 bufLen = strlen (argv[0]) + 20;
4443 argBuf = (char *) xmalloc (bufLen);
4447 enum target_signal oursig;
4449 oursig = target_signal_from_name (argv[0]);
4450 memset (argBuf, 0, bufLen);
4451 if (strcmp (argv[1], "Q") == 0)
4452 sprintf (argBuf, "%s %s", argv[0], "noprint");
4455 if (strcmp (argv[1], "s") == 0)
4457 if (!signal_stop[oursig])
4458 sprintf (argBuf, "%s %s", argv[0], "stop");
4460 sprintf (argBuf, "%s %s", argv[0], "nostop");
4462 else if (strcmp (argv[1], "i") == 0)
4464 if (!signal_program[oursig])
4465 sprintf (argBuf, "%s %s", argv[0], "pass");
4467 sprintf (argBuf, "%s %s", argv[0], "nopass");
4469 else if (strcmp (argv[1], "r") == 0)
4471 if (!signal_print[oursig])
4472 sprintf (argBuf, "%s %s", argv[0], "print");
4474 sprintf (argBuf, "%s %s", argv[0], "noprint");
4480 handle_command (argBuf, from_tty);
4482 printf_filtered (_("Invalid signal handling flag.\n"));
4487 do_cleanups (old_chain);
4490 /* Print current contents of the tables set by the handle command.
4491 It is possible we should just be printing signals actually used
4492 by the current target (but for things to work right when switching
4493 targets, all signals should be in the signal tables). */
4496 signals_info (char *signum_exp, int from_tty)
4498 enum target_signal oursig;
4499 sig_print_header ();
4503 /* First see if this is a symbol name. */
4504 oursig = target_signal_from_name (signum_exp);
4505 if (oursig == TARGET_SIGNAL_UNKNOWN)
4507 /* No, try numeric. */
4509 target_signal_from_command (parse_and_eval_long (signum_exp));
4511 sig_print_info (oursig);
4515 printf_filtered ("\n");
4516 /* These ugly casts brought to you by the native VAX compiler. */
4517 for (oursig = TARGET_SIGNAL_FIRST;
4518 (int) oursig < (int) TARGET_SIGNAL_LAST;
4519 oursig = (enum target_signal) ((int) oursig + 1))
4523 if (oursig != TARGET_SIGNAL_UNKNOWN
4524 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
4525 sig_print_info (oursig);
4528 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4531 struct inferior_status
4533 enum target_signal stop_signal;
4537 int stop_stack_dummy;
4538 int stopped_by_random_signal;
4539 int stepping_over_breakpoint;
4540 CORE_ADDR step_range_start;
4541 CORE_ADDR step_range_end;
4542 struct frame_id step_frame_id;
4543 enum step_over_calls_kind step_over_calls;
4544 CORE_ADDR step_resume_break_address;
4545 int stop_after_trap;
4548 /* These are here because if call_function_by_hand has written some
4549 registers and then decides to call error(), we better not have changed
4551 struct regcache *registers;
4553 /* A frame unique identifier. */
4554 struct frame_id selected_frame_id;
4556 int breakpoint_proceeded;
4557 int restore_stack_info;
4558 int proceed_to_finish;
4562 write_inferior_status_register (struct inferior_status *inf_status, int regno,
4565 int size = register_size (current_gdbarch, regno);
4566 void *buf = alloca (size);
4567 store_signed_integer (buf, size, val);
4568 regcache_raw_write (inf_status->registers, regno, buf);
4571 /* Save all of the information associated with the inferior<==>gdb
4572 connection. INF_STATUS is a pointer to a "struct inferior_status"
4573 (defined in inferior.h). */
4575 struct inferior_status *
4576 save_inferior_status (int restore_stack_info)
4578 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
4579 struct thread_info *tp = inferior_thread ();
4580 struct inferior *inf = current_inferior ();
4582 inf_status->stop_signal = tp->stop_signal;
4583 inf_status->stop_pc = stop_pc;
4584 inf_status->stop_step = tp->stop_step;
4585 inf_status->stop_stack_dummy = stop_stack_dummy;
4586 inf_status->stopped_by_random_signal = stopped_by_random_signal;
4587 inf_status->stepping_over_breakpoint = tp->trap_expected;
4588 inf_status->step_range_start = tp->step_range_start;
4589 inf_status->step_range_end = tp->step_range_end;
4590 inf_status->step_frame_id = tp->step_frame_id;
4591 inf_status->step_over_calls = tp->step_over_calls;
4592 inf_status->stop_after_trap = stop_after_trap;
4593 inf_status->stop_soon = inf->stop_soon;
4594 /* Save original bpstat chain here; replace it with copy of chain.
4595 If caller's caller is walking the chain, they'll be happier if we
4596 hand them back the original chain when restore_inferior_status is
4598 inf_status->stop_bpstat = tp->stop_bpstat;
4599 tp->stop_bpstat = bpstat_copy (tp->stop_bpstat);
4600 inf_status->breakpoint_proceeded = breakpoint_proceeded;
4601 inf_status->restore_stack_info = restore_stack_info;
4602 inf_status->proceed_to_finish = tp->proceed_to_finish;
4604 inf_status->registers = regcache_dup (get_current_regcache ());
4606 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
4611 restore_selected_frame (void *args)
4613 struct frame_id *fid = (struct frame_id *) args;
4614 struct frame_info *frame;
4616 frame = frame_find_by_id (*fid);
4618 /* If inf_status->selected_frame_id is NULL, there was no previously
4622 warning (_("Unable to restore previously selected frame."));
4626 select_frame (frame);
4632 restore_inferior_status (struct inferior_status *inf_status)
4634 struct thread_info *tp = inferior_thread ();
4635 struct inferior *inf = current_inferior ();
4637 tp->stop_signal = inf_status->stop_signal;
4638 stop_pc = inf_status->stop_pc;
4639 tp->stop_step = inf_status->stop_step;
4640 stop_stack_dummy = inf_status->stop_stack_dummy;
4641 stopped_by_random_signal = inf_status->stopped_by_random_signal;
4642 tp->trap_expected = inf_status->stepping_over_breakpoint;
4643 tp->step_range_start = inf_status->step_range_start;
4644 tp->step_range_end = inf_status->step_range_end;
4645 tp->step_frame_id = inf_status->step_frame_id;
4646 tp->step_over_calls = inf_status->step_over_calls;
4647 stop_after_trap = inf_status->stop_after_trap;
4648 inf->stop_soon = inf_status->stop_soon;
4649 bpstat_clear (&tp->stop_bpstat);
4650 tp->stop_bpstat = inf_status->stop_bpstat;
4651 breakpoint_proceeded = inf_status->breakpoint_proceeded;
4652 tp->proceed_to_finish = inf_status->proceed_to_finish;
4654 /* The inferior can be gone if the user types "print exit(0)"
4655 (and perhaps other times). */
4656 if (target_has_execution)
4657 /* NB: The register write goes through to the target. */
4658 regcache_cpy (get_current_regcache (), inf_status->registers);
4659 regcache_xfree (inf_status->registers);
4661 /* FIXME: If we are being called after stopping in a function which
4662 is called from gdb, we should not be trying to restore the
4663 selected frame; it just prints a spurious error message (The
4664 message is useful, however, in detecting bugs in gdb (like if gdb
4665 clobbers the stack)). In fact, should we be restoring the
4666 inferior status at all in that case? . */
4668 if (target_has_stack && inf_status->restore_stack_info)
4670 /* The point of catch_errors is that if the stack is clobbered,
4671 walking the stack might encounter a garbage pointer and
4672 error() trying to dereference it. */
4674 (restore_selected_frame, &inf_status->selected_frame_id,
4675 "Unable to restore previously selected frame:\n",
4676 RETURN_MASK_ERROR) == 0)
4677 /* Error in restoring the selected frame. Select the innermost
4679 select_frame (get_current_frame ());
4687 do_restore_inferior_status_cleanup (void *sts)
4689 restore_inferior_status (sts);
4693 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
4695 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
4699 discard_inferior_status (struct inferior_status *inf_status)
4701 /* See save_inferior_status for info on stop_bpstat. */
4702 bpstat_clear (&inf_status->stop_bpstat);
4703 regcache_xfree (inf_status->registers);
4708 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
4710 struct target_waitstatus last;
4713 get_last_target_status (&last_ptid, &last);
4715 if (last.kind != TARGET_WAITKIND_FORKED)
4718 if (!ptid_equal (last_ptid, pid))
4721 *child_pid = last.value.related_pid;
4726 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
4728 struct target_waitstatus last;
4731 get_last_target_status (&last_ptid, &last);
4733 if (last.kind != TARGET_WAITKIND_VFORKED)
4736 if (!ptid_equal (last_ptid, pid))
4739 *child_pid = last.value.related_pid;
4744 inferior_has_execd (ptid_t pid, char **execd_pathname)
4746 struct target_waitstatus last;
4749 get_last_target_status (&last_ptid, &last);
4751 if (last.kind != TARGET_WAITKIND_EXECD)
4754 if (!ptid_equal (last_ptid, pid))
4757 *execd_pathname = xstrdup (last.value.execd_pathname);
4761 /* Oft used ptids */
4763 ptid_t minus_one_ptid;
4765 /* Create a ptid given the necessary PID, LWP, and TID components. */
4768 ptid_build (int pid, long lwp, long tid)
4778 /* Create a ptid from just a pid. */
4781 pid_to_ptid (int pid)
4783 return ptid_build (pid, 0, 0);
4786 /* Fetch the pid (process id) component from a ptid. */
4789 ptid_get_pid (ptid_t ptid)
4794 /* Fetch the lwp (lightweight process) component from a ptid. */
4797 ptid_get_lwp (ptid_t ptid)
4802 /* Fetch the tid (thread id) component from a ptid. */
4805 ptid_get_tid (ptid_t ptid)
4810 /* ptid_equal() is used to test equality of two ptids. */
4813 ptid_equal (ptid_t ptid1, ptid_t ptid2)
4815 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
4816 && ptid1.tid == ptid2.tid);
4819 /* restore_inferior_ptid() will be used by the cleanup machinery
4820 to restore the inferior_ptid value saved in a call to
4821 save_inferior_ptid(). */
4824 restore_inferior_ptid (void *arg)
4826 ptid_t *saved_ptid_ptr = arg;
4827 inferior_ptid = *saved_ptid_ptr;
4831 /* Save the value of inferior_ptid so that it may be restored by a
4832 later call to do_cleanups(). Returns the struct cleanup pointer
4833 needed for later doing the cleanup. */
4836 save_inferior_ptid (void)
4838 ptid_t *saved_ptid_ptr;
4840 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
4841 *saved_ptid_ptr = inferior_ptid;
4842 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
4846 /* User interface for reverse debugging:
4847 Set exec-direction / show exec-direction commands
4848 (returns error unless target implements to_set_exec_direction method). */
4850 enum exec_direction_kind execution_direction = EXEC_FORWARD;
4851 static const char exec_forward[] = "forward";
4852 static const char exec_reverse[] = "reverse";
4853 static const char *exec_direction = exec_forward;
4854 static const char *exec_direction_names[] = {
4861 set_exec_direction_func (char *args, int from_tty,
4862 struct cmd_list_element *cmd)
4864 if (target_can_execute_reverse)
4866 if (!strcmp (exec_direction, exec_forward))
4867 execution_direction = EXEC_FORWARD;
4868 else if (!strcmp (exec_direction, exec_reverse))
4869 execution_direction = EXEC_REVERSE;
4874 show_exec_direction_func (struct ui_file *out, int from_tty,
4875 struct cmd_list_element *cmd, const char *value)
4877 switch (execution_direction) {
4879 fprintf_filtered (out, _("Forward.\n"));
4882 fprintf_filtered (out, _("Reverse.\n"));
4886 fprintf_filtered (out,
4887 _("Forward (target `%s' does not support exec-direction).\n"),
4893 /* User interface for non-stop mode. */
4896 static int non_stop_1 = 0;
4899 set_non_stop (char *args, int from_tty,
4900 struct cmd_list_element *c)
4902 if (target_has_execution)
4904 non_stop_1 = non_stop;
4905 error (_("Cannot change this setting while the inferior is running."));
4908 non_stop = non_stop_1;
4912 show_non_stop (struct ui_file *file, int from_tty,
4913 struct cmd_list_element *c, const char *value)
4915 fprintf_filtered (file,
4916 _("Controlling the inferior in non-stop mode is %s.\n"),
4922 _initialize_infrun (void)
4926 struct cmd_list_element *c;
4928 add_info ("signals", signals_info, _("\
4929 What debugger does when program gets various signals.\n\
4930 Specify a signal as argument to print info on that signal only."));
4931 add_info_alias ("handle", "signals", 0);
4933 add_com ("handle", class_run, handle_command, _("\
4934 Specify how to handle a signal.\n\
4935 Args are signals and actions to apply to those signals.\n\
4936 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4937 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4938 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4939 The special arg \"all\" is recognized to mean all signals except those\n\
4940 used by the debugger, typically SIGTRAP and SIGINT.\n\
4941 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4942 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4943 Stop means reenter debugger if this signal happens (implies print).\n\
4944 Print means print a message if this signal happens.\n\
4945 Pass means let program see this signal; otherwise program doesn't know.\n\
4946 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4947 Pass and Stop may be combined."));
4950 add_com ("lz", class_info, signals_info, _("\
4951 What debugger does when program gets various signals.\n\
4952 Specify a signal as argument to print info on that signal only."));
4953 add_com ("z", class_run, xdb_handle_command, _("\
4954 Specify how to handle a signal.\n\
4955 Args are signals and actions to apply to those signals.\n\
4956 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4957 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4958 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4959 The special arg \"all\" is recognized to mean all signals except those\n\
4960 used by the debugger, typically SIGTRAP and SIGINT.\n\
4961 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4962 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4963 nopass), \"Q\" (noprint)\n\
4964 Stop means reenter debugger if this signal happens (implies print).\n\
4965 Print means print a message if this signal happens.\n\
4966 Pass means let program see this signal; otherwise program doesn't know.\n\
4967 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4968 Pass and Stop may be combined."));
4972 stop_command = add_cmd ("stop", class_obscure,
4973 not_just_help_class_command, _("\
4974 There is no `stop' command, but you can set a hook on `stop'.\n\
4975 This allows you to set a list of commands to be run each time execution\n\
4976 of the program stops."), &cmdlist);
4978 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
4979 Set inferior debugging."), _("\
4980 Show inferior debugging."), _("\
4981 When non-zero, inferior specific debugging is enabled."),
4984 &setdebuglist, &showdebuglist);
4986 add_setshow_boolean_cmd ("displaced", class_maintenance, &debug_displaced, _("\
4987 Set displaced stepping debugging."), _("\
4988 Show displaced stepping debugging."), _("\
4989 When non-zero, displaced stepping specific debugging is enabled."),
4991 show_debug_displaced,
4992 &setdebuglist, &showdebuglist);
4994 add_setshow_boolean_cmd ("non-stop", no_class,
4996 Set whether gdb controls the inferior in non-stop mode."), _("\
4997 Show whether gdb controls the inferior in non-stop mode."), _("\
4998 When debugging a multi-threaded program and this setting is\n\
4999 off (the default, also called all-stop mode), when one thread stops\n\
5000 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
5001 all other threads in the program while you interact with the thread of\n\
5002 interest. When you continue or step a thread, you can allow the other\n\
5003 threads to run, or have them remain stopped, but while you inspect any\n\
5004 thread's state, all threads stop.\n\
5006 In non-stop mode, when one thread stops, other threads can continue\n\
5007 to run freely. You'll be able to step each thread independently,\n\
5008 leave it stopped or free to run as needed."),
5014 numsigs = (int) TARGET_SIGNAL_LAST;
5015 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
5016 signal_print = (unsigned char *)
5017 xmalloc (sizeof (signal_print[0]) * numsigs);
5018 signal_program = (unsigned char *)
5019 xmalloc (sizeof (signal_program[0]) * numsigs);
5020 for (i = 0; i < numsigs; i++)
5023 signal_print[i] = 1;
5024 signal_program[i] = 1;
5027 /* Signals caused by debugger's own actions
5028 should not be given to the program afterwards. */
5029 signal_program[TARGET_SIGNAL_TRAP] = 0;
5030 signal_program[TARGET_SIGNAL_INT] = 0;
5032 /* Signals that are not errors should not normally enter the debugger. */
5033 signal_stop[TARGET_SIGNAL_ALRM] = 0;
5034 signal_print[TARGET_SIGNAL_ALRM] = 0;
5035 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
5036 signal_print[TARGET_SIGNAL_VTALRM] = 0;
5037 signal_stop[TARGET_SIGNAL_PROF] = 0;
5038 signal_print[TARGET_SIGNAL_PROF] = 0;
5039 signal_stop[TARGET_SIGNAL_CHLD] = 0;
5040 signal_print[TARGET_SIGNAL_CHLD] = 0;
5041 signal_stop[TARGET_SIGNAL_IO] = 0;
5042 signal_print[TARGET_SIGNAL_IO] = 0;
5043 signal_stop[TARGET_SIGNAL_POLL] = 0;
5044 signal_print[TARGET_SIGNAL_POLL] = 0;
5045 signal_stop[TARGET_SIGNAL_URG] = 0;
5046 signal_print[TARGET_SIGNAL_URG] = 0;
5047 signal_stop[TARGET_SIGNAL_WINCH] = 0;
5048 signal_print[TARGET_SIGNAL_WINCH] = 0;
5050 /* These signals are used internally by user-level thread
5051 implementations. (See signal(5) on Solaris.) Like the above
5052 signals, a healthy program receives and handles them as part of
5053 its normal operation. */
5054 signal_stop[TARGET_SIGNAL_LWP] = 0;
5055 signal_print[TARGET_SIGNAL_LWP] = 0;
5056 signal_stop[TARGET_SIGNAL_WAITING] = 0;
5057 signal_print[TARGET_SIGNAL_WAITING] = 0;
5058 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
5059 signal_print[TARGET_SIGNAL_CANCEL] = 0;
5061 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
5062 &stop_on_solib_events, _("\
5063 Set stopping for shared library events."), _("\
5064 Show stopping for shared library events."), _("\
5065 If nonzero, gdb will give control to the user when the dynamic linker\n\
5066 notifies gdb of shared library events. The most common event of interest\n\
5067 to the user would be loading/unloading of a new library."),
5069 show_stop_on_solib_events,
5070 &setlist, &showlist);
5072 add_setshow_enum_cmd ("follow-fork-mode", class_run,
5073 follow_fork_mode_kind_names,
5074 &follow_fork_mode_string, _("\
5075 Set debugger response to a program call of fork or vfork."), _("\
5076 Show debugger response to a program call of fork or vfork."), _("\
5077 A fork or vfork creates a new process. follow-fork-mode can be:\n\
5078 parent - the original process is debugged after a fork\n\
5079 child - the new process is debugged after a fork\n\
5080 The unfollowed process will continue to run.\n\
5081 By default, the debugger will follow the parent process."),
5083 show_follow_fork_mode_string,
5084 &setlist, &showlist);
5086 add_setshow_enum_cmd ("scheduler-locking", class_run,
5087 scheduler_enums, &scheduler_mode, _("\
5088 Set mode for locking scheduler during execution."), _("\
5089 Show mode for locking scheduler during execution."), _("\
5090 off == no locking (threads may preempt at any time)\n\
5091 on == full locking (no thread except the current thread may run)\n\
5092 step == scheduler locked during every single-step operation.\n\
5093 In this mode, no other thread may run during a step command.\n\
5094 Other threads may run while stepping over a function call ('next')."),
5095 set_schedlock_func, /* traps on target vector */
5096 show_scheduler_mode,
5097 &setlist, &showlist);
5099 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
5100 Set mode of the step operation."), _("\
5101 Show mode of the step operation."), _("\
5102 When set, doing a step over a function without debug line information\n\
5103 will stop at the first instruction of that function. Otherwise, the\n\
5104 function is skipped and the step command stops at a different source line."),
5106 show_step_stop_if_no_debug,
5107 &setlist, &showlist);
5109 add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance,
5110 &can_use_displaced_stepping, _("\
5111 Set debugger's willingness to use displaced stepping."), _("\
5112 Show debugger's willingness to use displaced stepping."), _("\
5113 If zero, gdb will not use displaced stepping to step over\n\
5114 breakpoints, even if such is supported by the target."),
5116 show_can_use_displaced_stepping,
5117 &maintenance_set_cmdlist,
5118 &maintenance_show_cmdlist);
5120 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
5121 &exec_direction, _("Set direction of execution.\n\
5122 Options are 'forward' or 'reverse'."),
5123 _("Show direction of execution (forward/reverse)."),
5124 _("Tells gdb whether to execute forward or backward."),
5125 set_exec_direction_func, show_exec_direction_func,
5126 &setlist, &showlist);
5128 /* ptid initializations */
5129 null_ptid = ptid_build (0, 0, 0);
5130 minus_one_ptid = ptid_build (-1, 0, 0);
5131 inferior_ptid = null_ptid;
5132 target_last_wait_ptid = minus_one_ptid;
5133 displaced_step_ptid = null_ptid;
5135 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);