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, 2009, 2010 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"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "inline-frame.h"
54 #include "tracepoint.h"
56 /* Prototypes for local functions */
58 static void signals_info (char *, int);
60 static void handle_command (char *, int);
62 static void sig_print_info (enum target_signal
);
64 static void sig_print_header (void);
66 static void resume_cleanups (void *);
68 static int hook_stop_stub (void *);
70 static int restore_selected_frame (void *);
72 static int follow_fork (void);
74 static void set_schedlock_func (char *args
, int from_tty
,
75 struct cmd_list_element
*c
);
77 static int currently_stepping (struct thread_info
*tp
);
79 static int currently_stepping_or_nexting_callback (struct thread_info
*tp
,
82 static void xdb_handle_command (char *args
, int from_tty
);
84 static int prepare_to_proceed (int);
86 void _initialize_infrun (void);
88 void nullify_last_target_wait_ptid (void);
90 /* When set, stop the 'step' command if we enter a function which has
91 no line number information. The normal behavior is that we step
92 over such function. */
93 int step_stop_if_no_debug
= 0;
95 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
96 struct cmd_list_element
*c
, const char *value
)
98 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
101 /* In asynchronous mode, but simulating synchronous execution. */
103 int sync_execution
= 0;
105 /* wait_for_inferior and normal_stop use this to notify the user
106 when the inferior stopped in a different thread than it had been
109 static ptid_t previous_inferior_ptid
;
111 /* Default behavior is to detach newly forked processes (legacy). */
114 int debug_displaced
= 0;
116 show_debug_displaced (struct ui_file
*file
, int from_tty
,
117 struct cmd_list_element
*c
, const char *value
)
119 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
122 static int debug_infrun
= 0;
124 show_debug_infrun (struct ui_file
*file
, int from_tty
,
125 struct cmd_list_element
*c
, const char *value
)
127 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
130 /* If the program uses ELF-style shared libraries, then calls to
131 functions in shared libraries go through stubs, which live in a
132 table called the PLT (Procedure Linkage Table). The first time the
133 function is called, the stub sends control to the dynamic linker,
134 which looks up the function's real address, patches the stub so
135 that future calls will go directly to the function, and then passes
136 control to the function.
138 If we are stepping at the source level, we don't want to see any of
139 this --- we just want to skip over the stub and the dynamic linker.
140 The simple approach is to single-step until control leaves the
143 However, on some systems (e.g., Red Hat's 5.2 distribution) the
144 dynamic linker calls functions in the shared C library, so you
145 can't tell from the PC alone whether the dynamic linker is still
146 running. In this case, we use a step-resume breakpoint to get us
147 past the dynamic linker, as if we were using "next" to step over a
150 in_solib_dynsym_resolve_code() says whether we're in the dynamic
151 linker code or not. Normally, this means we single-step. However,
152 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
153 address where we can place a step-resume breakpoint to get past the
154 linker's symbol resolution function.
156 in_solib_dynsym_resolve_code() can generally be implemented in a
157 pretty portable way, by comparing the PC against the address ranges
158 of the dynamic linker's sections.
160 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
161 it depends on internal details of the dynamic linker. It's usually
162 not too hard to figure out where to put a breakpoint, but it
163 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
164 sanity checking. If it can't figure things out, returning zero and
165 getting the (possibly confusing) stepping behavior is better than
166 signalling an error, which will obscure the change in the
169 /* This function returns TRUE if pc is the address of an instruction
170 that lies within the dynamic linker (such as the event hook, or the
173 This function must be used only when a dynamic linker event has
174 been caught, and the inferior is being stepped out of the hook, or
175 undefined results are guaranteed. */
177 #ifndef SOLIB_IN_DYNAMIC_LINKER
178 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
181 /* "Observer mode" is somewhat like a more extreme version of
182 non-stop, in which all GDB operations that might affect the
183 target's execution have been disabled. */
185 static int non_stop_1
= 0;
187 int observer_mode
= 0;
188 static int observer_mode_1
= 0;
191 set_observer_mode (char *args
, int from_tty
,
192 struct cmd_list_element
*c
)
194 extern int pagination_enabled
;
196 if (target_has_execution
)
198 observer_mode_1
= observer_mode
;
199 error (_("Cannot change this setting while the inferior is running."));
202 observer_mode
= observer_mode_1
;
204 may_write_registers
= !observer_mode
;
205 may_write_memory
= !observer_mode
;
206 may_insert_breakpoints
= !observer_mode
;
207 may_insert_tracepoints
= !observer_mode
;
208 /* We can insert fast tracepoints in or out of observer mode,
209 but enable them if we're going into this mode. */
211 may_insert_fast_tracepoints
= 1;
212 may_stop
= !observer_mode
;
213 update_target_permissions ();
215 /* Going *into* observer mode we must force non-stop, then
216 going out we leave it that way. */
219 target_async_permitted
= 1;
220 pagination_enabled
= 0;
221 non_stop
= non_stop_1
= 1;
225 printf_filtered (_("Observer mode is now %s.\n"),
226 (observer_mode
? "on" : "off"));
230 show_observer_mode (struct ui_file
*file
, int from_tty
,
231 struct cmd_list_element
*c
, const char *value
)
233 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
236 /* This updates the value of observer mode based on changes in
237 permissions. Note that we are deliberately ignoring the values of
238 may-write-registers and may-write-memory, since the user may have
239 reason to enable these during a session, for instance to turn on a
240 debugging-related global. */
243 update_observer_mode (void)
247 newval
= (!may_insert_breakpoints
248 && !may_insert_tracepoints
249 && may_insert_fast_tracepoints
253 /* Let the user know if things change. */
254 if (newval
!= observer_mode
)
255 printf_filtered (_("Observer mode is now %s.\n"),
256 (newval
? "on" : "off"));
258 observer_mode
= observer_mode_1
= newval
;
261 /* Tables of how to react to signals; the user sets them. */
263 static unsigned char *signal_stop
;
264 static unsigned char *signal_print
;
265 static unsigned char *signal_program
;
267 #define SET_SIGS(nsigs,sigs,flags) \
269 int signum = (nsigs); \
270 while (signum-- > 0) \
271 if ((sigs)[signum]) \
272 (flags)[signum] = 1; \
275 #define UNSET_SIGS(nsigs,sigs,flags) \
277 int signum = (nsigs); \
278 while (signum-- > 0) \
279 if ((sigs)[signum]) \
280 (flags)[signum] = 0; \
283 /* Value to pass to target_resume() to cause all threads to resume */
285 #define RESUME_ALL minus_one_ptid
287 /* Command list pointer for the "stop" placeholder. */
289 static struct cmd_list_element
*stop_command
;
291 /* Function inferior was in as of last step command. */
293 static struct symbol
*step_start_function
;
295 /* Nonzero if we want to give control to the user when we're notified
296 of shared library events by the dynamic linker. */
297 static int stop_on_solib_events
;
299 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
300 struct cmd_list_element
*c
, const char *value
)
302 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
306 /* Nonzero means expecting a trace trap
307 and should stop the inferior and return silently when it happens. */
311 /* Save register contents here when executing a "finish" command or are
312 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
313 Thus this contains the return value from the called function (assuming
314 values are returned in a register). */
316 struct regcache
*stop_registers
;
318 /* Nonzero after stop if current stack frame should be printed. */
320 static int stop_print_frame
;
322 /* This is a cached copy of the pid/waitstatus of the last event
323 returned by target_wait()/deprecated_target_wait_hook(). This
324 information is returned by get_last_target_status(). */
325 static ptid_t target_last_wait_ptid
;
326 static struct target_waitstatus target_last_waitstatus
;
328 static void context_switch (ptid_t ptid
);
330 void init_thread_stepping_state (struct thread_info
*tss
);
332 void init_infwait_state (void);
334 static const char follow_fork_mode_child
[] = "child";
335 static const char follow_fork_mode_parent
[] = "parent";
337 static const char *follow_fork_mode_kind_names
[] = {
338 follow_fork_mode_child
,
339 follow_fork_mode_parent
,
343 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
345 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
346 struct cmd_list_element
*c
, const char *value
)
348 fprintf_filtered (file
, _("\
349 Debugger response to a program call of fork or vfork is \"%s\".\n"),
354 /* Tell the target to follow the fork we're stopped at. Returns true
355 if the inferior should be resumed; false, if the target for some
356 reason decided it's best not to resume. */
361 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
362 int should_resume
= 1;
363 struct thread_info
*tp
;
365 /* Copy user stepping state to the new inferior thread. FIXME: the
366 followed fork child thread should have a copy of most of the
367 parent thread structure's run control related fields, not just these.
368 Initialized to avoid "may be used uninitialized" warnings from gcc. */
369 struct breakpoint
*step_resume_breakpoint
= NULL
;
370 CORE_ADDR step_range_start
= 0;
371 CORE_ADDR step_range_end
= 0;
372 struct frame_id step_frame_id
= { 0 };
377 struct target_waitstatus wait_status
;
379 /* Get the last target status returned by target_wait(). */
380 get_last_target_status (&wait_ptid
, &wait_status
);
382 /* If not stopped at a fork event, then there's nothing else to
384 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
385 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
388 /* Check if we switched over from WAIT_PTID, since the event was
390 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
391 && !ptid_equal (inferior_ptid
, wait_ptid
))
393 /* We did. Switch back to WAIT_PTID thread, to tell the
394 target to follow it (in either direction). We'll
395 afterwards refuse to resume, and inform the user what
397 switch_to_thread (wait_ptid
);
402 tp
= inferior_thread ();
404 /* If there were any forks/vforks that were caught and are now to be
405 followed, then do so now. */
406 switch (tp
->pending_follow
.kind
)
408 case TARGET_WAITKIND_FORKED
:
409 case TARGET_WAITKIND_VFORKED
:
411 ptid_t parent
, child
;
413 /* If the user did a next/step, etc, over a fork call,
414 preserve the stepping state in the fork child. */
415 if (follow_child
&& should_resume
)
417 step_resume_breakpoint
418 = clone_momentary_breakpoint (tp
->step_resume_breakpoint
);
419 step_range_start
= tp
->step_range_start
;
420 step_range_end
= tp
->step_range_end
;
421 step_frame_id
= tp
->step_frame_id
;
423 /* For now, delete the parent's sr breakpoint, otherwise,
424 parent/child sr breakpoints are considered duplicates,
425 and the child version will not be installed. Remove
426 this when the breakpoints module becomes aware of
427 inferiors and address spaces. */
428 delete_step_resume_breakpoint (tp
);
429 tp
->step_range_start
= 0;
430 tp
->step_range_end
= 0;
431 tp
->step_frame_id
= null_frame_id
;
434 parent
= inferior_ptid
;
435 child
= tp
->pending_follow
.value
.related_pid
;
437 /* Tell the target to do whatever is necessary to follow
438 either parent or child. */
439 if (target_follow_fork (follow_child
))
441 /* Target refused to follow, or there's some other reason
442 we shouldn't resume. */
447 /* This pending follow fork event is now handled, one way
448 or another. The previous selected thread may be gone
449 from the lists by now, but if it is still around, need
450 to clear the pending follow request. */
451 tp
= find_thread_ptid (parent
);
453 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
455 /* This makes sure we don't try to apply the "Switched
456 over from WAIT_PID" logic above. */
457 nullify_last_target_wait_ptid ();
459 /* If we followed the child, switch to it... */
462 switch_to_thread (child
);
464 /* ... and preserve the stepping state, in case the
465 user was stepping over the fork call. */
468 tp
= inferior_thread ();
469 tp
->step_resume_breakpoint
= step_resume_breakpoint
;
470 tp
->step_range_start
= step_range_start
;
471 tp
->step_range_end
= step_range_end
;
472 tp
->step_frame_id
= step_frame_id
;
476 /* If we get here, it was because we're trying to
477 resume from a fork catchpoint, but, the user
478 has switched threads away from the thread that
479 forked. In that case, the resume command
480 issued is most likely not applicable to the
481 child, so just warn, and refuse to resume. */
483 Not resuming: switched threads before following fork child.\n"));
486 /* Reset breakpoints in the child as appropriate. */
487 follow_inferior_reset_breakpoints ();
490 switch_to_thread (parent
);
494 case TARGET_WAITKIND_SPURIOUS
:
495 /* Nothing to follow. */
498 internal_error (__FILE__
, __LINE__
,
499 "Unexpected pending_follow.kind %d\n",
500 tp
->pending_follow
.kind
);
504 return should_resume
;
508 follow_inferior_reset_breakpoints (void)
510 struct thread_info
*tp
= inferior_thread ();
512 /* Was there a step_resume breakpoint? (There was if the user
513 did a "next" at the fork() call.) If so, explicitly reset its
516 step_resumes are a form of bp that are made to be per-thread.
517 Since we created the step_resume bp when the parent process
518 was being debugged, and now are switching to the child process,
519 from the breakpoint package's viewpoint, that's a switch of
520 "threads". We must update the bp's notion of which thread
521 it is for, or it'll be ignored when it triggers. */
523 if (tp
->step_resume_breakpoint
)
524 breakpoint_re_set_thread (tp
->step_resume_breakpoint
);
526 /* Reinsert all breakpoints in the child. The user may have set
527 breakpoints after catching the fork, in which case those
528 were never set in the child, but only in the parent. This makes
529 sure the inserted breakpoints match the breakpoint list. */
531 breakpoint_re_set ();
532 insert_breakpoints ();
535 /* The child has exited or execed: resume threads of the parent the
536 user wanted to be executing. */
539 proceed_after_vfork_done (struct thread_info
*thread
,
542 int pid
= * (int *) arg
;
544 if (ptid_get_pid (thread
->ptid
) == pid
545 && is_running (thread
->ptid
)
546 && !is_executing (thread
->ptid
)
547 && !thread
->stop_requested
548 && thread
->stop_signal
== TARGET_SIGNAL_0
)
551 fprintf_unfiltered (gdb_stdlog
,
552 "infrun: resuming vfork parent thread %s\n",
553 target_pid_to_str (thread
->ptid
));
555 switch_to_thread (thread
->ptid
);
556 clear_proceed_status ();
557 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
563 /* Called whenever we notice an exec or exit event, to handle
564 detaching or resuming a vfork parent. */
567 handle_vfork_child_exec_or_exit (int exec
)
569 struct inferior
*inf
= current_inferior ();
571 if (inf
->vfork_parent
)
573 int resume_parent
= -1;
575 /* This exec or exit marks the end of the shared memory region
576 between the parent and the child. If the user wanted to
577 detach from the parent, now is the time. */
579 if (inf
->vfork_parent
->pending_detach
)
581 struct thread_info
*tp
;
582 struct cleanup
*old_chain
;
583 struct program_space
*pspace
;
584 struct address_space
*aspace
;
586 /* follow-fork child, detach-on-fork on */
588 old_chain
= make_cleanup_restore_current_thread ();
590 /* We're letting loose of the parent. */
591 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
592 switch_to_thread (tp
->ptid
);
594 /* We're about to detach from the parent, which implicitly
595 removes breakpoints from its address space. There's a
596 catch here: we want to reuse the spaces for the child,
597 but, parent/child are still sharing the pspace at this
598 point, although the exec in reality makes the kernel give
599 the child a fresh set of new pages. The problem here is
600 that the breakpoints module being unaware of this, would
601 likely chose the child process to write to the parent
602 address space. Swapping the child temporarily away from
603 the spaces has the desired effect. Yes, this is "sort
606 pspace
= inf
->pspace
;
607 aspace
= inf
->aspace
;
611 if (debug_infrun
|| info_verbose
)
613 target_terminal_ours ();
616 fprintf_filtered (gdb_stdlog
,
617 "Detaching vfork parent process %d after child exec.\n",
618 inf
->vfork_parent
->pid
);
620 fprintf_filtered (gdb_stdlog
,
621 "Detaching vfork parent process %d after child exit.\n",
622 inf
->vfork_parent
->pid
);
625 target_detach (NULL
, 0);
628 inf
->pspace
= pspace
;
629 inf
->aspace
= aspace
;
631 do_cleanups (old_chain
);
635 /* We're staying attached to the parent, so, really give the
636 child a new address space. */
637 inf
->pspace
= add_program_space (maybe_new_address_space ());
638 inf
->aspace
= inf
->pspace
->aspace
;
640 set_current_program_space (inf
->pspace
);
642 resume_parent
= inf
->vfork_parent
->pid
;
644 /* Break the bonds. */
645 inf
->vfork_parent
->vfork_child
= NULL
;
649 struct cleanup
*old_chain
;
650 struct program_space
*pspace
;
652 /* If this is a vfork child exiting, then the pspace and
653 aspaces were shared with the parent. Since we're
654 reporting the process exit, we'll be mourning all that is
655 found in the address space, and switching to null_ptid,
656 preparing to start a new inferior. But, since we don't
657 want to clobber the parent's address/program spaces, we
658 go ahead and create a new one for this exiting
661 /* Switch to null_ptid, so that clone_program_space doesn't want
662 to read the selected frame of a dead process. */
663 old_chain
= save_inferior_ptid ();
664 inferior_ptid
= null_ptid
;
666 /* This inferior is dead, so avoid giving the breakpoints
667 module the option to write through to it (cloning a
668 program space resets breakpoints). */
671 pspace
= add_program_space (maybe_new_address_space ());
672 set_current_program_space (pspace
);
674 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
675 inf
->pspace
= pspace
;
676 inf
->aspace
= pspace
->aspace
;
678 /* Put back inferior_ptid. We'll continue mourning this
680 do_cleanups (old_chain
);
682 resume_parent
= inf
->vfork_parent
->pid
;
683 /* Break the bonds. */
684 inf
->vfork_parent
->vfork_child
= NULL
;
687 inf
->vfork_parent
= NULL
;
689 gdb_assert (current_program_space
== inf
->pspace
);
691 if (non_stop
&& resume_parent
!= -1)
693 /* If the user wanted the parent to be running, let it go
695 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
698 fprintf_unfiltered (gdb_stdlog
, "infrun: resuming vfork parent process %d\n",
701 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
703 do_cleanups (old_chain
);
708 /* Enum strings for "set|show displaced-stepping". */
710 static const char follow_exec_mode_new
[] = "new";
711 static const char follow_exec_mode_same
[] = "same";
712 static const char *follow_exec_mode_names
[] =
714 follow_exec_mode_new
,
715 follow_exec_mode_same
,
719 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
721 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
722 struct cmd_list_element
*c
, const char *value
)
724 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
727 /* EXECD_PATHNAME is assumed to be non-NULL. */
730 follow_exec (ptid_t pid
, char *execd_pathname
)
732 struct thread_info
*th
= inferior_thread ();
733 struct inferior
*inf
= current_inferior ();
735 /* This is an exec event that we actually wish to pay attention to.
736 Refresh our symbol table to the newly exec'd program, remove any
739 If there are breakpoints, they aren't really inserted now,
740 since the exec() transformed our inferior into a fresh set
743 We want to preserve symbolic breakpoints on the list, since
744 we have hopes that they can be reset after the new a.out's
745 symbol table is read.
747 However, any "raw" breakpoints must be removed from the list
748 (e.g., the solib bp's), since their address is probably invalid
751 And, we DON'T want to call delete_breakpoints() here, since
752 that may write the bp's "shadow contents" (the instruction
753 value that was overwritten witha TRAP instruction). Since
754 we now have a new a.out, those shadow contents aren't valid. */
756 mark_breakpoints_out ();
758 update_breakpoints_after_exec ();
760 /* If there was one, it's gone now. We cannot truly step-to-next
761 statement through an exec(). */
762 th
->step_resume_breakpoint
= NULL
;
763 th
->step_range_start
= 0;
764 th
->step_range_end
= 0;
766 /* The target reports the exec event to the main thread, even if
767 some other thread does the exec, and even if the main thread was
768 already stopped --- if debugging in non-stop mode, it's possible
769 the user had the main thread held stopped in the previous image
770 --- release it now. This is the same behavior as step-over-exec
771 with scheduler-locking on in all-stop mode. */
772 th
->stop_requested
= 0;
774 /* What is this a.out's name? */
775 printf_unfiltered (_("%s is executing new program: %s\n"),
776 target_pid_to_str (inferior_ptid
),
779 /* We've followed the inferior through an exec. Therefore, the
780 inferior has essentially been killed & reborn. */
782 gdb_flush (gdb_stdout
);
784 breakpoint_init_inferior (inf_execd
);
786 if (gdb_sysroot
&& *gdb_sysroot
)
788 char *name
= alloca (strlen (gdb_sysroot
)
789 + strlen (execd_pathname
)
792 strcpy (name
, gdb_sysroot
);
793 strcat (name
, execd_pathname
);
794 execd_pathname
= name
;
797 /* Reset the shared library package. This ensures that we get a
798 shlib event when the child reaches "_start", at which point the
799 dld will have had a chance to initialize the child. */
800 /* Also, loading a symbol file below may trigger symbol lookups, and
801 we don't want those to be satisfied by the libraries of the
802 previous incarnation of this process. */
803 no_shared_libraries (NULL
, 0);
805 if (follow_exec_mode_string
== follow_exec_mode_new
)
807 struct program_space
*pspace
;
809 /* The user wants to keep the old inferior and program spaces
810 around. Create a new fresh one, and switch to it. */
812 inf
= add_inferior (current_inferior ()->pid
);
813 pspace
= add_program_space (maybe_new_address_space ());
814 inf
->pspace
= pspace
;
815 inf
->aspace
= pspace
->aspace
;
817 exit_inferior_num_silent (current_inferior ()->num
);
819 set_current_inferior (inf
);
820 set_current_program_space (pspace
);
823 gdb_assert (current_program_space
== inf
->pspace
);
825 /* That a.out is now the one to use. */
826 exec_file_attach (execd_pathname
, 0);
828 /* Load the main file's symbols. */
829 symbol_file_add_main (execd_pathname
, 0);
831 #ifdef SOLIB_CREATE_INFERIOR_HOOK
832 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
834 solib_create_inferior_hook (0);
837 jit_inferior_created_hook ();
839 /* Reinsert all breakpoints. (Those which were symbolic have
840 been reset to the proper address in the new a.out, thanks
841 to symbol_file_command...) */
842 insert_breakpoints ();
844 /* The next resume of this inferior should bring it to the shlib
845 startup breakpoints. (If the user had also set bp's on
846 "main" from the old (parent) process, then they'll auto-
847 matically get reset there in the new process.) */
850 /* Non-zero if we just simulating a single-step. This is needed
851 because we cannot remove the breakpoints in the inferior process
852 until after the `wait' in `wait_for_inferior'. */
853 static int singlestep_breakpoints_inserted_p
= 0;
855 /* The thread we inserted single-step breakpoints for. */
856 static ptid_t singlestep_ptid
;
858 /* PC when we started this single-step. */
859 static CORE_ADDR singlestep_pc
;
861 /* If another thread hit the singlestep breakpoint, we save the original
862 thread here so that we can resume single-stepping it later. */
863 static ptid_t saved_singlestep_ptid
;
864 static int stepping_past_singlestep_breakpoint
;
866 /* If not equal to null_ptid, this means that after stepping over breakpoint
867 is finished, we need to switch to deferred_step_ptid, and step it.
869 The use case is when one thread has hit a breakpoint, and then the user
870 has switched to another thread and issued 'step'. We need to step over
871 breakpoint in the thread which hit the breakpoint, but then continue
872 stepping the thread user has selected. */
873 static ptid_t deferred_step_ptid
;
875 /* Displaced stepping. */
877 /* In non-stop debugging mode, we must take special care to manage
878 breakpoints properly; in particular, the traditional strategy for
879 stepping a thread past a breakpoint it has hit is unsuitable.
880 'Displaced stepping' is a tactic for stepping one thread past a
881 breakpoint it has hit while ensuring that other threads running
882 concurrently will hit the breakpoint as they should.
884 The traditional way to step a thread T off a breakpoint in a
885 multi-threaded program in all-stop mode is as follows:
887 a0) Initially, all threads are stopped, and breakpoints are not
889 a1) We single-step T, leaving breakpoints uninserted.
890 a2) We insert breakpoints, and resume all threads.
892 In non-stop debugging, however, this strategy is unsuitable: we
893 don't want to have to stop all threads in the system in order to
894 continue or step T past a breakpoint. Instead, we use displaced
897 n0) Initially, T is stopped, other threads are running, and
898 breakpoints are inserted.
899 n1) We copy the instruction "under" the breakpoint to a separate
900 location, outside the main code stream, making any adjustments
901 to the instruction, register, and memory state as directed by
903 n2) We single-step T over the instruction at its new location.
904 n3) We adjust the resulting register and memory state as directed
905 by T's architecture. This includes resetting T's PC to point
906 back into the main instruction stream.
909 This approach depends on the following gdbarch methods:
911 - gdbarch_max_insn_length and gdbarch_displaced_step_location
912 indicate where to copy the instruction, and how much space must
913 be reserved there. We use these in step n1.
915 - gdbarch_displaced_step_copy_insn copies a instruction to a new
916 address, and makes any necessary adjustments to the instruction,
917 register contents, and memory. We use this in step n1.
919 - gdbarch_displaced_step_fixup adjusts registers and memory after
920 we have successfuly single-stepped the instruction, to yield the
921 same effect the instruction would have had if we had executed it
922 at its original address. We use this in step n3.
924 - gdbarch_displaced_step_free_closure provides cleanup.
926 The gdbarch_displaced_step_copy_insn and
927 gdbarch_displaced_step_fixup functions must be written so that
928 copying an instruction with gdbarch_displaced_step_copy_insn,
929 single-stepping across the copied instruction, and then applying
930 gdbarch_displaced_insn_fixup should have the same effects on the
931 thread's memory and registers as stepping the instruction in place
932 would have. Exactly which responsibilities fall to the copy and
933 which fall to the fixup is up to the author of those functions.
935 See the comments in gdbarch.sh for details.
937 Note that displaced stepping and software single-step cannot
938 currently be used in combination, although with some care I think
939 they could be made to. Software single-step works by placing
940 breakpoints on all possible subsequent instructions; if the
941 displaced instruction is a PC-relative jump, those breakpoints
942 could fall in very strange places --- on pages that aren't
943 executable, or at addresses that are not proper instruction
944 boundaries. (We do generally let other threads run while we wait
945 to hit the software single-step breakpoint, and they might
946 encounter such a corrupted instruction.) One way to work around
947 this would be to have gdbarch_displaced_step_copy_insn fully
948 simulate the effect of PC-relative instructions (and return NULL)
949 on architectures that use software single-stepping.
951 In non-stop mode, we can have independent and simultaneous step
952 requests, so more than one thread may need to simultaneously step
953 over a breakpoint. The current implementation assumes there is
954 only one scratch space per process. In this case, we have to
955 serialize access to the scratch space. If thread A wants to step
956 over a breakpoint, but we are currently waiting for some other
957 thread to complete a displaced step, we leave thread A stopped and
958 place it in the displaced_step_request_queue. Whenever a displaced
959 step finishes, we pick the next thread in the queue and start a new
960 displaced step operation on it. See displaced_step_prepare and
961 displaced_step_fixup for details. */
963 struct displaced_step_request
966 struct displaced_step_request
*next
;
969 /* Per-inferior displaced stepping state. */
970 struct displaced_step_inferior_state
972 /* Pointer to next in linked list. */
973 struct displaced_step_inferior_state
*next
;
975 /* The process this displaced step state refers to. */
978 /* A queue of pending displaced stepping requests. One entry per
979 thread that needs to do a displaced step. */
980 struct displaced_step_request
*step_request_queue
;
982 /* If this is not null_ptid, this is the thread carrying out a
983 displaced single-step in process PID. This thread's state will
984 require fixing up once it has completed its step. */
987 /* The architecture the thread had when we stepped it. */
988 struct gdbarch
*step_gdbarch
;
990 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
991 for post-step cleanup. */
992 struct displaced_step_closure
*step_closure
;
994 /* The address of the original instruction, and the copy we
996 CORE_ADDR step_original
, step_copy
;
998 /* Saved contents of copy area. */
999 gdb_byte
*step_saved_copy
;
1002 /* The list of states of processes involved in displaced stepping
1004 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1006 /* Get the displaced stepping state of process PID. */
1008 static struct displaced_step_inferior_state
*
1009 get_displaced_stepping_state (int pid
)
1011 struct displaced_step_inferior_state
*state
;
1013 for (state
= displaced_step_inferior_states
;
1015 state
= state
->next
)
1016 if (state
->pid
== pid
)
1022 /* Add a new displaced stepping state for process PID to the displaced
1023 stepping state list, or return a pointer to an already existing
1024 entry, if it already exists. Never returns NULL. */
1026 static struct displaced_step_inferior_state
*
1027 add_displaced_stepping_state (int pid
)
1029 struct displaced_step_inferior_state
*state
;
1031 for (state
= displaced_step_inferior_states
;
1033 state
= state
->next
)
1034 if (state
->pid
== pid
)
1037 state
= xcalloc (1, sizeof (*state
));
1039 state
->next
= displaced_step_inferior_states
;
1040 displaced_step_inferior_states
= state
;
1045 /* Remove the displaced stepping state of process PID. */
1048 remove_displaced_stepping_state (int pid
)
1050 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1052 gdb_assert (pid
!= 0);
1054 it
= displaced_step_inferior_states
;
1055 prev_next_p
= &displaced_step_inferior_states
;
1060 *prev_next_p
= it
->next
;
1065 prev_next_p
= &it
->next
;
1071 infrun_inferior_exit (struct inferior
*inf
)
1073 remove_displaced_stepping_state (inf
->pid
);
1076 /* Enum strings for "set|show displaced-stepping". */
1078 static const char can_use_displaced_stepping_auto
[] = "auto";
1079 static const char can_use_displaced_stepping_on
[] = "on";
1080 static const char can_use_displaced_stepping_off
[] = "off";
1081 static const char *can_use_displaced_stepping_enum
[] =
1083 can_use_displaced_stepping_auto
,
1084 can_use_displaced_stepping_on
,
1085 can_use_displaced_stepping_off
,
1089 /* If ON, and the architecture supports it, GDB will use displaced
1090 stepping to step over breakpoints. If OFF, or if the architecture
1091 doesn't support it, GDB will instead use the traditional
1092 hold-and-step approach. If AUTO (which is the default), GDB will
1093 decide which technique to use to step over breakpoints depending on
1094 which of all-stop or non-stop mode is active --- displaced stepping
1095 in non-stop mode; hold-and-step in all-stop mode. */
1097 static const char *can_use_displaced_stepping
=
1098 can_use_displaced_stepping_auto
;
1101 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1102 struct cmd_list_element
*c
,
1105 if (can_use_displaced_stepping
== can_use_displaced_stepping_auto
)
1106 fprintf_filtered (file
, _("\
1107 Debugger's willingness to use displaced stepping to step over \
1108 breakpoints is %s (currently %s).\n"),
1109 value
, non_stop
? "on" : "off");
1111 fprintf_filtered (file
, _("\
1112 Debugger's willingness to use displaced stepping to step over \
1113 breakpoints is %s.\n"), value
);
1116 /* Return non-zero if displaced stepping can/should be used to step
1117 over breakpoints. */
1120 use_displaced_stepping (struct gdbarch
*gdbarch
)
1122 return (((can_use_displaced_stepping
== can_use_displaced_stepping_auto
1124 || can_use_displaced_stepping
== can_use_displaced_stepping_on
)
1125 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1126 && !RECORD_IS_USED
);
1129 /* Clean out any stray displaced stepping state. */
1131 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1133 /* Indicate that there is no cleanup pending. */
1134 displaced
->step_ptid
= null_ptid
;
1136 if (displaced
->step_closure
)
1138 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1139 displaced
->step_closure
);
1140 displaced
->step_closure
= NULL
;
1145 displaced_step_clear_cleanup (void *arg
)
1147 struct displaced_step_inferior_state
*state
= arg
;
1149 displaced_step_clear (state
);
1152 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1154 displaced_step_dump_bytes (struct ui_file
*file
,
1155 const gdb_byte
*buf
,
1160 for (i
= 0; i
< len
; i
++)
1161 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1162 fputs_unfiltered ("\n", file
);
1165 /* Prepare to single-step, using displaced stepping.
1167 Note that we cannot use displaced stepping when we have a signal to
1168 deliver. If we have a signal to deliver and an instruction to step
1169 over, then after the step, there will be no indication from the
1170 target whether the thread entered a signal handler or ignored the
1171 signal and stepped over the instruction successfully --- both cases
1172 result in a simple SIGTRAP. In the first case we mustn't do a
1173 fixup, and in the second case we must --- but we can't tell which.
1174 Comments in the code for 'random signals' in handle_inferior_event
1175 explain how we handle this case instead.
1177 Returns 1 if preparing was successful -- this thread is going to be
1178 stepped now; or 0 if displaced stepping this thread got queued. */
1180 displaced_step_prepare (ptid_t ptid
)
1182 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1183 struct regcache
*regcache
= get_thread_regcache (ptid
);
1184 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1185 CORE_ADDR original
, copy
;
1187 struct displaced_step_closure
*closure
;
1188 struct displaced_step_inferior_state
*displaced
;
1190 /* We should never reach this function if the architecture does not
1191 support displaced stepping. */
1192 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1194 /* We have to displaced step one thread at a time, as we only have
1195 access to a single scratch space per inferior. */
1197 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1199 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1201 /* Already waiting for a displaced step to finish. Defer this
1202 request and place in queue. */
1203 struct displaced_step_request
*req
, *new_req
;
1205 if (debug_displaced
)
1206 fprintf_unfiltered (gdb_stdlog
,
1207 "displaced: defering step of %s\n",
1208 target_pid_to_str (ptid
));
1210 new_req
= xmalloc (sizeof (*new_req
));
1211 new_req
->ptid
= ptid
;
1212 new_req
->next
= NULL
;
1214 if (displaced
->step_request_queue
)
1216 for (req
= displaced
->step_request_queue
;
1220 req
->next
= new_req
;
1223 displaced
->step_request_queue
= new_req
;
1229 if (debug_displaced
)
1230 fprintf_unfiltered (gdb_stdlog
,
1231 "displaced: stepping %s now\n",
1232 target_pid_to_str (ptid
));
1235 displaced_step_clear (displaced
);
1237 old_cleanups
= save_inferior_ptid ();
1238 inferior_ptid
= ptid
;
1240 original
= regcache_read_pc (regcache
);
1242 copy
= gdbarch_displaced_step_location (gdbarch
);
1243 len
= gdbarch_max_insn_length (gdbarch
);
1245 /* Save the original contents of the copy area. */
1246 displaced
->step_saved_copy
= xmalloc (len
);
1247 ignore_cleanups
= make_cleanup (free_current_contents
,
1248 &displaced
->step_saved_copy
);
1249 read_memory (copy
, displaced
->step_saved_copy
, len
);
1250 if (debug_displaced
)
1252 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1253 paddress (gdbarch
, copy
));
1254 displaced_step_dump_bytes (gdb_stdlog
,
1255 displaced
->step_saved_copy
,
1259 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1260 original
, copy
, regcache
);
1262 /* We don't support the fully-simulated case at present. */
1263 gdb_assert (closure
);
1265 /* Save the information we need to fix things up if the step
1267 displaced
->step_ptid
= ptid
;
1268 displaced
->step_gdbarch
= gdbarch
;
1269 displaced
->step_closure
= closure
;
1270 displaced
->step_original
= original
;
1271 displaced
->step_copy
= copy
;
1273 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1275 /* Resume execution at the copy. */
1276 regcache_write_pc (regcache
, copy
);
1278 discard_cleanups (ignore_cleanups
);
1280 do_cleanups (old_cleanups
);
1282 if (debug_displaced
)
1283 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1284 paddress (gdbarch
, copy
));
1290 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1292 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1294 inferior_ptid
= ptid
;
1295 write_memory (memaddr
, myaddr
, len
);
1296 do_cleanups (ptid_cleanup
);
1300 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
1302 struct cleanup
*old_cleanups
;
1303 struct displaced_step_inferior_state
*displaced
1304 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1306 /* Was any thread of this process doing a displaced step? */
1307 if (displaced
== NULL
)
1310 /* Was this event for the pid we displaced? */
1311 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1312 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1315 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1317 /* Restore the contents of the copy area. */
1319 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1321 write_memory_ptid (displaced
->step_ptid
, displaced
->step_copy
,
1322 displaced
->step_saved_copy
, len
);
1323 if (debug_displaced
)
1324 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s\n",
1325 paddress (displaced
->step_gdbarch
,
1326 displaced
->step_copy
));
1329 /* Did the instruction complete successfully? */
1330 if (signal
== TARGET_SIGNAL_TRAP
)
1332 /* Fix up the resulting state. */
1333 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1334 displaced
->step_closure
,
1335 displaced
->step_original
,
1336 displaced
->step_copy
,
1337 get_thread_regcache (displaced
->step_ptid
));
1341 /* Since the instruction didn't complete, all we can do is
1343 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1344 CORE_ADDR pc
= regcache_read_pc (regcache
);
1346 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1347 regcache_write_pc (regcache
, pc
);
1350 do_cleanups (old_cleanups
);
1352 displaced
->step_ptid
= null_ptid
;
1354 /* Are there any pending displaced stepping requests? If so, run
1355 one now. Leave the state object around, since we're likely to
1356 need it again soon. */
1357 while (displaced
->step_request_queue
)
1359 struct displaced_step_request
*head
;
1361 struct regcache
*regcache
;
1362 struct gdbarch
*gdbarch
;
1363 CORE_ADDR actual_pc
;
1364 struct address_space
*aspace
;
1366 head
= displaced
->step_request_queue
;
1368 displaced
->step_request_queue
= head
->next
;
1371 context_switch (ptid
);
1373 regcache
= get_thread_regcache (ptid
);
1374 actual_pc
= regcache_read_pc (regcache
);
1375 aspace
= get_regcache_aspace (regcache
);
1377 if (breakpoint_here_p (aspace
, actual_pc
))
1379 if (debug_displaced
)
1380 fprintf_unfiltered (gdb_stdlog
,
1381 "displaced: stepping queued %s now\n",
1382 target_pid_to_str (ptid
));
1384 displaced_step_prepare (ptid
);
1386 gdbarch
= get_regcache_arch (regcache
);
1388 if (debug_displaced
)
1390 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1393 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1394 paddress (gdbarch
, actual_pc
));
1395 read_memory (actual_pc
, buf
, sizeof (buf
));
1396 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1399 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1400 displaced
->step_closure
))
1401 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
1403 target_resume (ptid
, 0, TARGET_SIGNAL_0
);
1405 /* Done, we're stepping a thread. */
1411 struct thread_info
*tp
= inferior_thread ();
1413 /* The breakpoint we were sitting under has since been
1415 tp
->trap_expected
= 0;
1417 /* Go back to what we were trying to do. */
1418 step
= currently_stepping (tp
);
1420 if (debug_displaced
)
1421 fprintf_unfiltered (gdb_stdlog
, "breakpoint is gone %s: step(%d)\n",
1422 target_pid_to_str (tp
->ptid
), step
);
1424 target_resume (ptid
, step
, TARGET_SIGNAL_0
);
1425 tp
->stop_signal
= TARGET_SIGNAL_0
;
1427 /* This request was discarded. See if there's any other
1428 thread waiting for its turn. */
1433 /* Update global variables holding ptids to hold NEW_PTID if they were
1434 holding OLD_PTID. */
1436 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1438 struct displaced_step_request
*it
;
1439 struct displaced_step_inferior_state
*displaced
;
1441 if (ptid_equal (inferior_ptid
, old_ptid
))
1442 inferior_ptid
= new_ptid
;
1444 if (ptid_equal (singlestep_ptid
, old_ptid
))
1445 singlestep_ptid
= new_ptid
;
1447 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1448 deferred_step_ptid
= new_ptid
;
1450 for (displaced
= displaced_step_inferior_states
;
1452 displaced
= displaced
->next
)
1454 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1455 displaced
->step_ptid
= new_ptid
;
1457 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1458 if (ptid_equal (it
->ptid
, old_ptid
))
1459 it
->ptid
= new_ptid
;
1466 /* Things to clean up if we QUIT out of resume (). */
1468 resume_cleanups (void *ignore
)
1473 static const char schedlock_off
[] = "off";
1474 static const char schedlock_on
[] = "on";
1475 static const char schedlock_step
[] = "step";
1476 static const char *scheduler_enums
[] = {
1482 static const char *scheduler_mode
= schedlock_off
;
1484 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1485 struct cmd_list_element
*c
, const char *value
)
1487 fprintf_filtered (file
, _("\
1488 Mode for locking scheduler during execution is \"%s\".\n"),
1493 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1495 if (!target_can_lock_scheduler
)
1497 scheduler_mode
= schedlock_off
;
1498 error (_("Target '%s' cannot support this command."), target_shortname
);
1502 /* True if execution commands resume all threads of all processes by
1503 default; otherwise, resume only threads of the current inferior
1505 int sched_multi
= 0;
1507 /* Try to setup for software single stepping over the specified location.
1508 Return 1 if target_resume() should use hardware single step.
1510 GDBARCH the current gdbarch.
1511 PC the location to step over. */
1514 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1518 if (gdbarch_software_single_step_p (gdbarch
)
1519 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1522 /* Do not pull these breakpoints until after a `wait' in
1523 `wait_for_inferior' */
1524 singlestep_breakpoints_inserted_p
= 1;
1525 singlestep_ptid
= inferior_ptid
;
1531 /* Resume the inferior, but allow a QUIT. This is useful if the user
1532 wants to interrupt some lengthy single-stepping operation
1533 (for child processes, the SIGINT goes to the inferior, and so
1534 we get a SIGINT random_signal, but for remote debugging and perhaps
1535 other targets, that's not true).
1537 STEP nonzero if we should step (zero to continue instead).
1538 SIG is the signal to give the inferior (zero for none). */
1540 resume (int step
, enum target_signal sig
)
1542 int should_resume
= 1;
1543 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1544 struct regcache
*regcache
= get_current_regcache ();
1545 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1546 struct thread_info
*tp
= inferior_thread ();
1547 CORE_ADDR pc
= regcache_read_pc (regcache
);
1548 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1553 fprintf_unfiltered (gdb_stdlog
,
1554 "infrun: resume (step=%d, signal=%d), "
1555 "trap_expected=%d\n",
1556 step
, sig
, tp
->trap_expected
);
1558 /* Normally, by the time we reach `resume', the breakpoints are either
1559 removed or inserted, as appropriate. The exception is if we're sitting
1560 at a permanent breakpoint; we need to step over it, but permanent
1561 breakpoints can't be removed. So we have to test for it here. */
1562 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1564 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1565 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1568 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1569 how to step past a permanent breakpoint on this architecture. Try using\n\
1570 a command like `return' or `jump' to continue execution."));
1573 /* If enabled, step over breakpoints by executing a copy of the
1574 instruction at a different address.
1576 We can't use displaced stepping when we have a signal to deliver;
1577 the comments for displaced_step_prepare explain why. The
1578 comments in the handle_inferior event for dealing with 'random
1579 signals' explain what we do instead. */
1580 if (use_displaced_stepping (gdbarch
)
1581 && (tp
->trap_expected
1582 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1583 && sig
== TARGET_SIGNAL_0
)
1585 struct displaced_step_inferior_state
*displaced
;
1587 if (!displaced_step_prepare (inferior_ptid
))
1589 /* Got placed in displaced stepping queue. Will be resumed
1590 later when all the currently queued displaced stepping
1591 requests finish. The thread is not executing at this point,
1592 and the call to set_executing will be made later. But we
1593 need to call set_running here, since from frontend point of view,
1594 the thread is running. */
1595 set_running (inferior_ptid
, 1);
1596 discard_cleanups (old_cleanups
);
1600 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1601 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1602 displaced
->step_closure
);
1605 /* Do we need to do it the hard way, w/temp breakpoints? */
1607 step
= maybe_software_singlestep (gdbarch
, pc
);
1613 /* If STEP is set, it's a request to use hardware stepping
1614 facilities. But in that case, we should never
1615 use singlestep breakpoint. */
1616 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1618 /* Decide the set of threads to ask the target to resume. Start
1619 by assuming everything will be resumed, than narrow the set
1620 by applying increasingly restricting conditions. */
1622 /* By default, resume all threads of all processes. */
1623 resume_ptid
= RESUME_ALL
;
1625 /* Maybe resume only all threads of the current process. */
1626 if (!sched_multi
&& target_supports_multi_process ())
1628 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1631 /* Maybe resume a single thread after all. */
1632 if (singlestep_breakpoints_inserted_p
1633 && stepping_past_singlestep_breakpoint
)
1635 /* The situation here is as follows. In thread T1 we wanted to
1636 single-step. Lacking hardware single-stepping we've
1637 set breakpoint at the PC of the next instruction -- call it
1638 P. After resuming, we've hit that breakpoint in thread T2.
1639 Now we've removed original breakpoint, inserted breakpoint
1640 at P+1, and try to step to advance T2 past breakpoint.
1641 We need to step only T2, as if T1 is allowed to freely run,
1642 it can run past P, and if other threads are allowed to run,
1643 they can hit breakpoint at P+1, and nested hits of single-step
1644 breakpoints is not something we'd want -- that's complicated
1645 to support, and has no value. */
1646 resume_ptid
= inferior_ptid
;
1648 else if ((step
|| singlestep_breakpoints_inserted_p
)
1649 && tp
->trap_expected
)
1651 /* We're allowing a thread to run past a breakpoint it has
1652 hit, by single-stepping the thread with the breakpoint
1653 removed. In which case, we need to single-step only this
1654 thread, and keep others stopped, as they can miss this
1655 breakpoint if allowed to run.
1657 The current code actually removes all breakpoints when
1658 doing this, not just the one being stepped over, so if we
1659 let other threads run, we can actually miss any
1660 breakpoint, not just the one at PC. */
1661 resume_ptid
= inferior_ptid
;
1665 /* With non-stop mode on, threads are always handled
1667 resume_ptid
= inferior_ptid
;
1669 else if ((scheduler_mode
== schedlock_on
)
1670 || (scheduler_mode
== schedlock_step
1671 && (step
|| singlestep_breakpoints_inserted_p
)))
1673 /* User-settable 'scheduler' mode requires solo thread resume. */
1674 resume_ptid
= inferior_ptid
;
1677 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1679 /* Most targets can step a breakpoint instruction, thus
1680 executing it normally. But if this one cannot, just
1681 continue and we will hit it anyway. */
1682 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1687 && use_displaced_stepping (gdbarch
)
1688 && tp
->trap_expected
)
1690 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1691 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1692 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1695 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1696 paddress (resume_gdbarch
, actual_pc
));
1697 read_memory (actual_pc
, buf
, sizeof (buf
));
1698 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1701 /* Install inferior's terminal modes. */
1702 target_terminal_inferior ();
1704 /* Avoid confusing the next resume, if the next stop/resume
1705 happens to apply to another thread. */
1706 tp
->stop_signal
= TARGET_SIGNAL_0
;
1708 target_resume (resume_ptid
, step
, sig
);
1711 discard_cleanups (old_cleanups
);
1716 /* Clear out all variables saying what to do when inferior is continued.
1717 First do this, then set the ones you want, then call `proceed'. */
1720 clear_proceed_status_thread (struct thread_info
*tp
)
1723 fprintf_unfiltered (gdb_stdlog
,
1724 "infrun: clear_proceed_status_thread (%s)\n",
1725 target_pid_to_str (tp
->ptid
));
1727 tp
->trap_expected
= 0;
1728 tp
->step_range_start
= 0;
1729 tp
->step_range_end
= 0;
1730 tp
->step_frame_id
= null_frame_id
;
1731 tp
->step_stack_frame_id
= null_frame_id
;
1732 tp
->step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1733 tp
->stop_requested
= 0;
1737 tp
->proceed_to_finish
= 0;
1739 /* Discard any remaining commands or status from previous stop. */
1740 bpstat_clear (&tp
->stop_bpstat
);
1744 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
1746 if (is_exited (tp
->ptid
))
1749 clear_proceed_status_thread (tp
);
1754 clear_proceed_status (void)
1758 /* In all-stop mode, delete the per-thread status of all
1759 threads, even if inferior_ptid is null_ptid, there may be
1760 threads on the list. E.g., we may be launching a new
1761 process, while selecting the executable. */
1762 iterate_over_threads (clear_proceed_status_callback
, NULL
);
1765 if (!ptid_equal (inferior_ptid
, null_ptid
))
1767 struct inferior
*inferior
;
1771 /* If in non-stop mode, only delete the per-thread status of
1772 the current thread. */
1773 clear_proceed_status_thread (inferior_thread ());
1776 inferior
= current_inferior ();
1777 inferior
->stop_soon
= NO_STOP_QUIETLY
;
1780 stop_after_trap
= 0;
1782 observer_notify_about_to_proceed ();
1786 regcache_xfree (stop_registers
);
1787 stop_registers
= NULL
;
1791 /* Check the current thread against the thread that reported the most recent
1792 event. If a step-over is required return TRUE and set the current thread
1793 to the old thread. Otherwise return FALSE.
1795 This should be suitable for any targets that support threads. */
1798 prepare_to_proceed (int step
)
1801 struct target_waitstatus wait_status
;
1802 int schedlock_enabled
;
1804 /* With non-stop mode on, threads are always handled individually. */
1805 gdb_assert (! non_stop
);
1807 /* Get the last target status returned by target_wait(). */
1808 get_last_target_status (&wait_ptid
, &wait_status
);
1810 /* Make sure we were stopped at a breakpoint. */
1811 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1812 || (wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
1813 && wait_status
.value
.sig
!= TARGET_SIGNAL_ILL
1814 && wait_status
.value
.sig
!= TARGET_SIGNAL_SEGV
1815 && wait_status
.value
.sig
!= TARGET_SIGNAL_EMT
))
1820 schedlock_enabled
= (scheduler_mode
== schedlock_on
1821 || (scheduler_mode
== schedlock_step
1824 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1825 if (schedlock_enabled
)
1828 /* Don't switch over if we're about to resume some other process
1829 other than WAIT_PTID's, and schedule-multiple is off. */
1831 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
1834 /* Switched over from WAIT_PID. */
1835 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1836 && !ptid_equal (inferior_ptid
, wait_ptid
))
1838 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1840 if (breakpoint_here_p (get_regcache_aspace (regcache
),
1841 regcache_read_pc (regcache
)))
1843 /* If stepping, remember current thread to switch back to. */
1845 deferred_step_ptid
= inferior_ptid
;
1847 /* Switch back to WAIT_PID thread. */
1848 switch_to_thread (wait_ptid
);
1850 /* We return 1 to indicate that there is a breakpoint here,
1851 so we need to step over it before continuing to avoid
1852 hitting it straight away. */
1860 /* Basic routine for continuing the program in various fashions.
1862 ADDR is the address to resume at, or -1 for resume where stopped.
1863 SIGGNAL is the signal to give it, or 0 for none,
1864 or -1 for act according to how it stopped.
1865 STEP is nonzero if should trap after one instruction.
1866 -1 means return after that and print nothing.
1867 You should probably set various step_... variables
1868 before calling here, if you are stepping.
1870 You should call clear_proceed_status before calling proceed. */
1873 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1875 struct regcache
*regcache
;
1876 struct gdbarch
*gdbarch
;
1877 struct thread_info
*tp
;
1879 struct address_space
*aspace
;
1882 /* If we're stopped at a fork/vfork, follow the branch set by the
1883 "set follow-fork-mode" command; otherwise, we'll just proceed
1884 resuming the current thread. */
1885 if (!follow_fork ())
1887 /* The target for some reason decided not to resume. */
1892 regcache
= get_current_regcache ();
1893 gdbarch
= get_regcache_arch (regcache
);
1894 aspace
= get_regcache_aspace (regcache
);
1895 pc
= regcache_read_pc (regcache
);
1898 step_start_function
= find_pc_function (pc
);
1900 stop_after_trap
= 1;
1902 if (addr
== (CORE_ADDR
) -1)
1904 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
1905 && execution_direction
!= EXEC_REVERSE
)
1906 /* There is a breakpoint at the address we will resume at,
1907 step one instruction before inserting breakpoints so that
1908 we do not stop right away (and report a second hit at this
1911 Note, we don't do this in reverse, because we won't
1912 actually be executing the breakpoint insn anyway.
1913 We'll be (un-)executing the previous instruction. */
1916 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1917 && gdbarch_single_step_through_delay (gdbarch
,
1918 get_current_frame ()))
1919 /* We stepped onto an instruction that needs to be stepped
1920 again before re-inserting the breakpoint, do so. */
1925 regcache_write_pc (regcache
, addr
);
1929 fprintf_unfiltered (gdb_stdlog
,
1930 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
1931 paddress (gdbarch
, addr
), siggnal
, step
);
1933 /* We're handling a live event, so make sure we're doing live
1934 debugging. If we're looking at traceframes while the target is
1935 running, we're going to need to get back to that mode after
1936 handling the event. */
1939 make_cleanup_restore_current_traceframe ();
1940 set_traceframe_number (-1);
1944 /* In non-stop, each thread is handled individually. The context
1945 must already be set to the right thread here. */
1949 /* In a multi-threaded task we may select another thread and
1950 then continue or step.
1952 But if the old thread was stopped at a breakpoint, it will
1953 immediately cause another breakpoint stop without any
1954 execution (i.e. it will report a breakpoint hit incorrectly).
1955 So we must step over it first.
1957 prepare_to_proceed checks the current thread against the
1958 thread that reported the most recent event. If a step-over
1959 is required it returns TRUE and sets the current thread to
1961 if (prepare_to_proceed (step
))
1965 /* prepare_to_proceed may change the current thread. */
1966 tp
= inferior_thread ();
1970 tp
->trap_expected
= 1;
1971 /* If displaced stepping is enabled, we can step over the
1972 breakpoint without hitting it, so leave all breakpoints
1973 inserted. Otherwise we need to disable all breakpoints, step
1974 one instruction, and then re-add them when that step is
1976 if (!use_displaced_stepping (gdbarch
))
1977 remove_breakpoints ();
1980 /* We can insert breakpoints if we're not trying to step over one,
1981 or if we are stepping over one but we're using displaced stepping
1983 if (! tp
->trap_expected
|| use_displaced_stepping (gdbarch
))
1984 insert_breakpoints ();
1988 /* Pass the last stop signal to the thread we're resuming,
1989 irrespective of whether the current thread is the thread that
1990 got the last event or not. This was historically GDB's
1991 behaviour before keeping a stop_signal per thread. */
1993 struct thread_info
*last_thread
;
1995 struct target_waitstatus last_status
;
1997 get_last_target_status (&last_ptid
, &last_status
);
1998 if (!ptid_equal (inferior_ptid
, last_ptid
)
1999 && !ptid_equal (last_ptid
, null_ptid
)
2000 && !ptid_equal (last_ptid
, minus_one_ptid
))
2002 last_thread
= find_thread_ptid (last_ptid
);
2005 tp
->stop_signal
= last_thread
->stop_signal
;
2006 last_thread
->stop_signal
= TARGET_SIGNAL_0
;
2011 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
2012 tp
->stop_signal
= siggnal
;
2013 /* If this signal should not be seen by program,
2014 give it zero. Used for debugging signals. */
2015 else if (!signal_program
[tp
->stop_signal
])
2016 tp
->stop_signal
= TARGET_SIGNAL_0
;
2018 annotate_starting ();
2020 /* Make sure that output from GDB appears before output from the
2022 gdb_flush (gdb_stdout
);
2024 /* Refresh prev_pc value just prior to resuming. This used to be
2025 done in stop_stepping, however, setting prev_pc there did not handle
2026 scenarios such as inferior function calls or returning from
2027 a function via the return command. In those cases, the prev_pc
2028 value was not set properly for subsequent commands. The prev_pc value
2029 is used to initialize the starting line number in the ecs. With an
2030 invalid value, the gdb next command ends up stopping at the position
2031 represented by the next line table entry past our start position.
2032 On platforms that generate one line table entry per line, this
2033 is not a problem. However, on the ia64, the compiler generates
2034 extraneous line table entries that do not increase the line number.
2035 When we issue the gdb next command on the ia64 after an inferior call
2036 or a return command, we often end up a few instructions forward, still
2037 within the original line we started.
2039 An attempt was made to refresh the prev_pc at the same time the
2040 execution_control_state is initialized (for instance, just before
2041 waiting for an inferior event). But this approach did not work
2042 because of platforms that use ptrace, where the pc register cannot
2043 be read unless the inferior is stopped. At that point, we are not
2044 guaranteed the inferior is stopped and so the regcache_read_pc() call
2045 can fail. Setting the prev_pc value here ensures the value is updated
2046 correctly when the inferior is stopped. */
2047 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2049 /* Fill in with reasonable starting values. */
2050 init_thread_stepping_state (tp
);
2052 /* Reset to normal state. */
2053 init_infwait_state ();
2055 /* Resume inferior. */
2056 resume (oneproc
|| step
|| bpstat_should_step (), tp
->stop_signal
);
2058 /* Wait for it to stop (if not standalone)
2059 and in any case decode why it stopped, and act accordingly. */
2060 /* Do this only if we are not using the event loop, or if the target
2061 does not support asynchronous execution. */
2062 if (!target_can_async_p ())
2064 wait_for_inferior (0);
2070 /* Start remote-debugging of a machine over a serial link. */
2073 start_remote (int from_tty
)
2075 struct inferior
*inferior
;
2077 init_wait_for_inferior ();
2078 inferior
= current_inferior ();
2079 inferior
->stop_soon
= STOP_QUIETLY_REMOTE
;
2081 /* Always go on waiting for the target, regardless of the mode. */
2082 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2083 indicate to wait_for_inferior that a target should timeout if
2084 nothing is returned (instead of just blocking). Because of this,
2085 targets expecting an immediate response need to, internally, set
2086 things up so that the target_wait() is forced to eventually
2088 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2089 differentiate to its caller what the state of the target is after
2090 the initial open has been performed. Here we're assuming that
2091 the target has stopped. It should be possible to eventually have
2092 target_open() return to the caller an indication that the target
2093 is currently running and GDB state should be set to the same as
2094 for an async run. */
2095 wait_for_inferior (0);
2097 /* Now that the inferior has stopped, do any bookkeeping like
2098 loading shared libraries. We want to do this before normal_stop,
2099 so that the displayed frame is up to date. */
2100 post_create_inferior (¤t_target
, from_tty
);
2105 /* Initialize static vars when a new inferior begins. */
2108 init_wait_for_inferior (void)
2110 /* These are meaningless until the first time through wait_for_inferior. */
2112 breakpoint_init_inferior (inf_starting
);
2114 clear_proceed_status ();
2116 stepping_past_singlestep_breakpoint
= 0;
2117 deferred_step_ptid
= null_ptid
;
2119 target_last_wait_ptid
= minus_one_ptid
;
2121 previous_inferior_ptid
= null_ptid
;
2122 init_infwait_state ();
2124 /* Discard any skipped inlined frames. */
2125 clear_inline_frame_state (minus_one_ptid
);
2129 /* This enum encodes possible reasons for doing a target_wait, so that
2130 wfi can call target_wait in one place. (Ultimately the call will be
2131 moved out of the infinite loop entirely.) */
2135 infwait_normal_state
,
2136 infwait_thread_hop_state
,
2137 infwait_step_watch_state
,
2138 infwait_nonstep_watch_state
2141 /* Why did the inferior stop? Used to print the appropriate messages
2142 to the interface from within handle_inferior_event(). */
2143 enum inferior_stop_reason
2145 /* Step, next, nexti, stepi finished. */
2147 /* Inferior terminated by signal. */
2149 /* Inferior exited. */
2151 /* Inferior received signal, and user asked to be notified. */
2153 /* Reverse execution -- target ran out of history info. */
2157 /* The PTID we'll do a target_wait on.*/
2160 /* Current inferior wait state. */
2161 enum infwait_states infwait_state
;
2163 /* Data to be passed around while handling an event. This data is
2164 discarded between events. */
2165 struct execution_control_state
2168 /* The thread that got the event, if this was a thread event; NULL
2170 struct thread_info
*event_thread
;
2172 struct target_waitstatus ws
;
2174 CORE_ADDR stop_func_start
;
2175 CORE_ADDR stop_func_end
;
2176 char *stop_func_name
;
2177 int new_thread_event
;
2181 static void handle_inferior_event (struct execution_control_state
*ecs
);
2183 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2184 struct execution_control_state
*ecs
);
2185 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2186 struct execution_control_state
*ecs
);
2187 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
2188 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
2189 static void insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
2190 struct symtab_and_line sr_sal
,
2191 struct frame_id sr_id
);
2192 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
2194 static void stop_stepping (struct execution_control_state
*ecs
);
2195 static void prepare_to_wait (struct execution_control_state
*ecs
);
2196 static void keep_going (struct execution_control_state
*ecs
);
2197 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
2200 /* Callback for iterate over threads. If the thread is stopped, but
2201 the user/frontend doesn't know about that yet, go through
2202 normal_stop, as if the thread had just stopped now. ARG points at
2203 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2204 ptid_is_pid(PTID) is true, applies to all threads of the process
2205 pointed at by PTID. Otherwise, apply only to the thread pointed by
2209 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2211 ptid_t ptid
= * (ptid_t
*) arg
;
2213 if ((ptid_equal (info
->ptid
, ptid
)
2214 || ptid_equal (minus_one_ptid
, ptid
)
2215 || (ptid_is_pid (ptid
)
2216 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2217 && is_running (info
->ptid
)
2218 && !is_executing (info
->ptid
))
2220 struct cleanup
*old_chain
;
2221 struct execution_control_state ecss
;
2222 struct execution_control_state
*ecs
= &ecss
;
2224 memset (ecs
, 0, sizeof (*ecs
));
2226 old_chain
= make_cleanup_restore_current_thread ();
2228 switch_to_thread (info
->ptid
);
2230 /* Go through handle_inferior_event/normal_stop, so we always
2231 have consistent output as if the stop event had been
2233 ecs
->ptid
= info
->ptid
;
2234 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2235 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2236 ecs
->ws
.value
.sig
= TARGET_SIGNAL_0
;
2238 handle_inferior_event (ecs
);
2240 if (!ecs
->wait_some_more
)
2242 struct thread_info
*tp
;
2246 /* Finish off the continuations. The continations
2247 themselves are responsible for realising the thread
2248 didn't finish what it was supposed to do. */
2249 tp
= inferior_thread ();
2250 do_all_intermediate_continuations_thread (tp
);
2251 do_all_continuations_thread (tp
);
2254 do_cleanups (old_chain
);
2260 /* This function is attached as a "thread_stop_requested" observer.
2261 Cleanup local state that assumed the PTID was to be resumed, and
2262 report the stop to the frontend. */
2265 infrun_thread_stop_requested (ptid_t ptid
)
2267 struct displaced_step_inferior_state
*displaced
;
2269 /* PTID was requested to stop. Remove it from the displaced
2270 stepping queue, so we don't try to resume it automatically. */
2272 for (displaced
= displaced_step_inferior_states
;
2274 displaced
= displaced
->next
)
2276 struct displaced_step_request
*it
, **prev_next_p
;
2278 it
= displaced
->step_request_queue
;
2279 prev_next_p
= &displaced
->step_request_queue
;
2282 if (ptid_match (it
->ptid
, ptid
))
2284 *prev_next_p
= it
->next
;
2290 prev_next_p
= &it
->next
;
2297 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2301 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2303 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2304 nullify_last_target_wait_ptid ();
2307 /* Callback for iterate_over_threads. */
2310 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2312 if (is_exited (info
->ptid
))
2315 delete_step_resume_breakpoint (info
);
2319 /* In all-stop, delete the step resume breakpoint of any thread that
2320 had one. In non-stop, delete the step resume breakpoint of the
2321 thread that just stopped. */
2324 delete_step_thread_step_resume_breakpoint (void)
2326 if (!target_has_execution
2327 || ptid_equal (inferior_ptid
, null_ptid
))
2328 /* If the inferior has exited, we have already deleted the step
2329 resume breakpoints out of GDB's lists. */
2334 /* If in non-stop mode, only delete the step-resume or
2335 longjmp-resume breakpoint of the thread that just stopped
2337 struct thread_info
*tp
= inferior_thread ();
2339 delete_step_resume_breakpoint (tp
);
2342 /* In all-stop mode, delete all step-resume and longjmp-resume
2343 breakpoints of any thread that had them. */
2344 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2347 /* A cleanup wrapper. */
2350 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2352 delete_step_thread_step_resume_breakpoint ();
2355 /* Pretty print the results of target_wait, for debugging purposes. */
2358 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2359 const struct target_waitstatus
*ws
)
2361 char *status_string
= target_waitstatus_to_string (ws
);
2362 struct ui_file
*tmp_stream
= mem_fileopen ();
2365 /* The text is split over several lines because it was getting too long.
2366 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2367 output as a unit; we want only one timestamp printed if debug_timestamp
2370 fprintf_unfiltered (tmp_stream
,
2371 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
2372 if (PIDGET (waiton_ptid
) != -1)
2373 fprintf_unfiltered (tmp_stream
,
2374 " [%s]", target_pid_to_str (waiton_ptid
));
2375 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2376 fprintf_unfiltered (tmp_stream
,
2377 "infrun: %d [%s],\n",
2378 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
2379 fprintf_unfiltered (tmp_stream
,
2383 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2385 /* This uses %s in part to handle %'s in the text, but also to avoid
2386 a gcc error: the format attribute requires a string literal. */
2387 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2389 xfree (status_string
);
2391 ui_file_delete (tmp_stream
);
2394 /* Prepare and stabilize the inferior for detaching it. E.g.,
2395 detaching while a thread is displaced stepping is a recipe for
2396 crashing it, as nothing would readjust the PC out of the scratch
2400 prepare_for_detach (void)
2402 struct inferior
*inf
= current_inferior ();
2403 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2404 struct cleanup
*old_chain_1
;
2405 struct displaced_step_inferior_state
*displaced
;
2407 displaced
= get_displaced_stepping_state (inf
->pid
);
2409 /* Is any thread of this process displaced stepping? If not,
2410 there's nothing else to do. */
2411 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2415 fprintf_unfiltered (gdb_stdlog
,
2416 "displaced-stepping in-process while detaching");
2418 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2421 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2423 struct cleanup
*old_chain_2
;
2424 struct execution_control_state ecss
;
2425 struct execution_control_state
*ecs
;
2428 memset (ecs
, 0, sizeof (*ecs
));
2430 overlay_cache_invalid
= 1;
2432 /* We have to invalidate the registers BEFORE calling
2433 target_wait because they can be loaded from the target while
2434 in target_wait. This makes remote debugging a bit more
2435 efficient for those targets that provide critical registers
2436 as part of their normal status mechanism. */
2438 registers_changed ();
2440 if (deprecated_target_wait_hook
)
2441 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2443 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2446 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2448 /* If an error happens while handling the event, propagate GDB's
2449 knowledge of the executing state to the frontend/user running
2451 old_chain_2
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2453 /* In non-stop mode, each thread is handled individually.
2454 Switch early, so the global state is set correctly for this
2457 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2458 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2459 context_switch (ecs
->ptid
);
2461 /* Now figure out what to do with the result of the result. */
2462 handle_inferior_event (ecs
);
2464 /* No error, don't finish the state yet. */
2465 discard_cleanups (old_chain_2
);
2467 /* Breakpoints and watchpoints are not installed on the target
2468 at this point, and signals are passed directly to the
2469 inferior, so this must mean the process is gone. */
2470 if (!ecs
->wait_some_more
)
2472 discard_cleanups (old_chain_1
);
2473 error (_("Program exited while detaching"));
2477 discard_cleanups (old_chain_1
);
2480 /* Wait for control to return from inferior to debugger.
2482 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
2483 as if they were SIGTRAP signals. This can be useful during
2484 the startup sequence on some targets such as HP/UX, where
2485 we receive an EXEC event instead of the expected SIGTRAP.
2487 If inferior gets a signal, we may decide to start it up again
2488 instead of returning. That is why there is a loop in this function.
2489 When this function actually returns it means the inferior
2490 should be left stopped and GDB should read more commands. */
2493 wait_for_inferior (int treat_exec_as_sigtrap
)
2495 struct cleanup
*old_cleanups
;
2496 struct execution_control_state ecss
;
2497 struct execution_control_state
*ecs
;
2501 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
2502 treat_exec_as_sigtrap
);
2505 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2508 memset (ecs
, 0, sizeof (*ecs
));
2510 /* We'll update this if & when we switch to a new thread. */
2511 previous_inferior_ptid
= inferior_ptid
;
2515 struct cleanup
*old_chain
;
2517 /* We have to invalidate the registers BEFORE calling target_wait
2518 because they can be loaded from the target while in target_wait.
2519 This makes remote debugging a bit more efficient for those
2520 targets that provide critical registers as part of their normal
2521 status mechanism. */
2523 overlay_cache_invalid
= 1;
2524 registers_changed ();
2526 if (deprecated_target_wait_hook
)
2527 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2529 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2532 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2534 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2536 xfree (ecs
->ws
.value
.execd_pathname
);
2537 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2538 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
2541 /* If an error happens while handling the event, propagate GDB's
2542 knowledge of the executing state to the frontend/user running
2544 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2546 if (ecs
->ws
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
2547 || ecs
->ws
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
2548 ecs
->ws
.value
.syscall_number
= UNKNOWN_SYSCALL
;
2550 /* Now figure out what to do with the result of the result. */
2551 handle_inferior_event (ecs
);
2553 /* No error, don't finish the state yet. */
2554 discard_cleanups (old_chain
);
2556 if (!ecs
->wait_some_more
)
2560 do_cleanups (old_cleanups
);
2563 /* Asynchronous version of wait_for_inferior. It is called by the
2564 event loop whenever a change of state is detected on the file
2565 descriptor corresponding to the target. It can be called more than
2566 once to complete a single execution command. In such cases we need
2567 to keep the state in a global variable ECSS. If it is the last time
2568 that this function is called for a single execution command, then
2569 report to the user that the inferior has stopped, and do the
2570 necessary cleanups. */
2573 fetch_inferior_event (void *client_data
)
2575 struct execution_control_state ecss
;
2576 struct execution_control_state
*ecs
= &ecss
;
2577 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2578 struct cleanup
*ts_old_chain
;
2579 int was_sync
= sync_execution
;
2581 memset (ecs
, 0, sizeof (*ecs
));
2583 /* We'll update this if & when we switch to a new thread. */
2584 previous_inferior_ptid
= inferior_ptid
;
2587 /* In non-stop mode, the user/frontend should not notice a thread
2588 switch due to internal events. Make sure we reverse to the
2589 user selected thread and frame after handling the event and
2590 running any breakpoint commands. */
2591 make_cleanup_restore_current_thread ();
2593 /* We have to invalidate the registers BEFORE calling target_wait
2594 because they can be loaded from the target while in target_wait.
2595 This makes remote debugging a bit more efficient for those
2596 targets that provide critical registers as part of their normal
2597 status mechanism. */
2599 overlay_cache_invalid
= 1;
2600 registers_changed ();
2602 if (deprecated_target_wait_hook
)
2604 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2606 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2609 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2612 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
2613 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2614 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2615 /* In non-stop mode, each thread is handled individually. Switch
2616 early, so the global state is set correctly for this
2618 context_switch (ecs
->ptid
);
2620 /* If an error happens while handling the event, propagate GDB's
2621 knowledge of the executing state to the frontend/user running
2624 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2626 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2628 /* Now figure out what to do with the result of the result. */
2629 handle_inferior_event (ecs
);
2631 if (!ecs
->wait_some_more
)
2633 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2635 delete_step_thread_step_resume_breakpoint ();
2637 /* We may not find an inferior if this was a process exit. */
2638 if (inf
== NULL
|| inf
->stop_soon
== NO_STOP_QUIETLY
)
2641 if (target_has_execution
2642 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2643 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2644 && ecs
->event_thread
->step_multi
2645 && ecs
->event_thread
->stop_step
)
2646 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2648 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2651 /* No error, don't finish the thread states yet. */
2652 discard_cleanups (ts_old_chain
);
2654 /* Revert thread and frame. */
2655 do_cleanups (old_chain
);
2657 /* If the inferior was in sync execution mode, and now isn't,
2658 restore the prompt. */
2659 if (was_sync
&& !sync_execution
)
2660 display_gdb_prompt (0);
2663 /* Record the frame and location we're currently stepping through. */
2665 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2667 struct thread_info
*tp
= inferior_thread ();
2669 tp
->step_frame_id
= get_frame_id (frame
);
2670 tp
->step_stack_frame_id
= get_stack_frame_id (frame
);
2672 tp
->current_symtab
= sal
.symtab
;
2673 tp
->current_line
= sal
.line
;
2676 /* Clear context switchable stepping state. */
2679 init_thread_stepping_state (struct thread_info
*tss
)
2681 tss
->stepping_over_breakpoint
= 0;
2682 tss
->step_after_step_resume_breakpoint
= 0;
2683 tss
->stepping_through_solib_after_catch
= 0;
2684 tss
->stepping_through_solib_catchpoints
= NULL
;
2687 /* Return the cached copy of the last pid/waitstatus returned by
2688 target_wait()/deprecated_target_wait_hook(). The data is actually
2689 cached by handle_inferior_event(), which gets called immediately
2690 after target_wait()/deprecated_target_wait_hook(). */
2693 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2695 *ptidp
= target_last_wait_ptid
;
2696 *status
= target_last_waitstatus
;
2700 nullify_last_target_wait_ptid (void)
2702 target_last_wait_ptid
= minus_one_ptid
;
2705 /* Switch thread contexts. */
2708 context_switch (ptid_t ptid
)
2712 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2713 target_pid_to_str (inferior_ptid
));
2714 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2715 target_pid_to_str (ptid
));
2718 switch_to_thread (ptid
);
2722 adjust_pc_after_break (struct execution_control_state
*ecs
)
2724 struct regcache
*regcache
;
2725 struct gdbarch
*gdbarch
;
2726 struct address_space
*aspace
;
2727 CORE_ADDR breakpoint_pc
;
2729 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2730 we aren't, just return.
2732 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2733 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2734 implemented by software breakpoints should be handled through the normal
2737 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2738 different signals (SIGILL or SIGEMT for instance), but it is less
2739 clear where the PC is pointing afterwards. It may not match
2740 gdbarch_decr_pc_after_break. I don't know any specific target that
2741 generates these signals at breakpoints (the code has been in GDB since at
2742 least 1992) so I can not guess how to handle them here.
2744 In earlier versions of GDB, a target with
2745 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2746 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2747 target with both of these set in GDB history, and it seems unlikely to be
2748 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2750 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2753 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
2756 /* In reverse execution, when a breakpoint is hit, the instruction
2757 under it has already been de-executed. The reported PC always
2758 points at the breakpoint address, so adjusting it further would
2759 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2762 B1 0x08000000 : INSN1
2763 B2 0x08000001 : INSN2
2765 PC -> 0x08000003 : INSN4
2767 Say you're stopped at 0x08000003 as above. Reverse continuing
2768 from that point should hit B2 as below. Reading the PC when the
2769 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2770 been de-executed already.
2772 B1 0x08000000 : INSN1
2773 B2 PC -> 0x08000001 : INSN2
2777 We can't apply the same logic as for forward execution, because
2778 we would wrongly adjust the PC to 0x08000000, since there's a
2779 breakpoint at PC - 1. We'd then report a hit on B1, although
2780 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2782 if (execution_direction
== EXEC_REVERSE
)
2785 /* If this target does not decrement the PC after breakpoints, then
2786 we have nothing to do. */
2787 regcache
= get_thread_regcache (ecs
->ptid
);
2788 gdbarch
= get_regcache_arch (regcache
);
2789 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2792 aspace
= get_regcache_aspace (regcache
);
2794 /* Find the location where (if we've hit a breakpoint) the
2795 breakpoint would be. */
2796 breakpoint_pc
= regcache_read_pc (regcache
)
2797 - gdbarch_decr_pc_after_break (gdbarch
);
2799 /* Check whether there actually is a software breakpoint inserted at
2802 If in non-stop mode, a race condition is possible where we've
2803 removed a breakpoint, but stop events for that breakpoint were
2804 already queued and arrive later. To suppress those spurious
2805 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2806 and retire them after a number of stop events are reported. */
2807 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
2808 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
2810 struct cleanup
*old_cleanups
= NULL
;
2813 old_cleanups
= record_gdb_operation_disable_set ();
2815 /* When using hardware single-step, a SIGTRAP is reported for both
2816 a completed single-step and a software breakpoint. Need to
2817 differentiate between the two, as the latter needs adjusting
2818 but the former does not.
2820 The SIGTRAP can be due to a completed hardware single-step only if
2821 - we didn't insert software single-step breakpoints
2822 - the thread to be examined is still the current thread
2823 - this thread is currently being stepped
2825 If any of these events did not occur, we must have stopped due
2826 to hitting a software breakpoint, and have to back up to the
2829 As a special case, we could have hardware single-stepped a
2830 software breakpoint. In this case (prev_pc == breakpoint_pc),
2831 we also need to back up to the breakpoint address. */
2833 if (singlestep_breakpoints_inserted_p
2834 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
2835 || !currently_stepping (ecs
->event_thread
)
2836 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
2837 regcache_write_pc (regcache
, breakpoint_pc
);
2840 do_cleanups (old_cleanups
);
2845 init_infwait_state (void)
2847 waiton_ptid
= pid_to_ptid (-1);
2848 infwait_state
= infwait_normal_state
;
2852 error_is_running (void)
2855 Cannot execute this command while the selected thread is running."));
2859 ensure_not_running (void)
2861 if (is_running (inferior_ptid
))
2862 error_is_running ();
2866 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
2868 for (frame
= get_prev_frame (frame
);
2870 frame
= get_prev_frame (frame
))
2872 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
2874 if (get_frame_type (frame
) != INLINE_FRAME
)
2881 /* Auxiliary function that handles syscall entry/return events.
2882 It returns 1 if the inferior should keep going (and GDB
2883 should ignore the event), or 0 if the event deserves to be
2887 handle_syscall_event (struct execution_control_state
*ecs
)
2889 struct regcache
*regcache
;
2890 struct gdbarch
*gdbarch
;
2893 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2894 context_switch (ecs
->ptid
);
2896 regcache
= get_thread_regcache (ecs
->ptid
);
2897 gdbarch
= get_regcache_arch (regcache
);
2898 syscall_number
= gdbarch_get_syscall_number (gdbarch
, ecs
->ptid
);
2899 stop_pc
= regcache_read_pc (regcache
);
2901 target_last_waitstatus
.value
.syscall_number
= syscall_number
;
2903 if (catch_syscall_enabled () > 0
2904 && catching_syscall_number (syscall_number
) > 0)
2907 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
2910 ecs
->event_thread
->stop_bpstat
2911 = bpstat_stop_status (get_regcache_aspace (regcache
),
2912 stop_pc
, ecs
->ptid
);
2913 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2915 if (!ecs
->random_signal
)
2917 /* Catchpoint hit. */
2918 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2923 /* If no catchpoint triggered for this, then keep going. */
2924 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2929 /* Given an execution control state that has been freshly filled in
2930 by an event from the inferior, figure out what it means and take
2931 appropriate action. */
2934 handle_inferior_event (struct execution_control_state
*ecs
)
2936 struct frame_info
*frame
;
2937 struct gdbarch
*gdbarch
;
2938 int sw_single_step_trap_p
= 0;
2939 int stopped_by_watchpoint
;
2940 int stepped_after_stopped_by_watchpoint
= 0;
2941 struct symtab_and_line stop_pc_sal
;
2942 enum stop_kind stop_soon
;
2944 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
2946 /* We had an event in the inferior, but we are not interested in
2947 handling it at this level. The lower layers have already
2948 done what needs to be done, if anything.
2950 One of the possible circumstances for this is when the
2951 inferior produces output for the console. The inferior has
2952 not stopped, and we are ignoring the event. Another possible
2953 circumstance is any event which the lower level knows will be
2954 reported multiple times without an intervening resume. */
2956 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2957 prepare_to_wait (ecs
);
2961 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2962 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2964 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2967 stop_soon
= inf
->stop_soon
;
2970 stop_soon
= NO_STOP_QUIETLY
;
2972 /* Cache the last pid/waitstatus. */
2973 target_last_wait_ptid
= ecs
->ptid
;
2974 target_last_waitstatus
= ecs
->ws
;
2976 /* Always clear state belonging to the previous time we stopped. */
2977 stop_stack_dummy
= STOP_NONE
;
2979 /* If it's a new process, add it to the thread database */
2981 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
2982 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
2983 && !in_thread_list (ecs
->ptid
));
2985 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2986 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
2987 add_thread (ecs
->ptid
);
2989 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
2991 /* Dependent on valid ECS->EVENT_THREAD. */
2992 adjust_pc_after_break (ecs
);
2994 /* Dependent on the current PC value modified by adjust_pc_after_break. */
2995 reinit_frame_cache ();
2997 breakpoint_retire_moribund ();
2999 /* First, distinguish signals caused by the debugger from signals
3000 that have to do with the program's own actions. Note that
3001 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3002 on the operating system version. Here we detect when a SIGILL or
3003 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3004 something similar for SIGSEGV, since a SIGSEGV will be generated
3005 when we're trying to execute a breakpoint instruction on a
3006 non-executable stack. This happens for call dummy breakpoints
3007 for architectures like SPARC that place call dummies on the
3009 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3010 && (ecs
->ws
.value
.sig
== TARGET_SIGNAL_ILL
3011 || ecs
->ws
.value
.sig
== TARGET_SIGNAL_SEGV
3012 || ecs
->ws
.value
.sig
== TARGET_SIGNAL_EMT
))
3014 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3016 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3017 regcache_read_pc (regcache
)))
3020 fprintf_unfiltered (gdb_stdlog
,
3021 "infrun: Treating signal as SIGTRAP\n");
3022 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
3026 /* Mark the non-executing threads accordingly. In all-stop, all
3027 threads of all processes are stopped when we get any event
3028 reported. In non-stop mode, only the event thread stops. If
3029 we're handling a process exit in non-stop mode, there's nothing
3030 to do, as threads of the dead process are gone, and threads of
3031 any other process were left running. */
3033 set_executing (minus_one_ptid
, 0);
3034 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3035 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3036 set_executing (inferior_ptid
, 0);
3038 switch (infwait_state
)
3040 case infwait_thread_hop_state
:
3042 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
3045 case infwait_normal_state
:
3047 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3050 case infwait_step_watch_state
:
3052 fprintf_unfiltered (gdb_stdlog
,
3053 "infrun: infwait_step_watch_state\n");
3055 stepped_after_stopped_by_watchpoint
= 1;
3058 case infwait_nonstep_watch_state
:
3060 fprintf_unfiltered (gdb_stdlog
,
3061 "infrun: infwait_nonstep_watch_state\n");
3062 insert_breakpoints ();
3064 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3065 handle things like signals arriving and other things happening
3066 in combination correctly? */
3067 stepped_after_stopped_by_watchpoint
= 1;
3071 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3074 infwait_state
= infwait_normal_state
;
3075 waiton_ptid
= pid_to_ptid (-1);
3077 switch (ecs
->ws
.kind
)
3079 case TARGET_WAITKIND_LOADED
:
3081 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3082 /* Ignore gracefully during startup of the inferior, as it might
3083 be the shell which has just loaded some objects, otherwise
3084 add the symbols for the newly loaded objects. Also ignore at
3085 the beginning of an attach or remote session; we will query
3086 the full list of libraries once the connection is
3088 if (stop_soon
== NO_STOP_QUIETLY
)
3090 /* Check for any newly added shared libraries if we're
3091 supposed to be adding them automatically. Switch
3092 terminal for any messages produced by
3093 breakpoint_re_set. */
3094 target_terminal_ours_for_output ();
3095 /* NOTE: cagney/2003-11-25: Make certain that the target
3096 stack's section table is kept up-to-date. Architectures,
3097 (e.g., PPC64), use the section table to perform
3098 operations such as address => section name and hence
3099 require the table to contain all sections (including
3100 those found in shared libraries). */
3102 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
3104 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
3106 target_terminal_inferior ();
3108 /* If requested, stop when the dynamic linker notifies
3109 gdb of events. This allows the user to get control
3110 and place breakpoints in initializer routines for
3111 dynamically loaded objects (among other things). */
3112 if (stop_on_solib_events
)
3114 /* Make sure we print "Stopped due to solib-event" in
3116 stop_print_frame
= 1;
3118 stop_stepping (ecs
);
3122 /* NOTE drow/2007-05-11: This might be a good place to check
3123 for "catch load". */
3126 /* If we are skipping through a shell, or through shared library
3127 loading that we aren't interested in, resume the program. If
3128 we're running the program normally, also resume. But stop if
3129 we're attaching or setting up a remote connection. */
3130 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3132 /* Loading of shared libraries might have changed breakpoint
3133 addresses. Make sure new breakpoints are inserted. */
3134 if (stop_soon
== NO_STOP_QUIETLY
3135 && !breakpoints_always_inserted_mode ())
3136 insert_breakpoints ();
3137 resume (0, TARGET_SIGNAL_0
);
3138 prepare_to_wait (ecs
);
3144 case TARGET_WAITKIND_SPURIOUS
:
3146 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3147 resume (0, TARGET_SIGNAL_0
);
3148 prepare_to_wait (ecs
);
3151 case TARGET_WAITKIND_EXITED
:
3153 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
3154 inferior_ptid
= ecs
->ptid
;
3155 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3156 set_current_program_space (current_inferior ()->pspace
);
3157 handle_vfork_child_exec_or_exit (0);
3158 target_terminal_ours (); /* Must do this before mourn anyway */
3159 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
3161 /* Record the exit code in the convenience variable $_exitcode, so
3162 that the user can inspect this again later. */
3163 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3164 (LONGEST
) ecs
->ws
.value
.integer
);
3165 gdb_flush (gdb_stdout
);
3166 target_mourn_inferior ();
3167 singlestep_breakpoints_inserted_p
= 0;
3168 stop_print_frame
= 0;
3169 stop_stepping (ecs
);
3172 case TARGET_WAITKIND_SIGNALLED
:
3174 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
3175 inferior_ptid
= ecs
->ptid
;
3176 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3177 set_current_program_space (current_inferior ()->pspace
);
3178 handle_vfork_child_exec_or_exit (0);
3179 stop_print_frame
= 0;
3180 target_terminal_ours (); /* Must do this before mourn anyway */
3182 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
3183 reach here unless the inferior is dead. However, for years
3184 target_kill() was called here, which hints that fatal signals aren't
3185 really fatal on some systems. If that's true, then some changes
3187 target_mourn_inferior ();
3189 print_stop_reason (SIGNAL_EXITED
, ecs
->ws
.value
.sig
);
3190 singlestep_breakpoints_inserted_p
= 0;
3191 stop_stepping (ecs
);
3194 /* The following are the only cases in which we keep going;
3195 the above cases end in a continue or goto. */
3196 case TARGET_WAITKIND_FORKED
:
3197 case TARGET_WAITKIND_VFORKED
:
3199 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3201 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3203 context_switch (ecs
->ptid
);
3204 reinit_frame_cache ();
3207 /* Immediately detach breakpoints from the child before there's
3208 any chance of letting the user delete breakpoints from the
3209 breakpoint lists. If we don't do this early, it's easy to
3210 leave left over traps in the child, vis: "break foo; catch
3211 fork; c; <fork>; del; c; <child calls foo>". We only follow
3212 the fork on the last `continue', and by that time the
3213 breakpoint at "foo" is long gone from the breakpoint table.
3214 If we vforked, then we don't need to unpatch here, since both
3215 parent and child are sharing the same memory pages; we'll
3216 need to unpatch at follow/detach time instead to be certain
3217 that new breakpoints added between catchpoint hit time and
3218 vfork follow are detached. */
3219 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3221 int child_pid
= ptid_get_pid (ecs
->ws
.value
.related_pid
);
3223 /* This won't actually modify the breakpoint list, but will
3224 physically remove the breakpoints from the child. */
3225 detach_breakpoints (child_pid
);
3228 /* In case the event is caught by a catchpoint, remember that
3229 the event is to be followed at the next resume of the thread,
3230 and not immediately. */
3231 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3233 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3235 ecs
->event_thread
->stop_bpstat
3236 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3237 stop_pc
, ecs
->ptid
);
3239 /* Note that we're interested in knowing the bpstat actually
3240 causes a stop, not just if it may explain the signal.
3241 Software watchpoints, for example, always appear in the
3243 ecs
->random_signal
= !bpstat_causes_stop (ecs
->event_thread
->stop_bpstat
);
3245 /* If no catchpoint triggered for this, then keep going. */
3246 if (ecs
->random_signal
)
3251 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
3253 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3255 should_resume
= follow_fork ();
3258 child
= ecs
->ws
.value
.related_pid
;
3260 /* In non-stop mode, also resume the other branch. */
3261 if (non_stop
&& !detach_fork
)
3264 switch_to_thread (parent
);
3266 switch_to_thread (child
);
3268 ecs
->event_thread
= inferior_thread ();
3269 ecs
->ptid
= inferior_ptid
;
3274 switch_to_thread (child
);
3276 switch_to_thread (parent
);
3278 ecs
->event_thread
= inferior_thread ();
3279 ecs
->ptid
= inferior_ptid
;
3284 stop_stepping (ecs
);
3287 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3288 goto process_event_stop_test
;
3290 case TARGET_WAITKIND_VFORK_DONE
:
3291 /* Done with the shared memory region. Re-insert breakpoints in
3292 the parent, and keep going. */
3295 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3297 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3298 context_switch (ecs
->ptid
);
3300 current_inferior ()->waiting_for_vfork_done
= 0;
3301 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3302 /* This also takes care of reinserting breakpoints in the
3303 previously locked inferior. */
3307 case TARGET_WAITKIND_EXECD
:
3309 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3311 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3313 context_switch (ecs
->ptid
);
3314 reinit_frame_cache ();
3317 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3319 /* Do whatever is necessary to the parent branch of the vfork. */
3320 handle_vfork_child_exec_or_exit (1);
3322 /* This causes the eventpoints and symbol table to be reset.
3323 Must do this now, before trying to determine whether to
3325 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3327 ecs
->event_thread
->stop_bpstat
3328 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3329 stop_pc
, ecs
->ptid
);
3330 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
3332 /* Note that this may be referenced from inside
3333 bpstat_stop_status above, through inferior_has_execd. */
3334 xfree (ecs
->ws
.value
.execd_pathname
);
3335 ecs
->ws
.value
.execd_pathname
= NULL
;
3337 /* If no catchpoint triggered for this, then keep going. */
3338 if (ecs
->random_signal
)
3340 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3344 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3345 goto process_event_stop_test
;
3347 /* Be careful not to try to gather much state about a thread
3348 that's in a syscall. It's frequently a losing proposition. */
3349 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3351 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3352 /* Getting the current syscall number */
3353 if (handle_syscall_event (ecs
) != 0)
3355 goto process_event_stop_test
;
3357 /* Before examining the threads further, step this thread to
3358 get it entirely out of the syscall. (We get notice of the
3359 event when the thread is just on the verge of exiting a
3360 syscall. Stepping one instruction seems to get it back
3362 case TARGET_WAITKIND_SYSCALL_RETURN
:
3364 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3365 if (handle_syscall_event (ecs
) != 0)
3367 goto process_event_stop_test
;
3369 case TARGET_WAITKIND_STOPPED
:
3371 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3372 ecs
->event_thread
->stop_signal
= ecs
->ws
.value
.sig
;
3375 case TARGET_WAITKIND_NO_HISTORY
:
3376 /* Reverse execution: target ran out of history info. */
3377 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3378 print_stop_reason (NO_HISTORY
, 0);
3379 stop_stepping (ecs
);
3383 if (ecs
->new_thread_event
)
3386 /* Non-stop assumes that the target handles adding new threads
3387 to the thread list. */
3388 internal_error (__FILE__
, __LINE__
, "\
3389 targets should add new threads to the thread list themselves in non-stop mode.");
3391 /* We may want to consider not doing a resume here in order to
3392 give the user a chance to play with the new thread. It might
3393 be good to make that a user-settable option. */
3395 /* At this point, all threads are stopped (happens automatically
3396 in either the OS or the native code). Therefore we need to
3397 continue all threads in order to make progress. */
3399 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3400 context_switch (ecs
->ptid
);
3401 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
3402 prepare_to_wait (ecs
);
3406 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
3408 /* Do we need to clean up the state of a thread that has
3409 completed a displaced single-step? (Doing so usually affects
3410 the PC, so do it here, before we set stop_pc.) */
3411 displaced_step_fixup (ecs
->ptid
, ecs
->event_thread
->stop_signal
);
3413 /* If we either finished a single-step or hit a breakpoint, but
3414 the user wanted this thread to be stopped, pretend we got a
3415 SIG0 (generic unsignaled stop). */
3417 if (ecs
->event_thread
->stop_requested
3418 && ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3419 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3422 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3426 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3427 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3428 struct cleanup
*old_chain
= save_inferior_ptid ();
3430 inferior_ptid
= ecs
->ptid
;
3432 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3433 paddress (gdbarch
, stop_pc
));
3434 if (target_stopped_by_watchpoint ())
3438 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3440 if (target_stopped_data_address (¤t_target
, &addr
))
3441 fprintf_unfiltered (gdb_stdlog
,
3442 "infrun: stopped data address = %s\n",
3443 paddress (gdbarch
, addr
));
3445 fprintf_unfiltered (gdb_stdlog
,
3446 "infrun: (no data address available)\n");
3449 do_cleanups (old_chain
);
3452 if (stepping_past_singlestep_breakpoint
)
3454 gdb_assert (singlestep_breakpoints_inserted_p
);
3455 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
3456 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
3458 stepping_past_singlestep_breakpoint
= 0;
3460 /* We've either finished single-stepping past the single-step
3461 breakpoint, or stopped for some other reason. It would be nice if
3462 we could tell, but we can't reliably. */
3463 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3466 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
3467 /* Pull the single step breakpoints out of the target. */
3468 remove_single_step_breakpoints ();
3469 singlestep_breakpoints_inserted_p
= 0;
3471 ecs
->random_signal
= 0;
3472 ecs
->event_thread
->trap_expected
= 0;
3474 context_switch (saved_singlestep_ptid
);
3475 if (deprecated_context_hook
)
3476 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3478 resume (1, TARGET_SIGNAL_0
);
3479 prepare_to_wait (ecs
);
3484 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
3486 /* In non-stop mode, there's never a deferred_step_ptid set. */
3487 gdb_assert (!non_stop
);
3489 /* If we stopped for some other reason than single-stepping, ignore
3490 the fact that we were supposed to switch back. */
3491 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3494 fprintf_unfiltered (gdb_stdlog
,
3495 "infrun: handling deferred step\n");
3497 /* Pull the single step breakpoints out of the target. */
3498 if (singlestep_breakpoints_inserted_p
)
3500 remove_single_step_breakpoints ();
3501 singlestep_breakpoints_inserted_p
= 0;
3504 /* Note: We do not call context_switch at this point, as the
3505 context is already set up for stepping the original thread. */
3506 switch_to_thread (deferred_step_ptid
);
3507 deferred_step_ptid
= null_ptid
;
3508 /* Suppress spurious "Switching to ..." message. */
3509 previous_inferior_ptid
= inferior_ptid
;
3511 resume (1, TARGET_SIGNAL_0
);
3512 prepare_to_wait (ecs
);
3516 deferred_step_ptid
= null_ptid
;
3519 /* See if a thread hit a thread-specific breakpoint that was meant for
3520 another thread. If so, then step that thread past the breakpoint,
3523 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3525 int thread_hop_needed
= 0;
3526 struct address_space
*aspace
=
3527 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
3529 /* Check if a regular breakpoint has been hit before checking
3530 for a potential single step breakpoint. Otherwise, GDB will
3531 not see this breakpoint hit when stepping onto breakpoints. */
3532 if (regular_breakpoint_inserted_here_p (aspace
, stop_pc
))
3534 ecs
->random_signal
= 0;
3535 if (!breakpoint_thread_match (aspace
, stop_pc
, ecs
->ptid
))
3536 thread_hop_needed
= 1;
3538 else if (singlestep_breakpoints_inserted_p
)
3540 /* We have not context switched yet, so this should be true
3541 no matter which thread hit the singlestep breakpoint. */
3542 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
3544 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
3546 target_pid_to_str (ecs
->ptid
));
3548 ecs
->random_signal
= 0;
3549 /* The call to in_thread_list is necessary because PTIDs sometimes
3550 change when we go from single-threaded to multi-threaded. If
3551 the singlestep_ptid is still in the list, assume that it is
3552 really different from ecs->ptid. */
3553 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
3554 && in_thread_list (singlestep_ptid
))
3556 /* If the PC of the thread we were trying to single-step
3557 has changed, discard this event (which we were going
3558 to ignore anyway), and pretend we saw that thread
3559 trap. This prevents us continuously moving the
3560 single-step breakpoint forward, one instruction at a
3561 time. If the PC has changed, then the thread we were
3562 trying to single-step has trapped or been signalled,
3563 but the event has not been reported to GDB yet.
3565 There might be some cases where this loses signal
3566 information, if a signal has arrived at exactly the
3567 same time that the PC changed, but this is the best
3568 we can do with the information available. Perhaps we
3569 should arrange to report all events for all threads
3570 when they stop, or to re-poll the remote looking for
3571 this particular thread (i.e. temporarily enable
3574 CORE_ADDR new_singlestep_pc
3575 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
3577 if (new_singlestep_pc
!= singlestep_pc
)
3579 enum target_signal stop_signal
;
3582 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
3583 " but expected thread advanced also\n");
3585 /* The current context still belongs to
3586 singlestep_ptid. Don't swap here, since that's
3587 the context we want to use. Just fudge our
3588 state and continue. */
3589 stop_signal
= ecs
->event_thread
->stop_signal
;
3590 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3591 ecs
->ptid
= singlestep_ptid
;
3592 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3593 ecs
->event_thread
->stop_signal
= stop_signal
;
3594 stop_pc
= new_singlestep_pc
;
3599 fprintf_unfiltered (gdb_stdlog
,
3600 "infrun: unexpected thread\n");
3602 thread_hop_needed
= 1;
3603 stepping_past_singlestep_breakpoint
= 1;
3604 saved_singlestep_ptid
= singlestep_ptid
;
3609 if (thread_hop_needed
)
3611 struct regcache
*thread_regcache
;
3612 int remove_status
= 0;
3615 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
3617 /* Switch context before touching inferior memory, the
3618 previous thread may have exited. */
3619 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
3620 context_switch (ecs
->ptid
);
3622 /* Saw a breakpoint, but it was hit by the wrong thread.
3625 if (singlestep_breakpoints_inserted_p
)
3627 /* Pull the single step breakpoints out of the target. */
3628 remove_single_step_breakpoints ();
3629 singlestep_breakpoints_inserted_p
= 0;
3632 /* If the arch can displace step, don't remove the
3634 thread_regcache
= get_thread_regcache (ecs
->ptid
);
3635 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
3636 remove_status
= remove_breakpoints ();
3638 /* Did we fail to remove breakpoints? If so, try
3639 to set the PC past the bp. (There's at least
3640 one situation in which we can fail to remove
3641 the bp's: On HP-UX's that use ttrace, we can't
3642 change the address space of a vforking child
3643 process until the child exits (well, okay, not
3644 then either :-) or execs. */
3645 if (remove_status
!= 0)
3646 error (_("Cannot step over breakpoint hit in wrong thread"));
3651 /* Only need to require the next event from this
3652 thread in all-stop mode. */
3653 waiton_ptid
= ecs
->ptid
;
3654 infwait_state
= infwait_thread_hop_state
;
3657 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3662 else if (singlestep_breakpoints_inserted_p
)
3664 sw_single_step_trap_p
= 1;
3665 ecs
->random_signal
= 0;
3669 ecs
->random_signal
= 1;
3671 /* See if something interesting happened to the non-current thread. If
3672 so, then switch to that thread. */
3673 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3676 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3678 context_switch (ecs
->ptid
);
3680 if (deprecated_context_hook
)
3681 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3684 /* At this point, get hold of the now-current thread's frame. */
3685 frame
= get_current_frame ();
3686 gdbarch
= get_frame_arch (frame
);
3688 if (singlestep_breakpoints_inserted_p
)
3690 /* Pull the single step breakpoints out of the target. */
3691 remove_single_step_breakpoints ();
3692 singlestep_breakpoints_inserted_p
= 0;
3695 if (stepped_after_stopped_by_watchpoint
)
3696 stopped_by_watchpoint
= 0;
3698 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
3700 /* If necessary, step over this watchpoint. We'll be back to display
3702 if (stopped_by_watchpoint
3703 && (target_have_steppable_watchpoint
3704 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
3706 /* At this point, we are stopped at an instruction which has
3707 attempted to write to a piece of memory under control of
3708 a watchpoint. The instruction hasn't actually executed
3709 yet. If we were to evaluate the watchpoint expression
3710 now, we would get the old value, and therefore no change
3711 would seem to have occurred.
3713 In order to make watchpoints work `right', we really need
3714 to complete the memory write, and then evaluate the
3715 watchpoint expression. We do this by single-stepping the
3718 It may not be necessary to disable the watchpoint to stop over
3719 it. For example, the PA can (with some kernel cooperation)
3720 single step over a watchpoint without disabling the watchpoint.
3722 It is far more common to need to disable a watchpoint to step
3723 the inferior over it. If we have non-steppable watchpoints,
3724 we must disable the current watchpoint; it's simplest to
3725 disable all watchpoints and breakpoints. */
3728 if (!target_have_steppable_watchpoint
)
3729 remove_breakpoints ();
3731 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
3732 target_resume (ecs
->ptid
, hw_step
, TARGET_SIGNAL_0
);
3733 waiton_ptid
= ecs
->ptid
;
3734 if (target_have_steppable_watchpoint
)
3735 infwait_state
= infwait_step_watch_state
;
3737 infwait_state
= infwait_nonstep_watch_state
;
3738 prepare_to_wait (ecs
);
3742 ecs
->stop_func_start
= 0;
3743 ecs
->stop_func_end
= 0;
3744 ecs
->stop_func_name
= 0;
3745 /* Don't care about return value; stop_func_start and stop_func_name
3746 will both be 0 if it doesn't work. */
3747 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3748 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3749 ecs
->stop_func_start
3750 += gdbarch_deprecated_function_start_offset (gdbarch
);
3751 ecs
->event_thread
->stepping_over_breakpoint
= 0;
3752 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
3753 ecs
->event_thread
->stop_step
= 0;
3754 stop_print_frame
= 1;
3755 ecs
->random_signal
= 0;
3756 stopped_by_random_signal
= 0;
3758 /* Hide inlined functions starting here, unless we just performed stepi or
3759 nexti. After stepi and nexti, always show the innermost frame (not any
3760 inline function call sites). */
3761 if (ecs
->event_thread
->step_range_end
!= 1)
3762 skip_inline_frames (ecs
->ptid
);
3764 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3765 && ecs
->event_thread
->trap_expected
3766 && gdbarch_single_step_through_delay_p (gdbarch
)
3767 && currently_stepping (ecs
->event_thread
))
3769 /* We're trying to step off a breakpoint. Turns out that we're
3770 also on an instruction that needs to be stepped multiple
3771 times before it's been fully executing. E.g., architectures
3772 with a delay slot. It needs to be stepped twice, once for
3773 the instruction and once for the delay slot. */
3774 int step_through_delay
3775 = gdbarch_single_step_through_delay (gdbarch
, frame
);
3777 if (debug_infrun
&& step_through_delay
)
3778 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
3779 if (ecs
->event_thread
->step_range_end
== 0 && step_through_delay
)
3781 /* The user issued a continue when stopped at a breakpoint.
3782 Set up for another trap and get out of here. */
3783 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3787 else if (step_through_delay
)
3789 /* The user issued a step when stopped at a breakpoint.
3790 Maybe we should stop, maybe we should not - the delay
3791 slot *might* correspond to a line of source. In any
3792 case, don't decide that here, just set
3793 ecs->stepping_over_breakpoint, making sure we
3794 single-step again before breakpoints are re-inserted. */
3795 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3799 /* Look at the cause of the stop, and decide what to do.
3800 The alternatives are:
3801 1) stop_stepping and return; to really stop and return to the debugger,
3802 2) keep_going and return to start up again
3803 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3804 3) set ecs->random_signal to 1, and the decision between 1 and 2
3805 will be made according to the signal handling tables. */
3807 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3808 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3809 || stop_soon
== STOP_QUIETLY_REMOTE
)
3811 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
3814 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
3815 stop_print_frame
= 0;
3816 stop_stepping (ecs
);
3820 /* This is originated from start_remote(), start_inferior() and
3821 shared libraries hook functions. */
3822 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
3825 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3826 stop_stepping (ecs
);
3830 /* This originates from attach_command(). We need to overwrite
3831 the stop_signal here, because some kernels don't ignore a
3832 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3833 See more comments in inferior.h. On the other hand, if we
3834 get a non-SIGSTOP, report it to the user - assume the backend
3835 will handle the SIGSTOP if it should show up later.
3837 Also consider that the attach is complete when we see a
3838 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3839 target extended-remote report it instead of a SIGSTOP
3840 (e.g. gdbserver). We already rely on SIGTRAP being our
3841 signal, so this is no exception.
3843 Also consider that the attach is complete when we see a
3844 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3845 the target to stop all threads of the inferior, in case the
3846 low level attach operation doesn't stop them implicitly. If
3847 they weren't stopped implicitly, then the stub will report a
3848 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3849 other than GDB's request. */
3850 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3851 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_STOP
3852 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3853 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_0
))
3855 stop_stepping (ecs
);
3856 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3860 /* See if there is a breakpoint at the current PC. */
3861 ecs
->event_thread
->stop_bpstat
3862 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3863 stop_pc
, ecs
->ptid
);
3865 /* Following in case break condition called a
3867 stop_print_frame
= 1;
3869 /* This is where we handle "moribund" watchpoints. Unlike
3870 software breakpoints traps, hardware watchpoint traps are
3871 always distinguishable from random traps. If no high-level
3872 watchpoint is associated with the reported stop data address
3873 anymore, then the bpstat does not explain the signal ---
3874 simply make sure to ignore it if `stopped_by_watchpoint' is
3878 && ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3879 && !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
)
3880 && stopped_by_watchpoint
)
3881 fprintf_unfiltered (gdb_stdlog
, "\
3882 infrun: no user watchpoint explains watchpoint SIGTRAP, ignoring\n");
3884 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3885 at one stage in the past included checks for an inferior
3886 function call's call dummy's return breakpoint. The original
3887 comment, that went with the test, read:
3889 ``End of a stack dummy. Some systems (e.g. Sony news) give
3890 another signal besides SIGTRAP, so check here as well as
3893 If someone ever tries to get call dummys on a
3894 non-executable stack to work (where the target would stop
3895 with something like a SIGSEGV), then those tests might need
3896 to be re-instated. Given, however, that the tests were only
3897 enabled when momentary breakpoints were not being used, I
3898 suspect that it won't be the case.
3900 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3901 be necessary for call dummies on a non-executable stack on
3904 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3906 = !(bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
)
3907 || stopped_by_watchpoint
3908 || ecs
->event_thread
->trap_expected
3909 || (ecs
->event_thread
->step_range_end
3910 && ecs
->event_thread
->step_resume_breakpoint
== NULL
));
3913 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
3914 if (!ecs
->random_signal
)
3915 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3919 /* When we reach this point, we've pretty much decided
3920 that the reason for stopping must've been a random
3921 (unexpected) signal. */
3924 ecs
->random_signal
= 1;
3926 process_event_stop_test
:
3928 /* Re-fetch current thread's frame in case we did a
3929 "goto process_event_stop_test" above. */
3930 frame
= get_current_frame ();
3931 gdbarch
= get_frame_arch (frame
);
3933 /* For the program's own signals, act according to
3934 the signal handling tables. */
3936 if (ecs
->random_signal
)
3938 /* Signal not for debugging purposes. */
3940 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3943 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
3944 ecs
->event_thread
->stop_signal
);
3946 stopped_by_random_signal
= 1;
3948 if (signal_print
[ecs
->event_thread
->stop_signal
])
3951 target_terminal_ours_for_output ();
3952 print_stop_reason (SIGNAL_RECEIVED
, ecs
->event_thread
->stop_signal
);
3954 /* Always stop on signals if we're either just gaining control
3955 of the program, or the user explicitly requested this thread
3956 to remain stopped. */
3957 if (stop_soon
!= NO_STOP_QUIETLY
3958 || ecs
->event_thread
->stop_requested
3960 && signal_stop_state (ecs
->event_thread
->stop_signal
)))
3962 stop_stepping (ecs
);
3965 /* If not going to stop, give terminal back
3966 if we took it away. */
3968 target_terminal_inferior ();
3970 /* Clear the signal if it should not be passed. */
3971 if (signal_program
[ecs
->event_thread
->stop_signal
] == 0)
3972 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3974 if (ecs
->event_thread
->prev_pc
== stop_pc
3975 && ecs
->event_thread
->trap_expected
3976 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3978 /* We were just starting a new sequence, attempting to
3979 single-step off of a breakpoint and expecting a SIGTRAP.
3980 Instead this signal arrives. This signal will take us out
3981 of the stepping range so GDB needs to remember to, when
3982 the signal handler returns, resume stepping off that
3984 /* To simplify things, "continue" is forced to use the same
3985 code paths as single-step - set a breakpoint at the
3986 signal return address and then, once hit, step off that
3989 fprintf_unfiltered (gdb_stdlog
,
3990 "infrun: signal arrived while stepping over "
3993 insert_step_resume_breakpoint_at_frame (frame
);
3994 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
3999 if (ecs
->event_thread
->step_range_end
!= 0
4000 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_0
4001 && (ecs
->event_thread
->step_range_start
<= stop_pc
4002 && stop_pc
< ecs
->event_thread
->step_range_end
)
4003 && frame_id_eq (get_stack_frame_id (frame
),
4004 ecs
->event_thread
->step_stack_frame_id
)
4005 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
4007 /* The inferior is about to take a signal that will take it
4008 out of the single step range. Set a breakpoint at the
4009 current PC (which is presumably where the signal handler
4010 will eventually return) and then allow the inferior to
4013 Note that this is only needed for a signal delivered
4014 while in the single-step range. Nested signals aren't a
4015 problem as they eventually all return. */
4017 fprintf_unfiltered (gdb_stdlog
,
4018 "infrun: signal may take us out of "
4019 "single-step range\n");
4021 insert_step_resume_breakpoint_at_frame (frame
);
4026 /* Note: step_resume_breakpoint may be non-NULL. This occures
4027 when either there's a nested signal, or when there's a
4028 pending signal enabled just as the signal handler returns
4029 (leaving the inferior at the step-resume-breakpoint without
4030 actually executing it). Either way continue until the
4031 breakpoint is really hit. */
4036 /* Handle cases caused by hitting a breakpoint. */
4038 CORE_ADDR jmp_buf_pc
;
4039 struct bpstat_what what
;
4041 what
= bpstat_what (ecs
->event_thread
->stop_bpstat
);
4043 if (what
.call_dummy
)
4045 stop_stack_dummy
= what
.call_dummy
;
4048 switch (what
.main_action
)
4050 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4051 /* If we hit the breakpoint at longjmp while stepping, we
4052 install a momentary breakpoint at the target of the
4056 fprintf_unfiltered (gdb_stdlog
,
4057 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4059 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4061 if (!gdbarch_get_longjmp_target_p (gdbarch
)
4062 || !gdbarch_get_longjmp_target (gdbarch
, frame
, &jmp_buf_pc
))
4065 fprintf_unfiltered (gdb_stdlog
, "\
4066 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
4071 /* We're going to replace the current step-resume breakpoint
4072 with a longjmp-resume breakpoint. */
4073 delete_step_resume_breakpoint (ecs
->event_thread
);
4075 /* Insert a breakpoint at resume address. */
4076 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4081 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4083 fprintf_unfiltered (gdb_stdlog
,
4084 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4086 gdb_assert (ecs
->event_thread
->step_resume_breakpoint
!= NULL
);
4087 delete_step_resume_breakpoint (ecs
->event_thread
);
4089 ecs
->event_thread
->stop_step
= 1;
4090 print_stop_reason (END_STEPPING_RANGE
, 0);
4091 stop_stepping (ecs
);
4094 case BPSTAT_WHAT_SINGLE
:
4096 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4097 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4098 /* Still need to check other stuff, at least the case
4099 where we are stepping and step out of the right range. */
4102 case BPSTAT_WHAT_STOP_NOISY
:
4104 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4105 stop_print_frame
= 1;
4107 /* We are about to nuke the step_resume_breakpointt via the
4108 cleanup chain, so no need to worry about it here. */
4110 stop_stepping (ecs
);
4113 case BPSTAT_WHAT_STOP_SILENT
:
4115 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4116 stop_print_frame
= 0;
4118 /* We are about to nuke the step_resume_breakpoin via the
4119 cleanup chain, so no need to worry about it here. */
4121 stop_stepping (ecs
);
4124 case BPSTAT_WHAT_STEP_RESUME
:
4126 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4128 delete_step_resume_breakpoint (ecs
->event_thread
);
4129 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4131 /* Back when the step-resume breakpoint was inserted, we
4132 were trying to single-step off a breakpoint. Go back
4134 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4135 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4139 if (stop_pc
== ecs
->stop_func_start
4140 && execution_direction
== EXEC_REVERSE
)
4142 /* We are stepping over a function call in reverse, and
4143 just hit the step-resume breakpoint at the start
4144 address of the function. Go back to single-stepping,
4145 which should take us back to the function call. */
4146 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4152 case BPSTAT_WHAT_CHECK_SHLIBS
:
4155 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
4157 /* Check for any newly added shared libraries if we're
4158 supposed to be adding them automatically. Switch
4159 terminal for any messages produced by
4160 breakpoint_re_set. */
4161 target_terminal_ours_for_output ();
4162 /* NOTE: cagney/2003-11-25: Make certain that the target
4163 stack's section table is kept up-to-date. Architectures,
4164 (e.g., PPC64), use the section table to perform
4165 operations such as address => section name and hence
4166 require the table to contain all sections (including
4167 those found in shared libraries). */
4169 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
4171 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
4173 target_terminal_inferior ();
4175 /* If requested, stop when the dynamic linker notifies
4176 gdb of events. This allows the user to get control
4177 and place breakpoints in initializer routines for
4178 dynamically loaded objects (among other things). */
4179 if (stop_on_solib_events
|| stop_stack_dummy
)
4181 stop_stepping (ecs
);
4186 /* We want to step over this breakpoint, then keep going. */
4187 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4193 case BPSTAT_WHAT_CHECK_JIT
:
4195 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_JIT\n");
4197 /* Switch terminal for any messages produced by breakpoint_re_set. */
4198 target_terminal_ours_for_output ();
4200 jit_event_handler (gdbarch
);
4202 target_terminal_inferior ();
4204 /* We want to step over this breakpoint, then keep going. */
4205 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4209 case BPSTAT_WHAT_LAST
:
4210 /* Not a real code, but listed here to shut up gcc -Wall. */
4212 case BPSTAT_WHAT_KEEP_CHECKING
:
4217 /* We come here if we hit a breakpoint but should not
4218 stop for it. Possibly we also were stepping
4219 and should stop for that. So fall through and
4220 test for stepping. But, if not stepping,
4223 /* In all-stop mode, if we're currently stepping but have stopped in
4224 some other thread, we need to switch back to the stepped thread. */
4227 struct thread_info
*tp
;
4229 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
4233 /* However, if the current thread is blocked on some internal
4234 breakpoint, and we simply need to step over that breakpoint
4235 to get it going again, do that first. */
4236 if ((ecs
->event_thread
->trap_expected
4237 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
4238 || ecs
->event_thread
->stepping_over_breakpoint
)
4244 /* If the stepping thread exited, then don't try to switch
4245 back and resume it, which could fail in several different
4246 ways depending on the target. Instead, just keep going.
4248 We can find a stepping dead thread in the thread list in
4251 - The target supports thread exit events, and when the
4252 target tries to delete the thread from the thread list,
4253 inferior_ptid pointed at the exiting thread. In such
4254 case, calling delete_thread does not really remove the
4255 thread from the list; instead, the thread is left listed,
4256 with 'exited' state.
4258 - The target's debug interface does not support thread
4259 exit events, and so we have no idea whatsoever if the
4260 previously stepping thread is still alive. For that
4261 reason, we need to synchronously query the target
4263 if (is_exited (tp
->ptid
)
4264 || !target_thread_alive (tp
->ptid
))
4267 fprintf_unfiltered (gdb_stdlog
, "\
4268 infrun: not switching back to stepped thread, it has vanished\n");
4270 delete_thread (tp
->ptid
);
4275 /* Otherwise, we no longer expect a trap in the current thread.
4276 Clear the trap_expected flag before switching back -- this is
4277 what keep_going would do as well, if we called it. */
4278 ecs
->event_thread
->trap_expected
= 0;
4281 fprintf_unfiltered (gdb_stdlog
,
4282 "infrun: switching back to stepped thread\n");
4284 ecs
->event_thread
= tp
;
4285 ecs
->ptid
= tp
->ptid
;
4286 context_switch (ecs
->ptid
);
4292 /* Are we stepping to get the inferior out of the dynamic linker's
4293 hook (and possibly the dld itself) after catching a shlib
4295 if (ecs
->event_thread
->stepping_through_solib_after_catch
)
4297 #if defined(SOLIB_ADD)
4298 /* Have we reached our destination? If not, keep going. */
4299 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
4302 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
4303 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4309 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
4310 /* Else, stop and report the catchpoint(s) whose triggering
4311 caused us to begin stepping. */
4312 ecs
->event_thread
->stepping_through_solib_after_catch
= 0;
4313 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
4314 ecs
->event_thread
->stop_bpstat
4315 = bpstat_copy (ecs
->event_thread
->stepping_through_solib_catchpoints
);
4316 bpstat_clear (&ecs
->event_thread
->stepping_through_solib_catchpoints
);
4317 stop_print_frame
= 1;
4318 stop_stepping (ecs
);
4322 if (ecs
->event_thread
->step_resume_breakpoint
)
4325 fprintf_unfiltered (gdb_stdlog
,
4326 "infrun: step-resume breakpoint is inserted\n");
4328 /* Having a step-resume breakpoint overrides anything
4329 else having to do with stepping commands until
4330 that breakpoint is reached. */
4335 if (ecs
->event_thread
->step_range_end
== 0)
4338 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4339 /* Likewise if we aren't even stepping. */
4344 /* Re-fetch current thread's frame in case the code above caused
4345 the frame cache to be re-initialized, making our FRAME variable
4346 a dangling pointer. */
4347 frame
= get_current_frame ();
4349 /* If stepping through a line, keep going if still within it.
4351 Note that step_range_end is the address of the first instruction
4352 beyond the step range, and NOT the address of the last instruction
4355 Note also that during reverse execution, we may be stepping
4356 through a function epilogue and therefore must detect when
4357 the current-frame changes in the middle of a line. */
4359 if (stop_pc
>= ecs
->event_thread
->step_range_start
4360 && stop_pc
< ecs
->event_thread
->step_range_end
4361 && (execution_direction
!= EXEC_REVERSE
4362 || frame_id_eq (get_frame_id (frame
),
4363 ecs
->event_thread
->step_frame_id
)))
4367 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4368 paddress (gdbarch
, ecs
->event_thread
->step_range_start
),
4369 paddress (gdbarch
, ecs
->event_thread
->step_range_end
));
4371 /* When stepping backward, stop at beginning of line range
4372 (unless it's the function entry point, in which case
4373 keep going back to the call point). */
4374 if (stop_pc
== ecs
->event_thread
->step_range_start
4375 && stop_pc
!= ecs
->stop_func_start
4376 && execution_direction
== EXEC_REVERSE
)
4378 ecs
->event_thread
->stop_step
= 1;
4379 print_stop_reason (END_STEPPING_RANGE
, 0);
4380 stop_stepping (ecs
);
4388 /* We stepped out of the stepping range. */
4390 /* If we are stepping at the source level and entered the runtime
4391 loader dynamic symbol resolution code...
4393 EXEC_FORWARD: we keep on single stepping until we exit the run
4394 time loader code and reach the callee's address.
4396 EXEC_REVERSE: we've already executed the callee (backward), and
4397 the runtime loader code is handled just like any other
4398 undebuggable function call. Now we need only keep stepping
4399 backward through the trampoline code, and that's handled further
4400 down, so there is nothing for us to do here. */
4402 if (execution_direction
!= EXEC_REVERSE
4403 && ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4404 && in_solib_dynsym_resolve_code (stop_pc
))
4406 CORE_ADDR pc_after_resolver
=
4407 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4410 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
4412 if (pc_after_resolver
)
4414 /* Set up a step-resume breakpoint at the address
4415 indicated by SKIP_SOLIB_RESOLVER. */
4416 struct symtab_and_line sr_sal
;
4419 sr_sal
.pc
= pc_after_resolver
;
4420 sr_sal
.pspace
= get_frame_program_space (frame
);
4422 insert_step_resume_breakpoint_at_sal (gdbarch
,
4423 sr_sal
, null_frame_id
);
4430 if (ecs
->event_thread
->step_range_end
!= 1
4431 && (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4432 || ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
4433 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4436 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
4437 /* The inferior, while doing a "step" or "next", has ended up in
4438 a signal trampoline (either by a signal being delivered or by
4439 the signal handler returning). Just single-step until the
4440 inferior leaves the trampoline (either by calling the handler
4446 /* Check for subroutine calls. The check for the current frame
4447 equalling the step ID is not necessary - the check of the
4448 previous frame's ID is sufficient - but it is a common case and
4449 cheaper than checking the previous frame's ID.
4451 NOTE: frame_id_eq will never report two invalid frame IDs as
4452 being equal, so to get into this block, both the current and
4453 previous frame must have valid frame IDs. */
4454 /* The outer_frame_id check is a heuristic to detect stepping
4455 through startup code. If we step over an instruction which
4456 sets the stack pointer from an invalid value to a valid value,
4457 we may detect that as a subroutine call from the mythical
4458 "outermost" function. This could be fixed by marking
4459 outermost frames as !stack_p,code_p,special_p. Then the
4460 initial outermost frame, before sp was valid, would
4461 have code_addr == &_start. See the comment in frame_id_eq
4463 if (!frame_id_eq (get_stack_frame_id (frame
),
4464 ecs
->event_thread
->step_stack_frame_id
)
4465 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4466 ecs
->event_thread
->step_stack_frame_id
)
4467 && (!frame_id_eq (ecs
->event_thread
->step_stack_frame_id
,
4469 || step_start_function
!= find_pc_function (stop_pc
))))
4471 CORE_ADDR real_stop_pc
;
4474 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4476 if ((ecs
->event_thread
->step_over_calls
== STEP_OVER_NONE
)
4477 || ((ecs
->event_thread
->step_range_end
== 1)
4478 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4479 ecs
->stop_func_start
)))
4481 /* I presume that step_over_calls is only 0 when we're
4482 supposed to be stepping at the assembly language level
4483 ("stepi"). Just stop. */
4484 /* Also, maybe we just did a "nexti" inside a prolog, so we
4485 thought it was a subroutine call but it was not. Stop as
4487 /* And this works the same backward as frontward. MVS */
4488 ecs
->event_thread
->stop_step
= 1;
4489 print_stop_reason (END_STEPPING_RANGE
, 0);
4490 stop_stepping (ecs
);
4494 /* Reverse stepping through solib trampolines. */
4496 if (execution_direction
== EXEC_REVERSE
4497 && ecs
->event_thread
->step_over_calls
!= STEP_OVER_NONE
4498 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4499 || (ecs
->stop_func_start
== 0
4500 && in_solib_dynsym_resolve_code (stop_pc
))))
4502 /* Any solib trampoline code can be handled in reverse
4503 by simply continuing to single-step. We have already
4504 executed the solib function (backwards), and a few
4505 steps will take us back through the trampoline to the
4511 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
4513 /* We're doing a "next".
4515 Normal (forward) execution: set a breakpoint at the
4516 callee's return address (the address at which the caller
4519 Reverse (backward) execution. set the step-resume
4520 breakpoint at the start of the function that we just
4521 stepped into (backwards), and continue to there. When we
4522 get there, we'll need to single-step back to the caller. */
4524 if (execution_direction
== EXEC_REVERSE
)
4526 struct symtab_and_line sr_sal
;
4528 /* Normal function call return (static or dynamic). */
4530 sr_sal
.pc
= ecs
->stop_func_start
;
4531 sr_sal
.pspace
= get_frame_program_space (frame
);
4532 insert_step_resume_breakpoint_at_sal (gdbarch
,
4533 sr_sal
, null_frame_id
);
4536 insert_step_resume_breakpoint_at_caller (frame
);
4542 /* If we are in a function call trampoline (a stub between the
4543 calling routine and the real function), locate the real
4544 function. That's what tells us (a) whether we want to step
4545 into it at all, and (b) what prologue we want to run to the
4546 end of, if we do step into it. */
4547 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4548 if (real_stop_pc
== 0)
4549 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4550 if (real_stop_pc
!= 0)
4551 ecs
->stop_func_start
= real_stop_pc
;
4553 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4555 struct symtab_and_line sr_sal
;
4558 sr_sal
.pc
= ecs
->stop_func_start
;
4559 sr_sal
.pspace
= get_frame_program_space (frame
);
4561 insert_step_resume_breakpoint_at_sal (gdbarch
,
4562 sr_sal
, null_frame_id
);
4567 /* If we have line number information for the function we are
4568 thinking of stepping into, step into it.
4570 If there are several symtabs at that PC (e.g. with include
4571 files), just want to know whether *any* of them have line
4572 numbers. find_pc_line handles this. */
4574 struct symtab_and_line tmp_sal
;
4576 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4577 tmp_sal
.pspace
= get_frame_program_space (frame
);
4578 if (tmp_sal
.line
!= 0)
4580 if (execution_direction
== EXEC_REVERSE
)
4581 handle_step_into_function_backward (gdbarch
, ecs
);
4583 handle_step_into_function (gdbarch
, ecs
);
4588 /* If we have no line number and the step-stop-if-no-debug is
4589 set, we stop the step so that the user has a chance to switch
4590 in assembly mode. */
4591 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4592 && step_stop_if_no_debug
)
4594 ecs
->event_thread
->stop_step
= 1;
4595 print_stop_reason (END_STEPPING_RANGE
, 0);
4596 stop_stepping (ecs
);
4600 if (execution_direction
== EXEC_REVERSE
)
4602 /* Set a breakpoint at callee's start address.
4603 From there we can step once and be back in the caller. */
4604 struct symtab_and_line sr_sal
;
4607 sr_sal
.pc
= ecs
->stop_func_start
;
4608 sr_sal
.pspace
= get_frame_program_space (frame
);
4609 insert_step_resume_breakpoint_at_sal (gdbarch
,
4610 sr_sal
, null_frame_id
);
4613 /* Set a breakpoint at callee's return address (the address
4614 at which the caller will resume). */
4615 insert_step_resume_breakpoint_at_caller (frame
);
4621 /* Reverse stepping through solib trampolines. */
4623 if (execution_direction
== EXEC_REVERSE
4624 && ecs
->event_thread
->step_over_calls
!= STEP_OVER_NONE
)
4626 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4627 || (ecs
->stop_func_start
== 0
4628 && in_solib_dynsym_resolve_code (stop_pc
)))
4630 /* Any solib trampoline code can be handled in reverse
4631 by simply continuing to single-step. We have already
4632 executed the solib function (backwards), and a few
4633 steps will take us back through the trampoline to the
4638 else if (in_solib_dynsym_resolve_code (stop_pc
))
4640 /* Stepped backward into the solib dynsym resolver.
4641 Set a breakpoint at its start and continue, then
4642 one more step will take us out. */
4643 struct symtab_and_line sr_sal
;
4646 sr_sal
.pc
= ecs
->stop_func_start
;
4647 sr_sal
.pspace
= get_frame_program_space (frame
);
4648 insert_step_resume_breakpoint_at_sal (gdbarch
,
4649 sr_sal
, null_frame_id
);
4655 /* If we're in the return path from a shared library trampoline,
4656 we want to proceed through the trampoline when stepping. */
4657 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4658 stop_pc
, ecs
->stop_func_name
))
4660 /* Determine where this trampoline returns. */
4661 CORE_ADDR real_stop_pc
;
4663 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4666 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
4668 /* Only proceed through if we know where it's going. */
4671 /* And put the step-breakpoint there and go until there. */
4672 struct symtab_and_line sr_sal
;
4674 init_sal (&sr_sal
); /* initialize to zeroes */
4675 sr_sal
.pc
= real_stop_pc
;
4676 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4677 sr_sal
.pspace
= get_frame_program_space (frame
);
4679 /* Do not specify what the fp should be when we stop since
4680 on some machines the prologue is where the new fp value
4682 insert_step_resume_breakpoint_at_sal (gdbarch
,
4683 sr_sal
, null_frame_id
);
4685 /* Restart without fiddling with the step ranges or
4692 stop_pc_sal
= find_pc_line (stop_pc
, 0);
4694 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4695 the trampoline processing logic, however, there are some trampolines
4696 that have no names, so we should do trampoline handling first. */
4697 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4698 && ecs
->stop_func_name
== NULL
4699 && stop_pc_sal
.line
== 0)
4702 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
4704 /* The inferior just stepped into, or returned to, an
4705 undebuggable function (where there is no debugging information
4706 and no line number corresponding to the address where the
4707 inferior stopped). Since we want to skip this kind of code,
4708 we keep going until the inferior returns from this
4709 function - unless the user has asked us not to (via
4710 set step-mode) or we no longer know how to get back
4711 to the call site. */
4712 if (step_stop_if_no_debug
4713 || !frame_id_p (frame_unwind_caller_id (frame
)))
4715 /* If we have no line number and the step-stop-if-no-debug
4716 is set, we stop the step so that the user has a chance to
4717 switch in assembly mode. */
4718 ecs
->event_thread
->stop_step
= 1;
4719 print_stop_reason (END_STEPPING_RANGE
, 0);
4720 stop_stepping (ecs
);
4725 /* Set a breakpoint at callee's return address (the address
4726 at which the caller will resume). */
4727 insert_step_resume_breakpoint_at_caller (frame
);
4733 if (ecs
->event_thread
->step_range_end
== 1)
4735 /* It is stepi or nexti. We always want to stop stepping after
4738 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
4739 ecs
->event_thread
->stop_step
= 1;
4740 print_stop_reason (END_STEPPING_RANGE
, 0);
4741 stop_stepping (ecs
);
4745 if (stop_pc_sal
.line
== 0)
4747 /* We have no line number information. That means to stop
4748 stepping (does this always happen right after one instruction,
4749 when we do "s" in a function with no line numbers,
4750 or can this happen as a result of a return or longjmp?). */
4752 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
4753 ecs
->event_thread
->stop_step
= 1;
4754 print_stop_reason (END_STEPPING_RANGE
, 0);
4755 stop_stepping (ecs
);
4759 /* Look for "calls" to inlined functions, part one. If the inline
4760 frame machinery detected some skipped call sites, we have entered
4761 a new inline function. */
4763 if (frame_id_eq (get_frame_id (get_current_frame ()),
4764 ecs
->event_thread
->step_frame_id
)
4765 && inline_skipped_frames (ecs
->ptid
))
4767 struct symtab_and_line call_sal
;
4770 fprintf_unfiltered (gdb_stdlog
,
4771 "infrun: stepped into inlined function\n");
4773 find_frame_sal (get_current_frame (), &call_sal
);
4775 if (ecs
->event_thread
->step_over_calls
!= STEP_OVER_ALL
)
4777 /* For "step", we're going to stop. But if the call site
4778 for this inlined function is on the same source line as
4779 we were previously stepping, go down into the function
4780 first. Otherwise stop at the call site. */
4782 if (call_sal
.line
== ecs
->event_thread
->current_line
4783 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
4784 step_into_inline_frame (ecs
->ptid
);
4786 ecs
->event_thread
->stop_step
= 1;
4787 print_stop_reason (END_STEPPING_RANGE
, 0);
4788 stop_stepping (ecs
);
4793 /* For "next", we should stop at the call site if it is on a
4794 different source line. Otherwise continue through the
4795 inlined function. */
4796 if (call_sal
.line
== ecs
->event_thread
->current_line
4797 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
4801 ecs
->event_thread
->stop_step
= 1;
4802 print_stop_reason (END_STEPPING_RANGE
, 0);
4803 stop_stepping (ecs
);
4809 /* Look for "calls" to inlined functions, part two. If we are still
4810 in the same real function we were stepping through, but we have
4811 to go further up to find the exact frame ID, we are stepping
4812 through a more inlined call beyond its call site. */
4814 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
4815 && !frame_id_eq (get_frame_id (get_current_frame ()),
4816 ecs
->event_thread
->step_frame_id
)
4817 && stepped_in_from (get_current_frame (),
4818 ecs
->event_thread
->step_frame_id
))
4821 fprintf_unfiltered (gdb_stdlog
,
4822 "infrun: stepping through inlined function\n");
4824 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
4828 ecs
->event_thread
->stop_step
= 1;
4829 print_stop_reason (END_STEPPING_RANGE
, 0);
4830 stop_stepping (ecs
);
4835 if ((stop_pc
== stop_pc_sal
.pc
)
4836 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
4837 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
4839 /* We are at the start of a different line. So stop. Note that
4840 we don't stop if we step into the middle of a different line.
4841 That is said to make things like for (;;) statements work
4844 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
4845 ecs
->event_thread
->stop_step
= 1;
4846 print_stop_reason (END_STEPPING_RANGE
, 0);
4847 stop_stepping (ecs
);
4851 /* We aren't done stepping.
4853 Optimize by setting the stepping range to the line.
4854 (We might not be in the original line, but if we entered a
4855 new line in mid-statement, we continue stepping. This makes
4856 things like for(;;) statements work better.) */
4858 ecs
->event_thread
->step_range_start
= stop_pc_sal
.pc
;
4859 ecs
->event_thread
->step_range_end
= stop_pc_sal
.end
;
4860 set_step_info (frame
, stop_pc_sal
);
4863 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
4867 /* Is thread TP in the middle of single-stepping? */
4870 currently_stepping (struct thread_info
*tp
)
4872 return ((tp
->step_range_end
&& tp
->step_resume_breakpoint
== NULL
)
4873 || tp
->trap_expected
4874 || tp
->stepping_through_solib_after_catch
4875 || bpstat_should_step ());
4878 /* Returns true if any thread *but* the one passed in "data" is in the
4879 middle of stepping or of handling a "next". */
4882 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
4887 return (tp
->step_range_end
4888 || tp
->trap_expected
4889 || tp
->stepping_through_solib_after_catch
);
4892 /* Inferior has stepped into a subroutine call with source code that
4893 we should not step over. Do step to the first line of code in
4897 handle_step_into_function (struct gdbarch
*gdbarch
,
4898 struct execution_control_state
*ecs
)
4901 struct symtab_and_line stop_func_sal
, sr_sal
;
4903 s
= find_pc_symtab (stop_pc
);
4904 if (s
&& s
->language
!= language_asm
)
4905 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
4906 ecs
->stop_func_start
);
4908 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4909 /* Use the step_resume_break to step until the end of the prologue,
4910 even if that involves jumps (as it seems to on the vax under
4912 /* If the prologue ends in the middle of a source line, continue to
4913 the end of that source line (if it is still within the function).
4914 Otherwise, just go to end of prologue. */
4915 if (stop_func_sal
.end
4916 && stop_func_sal
.pc
!= ecs
->stop_func_start
4917 && stop_func_sal
.end
< ecs
->stop_func_end
)
4918 ecs
->stop_func_start
= stop_func_sal
.end
;
4920 /* Architectures which require breakpoint adjustment might not be able
4921 to place a breakpoint at the computed address. If so, the test
4922 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
4923 ecs->stop_func_start to an address at which a breakpoint may be
4924 legitimately placed.
4926 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
4927 made, GDB will enter an infinite loop when stepping through
4928 optimized code consisting of VLIW instructions which contain
4929 subinstructions corresponding to different source lines. On
4930 FR-V, it's not permitted to place a breakpoint on any but the
4931 first subinstruction of a VLIW instruction. When a breakpoint is
4932 set, GDB will adjust the breakpoint address to the beginning of
4933 the VLIW instruction. Thus, we need to make the corresponding
4934 adjustment here when computing the stop address. */
4936 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
4938 ecs
->stop_func_start
4939 = gdbarch_adjust_breakpoint_address (gdbarch
,
4940 ecs
->stop_func_start
);
4943 if (ecs
->stop_func_start
== stop_pc
)
4945 /* We are already there: stop now. */
4946 ecs
->event_thread
->stop_step
= 1;
4947 print_stop_reason (END_STEPPING_RANGE
, 0);
4948 stop_stepping (ecs
);
4953 /* Put the step-breakpoint there and go until there. */
4954 init_sal (&sr_sal
); /* initialize to zeroes */
4955 sr_sal
.pc
= ecs
->stop_func_start
;
4956 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
4957 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
4959 /* Do not specify what the fp should be when we stop since on
4960 some machines the prologue is where the new fp value is
4962 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
4964 /* And make sure stepping stops right away then. */
4965 ecs
->event_thread
->step_range_end
= ecs
->event_thread
->step_range_start
;
4970 /* Inferior has stepped backward into a subroutine call with source
4971 code that we should not step over. Do step to the beginning of the
4972 last line of code in it. */
4975 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
4976 struct execution_control_state
*ecs
)
4979 struct symtab_and_line stop_func_sal
;
4981 s
= find_pc_symtab (stop_pc
);
4982 if (s
&& s
->language
!= language_asm
)
4983 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
4984 ecs
->stop_func_start
);
4986 stop_func_sal
= find_pc_line (stop_pc
, 0);
4988 /* OK, we're just going to keep stepping here. */
4989 if (stop_func_sal
.pc
== stop_pc
)
4991 /* We're there already. Just stop stepping now. */
4992 ecs
->event_thread
->stop_step
= 1;
4993 print_stop_reason (END_STEPPING_RANGE
, 0);
4994 stop_stepping (ecs
);
4998 /* Else just reset the step range and keep going.
4999 No step-resume breakpoint, they don't work for
5000 epilogues, which can have multiple entry paths. */
5001 ecs
->event_thread
->step_range_start
= stop_func_sal
.pc
;
5002 ecs
->event_thread
->step_range_end
= stop_func_sal
.end
;
5008 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5009 This is used to both functions and to skip over code. */
5012 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5013 struct symtab_and_line sr_sal
,
5014 struct frame_id sr_id
)
5016 /* There should never be more than one step-resume or longjmp-resume
5017 breakpoint per thread, so we should never be setting a new
5018 step_resume_breakpoint when one is already active. */
5019 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
5022 fprintf_unfiltered (gdb_stdlog
,
5023 "infrun: inserting step-resume breakpoint at %s\n",
5024 paddress (gdbarch
, sr_sal
.pc
));
5026 inferior_thread ()->step_resume_breakpoint
5027 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, bp_step_resume
);
5030 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
5031 to skip a potential signal handler.
5033 This is called with the interrupted function's frame. The signal
5034 handler, when it returns, will resume the interrupted function at
5038 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5040 struct symtab_and_line sr_sal
;
5041 struct gdbarch
*gdbarch
;
5043 gdb_assert (return_frame
!= NULL
);
5044 init_sal (&sr_sal
); /* initialize to zeros */
5046 gdbarch
= get_frame_arch (return_frame
);
5047 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5048 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5049 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5051 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5052 get_stack_frame_id (return_frame
));
5055 /* Similar to insert_step_resume_breakpoint_at_frame, except
5056 but a breakpoint at the previous frame's PC. This is used to
5057 skip a function after stepping into it (for "next" or if the called
5058 function has no debugging information).
5060 The current function has almost always been reached by single
5061 stepping a call or return instruction. NEXT_FRAME belongs to the
5062 current function, and the breakpoint will be set at the caller's
5065 This is a separate function rather than reusing
5066 insert_step_resume_breakpoint_at_frame in order to avoid
5067 get_prev_frame, which may stop prematurely (see the implementation
5068 of frame_unwind_caller_id for an example). */
5071 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5073 struct symtab_and_line sr_sal
;
5074 struct gdbarch
*gdbarch
;
5076 /* We shouldn't have gotten here if we don't know where the call site
5078 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5080 init_sal (&sr_sal
); /* initialize to zeros */
5082 gdbarch
= frame_unwind_caller_arch (next_frame
);
5083 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5084 frame_unwind_caller_pc (next_frame
));
5085 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5086 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5088 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5089 frame_unwind_caller_id (next_frame
));
5092 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5093 new breakpoint at the target of a jmp_buf. The handling of
5094 longjmp-resume uses the same mechanisms used for handling
5095 "step-resume" breakpoints. */
5098 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5100 /* There should never be more than one step-resume or longjmp-resume
5101 breakpoint per thread, so we should never be setting a new
5102 longjmp_resume_breakpoint when one is already active. */
5103 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
5106 fprintf_unfiltered (gdb_stdlog
,
5107 "infrun: inserting longjmp-resume breakpoint at %s\n",
5108 paddress (gdbarch
, pc
));
5110 inferior_thread ()->step_resume_breakpoint
=
5111 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5115 stop_stepping (struct execution_control_state
*ecs
)
5118 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5120 /* Let callers know we don't want to wait for the inferior anymore. */
5121 ecs
->wait_some_more
= 0;
5124 /* This function handles various cases where we need to continue
5125 waiting for the inferior. */
5126 /* (Used to be the keep_going: label in the old wait_for_inferior) */
5129 keep_going (struct execution_control_state
*ecs
)
5131 /* Make sure normal_stop is called if we get a QUIT handled before
5133 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5135 /* Save the pc before execution, to compare with pc after stop. */
5136 ecs
->event_thread
->prev_pc
5137 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5139 /* If we did not do break;, it means we should keep running the
5140 inferior and not return to debugger. */
5142 if (ecs
->event_thread
->trap_expected
5143 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
5145 /* We took a signal (which we are supposed to pass through to
5146 the inferior, else we'd not get here) and we haven't yet
5147 gotten our trap. Simply continue. */
5149 discard_cleanups (old_cleanups
);
5150 resume (currently_stepping (ecs
->event_thread
),
5151 ecs
->event_thread
->stop_signal
);
5155 /* Either the trap was not expected, but we are continuing
5156 anyway (the user asked that this signal be passed to the
5159 The signal was SIGTRAP, e.g. it was our signal, but we
5160 decided we should resume from it.
5162 We're going to run this baby now!
5164 Note that insert_breakpoints won't try to re-insert
5165 already inserted breakpoints. Therefore, we don't
5166 care if breakpoints were already inserted, or not. */
5168 if (ecs
->event_thread
->stepping_over_breakpoint
)
5170 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
5172 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
5173 /* Since we can't do a displaced step, we have to remove
5174 the breakpoint while we step it. To keep things
5175 simple, we remove them all. */
5176 remove_breakpoints ();
5180 struct gdb_exception e
;
5182 /* Stop stepping when inserting breakpoints
5184 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5186 insert_breakpoints ();
5190 exception_print (gdb_stderr
, e
);
5191 stop_stepping (ecs
);
5196 ecs
->event_thread
->trap_expected
= ecs
->event_thread
->stepping_over_breakpoint
;
5198 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5199 specifies that such a signal should be delivered to the
5202 Typically, this would occure when a user is debugging a
5203 target monitor on a simulator: the target monitor sets a
5204 breakpoint; the simulator encounters this break-point and
5205 halts the simulation handing control to GDB; GDB, noteing
5206 that the break-point isn't valid, returns control back to the
5207 simulator; the simulator then delivers the hardware
5208 equivalent of a SIGNAL_TRAP to the program being debugged. */
5210 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
5211 && !signal_program
[ecs
->event_thread
->stop_signal
])
5212 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
5214 discard_cleanups (old_cleanups
);
5215 resume (currently_stepping (ecs
->event_thread
),
5216 ecs
->event_thread
->stop_signal
);
5219 prepare_to_wait (ecs
);
5222 /* This function normally comes after a resume, before
5223 handle_inferior_event exits. It takes care of any last bits of
5224 housekeeping, and sets the all-important wait_some_more flag. */
5227 prepare_to_wait (struct execution_control_state
*ecs
)
5230 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5232 /* This is the old end of the while loop. Let everybody know we
5233 want to wait for the inferior some more and get called again
5235 ecs
->wait_some_more
= 1;
5238 /* Print why the inferior has stopped. We always print something when
5239 the inferior exits, or receives a signal. The rest of the cases are
5240 dealt with later on in normal_stop() and print_it_typical(). Ideally
5241 there should be a call to this function from handle_inferior_event()
5242 each time stop_stepping() is called.*/
5244 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
5246 switch (stop_reason
)
5248 case END_STEPPING_RANGE
:
5249 /* We are done with a step/next/si/ni command. */
5250 /* For now print nothing. */
5251 /* Print a message only if not in the middle of doing a "step n"
5252 operation for n > 1 */
5253 if (!inferior_thread ()->step_multi
5254 || !inferior_thread ()->stop_step
)
5255 if (ui_out_is_mi_like_p (uiout
))
5258 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5261 /* The inferior was terminated by a signal. */
5262 annotate_signalled ();
5263 if (ui_out_is_mi_like_p (uiout
))
5266 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5267 ui_out_text (uiout
, "\nProgram terminated with signal ");
5268 annotate_signal_name ();
5269 ui_out_field_string (uiout
, "signal-name",
5270 target_signal_to_name (stop_info
));
5271 annotate_signal_name_end ();
5272 ui_out_text (uiout
, ", ");
5273 annotate_signal_string ();
5274 ui_out_field_string (uiout
, "signal-meaning",
5275 target_signal_to_string (stop_info
));
5276 annotate_signal_string_end ();
5277 ui_out_text (uiout
, ".\n");
5278 ui_out_text (uiout
, "The program no longer exists.\n");
5281 /* The inferior program is finished. */
5282 annotate_exited (stop_info
);
5285 if (ui_out_is_mi_like_p (uiout
))
5286 ui_out_field_string (uiout
, "reason",
5287 async_reason_lookup (EXEC_ASYNC_EXITED
));
5288 ui_out_text (uiout
, "\nProgram exited with code ");
5289 ui_out_field_fmt (uiout
, "exit-code", "0%o",
5290 (unsigned int) stop_info
);
5291 ui_out_text (uiout
, ".\n");
5295 if (ui_out_is_mi_like_p (uiout
))
5298 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5299 ui_out_text (uiout
, "\nProgram exited normally.\n");
5301 /* Support the --return-child-result option. */
5302 return_child_result_value
= stop_info
;
5304 case SIGNAL_RECEIVED
:
5305 /* Signal received. The signal table tells us to print about
5309 if (stop_info
== TARGET_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5311 struct thread_info
*t
= inferior_thread ();
5313 ui_out_text (uiout
, "\n[");
5314 ui_out_field_string (uiout
, "thread-name",
5315 target_pid_to_str (t
->ptid
));
5316 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5317 ui_out_text (uiout
, " stopped");
5321 ui_out_text (uiout
, "\nProgram received signal ");
5322 annotate_signal_name ();
5323 if (ui_out_is_mi_like_p (uiout
))
5325 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
5326 ui_out_field_string (uiout
, "signal-name",
5327 target_signal_to_name (stop_info
));
5328 annotate_signal_name_end ();
5329 ui_out_text (uiout
, ", ");
5330 annotate_signal_string ();
5331 ui_out_field_string (uiout
, "signal-meaning",
5332 target_signal_to_string (stop_info
));
5333 annotate_signal_string_end ();
5335 ui_out_text (uiout
, ".\n");
5338 /* Reverse execution: target ran out of history info. */
5339 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
5342 internal_error (__FILE__
, __LINE__
,
5343 _("print_stop_reason: unrecognized enum value"));
5349 /* Here to return control to GDB when the inferior stops for real.
5350 Print appropriate messages, remove breakpoints, give terminal our modes.
5352 STOP_PRINT_FRAME nonzero means print the executing frame
5353 (pc, function, args, file, line number and line text).
5354 BREAKPOINTS_FAILED nonzero means stop was due to error
5355 attempting to insert breakpoints. */
5360 struct target_waitstatus last
;
5362 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5364 get_last_target_status (&last_ptid
, &last
);
5366 /* If an exception is thrown from this point on, make sure to
5367 propagate GDB's knowledge of the executing state to the
5368 frontend/user running state. A QUIT is an easy exception to see
5369 here, so do this before any filtered output. */
5371 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
5372 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5373 && last
.kind
!= TARGET_WAITKIND_EXITED
)
5374 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
5376 /* In non-stop mode, we don't want GDB to switch threads behind the
5377 user's back, to avoid races where the user is typing a command to
5378 apply to thread x, but GDB switches to thread y before the user
5379 finishes entering the command. */
5381 /* As with the notification of thread events, we want to delay
5382 notifying the user that we've switched thread context until
5383 the inferior actually stops.
5385 There's no point in saying anything if the inferior has exited.
5386 Note that SIGNALLED here means "exited with a signal", not
5387 "received a signal". */
5389 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
5390 && target_has_execution
5391 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5392 && last
.kind
!= TARGET_WAITKIND_EXITED
)
5394 target_terminal_ours_for_output ();
5395 printf_filtered (_("[Switching to %s]\n"),
5396 target_pid_to_str (inferior_ptid
));
5397 annotate_thread_changed ();
5398 previous_inferior_ptid
= inferior_ptid
;
5401 if (!breakpoints_always_inserted_mode () && target_has_execution
)
5403 if (remove_breakpoints ())
5405 target_terminal_ours_for_output ();
5406 printf_filtered (_("\
5407 Cannot remove breakpoints because program is no longer writable.\n\
5408 Further execution is probably impossible.\n"));
5412 /* If an auto-display called a function and that got a signal,
5413 delete that auto-display to avoid an infinite recursion. */
5415 if (stopped_by_random_signal
)
5416 disable_current_display ();
5418 /* Don't print a message if in the middle of doing a "step n"
5419 operation for n > 1 */
5420 if (target_has_execution
5421 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5422 && last
.kind
!= TARGET_WAITKIND_EXITED
5423 && inferior_thread ()->step_multi
5424 && inferior_thread ()->stop_step
)
5427 target_terminal_ours ();
5429 /* Set the current source location. This will also happen if we
5430 display the frame below, but the current SAL will be incorrect
5431 during a user hook-stop function. */
5432 if (has_stack_frames () && !stop_stack_dummy
)
5433 set_current_sal_from_frame (get_current_frame (), 1);
5435 /* Let the user/frontend see the threads as stopped. */
5436 do_cleanups (old_chain
);
5438 /* Look up the hook_stop and run it (CLI internally handles problem
5439 of stop_command's pre-hook not existing). */
5441 catch_errors (hook_stop_stub
, stop_command
,
5442 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
5444 if (!has_stack_frames ())
5447 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
5448 || last
.kind
== TARGET_WAITKIND_EXITED
)
5451 /* Select innermost stack frame - i.e., current frame is frame 0,
5452 and current location is based on that.
5453 Don't do this on return from a stack dummy routine,
5454 or if the program has exited. */
5456 if (!stop_stack_dummy
)
5458 select_frame (get_current_frame ());
5460 /* Print current location without a level number, if
5461 we have changed functions or hit a breakpoint.
5462 Print source line if we have one.
5463 bpstat_print() contains the logic deciding in detail
5464 what to print, based on the event(s) that just occurred. */
5466 /* If --batch-silent is enabled then there's no need to print the current
5467 source location, and to try risks causing an error message about
5468 missing source files. */
5469 if (stop_print_frame
&& !batch_silent
)
5473 int do_frame_printing
= 1;
5474 struct thread_info
*tp
= inferior_thread ();
5476 bpstat_ret
= bpstat_print (tp
->stop_bpstat
);
5480 /* If we had hit a shared library event breakpoint,
5481 bpstat_print would print out this message. If we hit
5482 an OS-level shared library event, do the same
5484 if (last
.kind
== TARGET_WAITKIND_LOADED
)
5486 printf_filtered (_("Stopped due to shared library event\n"));
5487 source_flag
= SRC_LINE
; /* something bogus */
5488 do_frame_printing
= 0;
5492 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5493 (or should) carry around the function and does (or
5494 should) use that when doing a frame comparison. */
5496 && frame_id_eq (tp
->step_frame_id
,
5497 get_frame_id (get_current_frame ()))
5498 && step_start_function
== find_pc_function (stop_pc
))
5499 source_flag
= SRC_LINE
; /* finished step, just print source line */
5501 source_flag
= SRC_AND_LOC
; /* print location and source line */
5503 case PRINT_SRC_AND_LOC
:
5504 source_flag
= SRC_AND_LOC
; /* print location and source line */
5506 case PRINT_SRC_ONLY
:
5507 source_flag
= SRC_LINE
;
5510 source_flag
= SRC_LINE
; /* something bogus */
5511 do_frame_printing
= 0;
5514 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
5517 /* The behavior of this routine with respect to the source
5519 SRC_LINE: Print only source line
5520 LOCATION: Print only location
5521 SRC_AND_LOC: Print location and source line */
5522 if (do_frame_printing
)
5523 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
5525 /* Display the auto-display expressions. */
5530 /* Save the function value return registers, if we care.
5531 We might be about to restore their previous contents. */
5532 if (inferior_thread ()->proceed_to_finish
)
5534 /* This should not be necessary. */
5536 regcache_xfree (stop_registers
);
5538 /* NB: The copy goes through to the target picking up the value of
5539 all the registers. */
5540 stop_registers
= regcache_dup (get_current_regcache ());
5543 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
5545 /* Pop the empty frame that contains the stack dummy.
5546 This also restores inferior state prior to the call
5547 (struct inferior_thread_state). */
5548 struct frame_info
*frame
= get_current_frame ();
5550 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
5552 /* frame_pop() calls reinit_frame_cache as the last thing it does
5553 which means there's currently no selected frame. We don't need
5554 to re-establish a selected frame if the dummy call returns normally,
5555 that will be done by restore_inferior_status. However, we do have
5556 to handle the case where the dummy call is returning after being
5557 stopped (e.g. the dummy call previously hit a breakpoint). We
5558 can't know which case we have so just always re-establish a
5559 selected frame here. */
5560 select_frame (get_current_frame ());
5564 annotate_stopped ();
5566 /* Suppress the stop observer if we're in the middle of:
5568 - a step n (n > 1), as there still more steps to be done.
5570 - a "finish" command, as the observer will be called in
5571 finish_command_continuation, so it can include the inferior
5572 function's return value.
5574 - calling an inferior function, as we pretend we inferior didn't
5575 run at all. The return value of the call is handled by the
5576 expression evaluator, through call_function_by_hand. */
5578 if (!target_has_execution
5579 || last
.kind
== TARGET_WAITKIND_SIGNALLED
5580 || last
.kind
== TARGET_WAITKIND_EXITED
5581 || (!inferior_thread ()->step_multi
5582 && !(inferior_thread ()->stop_bpstat
5583 && inferior_thread ()->proceed_to_finish
)
5584 && !inferior_thread ()->in_infcall
))
5586 if (!ptid_equal (inferior_ptid
, null_ptid
))
5587 observer_notify_normal_stop (inferior_thread ()->stop_bpstat
,
5590 observer_notify_normal_stop (NULL
, stop_print_frame
);
5593 if (target_has_execution
)
5595 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5596 && last
.kind
!= TARGET_WAITKIND_EXITED
)
5597 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5598 Delete any breakpoint that is to be deleted at the next stop. */
5599 breakpoint_auto_delete (inferior_thread ()->stop_bpstat
);
5602 /* Try to get rid of automatically added inferiors that are no
5603 longer needed. Keeping those around slows down things linearly.
5604 Note that this never removes the current inferior. */
5609 hook_stop_stub (void *cmd
)
5611 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
5616 signal_stop_state (int signo
)
5618 return signal_stop
[signo
];
5622 signal_print_state (int signo
)
5624 return signal_print
[signo
];
5628 signal_pass_state (int signo
)
5630 return signal_program
[signo
];
5634 signal_stop_update (int signo
, int state
)
5636 int ret
= signal_stop
[signo
];
5638 signal_stop
[signo
] = state
;
5643 signal_print_update (int signo
, int state
)
5645 int ret
= signal_print
[signo
];
5647 signal_print
[signo
] = state
;
5652 signal_pass_update (int signo
, int state
)
5654 int ret
= signal_program
[signo
];
5656 signal_program
[signo
] = state
;
5661 sig_print_header (void)
5663 printf_filtered (_("\
5664 Signal Stop\tPrint\tPass to program\tDescription\n"));
5668 sig_print_info (enum target_signal oursig
)
5670 const char *name
= target_signal_to_name (oursig
);
5671 int name_padding
= 13 - strlen (name
);
5673 if (name_padding
<= 0)
5676 printf_filtered ("%s", name
);
5677 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
5678 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
5679 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
5680 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
5681 printf_filtered ("%s\n", target_signal_to_string (oursig
));
5684 /* Specify how various signals in the inferior should be handled. */
5687 handle_command (char *args
, int from_tty
)
5690 int digits
, wordlen
;
5691 int sigfirst
, signum
, siglast
;
5692 enum target_signal oursig
;
5695 unsigned char *sigs
;
5696 struct cleanup
*old_chain
;
5700 error_no_arg (_("signal to handle"));
5703 /* Allocate and zero an array of flags for which signals to handle. */
5705 nsigs
= (int) TARGET_SIGNAL_LAST
;
5706 sigs
= (unsigned char *) alloca (nsigs
);
5707 memset (sigs
, 0, nsigs
);
5709 /* Break the command line up into args. */
5711 argv
= gdb_buildargv (args
);
5712 old_chain
= make_cleanup_freeargv (argv
);
5714 /* Walk through the args, looking for signal oursigs, signal names, and
5715 actions. Signal numbers and signal names may be interspersed with
5716 actions, with the actions being performed for all signals cumulatively
5717 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
5719 while (*argv
!= NULL
)
5721 wordlen
= strlen (*argv
);
5722 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
5726 sigfirst
= siglast
= -1;
5728 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
5730 /* Apply action to all signals except those used by the
5731 debugger. Silently skip those. */
5734 siglast
= nsigs
- 1;
5736 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
5738 SET_SIGS (nsigs
, sigs
, signal_stop
);
5739 SET_SIGS (nsigs
, sigs
, signal_print
);
5741 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
5743 UNSET_SIGS (nsigs
, sigs
, signal_program
);
5745 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
5747 SET_SIGS (nsigs
, sigs
, signal_print
);
5749 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
5751 SET_SIGS (nsigs
, sigs
, signal_program
);
5753 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
5755 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
5757 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
5759 SET_SIGS (nsigs
, sigs
, signal_program
);
5761 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
5763 UNSET_SIGS (nsigs
, sigs
, signal_print
);
5764 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
5766 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
5768 UNSET_SIGS (nsigs
, sigs
, signal_program
);
5770 else if (digits
> 0)
5772 /* It is numeric. The numeric signal refers to our own
5773 internal signal numbering from target.h, not to host/target
5774 signal number. This is a feature; users really should be
5775 using symbolic names anyway, and the common ones like
5776 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
5778 sigfirst
= siglast
= (int)
5779 target_signal_from_command (atoi (*argv
));
5780 if ((*argv
)[digits
] == '-')
5783 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
5785 if (sigfirst
> siglast
)
5787 /* Bet he didn't figure we'd think of this case... */
5795 oursig
= target_signal_from_name (*argv
);
5796 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
5798 sigfirst
= siglast
= (int) oursig
;
5802 /* Not a number and not a recognized flag word => complain. */
5803 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
5807 /* If any signal numbers or symbol names were found, set flags for
5808 which signals to apply actions to. */
5810 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
5812 switch ((enum target_signal
) signum
)
5814 case TARGET_SIGNAL_TRAP
:
5815 case TARGET_SIGNAL_INT
:
5816 if (!allsigs
&& !sigs
[signum
])
5818 if (query (_("%s is used by the debugger.\n\
5819 Are you sure you want to change it? "), target_signal_to_name ((enum target_signal
) signum
)))
5825 printf_unfiltered (_("Not confirmed, unchanged.\n"));
5826 gdb_flush (gdb_stdout
);
5830 case TARGET_SIGNAL_0
:
5831 case TARGET_SIGNAL_DEFAULT
:
5832 case TARGET_SIGNAL_UNKNOWN
:
5833 /* Make sure that "all" doesn't print these. */
5844 for (signum
= 0; signum
< nsigs
; signum
++)
5847 target_notice_signals (inferior_ptid
);
5851 /* Show the results. */
5852 sig_print_header ();
5853 for (; signum
< nsigs
; signum
++)
5855 sig_print_info (signum
);
5861 do_cleanups (old_chain
);
5865 xdb_handle_command (char *args
, int from_tty
)
5868 struct cleanup
*old_chain
;
5871 error_no_arg (_("xdb command"));
5873 /* Break the command line up into args. */
5875 argv
= gdb_buildargv (args
);
5876 old_chain
= make_cleanup_freeargv (argv
);
5877 if (argv
[1] != (char *) NULL
)
5882 bufLen
= strlen (argv
[0]) + 20;
5883 argBuf
= (char *) xmalloc (bufLen
);
5887 enum target_signal oursig
;
5889 oursig
= target_signal_from_name (argv
[0]);
5890 memset (argBuf
, 0, bufLen
);
5891 if (strcmp (argv
[1], "Q") == 0)
5892 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
5895 if (strcmp (argv
[1], "s") == 0)
5897 if (!signal_stop
[oursig
])
5898 sprintf (argBuf
, "%s %s", argv
[0], "stop");
5900 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
5902 else if (strcmp (argv
[1], "i") == 0)
5904 if (!signal_program
[oursig
])
5905 sprintf (argBuf
, "%s %s", argv
[0], "pass");
5907 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
5909 else if (strcmp (argv
[1], "r") == 0)
5911 if (!signal_print
[oursig
])
5912 sprintf (argBuf
, "%s %s", argv
[0], "print");
5914 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
5920 handle_command (argBuf
, from_tty
);
5922 printf_filtered (_("Invalid signal handling flag.\n"));
5927 do_cleanups (old_chain
);
5930 /* Print current contents of the tables set by the handle command.
5931 It is possible we should just be printing signals actually used
5932 by the current target (but for things to work right when switching
5933 targets, all signals should be in the signal tables). */
5936 signals_info (char *signum_exp
, int from_tty
)
5938 enum target_signal oursig
;
5940 sig_print_header ();
5944 /* First see if this is a symbol name. */
5945 oursig
= target_signal_from_name (signum_exp
);
5946 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
5948 /* No, try numeric. */
5950 target_signal_from_command (parse_and_eval_long (signum_exp
));
5952 sig_print_info (oursig
);
5956 printf_filtered ("\n");
5957 /* These ugly casts brought to you by the native VAX compiler. */
5958 for (oursig
= TARGET_SIGNAL_FIRST
;
5959 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
5960 oursig
= (enum target_signal
) ((int) oursig
+ 1))
5964 if (oursig
!= TARGET_SIGNAL_UNKNOWN
5965 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
5966 sig_print_info (oursig
);
5969 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
5972 /* The $_siginfo convenience variable is a bit special. We don't know
5973 for sure the type of the value until we actually have a chance to
5974 fetch the data. The type can change depending on gdbarch, so it it
5975 also dependent on which thread you have selected.
5977 1. making $_siginfo be an internalvar that creates a new value on
5980 2. making the value of $_siginfo be an lval_computed value. */
5982 /* This function implements the lval_computed support for reading a
5986 siginfo_value_read (struct value
*v
)
5988 LONGEST transferred
;
5991 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
5993 value_contents_all_raw (v
),
5995 TYPE_LENGTH (value_type (v
)));
5997 if (transferred
!= TYPE_LENGTH (value_type (v
)))
5998 error (_("Unable to read siginfo"));
6001 /* This function implements the lval_computed support for writing a
6005 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6007 LONGEST transferred
;
6009 transferred
= target_write (¤t_target
,
6010 TARGET_OBJECT_SIGNAL_INFO
,
6012 value_contents_all_raw (fromval
),
6014 TYPE_LENGTH (value_type (fromval
)));
6016 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6017 error (_("Unable to write siginfo"));
6020 static struct lval_funcs siginfo_value_funcs
=
6026 /* Return a new value with the correct type for the siginfo object of
6027 the current thread using architecture GDBARCH. Return a void value
6028 if there's no object available. */
6030 static struct value
*
6031 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
)
6033 if (target_has_stack
6034 && !ptid_equal (inferior_ptid
, null_ptid
)
6035 && gdbarch_get_siginfo_type_p (gdbarch
))
6037 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6039 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6042 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6046 /* Inferior thread state.
6047 These are details related to the inferior itself, and don't include
6048 things like what frame the user had selected or what gdb was doing
6049 with the target at the time.
6050 For inferior function calls these are things we want to restore
6051 regardless of whether the function call successfully completes
6052 or the dummy frame has to be manually popped. */
6054 struct inferior_thread_state
6056 enum target_signal stop_signal
;
6058 struct regcache
*registers
;
6061 struct inferior_thread_state
*
6062 save_inferior_thread_state (void)
6064 struct inferior_thread_state
*inf_state
= XMALLOC (struct inferior_thread_state
);
6065 struct thread_info
*tp
= inferior_thread ();
6067 inf_state
->stop_signal
= tp
->stop_signal
;
6068 inf_state
->stop_pc
= stop_pc
;
6070 inf_state
->registers
= regcache_dup (get_current_regcache ());
6075 /* Restore inferior session state to INF_STATE. */
6078 restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
6080 struct thread_info
*tp
= inferior_thread ();
6082 tp
->stop_signal
= inf_state
->stop_signal
;
6083 stop_pc
= inf_state
->stop_pc
;
6085 /* The inferior can be gone if the user types "print exit(0)"
6086 (and perhaps other times). */
6087 if (target_has_execution
)
6088 /* NB: The register write goes through to the target. */
6089 regcache_cpy (get_current_regcache (), inf_state
->registers
);
6090 regcache_xfree (inf_state
->registers
);
6095 do_restore_inferior_thread_state_cleanup (void *state
)
6097 restore_inferior_thread_state (state
);
6101 make_cleanup_restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
6103 return make_cleanup (do_restore_inferior_thread_state_cleanup
, inf_state
);
6107 discard_inferior_thread_state (struct inferior_thread_state
*inf_state
)
6109 regcache_xfree (inf_state
->registers
);
6114 get_inferior_thread_state_regcache (struct inferior_thread_state
*inf_state
)
6116 return inf_state
->registers
;
6119 /* Session related state for inferior function calls.
6120 These are the additional bits of state that need to be restored
6121 when an inferior function call successfully completes. */
6123 struct inferior_status
6127 enum stop_stack_kind stop_stack_dummy
;
6128 int stopped_by_random_signal
;
6129 int stepping_over_breakpoint
;
6130 CORE_ADDR step_range_start
;
6131 CORE_ADDR step_range_end
;
6132 struct frame_id step_frame_id
;
6133 struct frame_id step_stack_frame_id
;
6134 enum step_over_calls_kind step_over_calls
;
6135 CORE_ADDR step_resume_break_address
;
6136 int stop_after_trap
;
6139 /* ID if the selected frame when the inferior function call was made. */
6140 struct frame_id selected_frame_id
;
6142 int proceed_to_finish
;
6146 /* Save all of the information associated with the inferior<==>gdb
6149 struct inferior_status
*
6150 save_inferior_status (void)
6152 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
6153 struct thread_info
*tp
= inferior_thread ();
6154 struct inferior
*inf
= current_inferior ();
6156 inf_status
->stop_step
= tp
->stop_step
;
6157 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
6158 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
6159 inf_status
->stepping_over_breakpoint
= tp
->trap_expected
;
6160 inf_status
->step_range_start
= tp
->step_range_start
;
6161 inf_status
->step_range_end
= tp
->step_range_end
;
6162 inf_status
->step_frame_id
= tp
->step_frame_id
;
6163 inf_status
->step_stack_frame_id
= tp
->step_stack_frame_id
;
6164 inf_status
->step_over_calls
= tp
->step_over_calls
;
6165 inf_status
->stop_after_trap
= stop_after_trap
;
6166 inf_status
->stop_soon
= inf
->stop_soon
;
6167 /* Save original bpstat chain here; replace it with copy of chain.
6168 If caller's caller is walking the chain, they'll be happier if we
6169 hand them back the original chain when restore_inferior_status is
6171 inf_status
->stop_bpstat
= tp
->stop_bpstat
;
6172 tp
->stop_bpstat
= bpstat_copy (tp
->stop_bpstat
);
6173 inf_status
->proceed_to_finish
= tp
->proceed_to_finish
;
6174 inf_status
->in_infcall
= tp
->in_infcall
;
6176 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
6182 restore_selected_frame (void *args
)
6184 struct frame_id
*fid
= (struct frame_id
*) args
;
6185 struct frame_info
*frame
;
6187 frame
= frame_find_by_id (*fid
);
6189 /* If inf_status->selected_frame_id is NULL, there was no previously
6193 warning (_("Unable to restore previously selected frame."));
6197 select_frame (frame
);
6202 /* Restore inferior session state to INF_STATUS. */
6205 restore_inferior_status (struct inferior_status
*inf_status
)
6207 struct thread_info
*tp
= inferior_thread ();
6208 struct inferior
*inf
= current_inferior ();
6210 tp
->stop_step
= inf_status
->stop_step
;
6211 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
6212 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
6213 tp
->trap_expected
= inf_status
->stepping_over_breakpoint
;
6214 tp
->step_range_start
= inf_status
->step_range_start
;
6215 tp
->step_range_end
= inf_status
->step_range_end
;
6216 tp
->step_frame_id
= inf_status
->step_frame_id
;
6217 tp
->step_stack_frame_id
= inf_status
->step_stack_frame_id
;
6218 tp
->step_over_calls
= inf_status
->step_over_calls
;
6219 stop_after_trap
= inf_status
->stop_after_trap
;
6220 inf
->stop_soon
= inf_status
->stop_soon
;
6221 bpstat_clear (&tp
->stop_bpstat
);
6222 tp
->stop_bpstat
= inf_status
->stop_bpstat
;
6223 inf_status
->stop_bpstat
= NULL
;
6224 tp
->proceed_to_finish
= inf_status
->proceed_to_finish
;
6225 tp
->in_infcall
= inf_status
->in_infcall
;
6227 if (target_has_stack
)
6229 /* The point of catch_errors is that if the stack is clobbered,
6230 walking the stack might encounter a garbage pointer and
6231 error() trying to dereference it. */
6233 (restore_selected_frame
, &inf_status
->selected_frame_id
,
6234 "Unable to restore previously selected frame:\n",
6235 RETURN_MASK_ERROR
) == 0)
6236 /* Error in restoring the selected frame. Select the innermost
6238 select_frame (get_current_frame ());
6245 do_restore_inferior_status_cleanup (void *sts
)
6247 restore_inferior_status (sts
);
6251 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
6253 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
6257 discard_inferior_status (struct inferior_status
*inf_status
)
6259 /* See save_inferior_status for info on stop_bpstat. */
6260 bpstat_clear (&inf_status
->stop_bpstat
);
6265 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
6267 struct target_waitstatus last
;
6270 get_last_target_status (&last_ptid
, &last
);
6272 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
6275 if (!ptid_equal (last_ptid
, pid
))
6278 *child_pid
= last
.value
.related_pid
;
6283 inferior_has_vforked (ptid_t pid
, ptid_t
*child_pid
)
6285 struct target_waitstatus last
;
6288 get_last_target_status (&last_ptid
, &last
);
6290 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
6293 if (!ptid_equal (last_ptid
, pid
))
6296 *child_pid
= last
.value
.related_pid
;
6301 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
6303 struct target_waitstatus last
;
6306 get_last_target_status (&last_ptid
, &last
);
6308 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
6311 if (!ptid_equal (last_ptid
, pid
))
6314 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
6319 inferior_has_called_syscall (ptid_t pid
, int *syscall_number
)
6321 struct target_waitstatus last
;
6324 get_last_target_status (&last_ptid
, &last
);
6326 if (last
.kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
&&
6327 last
.kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
6330 if (!ptid_equal (last_ptid
, pid
))
6333 *syscall_number
= last
.value
.syscall_number
;
6337 /* Oft used ptids */
6339 ptid_t minus_one_ptid
;
6341 /* Create a ptid given the necessary PID, LWP, and TID components. */
6344 ptid_build (int pid
, long lwp
, long tid
)
6354 /* Create a ptid from just a pid. */
6357 pid_to_ptid (int pid
)
6359 return ptid_build (pid
, 0, 0);
6362 /* Fetch the pid (process id) component from a ptid. */
6365 ptid_get_pid (ptid_t ptid
)
6370 /* Fetch the lwp (lightweight process) component from a ptid. */
6373 ptid_get_lwp (ptid_t ptid
)
6378 /* Fetch the tid (thread id) component from a ptid. */
6381 ptid_get_tid (ptid_t ptid
)
6386 /* ptid_equal() is used to test equality of two ptids. */
6389 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
6391 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
6392 && ptid1
.tid
== ptid2
.tid
);
6395 /* Returns true if PTID represents a process. */
6398 ptid_is_pid (ptid_t ptid
)
6400 if (ptid_equal (minus_one_ptid
, ptid
))
6402 if (ptid_equal (null_ptid
, ptid
))
6405 return (ptid_get_lwp (ptid
) == 0 && ptid_get_tid (ptid
) == 0);
6409 ptid_match (ptid_t ptid
, ptid_t filter
)
6411 /* Since both parameters have the same type, prevent easy mistakes
6413 gdb_assert (!ptid_equal (ptid
, minus_one_ptid
)
6414 && !ptid_equal (ptid
, null_ptid
));
6416 if (ptid_equal (filter
, minus_one_ptid
))
6418 if (ptid_is_pid (filter
)
6419 && ptid_get_pid (ptid
) == ptid_get_pid (filter
))
6421 else if (ptid_equal (ptid
, filter
))
6427 /* restore_inferior_ptid() will be used by the cleanup machinery
6428 to restore the inferior_ptid value saved in a call to
6429 save_inferior_ptid(). */
6432 restore_inferior_ptid (void *arg
)
6434 ptid_t
*saved_ptid_ptr
= arg
;
6436 inferior_ptid
= *saved_ptid_ptr
;
6440 /* Save the value of inferior_ptid so that it may be restored by a
6441 later call to do_cleanups(). Returns the struct cleanup pointer
6442 needed for later doing the cleanup. */
6445 save_inferior_ptid (void)
6447 ptid_t
*saved_ptid_ptr
;
6449 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
6450 *saved_ptid_ptr
= inferior_ptid
;
6451 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
6455 /* User interface for reverse debugging:
6456 Set exec-direction / show exec-direction commands
6457 (returns error unless target implements to_set_exec_direction method). */
6459 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
6460 static const char exec_forward
[] = "forward";
6461 static const char exec_reverse
[] = "reverse";
6462 static const char *exec_direction
= exec_forward
;
6463 static const char *exec_direction_names
[] = {
6470 set_exec_direction_func (char *args
, int from_tty
,
6471 struct cmd_list_element
*cmd
)
6473 if (target_can_execute_reverse
)
6475 if (!strcmp (exec_direction
, exec_forward
))
6476 execution_direction
= EXEC_FORWARD
;
6477 else if (!strcmp (exec_direction
, exec_reverse
))
6478 execution_direction
= EXEC_REVERSE
;
6483 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
6484 struct cmd_list_element
*cmd
, const char *value
)
6486 switch (execution_direction
) {
6488 fprintf_filtered (out
, _("Forward.\n"));
6491 fprintf_filtered (out
, _("Reverse.\n"));
6495 fprintf_filtered (out
,
6496 _("Forward (target `%s' does not support exec-direction).\n"),
6502 /* User interface for non-stop mode. */
6507 set_non_stop (char *args
, int from_tty
,
6508 struct cmd_list_element
*c
)
6510 if (target_has_execution
)
6512 non_stop_1
= non_stop
;
6513 error (_("Cannot change this setting while the inferior is running."));
6516 non_stop
= non_stop_1
;
6520 show_non_stop (struct ui_file
*file
, int from_tty
,
6521 struct cmd_list_element
*c
, const char *value
)
6523 fprintf_filtered (file
,
6524 _("Controlling the inferior in non-stop mode is %s.\n"),
6529 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
6530 struct cmd_list_element
*c
, const char *value
)
6532 fprintf_filtered (file
, _("\
6533 Resuming the execution of threads of all processes is %s.\n"), value
);
6537 _initialize_infrun (void)
6542 add_info ("signals", signals_info
, _("\
6543 What debugger does when program gets various signals.\n\
6544 Specify a signal as argument to print info on that signal only."));
6545 add_info_alias ("handle", "signals", 0);
6547 add_com ("handle", class_run
, handle_command
, _("\
6548 Specify how to handle a signal.\n\
6549 Args are signals and actions to apply to those signals.\n\
6550 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6551 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6552 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6553 The special arg \"all\" is recognized to mean all signals except those\n\
6554 used by the debugger, typically SIGTRAP and SIGINT.\n\
6555 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6556 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6557 Stop means reenter debugger if this signal happens (implies print).\n\
6558 Print means print a message if this signal happens.\n\
6559 Pass means let program see this signal; otherwise program doesn't know.\n\
6560 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6561 Pass and Stop may be combined."));
6564 add_com ("lz", class_info
, signals_info
, _("\
6565 What debugger does when program gets various signals.\n\
6566 Specify a signal as argument to print info on that signal only."));
6567 add_com ("z", class_run
, xdb_handle_command
, _("\
6568 Specify how to handle a signal.\n\
6569 Args are signals and actions to apply to those signals.\n\
6570 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6571 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6572 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6573 The special arg \"all\" is recognized to mean all signals except those\n\
6574 used by the debugger, typically SIGTRAP and SIGINT.\n\
6575 Recognized actions include \"s\" (toggles between stop and nostop), \n\
6576 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6577 nopass), \"Q\" (noprint)\n\
6578 Stop means reenter debugger if this signal happens (implies print).\n\
6579 Print means print a message if this signal happens.\n\
6580 Pass means let program see this signal; otherwise program doesn't know.\n\
6581 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6582 Pass and Stop may be combined."));
6586 stop_command
= add_cmd ("stop", class_obscure
,
6587 not_just_help_class_command
, _("\
6588 There is no `stop' command, but you can set a hook on `stop'.\n\
6589 This allows you to set a list of commands to be run each time execution\n\
6590 of the program stops."), &cmdlist
);
6592 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
6593 Set inferior debugging."), _("\
6594 Show inferior debugging."), _("\
6595 When non-zero, inferior specific debugging is enabled."),
6598 &setdebuglist
, &showdebuglist
);
6600 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
6601 Set displaced stepping debugging."), _("\
6602 Show displaced stepping debugging."), _("\
6603 When non-zero, displaced stepping specific debugging is enabled."),
6605 show_debug_displaced
,
6606 &setdebuglist
, &showdebuglist
);
6608 add_setshow_boolean_cmd ("non-stop", no_class
,
6610 Set whether gdb controls the inferior in non-stop mode."), _("\
6611 Show whether gdb controls the inferior in non-stop mode."), _("\
6612 When debugging a multi-threaded program and this setting is\n\
6613 off (the default, also called all-stop mode), when one thread stops\n\
6614 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
6615 all other threads in the program while you interact with the thread of\n\
6616 interest. When you continue or step a thread, you can allow the other\n\
6617 threads to run, or have them remain stopped, but while you inspect any\n\
6618 thread's state, all threads stop.\n\
6620 In non-stop mode, when one thread stops, other threads can continue\n\
6621 to run freely. You'll be able to step each thread independently,\n\
6622 leave it stopped or free to run as needed."),
6628 numsigs
= (int) TARGET_SIGNAL_LAST
;
6629 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
6630 signal_print
= (unsigned char *)
6631 xmalloc (sizeof (signal_print
[0]) * numsigs
);
6632 signal_program
= (unsigned char *)
6633 xmalloc (sizeof (signal_program
[0]) * numsigs
);
6634 for (i
= 0; i
< numsigs
; i
++)
6637 signal_print
[i
] = 1;
6638 signal_program
[i
] = 1;
6641 /* Signals caused by debugger's own actions
6642 should not be given to the program afterwards. */
6643 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
6644 signal_program
[TARGET_SIGNAL_INT
] = 0;
6646 /* Signals that are not errors should not normally enter the debugger. */
6647 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
6648 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
6649 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
6650 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
6651 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
6652 signal_print
[TARGET_SIGNAL_PROF
] = 0;
6653 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
6654 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
6655 signal_stop
[TARGET_SIGNAL_IO
] = 0;
6656 signal_print
[TARGET_SIGNAL_IO
] = 0;
6657 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
6658 signal_print
[TARGET_SIGNAL_POLL
] = 0;
6659 signal_stop
[TARGET_SIGNAL_URG
] = 0;
6660 signal_print
[TARGET_SIGNAL_URG
] = 0;
6661 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
6662 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
6664 /* These signals are used internally by user-level thread
6665 implementations. (See signal(5) on Solaris.) Like the above
6666 signals, a healthy program receives and handles them as part of
6667 its normal operation. */
6668 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
6669 signal_print
[TARGET_SIGNAL_LWP
] = 0;
6670 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
6671 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
6672 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
6673 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
6675 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
6676 &stop_on_solib_events
, _("\
6677 Set stopping for shared library events."), _("\
6678 Show stopping for shared library events."), _("\
6679 If nonzero, gdb will give control to the user when the dynamic linker\n\
6680 notifies gdb of shared library events. The most common event of interest\n\
6681 to the user would be loading/unloading of a new library."),
6683 show_stop_on_solib_events
,
6684 &setlist
, &showlist
);
6686 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
6687 follow_fork_mode_kind_names
,
6688 &follow_fork_mode_string
, _("\
6689 Set debugger response to a program call of fork or vfork."), _("\
6690 Show debugger response to a program call of fork or vfork."), _("\
6691 A fork or vfork creates a new process. follow-fork-mode can be:\n\
6692 parent - the original process is debugged after a fork\n\
6693 child - the new process is debugged after a fork\n\
6694 The unfollowed process will continue to run.\n\
6695 By default, the debugger will follow the parent process."),
6697 show_follow_fork_mode_string
,
6698 &setlist
, &showlist
);
6700 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
6701 follow_exec_mode_names
,
6702 &follow_exec_mode_string
, _("\
6703 Set debugger response to a program call of exec."), _("\
6704 Show debugger response to a program call of exec."), _("\
6705 An exec call replaces the program image of a process.\n\
6707 follow-exec-mode can be:\n\
6709 new - the debugger creates a new inferior and rebinds the process \n\
6710 to this new inferior. The program the process was running before\n\
6711 the exec call can be restarted afterwards by restarting the original\n\
6714 same - the debugger keeps the process bound to the same inferior.\n\
6715 The new executable image replaces the previous executable loaded in\n\
6716 the inferior. Restarting the inferior after the exec call restarts\n\
6717 the executable the process was running after the exec call.\n\
6719 By default, the debugger will use the same inferior."),
6721 show_follow_exec_mode_string
,
6722 &setlist
, &showlist
);
6724 add_setshow_enum_cmd ("scheduler-locking", class_run
,
6725 scheduler_enums
, &scheduler_mode
, _("\
6726 Set mode for locking scheduler during execution."), _("\
6727 Show mode for locking scheduler during execution."), _("\
6728 off == no locking (threads may preempt at any time)\n\
6729 on == full locking (no thread except the current thread may run)\n\
6730 step == scheduler locked during every single-step operation.\n\
6731 In this mode, no other thread may run during a step command.\n\
6732 Other threads may run while stepping over a function call ('next')."),
6733 set_schedlock_func
, /* traps on target vector */
6734 show_scheduler_mode
,
6735 &setlist
, &showlist
);
6737 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
6738 Set mode for resuming threads of all processes."), _("\
6739 Show mode for resuming threads of all processes."), _("\
6740 When on, execution commands (such as 'continue' or 'next') resume all\n\
6741 threads of all processes. When off (which is the default), execution\n\
6742 commands only resume the threads of the current process. The set of\n\
6743 threads that are resumed is further refined by the scheduler-locking\n\
6744 mode (see help set scheduler-locking)."),
6746 show_schedule_multiple
,
6747 &setlist
, &showlist
);
6749 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
6750 Set mode of the step operation."), _("\
6751 Show mode of the step operation."), _("\
6752 When set, doing a step over a function without debug line information\n\
6753 will stop at the first instruction of that function. Otherwise, the\n\
6754 function is skipped and the step command stops at a different source line."),
6756 show_step_stop_if_no_debug
,
6757 &setlist
, &showlist
);
6759 add_setshow_enum_cmd ("displaced-stepping", class_run
,
6760 can_use_displaced_stepping_enum
,
6761 &can_use_displaced_stepping
, _("\
6762 Set debugger's willingness to use displaced stepping."), _("\
6763 Show debugger's willingness to use displaced stepping."), _("\
6764 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
6765 supported by the target architecture. If off, gdb will not use displaced\n\
6766 stepping to step over breakpoints, even if such is supported by the target\n\
6767 architecture. If auto (which is the default), gdb will use displaced stepping\n\
6768 if the target architecture supports it and non-stop mode is active, but will not\n\
6769 use it in all-stop mode (see help set non-stop)."),
6771 show_can_use_displaced_stepping
,
6772 &setlist
, &showlist
);
6774 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
6775 &exec_direction
, _("Set direction of execution.\n\
6776 Options are 'forward' or 'reverse'."),
6777 _("Show direction of execution (forward/reverse)."),
6778 _("Tells gdb whether to execute forward or backward."),
6779 set_exec_direction_func
, show_exec_direction_func
,
6780 &setlist
, &showlist
);
6782 /* Set/show detach-on-fork: user-settable mode. */
6784 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
6785 Set whether gdb will detach the child of a fork."), _("\
6786 Show whether gdb will detach the child of a fork."), _("\
6787 Tells gdb whether to detach the child of a fork."),
6788 NULL
, NULL
, &setlist
, &showlist
);
6790 /* ptid initializations */
6791 null_ptid
= ptid_build (0, 0, 0);
6792 minus_one_ptid
= ptid_build (-1, 0, 0);
6793 inferior_ptid
= null_ptid
;
6794 target_last_wait_ptid
= minus_one_ptid
;
6796 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
6797 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
6798 observer_attach_thread_exit (infrun_thread_thread_exit
);
6799 observer_attach_inferior_exit (infrun_inferior_exit
);
6801 /* Explicitly create without lookup, since that tries to create a
6802 value with a void typed value, and when we get here, gdbarch
6803 isn't initialized yet. At this point, we're quite sure there
6804 isn't another convenience variable of the same name. */
6805 create_internalvar_type_lazy ("_siginfo", siginfo_make_value
);
6807 add_setshow_boolean_cmd ("observer", no_class
,
6808 &observer_mode_1
, _("\
6809 Set whether gdb controls the inferior in observer mode."), _("\
6810 Show whether gdb controls the inferior in observer mode."), _("\
6811 In observer mode, GDB can get data from the inferior, but not\n\
6812 affect its execution. Registers and memory may not be changed,\n\
6813 breakpoints may not be set, and the program cannot be interrupted\n\