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;
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 original = regcache_read_pc (regcache);
686 copy = gdbarch_displaced_step_location (gdbarch);
687 len = gdbarch_max_insn_length (gdbarch);
689 /* Save the original contents of the copy area. */
690 displaced_step_saved_copy = xmalloc (len);
691 old_cleanups = make_cleanup (free_current_contents,
692 &displaced_step_saved_copy);
693 read_memory (copy, displaced_step_saved_copy, len);
696 fprintf_unfiltered (gdb_stdlog, "displaced: saved 0x%s: ",
698 displaced_step_dump_bytes (gdb_stdlog, displaced_step_saved_copy, len);
701 closure = gdbarch_displaced_step_copy_insn (gdbarch,
702 original, copy, regcache);
704 /* We don't support the fully-simulated case at present. */
705 gdb_assert (closure);
707 make_cleanup (cleanup_displaced_step_closure, closure);
709 /* Resume execution at the copy. */
710 regcache_write_pc (regcache, copy);
712 discard_cleanups (old_cleanups);
715 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to 0x%s\n",
718 /* Save the information we need to fix things up if the step
720 displaced_step_ptid = ptid;
721 displaced_step_gdbarch = gdbarch;
722 displaced_step_closure = closure;
723 displaced_step_original = original;
724 displaced_step_copy = copy;
729 displaced_step_clear_cleanup (void *ignore)
731 displaced_step_clear ();
735 write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, const gdb_byte *myaddr, int len)
737 struct cleanup *ptid_cleanup = save_inferior_ptid ();
738 inferior_ptid = ptid;
739 write_memory (memaddr, myaddr, len);
740 do_cleanups (ptid_cleanup);
744 displaced_step_fixup (ptid_t event_ptid, enum target_signal signal)
746 struct cleanup *old_cleanups;
748 /* Was this event for the pid we displaced? */
749 if (ptid_equal (displaced_step_ptid, null_ptid)
750 || ! ptid_equal (displaced_step_ptid, event_ptid))
753 old_cleanups = make_cleanup (displaced_step_clear_cleanup, 0);
755 /* Restore the contents of the copy area. */
757 ULONGEST len = gdbarch_max_insn_length (displaced_step_gdbarch);
758 write_memory_ptid (displaced_step_ptid, displaced_step_copy,
759 displaced_step_saved_copy, len);
761 fprintf_unfiltered (gdb_stdlog, "displaced: restored 0x%s\n",
762 paddr_nz (displaced_step_copy));
765 /* Did the instruction complete successfully? */
766 if (signal == TARGET_SIGNAL_TRAP)
768 /* Fix up the resulting state. */
769 gdbarch_displaced_step_fixup (displaced_step_gdbarch,
770 displaced_step_closure,
771 displaced_step_original,
773 get_thread_regcache (displaced_step_ptid));
777 /* Since the instruction didn't complete, all we can do is
779 struct regcache *regcache = get_thread_regcache (event_ptid);
780 CORE_ADDR pc = regcache_read_pc (regcache);
781 pc = displaced_step_original + (pc - displaced_step_copy);
782 regcache_write_pc (regcache, pc);
785 do_cleanups (old_cleanups);
787 /* Are there any pending displaced stepping requests? If so, run
789 if (displaced_step_request_queue)
791 struct displaced_step_request *head;
794 head = displaced_step_request_queue;
796 displaced_step_request_queue = head->next;
800 fprintf_unfiltered (gdb_stdlog,
801 "displaced: stepping queued %s now\n",
802 target_pid_to_str (ptid));
805 displaced_step_ptid = null_ptid;
806 displaced_step_prepare (ptid);
807 target_resume (ptid, 1, TARGET_SIGNAL_0);
811 /* Update global variables holding ptids to hold NEW_PTID if they were
814 infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
816 struct displaced_step_request *it;
818 if (ptid_equal (inferior_ptid, old_ptid))
819 inferior_ptid = new_ptid;
821 if (ptid_equal (singlestep_ptid, old_ptid))
822 singlestep_ptid = new_ptid;
824 if (ptid_equal (displaced_step_ptid, old_ptid))
825 displaced_step_ptid = new_ptid;
827 if (ptid_equal (deferred_step_ptid, old_ptid))
828 deferred_step_ptid = new_ptid;
830 for (it = displaced_step_request_queue; it; it = it->next)
831 if (ptid_equal (it->ptid, old_ptid))
838 /* Things to clean up if we QUIT out of resume (). */
840 resume_cleanups (void *ignore)
845 static const char schedlock_off[] = "off";
846 static const char schedlock_on[] = "on";
847 static const char schedlock_step[] = "step";
848 static const char *scheduler_enums[] = {
854 static const char *scheduler_mode = schedlock_off;
856 show_scheduler_mode (struct ui_file *file, int from_tty,
857 struct cmd_list_element *c, const char *value)
859 fprintf_filtered (file, _("\
860 Mode for locking scheduler during execution is \"%s\".\n"),
865 set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
867 if (!target_can_lock_scheduler)
869 scheduler_mode = schedlock_off;
870 error (_("Target '%s' cannot support this command."), target_shortname);
875 /* Resume the inferior, but allow a QUIT. This is useful if the user
876 wants to interrupt some lengthy single-stepping operation
877 (for child processes, the SIGINT goes to the inferior, and so
878 we get a SIGINT random_signal, but for remote debugging and perhaps
879 other targets, that's not true).
881 STEP nonzero if we should step (zero to continue instead).
882 SIG is the signal to give the inferior (zero for none). */
884 resume (int step, enum target_signal sig)
886 int should_resume = 1;
887 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
888 struct regcache *regcache = get_current_regcache ();
889 struct gdbarch *gdbarch = get_regcache_arch (regcache);
890 struct thread_info *tp = inferior_thread ();
891 CORE_ADDR pc = regcache_read_pc (regcache);
895 fprintf_unfiltered (gdb_stdlog,
896 "infrun: resume (step=%d, signal=%d), "
897 "trap_expected=%d\n",
898 step, sig, tp->trap_expected);
900 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
901 over an instruction that causes a page fault without triggering
902 a hardware watchpoint. The kernel properly notices that it shouldn't
903 stop, because the hardware watchpoint is not triggered, but it forgets
904 the step request and continues the program normally.
905 Work around the problem by removing hardware watchpoints if a step is
906 requested, GDB will check for a hardware watchpoint trigger after the
908 if (CANNOT_STEP_HW_WATCHPOINTS && step)
909 remove_hw_watchpoints ();
912 /* Normally, by the time we reach `resume', the breakpoints are either
913 removed or inserted, as appropriate. The exception is if we're sitting
914 at a permanent breakpoint; we need to step over it, but permanent
915 breakpoints can't be removed. So we have to test for it here. */
916 if (breakpoint_here_p (pc) == permanent_breakpoint_here)
918 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
919 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
922 The program is stopped at a permanent breakpoint, but GDB does not know\n\
923 how to step past a permanent breakpoint on this architecture. Try using\n\
924 a command like `return' or `jump' to continue execution."));
927 /* If enabled, step over breakpoints by executing a copy of the
928 instruction at a different address.
930 We can't use displaced stepping when we have a signal to deliver;
931 the comments for displaced_step_prepare explain why. The
932 comments in the handle_inferior event for dealing with 'random
933 signals' explain what we do instead. */
934 if (use_displaced_stepping (gdbarch)
936 && sig == TARGET_SIGNAL_0)
938 if (!displaced_step_prepare (inferior_ptid))
940 /* Got placed in displaced stepping queue. Will be resumed
941 later when all the currently queued displaced stepping
942 requests finish. The thread is not executing at this point,
943 and the call to set_executing will be made later. But we
944 need to call set_running here, since from frontend point of view,
945 the thread is running. */
946 set_running (inferior_ptid, 1);
947 discard_cleanups (old_cleanups);
952 if (step && gdbarch_software_single_step_p (gdbarch))
954 /* Do it the hard way, w/temp breakpoints */
955 if (gdbarch_software_single_step (gdbarch, get_current_frame ()))
957 /* ...and don't ask hardware to do it. */
959 /* and do not pull these breakpoints until after a `wait' in
960 `wait_for_inferior' */
961 singlestep_breakpoints_inserted_p = 1;
962 singlestep_ptid = inferior_ptid;
967 /* If there were any forks/vforks/execs that were caught and are
968 now to be followed, then do so. */
969 switch (pending_follow.kind)
971 case TARGET_WAITKIND_FORKED:
972 case TARGET_WAITKIND_VFORKED:
973 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
978 case TARGET_WAITKIND_EXECD:
979 /* follow_exec is called as soon as the exec event is seen. */
980 pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
987 /* Install inferior's terminal modes. */
988 target_terminal_inferior ();
994 resume_ptid = RESUME_ALL; /* Default */
996 /* If STEP is set, it's a request to use hardware stepping
997 facilities. But in that case, we should never
998 use singlestep breakpoint. */
999 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1001 if (singlestep_breakpoints_inserted_p
1002 && stepping_past_singlestep_breakpoint)
1004 /* The situation here is as follows. In thread T1 we wanted to
1005 single-step. Lacking hardware single-stepping we've
1006 set breakpoint at the PC of the next instruction -- call it
1007 P. After resuming, we've hit that breakpoint in thread T2.
1008 Now we've removed original breakpoint, inserted breakpoint
1009 at P+1, and try to step to advance T2 past breakpoint.
1010 We need to step only T2, as if T1 is allowed to freely run,
1011 it can run past P, and if other threads are allowed to run,
1012 they can hit breakpoint at P+1, and nested hits of single-step
1013 breakpoints is not something we'd want -- that's complicated
1014 to support, and has no value. */
1015 resume_ptid = inferior_ptid;
1018 if ((step || singlestep_breakpoints_inserted_p)
1019 && tp->trap_expected)
1021 /* We're allowing a thread to run past a breakpoint it has
1022 hit, by single-stepping the thread with the breakpoint
1023 removed. In which case, we need to single-step only this
1024 thread, and keep others stopped, as they can miss this
1025 breakpoint if allowed to run.
1027 The current code actually removes all breakpoints when
1028 doing this, not just the one being stepped over, so if we
1029 let other threads run, we can actually miss any
1030 breakpoint, not just the one at PC. */
1031 resume_ptid = inferior_ptid;
1036 /* With non-stop mode on, threads are always handled
1038 resume_ptid = inferior_ptid;
1040 else if ((scheduler_mode == schedlock_on)
1041 || (scheduler_mode == schedlock_step
1042 && (step || singlestep_breakpoints_inserted_p)))
1044 /* User-settable 'scheduler' mode requires solo thread resume. */
1045 resume_ptid = inferior_ptid;
1048 if (gdbarch_cannot_step_breakpoint (gdbarch))
1050 /* Most targets can step a breakpoint instruction, thus
1051 executing it normally. But if this one cannot, just
1052 continue and we will hit it anyway. */
1053 if (step && breakpoint_inserted_here_p (pc))
1058 && use_displaced_stepping (gdbarch)
1059 && tp->trap_expected)
1061 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1062 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1065 fprintf_unfiltered (gdb_stdlog, "displaced: run 0x%s: ",
1066 paddr_nz (actual_pc));
1067 read_memory (actual_pc, buf, sizeof (buf));
1068 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1071 target_resume (resume_ptid, step, sig);
1073 /* Avoid confusing the next resume, if the next stop/resume
1074 happens to apply to another thread. */
1075 tp->stop_signal = TARGET_SIGNAL_0;
1078 discard_cleanups (old_cleanups);
1083 /* Clear out all variables saying what to do when inferior is continued.
1084 First do this, then set the ones you want, then call `proceed'. */
1087 clear_proceed_status (void)
1089 if (!ptid_equal (inferior_ptid, null_ptid))
1091 struct thread_info *tp;
1092 struct inferior *inferior;
1094 tp = inferior_thread ();
1096 tp->trap_expected = 0;
1097 tp->step_range_start = 0;
1098 tp->step_range_end = 0;
1099 tp->step_frame_id = null_frame_id;
1100 tp->step_over_calls = STEP_OVER_UNDEBUGGABLE;
1104 tp->proceed_to_finish = 0;
1106 /* Discard any remaining commands or status from previous
1108 bpstat_clear (&tp->stop_bpstat);
1110 inferior = current_inferior ();
1111 inferior->stop_soon = NO_STOP_QUIETLY;
1114 stop_after_trap = 0;
1115 breakpoint_proceeded = 1; /* We're about to proceed... */
1119 regcache_xfree (stop_registers);
1120 stop_registers = NULL;
1124 /* This should be suitable for any targets that support threads. */
1127 prepare_to_proceed (int step)
1130 struct target_waitstatus wait_status;
1132 /* Get the last target status returned by target_wait(). */
1133 get_last_target_status (&wait_ptid, &wait_status);
1135 /* Make sure we were stopped at a breakpoint. */
1136 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1137 || wait_status.value.sig != TARGET_SIGNAL_TRAP)
1142 /* Switched over from WAIT_PID. */
1143 if (!ptid_equal (wait_ptid, minus_one_ptid)
1144 && !ptid_equal (inferior_ptid, wait_ptid))
1146 struct regcache *regcache = get_thread_regcache (wait_ptid);
1148 if (breakpoint_here_p (regcache_read_pc (regcache)))
1150 /* If stepping, remember current thread to switch back to. */
1152 deferred_step_ptid = inferior_ptid;
1154 /* Switch back to WAIT_PID thread. */
1155 switch_to_thread (wait_ptid);
1157 /* We return 1 to indicate that there is a breakpoint here,
1158 so we need to step over it before continuing to avoid
1159 hitting it straight away. */
1167 /* Basic routine for continuing the program in various fashions.
1169 ADDR is the address to resume at, or -1 for resume where stopped.
1170 SIGGNAL is the signal to give it, or 0 for none,
1171 or -1 for act according to how it stopped.
1172 STEP is nonzero if should trap after one instruction.
1173 -1 means return after that and print nothing.
1174 You should probably set various step_... variables
1175 before calling here, if you are stepping.
1177 You should call clear_proceed_status before calling proceed. */
1180 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
1182 struct regcache *regcache = get_current_regcache ();
1183 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1184 struct thread_info *tp;
1185 CORE_ADDR pc = regcache_read_pc (regcache);
1187 enum target_signal stop_signal;
1190 step_start_function = find_pc_function (pc);
1192 stop_after_trap = 1;
1194 if (addr == (CORE_ADDR) -1)
1196 if (pc == stop_pc && breakpoint_here_p (pc))
1197 /* There is a breakpoint at the address we will resume at,
1198 step one instruction before inserting breakpoints so that
1199 we do not stop right away (and report a second hit at this
1202 else if (gdbarch_single_step_through_delay_p (gdbarch)
1203 && gdbarch_single_step_through_delay (gdbarch,
1204 get_current_frame ()))
1205 /* We stepped onto an instruction that needs to be stepped
1206 again before re-inserting the breakpoint, do so. */
1211 regcache_write_pc (regcache, addr);
1215 fprintf_unfiltered (gdb_stdlog,
1216 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1217 paddr_nz (addr), siggnal, step);
1220 /* In non-stop, each thread is handled individually. The context
1221 must already be set to the right thread here. */
1225 /* In a multi-threaded task we may select another thread and
1226 then continue or step.
1228 But if the old thread was stopped at a breakpoint, it will
1229 immediately cause another breakpoint stop without any
1230 execution (i.e. it will report a breakpoint hit incorrectly).
1231 So we must step over it first.
1233 prepare_to_proceed checks the current thread against the
1234 thread that reported the most recent event. If a step-over
1235 is required it returns TRUE and sets the current thread to
1237 if (prepare_to_proceed (step))
1241 /* prepare_to_proceed may change the current thread. */
1242 tp = inferior_thread ();
1246 tp->trap_expected = 1;
1247 /* If displaced stepping is enabled, we can step over the
1248 breakpoint without hitting it, so leave all breakpoints
1249 inserted. Otherwise we need to disable all breakpoints, step
1250 one instruction, and then re-add them when that step is
1252 if (!use_displaced_stepping (gdbarch))
1253 remove_breakpoints ();
1256 /* We can insert breakpoints if we're not trying to step over one,
1257 or if we are stepping over one but we're using displaced stepping
1259 if (! tp->trap_expected || use_displaced_stepping (gdbarch))
1260 insert_breakpoints ();
1264 /* Pass the last stop signal to the thread we're resuming,
1265 irrespective of whether the current thread is the thread that
1266 got the last event or not. This was historically GDB's
1267 behaviour before keeping a stop_signal per thread. */
1269 struct thread_info *last_thread;
1271 struct target_waitstatus last_status;
1273 get_last_target_status (&last_ptid, &last_status);
1274 if (!ptid_equal (inferior_ptid, last_ptid)
1275 && !ptid_equal (last_ptid, null_ptid)
1276 && !ptid_equal (last_ptid, minus_one_ptid))
1278 last_thread = find_thread_pid (last_ptid);
1281 tp->stop_signal = last_thread->stop_signal;
1282 last_thread->stop_signal = TARGET_SIGNAL_0;
1287 if (siggnal != TARGET_SIGNAL_DEFAULT)
1288 tp->stop_signal = siggnal;
1289 /* If this signal should not be seen by program,
1290 give it zero. Used for debugging signals. */
1291 else if (!signal_program[tp->stop_signal])
1292 tp->stop_signal = TARGET_SIGNAL_0;
1294 annotate_starting ();
1296 /* Make sure that output from GDB appears before output from the
1298 gdb_flush (gdb_stdout);
1300 /* Refresh prev_pc value just prior to resuming. This used to be
1301 done in stop_stepping, however, setting prev_pc there did not handle
1302 scenarios such as inferior function calls or returning from
1303 a function via the return command. In those cases, the prev_pc
1304 value was not set properly for subsequent commands. The prev_pc value
1305 is used to initialize the starting line number in the ecs. With an
1306 invalid value, the gdb next command ends up stopping at the position
1307 represented by the next line table entry past our start position.
1308 On platforms that generate one line table entry per line, this
1309 is not a problem. However, on the ia64, the compiler generates
1310 extraneous line table entries that do not increase the line number.
1311 When we issue the gdb next command on the ia64 after an inferior call
1312 or a return command, we often end up a few instructions forward, still
1313 within the original line we started.
1315 An attempt was made to have init_execution_control_state () refresh
1316 the prev_pc value before calculating the line number. This approach
1317 did not work because on platforms that use ptrace, the pc register
1318 cannot be read unless the inferior is stopped. At that point, we
1319 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1320 call can fail. Setting the prev_pc value here ensures the value is
1321 updated correctly when the inferior is stopped. */
1322 tp->prev_pc = regcache_read_pc (get_current_regcache ());
1324 /* Fill in with reasonable starting values. */
1325 init_thread_stepping_state (tp);
1327 /* Reset to normal state. */
1328 init_infwait_state ();
1330 /* Resume inferior. */
1331 resume (oneproc || step || bpstat_should_step (), tp->stop_signal);
1333 /* Wait for it to stop (if not standalone)
1334 and in any case decode why it stopped, and act accordingly. */
1335 /* Do this only if we are not using the event loop, or if the target
1336 does not support asynchronous execution. */
1337 if (!target_can_async_p ())
1339 wait_for_inferior (0);
1345 /* Start remote-debugging of a machine over a serial link. */
1348 start_remote (int from_tty)
1350 struct inferior *inferior;
1351 init_wait_for_inferior ();
1353 inferior = current_inferior ();
1354 inferior->stop_soon = STOP_QUIETLY_REMOTE;
1356 /* Always go on waiting for the target, regardless of the mode. */
1357 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1358 indicate to wait_for_inferior that a target should timeout if
1359 nothing is returned (instead of just blocking). Because of this,
1360 targets expecting an immediate response need to, internally, set
1361 things up so that the target_wait() is forced to eventually
1363 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1364 differentiate to its caller what the state of the target is after
1365 the initial open has been performed. Here we're assuming that
1366 the target has stopped. It should be possible to eventually have
1367 target_open() return to the caller an indication that the target
1368 is currently running and GDB state should be set to the same as
1369 for an async run. */
1370 wait_for_inferior (0);
1372 /* Now that the inferior has stopped, do any bookkeeping like
1373 loading shared libraries. We want to do this before normal_stop,
1374 so that the displayed frame is up to date. */
1375 post_create_inferior (¤t_target, from_tty);
1380 /* Initialize static vars when a new inferior begins. */
1383 init_wait_for_inferior (void)
1385 /* These are meaningless until the first time through wait_for_inferior. */
1387 breakpoint_init_inferior (inf_starting);
1389 /* The first resume is not following a fork/vfork/exec. */
1390 pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */
1392 clear_proceed_status ();
1394 stepping_past_singlestep_breakpoint = 0;
1395 deferred_step_ptid = null_ptid;
1397 target_last_wait_ptid = minus_one_ptid;
1399 previous_inferior_ptid = null_ptid;
1400 init_infwait_state ();
1402 displaced_step_clear ();
1406 /* This enum encodes possible reasons for doing a target_wait, so that
1407 wfi can call target_wait in one place. (Ultimately the call will be
1408 moved out of the infinite loop entirely.) */
1412 infwait_normal_state,
1413 infwait_thread_hop_state,
1414 infwait_step_watch_state,
1415 infwait_nonstep_watch_state
1418 /* Why did the inferior stop? Used to print the appropriate messages
1419 to the interface from within handle_inferior_event(). */
1420 enum inferior_stop_reason
1422 /* Step, next, nexti, stepi finished. */
1424 /* Inferior terminated by signal. */
1426 /* Inferior exited. */
1428 /* Inferior received signal, and user asked to be notified. */
1432 /* The PTID we'll do a target_wait on.*/
1435 /* Current inferior wait state. */
1436 enum infwait_states infwait_state;
1438 /* Data to be passed around while handling an event. This data is
1439 discarded between events. */
1440 struct execution_control_state
1443 /* The thread that got the event, if this was a thread event; NULL
1445 struct thread_info *event_thread;
1447 struct target_waitstatus ws;
1449 CORE_ADDR stop_func_start;
1450 CORE_ADDR stop_func_end;
1451 char *stop_func_name;
1452 int new_thread_event;
1456 void init_execution_control_state (struct execution_control_state *ecs);
1458 void handle_inferior_event (struct execution_control_state *ecs);
1460 static void step_into_function (struct execution_control_state *ecs);
1461 static void insert_step_resume_breakpoint_at_frame (struct frame_info *step_frame);
1462 static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
1463 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal,
1464 struct frame_id sr_id);
1465 static void insert_longjmp_resume_breakpoint (CORE_ADDR);
1467 static void stop_stepping (struct execution_control_state *ecs);
1468 static void prepare_to_wait (struct execution_control_state *ecs);
1469 static void keep_going (struct execution_control_state *ecs);
1470 static void print_stop_reason (enum inferior_stop_reason stop_reason,
1473 /* Callback for iterate_over_threads. */
1476 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
1478 if (is_exited (info->ptid))
1481 delete_step_resume_breakpoint (info);
1485 /* In all-stop, delete the step resume breakpoint of any thread that
1486 had one. In non-stop, delete the step resume breakpoint of the
1487 thread that just stopped. */
1490 delete_step_thread_step_resume_breakpoint (void)
1492 if (!target_has_execution
1493 || ptid_equal (inferior_ptid, null_ptid))
1494 /* If the inferior has exited, we have already deleted the step
1495 resume breakpoints out of GDB's lists. */
1500 /* If in non-stop mode, only delete the step-resume or
1501 longjmp-resume breakpoint of the thread that just stopped
1503 struct thread_info *tp = inferior_thread ();
1504 delete_step_resume_breakpoint (tp);
1507 /* In all-stop mode, delete all step-resume and longjmp-resume
1508 breakpoints of any thread that had them. */
1509 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
1512 /* A cleanup wrapper. */
1515 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
1517 delete_step_thread_step_resume_breakpoint ();
1520 /* Wait for control to return from inferior to debugger.
1522 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1523 as if they were SIGTRAP signals. This can be useful during
1524 the startup sequence on some targets such as HP/UX, where
1525 we receive an EXEC event instead of the expected SIGTRAP.
1527 If inferior gets a signal, we may decide to start it up again
1528 instead of returning. That is why there is a loop in this function.
1529 When this function actually returns it means the inferior
1530 should be left stopped and GDB should read more commands. */
1533 wait_for_inferior (int treat_exec_as_sigtrap)
1535 struct cleanup *old_cleanups;
1536 struct execution_control_state ecss;
1537 struct execution_control_state *ecs;
1541 (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1542 treat_exec_as_sigtrap);
1545 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
1548 memset (ecs, 0, sizeof (*ecs));
1550 overlay_cache_invalid = 1;
1552 /* We'll update this if & when we switch to a new thread. */
1553 previous_inferior_ptid = inferior_ptid;
1555 /* We have to invalidate the registers BEFORE calling target_wait
1556 because they can be loaded from the target while in target_wait.
1557 This makes remote debugging a bit more efficient for those
1558 targets that provide critical registers as part of their normal
1559 status mechanism. */
1561 registers_changed ();
1565 if (deprecated_target_wait_hook)
1566 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
1568 ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
1570 if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD)
1572 xfree (ecs->ws.value.execd_pathname);
1573 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
1574 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
1577 /* Now figure out what to do with the result of the result. */
1578 handle_inferior_event (ecs);
1580 if (!ecs->wait_some_more)
1584 do_cleanups (old_cleanups);
1587 /* Asynchronous version of wait_for_inferior. It is called by the
1588 event loop whenever a change of state is detected on the file
1589 descriptor corresponding to the target. It can be called more than
1590 once to complete a single execution command. In such cases we need
1591 to keep the state in a global variable ECSS. If it is the last time
1592 that this function is called for a single execution command, then
1593 report to the user that the inferior has stopped, and do the
1594 necessary cleanups. */
1597 fetch_inferior_event (void *client_data)
1599 struct execution_control_state ecss;
1600 struct execution_control_state *ecs = &ecss;
1601 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
1602 int was_sync = sync_execution;
1604 memset (ecs, 0, sizeof (*ecs));
1606 overlay_cache_invalid = 1;
1608 /* We can only rely on wait_for_more being correct before handling
1609 the event in all-stop, but previous_inferior_ptid isn't used in
1611 if (!ecs->wait_some_more)
1612 /* We'll update this if & when we switch to a new thread. */
1613 previous_inferior_ptid = inferior_ptid;
1616 /* In non-stop mode, the user/frontend should not notice a thread
1617 switch due to internal events. Make sure we reverse to the
1618 user selected thread and frame after handling the event and
1619 running any breakpoint commands. */
1620 make_cleanup_restore_current_thread ();
1622 /* We have to invalidate the registers BEFORE calling target_wait
1623 because they can be loaded from the target while in target_wait.
1624 This makes remote debugging a bit more efficient for those
1625 targets that provide critical registers as part of their normal
1626 status mechanism. */
1628 registers_changed ();
1630 if (deprecated_target_wait_hook)
1632 deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
1634 ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
1637 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
1638 && ecs->ws.kind != TARGET_WAITKIND_EXITED
1639 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
1640 /* In non-stop mode, each thread is handled individually. Switch
1641 early, so the global state is set correctly for this
1643 context_switch (ecs->ptid);
1645 /* Now figure out what to do with the result of the result. */
1646 handle_inferior_event (ecs);
1648 if (!ecs->wait_some_more)
1650 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
1652 delete_step_thread_step_resume_breakpoint ();
1654 /* We may not find an inferior if this was a process exit. */
1655 if (inf == NULL || inf->stop_soon == NO_STOP_QUIETLY)
1658 if (target_has_execution
1659 && ecs->ws.kind != TARGET_WAITKIND_EXITED
1660 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1661 && ecs->event_thread->step_multi
1662 && ecs->event_thread->stop_step)
1663 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
1665 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
1668 /* Revert thread and frame. */
1669 do_cleanups (old_chain);
1671 /* If the inferior was in sync execution mode, and now isn't,
1672 restore the prompt. */
1673 if (was_sync && !sync_execution)
1674 display_gdb_prompt (0);
1677 /* Prepare an execution control state for looping through a
1678 wait_for_inferior-type loop. */
1681 init_execution_control_state (struct execution_control_state *ecs)
1683 ecs->random_signal = 0;
1686 /* Clear context switchable stepping state. */
1689 init_thread_stepping_state (struct thread_info *tss)
1691 struct symtab_and_line sal;
1693 tss->stepping_over_breakpoint = 0;
1694 tss->step_after_step_resume_breakpoint = 0;
1695 tss->stepping_through_solib_after_catch = 0;
1696 tss->stepping_through_solib_catchpoints = NULL;
1698 sal = find_pc_line (tss->prev_pc, 0);
1699 tss->current_line = sal.line;
1700 tss->current_symtab = sal.symtab;
1703 /* Return the cached copy of the last pid/waitstatus returned by
1704 target_wait()/deprecated_target_wait_hook(). The data is actually
1705 cached by handle_inferior_event(), which gets called immediately
1706 after target_wait()/deprecated_target_wait_hook(). */
1709 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
1711 *ptidp = target_last_wait_ptid;
1712 *status = target_last_waitstatus;
1716 nullify_last_target_wait_ptid (void)
1718 target_last_wait_ptid = minus_one_ptid;
1721 /* Switch thread contexts. */
1724 context_switch (ptid_t ptid)
1728 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
1729 target_pid_to_str (inferior_ptid));
1730 fprintf_unfiltered (gdb_stdlog, "to %s\n",
1731 target_pid_to_str (ptid));
1734 switch_to_thread (ptid);
1738 adjust_pc_after_break (struct execution_control_state *ecs)
1740 struct regcache *regcache;
1741 struct gdbarch *gdbarch;
1742 CORE_ADDR breakpoint_pc;
1744 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1745 we aren't, just return.
1747 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1748 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1749 implemented by software breakpoints should be handled through the normal
1752 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1753 different signals (SIGILL or SIGEMT for instance), but it is less
1754 clear where the PC is pointing afterwards. It may not match
1755 gdbarch_decr_pc_after_break. I don't know any specific target that
1756 generates these signals at breakpoints (the code has been in GDB since at
1757 least 1992) so I can not guess how to handle them here.
1759 In earlier versions of GDB, a target with
1760 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1761 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1762 target with both of these set in GDB history, and it seems unlikely to be
1763 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1765 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
1768 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
1771 /* If this target does not decrement the PC after breakpoints, then
1772 we have nothing to do. */
1773 regcache = get_thread_regcache (ecs->ptid);
1774 gdbarch = get_regcache_arch (regcache);
1775 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
1778 /* Find the location where (if we've hit a breakpoint) the
1779 breakpoint would be. */
1780 breakpoint_pc = regcache_read_pc (regcache)
1781 - gdbarch_decr_pc_after_break (gdbarch);
1783 /* Check whether there actually is a software breakpoint inserted
1784 at that location. */
1785 if (software_breakpoint_inserted_here_p (breakpoint_pc))
1787 /* When using hardware single-step, a SIGTRAP is reported for both
1788 a completed single-step and a software breakpoint. Need to
1789 differentiate between the two, as the latter needs adjusting
1790 but the former does not.
1792 The SIGTRAP can be due to a completed hardware single-step only if
1793 - we didn't insert software single-step breakpoints
1794 - the thread to be examined is still the current thread
1795 - this thread is currently being stepped
1797 If any of these events did not occur, we must have stopped due
1798 to hitting a software breakpoint, and have to back up to the
1801 As a special case, we could have hardware single-stepped a
1802 software breakpoint. In this case (prev_pc == breakpoint_pc),
1803 we also need to back up to the breakpoint address. */
1805 if (singlestep_breakpoints_inserted_p
1806 || !ptid_equal (ecs->ptid, inferior_ptid)
1807 || !currently_stepping (ecs->event_thread)
1808 || ecs->event_thread->prev_pc == breakpoint_pc)
1809 regcache_write_pc (regcache, breakpoint_pc);
1814 init_infwait_state (void)
1816 waiton_ptid = pid_to_ptid (-1);
1817 infwait_state = infwait_normal_state;
1821 error_is_running (void)
1824 Cannot execute this command while the selected thread is running."));
1828 ensure_not_running (void)
1830 if (is_running (inferior_ptid))
1831 error_is_running ();
1834 /* Given an execution control state that has been freshly filled in
1835 by an event from the inferior, figure out what it means and take
1836 appropriate action. */
1839 handle_inferior_event (struct execution_control_state *ecs)
1841 int sw_single_step_trap_p = 0;
1842 int stopped_by_watchpoint;
1843 int stepped_after_stopped_by_watchpoint = 0;
1844 struct symtab_and_line stop_pc_sal;
1845 enum stop_kind stop_soon;
1847 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1848 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
1849 && ecs->ws.kind != TARGET_WAITKIND_IGNORE)
1851 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
1853 stop_soon = inf->stop_soon;
1856 stop_soon = NO_STOP_QUIETLY;
1858 breakpoint_retire_moribund ();
1860 /* Cache the last pid/waitstatus. */
1861 target_last_wait_ptid = ecs->ptid;
1862 target_last_waitstatus = ecs->ws;
1864 /* Always clear state belonging to the previous time we stopped. */
1865 stop_stack_dummy = 0;
1867 /* If it's a new process, add it to the thread database */
1869 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
1870 && !ptid_equal (ecs->ptid, minus_one_ptid)
1871 && !in_thread_list (ecs->ptid));
1873 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
1874 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
1875 add_thread (ecs->ptid);
1877 ecs->event_thread = find_thread_pid (ecs->ptid);
1879 /* Dependent on valid ECS->EVENT_THREAD. */
1880 adjust_pc_after_break (ecs);
1882 /* Dependent on the current PC value modified by adjust_pc_after_break. */
1883 reinit_frame_cache ();
1885 if (ecs->ws.kind != TARGET_WAITKIND_IGNORE)
1887 /* Mark the non-executing threads accordingly. */
1889 || ecs->ws.kind == TARGET_WAITKIND_EXITED
1890 || ecs->ws.kind == TARGET_WAITKIND_SIGNALLED)
1891 set_executing (pid_to_ptid (-1), 0);
1893 set_executing (ecs->ptid, 0);
1896 switch (infwait_state)
1898 case infwait_thread_hop_state:
1900 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
1901 /* Cancel the waiton_ptid. */
1902 waiton_ptid = pid_to_ptid (-1);
1905 case infwait_normal_state:
1907 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
1910 case infwait_step_watch_state:
1912 fprintf_unfiltered (gdb_stdlog,
1913 "infrun: infwait_step_watch_state\n");
1915 stepped_after_stopped_by_watchpoint = 1;
1918 case infwait_nonstep_watch_state:
1920 fprintf_unfiltered (gdb_stdlog,
1921 "infrun: infwait_nonstep_watch_state\n");
1922 insert_breakpoints ();
1924 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1925 handle things like signals arriving and other things happening
1926 in combination correctly? */
1927 stepped_after_stopped_by_watchpoint = 1;
1931 internal_error (__FILE__, __LINE__, _("bad switch"));
1933 infwait_state = infwait_normal_state;
1935 switch (ecs->ws.kind)
1937 case TARGET_WAITKIND_LOADED:
1939 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
1940 /* Ignore gracefully during startup of the inferior, as it might
1941 be the shell which has just loaded some objects, otherwise
1942 add the symbols for the newly loaded objects. Also ignore at
1943 the beginning of an attach or remote session; we will query
1944 the full list of libraries once the connection is
1946 if (stop_soon == NO_STOP_QUIETLY)
1948 /* Check for any newly added shared libraries if we're
1949 supposed to be adding them automatically. Switch
1950 terminal for any messages produced by
1951 breakpoint_re_set. */
1952 target_terminal_ours_for_output ();
1953 /* NOTE: cagney/2003-11-25: Make certain that the target
1954 stack's section table is kept up-to-date. Architectures,
1955 (e.g., PPC64), use the section table to perform
1956 operations such as address => section name and hence
1957 require the table to contain all sections (including
1958 those found in shared libraries). */
1959 /* NOTE: cagney/2003-11-25: Pass current_target and not
1960 exec_ops to SOLIB_ADD. This is because current GDB is
1961 only tooled to propagate section_table changes out from
1962 the "current_target" (see target_resize_to_sections), and
1963 not up from the exec stratum. This, of course, isn't
1964 right. "infrun.c" should only interact with the
1965 exec/process stratum, instead relying on the target stack
1966 to propagate relevant changes (stop, section table
1967 changed, ...) up to other layers. */
1969 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
1971 solib_add (NULL, 0, ¤t_target, auto_solib_add);
1973 target_terminal_inferior ();
1975 /* If requested, stop when the dynamic linker notifies
1976 gdb of events. This allows the user to get control
1977 and place breakpoints in initializer routines for
1978 dynamically loaded objects (among other things). */
1979 if (stop_on_solib_events)
1981 stop_stepping (ecs);
1985 /* NOTE drow/2007-05-11: This might be a good place to check
1986 for "catch load". */
1989 /* If we are skipping through a shell, or through shared library
1990 loading that we aren't interested in, resume the program. If
1991 we're running the program normally, also resume. But stop if
1992 we're attaching or setting up a remote connection. */
1993 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
1995 /* Loading of shared libraries might have changed breakpoint
1996 addresses. Make sure new breakpoints are inserted. */
1997 if (stop_soon == NO_STOP_QUIETLY
1998 && !breakpoints_always_inserted_mode ())
1999 insert_breakpoints ();
2000 resume (0, TARGET_SIGNAL_0);
2001 prepare_to_wait (ecs);
2007 case TARGET_WAITKIND_SPURIOUS:
2009 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
2010 resume (0, TARGET_SIGNAL_0);
2011 prepare_to_wait (ecs);
2014 case TARGET_WAITKIND_EXITED:
2016 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
2017 target_terminal_ours (); /* Must do this before mourn anyway */
2018 print_stop_reason (EXITED, ecs->ws.value.integer);
2020 /* Record the exit code in the convenience variable $_exitcode, so
2021 that the user can inspect this again later. */
2022 set_internalvar (lookup_internalvar ("_exitcode"),
2023 value_from_longest (builtin_type_int32,
2024 (LONGEST) ecs->ws.value.integer));
2025 gdb_flush (gdb_stdout);
2026 target_mourn_inferior ();
2027 singlestep_breakpoints_inserted_p = 0;
2028 stop_print_frame = 0;
2029 stop_stepping (ecs);
2032 case TARGET_WAITKIND_SIGNALLED:
2034 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2035 stop_print_frame = 0;
2036 target_terminal_ours (); /* Must do this before mourn anyway */
2038 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
2039 reach here unless the inferior is dead. However, for years
2040 target_kill() was called here, which hints that fatal signals aren't
2041 really fatal on some systems. If that's true, then some changes
2043 target_mourn_inferior ();
2045 print_stop_reason (SIGNAL_EXITED, ecs->ws.value.sig);
2046 singlestep_breakpoints_inserted_p = 0;
2047 stop_stepping (ecs);
2050 /* The following are the only cases in which we keep going;
2051 the above cases end in a continue or goto. */
2052 case TARGET_WAITKIND_FORKED:
2053 case TARGET_WAITKIND_VFORKED:
2055 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
2056 pending_follow.kind = ecs->ws.kind;
2058 pending_follow.fork_event.parent_pid = ecs->ptid;
2059 pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
2061 if (!ptid_equal (ecs->ptid, inferior_ptid))
2063 context_switch (ecs->ptid);
2064 reinit_frame_cache ();
2067 stop_pc = read_pc ();
2069 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2071 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2073 /* If no catchpoint triggered for this, then keep going. */
2074 if (ecs->random_signal)
2076 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2080 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2081 goto process_event_stop_test;
2083 case TARGET_WAITKIND_EXECD:
2085 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
2086 pending_follow.execd_pathname =
2087 savestring (ecs->ws.value.execd_pathname,
2088 strlen (ecs->ws.value.execd_pathname));
2090 if (!ptid_equal (ecs->ptid, inferior_ptid))
2092 context_switch (ecs->ptid);
2093 reinit_frame_cache ();
2096 stop_pc = read_pc ();
2098 /* This causes the eventpoints and symbol table to be reset.
2099 Must do this now, before trying to determine whether to
2101 follow_exec (inferior_ptid, pending_follow.execd_pathname);
2102 xfree (pending_follow.execd_pathname);
2104 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2105 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2107 /* If no catchpoint triggered for this, then keep going. */
2108 if (ecs->random_signal)
2110 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2114 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2115 goto process_event_stop_test;
2117 /* Be careful not to try to gather much state about a thread
2118 that's in a syscall. It's frequently a losing proposition. */
2119 case TARGET_WAITKIND_SYSCALL_ENTRY:
2121 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2122 resume (0, TARGET_SIGNAL_0);
2123 prepare_to_wait (ecs);
2126 /* Before examining the threads further, step this thread to
2127 get it entirely out of the syscall. (We get notice of the
2128 event when the thread is just on the verge of exiting a
2129 syscall. Stepping one instruction seems to get it back
2131 case TARGET_WAITKIND_SYSCALL_RETURN:
2133 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2134 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
2135 prepare_to_wait (ecs);
2138 case TARGET_WAITKIND_STOPPED:
2140 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
2141 ecs->event_thread->stop_signal = ecs->ws.value.sig;
2144 /* We had an event in the inferior, but we are not interested
2145 in handling it at this level. The lower layers have already
2146 done what needs to be done, if anything.
2148 One of the possible circumstances for this is when the
2149 inferior produces output for the console. The inferior has
2150 not stopped, and we are ignoring the event. Another possible
2151 circumstance is any event which the lower level knows will be
2152 reported multiple times without an intervening resume. */
2153 case TARGET_WAITKIND_IGNORE:
2155 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
2156 prepare_to_wait (ecs);
2160 if (ecs->new_thread_event)
2163 /* Non-stop assumes that the target handles adding new threads
2164 to the thread list. */
2165 internal_error (__FILE__, __LINE__, "\
2166 targets should add new threads to the thread list themselves in non-stop mode.");
2168 /* We may want to consider not doing a resume here in order to
2169 give the user a chance to play with the new thread. It might
2170 be good to make that a user-settable option. */
2172 /* At this point, all threads are stopped (happens automatically
2173 in either the OS or the native code). Therefore we need to
2174 continue all threads in order to make progress. */
2176 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
2177 prepare_to_wait (ecs);
2181 /* Do we need to clean up the state of a thread that has completed a
2182 displaced single-step? (Doing so usually affects the PC, so do
2183 it here, before we set stop_pc.) */
2184 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
2185 displaced_step_fixup (ecs->ptid, ecs->event_thread->stop_signal);
2187 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
2191 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n",
2192 paddr_nz (stop_pc));
2193 if (STOPPED_BY_WATCHPOINT (&ecs->ws))
2196 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
2198 if (target_stopped_data_address (¤t_target, &addr))
2199 fprintf_unfiltered (gdb_stdlog,
2200 "infrun: stopped data address = 0x%s\n",
2203 fprintf_unfiltered (gdb_stdlog,
2204 "infrun: (no data address available)\n");
2208 if (stepping_past_singlestep_breakpoint)
2210 gdb_assert (singlestep_breakpoints_inserted_p);
2211 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
2212 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
2214 stepping_past_singlestep_breakpoint = 0;
2216 /* We've either finished single-stepping past the single-step
2217 breakpoint, or stopped for some other reason. It would be nice if
2218 we could tell, but we can't reliably. */
2219 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2222 fprintf_unfiltered (gdb_stdlog, "infrun: stepping_past_singlestep_breakpoint\n");
2223 /* Pull the single step breakpoints out of the target. */
2224 remove_single_step_breakpoints ();
2225 singlestep_breakpoints_inserted_p = 0;
2227 ecs->random_signal = 0;
2229 context_switch (saved_singlestep_ptid);
2230 if (deprecated_context_hook)
2231 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
2233 resume (1, TARGET_SIGNAL_0);
2234 prepare_to_wait (ecs);
2239 stepping_past_singlestep_breakpoint = 0;
2241 if (!ptid_equal (deferred_step_ptid, null_ptid))
2243 /* In non-stop mode, there's never a deferred_step_ptid set. */
2244 gdb_assert (!non_stop);
2246 /* If we stopped for some other reason than single-stepping, ignore
2247 the fact that we were supposed to switch back. */
2248 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2250 struct thread_info *tp;
2253 fprintf_unfiltered (gdb_stdlog,
2254 "infrun: handling deferred step\n");
2256 /* Pull the single step breakpoints out of the target. */
2257 if (singlestep_breakpoints_inserted_p)
2259 remove_single_step_breakpoints ();
2260 singlestep_breakpoints_inserted_p = 0;
2263 /* Note: We do not call context_switch at this point, as the
2264 context is already set up for stepping the original thread. */
2265 switch_to_thread (deferred_step_ptid);
2266 deferred_step_ptid = null_ptid;
2267 /* Suppress spurious "Switching to ..." message. */
2268 previous_inferior_ptid = inferior_ptid;
2270 resume (1, TARGET_SIGNAL_0);
2271 prepare_to_wait (ecs);
2275 deferred_step_ptid = null_ptid;
2278 /* See if a thread hit a thread-specific breakpoint that was meant for
2279 another thread. If so, then step that thread past the breakpoint,
2282 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2284 int thread_hop_needed = 0;
2286 /* Check if a regular breakpoint has been hit before checking
2287 for a potential single step breakpoint. Otherwise, GDB will
2288 not see this breakpoint hit when stepping onto breakpoints. */
2289 if (regular_breakpoint_inserted_here_p (stop_pc))
2291 ecs->random_signal = 0;
2292 if (!breakpoint_thread_match (stop_pc, ecs->ptid))
2293 thread_hop_needed = 1;
2295 else if (singlestep_breakpoints_inserted_p)
2297 /* We have not context switched yet, so this should be true
2298 no matter which thread hit the singlestep breakpoint. */
2299 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
2301 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
2303 target_pid_to_str (ecs->ptid));
2305 ecs->random_signal = 0;
2306 /* The call to in_thread_list is necessary because PTIDs sometimes
2307 change when we go from single-threaded to multi-threaded. If
2308 the singlestep_ptid is still in the list, assume that it is
2309 really different from ecs->ptid. */
2310 if (!ptid_equal (singlestep_ptid, ecs->ptid)
2311 && in_thread_list (singlestep_ptid))
2313 /* If the PC of the thread we were trying to single-step
2314 has changed, discard this event (which we were going
2315 to ignore anyway), and pretend we saw that thread
2316 trap. This prevents us continuously moving the
2317 single-step breakpoint forward, one instruction at a
2318 time. If the PC has changed, then the thread we were
2319 trying to single-step has trapped or been signalled,
2320 but the event has not been reported to GDB yet.
2322 There might be some cases where this loses signal
2323 information, if a signal has arrived at exactly the
2324 same time that the PC changed, but this is the best
2325 we can do with the information available. Perhaps we
2326 should arrange to report all events for all threads
2327 when they stop, or to re-poll the remote looking for
2328 this particular thread (i.e. temporarily enable
2331 CORE_ADDR new_singlestep_pc
2332 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
2334 if (new_singlestep_pc != singlestep_pc)
2336 enum target_signal stop_signal;
2339 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
2340 " but expected thread advanced also\n");
2342 /* The current context still belongs to
2343 singlestep_ptid. Don't swap here, since that's
2344 the context we want to use. Just fudge our
2345 state and continue. */
2346 stop_signal = ecs->event_thread->stop_signal;
2347 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2348 ecs->ptid = singlestep_ptid;
2349 ecs->event_thread = find_thread_pid (ecs->ptid);
2350 ecs->event_thread->stop_signal = stop_signal;
2351 stop_pc = new_singlestep_pc;
2356 fprintf_unfiltered (gdb_stdlog,
2357 "infrun: unexpected thread\n");
2359 thread_hop_needed = 1;
2360 stepping_past_singlestep_breakpoint = 1;
2361 saved_singlestep_ptid = singlestep_ptid;
2366 if (thread_hop_needed)
2368 int remove_status = 0;
2371 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
2373 /* Saw a breakpoint, but it was hit by the wrong thread.
2376 if (singlestep_breakpoints_inserted_p)
2378 /* Pull the single step breakpoints out of the target. */
2379 remove_single_step_breakpoints ();
2380 singlestep_breakpoints_inserted_p = 0;
2383 /* If the arch can displace step, don't remove the
2385 if (!use_displaced_stepping (current_gdbarch))
2386 remove_status = remove_breakpoints ();
2388 /* Did we fail to remove breakpoints? If so, try
2389 to set the PC past the bp. (There's at least
2390 one situation in which we can fail to remove
2391 the bp's: On HP-UX's that use ttrace, we can't
2392 change the address space of a vforking child
2393 process until the child exits (well, okay, not
2394 then either :-) or execs. */
2395 if (remove_status != 0)
2396 error (_("Cannot step over breakpoint hit in wrong thread"));
2399 if (!ptid_equal (inferior_ptid, ecs->ptid))
2400 context_switch (ecs->ptid);
2404 /* Only need to require the next event from this
2405 thread in all-stop mode. */
2406 waiton_ptid = ecs->ptid;
2407 infwait_state = infwait_thread_hop_state;
2410 ecs->event_thread->stepping_over_breakpoint = 1;
2412 registers_changed ();
2416 else if (singlestep_breakpoints_inserted_p)
2418 sw_single_step_trap_p = 1;
2419 ecs->random_signal = 0;
2423 ecs->random_signal = 1;
2425 /* See if something interesting happened to the non-current thread. If
2426 so, then switch to that thread. */
2427 if (!ptid_equal (ecs->ptid, inferior_ptid))
2430 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
2432 context_switch (ecs->ptid);
2434 if (deprecated_context_hook)
2435 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
2438 if (singlestep_breakpoints_inserted_p)
2440 /* Pull the single step breakpoints out of the target. */
2441 remove_single_step_breakpoints ();
2442 singlestep_breakpoints_inserted_p = 0;
2445 if (stepped_after_stopped_by_watchpoint)
2446 stopped_by_watchpoint = 0;
2448 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
2450 /* If necessary, step over this watchpoint. We'll be back to display
2452 if (stopped_by_watchpoint
2453 && (HAVE_STEPPABLE_WATCHPOINT
2454 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch)))
2456 /* At this point, we are stopped at an instruction which has
2457 attempted to write to a piece of memory under control of
2458 a watchpoint. The instruction hasn't actually executed
2459 yet. If we were to evaluate the watchpoint expression
2460 now, we would get the old value, and therefore no change
2461 would seem to have occurred.
2463 In order to make watchpoints work `right', we really need
2464 to complete the memory write, and then evaluate the
2465 watchpoint expression. We do this by single-stepping the
2468 It may not be necessary to disable the watchpoint to stop over
2469 it. For example, the PA can (with some kernel cooperation)
2470 single step over a watchpoint without disabling the watchpoint.
2472 It is far more common to need to disable a watchpoint to step
2473 the inferior over it. If we have non-steppable watchpoints,
2474 we must disable the current watchpoint; it's simplest to
2475 disable all watchpoints and breakpoints. */
2477 if (!HAVE_STEPPABLE_WATCHPOINT)
2478 remove_breakpoints ();
2479 registers_changed ();
2480 target_resume (ecs->ptid, 1, TARGET_SIGNAL_0); /* Single step */
2481 waiton_ptid = ecs->ptid;
2482 if (HAVE_STEPPABLE_WATCHPOINT)
2483 infwait_state = infwait_step_watch_state;
2485 infwait_state = infwait_nonstep_watch_state;
2486 prepare_to_wait (ecs);
2490 ecs->stop_func_start = 0;
2491 ecs->stop_func_end = 0;
2492 ecs->stop_func_name = 0;
2493 /* Don't care about return value; stop_func_start and stop_func_name
2494 will both be 0 if it doesn't work. */
2495 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
2496 &ecs->stop_func_start, &ecs->stop_func_end);
2497 ecs->stop_func_start
2498 += gdbarch_deprecated_function_start_offset (current_gdbarch);
2499 ecs->event_thread->stepping_over_breakpoint = 0;
2500 bpstat_clear (&ecs->event_thread->stop_bpstat);
2501 ecs->event_thread->stop_step = 0;
2502 stop_print_frame = 1;
2503 ecs->random_signal = 0;
2504 stopped_by_random_signal = 0;
2506 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
2507 && ecs->event_thread->trap_expected
2508 && gdbarch_single_step_through_delay_p (current_gdbarch)
2509 && currently_stepping (ecs->event_thread))
2511 /* We're trying to step off a breakpoint. Turns out that we're
2512 also on an instruction that needs to be stepped multiple
2513 times before it's been fully executing. E.g., architectures
2514 with a delay slot. It needs to be stepped twice, once for
2515 the instruction and once for the delay slot. */
2516 int step_through_delay
2517 = gdbarch_single_step_through_delay (current_gdbarch,
2518 get_current_frame ());
2519 if (debug_infrun && step_through_delay)
2520 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
2521 if (ecs->event_thread->step_range_end == 0 && step_through_delay)
2523 /* The user issued a continue when stopped at a breakpoint.
2524 Set up for another trap and get out of here. */
2525 ecs->event_thread->stepping_over_breakpoint = 1;
2529 else if (step_through_delay)
2531 /* The user issued a step when stopped at a breakpoint.
2532 Maybe we should stop, maybe we should not - the delay
2533 slot *might* correspond to a line of source. In any
2534 case, don't decide that here, just set
2535 ecs->stepping_over_breakpoint, making sure we
2536 single-step again before breakpoints are re-inserted. */
2537 ecs->event_thread->stepping_over_breakpoint = 1;
2541 /* Look at the cause of the stop, and decide what to do.
2542 The alternatives are:
2543 1) stop_stepping and return; to really stop and return to the debugger,
2544 2) keep_going and return to start up again
2545 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
2546 3) set ecs->random_signal to 1, and the decision between 1 and 2
2547 will be made according to the signal handling tables. */
2549 /* First, distinguish signals caused by the debugger from signals
2550 that have to do with the program's own actions. Note that
2551 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2552 on the operating system version. Here we detect when a SIGILL or
2553 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2554 something similar for SIGSEGV, since a SIGSEGV will be generated
2555 when we're trying to execute a breakpoint instruction on a
2556 non-executable stack. This happens for call dummy breakpoints
2557 for architectures like SPARC that place call dummies on the
2560 If we're doing a displaced step past a breakpoint, then the
2561 breakpoint is always inserted at the original instruction;
2562 non-standard signals can't be explained by the breakpoint. */
2563 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
2564 || (! ecs->event_thread->trap_expected
2565 && breakpoint_inserted_here_p (stop_pc)
2566 && (ecs->event_thread->stop_signal == TARGET_SIGNAL_ILL
2567 || ecs->event_thread->stop_signal == TARGET_SIGNAL_SEGV
2568 || ecs->event_thread->stop_signal == TARGET_SIGNAL_EMT))
2569 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
2570 || stop_soon == STOP_QUIETLY_REMOTE)
2572 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
2575 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
2576 stop_print_frame = 0;
2577 stop_stepping (ecs);
2581 /* This is originated from start_remote(), start_inferior() and
2582 shared libraries hook functions. */
2583 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
2586 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
2587 stop_stepping (ecs);
2591 /* This originates from attach_command(). We need to overwrite
2592 the stop_signal here, because some kernels don't ignore a
2593 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2594 See more comments in inferior.h. On the other hand, if we
2595 get a non-SIGSTOP, report it to the user - assume the backend
2596 will handle the SIGSTOP if it should show up later.
2598 Also consider that the attach is complete when we see a
2599 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
2600 target extended-remote report it instead of a SIGSTOP
2601 (e.g. gdbserver). We already rely on SIGTRAP being our
2602 signal, so this is no exception. */
2603 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
2604 && (ecs->event_thread->stop_signal == TARGET_SIGNAL_STOP
2605 || ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP))
2607 stop_stepping (ecs);
2608 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2612 /* See if there is a breakpoint at the current PC. */
2613 ecs->event_thread->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
2615 /* Following in case break condition called a
2617 stop_print_frame = 1;
2619 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2620 at one stage in the past included checks for an inferior
2621 function call's call dummy's return breakpoint. The original
2622 comment, that went with the test, read:
2624 ``End of a stack dummy. Some systems (e.g. Sony news) give
2625 another signal besides SIGTRAP, so check here as well as
2628 If someone ever tries to get get call dummys on a
2629 non-executable stack to work (where the target would stop
2630 with something like a SIGSEGV), then those tests might need
2631 to be re-instated. Given, however, that the tests were only
2632 enabled when momentary breakpoints were not being used, I
2633 suspect that it won't be the case.
2635 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2636 be necessary for call dummies on a non-executable stack on
2639 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP)
2641 = !(bpstat_explains_signal (ecs->event_thread->stop_bpstat)
2642 || ecs->event_thread->trap_expected
2643 || (ecs->event_thread->step_range_end
2644 && ecs->event_thread->step_resume_breakpoint == NULL));
2647 ecs->random_signal = !bpstat_explains_signal (ecs->event_thread->stop_bpstat);
2648 if (!ecs->random_signal)
2649 ecs->event_thread->stop_signal = TARGET_SIGNAL_TRAP;
2653 /* When we reach this point, we've pretty much decided
2654 that the reason for stopping must've been a random
2655 (unexpected) signal. */
2658 ecs->random_signal = 1;
2660 process_event_stop_test:
2661 /* For the program's own signals, act according to
2662 the signal handling tables. */
2664 if (ecs->random_signal)
2666 /* Signal not for debugging purposes. */
2670 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
2671 ecs->event_thread->stop_signal);
2673 stopped_by_random_signal = 1;
2675 if (signal_print[ecs->event_thread->stop_signal])
2678 target_terminal_ours_for_output ();
2679 print_stop_reason (SIGNAL_RECEIVED, ecs->event_thread->stop_signal);
2681 /* Always stop on signals if we're just gaining control of the
2683 if (stop_soon != NO_STOP_QUIETLY
2684 || signal_stop_state (ecs->event_thread->stop_signal))
2686 stop_stepping (ecs);
2689 /* If not going to stop, give terminal back
2690 if we took it away. */
2692 target_terminal_inferior ();
2694 /* Clear the signal if it should not be passed. */
2695 if (signal_program[ecs->event_thread->stop_signal] == 0)
2696 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
2698 if (ecs->event_thread->prev_pc == read_pc ()
2699 && ecs->event_thread->trap_expected
2700 && ecs->event_thread->step_resume_breakpoint == NULL)
2702 /* We were just starting a new sequence, attempting to
2703 single-step off of a breakpoint and expecting a SIGTRAP.
2704 Instead this signal arrives. This signal will take us out
2705 of the stepping range so GDB needs to remember to, when
2706 the signal handler returns, resume stepping off that
2708 /* To simplify things, "continue" is forced to use the same
2709 code paths as single-step - set a breakpoint at the
2710 signal return address and then, once hit, step off that
2713 fprintf_unfiltered (gdb_stdlog,
2714 "infrun: signal arrived while stepping over "
2717 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2718 ecs->event_thread->step_after_step_resume_breakpoint = 1;
2723 if (ecs->event_thread->step_range_end != 0
2724 && ecs->event_thread->stop_signal != TARGET_SIGNAL_0
2725 && (ecs->event_thread->step_range_start <= stop_pc
2726 && stop_pc < ecs->event_thread->step_range_end)
2727 && frame_id_eq (get_frame_id (get_current_frame ()),
2728 ecs->event_thread->step_frame_id)
2729 && ecs->event_thread->step_resume_breakpoint == NULL)
2731 /* The inferior is about to take a signal that will take it
2732 out of the single step range. Set a breakpoint at the
2733 current PC (which is presumably where the signal handler
2734 will eventually return) and then allow the inferior to
2737 Note that this is only needed for a signal delivered
2738 while in the single-step range. Nested signals aren't a
2739 problem as they eventually all return. */
2741 fprintf_unfiltered (gdb_stdlog,
2742 "infrun: signal may take us out of "
2743 "single-step range\n");
2745 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2750 /* Note: step_resume_breakpoint may be non-NULL. This occures
2751 when either there's a nested signal, or when there's a
2752 pending signal enabled just as the signal handler returns
2753 (leaving the inferior at the step-resume-breakpoint without
2754 actually executing it). Either way continue until the
2755 breakpoint is really hit. */
2760 /* Handle cases caused by hitting a breakpoint. */
2762 CORE_ADDR jmp_buf_pc;
2763 struct bpstat_what what;
2765 what = bpstat_what (ecs->event_thread->stop_bpstat);
2767 if (what.call_dummy)
2769 stop_stack_dummy = 1;
2772 switch (what.main_action)
2774 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
2775 /* If we hit the breakpoint at longjmp while stepping, we
2776 install a momentary breakpoint at the target of the
2780 fprintf_unfiltered (gdb_stdlog,
2781 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2783 ecs->event_thread->stepping_over_breakpoint = 1;
2785 if (!gdbarch_get_longjmp_target_p (current_gdbarch)
2786 || !gdbarch_get_longjmp_target (current_gdbarch,
2787 get_current_frame (), &jmp_buf_pc))
2790 fprintf_unfiltered (gdb_stdlog, "\
2791 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
2796 /* We're going to replace the current step-resume breakpoint
2797 with a longjmp-resume breakpoint. */
2798 delete_step_resume_breakpoint (ecs->event_thread);
2800 /* Insert a breakpoint at resume address. */
2801 insert_longjmp_resume_breakpoint (jmp_buf_pc);
2806 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
2808 fprintf_unfiltered (gdb_stdlog,
2809 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2811 gdb_assert (ecs->event_thread->step_resume_breakpoint != NULL);
2812 delete_step_resume_breakpoint (ecs->event_thread);
2814 ecs->event_thread->stop_step = 1;
2815 print_stop_reason (END_STEPPING_RANGE, 0);
2816 stop_stepping (ecs);
2819 case BPSTAT_WHAT_SINGLE:
2821 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
2822 ecs->event_thread->stepping_over_breakpoint = 1;
2823 /* Still need to check other stuff, at least the case
2824 where we are stepping and step out of the right range. */
2827 case BPSTAT_WHAT_STOP_NOISY:
2829 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2830 stop_print_frame = 1;
2832 /* We are about to nuke the step_resume_breakpointt via the
2833 cleanup chain, so no need to worry about it here. */
2835 stop_stepping (ecs);
2838 case BPSTAT_WHAT_STOP_SILENT:
2840 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2841 stop_print_frame = 0;
2843 /* We are about to nuke the step_resume_breakpoin via the
2844 cleanup chain, so no need to worry about it here. */
2846 stop_stepping (ecs);
2849 case BPSTAT_WHAT_STEP_RESUME:
2851 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2853 delete_step_resume_breakpoint (ecs->event_thread);
2854 if (ecs->event_thread->step_after_step_resume_breakpoint)
2856 /* Back when the step-resume breakpoint was inserted, we
2857 were trying to single-step off a breakpoint. Go back
2859 ecs->event_thread->step_after_step_resume_breakpoint = 0;
2860 ecs->event_thread->stepping_over_breakpoint = 1;
2866 case BPSTAT_WHAT_CHECK_SHLIBS:
2867 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK:
2870 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2872 /* Check for any newly added shared libraries if we're
2873 supposed to be adding them automatically. Switch
2874 terminal for any messages produced by
2875 breakpoint_re_set. */
2876 target_terminal_ours_for_output ();
2877 /* NOTE: cagney/2003-11-25: Make certain that the target
2878 stack's section table is kept up-to-date. Architectures,
2879 (e.g., PPC64), use the section table to perform
2880 operations such as address => section name and hence
2881 require the table to contain all sections (including
2882 those found in shared libraries). */
2883 /* NOTE: cagney/2003-11-25: Pass current_target and not
2884 exec_ops to SOLIB_ADD. This is because current GDB is
2885 only tooled to propagate section_table changes out from
2886 the "current_target" (see target_resize_to_sections), and
2887 not up from the exec stratum. This, of course, isn't
2888 right. "infrun.c" should only interact with the
2889 exec/process stratum, instead relying on the target stack
2890 to propagate relevant changes (stop, section table
2891 changed, ...) up to other layers. */
2893 SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add);
2895 solib_add (NULL, 0, ¤t_target, auto_solib_add);
2897 target_terminal_inferior ();
2899 /* If requested, stop when the dynamic linker notifies
2900 gdb of events. This allows the user to get control
2901 and place breakpoints in initializer routines for
2902 dynamically loaded objects (among other things). */
2903 if (stop_on_solib_events || stop_stack_dummy)
2905 stop_stepping (ecs);
2909 /* If we stopped due to an explicit catchpoint, then the
2910 (see above) call to SOLIB_ADD pulled in any symbols
2911 from a newly-loaded library, if appropriate.
2913 We do want the inferior to stop, but not where it is
2914 now, which is in the dynamic linker callback. Rather,
2915 we would like it stop in the user's program, just after
2916 the call that caused this catchpoint to trigger. That
2917 gives the user a more useful vantage from which to
2918 examine their program's state. */
2919 else if (what.main_action
2920 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK)
2922 /* ??rehrauer: If I could figure out how to get the
2923 right return PC from here, we could just set a temp
2924 breakpoint and resume. I'm not sure we can without
2925 cracking open the dld's shared libraries and sniffing
2926 their unwind tables and text/data ranges, and that's
2927 not a terribly portable notion.
2929 Until that time, we must step the inferior out of the
2930 dld callback, and also out of the dld itself (and any
2931 code or stubs in libdld.sl, such as "shl_load" and
2932 friends) until we reach non-dld code. At that point,
2933 we can stop stepping. */
2934 bpstat_get_triggered_catchpoints (ecs->event_thread->stop_bpstat,
2937 stepping_through_solib_catchpoints);
2938 ecs->event_thread->stepping_through_solib_after_catch = 1;
2940 /* Be sure to lift all breakpoints, so the inferior does
2941 actually step past this point... */
2942 ecs->event_thread->stepping_over_breakpoint = 1;
2947 /* We want to step over this breakpoint, then keep going. */
2948 ecs->event_thread->stepping_over_breakpoint = 1;
2954 case BPSTAT_WHAT_LAST:
2955 /* Not a real code, but listed here to shut up gcc -Wall. */
2957 case BPSTAT_WHAT_KEEP_CHECKING:
2962 /* We come here if we hit a breakpoint but should not
2963 stop for it. Possibly we also were stepping
2964 and should stop for that. So fall through and
2965 test for stepping. But, if not stepping,
2968 /* Are we stepping to get the inferior out of the dynamic linker's
2969 hook (and possibly the dld itself) after catching a shlib
2971 if (ecs->event_thread->stepping_through_solib_after_catch)
2973 #if defined(SOLIB_ADD)
2974 /* Have we reached our destination? If not, keep going. */
2975 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
2978 fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n");
2979 ecs->event_thread->stepping_over_breakpoint = 1;
2985 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
2986 /* Else, stop and report the catchpoint(s) whose triggering
2987 caused us to begin stepping. */
2988 ecs->event_thread->stepping_through_solib_after_catch = 0;
2989 bpstat_clear (&ecs->event_thread->stop_bpstat);
2990 ecs->event_thread->stop_bpstat
2991 = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints);
2992 bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints);
2993 stop_print_frame = 1;
2994 stop_stepping (ecs);
2998 if (ecs->event_thread->step_resume_breakpoint)
3001 fprintf_unfiltered (gdb_stdlog,
3002 "infrun: step-resume breakpoint is inserted\n");
3004 /* Having a step-resume breakpoint overrides anything
3005 else having to do with stepping commands until
3006 that breakpoint is reached. */
3011 if (ecs->event_thread->step_range_end == 0)
3014 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
3015 /* Likewise if we aren't even stepping. */
3020 /* If stepping through a line, keep going if still within it.
3022 Note that step_range_end is the address of the first instruction
3023 beyond the step range, and NOT the address of the last instruction
3025 if (stop_pc >= ecs->event_thread->step_range_start
3026 && stop_pc < ecs->event_thread->step_range_end)
3029 fprintf_unfiltered (gdb_stdlog, "infrun: stepping inside range [0x%s-0x%s]\n",
3030 paddr_nz (ecs->event_thread->step_range_start),
3031 paddr_nz (ecs->event_thread->step_range_end));
3036 /* We stepped out of the stepping range. */
3038 /* If we are stepping at the source level and entered the runtime
3039 loader dynamic symbol resolution code, we keep on single stepping
3040 until we exit the run time loader code and reach the callee's
3042 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3043 && in_solib_dynsym_resolve_code (stop_pc))
3045 CORE_ADDR pc_after_resolver =
3046 gdbarch_skip_solib_resolver (current_gdbarch, stop_pc);
3049 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into dynsym resolve code\n");
3051 if (pc_after_resolver)
3053 /* Set up a step-resume breakpoint at the address
3054 indicated by SKIP_SOLIB_RESOLVER. */
3055 struct symtab_and_line sr_sal;
3057 sr_sal.pc = pc_after_resolver;
3059 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3066 if (ecs->event_thread->step_range_end != 1
3067 && (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3068 || ecs->event_thread->step_over_calls == STEP_OVER_ALL)
3069 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME)
3072 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into signal trampoline\n");
3073 /* The inferior, while doing a "step" or "next", has ended up in
3074 a signal trampoline (either by a signal being delivered or by
3075 the signal handler returning). Just single-step until the
3076 inferior leaves the trampoline (either by calling the handler
3082 /* Check for subroutine calls. The check for the current frame
3083 equalling the step ID is not necessary - the check of the
3084 previous frame's ID is sufficient - but it is a common case and
3085 cheaper than checking the previous frame's ID.
3087 NOTE: frame_id_eq will never report two invalid frame IDs as
3088 being equal, so to get into this block, both the current and
3089 previous frame must have valid frame IDs. */
3090 if (!frame_id_eq (get_frame_id (get_current_frame ()),
3091 ecs->event_thread->step_frame_id)
3092 && frame_id_eq (frame_unwind_id (get_current_frame ()),
3093 ecs->event_thread->step_frame_id))
3095 CORE_ADDR real_stop_pc;
3098 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
3100 if ((ecs->event_thread->step_over_calls == STEP_OVER_NONE)
3101 || ((ecs->event_thread->step_range_end == 1)
3102 && in_prologue (ecs->event_thread->prev_pc,
3103 ecs->stop_func_start)))
3105 /* I presume that step_over_calls is only 0 when we're
3106 supposed to be stepping at the assembly language level
3107 ("stepi"). Just stop. */
3108 /* Also, maybe we just did a "nexti" inside a prolog, so we
3109 thought it was a subroutine call but it was not. Stop as
3111 ecs->event_thread->stop_step = 1;
3112 print_stop_reason (END_STEPPING_RANGE, 0);
3113 stop_stepping (ecs);
3117 if (ecs->event_thread->step_over_calls == STEP_OVER_ALL)
3119 /* We're doing a "next", set a breakpoint at callee's return
3120 address (the address at which the caller will
3122 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3127 /* If we are in a function call trampoline (a stub between the
3128 calling routine and the real function), locate the real
3129 function. That's what tells us (a) whether we want to step
3130 into it at all, and (b) what prologue we want to run to the
3131 end of, if we do step into it. */
3132 real_stop_pc = skip_language_trampoline (get_current_frame (), stop_pc);
3133 if (real_stop_pc == 0)
3134 real_stop_pc = gdbarch_skip_trampoline_code
3135 (current_gdbarch, get_current_frame (), stop_pc);
3136 if (real_stop_pc != 0)
3137 ecs->stop_func_start = real_stop_pc;
3139 if (in_solib_dynsym_resolve_code (ecs->stop_func_start))
3141 struct symtab_and_line sr_sal;
3143 sr_sal.pc = ecs->stop_func_start;
3145 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3150 /* If we have line number information for the function we are
3151 thinking of stepping into, step into it.
3153 If there are several symtabs at that PC (e.g. with include
3154 files), just want to know whether *any* of them have line
3155 numbers. find_pc_line handles this. */
3157 struct symtab_and_line tmp_sal;
3159 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
3160 if (tmp_sal.line != 0)
3162 step_into_function (ecs);
3167 /* If we have no line number and the step-stop-if-no-debug is
3168 set, we stop the step so that the user has a chance to switch
3169 in assembly mode. */
3170 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3171 && step_stop_if_no_debug)
3173 ecs->event_thread->stop_step = 1;
3174 print_stop_reason (END_STEPPING_RANGE, 0);
3175 stop_stepping (ecs);
3179 /* Set a breakpoint at callee's return address (the address at
3180 which the caller will resume). */
3181 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3186 /* If we're in the return path from a shared library trampoline,
3187 we want to proceed through the trampoline when stepping. */
3188 if (gdbarch_in_solib_return_trampoline (current_gdbarch,
3189 stop_pc, ecs->stop_func_name))
3191 /* Determine where this trampoline returns. */
3192 CORE_ADDR real_stop_pc;
3193 real_stop_pc = gdbarch_skip_trampoline_code
3194 (current_gdbarch, get_current_frame (), stop_pc);
3197 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into solib return tramp\n");
3199 /* Only proceed through if we know where it's going. */
3202 /* And put the step-breakpoint there and go until there. */
3203 struct symtab_and_line sr_sal;
3205 init_sal (&sr_sal); /* initialize to zeroes */
3206 sr_sal.pc = real_stop_pc;
3207 sr_sal.section = find_pc_overlay (sr_sal.pc);
3209 /* Do not specify what the fp should be when we stop since
3210 on some machines the prologue is where the new fp value
3212 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3214 /* Restart without fiddling with the step ranges or
3221 stop_pc_sal = find_pc_line (stop_pc, 0);
3223 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3224 the trampoline processing logic, however, there are some trampolines
3225 that have no names, so we should do trampoline handling first. */
3226 if (ecs->event_thread->step_over_calls == STEP_OVER_UNDEBUGGABLE
3227 && ecs->stop_func_name == NULL
3228 && stop_pc_sal.line == 0)
3231 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into undebuggable function\n");
3233 /* The inferior just stepped into, or returned to, an
3234 undebuggable function (where there is no debugging information
3235 and no line number corresponding to the address where the
3236 inferior stopped). Since we want to skip this kind of code,
3237 we keep going until the inferior returns from this
3238 function - unless the user has asked us not to (via
3239 set step-mode) or we no longer know how to get back
3240 to the call site. */
3241 if (step_stop_if_no_debug
3242 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3244 /* If we have no line number and the step-stop-if-no-debug
3245 is set, we stop the step so that the user has a chance to
3246 switch in assembly mode. */
3247 ecs->event_thread->stop_step = 1;
3248 print_stop_reason (END_STEPPING_RANGE, 0);
3249 stop_stepping (ecs);
3254 /* Set a breakpoint at callee's return address (the address
3255 at which the caller will resume). */
3256 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3262 if (ecs->event_thread->step_range_end == 1)
3264 /* It is stepi or nexti. We always want to stop stepping after
3267 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
3268 ecs->event_thread->stop_step = 1;
3269 print_stop_reason (END_STEPPING_RANGE, 0);
3270 stop_stepping (ecs);
3274 if (stop_pc_sal.line == 0)
3276 /* We have no line number information. That means to stop
3277 stepping (does this always happen right after one instruction,
3278 when we do "s" in a function with no line numbers,
3279 or can this happen as a result of a return or longjmp?). */
3281 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
3282 ecs->event_thread->stop_step = 1;
3283 print_stop_reason (END_STEPPING_RANGE, 0);
3284 stop_stepping (ecs);
3288 if ((stop_pc == stop_pc_sal.pc)
3289 && (ecs->event_thread->current_line != stop_pc_sal.line
3290 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
3292 /* We are at the start of a different line. So stop. Note that
3293 we don't stop if we step into the middle of a different line.
3294 That is said to make things like for (;;) statements work
3297 fprintf_unfiltered (gdb_stdlog, "infrun: stepped to a different line\n");
3298 ecs->event_thread->stop_step = 1;
3299 print_stop_reason (END_STEPPING_RANGE, 0);
3300 stop_stepping (ecs);
3304 /* We aren't done stepping.
3306 Optimize by setting the stepping range to the line.
3307 (We might not be in the original line, but if we entered a
3308 new line in mid-statement, we continue stepping. This makes
3309 things like for(;;) statements work better.) */
3311 ecs->event_thread->step_range_start = stop_pc_sal.pc;
3312 ecs->event_thread->step_range_end = stop_pc_sal.end;
3313 ecs->event_thread->step_frame_id = get_frame_id (get_current_frame ());
3314 ecs->event_thread->current_line = stop_pc_sal.line;
3315 ecs->event_thread->current_symtab = stop_pc_sal.symtab;
3318 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
3322 /* Are we in the middle of stepping? */
3325 currently_stepping (struct thread_info *tp)
3327 return (((tp->step_range_end && tp->step_resume_breakpoint == NULL)
3328 || tp->trap_expected)
3329 || tp->stepping_through_solib_after_catch
3330 || bpstat_should_step ());
3333 /* Subroutine call with source code we should not step over. Do step
3334 to the first line of code in it. */
3337 step_into_function (struct execution_control_state *ecs)
3340 struct symtab_and_line stop_func_sal, sr_sal;
3342 s = find_pc_symtab (stop_pc);
3343 if (s && s->language != language_asm)
3344 ecs->stop_func_start = gdbarch_skip_prologue
3345 (current_gdbarch, ecs->stop_func_start);
3347 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
3348 /* Use the step_resume_break to step until the end of the prologue,
3349 even if that involves jumps (as it seems to on the vax under
3351 /* If the prologue ends in the middle of a source line, continue to
3352 the end of that source line (if it is still within the function).
3353 Otherwise, just go to end of prologue. */
3354 if (stop_func_sal.end
3355 && stop_func_sal.pc != ecs->stop_func_start
3356 && stop_func_sal.end < ecs->stop_func_end)
3357 ecs->stop_func_start = stop_func_sal.end;
3359 /* Architectures which require breakpoint adjustment might not be able
3360 to place a breakpoint at the computed address. If so, the test
3361 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3362 ecs->stop_func_start to an address at which a breakpoint may be
3363 legitimately placed.
3365 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3366 made, GDB will enter an infinite loop when stepping through
3367 optimized code consisting of VLIW instructions which contain
3368 subinstructions corresponding to different source lines. On
3369 FR-V, it's not permitted to place a breakpoint on any but the
3370 first subinstruction of a VLIW instruction. When a breakpoint is
3371 set, GDB will adjust the breakpoint address to the beginning of
3372 the VLIW instruction. Thus, we need to make the corresponding
3373 adjustment here when computing the stop address. */
3375 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch))
3377 ecs->stop_func_start
3378 = gdbarch_adjust_breakpoint_address (current_gdbarch,
3379 ecs->stop_func_start);
3382 if (ecs->stop_func_start == stop_pc)
3384 /* We are already there: stop now. */
3385 ecs->event_thread->stop_step = 1;
3386 print_stop_reason (END_STEPPING_RANGE, 0);
3387 stop_stepping (ecs);
3392 /* Put the step-breakpoint there and go until there. */
3393 init_sal (&sr_sal); /* initialize to zeroes */
3394 sr_sal.pc = ecs->stop_func_start;
3395 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
3397 /* Do not specify what the fp should be when we stop since on
3398 some machines the prologue is where the new fp value is
3400 insert_step_resume_breakpoint_at_sal (sr_sal, null_frame_id);
3402 /* And make sure stepping stops right away then. */
3403 ecs->event_thread->step_range_end = ecs->event_thread->step_range_start;
3408 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3409 This is used to both functions and to skip over code. */
3412 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal,
3413 struct frame_id sr_id)
3415 /* There should never be more than one step-resume or longjmp-resume
3416 breakpoint per thread, so we should never be setting a new
3417 step_resume_breakpoint when one is already active. */
3418 gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL);
3421 fprintf_unfiltered (gdb_stdlog,
3422 "infrun: inserting step-resume breakpoint at 0x%s\n",
3423 paddr_nz (sr_sal.pc));
3425 inferior_thread ()->step_resume_breakpoint
3426 = set_momentary_breakpoint (sr_sal, sr_id, bp_step_resume);
3429 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3430 to skip a potential signal handler.
3432 This is called with the interrupted function's frame. The signal
3433 handler, when it returns, will resume the interrupted function at
3437 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
3439 struct symtab_and_line sr_sal;
3441 gdb_assert (return_frame != NULL);
3442 init_sal (&sr_sal); /* initialize to zeros */
3444 sr_sal.pc = gdbarch_addr_bits_remove
3445 (current_gdbarch, get_frame_pc (return_frame));
3446 sr_sal.section = find_pc_overlay (sr_sal.pc);
3448 insert_step_resume_breakpoint_at_sal (sr_sal, get_frame_id (return_frame));
3451 /* Similar to insert_step_resume_breakpoint_at_frame, except
3452 but a breakpoint at the previous frame's PC. This is used to
3453 skip a function after stepping into it (for "next" or if the called
3454 function has no debugging information).
3456 The current function has almost always been reached by single
3457 stepping a call or return instruction. NEXT_FRAME belongs to the
3458 current function, and the breakpoint will be set at the caller's
3461 This is a separate function rather than reusing
3462 insert_step_resume_breakpoint_at_frame in order to avoid
3463 get_prev_frame, which may stop prematurely (see the implementation
3464 of frame_unwind_id for an example). */
3467 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
3469 struct symtab_and_line sr_sal;
3471 /* We shouldn't have gotten here if we don't know where the call site
3473 gdb_assert (frame_id_p (frame_unwind_id (next_frame)));
3475 init_sal (&sr_sal); /* initialize to zeros */
3477 sr_sal.pc = gdbarch_addr_bits_remove
3478 (current_gdbarch, frame_pc_unwind (next_frame));
3479 sr_sal.section = find_pc_overlay (sr_sal.pc);
3481 insert_step_resume_breakpoint_at_sal (sr_sal, frame_unwind_id (next_frame));
3484 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
3485 new breakpoint at the target of a jmp_buf. The handling of
3486 longjmp-resume uses the same mechanisms used for handling
3487 "step-resume" breakpoints. */
3490 insert_longjmp_resume_breakpoint (CORE_ADDR pc)
3492 /* There should never be more than one step-resume or longjmp-resume
3493 breakpoint per thread, so we should never be setting a new
3494 longjmp_resume_breakpoint when one is already active. */
3495 gdb_assert (inferior_thread ()->step_resume_breakpoint == NULL);
3498 fprintf_unfiltered (gdb_stdlog,
3499 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
3502 inferior_thread ()->step_resume_breakpoint =
3503 set_momentary_breakpoint_at_pc (pc, bp_longjmp_resume);
3507 stop_stepping (struct execution_control_state *ecs)
3510 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
3512 /* Let callers know we don't want to wait for the inferior anymore. */
3513 ecs->wait_some_more = 0;
3516 /* This function handles various cases where we need to continue
3517 waiting for the inferior. */
3518 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3521 keep_going (struct execution_control_state *ecs)
3523 /* Save the pc before execution, to compare with pc after stop. */
3524 ecs->event_thread->prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
3526 /* If we did not do break;, it means we should keep running the
3527 inferior and not return to debugger. */
3529 if (ecs->event_thread->trap_expected
3530 && ecs->event_thread->stop_signal != TARGET_SIGNAL_TRAP)
3532 /* We took a signal (which we are supposed to pass through to
3533 the inferior, else we'd not get here) and we haven't yet
3534 gotten our trap. Simply continue. */
3535 resume (currently_stepping (ecs->event_thread),
3536 ecs->event_thread->stop_signal);
3540 /* Either the trap was not expected, but we are continuing
3541 anyway (the user asked that this signal be passed to the
3544 The signal was SIGTRAP, e.g. it was our signal, but we
3545 decided we should resume from it.
3547 We're going to run this baby now!
3549 Note that insert_breakpoints won't try to re-insert
3550 already inserted breakpoints. Therefore, we don't
3551 care if breakpoints were already inserted, or not. */
3553 if (ecs->event_thread->stepping_over_breakpoint)
3555 if (! use_displaced_stepping (current_gdbarch))
3556 /* Since we can't do a displaced step, we have to remove
3557 the breakpoint while we step it. To keep things
3558 simple, we remove them all. */
3559 remove_breakpoints ();
3563 struct gdb_exception e;
3564 /* Stop stepping when inserting breakpoints
3566 TRY_CATCH (e, RETURN_MASK_ERROR)
3568 insert_breakpoints ();
3572 stop_stepping (ecs);
3577 ecs->event_thread->trap_expected = ecs->event_thread->stepping_over_breakpoint;
3579 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3580 specifies that such a signal should be delivered to the
3583 Typically, this would occure when a user is debugging a
3584 target monitor on a simulator: the target monitor sets a
3585 breakpoint; the simulator encounters this break-point and
3586 halts the simulation handing control to GDB; GDB, noteing
3587 that the break-point isn't valid, returns control back to the
3588 simulator; the simulator then delivers the hardware
3589 equivalent of a SIGNAL_TRAP to the program being debugged. */
3591 if (ecs->event_thread->stop_signal == TARGET_SIGNAL_TRAP
3592 && !signal_program[ecs->event_thread->stop_signal])
3593 ecs->event_thread->stop_signal = TARGET_SIGNAL_0;
3595 resume (currently_stepping (ecs->event_thread),
3596 ecs->event_thread->stop_signal);
3599 prepare_to_wait (ecs);
3602 /* This function normally comes after a resume, before
3603 handle_inferior_event exits. It takes care of any last bits of
3604 housekeeping, and sets the all-important wait_some_more flag. */
3607 prepare_to_wait (struct execution_control_state *ecs)
3610 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
3611 if (infwait_state == infwait_normal_state)
3613 overlay_cache_invalid = 1;
3615 /* We have to invalidate the registers BEFORE calling
3616 target_wait because they can be loaded from the target while
3617 in target_wait. This makes remote debugging a bit more
3618 efficient for those targets that provide critical registers
3619 as part of their normal status mechanism. */
3621 registers_changed ();
3622 waiton_ptid = pid_to_ptid (-1);
3624 /* This is the old end of the while loop. Let everybody know we
3625 want to wait for the inferior some more and get called again
3627 ecs->wait_some_more = 1;
3630 /* Print why the inferior has stopped. We always print something when
3631 the inferior exits, or receives a signal. The rest of the cases are
3632 dealt with later on in normal_stop() and print_it_typical(). Ideally
3633 there should be a call to this function from handle_inferior_event()
3634 each time stop_stepping() is called.*/
3636 print_stop_reason (enum inferior_stop_reason stop_reason, int stop_info)
3638 switch (stop_reason)
3640 case END_STEPPING_RANGE:
3641 /* We are done with a step/next/si/ni command. */
3642 /* For now print nothing. */
3643 /* Print a message only if not in the middle of doing a "step n"
3644 operation for n > 1 */
3645 if (!inferior_thread ()->step_multi
3646 || !inferior_thread ()->stop_step)
3647 if (ui_out_is_mi_like_p (uiout))
3650 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
3653 /* The inferior was terminated by a signal. */
3654 annotate_signalled ();
3655 if (ui_out_is_mi_like_p (uiout))
3658 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
3659 ui_out_text (uiout, "\nProgram terminated with signal ");
3660 annotate_signal_name ();
3661 ui_out_field_string (uiout, "signal-name",
3662 target_signal_to_name (stop_info));
3663 annotate_signal_name_end ();
3664 ui_out_text (uiout, ", ");
3665 annotate_signal_string ();
3666 ui_out_field_string (uiout, "signal-meaning",
3667 target_signal_to_string (stop_info));
3668 annotate_signal_string_end ();
3669 ui_out_text (uiout, ".\n");
3670 ui_out_text (uiout, "The program no longer exists.\n");
3673 /* The inferior program is finished. */
3674 annotate_exited (stop_info);
3677 if (ui_out_is_mi_like_p (uiout))
3678 ui_out_field_string (uiout, "reason",
3679 async_reason_lookup (EXEC_ASYNC_EXITED));
3680 ui_out_text (uiout, "\nProgram exited with code ");
3681 ui_out_field_fmt (uiout, "exit-code", "0%o",
3682 (unsigned int) stop_info);
3683 ui_out_text (uiout, ".\n");
3687 if (ui_out_is_mi_like_p (uiout))
3690 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
3691 ui_out_text (uiout, "\nProgram exited normally.\n");
3693 /* Support the --return-child-result option. */
3694 return_child_result_value = stop_info;
3696 case SIGNAL_RECEIVED:
3697 /* Signal received. The signal table tells us to print about
3700 ui_out_text (uiout, "\nProgram received signal ");
3701 annotate_signal_name ();
3702 if (ui_out_is_mi_like_p (uiout))
3704 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
3705 ui_out_field_string (uiout, "signal-name",
3706 target_signal_to_name (stop_info));
3707 annotate_signal_name_end ();
3708 ui_out_text (uiout, ", ");
3709 annotate_signal_string ();
3710 ui_out_field_string (uiout, "signal-meaning",
3711 target_signal_to_string (stop_info));
3712 annotate_signal_string_end ();
3713 ui_out_text (uiout, ".\n");
3716 internal_error (__FILE__, __LINE__,
3717 _("print_stop_reason: unrecognized enum value"));
3723 /* Here to return control to GDB when the inferior stops for real.
3724 Print appropriate messages, remove breakpoints, give terminal our modes.
3726 STOP_PRINT_FRAME nonzero means print the executing frame
3727 (pc, function, args, file, line number and line text).
3728 BREAKPOINTS_FAILED nonzero means stop was due to error
3729 attempting to insert breakpoints. */
3734 struct target_waitstatus last;
3737 get_last_target_status (&last_ptid, &last);
3739 /* In non-stop mode, we don't want GDB to switch threads behind the
3740 user's back, to avoid races where the user is typing a command to
3741 apply to thread x, but GDB switches to thread y before the user
3742 finishes entering the command. */
3744 /* As with the notification of thread events, we want to delay
3745 notifying the user that we've switched thread context until
3746 the inferior actually stops.
3748 There's no point in saying anything if the inferior has exited.
3749 Note that SIGNALLED here means "exited with a signal", not
3750 "received a signal". */
3752 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
3753 && target_has_execution
3754 && last.kind != TARGET_WAITKIND_SIGNALLED
3755 && last.kind != TARGET_WAITKIND_EXITED)
3757 target_terminal_ours_for_output ();
3758 printf_filtered (_("[Switching to %s]\n"),
3759 target_pid_to_str (inferior_ptid));
3760 annotate_thread_changed ();
3761 previous_inferior_ptid = inferior_ptid;
3764 /* NOTE drow/2004-01-17: Is this still necessary? */
3765 /* Make sure that the current_frame's pc is correct. This
3766 is a correction for setting up the frame info before doing
3767 gdbarch_decr_pc_after_break */
3768 if (target_has_execution)
3769 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3770 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3771 frame code to check for this and sort out any resultant mess.
3772 gdbarch_decr_pc_after_break needs to just go away. */
3773 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3775 if (!breakpoints_always_inserted_mode () && target_has_execution)
3777 if (remove_breakpoints ())
3779 target_terminal_ours_for_output ();
3780 printf_filtered (_("\
3781 Cannot remove breakpoints because program is no longer writable.\n\
3782 It might be running in another process.\n\
3783 Further execution is probably impossible.\n"));
3787 /* If an auto-display called a function and that got a signal,
3788 delete that auto-display to avoid an infinite recursion. */
3790 if (stopped_by_random_signal)
3791 disable_current_display ();
3793 /* Don't print a message if in the middle of doing a "step n"
3794 operation for n > 1 */
3795 if (target_has_execution
3796 && last.kind != TARGET_WAITKIND_SIGNALLED
3797 && last.kind != TARGET_WAITKIND_EXITED
3798 && inferior_thread ()->step_multi
3799 && inferior_thread ()->stop_step)
3802 target_terminal_ours ();
3804 /* Set the current source location. This will also happen if we
3805 display the frame below, but the current SAL will be incorrect
3806 during a user hook-stop function. */
3807 if (target_has_stack && !stop_stack_dummy)
3808 set_current_sal_from_frame (get_current_frame (), 1);
3810 if (!target_has_stack)
3813 if (last.kind == TARGET_WAITKIND_SIGNALLED
3814 || last.kind == TARGET_WAITKIND_EXITED)
3817 /* Select innermost stack frame - i.e., current frame is frame 0,
3818 and current location is based on that.
3819 Don't do this on return from a stack dummy routine,
3820 or if the program has exited. */
3822 if (!stop_stack_dummy)
3824 select_frame (get_current_frame ());
3826 /* Print current location without a level number, if
3827 we have changed functions or hit a breakpoint.
3828 Print source line if we have one.
3829 bpstat_print() contains the logic deciding in detail
3830 what to print, based on the event(s) that just occurred. */
3832 /* If --batch-silent is enabled then there's no need to print the current
3833 source location, and to try risks causing an error message about
3834 missing source files. */
3835 if (stop_print_frame && !batch_silent)
3839 int do_frame_printing = 1;
3840 struct thread_info *tp = inferior_thread ();
3842 bpstat_ret = bpstat_print (tp->stop_bpstat);
3846 /* If we had hit a shared library event breakpoint,
3847 bpstat_print would print out this message. If we hit
3848 an OS-level shared library event, do the same
3850 if (last.kind == TARGET_WAITKIND_LOADED)
3852 printf_filtered (_("Stopped due to shared library event\n"));
3853 source_flag = SRC_LINE; /* something bogus */
3854 do_frame_printing = 0;
3858 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3859 (or should) carry around the function and does (or
3860 should) use that when doing a frame comparison. */
3862 && frame_id_eq (tp->step_frame_id,
3863 get_frame_id (get_current_frame ()))
3864 && step_start_function == find_pc_function (stop_pc))
3865 source_flag = SRC_LINE; /* finished step, just print source line */
3867 source_flag = SRC_AND_LOC; /* print location and source line */
3869 case PRINT_SRC_AND_LOC:
3870 source_flag = SRC_AND_LOC; /* print location and source line */
3872 case PRINT_SRC_ONLY:
3873 source_flag = SRC_LINE;
3876 source_flag = SRC_LINE; /* something bogus */
3877 do_frame_printing = 0;
3880 internal_error (__FILE__, __LINE__, _("Unknown value."));
3883 if (ui_out_is_mi_like_p (uiout))
3886 ui_out_field_int (uiout, "thread-id",
3887 pid_to_thread_id (inferior_ptid));
3890 struct cleanup *back_to = make_cleanup_ui_out_list_begin_end
3891 (uiout, "stopped-threads");
3892 ui_out_field_int (uiout, NULL,
3893 pid_to_thread_id (inferior_ptid));
3894 do_cleanups (back_to);
3897 ui_out_field_string (uiout, "stopped-threads", "all");
3899 /* The behavior of this routine with respect to the source
3901 SRC_LINE: Print only source line
3902 LOCATION: Print only location
3903 SRC_AND_LOC: Print location and source line */
3904 if (do_frame_printing)
3905 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
3907 /* Display the auto-display expressions. */
3912 /* Save the function value return registers, if we care.
3913 We might be about to restore their previous contents. */
3914 if (inferior_thread ()->proceed_to_finish)
3916 /* This should not be necessary. */
3918 regcache_xfree (stop_registers);
3920 /* NB: The copy goes through to the target picking up the value of
3921 all the registers. */
3922 stop_registers = regcache_dup (get_current_regcache ());
3925 if (stop_stack_dummy)
3927 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3928 ends with a setting of the current frame, so we can use that
3930 frame_pop (get_current_frame ());
3931 /* Set stop_pc to what it was before we called the function.
3932 Can't rely on restore_inferior_status because that only gets
3933 called if we don't stop in the called function. */
3934 stop_pc = read_pc ();
3935 select_frame (get_current_frame ());
3939 annotate_stopped ();
3940 if (!suppress_stop_observer
3941 && !(target_has_execution
3942 && last.kind != TARGET_WAITKIND_SIGNALLED
3943 && last.kind != TARGET_WAITKIND_EXITED
3944 && inferior_thread ()->step_multi))
3946 if (!ptid_equal (inferior_ptid, null_ptid))
3947 observer_notify_normal_stop (inferior_thread ()->stop_bpstat);
3949 observer_notify_normal_stop (NULL);
3951 if (target_has_execution
3952 && last.kind != TARGET_WAITKIND_SIGNALLED
3953 && last.kind != TARGET_WAITKIND_EXITED)
3955 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3956 Delete any breakpoint that is to be deleted at the next stop. */
3957 breakpoint_auto_delete (inferior_thread ()->stop_bpstat);
3960 set_running (pid_to_ptid (-1), 0);
3962 set_running (inferior_ptid, 0);
3965 /* Look up the hook_stop and run it (CLI internally handles problem
3966 of stop_command's pre-hook not existing). */
3968 catch_errors (hook_stop_stub, stop_command,
3969 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3974 hook_stop_stub (void *cmd)
3976 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
3981 signal_stop_state (int signo)
3983 return signal_stop[signo];
3987 signal_print_state (int signo)
3989 return signal_print[signo];
3993 signal_pass_state (int signo)
3995 return signal_program[signo];
3999 signal_stop_update (int signo, int state)
4001 int ret = signal_stop[signo];
4002 signal_stop[signo] = state;
4007 signal_print_update (int signo, int state)
4009 int ret = signal_print[signo];
4010 signal_print[signo] = state;
4015 signal_pass_update (int signo, int state)
4017 int ret = signal_program[signo];
4018 signal_program[signo] = state;
4023 sig_print_header (void)
4025 printf_filtered (_("\
4026 Signal Stop\tPrint\tPass to program\tDescription\n"));
4030 sig_print_info (enum target_signal oursig)
4032 char *name = target_signal_to_name (oursig);
4033 int name_padding = 13 - strlen (name);
4035 if (name_padding <= 0)
4038 printf_filtered ("%s", name);
4039 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
4040 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
4041 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
4042 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
4043 printf_filtered ("%s\n", target_signal_to_string (oursig));
4046 /* Specify how various signals in the inferior should be handled. */
4049 handle_command (char *args, int from_tty)
4052 int digits, wordlen;
4053 int sigfirst, signum, siglast;
4054 enum target_signal oursig;
4057 unsigned char *sigs;
4058 struct cleanup *old_chain;
4062 error_no_arg (_("signal to handle"));
4065 /* Allocate and zero an array of flags for which signals to handle. */
4067 nsigs = (int) TARGET_SIGNAL_LAST;
4068 sigs = (unsigned char *) alloca (nsigs);
4069 memset (sigs, 0, nsigs);
4071 /* Break the command line up into args. */
4073 argv = buildargv (args);
4078 old_chain = make_cleanup_freeargv (argv);
4080 /* Walk through the args, looking for signal oursigs, signal names, and
4081 actions. Signal numbers and signal names may be interspersed with
4082 actions, with the actions being performed for all signals cumulatively
4083 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4085 while (*argv != NULL)
4087 wordlen = strlen (*argv);
4088 for (digits = 0; isdigit ((*argv)[digits]); digits++)
4092 sigfirst = siglast = -1;
4094 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
4096 /* Apply action to all signals except those used by the
4097 debugger. Silently skip those. */
4100 siglast = nsigs - 1;
4102 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
4104 SET_SIGS (nsigs, sigs, signal_stop);
4105 SET_SIGS (nsigs, sigs, signal_print);
4107 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
4109 UNSET_SIGS (nsigs, sigs, signal_program);
4111 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
4113 SET_SIGS (nsigs, sigs, signal_print);
4115 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
4117 SET_SIGS (nsigs, sigs, signal_program);
4119 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
4121 UNSET_SIGS (nsigs, sigs, signal_stop);
4123 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
4125 SET_SIGS (nsigs, sigs, signal_program);
4127 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
4129 UNSET_SIGS (nsigs, sigs, signal_print);
4130 UNSET_SIGS (nsigs, sigs, signal_stop);
4132 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
4134 UNSET_SIGS (nsigs, sigs, signal_program);
4136 else if (digits > 0)
4138 /* It is numeric. The numeric signal refers to our own
4139 internal signal numbering from target.h, not to host/target
4140 signal number. This is a feature; users really should be
4141 using symbolic names anyway, and the common ones like
4142 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
4144 sigfirst = siglast = (int)
4145 target_signal_from_command (atoi (*argv));
4146 if ((*argv)[digits] == '-')
4149 target_signal_from_command (atoi ((*argv) + digits + 1));
4151 if (sigfirst > siglast)
4153 /* Bet he didn't figure we'd think of this case... */
4161 oursig = target_signal_from_name (*argv);
4162 if (oursig != TARGET_SIGNAL_UNKNOWN)
4164 sigfirst = siglast = (int) oursig;
4168 /* Not a number and not a recognized flag word => complain. */
4169 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
4173 /* If any signal numbers or symbol names were found, set flags for
4174 which signals to apply actions to. */
4176 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
4178 switch ((enum target_signal) signum)
4180 case TARGET_SIGNAL_TRAP:
4181 case TARGET_SIGNAL_INT:
4182 if (!allsigs && !sigs[signum])
4184 if (query ("%s is used by the debugger.\n\
4185 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal) signum)))
4191 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4192 gdb_flush (gdb_stdout);
4196 case TARGET_SIGNAL_0:
4197 case TARGET_SIGNAL_DEFAULT:
4198 case TARGET_SIGNAL_UNKNOWN:
4199 /* Make sure that "all" doesn't print these. */
4210 target_notice_signals (inferior_ptid);
4214 /* Show the results. */
4215 sig_print_header ();
4216 for (signum = 0; signum < nsigs; signum++)
4220 sig_print_info (signum);
4225 do_cleanups (old_chain);
4229 xdb_handle_command (char *args, int from_tty)
4232 struct cleanup *old_chain;
4234 /* Break the command line up into args. */
4236 argv = buildargv (args);
4241 old_chain = make_cleanup_freeargv (argv);
4242 if (argv[1] != (char *) NULL)
4247 bufLen = strlen (argv[0]) + 20;
4248 argBuf = (char *) xmalloc (bufLen);
4252 enum target_signal oursig;
4254 oursig = target_signal_from_name (argv[0]);
4255 memset (argBuf, 0, bufLen);
4256 if (strcmp (argv[1], "Q") == 0)
4257 sprintf (argBuf, "%s %s", argv[0], "noprint");
4260 if (strcmp (argv[1], "s") == 0)
4262 if (!signal_stop[oursig])
4263 sprintf (argBuf, "%s %s", argv[0], "stop");
4265 sprintf (argBuf, "%s %s", argv[0], "nostop");
4267 else if (strcmp (argv[1], "i") == 0)
4269 if (!signal_program[oursig])
4270 sprintf (argBuf, "%s %s", argv[0], "pass");
4272 sprintf (argBuf, "%s %s", argv[0], "nopass");
4274 else if (strcmp (argv[1], "r") == 0)
4276 if (!signal_print[oursig])
4277 sprintf (argBuf, "%s %s", argv[0], "print");
4279 sprintf (argBuf, "%s %s", argv[0], "noprint");
4285 handle_command (argBuf, from_tty);
4287 printf_filtered (_("Invalid signal handling flag.\n"));
4292 do_cleanups (old_chain);
4295 /* Print current contents of the tables set by the handle command.
4296 It is possible we should just be printing signals actually used
4297 by the current target (but for things to work right when switching
4298 targets, all signals should be in the signal tables). */
4301 signals_info (char *signum_exp, int from_tty)
4303 enum target_signal oursig;
4304 sig_print_header ();
4308 /* First see if this is a symbol name. */
4309 oursig = target_signal_from_name (signum_exp);
4310 if (oursig == TARGET_SIGNAL_UNKNOWN)
4312 /* No, try numeric. */
4314 target_signal_from_command (parse_and_eval_long (signum_exp));
4316 sig_print_info (oursig);
4320 printf_filtered ("\n");
4321 /* These ugly casts brought to you by the native VAX compiler. */
4322 for (oursig = TARGET_SIGNAL_FIRST;
4323 (int) oursig < (int) TARGET_SIGNAL_LAST;
4324 oursig = (enum target_signal) ((int) oursig + 1))
4328 if (oursig != TARGET_SIGNAL_UNKNOWN
4329 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
4330 sig_print_info (oursig);
4333 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4336 struct inferior_status
4338 enum target_signal stop_signal;
4342 int stop_stack_dummy;
4343 int stopped_by_random_signal;
4344 int stepping_over_breakpoint;
4345 CORE_ADDR step_range_start;
4346 CORE_ADDR step_range_end;
4347 struct frame_id step_frame_id;
4348 enum step_over_calls_kind step_over_calls;
4349 CORE_ADDR step_resume_break_address;
4350 int stop_after_trap;
4353 /* These are here because if call_function_by_hand has written some
4354 registers and then decides to call error(), we better not have changed
4356 struct regcache *registers;
4358 /* A frame unique identifier. */
4359 struct frame_id selected_frame_id;
4361 int breakpoint_proceeded;
4362 int restore_stack_info;
4363 int proceed_to_finish;
4367 write_inferior_status_register (struct inferior_status *inf_status, int regno,
4370 int size = register_size (current_gdbarch, regno);
4371 void *buf = alloca (size);
4372 store_signed_integer (buf, size, val);
4373 regcache_raw_write (inf_status->registers, regno, buf);
4376 /* Save all of the information associated with the inferior<==>gdb
4377 connection. INF_STATUS is a pointer to a "struct inferior_status"
4378 (defined in inferior.h). */
4380 struct inferior_status *
4381 save_inferior_status (int restore_stack_info)
4383 struct inferior_status *inf_status = XMALLOC (struct inferior_status);
4384 struct thread_info *tp = inferior_thread ();
4385 struct inferior *inf = current_inferior ();
4387 inf_status->stop_signal = tp->stop_signal;
4388 inf_status->stop_pc = stop_pc;
4389 inf_status->stop_step = tp->stop_step;
4390 inf_status->stop_stack_dummy = stop_stack_dummy;
4391 inf_status->stopped_by_random_signal = stopped_by_random_signal;
4392 inf_status->stepping_over_breakpoint = tp->trap_expected;
4393 inf_status->step_range_start = tp->step_range_start;
4394 inf_status->step_range_end = tp->step_range_end;
4395 inf_status->step_frame_id = tp->step_frame_id;
4396 inf_status->step_over_calls = tp->step_over_calls;
4397 inf_status->stop_after_trap = stop_after_trap;
4398 inf_status->stop_soon = inf->stop_soon;
4399 /* Save original bpstat chain here; replace it with copy of chain.
4400 If caller's caller is walking the chain, they'll be happier if we
4401 hand them back the original chain when restore_inferior_status is
4403 inf_status->stop_bpstat = tp->stop_bpstat;
4404 tp->stop_bpstat = bpstat_copy (tp->stop_bpstat);
4405 inf_status->breakpoint_proceeded = breakpoint_proceeded;
4406 inf_status->restore_stack_info = restore_stack_info;
4407 inf_status->proceed_to_finish = tp->proceed_to_finish;
4409 inf_status->registers = regcache_dup (get_current_regcache ());
4411 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
4416 restore_selected_frame (void *args)
4418 struct frame_id *fid = (struct frame_id *) args;
4419 struct frame_info *frame;
4421 frame = frame_find_by_id (*fid);
4423 /* If inf_status->selected_frame_id is NULL, there was no previously
4427 warning (_("Unable to restore previously selected frame."));
4431 select_frame (frame);
4437 restore_inferior_status (struct inferior_status *inf_status)
4439 struct thread_info *tp = inferior_thread ();
4440 struct inferior *inf = current_inferior ();
4442 tp->stop_signal = inf_status->stop_signal;
4443 stop_pc = inf_status->stop_pc;
4444 tp->stop_step = inf_status->stop_step;
4445 stop_stack_dummy = inf_status->stop_stack_dummy;
4446 stopped_by_random_signal = inf_status->stopped_by_random_signal;
4447 tp->trap_expected = inf_status->stepping_over_breakpoint;
4448 tp->step_range_start = inf_status->step_range_start;
4449 tp->step_range_end = inf_status->step_range_end;
4450 tp->step_frame_id = inf_status->step_frame_id;
4451 tp->step_over_calls = inf_status->step_over_calls;
4452 stop_after_trap = inf_status->stop_after_trap;
4453 inf->stop_soon = inf_status->stop_soon;
4454 bpstat_clear (&tp->stop_bpstat);
4455 tp->stop_bpstat = inf_status->stop_bpstat;
4456 breakpoint_proceeded = inf_status->breakpoint_proceeded;
4457 tp->proceed_to_finish = inf_status->proceed_to_finish;
4459 /* The inferior can be gone if the user types "print exit(0)"
4460 (and perhaps other times). */
4461 if (target_has_execution)
4462 /* NB: The register write goes through to the target. */
4463 regcache_cpy (get_current_regcache (), inf_status->registers);
4464 regcache_xfree (inf_status->registers);
4466 /* FIXME: If we are being called after stopping in a function which
4467 is called from gdb, we should not be trying to restore the
4468 selected frame; it just prints a spurious error message (The
4469 message is useful, however, in detecting bugs in gdb (like if gdb
4470 clobbers the stack)). In fact, should we be restoring the
4471 inferior status at all in that case? . */
4473 if (target_has_stack && inf_status->restore_stack_info)
4475 /* The point of catch_errors is that if the stack is clobbered,
4476 walking the stack might encounter a garbage pointer and
4477 error() trying to dereference it. */
4479 (restore_selected_frame, &inf_status->selected_frame_id,
4480 "Unable to restore previously selected frame:\n",
4481 RETURN_MASK_ERROR) == 0)
4482 /* Error in restoring the selected frame. Select the innermost
4484 select_frame (get_current_frame ());
4492 do_restore_inferior_status_cleanup (void *sts)
4494 restore_inferior_status (sts);
4498 make_cleanup_restore_inferior_status (struct inferior_status *inf_status)
4500 return make_cleanup (do_restore_inferior_status_cleanup, inf_status);
4504 discard_inferior_status (struct inferior_status *inf_status)
4506 /* See save_inferior_status for info on stop_bpstat. */
4507 bpstat_clear (&inf_status->stop_bpstat);
4508 regcache_xfree (inf_status->registers);
4513 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
4515 struct target_waitstatus last;
4518 get_last_target_status (&last_ptid, &last);
4520 if (last.kind != TARGET_WAITKIND_FORKED)
4523 if (!ptid_equal (last_ptid, pid))
4526 *child_pid = last.value.related_pid;
4531 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
4533 struct target_waitstatus last;
4536 get_last_target_status (&last_ptid, &last);
4538 if (last.kind != TARGET_WAITKIND_VFORKED)
4541 if (!ptid_equal (last_ptid, pid))
4544 *child_pid = last.value.related_pid;
4549 inferior_has_execd (ptid_t pid, char **execd_pathname)
4551 struct target_waitstatus last;
4554 get_last_target_status (&last_ptid, &last);
4556 if (last.kind != TARGET_WAITKIND_EXECD)
4559 if (!ptid_equal (last_ptid, pid))
4562 *execd_pathname = xstrdup (last.value.execd_pathname);
4566 /* Oft used ptids */
4568 ptid_t minus_one_ptid;
4570 /* Create a ptid given the necessary PID, LWP, and TID components. */
4573 ptid_build (int pid, long lwp, long tid)
4583 /* Create a ptid from just a pid. */
4586 pid_to_ptid (int pid)
4588 return ptid_build (pid, 0, 0);
4591 /* Fetch the pid (process id) component from a ptid. */
4594 ptid_get_pid (ptid_t ptid)
4599 /* Fetch the lwp (lightweight process) component from a ptid. */
4602 ptid_get_lwp (ptid_t ptid)
4607 /* Fetch the tid (thread id) component from a ptid. */
4610 ptid_get_tid (ptid_t ptid)
4615 /* ptid_equal() is used to test equality of two ptids. */
4618 ptid_equal (ptid_t ptid1, ptid_t ptid2)
4620 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
4621 && ptid1.tid == ptid2.tid);
4624 /* restore_inferior_ptid() will be used by the cleanup machinery
4625 to restore the inferior_ptid value saved in a call to
4626 save_inferior_ptid(). */
4629 restore_inferior_ptid (void *arg)
4631 ptid_t *saved_ptid_ptr = arg;
4632 inferior_ptid = *saved_ptid_ptr;
4636 /* Save the value of inferior_ptid so that it may be restored by a
4637 later call to do_cleanups(). Returns the struct cleanup pointer
4638 needed for later doing the cleanup. */
4641 save_inferior_ptid (void)
4643 ptid_t *saved_ptid_ptr;
4645 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
4646 *saved_ptid_ptr = inferior_ptid;
4647 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
4652 static int non_stop_1 = 0;
4655 set_non_stop (char *args, int from_tty,
4656 struct cmd_list_element *c)
4658 if (target_has_execution)
4660 non_stop_1 = non_stop;
4661 error (_("Cannot change this setting while the inferior is running."));
4664 non_stop = non_stop_1;
4668 show_non_stop (struct ui_file *file, int from_tty,
4669 struct cmd_list_element *c, const char *value)
4671 fprintf_filtered (file,
4672 _("Controlling the inferior in non-stop mode is %s.\n"),
4678 _initialize_infrun (void)
4682 struct cmd_list_element *c;
4684 add_info ("signals", signals_info, _("\
4685 What debugger does when program gets various signals.\n\
4686 Specify a signal as argument to print info on that signal only."));
4687 add_info_alias ("handle", "signals", 0);
4689 add_com ("handle", class_run, handle_command, _("\
4690 Specify how to handle a signal.\n\
4691 Args are signals and actions to apply to those signals.\n\
4692 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4693 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4694 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4695 The special arg \"all\" is recognized to mean all signals except those\n\
4696 used by the debugger, typically SIGTRAP and SIGINT.\n\
4697 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4698 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4699 Stop means reenter debugger if this signal happens (implies print).\n\
4700 Print means print a message if this signal happens.\n\
4701 Pass means let program see this signal; otherwise program doesn't know.\n\
4702 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4703 Pass and Stop may be combined."));
4706 add_com ("lz", class_info, signals_info, _("\
4707 What debugger does when program gets various signals.\n\
4708 Specify a signal as argument to print info on that signal only."));
4709 add_com ("z", class_run, xdb_handle_command, _("\
4710 Specify how to handle a signal.\n\
4711 Args are signals and actions to apply to those signals.\n\
4712 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4713 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4714 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4715 The special arg \"all\" is recognized to mean all signals except those\n\
4716 used by the debugger, typically SIGTRAP and SIGINT.\n\
4717 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4718 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4719 nopass), \"Q\" (noprint)\n\
4720 Stop means reenter debugger if this signal happens (implies print).\n\
4721 Print means print a message if this signal happens.\n\
4722 Pass means let program see this signal; otherwise program doesn't know.\n\
4723 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4724 Pass and Stop may be combined."));
4728 stop_command = add_cmd ("stop", class_obscure,
4729 not_just_help_class_command, _("\
4730 There is no `stop' command, but you can set a hook on `stop'.\n\
4731 This allows you to set a list of commands to be run each time execution\n\
4732 of the program stops."), &cmdlist);
4734 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
4735 Set inferior debugging."), _("\
4736 Show inferior debugging."), _("\
4737 When non-zero, inferior specific debugging is enabled."),
4740 &setdebuglist, &showdebuglist);
4742 add_setshow_boolean_cmd ("displaced", class_maintenance, &debug_displaced, _("\
4743 Set displaced stepping debugging."), _("\
4744 Show displaced stepping debugging."), _("\
4745 When non-zero, displaced stepping specific debugging is enabled."),
4747 show_debug_displaced,
4748 &setdebuglist, &showdebuglist);
4750 add_setshow_boolean_cmd ("non-stop", no_class,
4752 Set whether gdb controls the inferior in non-stop mode."), _("\
4753 Show whether gdb controls the inferior in non-stop mode."), _("\
4754 When debugging a multi-threaded program and this setting is\n\
4755 off (the default, also called all-stop mode), when one thread stops\n\
4756 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
4757 all other threads in the program while you interact with the thread of\n\
4758 interest. When you continue or step a thread, you can allow the other\n\
4759 threads to run, or have them remain stopped, but while you inspect any\n\
4760 thread's state, all threads stop.\n\
4762 In non-stop mode, when one thread stops, other threads can continue\n\
4763 to run freely. You'll be able to step each thread independently,\n\
4764 leave it stopped or free to run as needed."),
4770 numsigs = (int) TARGET_SIGNAL_LAST;
4771 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
4772 signal_print = (unsigned char *)
4773 xmalloc (sizeof (signal_print[0]) * numsigs);
4774 signal_program = (unsigned char *)
4775 xmalloc (sizeof (signal_program[0]) * numsigs);
4776 for (i = 0; i < numsigs; i++)
4779 signal_print[i] = 1;
4780 signal_program[i] = 1;
4783 /* Signals caused by debugger's own actions
4784 should not be given to the program afterwards. */
4785 signal_program[TARGET_SIGNAL_TRAP] = 0;
4786 signal_program[TARGET_SIGNAL_INT] = 0;
4788 /* Signals that are not errors should not normally enter the debugger. */
4789 signal_stop[TARGET_SIGNAL_ALRM] = 0;
4790 signal_print[TARGET_SIGNAL_ALRM] = 0;
4791 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
4792 signal_print[TARGET_SIGNAL_VTALRM] = 0;
4793 signal_stop[TARGET_SIGNAL_PROF] = 0;
4794 signal_print[TARGET_SIGNAL_PROF] = 0;
4795 signal_stop[TARGET_SIGNAL_CHLD] = 0;
4796 signal_print[TARGET_SIGNAL_CHLD] = 0;
4797 signal_stop[TARGET_SIGNAL_IO] = 0;
4798 signal_print[TARGET_SIGNAL_IO] = 0;
4799 signal_stop[TARGET_SIGNAL_POLL] = 0;
4800 signal_print[TARGET_SIGNAL_POLL] = 0;
4801 signal_stop[TARGET_SIGNAL_URG] = 0;
4802 signal_print[TARGET_SIGNAL_URG] = 0;
4803 signal_stop[TARGET_SIGNAL_WINCH] = 0;
4804 signal_print[TARGET_SIGNAL_WINCH] = 0;
4806 /* These signals are used internally by user-level thread
4807 implementations. (See signal(5) on Solaris.) Like the above
4808 signals, a healthy program receives and handles them as part of
4809 its normal operation. */
4810 signal_stop[TARGET_SIGNAL_LWP] = 0;
4811 signal_print[TARGET_SIGNAL_LWP] = 0;
4812 signal_stop[TARGET_SIGNAL_WAITING] = 0;
4813 signal_print[TARGET_SIGNAL_WAITING] = 0;
4814 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
4815 signal_print[TARGET_SIGNAL_CANCEL] = 0;
4817 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
4818 &stop_on_solib_events, _("\
4819 Set stopping for shared library events."), _("\
4820 Show stopping for shared library events."), _("\
4821 If nonzero, gdb will give control to the user when the dynamic linker\n\
4822 notifies gdb of shared library events. The most common event of interest\n\
4823 to the user would be loading/unloading of a new library."),
4825 show_stop_on_solib_events,
4826 &setlist, &showlist);
4828 add_setshow_enum_cmd ("follow-fork-mode", class_run,
4829 follow_fork_mode_kind_names,
4830 &follow_fork_mode_string, _("\
4831 Set debugger response to a program call of fork or vfork."), _("\
4832 Show debugger response to a program call of fork or vfork."), _("\
4833 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4834 parent - the original process is debugged after a fork\n\
4835 child - the new process is debugged after a fork\n\
4836 The unfollowed process will continue to run.\n\
4837 By default, the debugger will follow the parent process."),
4839 show_follow_fork_mode_string,
4840 &setlist, &showlist);
4842 add_setshow_enum_cmd ("scheduler-locking", class_run,
4843 scheduler_enums, &scheduler_mode, _("\
4844 Set mode for locking scheduler during execution."), _("\
4845 Show mode for locking scheduler during execution."), _("\
4846 off == no locking (threads may preempt at any time)\n\
4847 on == full locking (no thread except the current thread may run)\n\
4848 step == scheduler locked during every single-step operation.\n\
4849 In this mode, no other thread may run during a step command.\n\
4850 Other threads may run while stepping over a function call ('next')."),
4851 set_schedlock_func, /* traps on target vector */
4852 show_scheduler_mode,
4853 &setlist, &showlist);
4855 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
4856 Set mode of the step operation."), _("\
4857 Show mode of the step operation."), _("\
4858 When set, doing a step over a function without debug line information\n\
4859 will stop at the first instruction of that function. Otherwise, the\n\
4860 function is skipped and the step command stops at a different source line."),
4862 show_step_stop_if_no_debug,
4863 &setlist, &showlist);
4865 add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance,
4866 &can_use_displaced_stepping, _("\
4867 Set debugger's willingness to use displaced stepping."), _("\
4868 Show debugger's willingness to use displaced stepping."), _("\
4869 If zero, gdb will not use displaced stepping to step over\n\
4870 breakpoints, even if such is supported by the target."),
4872 show_can_use_displaced_stepping,
4873 &maintenance_set_cmdlist,
4874 &maintenance_show_cmdlist);
4876 /* ptid initializations */
4877 null_ptid = ptid_build (0, 0, 0);
4878 minus_one_ptid = ptid_build (-1, 0, 0);
4879 inferior_ptid = null_ptid;
4880 target_last_wait_ptid = minus_one_ptid;
4881 displaced_step_ptid = null_ptid;
4883 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);