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 struct thread_stepping_state
;
78 static int currently_stepping (struct thread_stepping_state
*tss
);
80 static void xdb_handle_command (char *args
, int from_tty
);
82 static int prepare_to_proceed (int);
84 void _initialize_infrun (void);
86 /* When set, stop the 'step' command if we enter a function which has
87 no line number information. The normal behavior is that we step
88 over such function. */
89 int step_stop_if_no_debug
= 0;
91 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
92 struct cmd_list_element
*c
, const char *value
)
94 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
97 /* In asynchronous mode, but simulating synchronous execution. */
99 int sync_execution
= 0;
101 /* wait_for_inferior and normal_stop use this to notify the user
102 when the inferior stopped in a different thread than it had been
105 static ptid_t previous_inferior_ptid
;
107 int debug_displaced
= 0;
109 show_debug_displaced (struct ui_file
*file
, int from_tty
,
110 struct cmd_list_element
*c
, const char *value
)
112 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
115 static int debug_infrun
= 0;
117 show_debug_infrun (struct ui_file
*file
, int from_tty
,
118 struct cmd_list_element
*c
, const char *value
)
120 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
123 /* If the program uses ELF-style shared libraries, then calls to
124 functions in shared libraries go through stubs, which live in a
125 table called the PLT (Procedure Linkage Table). The first time the
126 function is called, the stub sends control to the dynamic linker,
127 which looks up the function's real address, patches the stub so
128 that future calls will go directly to the function, and then passes
129 control to the function.
131 If we are stepping at the source level, we don't want to see any of
132 this --- we just want to skip over the stub and the dynamic linker.
133 The simple approach is to single-step until control leaves the
136 However, on some systems (e.g., Red Hat's 5.2 distribution) the
137 dynamic linker calls functions in the shared C library, so you
138 can't tell from the PC alone whether the dynamic linker is still
139 running. In this case, we use a step-resume breakpoint to get us
140 past the dynamic linker, as if we were using "next" to step over a
143 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
144 linker code or not. Normally, this means we single-step. However,
145 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
146 address where we can place a step-resume breakpoint to get past the
147 linker's symbol resolution function.
149 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
150 pretty portable way, by comparing the PC against the address ranges
151 of the dynamic linker's sections.
153 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
154 it depends on internal details of the dynamic linker. It's usually
155 not too hard to figure out where to put a breakpoint, but it
156 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
157 sanity checking. If it can't figure things out, returning zero and
158 getting the (possibly confusing) stepping behavior is better than
159 signalling an error, which will obscure the change in the
162 /* This function returns TRUE if pc is the address of an instruction
163 that lies within the dynamic linker (such as the event hook, or the
166 This function must be used only when a dynamic linker event has
167 been caught, and the inferior is being stepped out of the hook, or
168 undefined results are guaranteed. */
170 #ifndef SOLIB_IN_DYNAMIC_LINKER
171 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
175 /* Convert the #defines into values. This is temporary until wfi control
176 flow is completely sorted out. */
178 #ifndef CANNOT_STEP_HW_WATCHPOINTS
179 #define CANNOT_STEP_HW_WATCHPOINTS 0
181 #undef CANNOT_STEP_HW_WATCHPOINTS
182 #define CANNOT_STEP_HW_WATCHPOINTS 1
185 /* Tables of how to react to signals; the user sets them. */
187 static unsigned char *signal_stop
;
188 static unsigned char *signal_print
;
189 static unsigned char *signal_program
;
191 #define SET_SIGS(nsigs,sigs,flags) \
193 int signum = (nsigs); \
194 while (signum-- > 0) \
195 if ((sigs)[signum]) \
196 (flags)[signum] = 1; \
199 #define UNSET_SIGS(nsigs,sigs,flags) \
201 int signum = (nsigs); \
202 while (signum-- > 0) \
203 if ((sigs)[signum]) \
204 (flags)[signum] = 0; \
207 /* Value to pass to target_resume() to cause all threads to resume */
209 #define RESUME_ALL (pid_to_ptid (-1))
211 /* Command list pointer for the "stop" placeholder. */
213 static struct cmd_list_element
*stop_command
;
215 /* Function inferior was in as of last step command. */
217 static struct symbol
*step_start_function
;
219 /* Nonzero if we are presently stepping over a breakpoint.
221 If we hit a breakpoint or watchpoint, and then continue,
222 we need to single step the current thread with breakpoints
223 disabled, to avoid hitting the same breakpoint or
224 watchpoint again. And we should step just a single
225 thread and keep other threads stopped, so that
226 other threads don't miss breakpoints while they are removed.
228 So, this variable simultaneously means that we need to single
229 step the current thread, keep other threads stopped, and that
230 breakpoints should be removed while we step.
232 This variable is set either:
233 - in proceed, when we resume inferior on user's explicit request
234 - in keep_going, if handle_inferior_event decides we need to
235 step over breakpoint.
237 The variable is cleared in clear_proceed_status, called every
238 time before we call proceed. The proceed calls wait_for_inferior,
239 which calls handle_inferior_event in a loop, and until
240 wait_for_inferior exits, this variable is changed only by keep_going. */
242 static int stepping_over_breakpoint
;
244 /* Nonzero if we want to give control to the user when we're notified
245 of shared library events by the dynamic linker. */
246 static int stop_on_solib_events
;
248 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
249 struct cmd_list_element
*c
, const char *value
)
251 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
255 /* Nonzero means expecting a trace trap
256 and should stop the inferior and return silently when it happens. */
260 /* Nonzero means expecting a trap and caller will handle it themselves.
261 It is used after attach, due to attaching to a process;
262 when running in the shell before the child program has been exec'd;
263 and when running some kinds of remote stuff (FIXME?). */
265 enum stop_kind stop_soon
;
267 /* Nonzero if proceed is being used for a "finish" command or a similar
268 situation when stop_registers should be saved. */
270 int proceed_to_finish
;
272 /* Save register contents here when about to pop a stack dummy frame,
273 if-and-only-if proceed_to_finish is set.
274 Thus this contains the return value from the called function (assuming
275 values are returned in a register). */
277 struct regcache
*stop_registers
;
279 /* Nonzero after stop if current stack frame should be printed. */
281 static int stop_print_frame
;
283 /* Step-resume or longjmp-resume breakpoint. */
284 static struct breakpoint
*step_resume_breakpoint
= NULL
;
286 /* This is a cached copy of the pid/waitstatus of the last event
287 returned by target_wait()/deprecated_target_wait_hook(). This
288 information is returned by get_last_target_status(). */
289 static ptid_t target_last_wait_ptid
;
290 static struct target_waitstatus target_last_waitstatus
;
292 /* Context-switchable data. */
293 struct thread_stepping_state
295 /* Should we step over breakpoint next time keep_going
297 int stepping_over_breakpoint
;
298 struct symtab_and_line sal
;
300 struct symtab
*current_symtab
;
301 int step_after_step_resume_breakpoint
;
302 int stepping_through_solib_after_catch
;
303 bpstat stepping_through_solib_catchpoints
;
306 struct thread_stepping_state gtss
;
307 struct thread_stepping_state
*tss
= >ss
;
309 static void context_switch (ptid_t ptid
);
311 void init_thread_stepping_state (struct thread_stepping_state
*tss
);
313 void init_infwait_state (void);
315 /* This is used to remember when a fork, vfork or exec event
316 was caught by a catchpoint, and thus the event is to be
317 followed at the next resume of the inferior, and not
321 enum target_waitkind kind
;
328 char *execd_pathname
;
332 static const char follow_fork_mode_child
[] = "child";
333 static const char follow_fork_mode_parent
[] = "parent";
335 static const char *follow_fork_mode_kind_names
[] = {
336 follow_fork_mode_child
,
337 follow_fork_mode_parent
,
341 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
343 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
344 struct cmd_list_element
*c
, const char *value
)
346 fprintf_filtered (file
, _("\
347 Debugger response to a program call of fork or vfork is \"%s\".\n"),
355 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
357 return target_follow_fork (follow_child
);
361 follow_inferior_reset_breakpoints (void)
363 /* Was there a step_resume breakpoint? (There was if the user
364 did a "next" at the fork() call.) If so, explicitly reset its
367 step_resumes are a form of bp that are made to be per-thread.
368 Since we created the step_resume bp when the parent process
369 was being debugged, and now are switching to the child process,
370 from the breakpoint package's viewpoint, that's a switch of
371 "threads". We must update the bp's notion of which thread
372 it is for, or it'll be ignored when it triggers. */
374 if (step_resume_breakpoint
)
375 breakpoint_re_set_thread (step_resume_breakpoint
);
377 /* Reinsert all breakpoints in the child. The user may have set
378 breakpoints after catching the fork, in which case those
379 were never set in the child, but only in the parent. This makes
380 sure the inserted breakpoints match the breakpoint list. */
382 breakpoint_re_set ();
383 insert_breakpoints ();
386 /* EXECD_PATHNAME is assumed to be non-NULL. */
389 follow_exec (ptid_t pid
, char *execd_pathname
)
391 ptid_t saved_pid
= pid
;
392 struct target_ops
*tgt
;
394 /* This is an exec event that we actually wish to pay attention to.
395 Refresh our symbol table to the newly exec'd program, remove any
398 If there are breakpoints, they aren't really inserted now,
399 since the exec() transformed our inferior into a fresh set
402 We want to preserve symbolic breakpoints on the list, since
403 we have hopes that they can be reset after the new a.out's
404 symbol table is read.
406 However, any "raw" breakpoints must be removed from the list
407 (e.g., the solib bp's), since their address is probably invalid
410 And, we DON'T want to call delete_breakpoints() here, since
411 that may write the bp's "shadow contents" (the instruction
412 value that was overwritten witha TRAP instruction). Since
413 we now have a new a.out, those shadow contents aren't valid. */
414 update_breakpoints_after_exec ();
416 /* If there was one, it's gone now. We cannot truly step-to-next
417 statement through an exec(). */
418 step_resume_breakpoint
= NULL
;
419 step_range_start
= 0;
422 /* What is this a.out's name? */
423 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
425 /* We've followed the inferior through an exec. Therefore, the
426 inferior has essentially been killed & reborn. */
428 gdb_flush (gdb_stdout
);
429 generic_mourn_inferior ();
430 /* Because mourn_inferior resets inferior_ptid. */
431 inferior_ptid
= saved_pid
;
433 if (gdb_sysroot
&& *gdb_sysroot
)
435 char *name
= alloca (strlen (gdb_sysroot
)
436 + strlen (execd_pathname
)
438 strcpy (name
, gdb_sysroot
);
439 strcat (name
, execd_pathname
);
440 execd_pathname
= name
;
443 /* That a.out is now the one to use. */
444 exec_file_attach (execd_pathname
, 0);
446 /* Reset the shared library package. This ensures that we get a
447 shlib event when the child reaches "_start", at which point the
448 dld will have had a chance to initialize the child. */
449 /* Also, loading a symbol file below may trigger symbol lookups, and
450 we don't want those to be satisfied by the libraries of the
451 previous incarnation of this process. */
452 no_shared_libraries (NULL
, 0);
454 /* Load the main file's symbols. */
455 symbol_file_add_main (execd_pathname
, 0);
457 #ifdef SOLIB_CREATE_INFERIOR_HOOK
458 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
460 solib_create_inferior_hook ();
463 /* Reinsert all breakpoints. (Those which were symbolic have
464 been reset to the proper address in the new a.out, thanks
465 to symbol_file_command...) */
466 insert_breakpoints ();
468 /* The next resume of this inferior should bring it to the shlib
469 startup breakpoints. (If the user had also set bp's on
470 "main" from the old (parent) process, then they'll auto-
471 matically get reset there in the new process.) */
474 /* Non-zero if we just simulating a single-step. This is needed
475 because we cannot remove the breakpoints in the inferior process
476 until after the `wait' in `wait_for_inferior'. */
477 static int singlestep_breakpoints_inserted_p
= 0;
479 /* The thread we inserted single-step breakpoints for. */
480 static ptid_t singlestep_ptid
;
482 /* PC when we started this single-step. */
483 static CORE_ADDR singlestep_pc
;
485 /* If another thread hit the singlestep breakpoint, we save the original
486 thread here so that we can resume single-stepping it later. */
487 static ptid_t saved_singlestep_ptid
;
488 static int stepping_past_singlestep_breakpoint
;
490 /* If not equal to null_ptid, this means that after stepping over breakpoint
491 is finished, we need to switch to deferred_step_ptid, and step it.
493 The use case is when one thread has hit a breakpoint, and then the user
494 has switched to another thread and issued 'step'. We need to step over
495 breakpoint in the thread which hit the breakpoint, but then continue
496 stepping the thread user has selected. */
497 static ptid_t deferred_step_ptid
;
499 /* Displaced stepping. */
501 /* In non-stop debugging mode, we must take special care to manage
502 breakpoints properly; in particular, the traditional strategy for
503 stepping a thread past a breakpoint it has hit is unsuitable.
504 'Displaced stepping' is a tactic for stepping one thread past a
505 breakpoint it has hit while ensuring that other threads running
506 concurrently will hit the breakpoint as they should.
508 The traditional way to step a thread T off a breakpoint in a
509 multi-threaded program in all-stop mode is as follows:
511 a0) Initially, all threads are stopped, and breakpoints are not
513 a1) We single-step T, leaving breakpoints uninserted.
514 a2) We insert breakpoints, and resume all threads.
516 In non-stop debugging, however, this strategy is unsuitable: we
517 don't want to have to stop all threads in the system in order to
518 continue or step T past a breakpoint. Instead, we use displaced
521 n0) Initially, T is stopped, other threads are running, and
522 breakpoints are inserted.
523 n1) We copy the instruction "under" the breakpoint to a separate
524 location, outside the main code stream, making any adjustments
525 to the instruction, register, and memory state as directed by
527 n2) We single-step T over the instruction at its new location.
528 n3) We adjust the resulting register and memory state as directed
529 by T's architecture. This includes resetting T's PC to point
530 back into the main instruction stream.
533 This approach depends on the following gdbarch methods:
535 - gdbarch_max_insn_length and gdbarch_displaced_step_location
536 indicate where to copy the instruction, and how much space must
537 be reserved there. We use these in step n1.
539 - gdbarch_displaced_step_copy_insn copies a instruction to a new
540 address, and makes any necessary adjustments to the instruction,
541 register contents, and memory. We use this in step n1.
543 - gdbarch_displaced_step_fixup adjusts registers and memory after
544 we have successfuly single-stepped the instruction, to yield the
545 same effect the instruction would have had if we had executed it
546 at its original address. We use this in step n3.
548 - gdbarch_displaced_step_free_closure provides cleanup.
550 The gdbarch_displaced_step_copy_insn and
551 gdbarch_displaced_step_fixup functions must be written so that
552 copying an instruction with gdbarch_displaced_step_copy_insn,
553 single-stepping across the copied instruction, and then applying
554 gdbarch_displaced_insn_fixup should have the same effects on the
555 thread's memory and registers as stepping the instruction in place
556 would have. Exactly which responsibilities fall to the copy and
557 which fall to the fixup is up to the author of those functions.
559 See the comments in gdbarch.sh for details.
561 Note that displaced stepping and software single-step cannot
562 currently be used in combination, although with some care I think
563 they could be made to. Software single-step works by placing
564 breakpoints on all possible subsequent instructions; if the
565 displaced instruction is a PC-relative jump, those breakpoints
566 could fall in very strange places --- on pages that aren't
567 executable, or at addresses that are not proper instruction
568 boundaries. (We do generally let other threads run while we wait
569 to hit the software single-step breakpoint, and they might
570 encounter such a corrupted instruction.) One way to work around
571 this would be to have gdbarch_displaced_step_copy_insn fully
572 simulate the effect of PC-relative instructions (and return NULL)
573 on architectures that use software single-stepping.
575 In non-stop mode, we can have independent and simultaneous step
576 requests, so more than one thread may need to simultaneously step
577 over a breakpoint. The current implementation assumes there is
578 only one scratch space per process. In this case, we have to
579 serialize access to the scratch space. If thread A wants to step
580 over a breakpoint, but we are currently waiting for some other
581 thread to complete a displaced step, we leave thread A stopped and
582 place it in the displaced_step_request_queue. Whenever a displaced
583 step finishes, we pick the next thread in the queue and start a new
584 displaced step operation on it. See displaced_step_prepare and
585 displaced_step_fixup for details. */
587 /* If this is not null_ptid, this is the thread carrying out a
588 displaced single-step. This thread's state will require fixing up
589 once it has completed its step. */
590 static ptid_t displaced_step_ptid
;
592 struct displaced_step_request
595 struct displaced_step_request
*next
;
598 /* A queue of pending displaced stepping requests. */
599 struct displaced_step_request
*displaced_step_request_queue
;
601 /* The architecture the thread had when we stepped it. */
602 static struct gdbarch
*displaced_step_gdbarch
;
604 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
605 for post-step cleanup. */
606 static struct displaced_step_closure
*displaced_step_closure
;
608 /* The address of the original instruction, and the copy we made. */
609 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
611 /* Saved contents of copy area. */
612 static gdb_byte
*displaced_step_saved_copy
;
614 /* When this is non-zero, we are allowed to use displaced stepping, if
615 the architecture supports it. When this is zero, we use
616 traditional the hold-and-step approach. */
617 int can_use_displaced_stepping
= 1;
619 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
620 struct cmd_list_element
*c
,
623 fprintf_filtered (file
, _("\
624 Debugger's willingness to use displaced stepping to step over "
625 "breakpoints is %s.\n"), value
);
628 /* Return non-zero if displaced stepping is enabled, and can be used
631 use_displaced_stepping (struct gdbarch
*gdbarch
)
633 return (can_use_displaced_stepping
634 && gdbarch_displaced_step_copy_insn_p (gdbarch
));
637 /* Clean out any stray displaced stepping state. */
639 displaced_step_clear (void)
641 /* Indicate that there is no cleanup pending. */
642 displaced_step_ptid
= null_ptid
;
644 if (displaced_step_closure
)
646 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
647 displaced_step_closure
);
648 displaced_step_closure
= NULL
;
653 cleanup_displaced_step_closure (void *ptr
)
655 struct displaced_step_closure
*closure
= ptr
;
657 gdbarch_displaced_step_free_closure (current_gdbarch
, closure
);
660 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
662 displaced_step_dump_bytes (struct ui_file
*file
,
668 for (i
= 0; i
< len
; i
++)
669 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
670 fputs_unfiltered ("\n", file
);
673 /* Prepare to single-step, using displaced stepping.
675 Note that we cannot use displaced stepping when we have a signal to
676 deliver. If we have a signal to deliver and an instruction to step
677 over, then after the step, there will be no indication from the
678 target whether the thread entered a signal handler or ignored the
679 signal and stepped over the instruction successfully --- both cases
680 result in a simple SIGTRAP. In the first case we mustn't do a
681 fixup, and in the second case we must --- but we can't tell which.
682 Comments in the code for 'random signals' in handle_inferior_event
683 explain how we handle this case instead.
685 Returns 1 if preparing was successful -- this thread is going to be
686 stepped now; or 0 if displaced stepping this thread got queued. */
688 displaced_step_prepare (ptid_t ptid
)
690 struct cleanup
*old_cleanups
;
691 struct regcache
*regcache
= get_thread_regcache (ptid
);
692 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
693 CORE_ADDR original
, copy
;
695 struct displaced_step_closure
*closure
;
697 /* We should never reach this function if the architecture does not
698 support displaced stepping. */
699 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
701 /* For the first cut, we're displaced stepping one thread at a
704 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
706 /* Already waiting for a displaced step to finish. Defer this
707 request and place in queue. */
708 struct displaced_step_request
*req
, *new_req
;
711 fprintf_unfiltered (gdb_stdlog
,
712 "displaced: defering step of %s\n",
713 target_pid_to_str (ptid
));
715 new_req
= xmalloc (sizeof (*new_req
));
716 new_req
->ptid
= ptid
;
717 new_req
->next
= NULL
;
719 if (displaced_step_request_queue
)
721 for (req
= displaced_step_request_queue
;
728 displaced_step_request_queue
= new_req
;
735 fprintf_unfiltered (gdb_stdlog
,
736 "displaced: stepping %s now\n",
737 target_pid_to_str (ptid
));
740 displaced_step_clear ();
742 original
= regcache_read_pc (regcache
);
744 copy
= gdbarch_displaced_step_location (gdbarch
);
745 len
= gdbarch_max_insn_length (gdbarch
);
747 /* Save the original contents of the copy area. */
748 displaced_step_saved_copy
= xmalloc (len
);
749 old_cleanups
= make_cleanup (free_current_contents
,
750 &displaced_step_saved_copy
);
751 read_memory (copy
, displaced_step_saved_copy
, len
);
754 fprintf_unfiltered (gdb_stdlog
, "displaced: saved 0x%s: ",
756 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
759 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
760 original
, copy
, regcache
);
762 /* We don't support the fully-simulated case at present. */
763 gdb_assert (closure
);
765 make_cleanup (cleanup_displaced_step_closure
, closure
);
767 /* Resume execution at the copy. */
768 regcache_write_pc (regcache
, copy
);
770 discard_cleanups (old_cleanups
);
773 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to 0x%s\n",
776 /* Save the information we need to fix things up if the step
778 displaced_step_ptid
= ptid
;
779 displaced_step_gdbarch
= gdbarch
;
780 displaced_step_closure
= closure
;
781 displaced_step_original
= original
;
782 displaced_step_copy
= copy
;
787 displaced_step_clear_cleanup (void *ignore
)
789 displaced_step_clear ();
793 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
795 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
796 inferior_ptid
= ptid
;
797 write_memory (memaddr
, myaddr
, len
);
798 do_cleanups (ptid_cleanup
);
802 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
804 struct cleanup
*old_cleanups
;
806 /* Was this event for the pid we displaced? */
807 if (ptid_equal (displaced_step_ptid
, null_ptid
)
808 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
811 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
813 /* Restore the contents of the copy area. */
815 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
816 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
817 displaced_step_saved_copy
, len
);
819 fprintf_unfiltered (gdb_stdlog
, "displaced: restored 0x%s\n",
820 paddr_nz (displaced_step_copy
));
823 /* Did the instruction complete successfully? */
824 if (signal
== TARGET_SIGNAL_TRAP
)
826 /* Fix up the resulting state. */
827 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
828 displaced_step_closure
,
829 displaced_step_original
,
831 get_thread_regcache (displaced_step_ptid
));
835 /* Since the instruction didn't complete, all we can do is
837 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
838 CORE_ADDR pc
= regcache_read_pc (regcache
);
839 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
840 regcache_write_pc (regcache
, pc
);
843 do_cleanups (old_cleanups
);
845 /* Are there any pending displaced stepping requests? If so, run
847 if (displaced_step_request_queue
)
849 struct displaced_step_request
*head
;
852 head
= displaced_step_request_queue
;
854 displaced_step_request_queue
= head
->next
;
858 fprintf_unfiltered (gdb_stdlog
,
859 "displaced: stepping queued %s now\n",
860 target_pid_to_str (ptid
));
863 displaced_step_ptid
= null_ptid
;
864 displaced_step_prepare (ptid
);
865 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
872 /* Things to clean up if we QUIT out of resume (). */
874 resume_cleanups (void *ignore
)
879 static const char schedlock_off
[] = "off";
880 static const char schedlock_on
[] = "on";
881 static const char schedlock_step
[] = "step";
882 static const char *scheduler_enums
[] = {
888 static const char *scheduler_mode
= schedlock_off
;
890 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
891 struct cmd_list_element
*c
, const char *value
)
893 fprintf_filtered (file
, _("\
894 Mode for locking scheduler during execution is \"%s\".\n"),
899 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
901 if (!target_can_lock_scheduler
)
903 scheduler_mode
= schedlock_off
;
904 error (_("Target '%s' cannot support this command."), target_shortname
);
909 /* Resume the inferior, but allow a QUIT. This is useful if the user
910 wants to interrupt some lengthy single-stepping operation
911 (for child processes, the SIGINT goes to the inferior, and so
912 we get a SIGINT random_signal, but for remote debugging and perhaps
913 other targets, that's not true).
915 STEP nonzero if we should step (zero to continue instead).
916 SIG is the signal to give the inferior (zero for none). */
918 resume (int step
, enum target_signal sig
)
920 int should_resume
= 1;
921 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
922 struct regcache
*regcache
= get_current_regcache ();
923 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
924 CORE_ADDR pc
= regcache_read_pc (regcache
);
928 fprintf_unfiltered (gdb_stdlog
,
929 "infrun: resume (step=%d, signal=%d), "
930 "stepping_over_breakpoint=%d\n",
931 step
, sig
, stepping_over_breakpoint
);
933 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
934 over an instruction that causes a page fault without triggering
935 a hardware watchpoint. The kernel properly notices that it shouldn't
936 stop, because the hardware watchpoint is not triggered, but it forgets
937 the step request and continues the program normally.
938 Work around the problem by removing hardware watchpoints if a step is
939 requested, GDB will check for a hardware watchpoint trigger after the
941 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
942 remove_hw_watchpoints ();
945 /* Normally, by the time we reach `resume', the breakpoints are either
946 removed or inserted, as appropriate. The exception is if we're sitting
947 at a permanent breakpoint; we need to step over it, but permanent
948 breakpoints can't be removed. So we have to test for it here. */
949 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
951 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
952 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
955 The program is stopped at a permanent breakpoint, but GDB does not know\n\
956 how to step past a permanent breakpoint on this architecture. Try using\n\
957 a command like `return' or `jump' to continue execution."));
960 /* If enabled, step over breakpoints by executing a copy of the
961 instruction at a different address.
963 We can't use displaced stepping when we have a signal to deliver;
964 the comments for displaced_step_prepare explain why. The
965 comments in the handle_inferior event for dealing with 'random
966 signals' explain what we do instead. */
967 if (use_displaced_stepping (gdbarch
)
968 && stepping_over_breakpoint
969 && sig
== TARGET_SIGNAL_0
)
971 if (!displaced_step_prepare (inferior_ptid
))
973 /* Got placed in displaced stepping queue. Will be resumed
974 later when all the currently queued displaced stepping
976 discard_cleanups (old_cleanups
);
981 if (step
&& gdbarch_software_single_step_p (gdbarch
))
983 /* Do it the hard way, w/temp breakpoints */
984 if (gdbarch_software_single_step (gdbarch
, get_current_frame ()))
986 /* ...and don't ask hardware to do it. */
988 /* and do not pull these breakpoints until after a `wait' in
989 `wait_for_inferior' */
990 singlestep_breakpoints_inserted_p
= 1;
991 singlestep_ptid
= inferior_ptid
;
996 /* If there were any forks/vforks/execs that were caught and are
997 now to be followed, then do so. */
998 switch (pending_follow
.kind
)
1000 case TARGET_WAITKIND_FORKED
:
1001 case TARGET_WAITKIND_VFORKED
:
1002 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
1007 case TARGET_WAITKIND_EXECD
:
1008 /* follow_exec is called as soon as the exec event is seen. */
1009 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
1016 /* Install inferior's terminal modes. */
1017 target_terminal_inferior ();
1023 resume_ptid
= RESUME_ALL
; /* Default */
1025 /* If STEP is set, it's a request to use hardware stepping
1026 facilities. But in that case, we should never
1027 use singlestep breakpoint. */
1028 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1030 if (singlestep_breakpoints_inserted_p
1031 && stepping_past_singlestep_breakpoint
)
1033 /* The situation here is as follows. In thread T1 we wanted to
1034 single-step. Lacking hardware single-stepping we've
1035 set breakpoint at the PC of the next instruction -- call it
1036 P. After resuming, we've hit that breakpoint in thread T2.
1037 Now we've removed original breakpoint, inserted breakpoint
1038 at P+1, and try to step to advance T2 past breakpoint.
1039 We need to step only T2, as if T1 is allowed to freely run,
1040 it can run past P, and if other threads are allowed to run,
1041 they can hit breakpoint at P+1, and nested hits of single-step
1042 breakpoints is not something we'd want -- that's complicated
1043 to support, and has no value. */
1044 resume_ptid
= inferior_ptid
;
1047 if ((step
|| singlestep_breakpoints_inserted_p
)
1048 && stepping_over_breakpoint
)
1050 /* We're allowing a thread to run past a breakpoint it has
1051 hit, by single-stepping the thread with the breakpoint
1052 removed. In which case, we need to single-step only this
1053 thread, and keep others stopped, as they can miss this
1054 breakpoint if allowed to run.
1056 The current code actually removes all breakpoints when
1057 doing this, not just the one being stepped over, so if we
1058 let other threads run, we can actually miss any
1059 breakpoint, not just the one at PC. */
1060 resume_ptid
= inferior_ptid
;
1065 /* With non-stop mode on, threads are always handled
1067 resume_ptid
= inferior_ptid
;
1069 else if ((scheduler_mode
== schedlock_on
)
1070 || (scheduler_mode
== schedlock_step
1071 && (step
|| singlestep_breakpoints_inserted_p
)))
1073 /* User-settable 'scheduler' mode requires solo thread resume. */
1074 resume_ptid
= inferior_ptid
;
1077 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1079 /* Most targets can step a breakpoint instruction, thus
1080 executing it normally. But if this one cannot, just
1081 continue and we will hit it anyway. */
1082 if (step
&& breakpoint_inserted_here_p (pc
))
1087 && use_displaced_stepping (gdbarch
)
1088 && stepping_over_breakpoint
)
1090 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1091 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1094 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
1095 paddr_nz (actual_pc
));
1096 read_memory (actual_pc
, buf
, sizeof (buf
));
1097 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1100 target_resume (resume_ptid
, step
, sig
);
1103 discard_cleanups (old_cleanups
);
1108 /* Clear out all variables saying what to do when inferior is continued.
1109 First do this, then set the ones you want, then call `proceed'. */
1112 clear_proceed_status (void)
1114 stepping_over_breakpoint
= 0;
1115 step_range_start
= 0;
1117 step_frame_id
= null_frame_id
;
1118 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1119 stop_after_trap
= 0;
1120 stop_soon
= NO_STOP_QUIETLY
;
1121 proceed_to_finish
= 0;
1122 breakpoint_proceeded
= 1; /* We're about to proceed... */
1126 regcache_xfree (stop_registers
);
1127 stop_registers
= NULL
;
1130 /* Discard any remaining commands or status from previous stop. */
1131 bpstat_clear (&stop_bpstat
);
1134 /* This should be suitable for any targets that support threads. */
1137 prepare_to_proceed (int step
)
1140 struct target_waitstatus wait_status
;
1142 /* Get the last target status returned by target_wait(). */
1143 get_last_target_status (&wait_ptid
, &wait_status
);
1145 /* Make sure we were stopped at a breakpoint. */
1146 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1147 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1152 /* Switched over from WAIT_PID. */
1153 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1154 && !ptid_equal (inferior_ptid
, wait_ptid
))
1156 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1158 if (breakpoint_here_p (regcache_read_pc (regcache
)))
1160 /* If stepping, remember current thread to switch back to. */
1162 deferred_step_ptid
= inferior_ptid
;
1164 /* Switch back to WAIT_PID thread. */
1165 switch_to_thread (wait_ptid
);
1167 /* We return 1 to indicate that there is a breakpoint here,
1168 so we need to step over it before continuing to avoid
1169 hitting it straight away. */
1177 /* Record the pc of the program the last time it stopped. This is
1178 just used internally by wait_for_inferior, but need to be preserved
1179 over calls to it and cleared when the inferior is started. */
1180 static CORE_ADDR prev_pc
;
1182 /* Basic routine for continuing the program in various fashions.
1184 ADDR is the address to resume at, or -1 for resume where stopped.
1185 SIGGNAL is the signal to give it, or 0 for none,
1186 or -1 for act according to how it stopped.
1187 STEP is nonzero if should trap after one instruction.
1188 -1 means return after that and print nothing.
1189 You should probably set various step_... variables
1190 before calling here, if you are stepping.
1192 You should call clear_proceed_status before calling proceed. */
1195 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1197 struct regcache
*regcache
= get_current_regcache ();
1198 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1199 CORE_ADDR pc
= regcache_read_pc (regcache
);
1203 step_start_function
= find_pc_function (pc
);
1205 stop_after_trap
= 1;
1207 if (addr
== (CORE_ADDR
) -1)
1209 if (pc
== stop_pc
&& breakpoint_here_p (pc
))
1210 /* There is a breakpoint at the address we will resume at,
1211 step one instruction before inserting breakpoints so that
1212 we do not stop right away (and report a second hit at this
1215 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1216 && gdbarch_single_step_through_delay (gdbarch
,
1217 get_current_frame ()))
1218 /* We stepped onto an instruction that needs to be stepped
1219 again before re-inserting the breakpoint, do so. */
1224 regcache_write_pc (regcache
, addr
);
1228 fprintf_unfiltered (gdb_stdlog
,
1229 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1230 paddr_nz (addr
), siggnal
, step
);
1233 /* In non-stop, each thread is handled individually. The context
1234 must already be set to the right thread here. */
1238 /* In a multi-threaded task we may select another thread and
1239 then continue or step.
1241 But if the old thread was stopped at a breakpoint, it will
1242 immediately cause another breakpoint stop without any
1243 execution (i.e. it will report a breakpoint hit incorrectly).
1244 So we must step over it first.
1246 prepare_to_proceed checks the current thread against the
1247 thread that reported the most recent event. If a step-over
1248 is required it returns TRUE and sets the current thread to
1250 if (prepare_to_proceed (step
))
1256 stepping_over_breakpoint
= 1;
1257 /* If displaced stepping is enabled, we can step over the
1258 breakpoint without hitting it, so leave all breakpoints
1259 inserted. Otherwise we need to disable all breakpoints, step
1260 one instruction, and then re-add them when that step is
1262 if (!use_displaced_stepping (gdbarch
))
1263 remove_breakpoints ();
1266 /* We can insert breakpoints if we're not trying to step over one,
1267 or if we are stepping over one but we're using displaced stepping
1269 if (! stepping_over_breakpoint
|| use_displaced_stepping (gdbarch
))
1270 insert_breakpoints ();
1272 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1273 stop_signal
= siggnal
;
1274 /* If this signal should not be seen by program,
1275 give it zero. Used for debugging signals. */
1276 else if (!signal_program
[stop_signal
])
1277 stop_signal
= TARGET_SIGNAL_0
;
1279 annotate_starting ();
1281 /* Make sure that output from GDB appears before output from the
1283 gdb_flush (gdb_stdout
);
1285 /* Refresh prev_pc value just prior to resuming. This used to be
1286 done in stop_stepping, however, setting prev_pc there did not handle
1287 scenarios such as inferior function calls or returning from
1288 a function via the return command. In those cases, the prev_pc
1289 value was not set properly for subsequent commands. The prev_pc value
1290 is used to initialize the starting line number in the ecs. With an
1291 invalid value, the gdb next command ends up stopping at the position
1292 represented by the next line table entry past our start position.
1293 On platforms that generate one line table entry per line, this
1294 is not a problem. However, on the ia64, the compiler generates
1295 extraneous line table entries that do not increase the line number.
1296 When we issue the gdb next command on the ia64 after an inferior call
1297 or a return command, we often end up a few instructions forward, still
1298 within the original line we started.
1300 An attempt was made to have init_execution_control_state () refresh
1301 the prev_pc value before calculating the line number. This approach
1302 did not work because on platforms that use ptrace, the pc register
1303 cannot be read unless the inferior is stopped. At that point, we
1304 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1305 call can fail. Setting the prev_pc value here ensures the value is
1306 updated correctly when the inferior is stopped. */
1307 prev_pc
= regcache_read_pc (get_current_regcache ());
1309 /* Fill in with reasonable starting values. */
1310 init_thread_stepping_state (tss
);
1312 /* We'll update this if & when we switch to a new thread. */
1313 previous_inferior_ptid
= inferior_ptid
;
1315 /* Reset to normal state. */
1316 init_infwait_state ();
1318 /* Resume inferior. */
1319 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1321 /* Wait for it to stop (if not standalone)
1322 and in any case decode why it stopped, and act accordingly. */
1323 /* Do this only if we are not using the event loop, or if the target
1324 does not support asynchronous execution. */
1325 if (!target_can_async_p ())
1327 wait_for_inferior (0);
1333 /* Start remote-debugging of a machine over a serial link. */
1336 start_remote (int from_tty
)
1338 init_wait_for_inferior ();
1339 stop_soon
= STOP_QUIETLY_REMOTE
;
1340 stepping_over_breakpoint
= 0;
1342 /* Always go on waiting for the target, regardless of the mode. */
1343 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1344 indicate to wait_for_inferior that a target should timeout if
1345 nothing is returned (instead of just blocking). Because of this,
1346 targets expecting an immediate response need to, internally, set
1347 things up so that the target_wait() is forced to eventually
1349 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1350 differentiate to its caller what the state of the target is after
1351 the initial open has been performed. Here we're assuming that
1352 the target has stopped. It should be possible to eventually have
1353 target_open() return to the caller an indication that the target
1354 is currently running and GDB state should be set to the same as
1355 for an async run. */
1356 wait_for_inferior (0);
1358 /* Now that the inferior has stopped, do any bookkeeping like
1359 loading shared libraries. We want to do this before normal_stop,
1360 so that the displayed frame is up to date. */
1361 post_create_inferior (¤t_target
, from_tty
);
1366 /* Initialize static vars when a new inferior begins. */
1369 init_wait_for_inferior (void)
1371 /* These are meaningless until the first time through wait_for_inferior. */
1374 breakpoint_init_inferior (inf_starting
);
1376 /* Don't confuse first call to proceed(). */
1377 stop_signal
= TARGET_SIGNAL_0
;
1379 /* The first resume is not following a fork/vfork/exec. */
1380 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1382 clear_proceed_status ();
1384 stepping_past_singlestep_breakpoint
= 0;
1385 deferred_step_ptid
= null_ptid
;
1387 target_last_wait_ptid
= minus_one_ptid
;
1389 init_thread_stepping_state (tss
);
1390 previous_inferior_ptid
= null_ptid
;
1391 init_infwait_state ();
1393 displaced_step_clear ();
1397 /* This enum encodes possible reasons for doing a target_wait, so that
1398 wfi can call target_wait in one place. (Ultimately the call will be
1399 moved out of the infinite loop entirely.) */
1403 infwait_normal_state
,
1404 infwait_thread_hop_state
,
1405 infwait_step_watch_state
,
1406 infwait_nonstep_watch_state
1409 /* Why did the inferior stop? Used to print the appropriate messages
1410 to the interface from within handle_inferior_event(). */
1411 enum inferior_stop_reason
1413 /* Step, next, nexti, stepi finished. */
1415 /* Inferior terminated by signal. */
1417 /* Inferior exited. */
1419 /* Inferior received signal, and user asked to be notified. */
1423 /* The PTID we'll do a target_wait on.*/
1426 /* Current inferior wait state. */
1427 enum infwait_states infwait_state
;
1429 /* Data to be passed around while handling an event. This data is
1430 discarded between events. */
1431 struct execution_control_state
1434 struct target_waitstatus ws
;
1436 CORE_ADDR stop_func_start
;
1437 CORE_ADDR stop_func_end
;
1438 char *stop_func_name
;
1439 int new_thread_event
;
1443 void init_execution_control_state (struct execution_control_state
*ecs
);
1445 void handle_inferior_event (struct execution_control_state
*ecs
);
1447 static void step_into_function (struct execution_control_state
*ecs
);
1448 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1449 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1450 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
1451 struct frame_id sr_id
);
1452 static void insert_longjmp_resume_breakpoint (CORE_ADDR
);
1454 static void stop_stepping (struct execution_control_state
*ecs
);
1455 static void prepare_to_wait (struct execution_control_state
*ecs
);
1456 static void keep_going (struct execution_control_state
*ecs
);
1457 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1460 /* Wait for control to return from inferior to debugger.
1462 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1463 as if they were SIGTRAP signals. This can be useful during
1464 the startup sequence on some targets such as HP/UX, where
1465 we receive an EXEC event instead of the expected SIGTRAP.
1467 If inferior gets a signal, we may decide to start it up again
1468 instead of returning. That is why there is a loop in this function.
1469 When this function actually returns it means the inferior
1470 should be left stopped and GDB should read more commands. */
1473 wait_for_inferior (int treat_exec_as_sigtrap
)
1475 struct cleanup
*old_cleanups
;
1476 struct execution_control_state ecss
;
1477 struct execution_control_state
*ecs
;
1481 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1482 treat_exec_as_sigtrap
);
1484 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1485 &step_resume_breakpoint
);
1488 memset (ecs
, 0, sizeof (*ecs
));
1490 overlay_cache_invalid
= 1;
1492 /* We have to invalidate the registers BEFORE calling target_wait
1493 because they can be loaded from the target while in target_wait.
1494 This makes remote debugging a bit more efficient for those
1495 targets that provide critical registers as part of their normal
1496 status mechanism. */
1498 registers_changed ();
1502 if (deprecated_target_wait_hook
)
1503 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1505 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1507 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1509 xfree (ecs
->ws
.value
.execd_pathname
);
1510 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1511 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
1514 /* Now figure out what to do with the result of the result. */
1515 handle_inferior_event (ecs
);
1517 if (!ecs
->wait_some_more
)
1520 do_cleanups (old_cleanups
);
1523 /* Asynchronous version of wait_for_inferior. It is called by the
1524 event loop whenever a change of state is detected on the file
1525 descriptor corresponding to the target. It can be called more than
1526 once to complete a single execution command. In such cases we need
1527 to keep the state in a global variable ECSS. If it is the last time
1528 that this function is called for a single execution command, then
1529 report to the user that the inferior has stopped, and do the
1530 necessary cleanups. */
1533 fetch_inferior_event (void *client_data
)
1535 struct execution_control_state ecss
;
1536 struct execution_control_state
*ecs
= &ecss
;
1537 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
1538 int was_sync
= sync_execution
;
1540 memset (ecs
, 0, sizeof (*ecs
));
1542 overlay_cache_invalid
= 1;
1545 /* In non-stop mode, the user/frontend should not notice a thread
1546 switch due to internal events. Make sure we reverse to the
1547 user selected thread and frame after handling the event and
1548 running any breakpoint commands. */
1549 make_cleanup_restore_current_thread ();
1551 /* We have to invalidate the registers BEFORE calling target_wait
1552 because they can be loaded from the target while in target_wait.
1553 This makes remote debugging a bit more efficient for those
1554 targets that provide critical registers as part of their normal
1555 status mechanism. */
1557 registers_changed ();
1559 if (deprecated_target_wait_hook
)
1561 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1563 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1566 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
1567 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1568 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
1569 /* In non-stop mode, each thread is handled individually. Switch
1570 early, so the global state is set correctly for this
1572 context_switch (ecs
->ptid
);
1574 /* Now figure out what to do with the result of the result. */
1575 handle_inferior_event (ecs
);
1577 if (!ecs
->wait_some_more
)
1579 delete_step_resume_breakpoint (&step_resume_breakpoint
);
1582 if (step_multi
&& stop_step
)
1583 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1585 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1588 /* Revert thread and frame. */
1589 do_cleanups (old_chain
);
1591 /* If the inferior was in sync execution mode, and now isn't,
1592 restore the prompt. */
1593 if (was_sync
&& !sync_execution
)
1594 display_gdb_prompt (0);
1597 /* Prepare an execution control state for looping through a
1598 wait_for_inferior-type loop. */
1601 init_execution_control_state (struct execution_control_state
*ecs
)
1603 ecs
->random_signal
= 0;
1606 /* Clear context switchable stepping state. */
1609 init_thread_stepping_state (struct thread_stepping_state
*tss
)
1611 tss
->stepping_over_breakpoint
= 0;
1612 tss
->step_after_step_resume_breakpoint
= 0;
1613 tss
->stepping_through_solib_after_catch
= 0;
1614 tss
->stepping_through_solib_catchpoints
= NULL
;
1615 tss
->sal
= find_pc_line (prev_pc
, 0);
1616 tss
->current_line
= tss
->sal
.line
;
1617 tss
->current_symtab
= tss
->sal
.symtab
;
1620 /* Return the cached copy of the last pid/waitstatus returned by
1621 target_wait()/deprecated_target_wait_hook(). The data is actually
1622 cached by handle_inferior_event(), which gets called immediately
1623 after target_wait()/deprecated_target_wait_hook(). */
1626 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1628 *ptidp
= target_last_wait_ptid
;
1629 *status
= target_last_waitstatus
;
1633 nullify_last_target_wait_ptid (void)
1635 target_last_wait_ptid
= minus_one_ptid
;
1638 /* Switch thread contexts, maintaining "infrun state". */
1641 context_switch (ptid_t ptid
)
1643 /* Caution: it may happen that the new thread (or the old one!)
1644 is not in the thread list. In this case we must not attempt
1645 to "switch context", or we run the risk that our context may
1646 be lost. This may happen as a result of the target module
1647 mishandling thread creation. */
1651 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
1652 target_pid_to_str (inferior_ptid
));
1653 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
1654 target_pid_to_str (ptid
));
1657 if (in_thread_list (inferior_ptid
) && in_thread_list (ptid
))
1658 { /* Perform infrun state context switch: */
1659 /* Save infrun state for the old thread. */
1660 save_infrun_state (inferior_ptid
, prev_pc
,
1661 stepping_over_breakpoint
, step_resume_breakpoint
,
1663 step_range_end
, &step_frame_id
,
1664 tss
->stepping_over_breakpoint
,
1665 tss
->stepping_through_solib_after_catch
,
1666 tss
->stepping_through_solib_catchpoints
,
1667 tss
->current_line
, tss
->current_symtab
,
1668 cmd_continuation
, intermediate_continuation
,
1676 /* Load infrun state for the new thread. */
1677 load_infrun_state (ptid
, &prev_pc
,
1678 &stepping_over_breakpoint
, &step_resume_breakpoint
,
1680 &step_range_end
, &step_frame_id
,
1681 &tss
->stepping_over_breakpoint
,
1682 &tss
->stepping_through_solib_after_catch
,
1683 &tss
->stepping_through_solib_catchpoints
,
1684 &tss
->current_line
, &tss
->current_symtab
,
1685 &cmd_continuation
, &intermediate_continuation
,
1694 switch_to_thread (ptid
);
1697 /* Context switch to thread PTID. */
1699 context_switch_to (ptid_t ptid
)
1701 ptid_t current_ptid
= inferior_ptid
;
1703 /* Context switch to the new thread. */
1704 if (!ptid_equal (ptid
, inferior_ptid
))
1706 context_switch (ptid
);
1708 return current_ptid
;
1712 adjust_pc_after_break (struct execution_control_state
*ecs
)
1714 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
1715 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1716 CORE_ADDR breakpoint_pc
;
1718 /* If this target does not decrement the PC after breakpoints, then
1719 we have nothing to do. */
1720 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
1723 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1724 we aren't, just return.
1726 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1727 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1728 implemented by software breakpoints should be handled through the normal
1731 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1732 different signals (SIGILL or SIGEMT for instance), but it is less
1733 clear where the PC is pointing afterwards. It may not match
1734 gdbarch_decr_pc_after_break. I don't know any specific target that
1735 generates these signals at breakpoints (the code has been in GDB since at
1736 least 1992) so I can not guess how to handle them here.
1738 In earlier versions of GDB, a target with
1739 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1740 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1741 target with both of these set in GDB history, and it seems unlikely to be
1742 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1744 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
1747 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1750 /* Find the location where (if we've hit a breakpoint) the
1751 breakpoint would be. */
1752 breakpoint_pc
= regcache_read_pc (regcache
)
1753 - gdbarch_decr_pc_after_break (gdbarch
);
1755 /* Check whether there actually is a software breakpoint inserted
1756 at that location. */
1757 if (software_breakpoint_inserted_here_p (breakpoint_pc
))
1759 /* When using hardware single-step, a SIGTRAP is reported for both
1760 a completed single-step and a software breakpoint. Need to
1761 differentiate between the two, as the latter needs adjusting
1762 but the former does not.
1764 The SIGTRAP can be due to a completed hardware single-step only if
1765 - we didn't insert software single-step breakpoints
1766 - the thread to be examined is still the current thread
1767 - this thread is currently being stepped
1769 If any of these events did not occur, we must have stopped due
1770 to hitting a software breakpoint, and have to back up to the
1773 As a special case, we could have hardware single-stepped a
1774 software breakpoint. In this case (prev_pc == breakpoint_pc),
1775 we also need to back up to the breakpoint address. */
1777 if (singlestep_breakpoints_inserted_p
1778 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
1779 || !currently_stepping (tss
)
1780 || prev_pc
== breakpoint_pc
)
1781 regcache_write_pc (regcache
, breakpoint_pc
);
1786 init_infwait_state (void)
1788 waiton_ptid
= pid_to_ptid (-1);
1789 infwait_state
= infwait_normal_state
;
1793 error_is_running (void)
1796 Cannot execute this command while the selected thread is running."));
1800 ensure_not_running (void)
1802 if (is_running (inferior_ptid
))
1803 error_is_running ();
1806 /* Given an execution control state that has been freshly filled in
1807 by an event from the inferior, figure out what it means and take
1808 appropriate action. */
1811 handle_inferior_event (struct execution_control_state
*ecs
)
1813 int sw_single_step_trap_p
= 0;
1814 int stopped_by_watchpoint
;
1815 int stepped_after_stopped_by_watchpoint
= 0;
1817 breakpoint_retire_moribund ();
1819 /* Cache the last pid/waitstatus. */
1820 target_last_wait_ptid
= ecs
->ptid
;
1821 target_last_waitstatus
= ecs
->ws
;
1823 /* Always clear state belonging to the previous time we stopped. */
1824 stop_stack_dummy
= 0;
1826 adjust_pc_after_break (ecs
);
1828 switch (infwait_state
)
1830 case infwait_thread_hop_state
:
1832 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
1833 /* Cancel the waiton_ptid. */
1834 waiton_ptid
= pid_to_ptid (-1);
1837 case infwait_normal_state
:
1839 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
1842 case infwait_step_watch_state
:
1844 fprintf_unfiltered (gdb_stdlog
,
1845 "infrun: infwait_step_watch_state\n");
1847 stepped_after_stopped_by_watchpoint
= 1;
1850 case infwait_nonstep_watch_state
:
1852 fprintf_unfiltered (gdb_stdlog
,
1853 "infrun: infwait_nonstep_watch_state\n");
1854 insert_breakpoints ();
1856 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1857 handle things like signals arriving and other things happening
1858 in combination correctly? */
1859 stepped_after_stopped_by_watchpoint
= 1;
1863 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1865 infwait_state
= infwait_normal_state
;
1867 reinit_frame_cache ();
1869 /* If it's a new process, add it to the thread database */
1871 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1872 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
1873 && !in_thread_list (ecs
->ptid
));
1875 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1876 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1877 add_thread (ecs
->ptid
);
1879 if (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
1881 /* Mark the non-executing threads accordingly. */
1883 || ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
1884 || ecs
->ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
1885 set_executing (pid_to_ptid (-1), 0);
1887 set_executing (ecs
->ptid
, 0);
1890 switch (ecs
->ws
.kind
)
1892 case TARGET_WAITKIND_LOADED
:
1894 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
1895 /* Ignore gracefully during startup of the inferior, as it might
1896 be the shell which has just loaded some objects, otherwise
1897 add the symbols for the newly loaded objects. Also ignore at
1898 the beginning of an attach or remote session; we will query
1899 the full list of libraries once the connection is
1901 if (stop_soon
== NO_STOP_QUIETLY
)
1903 /* Check for any newly added shared libraries if we're
1904 supposed to be adding them automatically. Switch
1905 terminal for any messages produced by
1906 breakpoint_re_set. */
1907 target_terminal_ours_for_output ();
1908 /* NOTE: cagney/2003-11-25: Make certain that the target
1909 stack's section table is kept up-to-date. Architectures,
1910 (e.g., PPC64), use the section table to perform
1911 operations such as address => section name and hence
1912 require the table to contain all sections (including
1913 those found in shared libraries). */
1914 /* NOTE: cagney/2003-11-25: Pass current_target and not
1915 exec_ops to SOLIB_ADD. This is because current GDB is
1916 only tooled to propagate section_table changes out from
1917 the "current_target" (see target_resize_to_sections), and
1918 not up from the exec stratum. This, of course, isn't
1919 right. "infrun.c" should only interact with the
1920 exec/process stratum, instead relying on the target stack
1921 to propagate relevant changes (stop, section table
1922 changed, ...) up to other layers. */
1924 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
1926 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
1928 target_terminal_inferior ();
1930 /* If requested, stop when the dynamic linker notifies
1931 gdb of events. This allows the user to get control
1932 and place breakpoints in initializer routines for
1933 dynamically loaded objects (among other things). */
1934 if (stop_on_solib_events
)
1936 stop_stepping (ecs
);
1940 /* NOTE drow/2007-05-11: This might be a good place to check
1941 for "catch load". */
1944 /* If we are skipping through a shell, or through shared library
1945 loading that we aren't interested in, resume the program. If
1946 we're running the program normally, also resume. But stop if
1947 we're attaching or setting up a remote connection. */
1948 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
1950 /* Loading of shared libraries might have changed breakpoint
1951 addresses. Make sure new breakpoints are inserted. */
1952 if (stop_soon
== NO_STOP_QUIETLY
1953 && !breakpoints_always_inserted_mode ())
1954 insert_breakpoints ();
1955 resume (0, TARGET_SIGNAL_0
);
1956 prepare_to_wait (ecs
);
1962 case TARGET_WAITKIND_SPURIOUS
:
1964 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
1965 resume (0, TARGET_SIGNAL_0
);
1966 prepare_to_wait (ecs
);
1969 case TARGET_WAITKIND_EXITED
:
1971 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
1972 target_terminal_ours (); /* Must do this before mourn anyway */
1973 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1975 /* Record the exit code in the convenience variable $_exitcode, so
1976 that the user can inspect this again later. */
1977 set_internalvar (lookup_internalvar ("_exitcode"),
1978 value_from_longest (builtin_type_int
,
1979 (LONGEST
) ecs
->ws
.value
.integer
));
1980 gdb_flush (gdb_stdout
);
1981 target_mourn_inferior ();
1982 singlestep_breakpoints_inserted_p
= 0;
1983 stop_print_frame
= 0;
1984 stop_stepping (ecs
);
1987 case TARGET_WAITKIND_SIGNALLED
:
1989 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
1990 stop_print_frame
= 0;
1991 stop_signal
= ecs
->ws
.value
.sig
;
1992 target_terminal_ours (); /* Must do this before mourn anyway */
1994 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1995 reach here unless the inferior is dead. However, for years
1996 target_kill() was called here, which hints that fatal signals aren't
1997 really fatal on some systems. If that's true, then some changes
1999 target_mourn_inferior ();
2001 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
2002 singlestep_breakpoints_inserted_p
= 0;
2003 stop_stepping (ecs
);
2006 /* The following are the only cases in which we keep going;
2007 the above cases end in a continue or goto. */
2008 case TARGET_WAITKIND_FORKED
:
2009 case TARGET_WAITKIND_VFORKED
:
2011 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
2012 stop_signal
= TARGET_SIGNAL_TRAP
;
2013 pending_follow
.kind
= ecs
->ws
.kind
;
2015 pending_follow
.fork_event
.parent_pid
= ecs
->ptid
;
2016 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
2018 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2020 context_switch (ecs
->ptid
);
2021 reinit_frame_cache ();
2024 stop_pc
= read_pc ();
2026 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2028 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2030 /* If no catchpoint triggered for this, then keep going. */
2031 if (ecs
->random_signal
)
2033 stop_signal
= TARGET_SIGNAL_0
;
2037 goto process_event_stop_test
;
2039 case TARGET_WAITKIND_EXECD
:
2041 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
2042 stop_signal
= TARGET_SIGNAL_TRAP
;
2044 pending_follow
.execd_pathname
=
2045 savestring (ecs
->ws
.value
.execd_pathname
,
2046 strlen (ecs
->ws
.value
.execd_pathname
));
2048 /* This causes the eventpoints and symbol table to be reset. Must
2049 do this now, before trying to determine whether to stop. */
2050 follow_exec (inferior_ptid
, pending_follow
.execd_pathname
);
2051 xfree (pending_follow
.execd_pathname
);
2053 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2056 /* The breakpoints module may need to touch the inferior's
2057 memory. Switch to the (stopped) event ptid
2059 ptid_t saved_inferior_ptid
= inferior_ptid
;
2060 inferior_ptid
= ecs
->ptid
;
2062 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2064 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2065 inferior_ptid
= saved_inferior_ptid
;
2068 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2070 context_switch (ecs
->ptid
);
2071 reinit_frame_cache ();
2074 /* If no catchpoint triggered for this, then keep going. */
2075 if (ecs
->random_signal
)
2077 stop_signal
= TARGET_SIGNAL_0
;
2081 goto process_event_stop_test
;
2083 /* Be careful not to try to gather much state about a thread
2084 that's in a syscall. It's frequently a losing proposition. */
2085 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2087 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2088 resume (0, TARGET_SIGNAL_0
);
2089 prepare_to_wait (ecs
);
2092 /* Before examining the threads further, step this thread to
2093 get it entirely out of the syscall. (We get notice of the
2094 event when the thread is just on the verge of exiting a
2095 syscall. Stepping one instruction seems to get it back
2097 case TARGET_WAITKIND_SYSCALL_RETURN
:
2099 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2100 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2101 prepare_to_wait (ecs
);
2104 case TARGET_WAITKIND_STOPPED
:
2106 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
2107 stop_signal
= ecs
->ws
.value
.sig
;
2110 /* We had an event in the inferior, but we are not interested
2111 in handling it at this level. The lower layers have already
2112 done what needs to be done, if anything.
2114 One of the possible circumstances for this is when the
2115 inferior produces output for the console. The inferior has
2116 not stopped, and we are ignoring the event. Another possible
2117 circumstance is any event which the lower level knows will be
2118 reported multiple times without an intervening resume. */
2119 case TARGET_WAITKIND_IGNORE
:
2121 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2122 prepare_to_wait (ecs
);
2126 if (ecs
->new_thread_event
)
2129 /* Non-stop assumes that the target handles adding new threads
2130 to the thread list. */
2131 internal_error (__FILE__
, __LINE__
, "\
2132 targets should add new threads to the thread list themselves in non-stop mode.");
2134 /* We may want to consider not doing a resume here in order to
2135 give the user a chance to play with the new thread. It might
2136 be good to make that a user-settable option. */
2138 /* At this point, all threads are stopped (happens automatically
2139 in either the OS or the native code). Therefore we need to
2140 continue all threads in order to make progress. */
2142 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
2143 prepare_to_wait (ecs
);
2147 /* Do we need to clean up the state of a thread that has completed a
2148 displaced single-step? (Doing so usually affects the PC, so do
2149 it here, before we set stop_pc.) */
2150 displaced_step_fixup (ecs
->ptid
, stop_signal
);
2152 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2156 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n",
2157 paddr_nz (stop_pc
));
2158 if (STOPPED_BY_WATCHPOINT (&ecs
->ws
))
2161 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2163 if (target_stopped_data_address (¤t_target
, &addr
))
2164 fprintf_unfiltered (gdb_stdlog
,
2165 "infrun: stopped data address = 0x%s\n",
2168 fprintf_unfiltered (gdb_stdlog
,
2169 "infrun: (no data address available)\n");
2173 if (stepping_past_singlestep_breakpoint
)
2175 gdb_assert (singlestep_breakpoints_inserted_p
);
2176 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2177 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2179 stepping_past_singlestep_breakpoint
= 0;
2181 /* We've either finished single-stepping past the single-step
2182 breakpoint, or stopped for some other reason. It would be nice if
2183 we could tell, but we can't reliably. */
2184 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2187 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2188 /* Pull the single step breakpoints out of the target. */
2189 remove_single_step_breakpoints ();
2190 singlestep_breakpoints_inserted_p
= 0;
2192 ecs
->random_signal
= 0;
2194 context_switch (saved_singlestep_ptid
);
2195 if (deprecated_context_hook
)
2196 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2198 resume (1, TARGET_SIGNAL_0
);
2199 prepare_to_wait (ecs
);
2204 stepping_past_singlestep_breakpoint
= 0;
2206 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2208 /* In non-stop mode, there's never a deferred_step_ptid set. */
2209 gdb_assert (!non_stop
);
2211 /* If we stopped for some other reason than single-stepping, ignore
2212 the fact that we were supposed to switch back. */
2213 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2216 fprintf_unfiltered (gdb_stdlog
,
2217 "infrun: handling deferred step\n");
2219 /* Pull the single step breakpoints out of the target. */
2220 if (singlestep_breakpoints_inserted_p
)
2222 remove_single_step_breakpoints ();
2223 singlestep_breakpoints_inserted_p
= 0;
2226 /* Note: We do not call context_switch at this point, as the
2227 context is already set up for stepping the original thread. */
2228 switch_to_thread (deferred_step_ptid
);
2229 deferred_step_ptid
= null_ptid
;
2230 /* Suppress spurious "Switching to ..." message. */
2231 previous_inferior_ptid
= inferior_ptid
;
2233 resume (1, TARGET_SIGNAL_0
);
2234 prepare_to_wait (ecs
);
2238 deferred_step_ptid
= null_ptid
;
2241 /* See if a thread hit a thread-specific breakpoint that was meant for
2242 another thread. If so, then step that thread past the breakpoint,
2245 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2247 int thread_hop_needed
= 0;
2249 /* Check if a regular breakpoint has been hit before checking
2250 for a potential single step breakpoint. Otherwise, GDB will
2251 not see this breakpoint hit when stepping onto breakpoints. */
2252 if (regular_breakpoint_inserted_here_p (stop_pc
))
2254 ecs
->random_signal
= 0;
2255 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2256 thread_hop_needed
= 1;
2258 else if (singlestep_breakpoints_inserted_p
)
2260 /* We have not context switched yet, so this should be true
2261 no matter which thread hit the singlestep breakpoint. */
2262 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2264 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2266 target_pid_to_str (ecs
->ptid
));
2268 ecs
->random_signal
= 0;
2269 /* The call to in_thread_list is necessary because PTIDs sometimes
2270 change when we go from single-threaded to multi-threaded. If
2271 the singlestep_ptid is still in the list, assume that it is
2272 really different from ecs->ptid. */
2273 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2274 && in_thread_list (singlestep_ptid
))
2276 /* If the PC of the thread we were trying to single-step
2277 has changed, discard this event (which we were going
2278 to ignore anyway), and pretend we saw that thread
2279 trap. This prevents us continuously moving the
2280 single-step breakpoint forward, one instruction at a
2281 time. If the PC has changed, then the thread we were
2282 trying to single-step has trapped or been signalled,
2283 but the event has not been reported to GDB yet.
2285 There might be some cases where this loses signal
2286 information, if a signal has arrived at exactly the
2287 same time that the PC changed, but this is the best
2288 we can do with the information available. Perhaps we
2289 should arrange to report all events for all threads
2290 when they stop, or to re-poll the remote looking for
2291 this particular thread (i.e. temporarily enable
2294 CORE_ADDR new_singlestep_pc
2295 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
2297 if (new_singlestep_pc
!= singlestep_pc
)
2300 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2301 " but expected thread advanced also\n");
2303 /* The current context still belongs to
2304 singlestep_ptid. Don't swap here, since that's
2305 the context we want to use. Just fudge our
2306 state and continue. */
2307 ecs
->ptid
= singlestep_ptid
;
2308 stop_pc
= new_singlestep_pc
;
2313 fprintf_unfiltered (gdb_stdlog
,
2314 "infrun: unexpected thread\n");
2316 thread_hop_needed
= 1;
2317 stepping_past_singlestep_breakpoint
= 1;
2318 saved_singlestep_ptid
= singlestep_ptid
;
2323 if (thread_hop_needed
)
2325 int remove_status
= 0;
2328 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2330 /* Saw a breakpoint, but it was hit by the wrong thread.
2333 if (singlestep_breakpoints_inserted_p
)
2335 /* Pull the single step breakpoints out of the target. */
2336 remove_single_step_breakpoints ();
2337 singlestep_breakpoints_inserted_p
= 0;
2340 /* If the arch can displace step, don't remove the
2342 if (!use_displaced_stepping (current_gdbarch
))
2343 remove_status
= remove_breakpoints ();
2345 /* Did we fail to remove breakpoints? If so, try
2346 to set the PC past the bp. (There's at least
2347 one situation in which we can fail to remove
2348 the bp's: On HP-UX's that use ttrace, we can't
2349 change the address space of a vforking child
2350 process until the child exits (well, okay, not
2351 then either :-) or execs. */
2352 if (remove_status
!= 0)
2353 error (_("Cannot step over breakpoint hit in wrong thread"));
2356 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2357 context_switch (ecs
->ptid
);
2361 /* Only need to require the next event from this
2362 thread in all-stop mode. */
2363 waiton_ptid
= ecs
->ptid
;
2364 infwait_state
= infwait_thread_hop_state
;
2367 tss
->stepping_over_breakpoint
= 1;
2369 registers_changed ();
2373 else if (singlestep_breakpoints_inserted_p
)
2375 sw_single_step_trap_p
= 1;
2376 ecs
->random_signal
= 0;
2380 ecs
->random_signal
= 1;
2382 /* See if something interesting happened to the non-current thread. If
2383 so, then switch to that thread. */
2384 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2387 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
2389 context_switch (ecs
->ptid
);
2391 if (deprecated_context_hook
)
2392 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2395 if (singlestep_breakpoints_inserted_p
)
2397 /* Pull the single step breakpoints out of the target. */
2398 remove_single_step_breakpoints ();
2399 singlestep_breakpoints_inserted_p
= 0;
2402 if (stepped_after_stopped_by_watchpoint
)
2403 stopped_by_watchpoint
= 0;
2405 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
2407 /* If necessary, step over this watchpoint. We'll be back to display
2409 if (stopped_by_watchpoint
2410 && (HAVE_STEPPABLE_WATCHPOINT
2411 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
2413 /* At this point, we are stopped at an instruction which has
2414 attempted to write to a piece of memory under control of
2415 a watchpoint. The instruction hasn't actually executed
2416 yet. If we were to evaluate the watchpoint expression
2417 now, we would get the old value, and therefore no change
2418 would seem to have occurred.
2420 In order to make watchpoints work `right', we really need
2421 to complete the memory write, and then evaluate the
2422 watchpoint expression. We do this by single-stepping the
2425 It may not be necessary to disable the watchpoint to stop over
2426 it. For example, the PA can (with some kernel cooperation)
2427 single step over a watchpoint without disabling the watchpoint.
2429 It is far more common to need to disable a watchpoint to step
2430 the inferior over it. If we have non-steppable watchpoints,
2431 we must disable the current watchpoint; it's simplest to
2432 disable all watchpoints and breakpoints. */
2434 if (!HAVE_STEPPABLE_WATCHPOINT
)
2435 remove_breakpoints ();
2436 registers_changed ();
2437 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2438 waiton_ptid
= ecs
->ptid
;
2439 if (HAVE_STEPPABLE_WATCHPOINT
)
2440 infwait_state
= infwait_step_watch_state
;
2442 infwait_state
= infwait_nonstep_watch_state
;
2443 prepare_to_wait (ecs
);
2447 ecs
->stop_func_start
= 0;
2448 ecs
->stop_func_end
= 0;
2449 ecs
->stop_func_name
= 0;
2450 /* Don't care about return value; stop_func_start and stop_func_name
2451 will both be 0 if it doesn't work. */
2452 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2453 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2454 ecs
->stop_func_start
2455 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
2456 tss
->stepping_over_breakpoint
= 0;
2457 bpstat_clear (&stop_bpstat
);
2459 stop_print_frame
= 1;
2460 ecs
->random_signal
= 0;
2461 stopped_by_random_signal
= 0;
2463 if (stop_signal
== TARGET_SIGNAL_TRAP
2464 && stepping_over_breakpoint
2465 && gdbarch_single_step_through_delay_p (current_gdbarch
)
2466 && currently_stepping (tss
))
2468 /* We're trying to step off a breakpoint. Turns out that we're
2469 also on an instruction that needs to be stepped multiple
2470 times before it's been fully executing. E.g., architectures
2471 with a delay slot. It needs to be stepped twice, once for
2472 the instruction and once for the delay slot. */
2473 int step_through_delay
2474 = gdbarch_single_step_through_delay (current_gdbarch
,
2475 get_current_frame ());
2476 if (debug_infrun
&& step_through_delay
)
2477 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
2478 if (step_range_end
== 0 && step_through_delay
)
2480 /* The user issued a continue when stopped at a breakpoint.
2481 Set up for another trap and get out of here. */
2482 tss
->stepping_over_breakpoint
= 1;
2486 else if (step_through_delay
)
2488 /* The user issued a step when stopped at a breakpoint.
2489 Maybe we should stop, maybe we should not - the delay
2490 slot *might* correspond to a line of source. In any
2491 case, don't decide that here, just set
2492 ecs->stepping_over_breakpoint, making sure we
2493 single-step again before breakpoints are re-inserted. */
2494 tss
->stepping_over_breakpoint
= 1;
2498 /* Look at the cause of the stop, and decide what to do.
2499 The alternatives are:
2500 1) stop_stepping and return; to really stop and return to the debugger,
2501 2) keep_going and return to start up again
2502 (set tss->stepping_over_breakpoint to 1 to single step once)
2503 3) set ecs->random_signal to 1, and the decision between 1 and 2
2504 will be made according to the signal handling tables. */
2506 /* First, distinguish signals caused by the debugger from signals
2507 that have to do with the program's own actions. Note that
2508 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2509 on the operating system version. Here we detect when a SIGILL or
2510 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2511 something similar for SIGSEGV, since a SIGSEGV will be generated
2512 when we're trying to execute a breakpoint instruction on a
2513 non-executable stack. This happens for call dummy breakpoints
2514 for architectures like SPARC that place call dummies on the
2517 If we're doing a displaced step past a breakpoint, then the
2518 breakpoint is always inserted at the original instruction;
2519 non-standard signals can't be explained by the breakpoint. */
2520 if (stop_signal
== TARGET_SIGNAL_TRAP
2521 || (! stepping_over_breakpoint
2522 && breakpoint_inserted_here_p (stop_pc
)
2523 && (stop_signal
== TARGET_SIGNAL_ILL
2524 || stop_signal
== TARGET_SIGNAL_SEGV
2525 || stop_signal
== TARGET_SIGNAL_EMT
))
2526 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2527 || stop_soon
== STOP_QUIETLY_REMOTE
)
2529 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2532 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
2533 stop_print_frame
= 0;
2534 stop_stepping (ecs
);
2538 /* This is originated from start_remote(), start_inferior() and
2539 shared libraries hook functions. */
2540 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
2543 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
2544 stop_stepping (ecs
);
2548 /* This originates from attach_command(). We need to overwrite
2549 the stop_signal here, because some kernels don't ignore a
2550 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2551 See more comments in inferior.h. On the other hand, if we
2552 get a non-SIGSTOP, report it to the user - assume the backend
2553 will handle the SIGSTOP if it should show up later.
2555 Also consider that the attach is complete when we see a
2556 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
2557 target extended-remote report it instead of a SIGSTOP
2558 (e.g. gdbserver). We already rely on SIGTRAP being our
2559 signal, so this is no exception. */
2560 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2561 && (stop_signal
== TARGET_SIGNAL_STOP
2562 || stop_signal
== TARGET_SIGNAL_TRAP
))
2564 stop_stepping (ecs
);
2565 stop_signal
= TARGET_SIGNAL_0
;
2569 /* See if there is a breakpoint at the current PC. */
2570 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2572 /* Following in case break condition called a
2574 stop_print_frame
= 1;
2576 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2577 at one stage in the past included checks for an inferior
2578 function call's call dummy's return breakpoint. The original
2579 comment, that went with the test, read:
2581 ``End of a stack dummy. Some systems (e.g. Sony news) give
2582 another signal besides SIGTRAP, so check here as well as
2585 If someone ever tries to get get call dummys on a
2586 non-executable stack to work (where the target would stop
2587 with something like a SIGSEGV), then those tests might need
2588 to be re-instated. Given, however, that the tests were only
2589 enabled when momentary breakpoints were not being used, I
2590 suspect that it won't be the case.
2592 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2593 be necessary for call dummies on a non-executable stack on
2596 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2598 = !(bpstat_explains_signal (stop_bpstat
)
2599 || stepping_over_breakpoint
2600 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2603 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2604 if (!ecs
->random_signal
)
2605 stop_signal
= TARGET_SIGNAL_TRAP
;
2609 /* When we reach this point, we've pretty much decided
2610 that the reason for stopping must've been a random
2611 (unexpected) signal. */
2614 ecs
->random_signal
= 1;
2616 process_event_stop_test
:
2617 /* For the program's own signals, act according to
2618 the signal handling tables. */
2620 if (ecs
->random_signal
)
2622 /* Signal not for debugging purposes. */
2626 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n", stop_signal
);
2628 stopped_by_random_signal
= 1;
2630 if (signal_print
[stop_signal
])
2633 target_terminal_ours_for_output ();
2634 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2636 if (signal_stop_state (stop_signal
))
2638 stop_stepping (ecs
);
2641 /* If not going to stop, give terminal back
2642 if we took it away. */
2644 target_terminal_inferior ();
2646 /* Clear the signal if it should not be passed. */
2647 if (signal_program
[stop_signal
] == 0)
2648 stop_signal
= TARGET_SIGNAL_0
;
2650 if (prev_pc
== read_pc ()
2651 && stepping_over_breakpoint
2652 && step_resume_breakpoint
== NULL
)
2654 /* We were just starting a new sequence, attempting to
2655 single-step off of a breakpoint and expecting a SIGTRAP.
2656 Instead this signal arrives. This signal will take us out
2657 of the stepping range so GDB needs to remember to, when
2658 the signal handler returns, resume stepping off that
2660 /* To simplify things, "continue" is forced to use the same
2661 code paths as single-step - set a breakpoint at the
2662 signal return address and then, once hit, step off that
2665 fprintf_unfiltered (gdb_stdlog
,
2666 "infrun: signal arrived while stepping over "
2669 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2670 tss
->step_after_step_resume_breakpoint
= 1;
2675 if (step_range_end
!= 0
2676 && stop_signal
!= TARGET_SIGNAL_0
2677 && stop_pc
>= step_range_start
&& stop_pc
< step_range_end
2678 && frame_id_eq (get_frame_id (get_current_frame ()),
2680 && step_resume_breakpoint
== NULL
)
2682 /* The inferior is about to take a signal that will take it
2683 out of the single step range. Set a breakpoint at the
2684 current PC (which is presumably where the signal handler
2685 will eventually return) and then allow the inferior to
2688 Note that this is only needed for a signal delivered
2689 while in the single-step range. Nested signals aren't a
2690 problem as they eventually all return. */
2692 fprintf_unfiltered (gdb_stdlog
,
2693 "infrun: signal may take us out of "
2694 "single-step range\n");
2696 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2701 /* Note: step_resume_breakpoint may be non-NULL. This occures
2702 when either there's a nested signal, or when there's a
2703 pending signal enabled just as the signal handler returns
2704 (leaving the inferior at the step-resume-breakpoint without
2705 actually executing it). Either way continue until the
2706 breakpoint is really hit. */
2711 /* Handle cases caused by hitting a breakpoint. */
2713 CORE_ADDR jmp_buf_pc
;
2714 struct bpstat_what what
;
2716 what
= bpstat_what (stop_bpstat
);
2718 if (what
.call_dummy
)
2720 stop_stack_dummy
= 1;
2723 switch (what
.main_action
)
2725 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2726 /* If we hit the breakpoint at longjmp while stepping, we
2727 install a momentary breakpoint at the target of the
2731 fprintf_unfiltered (gdb_stdlog
,
2732 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2734 tss
->stepping_over_breakpoint
= 1;
2736 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
2737 || !gdbarch_get_longjmp_target (current_gdbarch
,
2738 get_current_frame (), &jmp_buf_pc
))
2741 fprintf_unfiltered (gdb_stdlog
, "\
2742 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
2747 /* We're going to replace the current step-resume breakpoint
2748 with a longjmp-resume breakpoint. */
2749 if (step_resume_breakpoint
!= NULL
)
2750 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2752 /* Insert a breakpoint at resume address. */
2753 insert_longjmp_resume_breakpoint (jmp_buf_pc
);
2758 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2760 fprintf_unfiltered (gdb_stdlog
,
2761 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2763 gdb_assert (step_resume_breakpoint
!= NULL
);
2764 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2767 print_stop_reason (END_STEPPING_RANGE
, 0);
2768 stop_stepping (ecs
);
2771 case BPSTAT_WHAT_SINGLE
:
2773 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
2774 tss
->stepping_over_breakpoint
= 1;
2775 /* Still need to check other stuff, at least the case
2776 where we are stepping and step out of the right range. */
2779 case BPSTAT_WHAT_STOP_NOISY
:
2781 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2782 stop_print_frame
= 1;
2784 /* We are about to nuke the step_resume_breakpointt via the
2785 cleanup chain, so no need to worry about it here. */
2787 stop_stepping (ecs
);
2790 case BPSTAT_WHAT_STOP_SILENT
:
2792 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2793 stop_print_frame
= 0;
2795 /* We are about to nuke the step_resume_breakpoin via the
2796 cleanup chain, so no need to worry about it here. */
2798 stop_stepping (ecs
);
2801 case BPSTAT_WHAT_STEP_RESUME
:
2802 /* This proably demands a more elegant solution, but, yeah
2805 This function's use of the simple variable
2806 step_resume_breakpoint doesn't seem to accomodate
2807 simultaneously active step-resume bp's, although the
2808 breakpoint list certainly can.
2810 If we reach here and step_resume_breakpoint is already
2811 NULL, then apparently we have multiple active
2812 step-resume bp's. We'll just delete the breakpoint we
2813 stopped at, and carry on.
2815 Correction: what the code currently does is delete a
2816 step-resume bp, but it makes no effort to ensure that
2817 the one deleted is the one currently stopped at. MVS */
2820 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2822 if (step_resume_breakpoint
== NULL
)
2824 step_resume_breakpoint
=
2825 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2827 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2828 if (tss
->step_after_step_resume_breakpoint
)
2830 /* Back when the step-resume breakpoint was inserted, we
2831 were trying to single-step off a breakpoint. Go back
2833 tss
->step_after_step_resume_breakpoint
= 0;
2834 tss
->stepping_over_breakpoint
= 1;
2840 case BPSTAT_WHAT_CHECK_SHLIBS
:
2841 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2844 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2846 /* Check for any newly added shared libraries if we're
2847 supposed to be adding them automatically. Switch
2848 terminal for any messages produced by
2849 breakpoint_re_set. */
2850 target_terminal_ours_for_output ();
2851 /* NOTE: cagney/2003-11-25: Make certain that the target
2852 stack's section table is kept up-to-date. Architectures,
2853 (e.g., PPC64), use the section table to perform
2854 operations such as address => section name and hence
2855 require the table to contain all sections (including
2856 those found in shared libraries). */
2857 /* NOTE: cagney/2003-11-25: Pass current_target and not
2858 exec_ops to SOLIB_ADD. This is because current GDB is
2859 only tooled to propagate section_table changes out from
2860 the "current_target" (see target_resize_to_sections), and
2861 not up from the exec stratum. This, of course, isn't
2862 right. "infrun.c" should only interact with the
2863 exec/process stratum, instead relying on the target stack
2864 to propagate relevant changes (stop, section table
2865 changed, ...) up to other layers. */
2867 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2869 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2871 target_terminal_inferior ();
2873 /* If requested, stop when the dynamic linker notifies
2874 gdb of events. This allows the user to get control
2875 and place breakpoints in initializer routines for
2876 dynamically loaded objects (among other things). */
2877 if (stop_on_solib_events
|| stop_stack_dummy
)
2879 stop_stepping (ecs
);
2883 /* If we stopped due to an explicit catchpoint, then the
2884 (see above) call to SOLIB_ADD pulled in any symbols
2885 from a newly-loaded library, if appropriate.
2887 We do want the inferior to stop, but not where it is
2888 now, which is in the dynamic linker callback. Rather,
2889 we would like it stop in the user's program, just after
2890 the call that caused this catchpoint to trigger. That
2891 gives the user a more useful vantage from which to
2892 examine their program's state. */
2893 else if (what
.main_action
2894 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2896 /* ??rehrauer: If I could figure out how to get the
2897 right return PC from here, we could just set a temp
2898 breakpoint and resume. I'm not sure we can without
2899 cracking open the dld's shared libraries and sniffing
2900 their unwind tables and text/data ranges, and that's
2901 not a terribly portable notion.
2903 Until that time, we must step the inferior out of the
2904 dld callback, and also out of the dld itself (and any
2905 code or stubs in libdld.sl, such as "shl_load" and
2906 friends) until we reach non-dld code. At that point,
2907 we can stop stepping. */
2908 bpstat_get_triggered_catchpoints (stop_bpstat
,
2910 stepping_through_solib_catchpoints
);
2911 tss
->stepping_through_solib_after_catch
= 1;
2913 /* Be sure to lift all breakpoints, so the inferior does
2914 actually step past this point... */
2915 tss
->stepping_over_breakpoint
= 1;
2920 /* We want to step over this breakpoint, then keep going. */
2921 tss
->stepping_over_breakpoint
= 1;
2927 case BPSTAT_WHAT_LAST
:
2928 /* Not a real code, but listed here to shut up gcc -Wall. */
2930 case BPSTAT_WHAT_KEEP_CHECKING
:
2935 /* We come here if we hit a breakpoint but should not
2936 stop for it. Possibly we also were stepping
2937 and should stop for that. So fall through and
2938 test for stepping. But, if not stepping,
2941 /* Are we stepping to get the inferior out of the dynamic linker's
2942 hook (and possibly the dld itself) after catching a shlib
2944 if (tss
->stepping_through_solib_after_catch
)
2946 #if defined(SOLIB_ADD)
2947 /* Have we reached our destination? If not, keep going. */
2948 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2951 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
2952 tss
->stepping_over_breakpoint
= 1;
2958 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
2959 /* Else, stop and report the catchpoint(s) whose triggering
2960 caused us to begin stepping. */
2961 tss
->stepping_through_solib_after_catch
= 0;
2962 bpstat_clear (&stop_bpstat
);
2963 stop_bpstat
= bpstat_copy (tss
->stepping_through_solib_catchpoints
);
2964 bpstat_clear (&tss
->stepping_through_solib_catchpoints
);
2965 stop_print_frame
= 1;
2966 stop_stepping (ecs
);
2970 if (step_resume_breakpoint
)
2973 fprintf_unfiltered (gdb_stdlog
,
2974 "infrun: step-resume breakpoint is inserted\n");
2976 /* Having a step-resume breakpoint overrides anything
2977 else having to do with stepping commands until
2978 that breakpoint is reached. */
2983 if (step_range_end
== 0)
2986 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
2987 /* Likewise if we aren't even stepping. */
2992 /* If stepping through a line, keep going if still within it.
2994 Note that step_range_end is the address of the first instruction
2995 beyond the step range, and NOT the address of the last instruction
2997 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
3000 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
3001 paddr_nz (step_range_start
),
3002 paddr_nz (step_range_end
));
3007 /* We stepped out of the stepping range. */
3009 /* If we are stepping at the source level and entered the runtime
3010 loader dynamic symbol resolution code, we keep on single stepping
3011 until we exit the run time loader code and reach the callee's
3013 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3014 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
3015 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
)
3017 && in_solib_dynsym_resolve_code (stop_pc
)
3021 CORE_ADDR pc_after_resolver
=
3022 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
3025 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
3027 if (pc_after_resolver
)
3029 /* Set up a step-resume breakpoint at the address
3030 indicated by SKIP_SOLIB_RESOLVER. */
3031 struct symtab_and_line sr_sal
;
3033 sr_sal
.pc
= pc_after_resolver
;
3035 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3042 if (step_range_end
!= 1
3043 && (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3044 || step_over_calls
== STEP_OVER_ALL
)
3045 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
3048 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
3049 /* The inferior, while doing a "step" or "next", has ended up in
3050 a signal trampoline (either by a signal being delivered or by
3051 the signal handler returning). Just single-step until the
3052 inferior leaves the trampoline (either by calling the handler
3058 /* Check for subroutine calls. The check for the current frame
3059 equalling the step ID is not necessary - the check of the
3060 previous frame's ID is sufficient - but it is a common case and
3061 cheaper than checking the previous frame's ID.
3063 NOTE: frame_id_eq will never report two invalid frame IDs as
3064 being equal, so to get into this block, both the current and
3065 previous frame must have valid frame IDs. */
3066 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id
)
3067 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id
))
3069 CORE_ADDR real_stop_pc
;
3072 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
3074 if ((step_over_calls
== STEP_OVER_NONE
)
3075 || ((step_range_end
== 1)
3076 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
3078 /* I presume that step_over_calls is only 0 when we're
3079 supposed to be stepping at the assembly language level
3080 ("stepi"). Just stop. */
3081 /* Also, maybe we just did a "nexti" inside a prolog, so we
3082 thought it was a subroutine call but it was not. Stop as
3085 print_stop_reason (END_STEPPING_RANGE
, 0);
3086 stop_stepping (ecs
);
3090 if (step_over_calls
== STEP_OVER_ALL
)
3092 /* We're doing a "next", set a breakpoint at callee's return
3093 address (the address at which the caller will
3095 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3100 /* If we are in a function call trampoline (a stub between the
3101 calling routine and the real function), locate the real
3102 function. That's what tells us (a) whether we want to step
3103 into it at all, and (b) what prologue we want to run to the
3104 end of, if we do step into it. */
3105 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
3106 if (real_stop_pc
== 0)
3107 real_stop_pc
= gdbarch_skip_trampoline_code
3108 (current_gdbarch
, get_current_frame (), stop_pc
);
3109 if (real_stop_pc
!= 0)
3110 ecs
->stop_func_start
= real_stop_pc
;
3113 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
3114 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs
->stop_func_start
)
3116 in_solib_dynsym_resolve_code (ecs
->stop_func_start
)
3120 struct symtab_and_line sr_sal
;
3122 sr_sal
.pc
= ecs
->stop_func_start
;
3124 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3129 /* If we have line number information for the function we are
3130 thinking of stepping into, step into it.
3132 If there are several symtabs at that PC (e.g. with include
3133 files), just want to know whether *any* of them have line
3134 numbers. find_pc_line handles this. */
3136 struct symtab_and_line tmp_sal
;
3138 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3139 if (tmp_sal
.line
!= 0)
3141 step_into_function (ecs
);
3146 /* If we have no line number and the step-stop-if-no-debug is
3147 set, we stop the step so that the user has a chance to switch
3148 in assembly mode. */
3149 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
3152 print_stop_reason (END_STEPPING_RANGE
, 0);
3153 stop_stepping (ecs
);
3157 /* Set a breakpoint at callee's return address (the address at
3158 which the caller will resume). */
3159 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3164 /* If we're in the return path from a shared library trampoline,
3165 we want to proceed through the trampoline when stepping. */
3166 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
3167 stop_pc
, ecs
->stop_func_name
))
3169 /* Determine where this trampoline returns. */
3170 CORE_ADDR real_stop_pc
;
3171 real_stop_pc
= gdbarch_skip_trampoline_code
3172 (current_gdbarch
, get_current_frame (), stop_pc
);
3175 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3177 /* Only proceed through if we know where it's going. */
3180 /* And put the step-breakpoint there and go until there. */
3181 struct symtab_and_line sr_sal
;
3183 init_sal (&sr_sal
); /* initialize to zeroes */
3184 sr_sal
.pc
= real_stop_pc
;
3185 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3187 /* Do not specify what the fp should be when we stop since
3188 on some machines the prologue is where the new fp value
3190 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3192 /* Restart without fiddling with the step ranges or
3199 tss
->sal
= find_pc_line (stop_pc
, 0);
3201 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3202 the trampoline processing logic, however, there are some trampolines
3203 that have no names, so we should do trampoline handling first. */
3204 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3205 && ecs
->stop_func_name
== NULL
3206 && tss
->sal
.line
== 0)
3209 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3211 /* The inferior just stepped into, or returned to, an
3212 undebuggable function (where there is no debugging information
3213 and no line number corresponding to the address where the
3214 inferior stopped). Since we want to skip this kind of code,
3215 we keep going until the inferior returns from this
3216 function - unless the user has asked us not to (via
3217 set step-mode) or we no longer know how to get back
3218 to the call site. */
3219 if (step_stop_if_no_debug
3220 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3222 /* If we have no line number and the step-stop-if-no-debug
3223 is set, we stop the step so that the user has a chance to
3224 switch in assembly mode. */
3226 print_stop_reason (END_STEPPING_RANGE
, 0);
3227 stop_stepping (ecs
);
3232 /* Set a breakpoint at callee's return address (the address
3233 at which the caller will resume). */
3234 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3240 if (step_range_end
== 1)
3242 /* It is stepi or nexti. We always want to stop stepping after
3245 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
3247 print_stop_reason (END_STEPPING_RANGE
, 0);
3248 stop_stepping (ecs
);
3252 if (tss
->sal
.line
== 0)
3254 /* We have no line number information. That means to stop
3255 stepping (does this always happen right after one instruction,
3256 when we do "s" in a function with no line numbers,
3257 or can this happen as a result of a return or longjmp?). */
3259 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
3261 print_stop_reason (END_STEPPING_RANGE
, 0);
3262 stop_stepping (ecs
);
3266 if ((stop_pc
== tss
->sal
.pc
)
3267 && (tss
->current_line
!= tss
->sal
.line
3268 || tss
->current_symtab
!= tss
->sal
.symtab
))
3270 /* We are at the start of a different line. So stop. Note that
3271 we don't stop if we step into the middle of a different line.
3272 That is said to make things like for (;;) statements work
3275 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
3277 print_stop_reason (END_STEPPING_RANGE
, 0);
3278 stop_stepping (ecs
);
3282 /* We aren't done stepping.
3284 Optimize by setting the stepping range to the line.
3285 (We might not be in the original line, but if we entered a
3286 new line in mid-statement, we continue stepping. This makes
3287 things like for(;;) statements work better.) */
3289 step_range_start
= tss
->sal
.pc
;
3290 step_range_end
= tss
->sal
.end
;
3291 step_frame_id
= get_frame_id (get_current_frame ());
3292 tss
->current_line
= tss
->sal
.line
;
3293 tss
->current_symtab
= tss
->sal
.symtab
;
3295 /* In the case where we just stepped out of a function into the
3296 middle of a line of the caller, continue stepping, but
3297 step_frame_id must be modified to current frame */
3299 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
3300 generous. It will trigger on things like a step into a frameless
3301 stackless leaf function. I think the logic should instead look
3302 at the unwound frame ID has that should give a more robust
3303 indication of what happened. */
3304 if (step
- ID
== current
- ID
)
3305 still stepping in same function
;
3306 else if (step
- ID
== unwind (current
- ID
))
3307 stepped into a function
;
3309 stepped out of a function
;
3310 /* Of course this assumes that the frame ID unwind code is robust
3311 and we're willing to introduce frame unwind logic into this
3312 function. Fortunately, those days are nearly upon us. */
3315 struct frame_info
*frame
= get_current_frame ();
3316 struct frame_id current_frame
= get_frame_id (frame
);
3317 if (!(frame_id_inner (get_frame_arch (frame
), current_frame
,
3319 step_frame_id
= current_frame
;
3323 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
3327 /* Are we in the middle of stepping? */
3330 currently_stepping (struct thread_stepping_state
*tss
)
3332 return (((step_range_end
&& step_resume_breakpoint
== NULL
)
3333 || stepping_over_breakpoint
)
3334 || tss
->stepping_through_solib_after_catch
3335 || bpstat_should_step ());
3338 /* Subroutine call with source code we should not step over. Do step
3339 to the first line of code in it. */
3342 step_into_function (struct execution_control_state
*ecs
)
3345 struct symtab_and_line sr_sal
;
3347 s
= find_pc_symtab (stop_pc
);
3348 if (s
&& s
->language
!= language_asm
)
3349 ecs
->stop_func_start
= gdbarch_skip_prologue
3350 (current_gdbarch
, ecs
->stop_func_start
);
3352 tss
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3353 /* Use the step_resume_break to step until the end of the prologue,
3354 even if that involves jumps (as it seems to on the vax under
3356 /* If the prologue ends in the middle of a source line, continue to
3357 the end of that source line (if it is still within the function).
3358 Otherwise, just go to end of prologue. */
3360 && tss
->sal
.pc
!= ecs
->stop_func_start
3361 && tss
->sal
.end
< ecs
->stop_func_end
)
3362 ecs
->stop_func_start
= tss
->sal
.end
;
3364 /* Architectures which require breakpoint adjustment might not be able
3365 to place a breakpoint at the computed address. If so, the test
3366 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3367 ecs->stop_func_start to an address at which a breakpoint may be
3368 legitimately placed.
3370 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3371 made, GDB will enter an infinite loop when stepping through
3372 optimized code consisting of VLIW instructions which contain
3373 subinstructions corresponding to different source lines. On
3374 FR-V, it's not permitted to place a breakpoint on any but the
3375 first subinstruction of a VLIW instruction. When a breakpoint is
3376 set, GDB will adjust the breakpoint address to the beginning of
3377 the VLIW instruction. Thus, we need to make the corresponding
3378 adjustment here when computing the stop address. */
3380 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3382 ecs
->stop_func_start
3383 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
3384 ecs
->stop_func_start
);
3387 if (ecs
->stop_func_start
== stop_pc
)
3389 /* We are already there: stop now. */
3391 print_stop_reason (END_STEPPING_RANGE
, 0);
3392 stop_stepping (ecs
);
3397 /* Put the step-breakpoint there and go until there. */
3398 init_sal (&sr_sal
); /* initialize to zeroes */
3399 sr_sal
.pc
= ecs
->stop_func_start
;
3400 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3402 /* Do not specify what the fp should be when we stop since on
3403 some machines the prologue is where the new fp value is
3405 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3407 /* And make sure stepping stops right away then. */
3408 step_range_end
= step_range_start
;
3413 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3414 This is used to both functions and to skip over code. */
3417 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
3418 struct frame_id sr_id
)
3420 /* There should never be more than one step-resume or longjmp-resume
3421 breakpoint per thread, so we should never be setting a new
3422 step_resume_breakpoint when one is already active. */
3423 gdb_assert (step_resume_breakpoint
== NULL
);
3426 fprintf_unfiltered (gdb_stdlog
,
3427 "infrun: inserting step-resume breakpoint at 0x%s\n",
3428 paddr_nz (sr_sal
.pc
));
3430 step_resume_breakpoint
= set_momentary_breakpoint (sr_sal
, sr_id
,
3434 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3435 to skip a potential signal handler.
3437 This is called with the interrupted function's frame. The signal
3438 handler, when it returns, will resume the interrupted function at
3442 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
3444 struct symtab_and_line sr_sal
;
3446 gdb_assert (return_frame
!= NULL
);
3447 init_sal (&sr_sal
); /* initialize to zeros */
3449 sr_sal
.pc
= gdbarch_addr_bits_remove
3450 (current_gdbarch
, get_frame_pc (return_frame
));
3451 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3453 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
3456 /* Similar to insert_step_resume_breakpoint_at_frame, except
3457 but a breakpoint at the previous frame's PC. This is used to
3458 skip a function after stepping into it (for "next" or if the called
3459 function has no debugging information).
3461 The current function has almost always been reached by single
3462 stepping a call or return instruction. NEXT_FRAME belongs to the
3463 current function, and the breakpoint will be set at the caller's
3466 This is a separate function rather than reusing
3467 insert_step_resume_breakpoint_at_frame in order to avoid
3468 get_prev_frame, which may stop prematurely (see the implementation
3469 of frame_unwind_id for an example). */
3472 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
3474 struct symtab_and_line sr_sal
;
3476 /* We shouldn't have gotten here if we don't know where the call site
3478 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
3480 init_sal (&sr_sal
); /* initialize to zeros */
3482 sr_sal
.pc
= gdbarch_addr_bits_remove
3483 (current_gdbarch
, frame_pc_unwind (next_frame
));
3484 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3486 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
3489 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
3490 new breakpoint at the target of a jmp_buf. The handling of
3491 longjmp-resume uses the same mechanisms used for handling
3492 "step-resume" breakpoints. */
3495 insert_longjmp_resume_breakpoint (CORE_ADDR pc
)
3497 /* There should never be more than one step-resume or longjmp-resume
3498 breakpoint per thread, so we should never be setting a new
3499 longjmp_resume_breakpoint when one is already active. */
3500 gdb_assert (step_resume_breakpoint
== NULL
);
3503 fprintf_unfiltered (gdb_stdlog
,
3504 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
3507 step_resume_breakpoint
=
3508 set_momentary_breakpoint_at_pc (pc
, bp_longjmp_resume
);
3512 stop_stepping (struct execution_control_state
*ecs
)
3515 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
3517 /* Let callers know we don't want to wait for the inferior anymore. */
3518 ecs
->wait_some_more
= 0;
3521 /* This function handles various cases where we need to continue
3522 waiting for the inferior. */
3523 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3526 keep_going (struct execution_control_state
*ecs
)
3528 /* Save the pc before execution, to compare with pc after stop. */
3529 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3531 /* If we did not do break;, it means we should keep running the
3532 inferior and not return to debugger. */
3534 if (stepping_over_breakpoint
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3536 /* We took a signal (which we are supposed to pass through to
3537 the inferior, else we'd have done a break above) and we
3538 haven't yet gotten our trap. Simply continue. */
3539 resume (currently_stepping (tss
), stop_signal
);
3543 /* Either the trap was not expected, but we are continuing
3544 anyway (the user asked that this signal be passed to the
3547 The signal was SIGTRAP, e.g. it was our signal, but we
3548 decided we should resume from it.
3550 We're going to run this baby now!
3552 Note that insert_breakpoints won't try to re-insert
3553 already inserted breakpoints. Therefore, we don't
3554 care if breakpoints were already inserted, or not. */
3556 if (tss
->stepping_over_breakpoint
)
3558 if (! use_displaced_stepping (current_gdbarch
))
3559 /* Since we can't do a displaced step, we have to remove
3560 the breakpoint while we step it. To keep things
3561 simple, we remove them all. */
3562 remove_breakpoints ();
3566 struct gdb_exception e
;
3567 /* Stop stepping when inserting breakpoints
3569 TRY_CATCH (e
, RETURN_MASK_ERROR
)
3571 insert_breakpoints ();
3575 stop_stepping (ecs
);
3580 stepping_over_breakpoint
= tss
->stepping_over_breakpoint
;
3582 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3583 specifies that such a signal should be delivered to the
3586 Typically, this would occure when a user is debugging a
3587 target monitor on a simulator: the target monitor sets a
3588 breakpoint; the simulator encounters this break-point and
3589 halts the simulation handing control to GDB; GDB, noteing
3590 that the break-point isn't valid, returns control back to the
3591 simulator; the simulator then delivers the hardware
3592 equivalent of a SIGNAL_TRAP to the program being debugged. */
3594 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3595 stop_signal
= TARGET_SIGNAL_0
;
3598 resume (currently_stepping (tss
), stop_signal
);
3601 prepare_to_wait (ecs
);
3604 /* This function normally comes after a resume, before
3605 handle_inferior_event exits. It takes care of any last bits of
3606 housekeeping, and sets the all-important wait_some_more flag. */
3609 prepare_to_wait (struct execution_control_state
*ecs
)
3612 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
3613 if (infwait_state
== infwait_normal_state
)
3615 overlay_cache_invalid
= 1;
3617 /* We have to invalidate the registers BEFORE calling
3618 target_wait because they can be loaded from the target while
3619 in target_wait. This makes remote debugging a bit more
3620 efficient for those targets that provide critical registers
3621 as part of their normal status mechanism. */
3623 registers_changed ();
3624 waiton_ptid
= pid_to_ptid (-1);
3626 /* This is the old end of the while loop. Let everybody know we
3627 want to wait for the inferior some more and get called again
3629 ecs
->wait_some_more
= 1;
3632 /* Print why the inferior has stopped. We always print something when
3633 the inferior exits, or receives a signal. The rest of the cases are
3634 dealt with later on in normal_stop() and print_it_typical(). Ideally
3635 there should be a call to this function from handle_inferior_event()
3636 each time stop_stepping() is called.*/
3638 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3640 switch (stop_reason
)
3642 case END_STEPPING_RANGE
:
3643 /* We are done with a step/next/si/ni command. */
3644 /* For now print nothing. */
3645 /* Print a message only if not in the middle of doing a "step n"
3646 operation for n > 1 */
3647 if (!step_multi
|| !stop_step
)
3648 if (ui_out_is_mi_like_p (uiout
))
3651 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
3654 /* The inferior was terminated by a signal. */
3655 annotate_signalled ();
3656 if (ui_out_is_mi_like_p (uiout
))
3659 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
3660 ui_out_text (uiout
, "\nProgram terminated with signal ");
3661 annotate_signal_name ();
3662 ui_out_field_string (uiout
, "signal-name",
3663 target_signal_to_name (stop_info
));
3664 annotate_signal_name_end ();
3665 ui_out_text (uiout
, ", ");
3666 annotate_signal_string ();
3667 ui_out_field_string (uiout
, "signal-meaning",
3668 target_signal_to_string (stop_info
));
3669 annotate_signal_string_end ();
3670 ui_out_text (uiout
, ".\n");
3671 ui_out_text (uiout
, "The program no longer exists.\n");
3674 /* The inferior program is finished. */
3675 annotate_exited (stop_info
);
3678 if (ui_out_is_mi_like_p (uiout
))
3679 ui_out_field_string (uiout
, "reason",
3680 async_reason_lookup (EXEC_ASYNC_EXITED
));
3681 ui_out_text (uiout
, "\nProgram exited with code ");
3682 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3683 (unsigned int) stop_info
);
3684 ui_out_text (uiout
, ".\n");
3688 if (ui_out_is_mi_like_p (uiout
))
3691 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
3692 ui_out_text (uiout
, "\nProgram exited normally.\n");
3694 /* Support the --return-child-result option. */
3695 return_child_result_value
= stop_info
;
3697 case SIGNAL_RECEIVED
:
3698 /* Signal received. The signal table tells us to print about
3701 ui_out_text (uiout
, "\nProgram received signal ");
3702 annotate_signal_name ();
3703 if (ui_out_is_mi_like_p (uiout
))
3705 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
3706 ui_out_field_string (uiout
, "signal-name",
3707 target_signal_to_name (stop_info
));
3708 annotate_signal_name_end ();
3709 ui_out_text (uiout
, ", ");
3710 annotate_signal_string ();
3711 ui_out_field_string (uiout
, "signal-meaning",
3712 target_signal_to_string (stop_info
));
3713 annotate_signal_string_end ();
3714 ui_out_text (uiout
, ".\n");
3717 internal_error (__FILE__
, __LINE__
,
3718 _("print_stop_reason: unrecognized enum value"));
3724 /* Here to return control to GDB when the inferior stops for real.
3725 Print appropriate messages, remove breakpoints, give terminal our modes.
3727 STOP_PRINT_FRAME nonzero means print the executing frame
3728 (pc, function, args, file, line number and line text).
3729 BREAKPOINTS_FAILED nonzero means stop was due to error
3730 attempting to insert breakpoints. */
3735 struct target_waitstatus last
;
3738 get_last_target_status (&last_ptid
, &last
);
3740 /* In non-stop mode, we don't want GDB to switch threads behind the
3741 user's back, to avoid races where the user is typing a command to
3742 apply to thread x, but GDB switches to thread y before the user
3743 finishes entering the command. */
3745 /* As with the notification of thread events, we want to delay
3746 notifying the user that we've switched thread context until
3747 the inferior actually stops.
3749 There's no point in saying anything if the inferior has exited.
3750 Note that SIGNALLED here means "exited with a signal", not
3751 "received a signal". */
3753 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3754 && target_has_execution
3755 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3756 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3758 target_terminal_ours_for_output ();
3759 printf_filtered (_("[Switching to %s]\n"),
3760 target_pid_to_str (inferior_ptid
));
3761 annotate_thread_changed ();
3762 previous_inferior_ptid
= inferior_ptid
;
3765 /* NOTE drow/2004-01-17: Is this still necessary? */
3766 /* Make sure that the current_frame's pc is correct. This
3767 is a correction for setting up the frame info before doing
3768 gdbarch_decr_pc_after_break */
3769 if (target_has_execution
)
3770 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3771 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3772 frame code to check for this and sort out any resultant mess.
3773 gdbarch_decr_pc_after_break needs to just go away. */
3774 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3776 if (!breakpoints_always_inserted_mode () && target_has_execution
)
3778 if (remove_breakpoints ())
3780 target_terminal_ours_for_output ();
3781 printf_filtered (_("\
3782 Cannot remove breakpoints because program is no longer writable.\n\
3783 It might be running in another process.\n\
3784 Further execution is probably impossible.\n"));
3788 /* If an auto-display called a function and that got a signal,
3789 delete that auto-display to avoid an infinite recursion. */
3791 if (stopped_by_random_signal
)
3792 disable_current_display ();
3794 /* Don't print a message if in the middle of doing a "step n"
3795 operation for n > 1 */
3796 if (step_multi
&& stop_step
)
3799 target_terminal_ours ();
3801 /* Set the current source location. This will also happen if we
3802 display the frame below, but the current SAL will be incorrect
3803 during a user hook-stop function. */
3804 if (target_has_stack
&& !stop_stack_dummy
)
3805 set_current_sal_from_frame (get_current_frame (), 1);
3807 /* Look up the hook_stop and run it (CLI internally handles problem
3808 of stop_command's pre-hook not existing). */
3810 catch_errors (hook_stop_stub
, stop_command
,
3811 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3813 if (!target_has_stack
)
3819 /* Select innermost stack frame - i.e., current frame is frame 0,
3820 and current location is based on that.
3821 Don't do this on return from a stack dummy routine,
3822 or if the program has exited. */
3824 if (!stop_stack_dummy
)
3826 select_frame (get_current_frame ());
3828 /* Print current location without a level number, if
3829 we have changed functions or hit a breakpoint.
3830 Print source line if we have one.
3831 bpstat_print() contains the logic deciding in detail
3832 what to print, based on the event(s) that just occurred. */
3834 /* If --batch-silent is enabled then there's no need to print the current
3835 source location, and to try risks causing an error message about
3836 missing source files. */
3837 if (stop_print_frame
&& !batch_silent
)
3841 int do_frame_printing
= 1;
3843 bpstat_ret
= bpstat_print (stop_bpstat
);
3847 /* If we had hit a shared library event breakpoint,
3848 bpstat_print would print out this message. If we hit
3849 an OS-level shared library event, do the same
3851 if (last
.kind
== TARGET_WAITKIND_LOADED
)
3853 printf_filtered (_("Stopped due to shared library event\n"));
3854 source_flag
= SRC_LINE
; /* something bogus */
3855 do_frame_printing
= 0;
3859 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3860 (or should) carry around the function and does (or
3861 should) use that when doing a frame comparison. */
3863 && frame_id_eq (step_frame_id
,
3864 get_frame_id (get_current_frame ()))
3865 && step_start_function
== find_pc_function (stop_pc
))
3866 source_flag
= SRC_LINE
; /* finished step, just print source line */
3868 source_flag
= SRC_AND_LOC
; /* print location and source line */
3870 case PRINT_SRC_AND_LOC
:
3871 source_flag
= SRC_AND_LOC
; /* print location and source line */
3873 case PRINT_SRC_ONLY
:
3874 source_flag
= SRC_LINE
;
3877 source_flag
= SRC_LINE
; /* something bogus */
3878 do_frame_printing
= 0;
3881 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
3884 if (ui_out_is_mi_like_p (uiout
))
3887 ui_out_field_int (uiout
, "thread-id",
3888 pid_to_thread_id (inferior_ptid
));
3891 struct cleanup
*back_to
= make_cleanup_ui_out_list_begin_end
3892 (uiout
, "stopped-threads");
3893 ui_out_field_int (uiout
, NULL
,
3894 pid_to_thread_id (inferior_ptid
));
3895 do_cleanups (back_to
);
3898 ui_out_field_string (uiout
, "stopped-threads", "all");
3900 /* The behavior of this routine with respect to the source
3902 SRC_LINE: Print only source line
3903 LOCATION: Print only location
3904 SRC_AND_LOC: Print location and source line */
3905 if (do_frame_printing
)
3906 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
3908 /* Display the auto-display expressions. */
3913 /* Save the function value return registers, if we care.
3914 We might be about to restore their previous contents. */
3915 if (proceed_to_finish
)
3917 /* This should not be necessary. */
3919 regcache_xfree (stop_registers
);
3921 /* NB: The copy goes through to the target picking up the value of
3922 all the registers. */
3923 stop_registers
= regcache_dup (get_current_regcache ());
3926 if (stop_stack_dummy
)
3928 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3929 ends with a setting of the current frame, so we can use that
3931 frame_pop (get_current_frame ());
3932 /* Set stop_pc to what it was before we called the function.
3933 Can't rely on restore_inferior_status because that only gets
3934 called if we don't stop in the called function. */
3935 stop_pc
= read_pc ();
3936 select_frame (get_current_frame ());
3940 annotate_stopped ();
3941 if (!suppress_stop_observer
&& !step_multi
)
3942 observer_notify_normal_stop (stop_bpstat
);
3943 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3944 Delete any breakpoint that is to be deleted at the next stop. */
3945 breakpoint_auto_delete (stop_bpstat
);
3947 if (target_has_execution
3948 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3949 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3952 set_running (pid_to_ptid (-1), 0);
3954 set_running (inferior_ptid
, 0);
3959 hook_stop_stub (void *cmd
)
3961 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3966 signal_stop_state (int signo
)
3968 /* Always stop on signals if we're just gaining control of the
3970 return signal_stop
[signo
] || stop_soon
!= NO_STOP_QUIETLY
;
3974 signal_print_state (int signo
)
3976 return signal_print
[signo
];
3980 signal_pass_state (int signo
)
3982 return signal_program
[signo
];
3986 signal_stop_update (int signo
, int state
)
3988 int ret
= signal_stop
[signo
];
3989 signal_stop
[signo
] = state
;
3994 signal_print_update (int signo
, int state
)
3996 int ret
= signal_print
[signo
];
3997 signal_print
[signo
] = state
;
4002 signal_pass_update (int signo
, int state
)
4004 int ret
= signal_program
[signo
];
4005 signal_program
[signo
] = state
;
4010 sig_print_header (void)
4012 printf_filtered (_("\
4013 Signal Stop\tPrint\tPass to program\tDescription\n"));
4017 sig_print_info (enum target_signal oursig
)
4019 char *name
= target_signal_to_name (oursig
);
4020 int name_padding
= 13 - strlen (name
);
4022 if (name_padding
<= 0)
4025 printf_filtered ("%s", name
);
4026 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
4027 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
4028 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
4029 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
4030 printf_filtered ("%s\n", target_signal_to_string (oursig
));
4033 /* Specify how various signals in the inferior should be handled. */
4036 handle_command (char *args
, int from_tty
)
4039 int digits
, wordlen
;
4040 int sigfirst
, signum
, siglast
;
4041 enum target_signal oursig
;
4044 unsigned char *sigs
;
4045 struct cleanup
*old_chain
;
4049 error_no_arg (_("signal to handle"));
4052 /* Allocate and zero an array of flags for which signals to handle. */
4054 nsigs
= (int) TARGET_SIGNAL_LAST
;
4055 sigs
= (unsigned char *) alloca (nsigs
);
4056 memset (sigs
, 0, nsigs
);
4058 /* Break the command line up into args. */
4060 argv
= buildargv (args
);
4065 old_chain
= make_cleanup_freeargv (argv
);
4067 /* Walk through the args, looking for signal oursigs, signal names, and
4068 actions. Signal numbers and signal names may be interspersed with
4069 actions, with the actions being performed for all signals cumulatively
4070 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4072 while (*argv
!= NULL
)
4074 wordlen
= strlen (*argv
);
4075 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
4079 sigfirst
= siglast
= -1;
4081 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
4083 /* Apply action to all signals except those used by the
4084 debugger. Silently skip those. */
4087 siglast
= nsigs
- 1;
4089 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
4091 SET_SIGS (nsigs
, sigs
, signal_stop
);
4092 SET_SIGS (nsigs
, sigs
, signal_print
);
4094 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
4096 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4098 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
4100 SET_SIGS (nsigs
, sigs
, signal_print
);
4102 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
4104 SET_SIGS (nsigs
, sigs
, signal_program
);
4106 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
4108 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4110 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
4112 SET_SIGS (nsigs
, sigs
, signal_program
);
4114 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
4116 UNSET_SIGS (nsigs
, sigs
, signal_print
);
4117 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4119 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
4121 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4123 else if (digits
> 0)
4125 /* It is numeric. The numeric signal refers to our own
4126 internal signal numbering from target.h, not to host/target
4127 signal number. This is a feature; users really should be
4128 using symbolic names anyway, and the common ones like
4129 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
4131 sigfirst
= siglast
= (int)
4132 target_signal_from_command (atoi (*argv
));
4133 if ((*argv
)[digits
] == '-')
4136 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
4138 if (sigfirst
> siglast
)
4140 /* Bet he didn't figure we'd think of this case... */
4148 oursig
= target_signal_from_name (*argv
);
4149 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
4151 sigfirst
= siglast
= (int) oursig
;
4155 /* Not a number and not a recognized flag word => complain. */
4156 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
4160 /* If any signal numbers or symbol names were found, set flags for
4161 which signals to apply actions to. */
4163 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
4165 switch ((enum target_signal
) signum
)
4167 case TARGET_SIGNAL_TRAP
:
4168 case TARGET_SIGNAL_INT
:
4169 if (!allsigs
&& !sigs
[signum
])
4171 if (query ("%s is used by the debugger.\n\
4172 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
4178 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4179 gdb_flush (gdb_stdout
);
4183 case TARGET_SIGNAL_0
:
4184 case TARGET_SIGNAL_DEFAULT
:
4185 case TARGET_SIGNAL_UNKNOWN
:
4186 /* Make sure that "all" doesn't print these. */
4197 target_notice_signals (inferior_ptid
);
4201 /* Show the results. */
4202 sig_print_header ();
4203 for (signum
= 0; signum
< nsigs
; signum
++)
4207 sig_print_info (signum
);
4212 do_cleanups (old_chain
);
4216 xdb_handle_command (char *args
, int from_tty
)
4219 struct cleanup
*old_chain
;
4221 /* Break the command line up into args. */
4223 argv
= buildargv (args
);
4228 old_chain
= make_cleanup_freeargv (argv
);
4229 if (argv
[1] != (char *) NULL
)
4234 bufLen
= strlen (argv
[0]) + 20;
4235 argBuf
= (char *) xmalloc (bufLen
);
4239 enum target_signal oursig
;
4241 oursig
= target_signal_from_name (argv
[0]);
4242 memset (argBuf
, 0, bufLen
);
4243 if (strcmp (argv
[1], "Q") == 0)
4244 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4247 if (strcmp (argv
[1], "s") == 0)
4249 if (!signal_stop
[oursig
])
4250 sprintf (argBuf
, "%s %s", argv
[0], "stop");
4252 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
4254 else if (strcmp (argv
[1], "i") == 0)
4256 if (!signal_program
[oursig
])
4257 sprintf (argBuf
, "%s %s", argv
[0], "pass");
4259 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
4261 else if (strcmp (argv
[1], "r") == 0)
4263 if (!signal_print
[oursig
])
4264 sprintf (argBuf
, "%s %s", argv
[0], "print");
4266 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4272 handle_command (argBuf
, from_tty
);
4274 printf_filtered (_("Invalid signal handling flag.\n"));
4279 do_cleanups (old_chain
);
4282 /* Print current contents of the tables set by the handle command.
4283 It is possible we should just be printing signals actually used
4284 by the current target (but for things to work right when switching
4285 targets, all signals should be in the signal tables). */
4288 signals_info (char *signum_exp
, int from_tty
)
4290 enum target_signal oursig
;
4291 sig_print_header ();
4295 /* First see if this is a symbol name. */
4296 oursig
= target_signal_from_name (signum_exp
);
4297 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
4299 /* No, try numeric. */
4301 target_signal_from_command (parse_and_eval_long (signum_exp
));
4303 sig_print_info (oursig
);
4307 printf_filtered ("\n");
4308 /* These ugly casts brought to you by the native VAX compiler. */
4309 for (oursig
= TARGET_SIGNAL_FIRST
;
4310 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
4311 oursig
= (enum target_signal
) ((int) oursig
+ 1))
4315 if (oursig
!= TARGET_SIGNAL_UNKNOWN
4316 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
4317 sig_print_info (oursig
);
4320 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4323 struct inferior_status
4325 enum target_signal stop_signal
;
4329 int stop_stack_dummy
;
4330 int stopped_by_random_signal
;
4331 int stepping_over_breakpoint
;
4332 CORE_ADDR step_range_start
;
4333 CORE_ADDR step_range_end
;
4334 struct frame_id step_frame_id
;
4335 enum step_over_calls_kind step_over_calls
;
4336 CORE_ADDR step_resume_break_address
;
4337 int stop_after_trap
;
4340 /* These are here because if call_function_by_hand has written some
4341 registers and then decides to call error(), we better not have changed
4343 struct regcache
*registers
;
4345 /* A frame unique identifier. */
4346 struct frame_id selected_frame_id
;
4348 int breakpoint_proceeded
;
4349 int restore_stack_info
;
4350 int proceed_to_finish
;
4354 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
4357 int size
= register_size (current_gdbarch
, regno
);
4358 void *buf
= alloca (size
);
4359 store_signed_integer (buf
, size
, val
);
4360 regcache_raw_write (inf_status
->registers
, regno
, buf
);
4363 /* Save all of the information associated with the inferior<==>gdb
4364 connection. INF_STATUS is a pointer to a "struct inferior_status"
4365 (defined in inferior.h). */
4367 struct inferior_status
*
4368 save_inferior_status (int restore_stack_info
)
4370 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
4372 inf_status
->stop_signal
= stop_signal
;
4373 inf_status
->stop_pc
= stop_pc
;
4374 inf_status
->stop_step
= stop_step
;
4375 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
4376 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
4377 inf_status
->stepping_over_breakpoint
= stepping_over_breakpoint
;
4378 inf_status
->step_range_start
= step_range_start
;
4379 inf_status
->step_range_end
= step_range_end
;
4380 inf_status
->step_frame_id
= step_frame_id
;
4381 inf_status
->step_over_calls
= step_over_calls
;
4382 inf_status
->stop_after_trap
= stop_after_trap
;
4383 inf_status
->stop_soon
= stop_soon
;
4384 /* Save original bpstat chain here; replace it with copy of chain.
4385 If caller's caller is walking the chain, they'll be happier if we
4386 hand them back the original chain when restore_inferior_status is
4388 inf_status
->stop_bpstat
= stop_bpstat
;
4389 stop_bpstat
= bpstat_copy (stop_bpstat
);
4390 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4391 inf_status
->restore_stack_info
= restore_stack_info
;
4392 inf_status
->proceed_to_finish
= proceed_to_finish
;
4394 inf_status
->registers
= regcache_dup (get_current_regcache ());
4396 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
4401 restore_selected_frame (void *args
)
4403 struct frame_id
*fid
= (struct frame_id
*) args
;
4404 struct frame_info
*frame
;
4406 frame
= frame_find_by_id (*fid
);
4408 /* If inf_status->selected_frame_id is NULL, there was no previously
4412 warning (_("Unable to restore previously selected frame."));
4416 select_frame (frame
);
4422 restore_inferior_status (struct inferior_status
*inf_status
)
4424 stop_signal
= inf_status
->stop_signal
;
4425 stop_pc
= inf_status
->stop_pc
;
4426 stop_step
= inf_status
->stop_step
;
4427 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4428 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4429 stepping_over_breakpoint
= inf_status
->stepping_over_breakpoint
;
4430 step_range_start
= inf_status
->step_range_start
;
4431 step_range_end
= inf_status
->step_range_end
;
4432 step_frame_id
= inf_status
->step_frame_id
;
4433 step_over_calls
= inf_status
->step_over_calls
;
4434 stop_after_trap
= inf_status
->stop_after_trap
;
4435 stop_soon
= inf_status
->stop_soon
;
4436 bpstat_clear (&stop_bpstat
);
4437 stop_bpstat
= inf_status
->stop_bpstat
;
4438 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4439 proceed_to_finish
= inf_status
->proceed_to_finish
;
4441 /* The inferior can be gone if the user types "print exit(0)"
4442 (and perhaps other times). */
4443 if (target_has_execution
)
4444 /* NB: The register write goes through to the target. */
4445 regcache_cpy (get_current_regcache (), inf_status
->registers
);
4446 regcache_xfree (inf_status
->registers
);
4448 /* FIXME: If we are being called after stopping in a function which
4449 is called from gdb, we should not be trying to restore the
4450 selected frame; it just prints a spurious error message (The
4451 message is useful, however, in detecting bugs in gdb (like if gdb
4452 clobbers the stack)). In fact, should we be restoring the
4453 inferior status at all in that case? . */
4455 if (target_has_stack
&& inf_status
->restore_stack_info
)
4457 /* The point of catch_errors is that if the stack is clobbered,
4458 walking the stack might encounter a garbage pointer and
4459 error() trying to dereference it. */
4461 (restore_selected_frame
, &inf_status
->selected_frame_id
,
4462 "Unable to restore previously selected frame:\n",
4463 RETURN_MASK_ERROR
) == 0)
4464 /* Error in restoring the selected frame. Select the innermost
4466 select_frame (get_current_frame ());
4474 do_restore_inferior_status_cleanup (void *sts
)
4476 restore_inferior_status (sts
);
4480 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4482 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4486 discard_inferior_status (struct inferior_status
*inf_status
)
4488 /* See save_inferior_status for info on stop_bpstat. */
4489 bpstat_clear (&inf_status
->stop_bpstat
);
4490 regcache_xfree (inf_status
->registers
);
4495 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
4497 struct target_waitstatus last
;
4500 get_last_target_status (&last_ptid
, &last
);
4502 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
4505 if (!ptid_equal (last_ptid
, pid
))
4508 *child_pid
= last
.value
.related_pid
;
4513 inferior_has_vforked (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_VFORKED
)
4523 if (!ptid_equal (last_ptid
, pid
))
4526 *child_pid
= last
.value
.related_pid
;
4531 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
4533 struct target_waitstatus last
;
4536 get_last_target_status (&last_ptid
, &last
);
4538 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
4541 if (!ptid_equal (last_ptid
, pid
))
4544 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
4548 /* Oft used ptids */
4550 ptid_t minus_one_ptid
;
4552 /* Create a ptid given the necessary PID, LWP, and TID components. */
4555 ptid_build (int pid
, long lwp
, long tid
)
4565 /* Create a ptid from just a pid. */
4568 pid_to_ptid (int pid
)
4570 return ptid_build (pid
, 0, 0);
4573 /* Fetch the pid (process id) component from a ptid. */
4576 ptid_get_pid (ptid_t ptid
)
4581 /* Fetch the lwp (lightweight process) component from a ptid. */
4584 ptid_get_lwp (ptid_t ptid
)
4589 /* Fetch the tid (thread id) component from a ptid. */
4592 ptid_get_tid (ptid_t ptid
)
4597 /* ptid_equal() is used to test equality of two ptids. */
4600 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4602 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4603 && ptid1
.tid
== ptid2
.tid
);
4606 /* restore_inferior_ptid() will be used by the cleanup machinery
4607 to restore the inferior_ptid value saved in a call to
4608 save_inferior_ptid(). */
4611 restore_inferior_ptid (void *arg
)
4613 ptid_t
*saved_ptid_ptr
= arg
;
4614 inferior_ptid
= *saved_ptid_ptr
;
4618 /* Save the value of inferior_ptid so that it may be restored by a
4619 later call to do_cleanups(). Returns the struct cleanup pointer
4620 needed for later doing the cleanup. */
4623 save_inferior_ptid (void)
4625 ptid_t
*saved_ptid_ptr
;
4627 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4628 *saved_ptid_ptr
= inferior_ptid
;
4629 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4634 static int non_stop_1
= 0;
4637 set_non_stop (char *args
, int from_tty
,
4638 struct cmd_list_element
*c
)
4640 if (target_has_execution
)
4642 non_stop_1
= non_stop
;
4643 error (_("Cannot change this setting while the inferior is running."));
4646 non_stop
= non_stop_1
;
4650 show_non_stop (struct ui_file
*file
, int from_tty
,
4651 struct cmd_list_element
*c
, const char *value
)
4653 fprintf_filtered (file
,
4654 _("Controlling the inferior in non-stop mode is %s.\n"),
4660 _initialize_infrun (void)
4664 struct cmd_list_element
*c
;
4666 add_info ("signals", signals_info
, _("\
4667 What debugger does when program gets various signals.\n\
4668 Specify a signal as argument to print info on that signal only."));
4669 add_info_alias ("handle", "signals", 0);
4671 add_com ("handle", class_run
, handle_command
, _("\
4672 Specify how to handle a signal.\n\
4673 Args are signals and actions to apply to those signals.\n\
4674 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4675 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4676 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4677 The special arg \"all\" is recognized to mean all signals except those\n\
4678 used by the debugger, typically SIGTRAP and SIGINT.\n\
4679 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4680 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4681 Stop means reenter debugger if this signal happens (implies print).\n\
4682 Print means print a message if this signal happens.\n\
4683 Pass means let program see this signal; otherwise program doesn't know.\n\
4684 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4685 Pass and Stop may be combined."));
4688 add_com ("lz", class_info
, signals_info
, _("\
4689 What debugger does when program gets various signals.\n\
4690 Specify a signal as argument to print info on that signal only."));
4691 add_com ("z", class_run
, xdb_handle_command
, _("\
4692 Specify how to handle a signal.\n\
4693 Args are signals and actions to apply to those signals.\n\
4694 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4695 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4696 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4697 The special arg \"all\" is recognized to mean all signals except those\n\
4698 used by the debugger, typically SIGTRAP and SIGINT.\n\
4699 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4700 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4701 nopass), \"Q\" (noprint)\n\
4702 Stop means reenter debugger if this signal happens (implies print).\n\
4703 Print means print a message if this signal happens.\n\
4704 Pass means let program see this signal; otherwise program doesn't know.\n\
4705 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4706 Pass and Stop may be combined."));
4710 stop_command
= add_cmd ("stop", class_obscure
,
4711 not_just_help_class_command
, _("\
4712 There is no `stop' command, but you can set a hook on `stop'.\n\
4713 This allows you to set a list of commands to be run each time execution\n\
4714 of the program stops."), &cmdlist
);
4716 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
4717 Set inferior debugging."), _("\
4718 Show inferior debugging."), _("\
4719 When non-zero, inferior specific debugging is enabled."),
4722 &setdebuglist
, &showdebuglist
);
4724 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
4725 Set displaced stepping debugging."), _("\
4726 Show displaced stepping debugging."), _("\
4727 When non-zero, displaced stepping specific debugging is enabled."),
4729 show_debug_displaced
,
4730 &setdebuglist
, &showdebuglist
);
4732 add_setshow_boolean_cmd ("non-stop", no_class
,
4734 Set whether gdb controls the inferior in non-stop mode."), _("\
4735 Show whether gdb controls the inferior in non-stop mode."), _("\
4736 When debugging a multi-threaded program and this setting is\n\
4737 off (the default, also called all-stop mode), when one thread stops\n\
4738 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
4739 all other threads in the program while you interact with the thread of\n\
4740 interest. When you continue or step a thread, you can allow the other\n\
4741 threads to run, or have them remain stopped, but while you inspect any\n\
4742 thread's state, all threads stop.\n\
4744 In non-stop mode, when one thread stops, other threads can continue\n\
4745 to run freely. You'll be able to step each thread independently,\n\
4746 leave it stopped or free to run as needed."),
4752 numsigs
= (int) TARGET_SIGNAL_LAST
;
4753 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4754 signal_print
= (unsigned char *)
4755 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4756 signal_program
= (unsigned char *)
4757 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4758 for (i
= 0; i
< numsigs
; i
++)
4761 signal_print
[i
] = 1;
4762 signal_program
[i
] = 1;
4765 /* Signals caused by debugger's own actions
4766 should not be given to the program afterwards. */
4767 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4768 signal_program
[TARGET_SIGNAL_INT
] = 0;
4770 /* Signals that are not errors should not normally enter the debugger. */
4771 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4772 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4773 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4774 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4775 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4776 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4777 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4778 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4779 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4780 signal_print
[TARGET_SIGNAL_IO
] = 0;
4781 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4782 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4783 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4784 signal_print
[TARGET_SIGNAL_URG
] = 0;
4785 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4786 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4788 /* These signals are used internally by user-level thread
4789 implementations. (See signal(5) on Solaris.) Like the above
4790 signals, a healthy program receives and handles them as part of
4791 its normal operation. */
4792 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4793 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4794 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4795 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4796 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4797 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4799 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
4800 &stop_on_solib_events
, _("\
4801 Set stopping for shared library events."), _("\
4802 Show stopping for shared library events."), _("\
4803 If nonzero, gdb will give control to the user when the dynamic linker\n\
4804 notifies gdb of shared library events. The most common event of interest\n\
4805 to the user would be loading/unloading of a new library."),
4807 show_stop_on_solib_events
,
4808 &setlist
, &showlist
);
4810 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
4811 follow_fork_mode_kind_names
,
4812 &follow_fork_mode_string
, _("\
4813 Set debugger response to a program call of fork or vfork."), _("\
4814 Show debugger response to a program call of fork or vfork."), _("\
4815 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4816 parent - the original process is debugged after a fork\n\
4817 child - the new process is debugged after a fork\n\
4818 The unfollowed process will continue to run.\n\
4819 By default, the debugger will follow the parent process."),
4821 show_follow_fork_mode_string
,
4822 &setlist
, &showlist
);
4824 add_setshow_enum_cmd ("scheduler-locking", class_run
,
4825 scheduler_enums
, &scheduler_mode
, _("\
4826 Set mode for locking scheduler during execution."), _("\
4827 Show mode for locking scheduler during execution."), _("\
4828 off == no locking (threads may preempt at any time)\n\
4829 on == full locking (no thread except the current thread may run)\n\
4830 step == scheduler locked during every single-step operation.\n\
4831 In this mode, no other thread may run during a step command.\n\
4832 Other threads may run while stepping over a function call ('next')."),
4833 set_schedlock_func
, /* traps on target vector */
4834 show_scheduler_mode
,
4835 &setlist
, &showlist
);
4837 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
4838 Set mode of the step operation."), _("\
4839 Show mode of the step operation."), _("\
4840 When set, doing a step over a function without debug line information\n\
4841 will stop at the first instruction of that function. Otherwise, the\n\
4842 function is skipped and the step command stops at a different source line."),
4844 show_step_stop_if_no_debug
,
4845 &setlist
, &showlist
);
4847 add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance
,
4848 &can_use_displaced_stepping
, _("\
4849 Set debugger's willingness to use displaced stepping."), _("\
4850 Show debugger's willingness to use displaced stepping."), _("\
4851 If zero, gdb will not use displaced stepping to step over\n\
4852 breakpoints, even if such is supported by the target."),
4854 show_can_use_displaced_stepping
,
4855 &maintenance_set_cmdlist
,
4856 &maintenance_show_cmdlist
);
4858 /* ptid initializations */
4859 null_ptid
= ptid_build (0, 0, 0);
4860 minus_one_ptid
= ptid_build (-1, 0, 0);
4861 inferior_ptid
= null_ptid
;
4862 target_last_wait_ptid
= minus_one_ptid
;
4863 displaced_step_ptid
= null_ptid
;