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"
55 /* Prototypes for local functions */
57 static void signals_info (char *, int);
59 static void handle_command (char *, int);
61 static void sig_print_info (enum target_signal
);
63 static void sig_print_header (void);
65 static void resume_cleanups (void *);
67 static int hook_stop_stub (void *);
69 static int restore_selected_frame (void *);
71 static int follow_fork (void);
73 static void set_schedlock_func (char *args
, int from_tty
,
74 struct cmd_list_element
*c
);
76 static int currently_stepping (struct thread_info
*tp
);
78 static int currently_stepping_or_nexting_callback (struct thread_info
*tp
,
81 static void xdb_handle_command (char *args
, int from_tty
);
83 static int prepare_to_proceed (int);
85 void _initialize_infrun (void);
87 void nullify_last_target_wait_ptid (void);
89 /* When set, stop the 'step' command if we enter a function which has
90 no line number information. The normal behavior is that we step
91 over such function. */
92 int step_stop_if_no_debug
= 0;
94 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
95 struct cmd_list_element
*c
, const char *value
)
97 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
100 /* In asynchronous mode, but simulating synchronous execution. */
102 int sync_execution
= 0;
104 /* wait_for_inferior and normal_stop use this to notify the user
105 when the inferior stopped in a different thread than it had been
108 static ptid_t previous_inferior_ptid
;
110 /* Default behavior is to detach newly forked processes (legacy). */
113 int debug_displaced
= 0;
115 show_debug_displaced (struct ui_file
*file
, int from_tty
,
116 struct cmd_list_element
*c
, const char *value
)
118 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
121 static int debug_infrun
= 0;
123 show_debug_infrun (struct ui_file
*file
, int from_tty
,
124 struct cmd_list_element
*c
, const char *value
)
126 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
129 /* If the program uses ELF-style shared libraries, then calls to
130 functions in shared libraries go through stubs, which live in a
131 table called the PLT (Procedure Linkage Table). The first time the
132 function is called, the stub sends control to the dynamic linker,
133 which looks up the function's real address, patches the stub so
134 that future calls will go directly to the function, and then passes
135 control to the function.
137 If we are stepping at the source level, we don't want to see any of
138 this --- we just want to skip over the stub and the dynamic linker.
139 The simple approach is to single-step until control leaves the
142 However, on some systems (e.g., Red Hat's 5.2 distribution) the
143 dynamic linker calls functions in the shared C library, so you
144 can't tell from the PC alone whether the dynamic linker is still
145 running. In this case, we use a step-resume breakpoint to get us
146 past the dynamic linker, as if we were using "next" to step over a
149 in_solib_dynsym_resolve_code() says whether we're in the dynamic
150 linker code or not. Normally, this means we single-step. However,
151 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
152 address where we can place a step-resume breakpoint to get past the
153 linker's symbol resolution function.
155 in_solib_dynsym_resolve_code() can generally be implemented in a
156 pretty portable way, by comparing the PC against the address ranges
157 of the dynamic linker's sections.
159 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
160 it depends on internal details of the dynamic linker. It's usually
161 not too hard to figure out where to put a breakpoint, but it
162 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
163 sanity checking. If it can't figure things out, returning zero and
164 getting the (possibly confusing) stepping behavior is better than
165 signalling an error, which will obscure the change in the
168 /* This function returns TRUE if pc is the address of an instruction
169 that lies within the dynamic linker (such as the event hook, or the
172 This function must be used only when a dynamic linker event has
173 been caught, and the inferior is being stepped out of the hook, or
174 undefined results are guaranteed. */
176 #ifndef SOLIB_IN_DYNAMIC_LINKER
177 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
181 /* Convert the #defines into values. This is temporary until wfi control
182 flow is completely sorted out. */
184 #ifndef CANNOT_STEP_HW_WATCHPOINTS
185 #define CANNOT_STEP_HW_WATCHPOINTS 0
187 #undef CANNOT_STEP_HW_WATCHPOINTS
188 #define CANNOT_STEP_HW_WATCHPOINTS 1
191 /* Tables of how to react to signals; the user sets them. */
193 static unsigned char *signal_stop
;
194 static unsigned char *signal_print
;
195 static unsigned char *signal_program
;
197 #define SET_SIGS(nsigs,sigs,flags) \
199 int signum = (nsigs); \
200 while (signum-- > 0) \
201 if ((sigs)[signum]) \
202 (flags)[signum] = 1; \
205 #define UNSET_SIGS(nsigs,sigs,flags) \
207 int signum = (nsigs); \
208 while (signum-- > 0) \
209 if ((sigs)[signum]) \
210 (flags)[signum] = 0; \
213 /* Value to pass to target_resume() to cause all threads to resume */
215 #define RESUME_ALL minus_one_ptid
217 /* Command list pointer for the "stop" placeholder. */
219 static struct cmd_list_element
*stop_command
;
221 /* Function inferior was in as of last step command. */
223 static struct symbol
*step_start_function
;
225 /* Nonzero if we want to give control to the user when we're notified
226 of shared library events by the dynamic linker. */
227 static int stop_on_solib_events
;
229 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
230 struct cmd_list_element
*c
, const char *value
)
232 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
236 /* Nonzero means expecting a trace trap
237 and should stop the inferior and return silently when it happens. */
241 /* Save register contents here when executing a "finish" command or are
242 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
243 Thus this contains the return value from the called function (assuming
244 values are returned in a register). */
246 struct regcache
*stop_registers
;
248 /* Nonzero after stop if current stack frame should be printed. */
250 static int stop_print_frame
;
252 /* This is a cached copy of the pid/waitstatus of the last event
253 returned by target_wait()/deprecated_target_wait_hook(). This
254 information is returned by get_last_target_status(). */
255 static ptid_t target_last_wait_ptid
;
256 static struct target_waitstatus target_last_waitstatus
;
258 static void context_switch (ptid_t ptid
);
260 void init_thread_stepping_state (struct thread_info
*tss
);
262 void init_infwait_state (void);
264 static const char follow_fork_mode_child
[] = "child";
265 static const char follow_fork_mode_parent
[] = "parent";
267 static const char *follow_fork_mode_kind_names
[] = {
268 follow_fork_mode_child
,
269 follow_fork_mode_parent
,
273 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
275 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
276 struct cmd_list_element
*c
, const char *value
)
278 fprintf_filtered (file
, _("\
279 Debugger response to a program call of fork or vfork is \"%s\".\n"),
284 /* Tell the target to follow the fork we're stopped at. Returns true
285 if the inferior should be resumed; false, if the target for some
286 reason decided it's best not to resume. */
291 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
292 int should_resume
= 1;
293 struct thread_info
*tp
;
295 /* Copy user stepping state to the new inferior thread. FIXME: the
296 followed fork child thread should have a copy of most of the
297 parent thread structure's run control related fields, not just these.
298 Initialized to avoid "may be used uninitialized" warnings from gcc. */
299 struct breakpoint
*step_resume_breakpoint
= NULL
;
300 CORE_ADDR step_range_start
= 0;
301 CORE_ADDR step_range_end
= 0;
302 struct frame_id step_frame_id
= { 0 };
307 struct target_waitstatus wait_status
;
309 /* Get the last target status returned by target_wait(). */
310 get_last_target_status (&wait_ptid
, &wait_status
);
312 /* If not stopped at a fork event, then there's nothing else to
314 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
315 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
318 /* Check if we switched over from WAIT_PTID, since the event was
320 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
321 && !ptid_equal (inferior_ptid
, wait_ptid
))
323 /* We did. Switch back to WAIT_PTID thread, to tell the
324 target to follow it (in either direction). We'll
325 afterwards refuse to resume, and inform the user what
327 switch_to_thread (wait_ptid
);
332 tp
= inferior_thread ();
334 /* If there were any forks/vforks that were caught and are now to be
335 followed, then do so now. */
336 switch (tp
->pending_follow
.kind
)
338 case TARGET_WAITKIND_FORKED
:
339 case TARGET_WAITKIND_VFORKED
:
341 ptid_t parent
, child
;
343 /* If the user did a next/step, etc, over a fork call,
344 preserve the stepping state in the fork child. */
345 if (follow_child
&& should_resume
)
347 step_resume_breakpoint
348 = clone_momentary_breakpoint (tp
->step_resume_breakpoint
);
349 step_range_start
= tp
->step_range_start
;
350 step_range_end
= tp
->step_range_end
;
351 step_frame_id
= tp
->step_frame_id
;
353 /* For now, delete the parent's sr breakpoint, otherwise,
354 parent/child sr breakpoints are considered duplicates,
355 and the child version will not be installed. Remove
356 this when the breakpoints module becomes aware of
357 inferiors and address spaces. */
358 delete_step_resume_breakpoint (tp
);
359 tp
->step_range_start
= 0;
360 tp
->step_range_end
= 0;
361 tp
->step_frame_id
= null_frame_id
;
364 parent
= inferior_ptid
;
365 child
= tp
->pending_follow
.value
.related_pid
;
367 /* Tell the target to do whatever is necessary to follow
368 either parent or child. */
369 if (target_follow_fork (follow_child
))
371 /* Target refused to follow, or there's some other reason
372 we shouldn't resume. */
377 /* This pending follow fork event is now handled, one way
378 or another. The previous selected thread may be gone
379 from the lists by now, but if it is still around, need
380 to clear the pending follow request. */
381 tp
= find_thread_ptid (parent
);
383 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
385 /* This makes sure we don't try to apply the "Switched
386 over from WAIT_PID" logic above. */
387 nullify_last_target_wait_ptid ();
389 /* If we followed the child, switch to it... */
392 switch_to_thread (child
);
394 /* ... and preserve the stepping state, in case the
395 user was stepping over the fork call. */
398 tp
= inferior_thread ();
399 tp
->step_resume_breakpoint
= step_resume_breakpoint
;
400 tp
->step_range_start
= step_range_start
;
401 tp
->step_range_end
= step_range_end
;
402 tp
->step_frame_id
= step_frame_id
;
406 /* If we get here, it was because we're trying to
407 resume from a fork catchpoint, but, the user
408 has switched threads away from the thread that
409 forked. In that case, the resume command
410 issued is most likely not applicable to the
411 child, so just warn, and refuse to resume. */
413 Not resuming: switched threads before following fork child.\n"));
416 /* Reset breakpoints in the child as appropriate. */
417 follow_inferior_reset_breakpoints ();
420 switch_to_thread (parent
);
424 case TARGET_WAITKIND_SPURIOUS
:
425 /* Nothing to follow. */
428 internal_error (__FILE__
, __LINE__
,
429 "Unexpected pending_follow.kind %d\n",
430 tp
->pending_follow
.kind
);
434 return should_resume
;
438 follow_inferior_reset_breakpoints (void)
440 struct thread_info
*tp
= inferior_thread ();
442 /* Was there a step_resume breakpoint? (There was if the user
443 did a "next" at the fork() call.) If so, explicitly reset its
446 step_resumes are a form of bp that are made to be per-thread.
447 Since we created the step_resume bp when the parent process
448 was being debugged, and now are switching to the child process,
449 from the breakpoint package's viewpoint, that's a switch of
450 "threads". We must update the bp's notion of which thread
451 it is for, or it'll be ignored when it triggers. */
453 if (tp
->step_resume_breakpoint
)
454 breakpoint_re_set_thread (tp
->step_resume_breakpoint
);
456 /* Reinsert all breakpoints in the child. The user may have set
457 breakpoints after catching the fork, in which case those
458 were never set in the child, but only in the parent. This makes
459 sure the inserted breakpoints match the breakpoint list. */
461 breakpoint_re_set ();
462 insert_breakpoints ();
465 /* The child has exited or execed: resume threads of the parent the
466 user wanted to be executing. */
469 proceed_after_vfork_done (struct thread_info
*thread
,
472 int pid
= * (int *) arg
;
474 if (ptid_get_pid (thread
->ptid
) == pid
475 && is_running (thread
->ptid
)
476 && !is_executing (thread
->ptid
)
477 && !thread
->stop_requested
478 && thread
->stop_signal
== TARGET_SIGNAL_0
)
481 fprintf_unfiltered (gdb_stdlog
,
482 "infrun: resuming vfork parent thread %s\n",
483 target_pid_to_str (thread
->ptid
));
485 switch_to_thread (thread
->ptid
);
486 clear_proceed_status ();
487 proceed ((CORE_ADDR
) -1, TARGET_SIGNAL_DEFAULT
, 0);
493 /* Called whenever we notice an exec or exit event, to handle
494 detaching or resuming a vfork parent. */
497 handle_vfork_child_exec_or_exit (int exec
)
499 struct inferior
*inf
= current_inferior ();
501 if (inf
->vfork_parent
)
503 int resume_parent
= -1;
505 /* This exec or exit marks the end of the shared memory region
506 between the parent and the child. If the user wanted to
507 detach from the parent, now is the time. */
509 if (inf
->vfork_parent
->pending_detach
)
511 struct thread_info
*tp
;
512 struct cleanup
*old_chain
;
513 struct program_space
*pspace
;
514 struct address_space
*aspace
;
516 /* follow-fork child, detach-on-fork on */
518 old_chain
= make_cleanup_restore_current_thread ();
520 /* We're letting loose of the parent. */
521 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
522 switch_to_thread (tp
->ptid
);
524 /* We're about to detach from the parent, which implicitly
525 removes breakpoints from its address space. There's a
526 catch here: we want to reuse the spaces for the child,
527 but, parent/child are still sharing the pspace at this
528 point, although the exec in reality makes the kernel give
529 the child a fresh set of new pages. The problem here is
530 that the breakpoints module being unaware of this, would
531 likely chose the child process to write to the parent
532 address space. Swapping the child temporarily away from
533 the spaces has the desired effect. Yes, this is "sort
536 pspace
= inf
->pspace
;
537 aspace
= inf
->aspace
;
541 if (debug_infrun
|| info_verbose
)
543 target_terminal_ours ();
546 fprintf_filtered (gdb_stdlog
,
547 "Detaching vfork parent process %d after child exec.\n",
548 inf
->vfork_parent
->pid
);
550 fprintf_filtered (gdb_stdlog
,
551 "Detaching vfork parent process %d after child exit.\n",
552 inf
->vfork_parent
->pid
);
555 target_detach (NULL
, 0);
558 inf
->pspace
= pspace
;
559 inf
->aspace
= aspace
;
561 do_cleanups (old_chain
);
565 /* We're staying attached to the parent, so, really give the
566 child a new address space. */
567 inf
->pspace
= add_program_space (maybe_new_address_space ());
568 inf
->aspace
= inf
->pspace
->aspace
;
570 set_current_program_space (inf
->pspace
);
572 resume_parent
= inf
->vfork_parent
->pid
;
574 /* Break the bonds. */
575 inf
->vfork_parent
->vfork_child
= NULL
;
579 struct cleanup
*old_chain
;
580 struct program_space
*pspace
;
582 /* If this is a vfork child exiting, then the pspace and
583 aspaces were shared with the parent. Since we're
584 reporting the process exit, we'll be mourning all that is
585 found in the address space, and switching to null_ptid,
586 preparing to start a new inferior. But, since we don't
587 want to clobber the parent's address/program spaces, we
588 go ahead and create a new one for this exiting
591 /* Switch to null_ptid, so that clone_program_space doesn't want
592 to read the selected frame of a dead process. */
593 old_chain
= save_inferior_ptid ();
594 inferior_ptid
= null_ptid
;
596 /* This inferior is dead, so avoid giving the breakpoints
597 module the option to write through to it (cloning a
598 program space resets breakpoints). */
601 pspace
= add_program_space (maybe_new_address_space ());
602 set_current_program_space (pspace
);
604 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
605 inf
->pspace
= pspace
;
606 inf
->aspace
= pspace
->aspace
;
608 /* Put back inferior_ptid. We'll continue mourning this
610 do_cleanups (old_chain
);
612 resume_parent
= inf
->vfork_parent
->pid
;
613 /* Break the bonds. */
614 inf
->vfork_parent
->vfork_child
= NULL
;
617 inf
->vfork_parent
= NULL
;
619 gdb_assert (current_program_space
== inf
->pspace
);
621 if (non_stop
&& resume_parent
!= -1)
623 /* If the user wanted the parent to be running, let it go
625 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
628 fprintf_unfiltered (gdb_stdlog
, "infrun: resuming vfork parent process %d\n",
631 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
633 do_cleanups (old_chain
);
638 /* Enum strings for "set|show displaced-stepping". */
640 static const char follow_exec_mode_new
[] = "new";
641 static const char follow_exec_mode_same
[] = "same";
642 static const char *follow_exec_mode_names
[] =
644 follow_exec_mode_new
,
645 follow_exec_mode_same
,
649 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
651 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
652 struct cmd_list_element
*c
, const char *value
)
654 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
657 /* EXECD_PATHNAME is assumed to be non-NULL. */
660 follow_exec (ptid_t pid
, char *execd_pathname
)
662 struct target_ops
*tgt
;
663 struct thread_info
*th
= inferior_thread ();
664 struct inferior
*inf
= current_inferior ();
666 /* This is an exec event that we actually wish to pay attention to.
667 Refresh our symbol table to the newly exec'd program, remove any
670 If there are breakpoints, they aren't really inserted now,
671 since the exec() transformed our inferior into a fresh set
674 We want to preserve symbolic breakpoints on the list, since
675 we have hopes that they can be reset after the new a.out's
676 symbol table is read.
678 However, any "raw" breakpoints must be removed from the list
679 (e.g., the solib bp's), since their address is probably invalid
682 And, we DON'T want to call delete_breakpoints() here, since
683 that may write the bp's "shadow contents" (the instruction
684 value that was overwritten witha TRAP instruction). Since
685 we now have a new a.out, those shadow contents aren't valid. */
687 mark_breakpoints_out ();
689 update_breakpoints_after_exec ();
691 /* If there was one, it's gone now. We cannot truly step-to-next
692 statement through an exec(). */
693 th
->step_resume_breakpoint
= NULL
;
694 th
->step_range_start
= 0;
695 th
->step_range_end
= 0;
697 /* The target reports the exec event to the main thread, even if
698 some other thread does the exec, and even if the main thread was
699 already stopped --- if debugging in non-stop mode, it's possible
700 the user had the main thread held stopped in the previous image
701 --- release it now. This is the same behavior as step-over-exec
702 with scheduler-locking on in all-stop mode. */
703 th
->stop_requested
= 0;
705 /* What is this a.out's name? */
706 printf_unfiltered (_("%s is executing new program: %s\n"),
707 target_pid_to_str (inferior_ptid
),
710 /* We've followed the inferior through an exec. Therefore, the
711 inferior has essentially been killed & reborn. */
713 gdb_flush (gdb_stdout
);
715 breakpoint_init_inferior (inf_execd
);
717 if (gdb_sysroot
&& *gdb_sysroot
)
719 char *name
= alloca (strlen (gdb_sysroot
)
720 + strlen (execd_pathname
)
722 strcpy (name
, gdb_sysroot
);
723 strcat (name
, execd_pathname
);
724 execd_pathname
= name
;
727 /* Reset the shared library package. This ensures that we get a
728 shlib event when the child reaches "_start", at which point the
729 dld will have had a chance to initialize the child. */
730 /* Also, loading a symbol file below may trigger symbol lookups, and
731 we don't want those to be satisfied by the libraries of the
732 previous incarnation of this process. */
733 no_shared_libraries (NULL
, 0);
735 if (follow_exec_mode_string
== follow_exec_mode_new
)
737 struct program_space
*pspace
;
738 struct inferior
*new_inf
;
740 /* The user wants to keep the old inferior and program spaces
741 around. Create a new fresh one, and switch to it. */
743 inf
= add_inferior (current_inferior ()->pid
);
744 pspace
= add_program_space (maybe_new_address_space ());
745 inf
->pspace
= pspace
;
746 inf
->aspace
= pspace
->aspace
;
748 exit_inferior_num_silent (current_inferior ()->num
);
750 set_current_inferior (inf
);
751 set_current_program_space (pspace
);
754 gdb_assert (current_program_space
== inf
->pspace
);
756 /* That a.out is now the one to use. */
757 exec_file_attach (execd_pathname
, 0);
759 /* Load the main file's symbols. */
760 symbol_file_add_main (execd_pathname
, 0);
762 #ifdef SOLIB_CREATE_INFERIOR_HOOK
763 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
765 solib_create_inferior_hook (0);
768 jit_inferior_created_hook ();
770 /* Reinsert all breakpoints. (Those which were symbolic have
771 been reset to the proper address in the new a.out, thanks
772 to symbol_file_command...) */
773 insert_breakpoints ();
775 /* The next resume of this inferior should bring it to the shlib
776 startup breakpoints. (If the user had also set bp's on
777 "main" from the old (parent) process, then they'll auto-
778 matically get reset there in the new process.) */
781 /* Non-zero if we just simulating a single-step. This is needed
782 because we cannot remove the breakpoints in the inferior process
783 until after the `wait' in `wait_for_inferior'. */
784 static int singlestep_breakpoints_inserted_p
= 0;
786 /* The thread we inserted single-step breakpoints for. */
787 static ptid_t singlestep_ptid
;
789 /* PC when we started this single-step. */
790 static CORE_ADDR singlestep_pc
;
792 /* If another thread hit the singlestep breakpoint, we save the original
793 thread here so that we can resume single-stepping it later. */
794 static ptid_t saved_singlestep_ptid
;
795 static int stepping_past_singlestep_breakpoint
;
797 /* If not equal to null_ptid, this means that after stepping over breakpoint
798 is finished, we need to switch to deferred_step_ptid, and step it.
800 The use case is when one thread has hit a breakpoint, and then the user
801 has switched to another thread and issued 'step'. We need to step over
802 breakpoint in the thread which hit the breakpoint, but then continue
803 stepping the thread user has selected. */
804 static ptid_t deferred_step_ptid
;
806 /* Displaced stepping. */
808 /* In non-stop debugging mode, we must take special care to manage
809 breakpoints properly; in particular, the traditional strategy for
810 stepping a thread past a breakpoint it has hit is unsuitable.
811 'Displaced stepping' is a tactic for stepping one thread past a
812 breakpoint it has hit while ensuring that other threads running
813 concurrently will hit the breakpoint as they should.
815 The traditional way to step a thread T off a breakpoint in a
816 multi-threaded program in all-stop mode is as follows:
818 a0) Initially, all threads are stopped, and breakpoints are not
820 a1) We single-step T, leaving breakpoints uninserted.
821 a2) We insert breakpoints, and resume all threads.
823 In non-stop debugging, however, this strategy is unsuitable: we
824 don't want to have to stop all threads in the system in order to
825 continue or step T past a breakpoint. Instead, we use displaced
828 n0) Initially, T is stopped, other threads are running, and
829 breakpoints are inserted.
830 n1) We copy the instruction "under" the breakpoint to a separate
831 location, outside the main code stream, making any adjustments
832 to the instruction, register, and memory state as directed by
834 n2) We single-step T over the instruction at its new location.
835 n3) We adjust the resulting register and memory state as directed
836 by T's architecture. This includes resetting T's PC to point
837 back into the main instruction stream.
840 This approach depends on the following gdbarch methods:
842 - gdbarch_max_insn_length and gdbarch_displaced_step_location
843 indicate where to copy the instruction, and how much space must
844 be reserved there. We use these in step n1.
846 - gdbarch_displaced_step_copy_insn copies a instruction to a new
847 address, and makes any necessary adjustments to the instruction,
848 register contents, and memory. We use this in step n1.
850 - gdbarch_displaced_step_fixup adjusts registers and memory after
851 we have successfuly single-stepped the instruction, to yield the
852 same effect the instruction would have had if we had executed it
853 at its original address. We use this in step n3.
855 - gdbarch_displaced_step_free_closure provides cleanup.
857 The gdbarch_displaced_step_copy_insn and
858 gdbarch_displaced_step_fixup functions must be written so that
859 copying an instruction with gdbarch_displaced_step_copy_insn,
860 single-stepping across the copied instruction, and then applying
861 gdbarch_displaced_insn_fixup should have the same effects on the
862 thread's memory and registers as stepping the instruction in place
863 would have. Exactly which responsibilities fall to the copy and
864 which fall to the fixup is up to the author of those functions.
866 See the comments in gdbarch.sh for details.
868 Note that displaced stepping and software single-step cannot
869 currently be used in combination, although with some care I think
870 they could be made to. Software single-step works by placing
871 breakpoints on all possible subsequent instructions; if the
872 displaced instruction is a PC-relative jump, those breakpoints
873 could fall in very strange places --- on pages that aren't
874 executable, or at addresses that are not proper instruction
875 boundaries. (We do generally let other threads run while we wait
876 to hit the software single-step breakpoint, and they might
877 encounter such a corrupted instruction.) One way to work around
878 this would be to have gdbarch_displaced_step_copy_insn fully
879 simulate the effect of PC-relative instructions (and return NULL)
880 on architectures that use software single-stepping.
882 In non-stop mode, we can have independent and simultaneous step
883 requests, so more than one thread may need to simultaneously step
884 over a breakpoint. The current implementation assumes there is
885 only one scratch space per process. In this case, we have to
886 serialize access to the scratch space. If thread A wants to step
887 over a breakpoint, but we are currently waiting for some other
888 thread to complete a displaced step, we leave thread A stopped and
889 place it in the displaced_step_request_queue. Whenever a displaced
890 step finishes, we pick the next thread in the queue and start a new
891 displaced step operation on it. See displaced_step_prepare and
892 displaced_step_fixup for details. */
894 /* If this is not null_ptid, this is the thread carrying out a
895 displaced single-step. This thread's state will require fixing up
896 once it has completed its step. */
897 static ptid_t displaced_step_ptid
;
899 struct displaced_step_request
902 struct displaced_step_request
*next
;
905 /* A queue of pending displaced stepping requests. */
906 struct displaced_step_request
*displaced_step_request_queue
;
908 /* The architecture the thread had when we stepped it. */
909 static struct gdbarch
*displaced_step_gdbarch
;
911 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
912 for post-step cleanup. */
913 static struct displaced_step_closure
*displaced_step_closure
;
915 /* The address of the original instruction, and the copy we made. */
916 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
918 /* Saved contents of copy area. */
919 static gdb_byte
*displaced_step_saved_copy
;
921 /* Enum strings for "set|show displaced-stepping". */
923 static const char can_use_displaced_stepping_auto
[] = "auto";
924 static const char can_use_displaced_stepping_on
[] = "on";
925 static const char can_use_displaced_stepping_off
[] = "off";
926 static const char *can_use_displaced_stepping_enum
[] =
928 can_use_displaced_stepping_auto
,
929 can_use_displaced_stepping_on
,
930 can_use_displaced_stepping_off
,
934 /* If ON, and the architecture supports it, GDB will use displaced
935 stepping to step over breakpoints. If OFF, or if the architecture
936 doesn't support it, GDB will instead use the traditional
937 hold-and-step approach. If AUTO (which is the default), GDB will
938 decide which technique to use to step over breakpoints depending on
939 which of all-stop or non-stop mode is active --- displaced stepping
940 in non-stop mode; hold-and-step in all-stop mode. */
942 static const char *can_use_displaced_stepping
=
943 can_use_displaced_stepping_auto
;
946 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
947 struct cmd_list_element
*c
,
950 if (can_use_displaced_stepping
== can_use_displaced_stepping_auto
)
951 fprintf_filtered (file
, _("\
952 Debugger's willingness to use displaced stepping to step over \
953 breakpoints is %s (currently %s).\n"),
954 value
, non_stop
? "on" : "off");
956 fprintf_filtered (file
, _("\
957 Debugger's willingness to use displaced stepping to step over \
958 breakpoints is %s.\n"), value
);
961 /* Return non-zero if displaced stepping can/should be used to step
965 use_displaced_stepping (struct gdbarch
*gdbarch
)
967 return (((can_use_displaced_stepping
== can_use_displaced_stepping_auto
969 || can_use_displaced_stepping
== can_use_displaced_stepping_on
)
970 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
974 /* Clean out any stray displaced stepping state. */
976 displaced_step_clear (void)
978 /* Indicate that there is no cleanup pending. */
979 displaced_step_ptid
= null_ptid
;
981 if (displaced_step_closure
)
983 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
984 displaced_step_closure
);
985 displaced_step_closure
= NULL
;
990 displaced_step_clear_cleanup (void *ignore
)
992 displaced_step_clear ();
995 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
997 displaced_step_dump_bytes (struct ui_file
*file
,
1003 for (i
= 0; i
< len
; i
++)
1004 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1005 fputs_unfiltered ("\n", file
);
1008 /* Prepare to single-step, using displaced stepping.
1010 Note that we cannot use displaced stepping when we have a signal to
1011 deliver. If we have a signal to deliver and an instruction to step
1012 over, then after the step, there will be no indication from the
1013 target whether the thread entered a signal handler or ignored the
1014 signal and stepped over the instruction successfully --- both cases
1015 result in a simple SIGTRAP. In the first case we mustn't do a
1016 fixup, and in the second case we must --- but we can't tell which.
1017 Comments in the code for 'random signals' in handle_inferior_event
1018 explain how we handle this case instead.
1020 Returns 1 if preparing was successful -- this thread is going to be
1021 stepped now; or 0 if displaced stepping this thread got queued. */
1023 displaced_step_prepare (ptid_t ptid
)
1025 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1026 struct regcache
*regcache
= get_thread_regcache (ptid
);
1027 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1028 CORE_ADDR original
, copy
;
1030 struct displaced_step_closure
*closure
;
1032 /* We should never reach this function if the architecture does not
1033 support displaced stepping. */
1034 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1036 /* For the first cut, we're displaced stepping one thread at a
1039 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
1041 /* Already waiting for a displaced step to finish. Defer this
1042 request and place in queue. */
1043 struct displaced_step_request
*req
, *new_req
;
1045 if (debug_displaced
)
1046 fprintf_unfiltered (gdb_stdlog
,
1047 "displaced: defering step of %s\n",
1048 target_pid_to_str (ptid
));
1050 new_req
= xmalloc (sizeof (*new_req
));
1051 new_req
->ptid
= ptid
;
1052 new_req
->next
= NULL
;
1054 if (displaced_step_request_queue
)
1056 for (req
= displaced_step_request_queue
;
1060 req
->next
= new_req
;
1063 displaced_step_request_queue
= new_req
;
1069 if (debug_displaced
)
1070 fprintf_unfiltered (gdb_stdlog
,
1071 "displaced: stepping %s now\n",
1072 target_pid_to_str (ptid
));
1075 displaced_step_clear ();
1077 old_cleanups
= save_inferior_ptid ();
1078 inferior_ptid
= ptid
;
1080 original
= regcache_read_pc (regcache
);
1082 copy
= gdbarch_displaced_step_location (gdbarch
);
1083 len
= gdbarch_max_insn_length (gdbarch
);
1085 /* Save the original contents of the copy area. */
1086 displaced_step_saved_copy
= xmalloc (len
);
1087 ignore_cleanups
= make_cleanup (free_current_contents
,
1088 &displaced_step_saved_copy
);
1089 read_memory (copy
, displaced_step_saved_copy
, len
);
1090 if (debug_displaced
)
1092 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1093 paddress (gdbarch
, copy
));
1094 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
1097 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1098 original
, copy
, regcache
);
1100 /* We don't support the fully-simulated case at present. */
1101 gdb_assert (closure
);
1103 /* Save the information we need to fix things up if the step
1105 displaced_step_ptid
= ptid
;
1106 displaced_step_gdbarch
= gdbarch
;
1107 displaced_step_closure
= closure
;
1108 displaced_step_original
= original
;
1109 displaced_step_copy
= copy
;
1111 make_cleanup (displaced_step_clear_cleanup
, 0);
1113 /* Resume execution at the copy. */
1114 regcache_write_pc (regcache
, copy
);
1116 discard_cleanups (ignore_cleanups
);
1118 do_cleanups (old_cleanups
);
1120 if (debug_displaced
)
1121 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1122 paddress (gdbarch
, copy
));
1128 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
1130 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1131 inferior_ptid
= ptid
;
1132 write_memory (memaddr
, myaddr
, len
);
1133 do_cleanups (ptid_cleanup
);
1137 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
1139 struct cleanup
*old_cleanups
;
1141 /* Was this event for the pid we displaced? */
1142 if (ptid_equal (displaced_step_ptid
, null_ptid
)
1143 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
1146 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
1148 /* Restore the contents of the copy area. */
1150 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
1151 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
1152 displaced_step_saved_copy
, len
);
1153 if (debug_displaced
)
1154 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s\n",
1155 paddress (displaced_step_gdbarch
,
1156 displaced_step_copy
));
1159 /* Did the instruction complete successfully? */
1160 if (signal
== TARGET_SIGNAL_TRAP
)
1162 /* Fix up the resulting state. */
1163 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
1164 displaced_step_closure
,
1165 displaced_step_original
,
1166 displaced_step_copy
,
1167 get_thread_regcache (displaced_step_ptid
));
1171 /* Since the instruction didn't complete, all we can do is
1173 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1174 CORE_ADDR pc
= regcache_read_pc (regcache
);
1175 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
1176 regcache_write_pc (regcache
, pc
);
1179 do_cleanups (old_cleanups
);
1181 displaced_step_ptid
= null_ptid
;
1183 /* Are there any pending displaced stepping requests? If so, run
1185 while (displaced_step_request_queue
)
1187 struct displaced_step_request
*head
;
1189 struct regcache
*regcache
;
1190 struct gdbarch
*gdbarch
;
1191 CORE_ADDR actual_pc
;
1192 struct address_space
*aspace
;
1194 head
= displaced_step_request_queue
;
1196 displaced_step_request_queue
= head
->next
;
1199 context_switch (ptid
);
1201 regcache
= get_thread_regcache (ptid
);
1202 actual_pc
= regcache_read_pc (regcache
);
1203 aspace
= get_regcache_aspace (regcache
);
1205 if (breakpoint_here_p (aspace
, actual_pc
))
1207 if (debug_displaced
)
1208 fprintf_unfiltered (gdb_stdlog
,
1209 "displaced: stepping queued %s now\n",
1210 target_pid_to_str (ptid
));
1212 displaced_step_prepare (ptid
);
1214 gdbarch
= get_regcache_arch (regcache
);
1216 if (debug_displaced
)
1218 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1221 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1222 paddress (gdbarch
, actual_pc
));
1223 read_memory (actual_pc
, buf
, sizeof (buf
));
1224 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1227 if (gdbarch_displaced_step_hw_singlestep
1228 (gdbarch
, displaced_step_closure
))
1229 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
1231 target_resume (ptid
, 0, TARGET_SIGNAL_0
);
1233 /* Done, we're stepping a thread. */
1239 struct thread_info
*tp
= inferior_thread ();
1241 /* The breakpoint we were sitting under has since been
1243 tp
->trap_expected
= 0;
1245 /* Go back to what we were trying to do. */
1246 step
= currently_stepping (tp
);
1248 if (debug_displaced
)
1249 fprintf_unfiltered (gdb_stdlog
, "breakpoint is gone %s: step(%d)\n",
1250 target_pid_to_str (tp
->ptid
), step
);
1252 target_resume (ptid
, step
, TARGET_SIGNAL_0
);
1253 tp
->stop_signal
= TARGET_SIGNAL_0
;
1255 /* This request was discarded. See if there's any other
1256 thread waiting for its turn. */
1261 /* Update global variables holding ptids to hold NEW_PTID if they were
1262 holding OLD_PTID. */
1264 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1266 struct displaced_step_request
*it
;
1268 if (ptid_equal (inferior_ptid
, old_ptid
))
1269 inferior_ptid
= new_ptid
;
1271 if (ptid_equal (singlestep_ptid
, old_ptid
))
1272 singlestep_ptid
= new_ptid
;
1274 if (ptid_equal (displaced_step_ptid
, old_ptid
))
1275 displaced_step_ptid
= new_ptid
;
1277 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1278 deferred_step_ptid
= new_ptid
;
1280 for (it
= displaced_step_request_queue
; it
; it
= it
->next
)
1281 if (ptid_equal (it
->ptid
, old_ptid
))
1282 it
->ptid
= new_ptid
;
1288 /* Things to clean up if we QUIT out of resume (). */
1290 resume_cleanups (void *ignore
)
1295 static const char schedlock_off
[] = "off";
1296 static const char schedlock_on
[] = "on";
1297 static const char schedlock_step
[] = "step";
1298 static const char *scheduler_enums
[] = {
1304 static const char *scheduler_mode
= schedlock_off
;
1306 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1307 struct cmd_list_element
*c
, const char *value
)
1309 fprintf_filtered (file
, _("\
1310 Mode for locking scheduler during execution is \"%s\".\n"),
1315 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1317 if (!target_can_lock_scheduler
)
1319 scheduler_mode
= schedlock_off
;
1320 error (_("Target '%s' cannot support this command."), target_shortname
);
1324 /* True if execution commands resume all threads of all processes by
1325 default; otherwise, resume only threads of the current inferior
1327 int sched_multi
= 0;
1329 /* Try to setup for software single stepping over the specified location.
1330 Return 1 if target_resume() should use hardware single step.
1332 GDBARCH the current gdbarch.
1333 PC the location to step over. */
1336 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1340 if (gdbarch_software_single_step_p (gdbarch
)
1341 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1344 /* Do not pull these breakpoints until after a `wait' in
1345 `wait_for_inferior' */
1346 singlestep_breakpoints_inserted_p
= 1;
1347 singlestep_ptid
= inferior_ptid
;
1353 /* Resume the inferior, but allow a QUIT. This is useful if the user
1354 wants to interrupt some lengthy single-stepping operation
1355 (for child processes, the SIGINT goes to the inferior, and so
1356 we get a SIGINT random_signal, but for remote debugging and perhaps
1357 other targets, that's not true).
1359 STEP nonzero if we should step (zero to continue instead).
1360 SIG is the signal to give the inferior (zero for none). */
1362 resume (int step
, enum target_signal sig
)
1364 int should_resume
= 1;
1365 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1366 struct regcache
*regcache
= get_current_regcache ();
1367 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1368 struct thread_info
*tp
= inferior_thread ();
1369 CORE_ADDR pc
= regcache_read_pc (regcache
);
1370 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1375 fprintf_unfiltered (gdb_stdlog
,
1376 "infrun: resume (step=%d, signal=%d), "
1377 "trap_expected=%d\n",
1378 step
, sig
, tp
->trap_expected
);
1380 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
1381 over an instruction that causes a page fault without triggering
1382 a hardware watchpoint. The kernel properly notices that it shouldn't
1383 stop, because the hardware watchpoint is not triggered, but it forgets
1384 the step request and continues the program normally.
1385 Work around the problem by removing hardware watchpoints if a step is
1386 requested, GDB will check for a hardware watchpoint trigger after the
1388 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
1389 remove_hw_watchpoints ();
1392 /* Normally, by the time we reach `resume', the breakpoints are either
1393 removed or inserted, as appropriate. The exception is if we're sitting
1394 at a permanent breakpoint; we need to step over it, but permanent
1395 breakpoints can't be removed. So we have to test for it here. */
1396 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1398 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1399 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1402 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1403 how to step past a permanent breakpoint on this architecture. Try using\n\
1404 a command like `return' or `jump' to continue execution."));
1407 /* If enabled, step over breakpoints by executing a copy of the
1408 instruction at a different address.
1410 We can't use displaced stepping when we have a signal to deliver;
1411 the comments for displaced_step_prepare explain why. The
1412 comments in the handle_inferior event for dealing with 'random
1413 signals' explain what we do instead. */
1414 if (use_displaced_stepping (gdbarch
)
1415 && (tp
->trap_expected
1416 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1417 && sig
== TARGET_SIGNAL_0
)
1419 if (!displaced_step_prepare (inferior_ptid
))
1421 /* Got placed in displaced stepping queue. Will be resumed
1422 later when all the currently queued displaced stepping
1423 requests finish. The thread is not executing at this point,
1424 and the call to set_executing will be made later. But we
1425 need to call set_running here, since from frontend point of view,
1426 the thread is running. */
1427 set_running (inferior_ptid
, 1);
1428 discard_cleanups (old_cleanups
);
1432 step
= gdbarch_displaced_step_hw_singlestep
1433 (gdbarch
, displaced_step_closure
);
1436 /* Do we need to do it the hard way, w/temp breakpoints? */
1438 step
= maybe_software_singlestep (gdbarch
, pc
);
1444 /* If STEP is set, it's a request to use hardware stepping
1445 facilities. But in that case, we should never
1446 use singlestep breakpoint. */
1447 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1449 /* Decide the set of threads to ask the target to resume. Start
1450 by assuming everything will be resumed, than narrow the set
1451 by applying increasingly restricting conditions. */
1453 /* By default, resume all threads of all processes. */
1454 resume_ptid
= RESUME_ALL
;
1456 /* Maybe resume only all threads of the current process. */
1457 if (!sched_multi
&& target_supports_multi_process ())
1459 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1462 /* Maybe resume a single thread after all. */
1463 if (singlestep_breakpoints_inserted_p
1464 && stepping_past_singlestep_breakpoint
)
1466 /* The situation here is as follows. In thread T1 we wanted to
1467 single-step. Lacking hardware single-stepping we've
1468 set breakpoint at the PC of the next instruction -- call it
1469 P. After resuming, we've hit that breakpoint in thread T2.
1470 Now we've removed original breakpoint, inserted breakpoint
1471 at P+1, and try to step to advance T2 past breakpoint.
1472 We need to step only T2, as if T1 is allowed to freely run,
1473 it can run past P, and if other threads are allowed to run,
1474 they can hit breakpoint at P+1, and nested hits of single-step
1475 breakpoints is not something we'd want -- that's complicated
1476 to support, and has no value. */
1477 resume_ptid
= inferior_ptid
;
1479 else if ((step
|| singlestep_breakpoints_inserted_p
)
1480 && tp
->trap_expected
)
1482 /* We're allowing a thread to run past a breakpoint it has
1483 hit, by single-stepping the thread with the breakpoint
1484 removed. In which case, we need to single-step only this
1485 thread, and keep others stopped, as they can miss this
1486 breakpoint if allowed to run.
1488 The current code actually removes all breakpoints when
1489 doing this, not just the one being stepped over, so if we
1490 let other threads run, we can actually miss any
1491 breakpoint, not just the one at PC. */
1492 resume_ptid
= inferior_ptid
;
1496 /* With non-stop mode on, threads are always handled
1498 resume_ptid
= inferior_ptid
;
1500 else if ((scheduler_mode
== schedlock_on
)
1501 || (scheduler_mode
== schedlock_step
1502 && (step
|| singlestep_breakpoints_inserted_p
)))
1504 /* User-settable 'scheduler' mode requires solo thread resume. */
1505 resume_ptid
= inferior_ptid
;
1508 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1510 /* Most targets can step a breakpoint instruction, thus
1511 executing it normally. But if this one cannot, just
1512 continue and we will hit it anyway. */
1513 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1518 && use_displaced_stepping (gdbarch
)
1519 && tp
->trap_expected
)
1521 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1522 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1523 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1526 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1527 paddress (resume_gdbarch
, actual_pc
));
1528 read_memory (actual_pc
, buf
, sizeof (buf
));
1529 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1532 /* Install inferior's terminal modes. */
1533 target_terminal_inferior ();
1535 /* Avoid confusing the next resume, if the next stop/resume
1536 happens to apply to another thread. */
1537 tp
->stop_signal
= TARGET_SIGNAL_0
;
1539 target_resume (resume_ptid
, step
, sig
);
1542 discard_cleanups (old_cleanups
);
1547 /* Clear out all variables saying what to do when inferior is continued.
1548 First do this, then set the ones you want, then call `proceed'. */
1551 clear_proceed_status_thread (struct thread_info
*tp
)
1554 fprintf_unfiltered (gdb_stdlog
,
1555 "infrun: clear_proceed_status_thread (%s)\n",
1556 target_pid_to_str (tp
->ptid
));
1558 tp
->trap_expected
= 0;
1559 tp
->step_range_start
= 0;
1560 tp
->step_range_end
= 0;
1561 tp
->step_frame_id
= null_frame_id
;
1562 tp
->step_stack_frame_id
= null_frame_id
;
1563 tp
->step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1564 tp
->stop_requested
= 0;
1568 tp
->proceed_to_finish
= 0;
1570 /* Discard any remaining commands or status from previous stop. */
1571 bpstat_clear (&tp
->stop_bpstat
);
1575 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
1577 if (is_exited (tp
->ptid
))
1580 clear_proceed_status_thread (tp
);
1585 clear_proceed_status (void)
1589 /* In all-stop mode, delete the per-thread status of all
1590 threads, even if inferior_ptid is null_ptid, there may be
1591 threads on the list. E.g., we may be launching a new
1592 process, while selecting the executable. */
1593 iterate_over_threads (clear_proceed_status_callback
, NULL
);
1596 if (!ptid_equal (inferior_ptid
, null_ptid
))
1598 struct inferior
*inferior
;
1602 /* If in non-stop mode, only delete the per-thread status of
1603 the current thread. */
1604 clear_proceed_status_thread (inferior_thread ());
1607 inferior
= current_inferior ();
1608 inferior
->stop_soon
= NO_STOP_QUIETLY
;
1611 stop_after_trap
= 0;
1613 observer_notify_about_to_proceed ();
1617 regcache_xfree (stop_registers
);
1618 stop_registers
= NULL
;
1622 /* Check the current thread against the thread that reported the most recent
1623 event. If a step-over is required return TRUE and set the current thread
1624 to the old thread. Otherwise return FALSE.
1626 This should be suitable for any targets that support threads. */
1629 prepare_to_proceed (int step
)
1632 struct target_waitstatus wait_status
;
1633 int schedlock_enabled
;
1635 /* With non-stop mode on, threads are always handled individually. */
1636 gdb_assert (! non_stop
);
1638 /* Get the last target status returned by target_wait(). */
1639 get_last_target_status (&wait_ptid
, &wait_status
);
1641 /* Make sure we were stopped at a breakpoint. */
1642 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1643 || (wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
1644 && wait_status
.value
.sig
!= TARGET_SIGNAL_ILL
1645 && wait_status
.value
.sig
!= TARGET_SIGNAL_SEGV
1646 && wait_status
.value
.sig
!= TARGET_SIGNAL_EMT
))
1651 schedlock_enabled
= (scheduler_mode
== schedlock_on
1652 || (scheduler_mode
== schedlock_step
1655 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1656 if (schedlock_enabled
)
1659 /* Don't switch over if we're about to resume some other process
1660 other than WAIT_PTID's, and schedule-multiple is off. */
1662 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
1665 /* Switched over from WAIT_PID. */
1666 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1667 && !ptid_equal (inferior_ptid
, wait_ptid
))
1669 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1671 if (breakpoint_here_p (get_regcache_aspace (regcache
),
1672 regcache_read_pc (regcache
)))
1674 /* If stepping, remember current thread to switch back to. */
1676 deferred_step_ptid
= inferior_ptid
;
1678 /* Switch back to WAIT_PID thread. */
1679 switch_to_thread (wait_ptid
);
1681 /* We return 1 to indicate that there is a breakpoint here,
1682 so we need to step over it before continuing to avoid
1683 hitting it straight away. */
1691 /* Basic routine for continuing the program in various fashions.
1693 ADDR is the address to resume at, or -1 for resume where stopped.
1694 SIGGNAL is the signal to give it, or 0 for none,
1695 or -1 for act according to how it stopped.
1696 STEP is nonzero if should trap after one instruction.
1697 -1 means return after that and print nothing.
1698 You should probably set various step_... variables
1699 before calling here, if you are stepping.
1701 You should call clear_proceed_status before calling proceed. */
1704 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1706 struct regcache
*regcache
;
1707 struct gdbarch
*gdbarch
;
1708 struct thread_info
*tp
;
1710 struct address_space
*aspace
;
1713 /* If we're stopped at a fork/vfork, follow the branch set by the
1714 "set follow-fork-mode" command; otherwise, we'll just proceed
1715 resuming the current thread. */
1716 if (!follow_fork ())
1718 /* The target for some reason decided not to resume. */
1723 regcache
= get_current_regcache ();
1724 gdbarch
= get_regcache_arch (regcache
);
1725 aspace
= get_regcache_aspace (regcache
);
1726 pc
= regcache_read_pc (regcache
);
1729 step_start_function
= find_pc_function (pc
);
1731 stop_after_trap
= 1;
1733 if (addr
== (CORE_ADDR
) -1)
1735 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
1736 && execution_direction
!= EXEC_REVERSE
)
1737 /* There is a breakpoint at the address we will resume at,
1738 step one instruction before inserting breakpoints so that
1739 we do not stop right away (and report a second hit at this
1742 Note, we don't do this in reverse, because we won't
1743 actually be executing the breakpoint insn anyway.
1744 We'll be (un-)executing the previous instruction. */
1747 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1748 && gdbarch_single_step_through_delay (gdbarch
,
1749 get_current_frame ()))
1750 /* We stepped onto an instruction that needs to be stepped
1751 again before re-inserting the breakpoint, do so. */
1756 regcache_write_pc (regcache
, addr
);
1760 fprintf_unfiltered (gdb_stdlog
,
1761 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
1762 paddress (gdbarch
, addr
), siggnal
, step
);
1765 /* In non-stop, each thread is handled individually. The context
1766 must already be set to the right thread here. */
1770 /* In a multi-threaded task we may select another thread and
1771 then continue or step.
1773 But if the old thread was stopped at a breakpoint, it will
1774 immediately cause another breakpoint stop without any
1775 execution (i.e. it will report a breakpoint hit incorrectly).
1776 So we must step over it first.
1778 prepare_to_proceed checks the current thread against the
1779 thread that reported the most recent event. If a step-over
1780 is required it returns TRUE and sets the current thread to
1782 if (prepare_to_proceed (step
))
1786 /* prepare_to_proceed may change the current thread. */
1787 tp
= inferior_thread ();
1791 tp
->trap_expected
= 1;
1792 /* If displaced stepping is enabled, we can step over the
1793 breakpoint without hitting it, so leave all breakpoints
1794 inserted. Otherwise we need to disable all breakpoints, step
1795 one instruction, and then re-add them when that step is
1797 if (!use_displaced_stepping (gdbarch
))
1798 remove_breakpoints ();
1801 /* We can insert breakpoints if we're not trying to step over one,
1802 or if we are stepping over one but we're using displaced stepping
1804 if (! tp
->trap_expected
|| use_displaced_stepping (gdbarch
))
1805 insert_breakpoints ();
1809 /* Pass the last stop signal to the thread we're resuming,
1810 irrespective of whether the current thread is the thread that
1811 got the last event or not. This was historically GDB's
1812 behaviour before keeping a stop_signal per thread. */
1814 struct thread_info
*last_thread
;
1816 struct target_waitstatus last_status
;
1818 get_last_target_status (&last_ptid
, &last_status
);
1819 if (!ptid_equal (inferior_ptid
, last_ptid
)
1820 && !ptid_equal (last_ptid
, null_ptid
)
1821 && !ptid_equal (last_ptid
, minus_one_ptid
))
1823 last_thread
= find_thread_ptid (last_ptid
);
1826 tp
->stop_signal
= last_thread
->stop_signal
;
1827 last_thread
->stop_signal
= TARGET_SIGNAL_0
;
1832 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1833 tp
->stop_signal
= siggnal
;
1834 /* If this signal should not be seen by program,
1835 give it zero. Used for debugging signals. */
1836 else if (!signal_program
[tp
->stop_signal
])
1837 tp
->stop_signal
= TARGET_SIGNAL_0
;
1839 annotate_starting ();
1841 /* Make sure that output from GDB appears before output from the
1843 gdb_flush (gdb_stdout
);
1845 /* Refresh prev_pc value just prior to resuming. This used to be
1846 done in stop_stepping, however, setting prev_pc there did not handle
1847 scenarios such as inferior function calls or returning from
1848 a function via the return command. In those cases, the prev_pc
1849 value was not set properly for subsequent commands. The prev_pc value
1850 is used to initialize the starting line number in the ecs. With an
1851 invalid value, the gdb next command ends up stopping at the position
1852 represented by the next line table entry past our start position.
1853 On platforms that generate one line table entry per line, this
1854 is not a problem. However, on the ia64, the compiler generates
1855 extraneous line table entries that do not increase the line number.
1856 When we issue the gdb next command on the ia64 after an inferior call
1857 or a return command, we often end up a few instructions forward, still
1858 within the original line we started.
1860 An attempt was made to refresh the prev_pc at the same time the
1861 execution_control_state is initialized (for instance, just before
1862 waiting for an inferior event). But this approach did not work
1863 because of platforms that use ptrace, where the pc register cannot
1864 be read unless the inferior is stopped. At that point, we are not
1865 guaranteed the inferior is stopped and so the regcache_read_pc() call
1866 can fail. Setting the prev_pc value here ensures the value is updated
1867 correctly when the inferior is stopped. */
1868 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
1870 /* Fill in with reasonable starting values. */
1871 init_thread_stepping_state (tp
);
1873 /* Reset to normal state. */
1874 init_infwait_state ();
1876 /* Resume inferior. */
1877 resume (oneproc
|| step
|| bpstat_should_step (), tp
->stop_signal
);
1879 /* Wait for it to stop (if not standalone)
1880 and in any case decode why it stopped, and act accordingly. */
1881 /* Do this only if we are not using the event loop, or if the target
1882 does not support asynchronous execution. */
1883 if (!target_can_async_p ())
1885 wait_for_inferior (0);
1891 /* Start remote-debugging of a machine over a serial link. */
1894 start_remote (int from_tty
)
1896 struct inferior
*inferior
;
1897 init_wait_for_inferior ();
1899 inferior
= current_inferior ();
1900 inferior
->stop_soon
= STOP_QUIETLY_REMOTE
;
1902 /* Always go on waiting for the target, regardless of the mode. */
1903 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1904 indicate to wait_for_inferior that a target should timeout if
1905 nothing is returned (instead of just blocking). Because of this,
1906 targets expecting an immediate response need to, internally, set
1907 things up so that the target_wait() is forced to eventually
1909 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1910 differentiate to its caller what the state of the target is after
1911 the initial open has been performed. Here we're assuming that
1912 the target has stopped. It should be possible to eventually have
1913 target_open() return to the caller an indication that the target
1914 is currently running and GDB state should be set to the same as
1915 for an async run. */
1916 wait_for_inferior (0);
1918 /* Now that the inferior has stopped, do any bookkeeping like
1919 loading shared libraries. We want to do this before normal_stop,
1920 so that the displayed frame is up to date. */
1921 post_create_inferior (¤t_target
, from_tty
);
1926 /* Initialize static vars when a new inferior begins. */
1929 init_wait_for_inferior (void)
1931 /* These are meaningless until the first time through wait_for_inferior. */
1933 breakpoint_init_inferior (inf_starting
);
1935 clear_proceed_status ();
1937 stepping_past_singlestep_breakpoint
= 0;
1938 deferred_step_ptid
= null_ptid
;
1940 target_last_wait_ptid
= minus_one_ptid
;
1942 previous_inferior_ptid
= null_ptid
;
1943 init_infwait_state ();
1945 displaced_step_clear ();
1947 /* Discard any skipped inlined frames. */
1948 clear_inline_frame_state (minus_one_ptid
);
1952 /* This enum encodes possible reasons for doing a target_wait, so that
1953 wfi can call target_wait in one place. (Ultimately the call will be
1954 moved out of the infinite loop entirely.) */
1958 infwait_normal_state
,
1959 infwait_thread_hop_state
,
1960 infwait_step_watch_state
,
1961 infwait_nonstep_watch_state
1964 /* Why did the inferior stop? Used to print the appropriate messages
1965 to the interface from within handle_inferior_event(). */
1966 enum inferior_stop_reason
1968 /* Step, next, nexti, stepi finished. */
1970 /* Inferior terminated by signal. */
1972 /* Inferior exited. */
1974 /* Inferior received signal, and user asked to be notified. */
1976 /* Reverse execution -- target ran out of history info. */
1980 /* The PTID we'll do a target_wait on.*/
1983 /* Current inferior wait state. */
1984 enum infwait_states infwait_state
;
1986 /* Data to be passed around while handling an event. This data is
1987 discarded between events. */
1988 struct execution_control_state
1991 /* The thread that got the event, if this was a thread event; NULL
1993 struct thread_info
*event_thread
;
1995 struct target_waitstatus ws
;
1997 CORE_ADDR stop_func_start
;
1998 CORE_ADDR stop_func_end
;
1999 char *stop_func_name
;
2000 int new_thread_event
;
2004 static void handle_inferior_event (struct execution_control_state
*ecs
);
2006 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2007 struct execution_control_state
*ecs
);
2008 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2009 struct execution_control_state
*ecs
);
2010 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
2011 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
2012 static void insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
2013 struct symtab_and_line sr_sal
,
2014 struct frame_id sr_id
);
2015 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
2017 static void stop_stepping (struct execution_control_state
*ecs
);
2018 static void prepare_to_wait (struct execution_control_state
*ecs
);
2019 static void keep_going (struct execution_control_state
*ecs
);
2020 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
2023 /* Callback for iterate over threads. If the thread is stopped, but
2024 the user/frontend doesn't know about that yet, go through
2025 normal_stop, as if the thread had just stopped now. ARG points at
2026 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2027 ptid_is_pid(PTID) is true, applies to all threads of the process
2028 pointed at by PTID. Otherwise, apply only to the thread pointed by
2032 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2034 ptid_t ptid
= * (ptid_t
*) arg
;
2036 if ((ptid_equal (info
->ptid
, ptid
)
2037 || ptid_equal (minus_one_ptid
, ptid
)
2038 || (ptid_is_pid (ptid
)
2039 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2040 && is_running (info
->ptid
)
2041 && !is_executing (info
->ptid
))
2043 struct cleanup
*old_chain
;
2044 struct execution_control_state ecss
;
2045 struct execution_control_state
*ecs
= &ecss
;
2047 memset (ecs
, 0, sizeof (*ecs
));
2049 old_chain
= make_cleanup_restore_current_thread ();
2051 switch_to_thread (info
->ptid
);
2053 /* Go through handle_inferior_event/normal_stop, so we always
2054 have consistent output as if the stop event had been
2056 ecs
->ptid
= info
->ptid
;
2057 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2058 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2059 ecs
->ws
.value
.sig
= TARGET_SIGNAL_0
;
2061 handle_inferior_event (ecs
);
2063 if (!ecs
->wait_some_more
)
2065 struct thread_info
*tp
;
2069 /* Finish off the continuations. The continations
2070 themselves are responsible for realising the thread
2071 didn't finish what it was supposed to do. */
2072 tp
= inferior_thread ();
2073 do_all_intermediate_continuations_thread (tp
);
2074 do_all_continuations_thread (tp
);
2077 do_cleanups (old_chain
);
2083 /* This function is attached as a "thread_stop_requested" observer.
2084 Cleanup local state that assumed the PTID was to be resumed, and
2085 report the stop to the frontend. */
2088 infrun_thread_stop_requested (ptid_t ptid
)
2090 struct displaced_step_request
*it
, *next
, *prev
= NULL
;
2092 /* PTID was requested to stop. Remove it from the displaced
2093 stepping queue, so we don't try to resume it automatically. */
2094 for (it
= displaced_step_request_queue
; it
; it
= next
)
2098 if (ptid_equal (it
->ptid
, ptid
)
2099 || ptid_equal (minus_one_ptid
, ptid
)
2100 || (ptid_is_pid (ptid
)
2101 && ptid_get_pid (ptid
) == ptid_get_pid (it
->ptid
)))
2103 if (displaced_step_request_queue
== it
)
2104 displaced_step_request_queue
= it
->next
;
2106 prev
->next
= it
->next
;
2114 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2118 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2120 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2121 nullify_last_target_wait_ptid ();
2124 /* Callback for iterate_over_threads. */
2127 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2129 if (is_exited (info
->ptid
))
2132 delete_step_resume_breakpoint (info
);
2136 /* In all-stop, delete the step resume breakpoint of any thread that
2137 had one. In non-stop, delete the step resume breakpoint of the
2138 thread that just stopped. */
2141 delete_step_thread_step_resume_breakpoint (void)
2143 if (!target_has_execution
2144 || ptid_equal (inferior_ptid
, null_ptid
))
2145 /* If the inferior has exited, we have already deleted the step
2146 resume breakpoints out of GDB's lists. */
2151 /* If in non-stop mode, only delete the step-resume or
2152 longjmp-resume breakpoint of the thread that just stopped
2154 struct thread_info
*tp
= inferior_thread ();
2155 delete_step_resume_breakpoint (tp
);
2158 /* In all-stop mode, delete all step-resume and longjmp-resume
2159 breakpoints of any thread that had them. */
2160 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2163 /* A cleanup wrapper. */
2166 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2168 delete_step_thread_step_resume_breakpoint ();
2171 /* Pretty print the results of target_wait, for debugging purposes. */
2174 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2175 const struct target_waitstatus
*ws
)
2177 char *status_string
= target_waitstatus_to_string (ws
);
2178 struct ui_file
*tmp_stream
= mem_fileopen ();
2181 /* The text is split over several lines because it was getting too long.
2182 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2183 output as a unit; we want only one timestamp printed if debug_timestamp
2186 fprintf_unfiltered (tmp_stream
,
2187 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
2188 if (PIDGET (waiton_ptid
) != -1)
2189 fprintf_unfiltered (tmp_stream
,
2190 " [%s]", target_pid_to_str (waiton_ptid
));
2191 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2192 fprintf_unfiltered (tmp_stream
,
2193 "infrun: %d [%s],\n",
2194 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
2195 fprintf_unfiltered (tmp_stream
,
2199 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2201 /* This uses %s in part to handle %'s in the text, but also to avoid
2202 a gcc error: the format attribute requires a string literal. */
2203 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2205 xfree (status_string
);
2207 ui_file_delete (tmp_stream
);
2210 /* Wait for control to return from inferior to debugger.
2212 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
2213 as if they were SIGTRAP signals. This can be useful during
2214 the startup sequence on some targets such as HP/UX, where
2215 we receive an EXEC event instead of the expected SIGTRAP.
2217 If inferior gets a signal, we may decide to start it up again
2218 instead of returning. That is why there is a loop in this function.
2219 When this function actually returns it means the inferior
2220 should be left stopped and GDB should read more commands. */
2223 wait_for_inferior (int treat_exec_as_sigtrap
)
2225 struct cleanup
*old_cleanups
;
2226 struct execution_control_state ecss
;
2227 struct execution_control_state
*ecs
;
2231 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
2232 treat_exec_as_sigtrap
);
2235 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2238 memset (ecs
, 0, sizeof (*ecs
));
2240 /* We'll update this if & when we switch to a new thread. */
2241 previous_inferior_ptid
= inferior_ptid
;
2245 struct cleanup
*old_chain
;
2247 /* We have to invalidate the registers BEFORE calling target_wait
2248 because they can be loaded from the target while in target_wait.
2249 This makes remote debugging a bit more efficient for those
2250 targets that provide critical registers as part of their normal
2251 status mechanism. */
2253 overlay_cache_invalid
= 1;
2254 registers_changed ();
2256 if (deprecated_target_wait_hook
)
2257 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2259 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2262 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2264 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2266 xfree (ecs
->ws
.value
.execd_pathname
);
2267 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2268 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
2271 /* If an error happens while handling the event, propagate GDB's
2272 knowledge of the executing state to the frontend/user running
2274 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2276 if (ecs
->ws
.kind
== TARGET_WAITKIND_SYSCALL_ENTRY
2277 || ecs
->ws
.kind
== TARGET_WAITKIND_SYSCALL_RETURN
)
2278 ecs
->ws
.value
.syscall_number
= UNKNOWN_SYSCALL
;
2280 /* Now figure out what to do with the result of the result. */
2281 handle_inferior_event (ecs
);
2283 /* No error, don't finish the state yet. */
2284 discard_cleanups (old_chain
);
2286 if (!ecs
->wait_some_more
)
2290 do_cleanups (old_cleanups
);
2293 /* Asynchronous version of wait_for_inferior. It is called by the
2294 event loop whenever a change of state is detected on the file
2295 descriptor corresponding to the target. It can be called more than
2296 once to complete a single execution command. In such cases we need
2297 to keep the state in a global variable ECSS. If it is the last time
2298 that this function is called for a single execution command, then
2299 report to the user that the inferior has stopped, and do the
2300 necessary cleanups. */
2303 fetch_inferior_event (void *client_data
)
2305 struct execution_control_state ecss
;
2306 struct execution_control_state
*ecs
= &ecss
;
2307 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2308 struct cleanup
*ts_old_chain
;
2309 int was_sync
= sync_execution
;
2311 memset (ecs
, 0, sizeof (*ecs
));
2313 /* We'll update this if & when we switch to a new thread. */
2314 previous_inferior_ptid
= inferior_ptid
;
2317 /* In non-stop mode, the user/frontend should not notice a thread
2318 switch due to internal events. Make sure we reverse to the
2319 user selected thread and frame after handling the event and
2320 running any breakpoint commands. */
2321 make_cleanup_restore_current_thread ();
2323 /* We have to invalidate the registers BEFORE calling target_wait
2324 because they can be loaded from the target while in target_wait.
2325 This makes remote debugging a bit more efficient for those
2326 targets that provide critical registers as part of their normal
2327 status mechanism. */
2329 overlay_cache_invalid
= 1;
2330 registers_changed ();
2332 if (deprecated_target_wait_hook
)
2334 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2336 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2339 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2342 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
2343 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2344 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2345 /* In non-stop mode, each thread is handled individually. Switch
2346 early, so the global state is set correctly for this
2348 context_switch (ecs
->ptid
);
2350 /* If an error happens while handling the event, propagate GDB's
2351 knowledge of the executing state to the frontend/user running
2354 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2356 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2358 /* Now figure out what to do with the result of the result. */
2359 handle_inferior_event (ecs
);
2361 if (!ecs
->wait_some_more
)
2363 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2365 delete_step_thread_step_resume_breakpoint ();
2367 /* We may not find an inferior if this was a process exit. */
2368 if (inf
== NULL
|| inf
->stop_soon
== NO_STOP_QUIETLY
)
2371 if (target_has_execution
2372 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2373 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2374 && ecs
->event_thread
->step_multi
2375 && ecs
->event_thread
->stop_step
)
2376 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2378 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2381 /* No error, don't finish the thread states yet. */
2382 discard_cleanups (ts_old_chain
);
2384 /* Revert thread and frame. */
2385 do_cleanups (old_chain
);
2387 /* If the inferior was in sync execution mode, and now isn't,
2388 restore the prompt. */
2389 if (was_sync
&& !sync_execution
)
2390 display_gdb_prompt (0);
2393 /* Record the frame and location we're currently stepping through. */
2395 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2397 struct thread_info
*tp
= inferior_thread ();
2399 tp
->step_frame_id
= get_frame_id (frame
);
2400 tp
->step_stack_frame_id
= get_stack_frame_id (frame
);
2402 tp
->current_symtab
= sal
.symtab
;
2403 tp
->current_line
= sal
.line
;
2406 /* Clear context switchable stepping state. */
2409 init_thread_stepping_state (struct thread_info
*tss
)
2411 tss
->stepping_over_breakpoint
= 0;
2412 tss
->step_after_step_resume_breakpoint
= 0;
2413 tss
->stepping_through_solib_after_catch
= 0;
2414 tss
->stepping_through_solib_catchpoints
= NULL
;
2417 /* Return the cached copy of the last pid/waitstatus returned by
2418 target_wait()/deprecated_target_wait_hook(). The data is actually
2419 cached by handle_inferior_event(), which gets called immediately
2420 after target_wait()/deprecated_target_wait_hook(). */
2423 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2425 *ptidp
= target_last_wait_ptid
;
2426 *status
= target_last_waitstatus
;
2430 nullify_last_target_wait_ptid (void)
2432 target_last_wait_ptid
= minus_one_ptid
;
2435 /* Switch thread contexts. */
2438 context_switch (ptid_t ptid
)
2442 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2443 target_pid_to_str (inferior_ptid
));
2444 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2445 target_pid_to_str (ptid
));
2448 switch_to_thread (ptid
);
2452 adjust_pc_after_break (struct execution_control_state
*ecs
)
2454 struct regcache
*regcache
;
2455 struct gdbarch
*gdbarch
;
2456 struct address_space
*aspace
;
2457 CORE_ADDR breakpoint_pc
;
2459 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2460 we aren't, just return.
2462 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2463 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2464 implemented by software breakpoints should be handled through the normal
2467 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2468 different signals (SIGILL or SIGEMT for instance), but it is less
2469 clear where the PC is pointing afterwards. It may not match
2470 gdbarch_decr_pc_after_break. I don't know any specific target that
2471 generates these signals at breakpoints (the code has been in GDB since at
2472 least 1992) so I can not guess how to handle them here.
2474 In earlier versions of GDB, a target with
2475 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2476 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2477 target with both of these set in GDB history, and it seems unlikely to be
2478 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2480 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2483 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
2486 /* In reverse execution, when a breakpoint is hit, the instruction
2487 under it has already been de-executed. The reported PC always
2488 points at the breakpoint address, so adjusting it further would
2489 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2492 B1 0x08000000 : INSN1
2493 B2 0x08000001 : INSN2
2495 PC -> 0x08000003 : INSN4
2497 Say you're stopped at 0x08000003 as above. Reverse continuing
2498 from that point should hit B2 as below. Reading the PC when the
2499 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2500 been de-executed already.
2502 B1 0x08000000 : INSN1
2503 B2 PC -> 0x08000001 : INSN2
2507 We can't apply the same logic as for forward execution, because
2508 we would wrongly adjust the PC to 0x08000000, since there's a
2509 breakpoint at PC - 1. We'd then report a hit on B1, although
2510 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2512 if (execution_direction
== EXEC_REVERSE
)
2515 /* If this target does not decrement the PC after breakpoints, then
2516 we have nothing to do. */
2517 regcache
= get_thread_regcache (ecs
->ptid
);
2518 gdbarch
= get_regcache_arch (regcache
);
2519 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2522 aspace
= get_regcache_aspace (regcache
);
2524 /* Find the location where (if we've hit a breakpoint) the
2525 breakpoint would be. */
2526 breakpoint_pc
= regcache_read_pc (regcache
)
2527 - gdbarch_decr_pc_after_break (gdbarch
);
2529 /* Check whether there actually is a software breakpoint inserted at
2532 If in non-stop mode, a race condition is possible where we've
2533 removed a breakpoint, but stop events for that breakpoint were
2534 already queued and arrive later. To suppress those spurious
2535 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2536 and retire them after a number of stop events are reported. */
2537 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
2538 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
2540 struct cleanup
*old_cleanups
= NULL
;
2542 old_cleanups
= record_gdb_operation_disable_set ();
2544 /* When using hardware single-step, a SIGTRAP is reported for both
2545 a completed single-step and a software breakpoint. Need to
2546 differentiate between the two, as the latter needs adjusting
2547 but the former does not.
2549 The SIGTRAP can be due to a completed hardware single-step only if
2550 - we didn't insert software single-step breakpoints
2551 - the thread to be examined is still the current thread
2552 - this thread is currently being stepped
2554 If any of these events did not occur, we must have stopped due
2555 to hitting a software breakpoint, and have to back up to the
2558 As a special case, we could have hardware single-stepped a
2559 software breakpoint. In this case (prev_pc == breakpoint_pc),
2560 we also need to back up to the breakpoint address. */
2562 if (singlestep_breakpoints_inserted_p
2563 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
2564 || !currently_stepping (ecs
->event_thread
)
2565 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
2566 regcache_write_pc (regcache
, breakpoint_pc
);
2569 do_cleanups (old_cleanups
);
2574 init_infwait_state (void)
2576 waiton_ptid
= pid_to_ptid (-1);
2577 infwait_state
= infwait_normal_state
;
2581 error_is_running (void)
2584 Cannot execute this command while the selected thread is running."));
2588 ensure_not_running (void)
2590 if (is_running (inferior_ptid
))
2591 error_is_running ();
2595 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
2597 for (frame
= get_prev_frame (frame
);
2599 frame
= get_prev_frame (frame
))
2601 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
2603 if (get_frame_type (frame
) != INLINE_FRAME
)
2610 /* Auxiliary function that handles syscall entry/return events.
2611 It returns 1 if the inferior should keep going (and GDB
2612 should ignore the event), or 0 if the event deserves to be
2616 handle_syscall_event (struct execution_control_state
*ecs
)
2618 struct regcache
*regcache
;
2619 struct gdbarch
*gdbarch
;
2622 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2623 context_switch (ecs
->ptid
);
2625 regcache
= get_thread_regcache (ecs
->ptid
);
2626 gdbarch
= get_regcache_arch (regcache
);
2627 syscall_number
= gdbarch_get_syscall_number (gdbarch
, ecs
->ptid
);
2628 stop_pc
= regcache_read_pc (regcache
);
2630 target_last_waitstatus
.value
.syscall_number
= syscall_number
;
2632 if (catch_syscall_enabled () > 0
2633 && catching_syscall_number (syscall_number
) > 0)
2636 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
2639 ecs
->event_thread
->stop_bpstat
2640 = bpstat_stop_status (get_regcache_aspace (regcache
),
2641 stop_pc
, ecs
->ptid
);
2642 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2644 if (!ecs
->random_signal
)
2646 /* Catchpoint hit. */
2647 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2652 /* If no catchpoint triggered for this, then keep going. */
2653 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2658 /* Given an execution control state that has been freshly filled in
2659 by an event from the inferior, figure out what it means and take
2660 appropriate action. */
2663 handle_inferior_event (struct execution_control_state
*ecs
)
2665 struct frame_info
*frame
;
2666 struct gdbarch
*gdbarch
;
2667 int sw_single_step_trap_p
= 0;
2668 int stopped_by_watchpoint
;
2669 int stepped_after_stopped_by_watchpoint
= 0;
2670 struct symtab_and_line stop_pc_sal
;
2671 enum stop_kind stop_soon
;
2673 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
2675 /* We had an event in the inferior, but we are not interested in
2676 handling it at this level. The lower layers have already
2677 done what needs to be done, if anything.
2679 One of the possible circumstances for this is when the
2680 inferior produces output for the console. The inferior has
2681 not stopped, and we are ignoring the event. Another possible
2682 circumstance is any event which the lower level knows will be
2683 reported multiple times without an intervening resume. */
2685 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2686 prepare_to_wait (ecs
);
2690 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2691 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2693 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2695 stop_soon
= inf
->stop_soon
;
2698 stop_soon
= NO_STOP_QUIETLY
;
2700 /* Cache the last pid/waitstatus. */
2701 target_last_wait_ptid
= ecs
->ptid
;
2702 target_last_waitstatus
= ecs
->ws
;
2704 /* Always clear state belonging to the previous time we stopped. */
2705 stop_stack_dummy
= 0;
2707 /* If it's a new process, add it to the thread database */
2709 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
2710 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
2711 && !in_thread_list (ecs
->ptid
));
2713 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2714 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
2715 add_thread (ecs
->ptid
);
2717 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
2719 /* Dependent on valid ECS->EVENT_THREAD. */
2720 adjust_pc_after_break (ecs
);
2722 /* Dependent on the current PC value modified by adjust_pc_after_break. */
2723 reinit_frame_cache ();
2725 breakpoint_retire_moribund ();
2727 /* First, distinguish signals caused by the debugger from signals
2728 that have to do with the program's own actions. Note that
2729 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2730 on the operating system version. Here we detect when a SIGILL or
2731 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2732 something similar for SIGSEGV, since a SIGSEGV will be generated
2733 when we're trying to execute a breakpoint instruction on a
2734 non-executable stack. This happens for call dummy breakpoints
2735 for architectures like SPARC that place call dummies on the
2737 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
2738 && (ecs
->ws
.value
.sig
== TARGET_SIGNAL_ILL
2739 || ecs
->ws
.value
.sig
== TARGET_SIGNAL_SEGV
2740 || ecs
->ws
.value
.sig
== TARGET_SIGNAL_EMT
))
2742 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
2744 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
2745 regcache_read_pc (regcache
)))
2748 fprintf_unfiltered (gdb_stdlog
,
2749 "infrun: Treating signal as SIGTRAP\n");
2750 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
2754 /* Mark the non-executing threads accordingly. In all-stop, all
2755 threads of all processes are stopped when we get any event
2756 reported. In non-stop mode, only the event thread stops. If
2757 we're handling a process exit in non-stop mode, there's nothing
2758 to do, as threads of the dead process are gone, and threads of
2759 any other process were left running. */
2761 set_executing (minus_one_ptid
, 0);
2762 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2763 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
2764 set_executing (inferior_ptid
, 0);
2766 switch (infwait_state
)
2768 case infwait_thread_hop_state
:
2770 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
2773 case infwait_normal_state
:
2775 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
2778 case infwait_step_watch_state
:
2780 fprintf_unfiltered (gdb_stdlog
,
2781 "infrun: infwait_step_watch_state\n");
2783 stepped_after_stopped_by_watchpoint
= 1;
2786 case infwait_nonstep_watch_state
:
2788 fprintf_unfiltered (gdb_stdlog
,
2789 "infrun: infwait_nonstep_watch_state\n");
2790 insert_breakpoints ();
2792 /* FIXME-maybe: is this cleaner than setting a flag? Does it
2793 handle things like signals arriving and other things happening
2794 in combination correctly? */
2795 stepped_after_stopped_by_watchpoint
= 1;
2799 internal_error (__FILE__
, __LINE__
, _("bad switch"));
2802 infwait_state
= infwait_normal_state
;
2803 waiton_ptid
= pid_to_ptid (-1);
2805 switch (ecs
->ws
.kind
)
2807 case TARGET_WAITKIND_LOADED
:
2809 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
2810 /* Ignore gracefully during startup of the inferior, as it might
2811 be the shell which has just loaded some objects, otherwise
2812 add the symbols for the newly loaded objects. Also ignore at
2813 the beginning of an attach or remote session; we will query
2814 the full list of libraries once the connection is
2816 if (stop_soon
== NO_STOP_QUIETLY
)
2818 /* Check for any newly added shared libraries if we're
2819 supposed to be adding them automatically. Switch
2820 terminal for any messages produced by
2821 breakpoint_re_set. */
2822 target_terminal_ours_for_output ();
2823 /* NOTE: cagney/2003-11-25: Make certain that the target
2824 stack's section table is kept up-to-date. Architectures,
2825 (e.g., PPC64), use the section table to perform
2826 operations such as address => section name and hence
2827 require the table to contain all sections (including
2828 those found in shared libraries). */
2830 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2832 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2834 target_terminal_inferior ();
2836 /* If requested, stop when the dynamic linker notifies
2837 gdb of events. This allows the user to get control
2838 and place breakpoints in initializer routines for
2839 dynamically loaded objects (among other things). */
2840 if (stop_on_solib_events
)
2842 /* Make sure we print "Stopped due to solib-event" in
2844 stop_print_frame
= 1;
2846 stop_stepping (ecs
);
2850 /* NOTE drow/2007-05-11: This might be a good place to check
2851 for "catch load". */
2854 /* If we are skipping through a shell, or through shared library
2855 loading that we aren't interested in, resume the program. If
2856 we're running the program normally, also resume. But stop if
2857 we're attaching or setting up a remote connection. */
2858 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
2860 /* Loading of shared libraries might have changed breakpoint
2861 addresses. Make sure new breakpoints are inserted. */
2862 if (stop_soon
== NO_STOP_QUIETLY
2863 && !breakpoints_always_inserted_mode ())
2864 insert_breakpoints ();
2865 resume (0, TARGET_SIGNAL_0
);
2866 prepare_to_wait (ecs
);
2872 case TARGET_WAITKIND_SPURIOUS
:
2874 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
2875 resume (0, TARGET_SIGNAL_0
);
2876 prepare_to_wait (ecs
);
2879 case TARGET_WAITKIND_EXITED
:
2881 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
2882 inferior_ptid
= ecs
->ptid
;
2883 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
2884 set_current_program_space (current_inferior ()->pspace
);
2885 handle_vfork_child_exec_or_exit (0);
2886 target_terminal_ours (); /* Must do this before mourn anyway */
2887 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
2889 /* Record the exit code in the convenience variable $_exitcode, so
2890 that the user can inspect this again later. */
2891 set_internalvar_integer (lookup_internalvar ("_exitcode"),
2892 (LONGEST
) ecs
->ws
.value
.integer
);
2893 gdb_flush (gdb_stdout
);
2894 target_mourn_inferior ();
2895 singlestep_breakpoints_inserted_p
= 0;
2896 stop_print_frame
= 0;
2897 stop_stepping (ecs
);
2900 case TARGET_WAITKIND_SIGNALLED
:
2902 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2903 inferior_ptid
= ecs
->ptid
;
2904 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
2905 set_current_program_space (current_inferior ()->pspace
);
2906 handle_vfork_child_exec_or_exit (0);
2907 stop_print_frame
= 0;
2908 target_terminal_ours (); /* Must do this before mourn anyway */
2910 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
2911 reach here unless the inferior is dead. However, for years
2912 target_kill() was called here, which hints that fatal signals aren't
2913 really fatal on some systems. If that's true, then some changes
2915 target_mourn_inferior ();
2917 print_stop_reason (SIGNAL_EXITED
, ecs
->ws
.value
.sig
);
2918 singlestep_breakpoints_inserted_p
= 0;
2919 stop_stepping (ecs
);
2922 /* The following are the only cases in which we keep going;
2923 the above cases end in a continue or goto. */
2924 case TARGET_WAITKIND_FORKED
:
2925 case TARGET_WAITKIND_VFORKED
:
2927 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
2929 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2931 context_switch (ecs
->ptid
);
2932 reinit_frame_cache ();
2935 /* Immediately detach breakpoints from the child before there's
2936 any chance of letting the user delete breakpoints from the
2937 breakpoint lists. If we don't do this early, it's easy to
2938 leave left over traps in the child, vis: "break foo; catch
2939 fork; c; <fork>; del; c; <child calls foo>". We only follow
2940 the fork on the last `continue', and by that time the
2941 breakpoint at "foo" is long gone from the breakpoint table.
2942 If we vforked, then we don't need to unpatch here, since both
2943 parent and child are sharing the same memory pages; we'll
2944 need to unpatch at follow/detach time instead to be certain
2945 that new breakpoints added between catchpoint hit time and
2946 vfork follow are detached. */
2947 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
2949 int child_pid
= ptid_get_pid (ecs
->ws
.value
.related_pid
);
2951 /* This won't actually modify the breakpoint list, but will
2952 physically remove the breakpoints from the child. */
2953 detach_breakpoints (child_pid
);
2956 /* In case the event is caught by a catchpoint, remember that
2957 the event is to be followed at the next resume of the thread,
2958 and not immediately. */
2959 ecs
->event_thread
->pending_follow
= ecs
->ws
;
2961 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2963 ecs
->event_thread
->stop_bpstat
2964 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
2965 stop_pc
, ecs
->ptid
);
2967 /* Note that we're interested in knowing the bpstat actually
2968 causes a stop, not just if it may explain the signal.
2969 Software watchpoints, for example, always appear in the
2971 ecs
->random_signal
= !bpstat_causes_stop (ecs
->event_thread
->stop_bpstat
);
2973 /* If no catchpoint triggered for this, then keep going. */
2974 if (ecs
->random_signal
)
2979 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
2981 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2983 should_resume
= follow_fork ();
2986 child
= ecs
->ws
.value
.related_pid
;
2988 /* In non-stop mode, also resume the other branch. */
2989 if (non_stop
&& !detach_fork
)
2992 switch_to_thread (parent
);
2994 switch_to_thread (child
);
2996 ecs
->event_thread
= inferior_thread ();
2997 ecs
->ptid
= inferior_ptid
;
3002 switch_to_thread (child
);
3004 switch_to_thread (parent
);
3006 ecs
->event_thread
= inferior_thread ();
3007 ecs
->ptid
= inferior_ptid
;
3012 stop_stepping (ecs
);
3015 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3016 goto process_event_stop_test
;
3018 case TARGET_WAITKIND_VFORK_DONE
:
3019 /* Done with the shared memory region. Re-insert breakpoints in
3020 the parent, and keep going. */
3023 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3025 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3026 context_switch (ecs
->ptid
);
3028 current_inferior ()->waiting_for_vfork_done
= 0;
3029 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3030 /* This also takes care of reinserting breakpoints in the
3031 previously locked inferior. */
3035 case TARGET_WAITKIND_EXECD
:
3037 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3039 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3041 context_switch (ecs
->ptid
);
3042 reinit_frame_cache ();
3045 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3047 /* Do whatever is necessary to the parent branch of the vfork. */
3048 handle_vfork_child_exec_or_exit (1);
3050 /* This causes the eventpoints and symbol table to be reset.
3051 Must do this now, before trying to determine whether to
3053 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3055 ecs
->event_thread
->stop_bpstat
3056 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3057 stop_pc
, ecs
->ptid
);
3058 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
3060 /* Note that this may be referenced from inside
3061 bpstat_stop_status above, through inferior_has_execd. */
3062 xfree (ecs
->ws
.value
.execd_pathname
);
3063 ecs
->ws
.value
.execd_pathname
= NULL
;
3065 /* If no catchpoint triggered for this, then keep going. */
3066 if (ecs
->random_signal
)
3068 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3072 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3073 goto process_event_stop_test
;
3075 /* Be careful not to try to gather much state about a thread
3076 that's in a syscall. It's frequently a losing proposition. */
3077 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3079 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3080 /* Getting the current syscall number */
3081 if (handle_syscall_event (ecs
) != 0)
3083 goto process_event_stop_test
;
3085 /* Before examining the threads further, step this thread to
3086 get it entirely out of the syscall. (We get notice of the
3087 event when the thread is just on the verge of exiting a
3088 syscall. Stepping one instruction seems to get it back
3090 case TARGET_WAITKIND_SYSCALL_RETURN
:
3092 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3093 if (handle_syscall_event (ecs
) != 0)
3095 goto process_event_stop_test
;
3097 case TARGET_WAITKIND_STOPPED
:
3099 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3100 ecs
->event_thread
->stop_signal
= ecs
->ws
.value
.sig
;
3103 case TARGET_WAITKIND_NO_HISTORY
:
3104 /* Reverse execution: target ran out of history info. */
3105 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3106 print_stop_reason (NO_HISTORY
, 0);
3107 stop_stepping (ecs
);
3111 if (ecs
->new_thread_event
)
3114 /* Non-stop assumes that the target handles adding new threads
3115 to the thread list. */
3116 internal_error (__FILE__
, __LINE__
, "\
3117 targets should add new threads to the thread list themselves in non-stop mode.");
3119 /* We may want to consider not doing a resume here in order to
3120 give the user a chance to play with the new thread. It might
3121 be good to make that a user-settable option. */
3123 /* At this point, all threads are stopped (happens automatically
3124 in either the OS or the native code). Therefore we need to
3125 continue all threads in order to make progress. */
3127 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3128 context_switch (ecs
->ptid
);
3129 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
3130 prepare_to_wait (ecs
);
3134 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
3136 /* Do we need to clean up the state of a thread that has
3137 completed a displaced single-step? (Doing so usually affects
3138 the PC, so do it here, before we set stop_pc.) */
3139 displaced_step_fixup (ecs
->ptid
, ecs
->event_thread
->stop_signal
);
3141 /* If we either finished a single-step or hit a breakpoint, but
3142 the user wanted this thread to be stopped, pretend we got a
3143 SIG0 (generic unsignaled stop). */
3145 if (ecs
->event_thread
->stop_requested
3146 && ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3147 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3150 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3154 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3155 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3156 struct cleanup
*old_chain
= save_inferior_ptid ();
3158 inferior_ptid
= ecs
->ptid
;
3160 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3161 paddress (gdbarch
, stop_pc
));
3162 if (target_stopped_by_watchpoint ())
3165 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3167 if (target_stopped_data_address (¤t_target
, &addr
))
3168 fprintf_unfiltered (gdb_stdlog
,
3169 "infrun: stopped data address = %s\n",
3170 paddress (gdbarch
, addr
));
3172 fprintf_unfiltered (gdb_stdlog
,
3173 "infrun: (no data address available)\n");
3176 do_cleanups (old_chain
);
3179 if (stepping_past_singlestep_breakpoint
)
3181 gdb_assert (singlestep_breakpoints_inserted_p
);
3182 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
3183 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
3185 stepping_past_singlestep_breakpoint
= 0;
3187 /* We've either finished single-stepping past the single-step
3188 breakpoint, or stopped for some other reason. It would be nice if
3189 we could tell, but we can't reliably. */
3190 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3193 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
3194 /* Pull the single step breakpoints out of the target. */
3195 remove_single_step_breakpoints ();
3196 singlestep_breakpoints_inserted_p
= 0;
3198 ecs
->random_signal
= 0;
3199 ecs
->event_thread
->trap_expected
= 0;
3201 context_switch (saved_singlestep_ptid
);
3202 if (deprecated_context_hook
)
3203 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3205 resume (1, TARGET_SIGNAL_0
);
3206 prepare_to_wait (ecs
);
3211 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
3213 /* In non-stop mode, there's never a deferred_step_ptid set. */
3214 gdb_assert (!non_stop
);
3216 /* If we stopped for some other reason than single-stepping, ignore
3217 the fact that we were supposed to switch back. */
3218 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3221 fprintf_unfiltered (gdb_stdlog
,
3222 "infrun: handling deferred step\n");
3224 /* Pull the single step breakpoints out of the target. */
3225 if (singlestep_breakpoints_inserted_p
)
3227 remove_single_step_breakpoints ();
3228 singlestep_breakpoints_inserted_p
= 0;
3231 /* Note: We do not call context_switch at this point, as the
3232 context is already set up for stepping the original thread. */
3233 switch_to_thread (deferred_step_ptid
);
3234 deferred_step_ptid
= null_ptid
;
3235 /* Suppress spurious "Switching to ..." message. */
3236 previous_inferior_ptid
= inferior_ptid
;
3238 resume (1, TARGET_SIGNAL_0
);
3239 prepare_to_wait (ecs
);
3243 deferred_step_ptid
= null_ptid
;
3246 /* See if a thread hit a thread-specific breakpoint that was meant for
3247 another thread. If so, then step that thread past the breakpoint,
3250 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3252 int thread_hop_needed
= 0;
3253 struct address_space
*aspace
=
3254 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
3256 /* Check if a regular breakpoint has been hit before checking
3257 for a potential single step breakpoint. Otherwise, GDB will
3258 not see this breakpoint hit when stepping onto breakpoints. */
3259 if (regular_breakpoint_inserted_here_p (aspace
, stop_pc
))
3261 ecs
->random_signal
= 0;
3262 if (!breakpoint_thread_match (aspace
, stop_pc
, ecs
->ptid
))
3263 thread_hop_needed
= 1;
3265 else if (singlestep_breakpoints_inserted_p
)
3267 /* We have not context switched yet, so this should be true
3268 no matter which thread hit the singlestep breakpoint. */
3269 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
3271 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
3273 target_pid_to_str (ecs
->ptid
));
3275 ecs
->random_signal
= 0;
3276 /* The call to in_thread_list is necessary because PTIDs sometimes
3277 change when we go from single-threaded to multi-threaded. If
3278 the singlestep_ptid is still in the list, assume that it is
3279 really different from ecs->ptid. */
3280 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
3281 && in_thread_list (singlestep_ptid
))
3283 /* If the PC of the thread we were trying to single-step
3284 has changed, discard this event (which we were going
3285 to ignore anyway), and pretend we saw that thread
3286 trap. This prevents us continuously moving the
3287 single-step breakpoint forward, one instruction at a
3288 time. If the PC has changed, then the thread we were
3289 trying to single-step has trapped or been signalled,
3290 but the event has not been reported to GDB yet.
3292 There might be some cases where this loses signal
3293 information, if a signal has arrived at exactly the
3294 same time that the PC changed, but this is the best
3295 we can do with the information available. Perhaps we
3296 should arrange to report all events for all threads
3297 when they stop, or to re-poll the remote looking for
3298 this particular thread (i.e. temporarily enable
3301 CORE_ADDR new_singlestep_pc
3302 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
3304 if (new_singlestep_pc
!= singlestep_pc
)
3306 enum target_signal stop_signal
;
3309 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
3310 " but expected thread advanced also\n");
3312 /* The current context still belongs to
3313 singlestep_ptid. Don't swap here, since that's
3314 the context we want to use. Just fudge our
3315 state and continue. */
3316 stop_signal
= ecs
->event_thread
->stop_signal
;
3317 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3318 ecs
->ptid
= singlestep_ptid
;
3319 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3320 ecs
->event_thread
->stop_signal
= stop_signal
;
3321 stop_pc
= new_singlestep_pc
;
3326 fprintf_unfiltered (gdb_stdlog
,
3327 "infrun: unexpected thread\n");
3329 thread_hop_needed
= 1;
3330 stepping_past_singlestep_breakpoint
= 1;
3331 saved_singlestep_ptid
= singlestep_ptid
;
3336 if (thread_hop_needed
)
3338 struct regcache
*thread_regcache
;
3339 int remove_status
= 0;
3342 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
3344 /* Switch context before touching inferior memory, the
3345 previous thread may have exited. */
3346 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
3347 context_switch (ecs
->ptid
);
3349 /* Saw a breakpoint, but it was hit by the wrong thread.
3352 if (singlestep_breakpoints_inserted_p
)
3354 /* Pull the single step breakpoints out of the target. */
3355 remove_single_step_breakpoints ();
3356 singlestep_breakpoints_inserted_p
= 0;
3359 /* If the arch can displace step, don't remove the
3361 thread_regcache
= get_thread_regcache (ecs
->ptid
);
3362 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
3363 remove_status
= remove_breakpoints ();
3365 /* Did we fail to remove breakpoints? If so, try
3366 to set the PC past the bp. (There's at least
3367 one situation in which we can fail to remove
3368 the bp's: On HP-UX's that use ttrace, we can't
3369 change the address space of a vforking child
3370 process until the child exits (well, okay, not
3371 then either :-) or execs. */
3372 if (remove_status
!= 0)
3373 error (_("Cannot step over breakpoint hit in wrong thread"));
3378 /* Only need to require the next event from this
3379 thread in all-stop mode. */
3380 waiton_ptid
= ecs
->ptid
;
3381 infwait_state
= infwait_thread_hop_state
;
3384 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3389 else if (singlestep_breakpoints_inserted_p
)
3391 sw_single_step_trap_p
= 1;
3392 ecs
->random_signal
= 0;
3396 ecs
->random_signal
= 1;
3398 /* See if something interesting happened to the non-current thread. If
3399 so, then switch to that thread. */
3400 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3403 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3405 context_switch (ecs
->ptid
);
3407 if (deprecated_context_hook
)
3408 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3411 /* At this point, get hold of the now-current thread's frame. */
3412 frame
= get_current_frame ();
3413 gdbarch
= get_frame_arch (frame
);
3415 if (singlestep_breakpoints_inserted_p
)
3417 /* Pull the single step breakpoints out of the target. */
3418 remove_single_step_breakpoints ();
3419 singlestep_breakpoints_inserted_p
= 0;
3422 if (stepped_after_stopped_by_watchpoint
)
3423 stopped_by_watchpoint
= 0;
3425 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
3427 /* If necessary, step over this watchpoint. We'll be back to display
3429 if (stopped_by_watchpoint
3430 && (target_have_steppable_watchpoint
3431 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
3433 /* At this point, we are stopped at an instruction which has
3434 attempted to write to a piece of memory under control of
3435 a watchpoint. The instruction hasn't actually executed
3436 yet. If we were to evaluate the watchpoint expression
3437 now, we would get the old value, and therefore no change
3438 would seem to have occurred.
3440 In order to make watchpoints work `right', we really need
3441 to complete the memory write, and then evaluate the
3442 watchpoint expression. We do this by single-stepping the
3445 It may not be necessary to disable the watchpoint to stop over
3446 it. For example, the PA can (with some kernel cooperation)
3447 single step over a watchpoint without disabling the watchpoint.
3449 It is far more common to need to disable a watchpoint to step
3450 the inferior over it. If we have non-steppable watchpoints,
3451 we must disable the current watchpoint; it's simplest to
3452 disable all watchpoints and breakpoints. */
3455 if (!target_have_steppable_watchpoint
)
3456 remove_breakpoints ();
3458 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
3459 target_resume (ecs
->ptid
, hw_step
, TARGET_SIGNAL_0
);
3460 waiton_ptid
= ecs
->ptid
;
3461 if (target_have_steppable_watchpoint
)
3462 infwait_state
= infwait_step_watch_state
;
3464 infwait_state
= infwait_nonstep_watch_state
;
3465 prepare_to_wait (ecs
);
3469 ecs
->stop_func_start
= 0;
3470 ecs
->stop_func_end
= 0;
3471 ecs
->stop_func_name
= 0;
3472 /* Don't care about return value; stop_func_start and stop_func_name
3473 will both be 0 if it doesn't work. */
3474 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3475 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3476 ecs
->stop_func_start
3477 += gdbarch_deprecated_function_start_offset (gdbarch
);
3478 ecs
->event_thread
->stepping_over_breakpoint
= 0;
3479 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
3480 ecs
->event_thread
->stop_step
= 0;
3481 stop_print_frame
= 1;
3482 ecs
->random_signal
= 0;
3483 stopped_by_random_signal
= 0;
3485 /* Hide inlined functions starting here, unless we just performed stepi or
3486 nexti. After stepi and nexti, always show the innermost frame (not any
3487 inline function call sites). */
3488 if (ecs
->event_thread
->step_range_end
!= 1)
3489 skip_inline_frames (ecs
->ptid
);
3491 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3492 && ecs
->event_thread
->trap_expected
3493 && gdbarch_single_step_through_delay_p (gdbarch
)
3494 && currently_stepping (ecs
->event_thread
))
3496 /* We're trying to step off a breakpoint. Turns out that we're
3497 also on an instruction that needs to be stepped multiple
3498 times before it's been fully executing. E.g., architectures
3499 with a delay slot. It needs to be stepped twice, once for
3500 the instruction and once for the delay slot. */
3501 int step_through_delay
3502 = gdbarch_single_step_through_delay (gdbarch
, frame
);
3503 if (debug_infrun
&& step_through_delay
)
3504 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
3505 if (ecs
->event_thread
->step_range_end
== 0 && step_through_delay
)
3507 /* The user issued a continue when stopped at a breakpoint.
3508 Set up for another trap and get out of here. */
3509 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3513 else if (step_through_delay
)
3515 /* The user issued a step when stopped at a breakpoint.
3516 Maybe we should stop, maybe we should not - the delay
3517 slot *might* correspond to a line of source. In any
3518 case, don't decide that here, just set
3519 ecs->stepping_over_breakpoint, making sure we
3520 single-step again before breakpoints are re-inserted. */
3521 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3525 /* Look at the cause of the stop, and decide what to do.
3526 The alternatives are:
3527 1) stop_stepping and return; to really stop and return to the debugger,
3528 2) keep_going and return to start up again
3529 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3530 3) set ecs->random_signal to 1, and the decision between 1 and 2
3531 will be made according to the signal handling tables. */
3533 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3534 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3535 || stop_soon
== STOP_QUIETLY_REMOTE
)
3537 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
3540 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
3541 stop_print_frame
= 0;
3542 stop_stepping (ecs
);
3546 /* This is originated from start_remote(), start_inferior() and
3547 shared libraries hook functions. */
3548 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
3551 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3552 stop_stepping (ecs
);
3556 /* This originates from attach_command(). We need to overwrite
3557 the stop_signal here, because some kernels don't ignore a
3558 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3559 See more comments in inferior.h. On the other hand, if we
3560 get a non-SIGSTOP, report it to the user - assume the backend
3561 will handle the SIGSTOP if it should show up later.
3563 Also consider that the attach is complete when we see a
3564 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3565 target extended-remote report it instead of a SIGSTOP
3566 (e.g. gdbserver). We already rely on SIGTRAP being our
3567 signal, so this is no exception.
3569 Also consider that the attach is complete when we see a
3570 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3571 the target to stop all threads of the inferior, in case the
3572 low level attach operation doesn't stop them implicitly. If
3573 they weren't stopped implicitly, then the stub will report a
3574 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3575 other than GDB's request. */
3576 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3577 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_STOP
3578 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3579 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_0
))
3581 stop_stepping (ecs
);
3582 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3586 /* See if there is a breakpoint at the current PC. */
3587 ecs
->event_thread
->stop_bpstat
3588 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3589 stop_pc
, ecs
->ptid
);
3591 /* Following in case break condition called a
3593 stop_print_frame
= 1;
3595 /* This is where we handle "moribund" watchpoints. Unlike
3596 software breakpoints traps, hardware watchpoint traps are
3597 always distinguishable from random traps. If no high-level
3598 watchpoint is associated with the reported stop data address
3599 anymore, then the bpstat does not explain the signal ---
3600 simply make sure to ignore it if `stopped_by_watchpoint' is
3604 && ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3605 && !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
)
3606 && stopped_by_watchpoint
)
3607 fprintf_unfiltered (gdb_stdlog
, "\
3608 infrun: no user watchpoint explains watchpoint SIGTRAP, ignoring\n");
3610 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3611 at one stage in the past included checks for an inferior
3612 function call's call dummy's return breakpoint. The original
3613 comment, that went with the test, read:
3615 ``End of a stack dummy. Some systems (e.g. Sony news) give
3616 another signal besides SIGTRAP, so check here as well as
3619 If someone ever tries to get call dummys on a
3620 non-executable stack to work (where the target would stop
3621 with something like a SIGSEGV), then those tests might need
3622 to be re-instated. Given, however, that the tests were only
3623 enabled when momentary breakpoints were not being used, I
3624 suspect that it won't be the case.
3626 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3627 be necessary for call dummies on a non-executable stack on
3630 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3632 = !(bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
)
3633 || stopped_by_watchpoint
3634 || ecs
->event_thread
->trap_expected
3635 || (ecs
->event_thread
->step_range_end
3636 && ecs
->event_thread
->step_resume_breakpoint
== NULL
));
3639 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
3640 if (!ecs
->random_signal
)
3641 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3645 /* When we reach this point, we've pretty much decided
3646 that the reason for stopping must've been a random
3647 (unexpected) signal. */
3650 ecs
->random_signal
= 1;
3652 process_event_stop_test
:
3654 /* Re-fetch current thread's frame in case we did a
3655 "goto process_event_stop_test" above. */
3656 frame
= get_current_frame ();
3657 gdbarch
= get_frame_arch (frame
);
3659 /* For the program's own signals, act according to
3660 the signal handling tables. */
3662 if (ecs
->random_signal
)
3664 /* Signal not for debugging purposes. */
3668 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
3669 ecs
->event_thread
->stop_signal
);
3671 stopped_by_random_signal
= 1;
3673 if (signal_print
[ecs
->event_thread
->stop_signal
])
3676 target_terminal_ours_for_output ();
3677 print_stop_reason (SIGNAL_RECEIVED
, ecs
->event_thread
->stop_signal
);
3679 /* Always stop on signals if we're either just gaining control
3680 of the program, or the user explicitly requested this thread
3681 to remain stopped. */
3682 if (stop_soon
!= NO_STOP_QUIETLY
3683 || ecs
->event_thread
->stop_requested
3684 || signal_stop_state (ecs
->event_thread
->stop_signal
))
3686 stop_stepping (ecs
);
3689 /* If not going to stop, give terminal back
3690 if we took it away. */
3692 target_terminal_inferior ();
3694 /* Clear the signal if it should not be passed. */
3695 if (signal_program
[ecs
->event_thread
->stop_signal
] == 0)
3696 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3698 if (ecs
->event_thread
->prev_pc
== stop_pc
3699 && ecs
->event_thread
->trap_expected
3700 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3702 /* We were just starting a new sequence, attempting to
3703 single-step off of a breakpoint and expecting a SIGTRAP.
3704 Instead this signal arrives. This signal will take us out
3705 of the stepping range so GDB needs to remember to, when
3706 the signal handler returns, resume stepping off that
3708 /* To simplify things, "continue" is forced to use the same
3709 code paths as single-step - set a breakpoint at the
3710 signal return address and then, once hit, step off that
3713 fprintf_unfiltered (gdb_stdlog
,
3714 "infrun: signal arrived while stepping over "
3717 insert_step_resume_breakpoint_at_frame (frame
);
3718 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
3723 if (ecs
->event_thread
->step_range_end
!= 0
3724 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_0
3725 && (ecs
->event_thread
->step_range_start
<= stop_pc
3726 && stop_pc
< ecs
->event_thread
->step_range_end
)
3727 && frame_id_eq (get_stack_frame_id (frame
),
3728 ecs
->event_thread
->step_stack_frame_id
)
3729 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3731 /* The inferior is about to take a signal that will take it
3732 out of the single step range. Set a breakpoint at the
3733 current PC (which is presumably where the signal handler
3734 will eventually return) and then allow the inferior to
3737 Note that this is only needed for a signal delivered
3738 while in the single-step range. Nested signals aren't a
3739 problem as they eventually all return. */
3741 fprintf_unfiltered (gdb_stdlog
,
3742 "infrun: signal may take us out of "
3743 "single-step range\n");
3745 insert_step_resume_breakpoint_at_frame (frame
);
3750 /* Note: step_resume_breakpoint may be non-NULL. This occures
3751 when either there's a nested signal, or when there's a
3752 pending signal enabled just as the signal handler returns
3753 (leaving the inferior at the step-resume-breakpoint without
3754 actually executing it). Either way continue until the
3755 breakpoint is really hit. */
3760 /* Handle cases caused by hitting a breakpoint. */
3762 CORE_ADDR jmp_buf_pc
;
3763 struct bpstat_what what
;
3765 what
= bpstat_what (ecs
->event_thread
->stop_bpstat
);
3767 if (what
.call_dummy
)
3769 stop_stack_dummy
= 1;
3772 switch (what
.main_action
)
3774 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
3775 /* If we hit the breakpoint at longjmp while stepping, we
3776 install a momentary breakpoint at the target of the
3780 fprintf_unfiltered (gdb_stdlog
,
3781 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
3783 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3785 if (!gdbarch_get_longjmp_target_p (gdbarch
)
3786 || !gdbarch_get_longjmp_target (gdbarch
, frame
, &jmp_buf_pc
))
3789 fprintf_unfiltered (gdb_stdlog
, "\
3790 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
3795 /* We're going to replace the current step-resume breakpoint
3796 with a longjmp-resume breakpoint. */
3797 delete_step_resume_breakpoint (ecs
->event_thread
);
3799 /* Insert a breakpoint at resume address. */
3800 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
3805 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
3807 fprintf_unfiltered (gdb_stdlog
,
3808 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
3810 gdb_assert (ecs
->event_thread
->step_resume_breakpoint
!= NULL
);
3811 delete_step_resume_breakpoint (ecs
->event_thread
);
3813 ecs
->event_thread
->stop_step
= 1;
3814 print_stop_reason (END_STEPPING_RANGE
, 0);
3815 stop_stepping (ecs
);
3818 case BPSTAT_WHAT_SINGLE
:
3820 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
3821 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3822 /* Still need to check other stuff, at least the case
3823 where we are stepping and step out of the right range. */
3826 case BPSTAT_WHAT_STOP_NOISY
:
3828 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
3829 stop_print_frame
= 1;
3831 /* We are about to nuke the step_resume_breakpointt via the
3832 cleanup chain, so no need to worry about it here. */
3834 stop_stepping (ecs
);
3837 case BPSTAT_WHAT_STOP_SILENT
:
3839 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
3840 stop_print_frame
= 0;
3842 /* We are about to nuke the step_resume_breakpoin via the
3843 cleanup chain, so no need to worry about it here. */
3845 stop_stepping (ecs
);
3848 case BPSTAT_WHAT_STEP_RESUME
:
3850 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
3852 delete_step_resume_breakpoint (ecs
->event_thread
);
3853 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
3855 /* Back when the step-resume breakpoint was inserted, we
3856 were trying to single-step off a breakpoint. Go back
3858 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
3859 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3863 if (stop_pc
== ecs
->stop_func_start
3864 && execution_direction
== EXEC_REVERSE
)
3866 /* We are stepping over a function call in reverse, and
3867 just hit the step-resume breakpoint at the start
3868 address of the function. Go back to single-stepping,
3869 which should take us back to the function call. */
3870 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3876 case BPSTAT_WHAT_CHECK_SHLIBS
:
3879 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
3881 /* Check for any newly added shared libraries if we're
3882 supposed to be adding them automatically. Switch
3883 terminal for any messages produced by
3884 breakpoint_re_set. */
3885 target_terminal_ours_for_output ();
3886 /* NOTE: cagney/2003-11-25: Make certain that the target
3887 stack's section table is kept up-to-date. Architectures,
3888 (e.g., PPC64), use the section table to perform
3889 operations such as address => section name and hence
3890 require the table to contain all sections (including
3891 those found in shared libraries). */
3893 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
3895 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
3897 target_terminal_inferior ();
3899 /* If requested, stop when the dynamic linker notifies
3900 gdb of events. This allows the user to get control
3901 and place breakpoints in initializer routines for
3902 dynamically loaded objects (among other things). */
3903 if (stop_on_solib_events
|| stop_stack_dummy
)
3905 stop_stepping (ecs
);
3910 /* We want to step over this breakpoint, then keep going. */
3911 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3917 case BPSTAT_WHAT_CHECK_JIT
:
3919 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_JIT\n");
3921 /* Switch terminal for any messages produced by breakpoint_re_set. */
3922 target_terminal_ours_for_output ();
3924 jit_event_handler (gdbarch
);
3926 target_terminal_inferior ();
3928 /* We want to step over this breakpoint, then keep going. */
3929 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3933 case BPSTAT_WHAT_LAST
:
3934 /* Not a real code, but listed here to shut up gcc -Wall. */
3936 case BPSTAT_WHAT_KEEP_CHECKING
:
3941 /* We come here if we hit a breakpoint but should not
3942 stop for it. Possibly we also were stepping
3943 and should stop for that. So fall through and
3944 test for stepping. But, if not stepping,
3947 /* In all-stop mode, if we're currently stepping but have stopped in
3948 some other thread, we need to switch back to the stepped thread. */
3951 struct thread_info
*tp
;
3952 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
3956 /* However, if the current thread is blocked on some internal
3957 breakpoint, and we simply need to step over that breakpoint
3958 to get it going again, do that first. */
3959 if ((ecs
->event_thread
->trap_expected
3960 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
3961 || ecs
->event_thread
->stepping_over_breakpoint
)
3967 /* If the stepping thread exited, then don't try to switch
3968 back and resume it, which could fail in several different
3969 ways depending on the target. Instead, just keep going.
3971 We can find a stepping dead thread in the thread list in
3974 - The target supports thread exit events, and when the
3975 target tries to delete the thread from the thread list,
3976 inferior_ptid pointed at the exiting thread. In such
3977 case, calling delete_thread does not really remove the
3978 thread from the list; instead, the thread is left listed,
3979 with 'exited' state.
3981 - The target's debug interface does not support thread
3982 exit events, and so we have no idea whatsoever if the
3983 previously stepping thread is still alive. For that
3984 reason, we need to synchronously query the target
3986 if (is_exited (tp
->ptid
)
3987 || !target_thread_alive (tp
->ptid
))
3990 fprintf_unfiltered (gdb_stdlog
, "\
3991 infrun: not switching back to stepped thread, it has vanished\n");
3993 delete_thread (tp
->ptid
);
3998 /* Otherwise, we no longer expect a trap in the current thread.
3999 Clear the trap_expected flag before switching back -- this is
4000 what keep_going would do as well, if we called it. */
4001 ecs
->event_thread
->trap_expected
= 0;
4004 fprintf_unfiltered (gdb_stdlog
,
4005 "infrun: switching back to stepped thread\n");
4007 ecs
->event_thread
= tp
;
4008 ecs
->ptid
= tp
->ptid
;
4009 context_switch (ecs
->ptid
);
4015 /* Are we stepping to get the inferior out of the dynamic linker's
4016 hook (and possibly the dld itself) after catching a shlib
4018 if (ecs
->event_thread
->stepping_through_solib_after_catch
)
4020 #if defined(SOLIB_ADD)
4021 /* Have we reached our destination? If not, keep going. */
4022 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
4025 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
4026 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4032 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
4033 /* Else, stop and report the catchpoint(s) whose triggering
4034 caused us to begin stepping. */
4035 ecs
->event_thread
->stepping_through_solib_after_catch
= 0;
4036 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
4037 ecs
->event_thread
->stop_bpstat
4038 = bpstat_copy (ecs
->event_thread
->stepping_through_solib_catchpoints
);
4039 bpstat_clear (&ecs
->event_thread
->stepping_through_solib_catchpoints
);
4040 stop_print_frame
= 1;
4041 stop_stepping (ecs
);
4045 if (ecs
->event_thread
->step_resume_breakpoint
)
4048 fprintf_unfiltered (gdb_stdlog
,
4049 "infrun: step-resume breakpoint is inserted\n");
4051 /* Having a step-resume breakpoint overrides anything
4052 else having to do with stepping commands until
4053 that breakpoint is reached. */
4058 if (ecs
->event_thread
->step_range_end
== 0)
4061 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4062 /* Likewise if we aren't even stepping. */
4067 /* Re-fetch current thread's frame in case the code above caused
4068 the frame cache to be re-initialized, making our FRAME variable
4069 a dangling pointer. */
4070 frame
= get_current_frame ();
4072 /* If stepping through a line, keep going if still within it.
4074 Note that step_range_end is the address of the first instruction
4075 beyond the step range, and NOT the address of the last instruction
4078 Note also that during reverse execution, we may be stepping
4079 through a function epilogue and therefore must detect when
4080 the current-frame changes in the middle of a line. */
4082 if (stop_pc
>= ecs
->event_thread
->step_range_start
4083 && stop_pc
< ecs
->event_thread
->step_range_end
4084 && (execution_direction
!= EXEC_REVERSE
4085 || frame_id_eq (get_frame_id (frame
),
4086 ecs
->event_thread
->step_frame_id
)))
4090 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4091 paddress (gdbarch
, ecs
->event_thread
->step_range_start
),
4092 paddress (gdbarch
, ecs
->event_thread
->step_range_end
));
4094 /* When stepping backward, stop at beginning of line range
4095 (unless it's the function entry point, in which case
4096 keep going back to the call point). */
4097 if (stop_pc
== ecs
->event_thread
->step_range_start
4098 && stop_pc
!= ecs
->stop_func_start
4099 && execution_direction
== EXEC_REVERSE
)
4101 ecs
->event_thread
->stop_step
= 1;
4102 print_stop_reason (END_STEPPING_RANGE
, 0);
4103 stop_stepping (ecs
);
4111 /* We stepped out of the stepping range. */
4113 /* If we are stepping at the source level and entered the runtime
4114 loader dynamic symbol resolution code...
4116 EXEC_FORWARD: we keep on single stepping until we exit the run
4117 time loader code and reach the callee's address.
4119 EXEC_REVERSE: we've already executed the callee (backward), and
4120 the runtime loader code is handled just like any other
4121 undebuggable function call. Now we need only keep stepping
4122 backward through the trampoline code, and that's handled further
4123 down, so there is nothing for us to do here. */
4125 if (execution_direction
!= EXEC_REVERSE
4126 && ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4127 && in_solib_dynsym_resolve_code (stop_pc
))
4129 CORE_ADDR pc_after_resolver
=
4130 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4133 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
4135 if (pc_after_resolver
)
4137 /* Set up a step-resume breakpoint at the address
4138 indicated by SKIP_SOLIB_RESOLVER. */
4139 struct symtab_and_line sr_sal
;
4141 sr_sal
.pc
= pc_after_resolver
;
4142 sr_sal
.pspace
= get_frame_program_space (frame
);
4144 insert_step_resume_breakpoint_at_sal (gdbarch
,
4145 sr_sal
, null_frame_id
);
4152 if (ecs
->event_thread
->step_range_end
!= 1
4153 && (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4154 || ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
4155 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4158 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
4159 /* The inferior, while doing a "step" or "next", has ended up in
4160 a signal trampoline (either by a signal being delivered or by
4161 the signal handler returning). Just single-step until the
4162 inferior leaves the trampoline (either by calling the handler
4168 /* Check for subroutine calls. The check for the current frame
4169 equalling the step ID is not necessary - the check of the
4170 previous frame's ID is sufficient - but it is a common case and
4171 cheaper than checking the previous frame's ID.
4173 NOTE: frame_id_eq will never report two invalid frame IDs as
4174 being equal, so to get into this block, both the current and
4175 previous frame must have valid frame IDs. */
4176 /* The outer_frame_id check is a heuristic to detect stepping
4177 through startup code. If we step over an instruction which
4178 sets the stack pointer from an invalid value to a valid value,
4179 we may detect that as a subroutine call from the mythical
4180 "outermost" function. This could be fixed by marking
4181 outermost frames as !stack_p,code_p,special_p. Then the
4182 initial outermost frame, before sp was valid, would
4183 have code_addr == &_start. See the comment in frame_id_eq
4185 if (!frame_id_eq (get_stack_frame_id (frame
),
4186 ecs
->event_thread
->step_stack_frame_id
)
4187 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4188 ecs
->event_thread
->step_stack_frame_id
)
4189 && (!frame_id_eq (ecs
->event_thread
->step_stack_frame_id
,
4191 || step_start_function
!= find_pc_function (stop_pc
))))
4193 CORE_ADDR real_stop_pc
;
4196 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4198 if ((ecs
->event_thread
->step_over_calls
== STEP_OVER_NONE
)
4199 || ((ecs
->event_thread
->step_range_end
== 1)
4200 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4201 ecs
->stop_func_start
)))
4203 /* I presume that step_over_calls is only 0 when we're
4204 supposed to be stepping at the assembly language level
4205 ("stepi"). Just stop. */
4206 /* Also, maybe we just did a "nexti" inside a prolog, so we
4207 thought it was a subroutine call but it was not. Stop as
4209 /* And this works the same backward as frontward. MVS */
4210 ecs
->event_thread
->stop_step
= 1;
4211 print_stop_reason (END_STEPPING_RANGE
, 0);
4212 stop_stepping (ecs
);
4216 /* Reverse stepping through solib trampolines. */
4218 if (execution_direction
== EXEC_REVERSE
4219 && ecs
->event_thread
->step_over_calls
!= STEP_OVER_NONE
4220 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4221 || (ecs
->stop_func_start
== 0
4222 && in_solib_dynsym_resolve_code (stop_pc
))))
4224 /* Any solib trampoline code can be handled in reverse
4225 by simply continuing to single-step. We have already
4226 executed the solib function (backwards), and a few
4227 steps will take us back through the trampoline to the
4233 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
4235 /* We're doing a "next".
4237 Normal (forward) execution: set a breakpoint at the
4238 callee's return address (the address at which the caller
4241 Reverse (backward) execution. set the step-resume
4242 breakpoint at the start of the function that we just
4243 stepped into (backwards), and continue to there. When we
4244 get there, we'll need to single-step back to the caller. */
4246 if (execution_direction
== EXEC_REVERSE
)
4248 struct symtab_and_line sr_sal
;
4250 /* Normal function call return (static or dynamic). */
4252 sr_sal
.pc
= ecs
->stop_func_start
;
4253 sr_sal
.pspace
= get_frame_program_space (frame
);
4254 insert_step_resume_breakpoint_at_sal (gdbarch
,
4255 sr_sal
, null_frame_id
);
4258 insert_step_resume_breakpoint_at_caller (frame
);
4264 /* If we are in a function call trampoline (a stub between the
4265 calling routine and the real function), locate the real
4266 function. That's what tells us (a) whether we want to step
4267 into it at all, and (b) what prologue we want to run to the
4268 end of, if we do step into it. */
4269 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4270 if (real_stop_pc
== 0)
4271 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4272 if (real_stop_pc
!= 0)
4273 ecs
->stop_func_start
= real_stop_pc
;
4275 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4277 struct symtab_and_line sr_sal
;
4279 sr_sal
.pc
= ecs
->stop_func_start
;
4280 sr_sal
.pspace
= get_frame_program_space (frame
);
4282 insert_step_resume_breakpoint_at_sal (gdbarch
,
4283 sr_sal
, null_frame_id
);
4288 /* If we have line number information for the function we are
4289 thinking of stepping into, step into it.
4291 If there are several symtabs at that PC (e.g. with include
4292 files), just want to know whether *any* of them have line
4293 numbers. find_pc_line handles this. */
4295 struct symtab_and_line tmp_sal
;
4297 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4298 tmp_sal
.pspace
= get_frame_program_space (frame
);
4299 if (tmp_sal
.line
!= 0)
4301 if (execution_direction
== EXEC_REVERSE
)
4302 handle_step_into_function_backward (gdbarch
, ecs
);
4304 handle_step_into_function (gdbarch
, ecs
);
4309 /* If we have no line number and the step-stop-if-no-debug is
4310 set, we stop the step so that the user has a chance to switch
4311 in assembly mode. */
4312 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4313 && step_stop_if_no_debug
)
4315 ecs
->event_thread
->stop_step
= 1;
4316 print_stop_reason (END_STEPPING_RANGE
, 0);
4317 stop_stepping (ecs
);
4321 if (execution_direction
== EXEC_REVERSE
)
4323 /* Set a breakpoint at callee's start address.
4324 From there we can step once and be back in the caller. */
4325 struct symtab_and_line sr_sal
;
4327 sr_sal
.pc
= ecs
->stop_func_start
;
4328 sr_sal
.pspace
= get_frame_program_space (frame
);
4329 insert_step_resume_breakpoint_at_sal (gdbarch
,
4330 sr_sal
, null_frame_id
);
4333 /* Set a breakpoint at callee's return address (the address
4334 at which the caller will resume). */
4335 insert_step_resume_breakpoint_at_caller (frame
);
4341 /* Reverse stepping through solib trampolines. */
4343 if (execution_direction
== EXEC_REVERSE
4344 && ecs
->event_thread
->step_over_calls
!= STEP_OVER_NONE
)
4346 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4347 || (ecs
->stop_func_start
== 0
4348 && in_solib_dynsym_resolve_code (stop_pc
)))
4350 /* Any solib trampoline code can be handled in reverse
4351 by simply continuing to single-step. We have already
4352 executed the solib function (backwards), and a few
4353 steps will take us back through the trampoline to the
4358 else if (in_solib_dynsym_resolve_code (stop_pc
))
4360 /* Stepped backward into the solib dynsym resolver.
4361 Set a breakpoint at its start and continue, then
4362 one more step will take us out. */
4363 struct symtab_and_line sr_sal
;
4365 sr_sal
.pc
= ecs
->stop_func_start
;
4366 sr_sal
.pspace
= get_frame_program_space (frame
);
4367 insert_step_resume_breakpoint_at_sal (gdbarch
,
4368 sr_sal
, null_frame_id
);
4374 /* If we're in the return path from a shared library trampoline,
4375 we want to proceed through the trampoline when stepping. */
4376 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4377 stop_pc
, ecs
->stop_func_name
))
4379 /* Determine where this trampoline returns. */
4380 CORE_ADDR real_stop_pc
;
4381 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4384 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
4386 /* Only proceed through if we know where it's going. */
4389 /* And put the step-breakpoint there and go until there. */
4390 struct symtab_and_line sr_sal
;
4392 init_sal (&sr_sal
); /* initialize to zeroes */
4393 sr_sal
.pc
= real_stop_pc
;
4394 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4395 sr_sal
.pspace
= get_frame_program_space (frame
);
4397 /* Do not specify what the fp should be when we stop since
4398 on some machines the prologue is where the new fp value
4400 insert_step_resume_breakpoint_at_sal (gdbarch
,
4401 sr_sal
, null_frame_id
);
4403 /* Restart without fiddling with the step ranges or
4410 stop_pc_sal
= find_pc_line (stop_pc
, 0);
4412 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4413 the trampoline processing logic, however, there are some trampolines
4414 that have no names, so we should do trampoline handling first. */
4415 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
4416 && ecs
->stop_func_name
== NULL
4417 && stop_pc_sal
.line
== 0)
4420 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
4422 /* The inferior just stepped into, or returned to, an
4423 undebuggable function (where there is no debugging information
4424 and no line number corresponding to the address where the
4425 inferior stopped). Since we want to skip this kind of code,
4426 we keep going until the inferior returns from this
4427 function - unless the user has asked us not to (via
4428 set step-mode) or we no longer know how to get back
4429 to the call site. */
4430 if (step_stop_if_no_debug
4431 || !frame_id_p (frame_unwind_caller_id (frame
)))
4433 /* If we have no line number and the step-stop-if-no-debug
4434 is set, we stop the step so that the user has a chance to
4435 switch in assembly mode. */
4436 ecs
->event_thread
->stop_step
= 1;
4437 print_stop_reason (END_STEPPING_RANGE
, 0);
4438 stop_stepping (ecs
);
4443 /* Set a breakpoint at callee's return address (the address
4444 at which the caller will resume). */
4445 insert_step_resume_breakpoint_at_caller (frame
);
4451 if (ecs
->event_thread
->step_range_end
== 1)
4453 /* It is stepi or nexti. We always want to stop stepping after
4456 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
4457 ecs
->event_thread
->stop_step
= 1;
4458 print_stop_reason (END_STEPPING_RANGE
, 0);
4459 stop_stepping (ecs
);
4463 if (stop_pc_sal
.line
== 0)
4465 /* We have no line number information. That means to stop
4466 stepping (does this always happen right after one instruction,
4467 when we do "s" in a function with no line numbers,
4468 or can this happen as a result of a return or longjmp?). */
4470 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
4471 ecs
->event_thread
->stop_step
= 1;
4472 print_stop_reason (END_STEPPING_RANGE
, 0);
4473 stop_stepping (ecs
);
4477 /* Look for "calls" to inlined functions, part one. If the inline
4478 frame machinery detected some skipped call sites, we have entered
4479 a new inline function. */
4481 if (frame_id_eq (get_frame_id (get_current_frame ()),
4482 ecs
->event_thread
->step_frame_id
)
4483 && inline_skipped_frames (ecs
->ptid
))
4485 struct symtab_and_line call_sal
;
4488 fprintf_unfiltered (gdb_stdlog
,
4489 "infrun: stepped into inlined function\n");
4491 find_frame_sal (get_current_frame (), &call_sal
);
4493 if (ecs
->event_thread
->step_over_calls
!= STEP_OVER_ALL
)
4495 /* For "step", we're going to stop. But if the call site
4496 for this inlined function is on the same source line as
4497 we were previously stepping, go down into the function
4498 first. Otherwise stop at the call site. */
4500 if (call_sal
.line
== ecs
->event_thread
->current_line
4501 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
4502 step_into_inline_frame (ecs
->ptid
);
4504 ecs
->event_thread
->stop_step
= 1;
4505 print_stop_reason (END_STEPPING_RANGE
, 0);
4506 stop_stepping (ecs
);
4511 /* For "next", we should stop at the call site if it is on a
4512 different source line. Otherwise continue through the
4513 inlined function. */
4514 if (call_sal
.line
== ecs
->event_thread
->current_line
4515 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
4519 ecs
->event_thread
->stop_step
= 1;
4520 print_stop_reason (END_STEPPING_RANGE
, 0);
4521 stop_stepping (ecs
);
4527 /* Look for "calls" to inlined functions, part two. If we are still
4528 in the same real function we were stepping through, but we have
4529 to go further up to find the exact frame ID, we are stepping
4530 through a more inlined call beyond its call site. */
4532 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
4533 && !frame_id_eq (get_frame_id (get_current_frame ()),
4534 ecs
->event_thread
->step_frame_id
)
4535 && stepped_in_from (get_current_frame (),
4536 ecs
->event_thread
->step_frame_id
))
4539 fprintf_unfiltered (gdb_stdlog
,
4540 "infrun: stepping through inlined function\n");
4542 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
4546 ecs
->event_thread
->stop_step
= 1;
4547 print_stop_reason (END_STEPPING_RANGE
, 0);
4548 stop_stepping (ecs
);
4553 if ((stop_pc
== stop_pc_sal
.pc
)
4554 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
4555 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
4557 /* We are at the start of a different line. So stop. Note that
4558 we don't stop if we step into the middle of a different line.
4559 That is said to make things like for (;;) statements work
4562 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
4563 ecs
->event_thread
->stop_step
= 1;
4564 print_stop_reason (END_STEPPING_RANGE
, 0);
4565 stop_stepping (ecs
);
4569 /* We aren't done stepping.
4571 Optimize by setting the stepping range to the line.
4572 (We might not be in the original line, but if we entered a
4573 new line in mid-statement, we continue stepping. This makes
4574 things like for(;;) statements work better.) */
4576 ecs
->event_thread
->step_range_start
= stop_pc_sal
.pc
;
4577 ecs
->event_thread
->step_range_end
= stop_pc_sal
.end
;
4578 set_step_info (frame
, stop_pc_sal
);
4581 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
4585 /* Is thread TP in the middle of single-stepping? */
4588 currently_stepping (struct thread_info
*tp
)
4590 return ((tp
->step_range_end
&& tp
->step_resume_breakpoint
== NULL
)
4591 || tp
->trap_expected
4592 || tp
->stepping_through_solib_after_catch
4593 || bpstat_should_step ());
4596 /* Returns true if any thread *but* the one passed in "data" is in the
4597 middle of stepping or of handling a "next". */
4600 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
4605 return (tp
->step_range_end
4606 || tp
->trap_expected
4607 || tp
->stepping_through_solib_after_catch
);
4610 /* Inferior has stepped into a subroutine call with source code that
4611 we should not step over. Do step to the first line of code in
4615 handle_step_into_function (struct gdbarch
*gdbarch
,
4616 struct execution_control_state
*ecs
)
4619 struct symtab_and_line stop_func_sal
, sr_sal
;
4621 s
= find_pc_symtab (stop_pc
);
4622 if (s
&& s
->language
!= language_asm
)
4623 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
4624 ecs
->stop_func_start
);
4626 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4627 /* Use the step_resume_break to step until the end of the prologue,
4628 even if that involves jumps (as it seems to on the vax under
4630 /* If the prologue ends in the middle of a source line, continue to
4631 the end of that source line (if it is still within the function).
4632 Otherwise, just go to end of prologue. */
4633 if (stop_func_sal
.end
4634 && stop_func_sal
.pc
!= ecs
->stop_func_start
4635 && stop_func_sal
.end
< ecs
->stop_func_end
)
4636 ecs
->stop_func_start
= stop_func_sal
.end
;
4638 /* Architectures which require breakpoint adjustment might not be able
4639 to place a breakpoint at the computed address. If so, the test
4640 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
4641 ecs->stop_func_start to an address at which a breakpoint may be
4642 legitimately placed.
4644 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
4645 made, GDB will enter an infinite loop when stepping through
4646 optimized code consisting of VLIW instructions which contain
4647 subinstructions corresponding to different source lines. On
4648 FR-V, it's not permitted to place a breakpoint on any but the
4649 first subinstruction of a VLIW instruction. When a breakpoint is
4650 set, GDB will adjust the breakpoint address to the beginning of
4651 the VLIW instruction. Thus, we need to make the corresponding
4652 adjustment here when computing the stop address. */
4654 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
4656 ecs
->stop_func_start
4657 = gdbarch_adjust_breakpoint_address (gdbarch
,
4658 ecs
->stop_func_start
);
4661 if (ecs
->stop_func_start
== stop_pc
)
4663 /* We are already there: stop now. */
4664 ecs
->event_thread
->stop_step
= 1;
4665 print_stop_reason (END_STEPPING_RANGE
, 0);
4666 stop_stepping (ecs
);
4671 /* Put the step-breakpoint there and go until there. */
4672 init_sal (&sr_sal
); /* initialize to zeroes */
4673 sr_sal
.pc
= ecs
->stop_func_start
;
4674 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
4675 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
4677 /* Do not specify what the fp should be when we stop since on
4678 some machines the prologue is where the new fp value is
4680 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
4682 /* And make sure stepping stops right away then. */
4683 ecs
->event_thread
->step_range_end
= ecs
->event_thread
->step_range_start
;
4688 /* Inferior has stepped backward into a subroutine call with source
4689 code that we should not step over. Do step to the beginning of the
4690 last line of code in it. */
4693 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
4694 struct execution_control_state
*ecs
)
4697 struct symtab_and_line stop_func_sal
, sr_sal
;
4699 s
= find_pc_symtab (stop_pc
);
4700 if (s
&& s
->language
!= language_asm
)
4701 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
4702 ecs
->stop_func_start
);
4704 stop_func_sal
= find_pc_line (stop_pc
, 0);
4706 /* OK, we're just going to keep stepping here. */
4707 if (stop_func_sal
.pc
== stop_pc
)
4709 /* We're there already. Just stop stepping now. */
4710 ecs
->event_thread
->stop_step
= 1;
4711 print_stop_reason (END_STEPPING_RANGE
, 0);
4712 stop_stepping (ecs
);
4716 /* Else just reset the step range and keep going.
4717 No step-resume breakpoint, they don't work for
4718 epilogues, which can have multiple entry paths. */
4719 ecs
->event_thread
->step_range_start
= stop_func_sal
.pc
;
4720 ecs
->event_thread
->step_range_end
= stop_func_sal
.end
;
4726 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
4727 This is used to both functions and to skip over code. */
4730 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
4731 struct symtab_and_line sr_sal
,
4732 struct frame_id sr_id
)
4734 /* There should never be more than one step-resume or longjmp-resume
4735 breakpoint per thread, so we should never be setting a new
4736 step_resume_breakpoint when one is already active. */
4737 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
4740 fprintf_unfiltered (gdb_stdlog
,
4741 "infrun: inserting step-resume breakpoint at %s\n",
4742 paddress (gdbarch
, sr_sal
.pc
));
4744 inferior_thread ()->step_resume_breakpoint
4745 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, bp_step_resume
);
4748 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
4749 to skip a potential signal handler.
4751 This is called with the interrupted function's frame. The signal
4752 handler, when it returns, will resume the interrupted function at
4756 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
4758 struct symtab_and_line sr_sal
;
4759 struct gdbarch
*gdbarch
;
4761 gdb_assert (return_frame
!= NULL
);
4762 init_sal (&sr_sal
); /* initialize to zeros */
4764 gdbarch
= get_frame_arch (return_frame
);
4765 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
4766 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4767 sr_sal
.pspace
= get_frame_program_space (return_frame
);
4769 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
4770 get_stack_frame_id (return_frame
));
4773 /* Similar to insert_step_resume_breakpoint_at_frame, except
4774 but a breakpoint at the previous frame's PC. This is used to
4775 skip a function after stepping into it (for "next" or if the called
4776 function has no debugging information).
4778 The current function has almost always been reached by single
4779 stepping a call or return instruction. NEXT_FRAME belongs to the
4780 current function, and the breakpoint will be set at the caller's
4783 This is a separate function rather than reusing
4784 insert_step_resume_breakpoint_at_frame in order to avoid
4785 get_prev_frame, which may stop prematurely (see the implementation
4786 of frame_unwind_caller_id for an example). */
4789 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
4791 struct symtab_and_line sr_sal
;
4792 struct gdbarch
*gdbarch
;
4794 /* We shouldn't have gotten here if we don't know where the call site
4796 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
4798 init_sal (&sr_sal
); /* initialize to zeros */
4800 gdbarch
= frame_unwind_caller_arch (next_frame
);
4801 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
4802 frame_unwind_caller_pc (next_frame
));
4803 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4804 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
4806 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
4807 frame_unwind_caller_id (next_frame
));
4810 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
4811 new breakpoint at the target of a jmp_buf. The handling of
4812 longjmp-resume uses the same mechanisms used for handling
4813 "step-resume" breakpoints. */
4816 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4818 /* There should never be more than one step-resume or longjmp-resume
4819 breakpoint per thread, so we should never be setting a new
4820 longjmp_resume_breakpoint when one is already active. */
4821 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
4824 fprintf_unfiltered (gdb_stdlog
,
4825 "infrun: inserting longjmp-resume breakpoint at %s\n",
4826 paddress (gdbarch
, pc
));
4828 inferior_thread ()->step_resume_breakpoint
=
4829 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
4833 stop_stepping (struct execution_control_state
*ecs
)
4836 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
4838 /* Let callers know we don't want to wait for the inferior anymore. */
4839 ecs
->wait_some_more
= 0;
4842 /* This function handles various cases where we need to continue
4843 waiting for the inferior. */
4844 /* (Used to be the keep_going: label in the old wait_for_inferior) */
4847 keep_going (struct execution_control_state
*ecs
)
4849 /* Make sure normal_stop is called if we get a QUIT handled before
4851 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
4853 /* Save the pc before execution, to compare with pc after stop. */
4854 ecs
->event_thread
->prev_pc
4855 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4857 /* If we did not do break;, it means we should keep running the
4858 inferior and not return to debugger. */
4860 if (ecs
->event_thread
->trap_expected
4861 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
4863 /* We took a signal (which we are supposed to pass through to
4864 the inferior, else we'd not get here) and we haven't yet
4865 gotten our trap. Simply continue. */
4867 discard_cleanups (old_cleanups
);
4868 resume (currently_stepping (ecs
->event_thread
),
4869 ecs
->event_thread
->stop_signal
);
4873 /* Either the trap was not expected, but we are continuing
4874 anyway (the user asked that this signal be passed to the
4877 The signal was SIGTRAP, e.g. it was our signal, but we
4878 decided we should resume from it.
4880 We're going to run this baby now!
4882 Note that insert_breakpoints won't try to re-insert
4883 already inserted breakpoints. Therefore, we don't
4884 care if breakpoints were already inserted, or not. */
4886 if (ecs
->event_thread
->stepping_over_breakpoint
)
4888 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
4889 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
4890 /* Since we can't do a displaced step, we have to remove
4891 the breakpoint while we step it. To keep things
4892 simple, we remove them all. */
4893 remove_breakpoints ();
4897 struct gdb_exception e
;
4898 /* Stop stepping when inserting breakpoints
4900 TRY_CATCH (e
, RETURN_MASK_ERROR
)
4902 insert_breakpoints ();
4906 exception_print (gdb_stderr
, e
);
4907 stop_stepping (ecs
);
4912 ecs
->event_thread
->trap_expected
= ecs
->event_thread
->stepping_over_breakpoint
;
4914 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
4915 specifies that such a signal should be delivered to the
4918 Typically, this would occure when a user is debugging a
4919 target monitor on a simulator: the target monitor sets a
4920 breakpoint; the simulator encounters this break-point and
4921 halts the simulation handing control to GDB; GDB, noteing
4922 that the break-point isn't valid, returns control back to the
4923 simulator; the simulator then delivers the hardware
4924 equivalent of a SIGNAL_TRAP to the program being debugged. */
4926 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
4927 && !signal_program
[ecs
->event_thread
->stop_signal
])
4928 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
4930 discard_cleanups (old_cleanups
);
4931 resume (currently_stepping (ecs
->event_thread
),
4932 ecs
->event_thread
->stop_signal
);
4935 prepare_to_wait (ecs
);
4938 /* This function normally comes after a resume, before
4939 handle_inferior_event exits. It takes care of any last bits of
4940 housekeeping, and sets the all-important wait_some_more flag. */
4943 prepare_to_wait (struct execution_control_state
*ecs
)
4946 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
4948 /* This is the old end of the while loop. Let everybody know we
4949 want to wait for the inferior some more and get called again
4951 ecs
->wait_some_more
= 1;
4954 /* Print why the inferior has stopped. We always print something when
4955 the inferior exits, or receives a signal. The rest of the cases are
4956 dealt with later on in normal_stop() and print_it_typical(). Ideally
4957 there should be a call to this function from handle_inferior_event()
4958 each time stop_stepping() is called.*/
4960 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
4962 switch (stop_reason
)
4964 case END_STEPPING_RANGE
:
4965 /* We are done with a step/next/si/ni command. */
4966 /* For now print nothing. */
4967 /* Print a message only if not in the middle of doing a "step n"
4968 operation for n > 1 */
4969 if (!inferior_thread ()->step_multi
4970 || !inferior_thread ()->stop_step
)
4971 if (ui_out_is_mi_like_p (uiout
))
4974 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
4977 /* The inferior was terminated by a signal. */
4978 annotate_signalled ();
4979 if (ui_out_is_mi_like_p (uiout
))
4982 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
4983 ui_out_text (uiout
, "\nProgram terminated with signal ");
4984 annotate_signal_name ();
4985 ui_out_field_string (uiout
, "signal-name",
4986 target_signal_to_name (stop_info
));
4987 annotate_signal_name_end ();
4988 ui_out_text (uiout
, ", ");
4989 annotate_signal_string ();
4990 ui_out_field_string (uiout
, "signal-meaning",
4991 target_signal_to_string (stop_info
));
4992 annotate_signal_string_end ();
4993 ui_out_text (uiout
, ".\n");
4994 ui_out_text (uiout
, "The program no longer exists.\n");
4997 /* The inferior program is finished. */
4998 annotate_exited (stop_info
);
5001 if (ui_out_is_mi_like_p (uiout
))
5002 ui_out_field_string (uiout
, "reason",
5003 async_reason_lookup (EXEC_ASYNC_EXITED
));
5004 ui_out_text (uiout
, "\nProgram exited with code ");
5005 ui_out_field_fmt (uiout
, "exit-code", "0%o",
5006 (unsigned int) stop_info
);
5007 ui_out_text (uiout
, ".\n");
5011 if (ui_out_is_mi_like_p (uiout
))
5014 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5015 ui_out_text (uiout
, "\nProgram exited normally.\n");
5017 /* Support the --return-child-result option. */
5018 return_child_result_value
= stop_info
;
5020 case SIGNAL_RECEIVED
:
5021 /* Signal received. The signal table tells us to print about
5025 if (stop_info
== TARGET_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5027 struct thread_info
*t
= inferior_thread ();
5029 ui_out_text (uiout
, "\n[");
5030 ui_out_field_string (uiout
, "thread-name",
5031 target_pid_to_str (t
->ptid
));
5032 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5033 ui_out_text (uiout
, " stopped");
5037 ui_out_text (uiout
, "\nProgram received signal ");
5038 annotate_signal_name ();
5039 if (ui_out_is_mi_like_p (uiout
))
5041 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
5042 ui_out_field_string (uiout
, "signal-name",
5043 target_signal_to_name (stop_info
));
5044 annotate_signal_name_end ();
5045 ui_out_text (uiout
, ", ");
5046 annotate_signal_string ();
5047 ui_out_field_string (uiout
, "signal-meaning",
5048 target_signal_to_string (stop_info
));
5049 annotate_signal_string_end ();
5051 ui_out_text (uiout
, ".\n");
5054 /* Reverse execution: target ran out of history info. */
5055 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
5058 internal_error (__FILE__
, __LINE__
,
5059 _("print_stop_reason: unrecognized enum value"));
5065 /* Here to return control to GDB when the inferior stops for real.
5066 Print appropriate messages, remove breakpoints, give terminal our modes.
5068 STOP_PRINT_FRAME nonzero means print the executing frame
5069 (pc, function, args, file, line number and line text).
5070 BREAKPOINTS_FAILED nonzero means stop was due to error
5071 attempting to insert breakpoints. */
5076 struct target_waitstatus last
;
5078 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5080 get_last_target_status (&last_ptid
, &last
);
5082 /* If an exception is thrown from this point on, make sure to
5083 propagate GDB's knowledge of the executing state to the
5084 frontend/user running state. A QUIT is an easy exception to see
5085 here, so do this before any filtered output. */
5087 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
5088 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5089 && last
.kind
!= TARGET_WAITKIND_EXITED
)
5090 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
5092 /* In non-stop mode, we don't want GDB to switch threads behind the
5093 user's back, to avoid races where the user is typing a command to
5094 apply to thread x, but GDB switches to thread y before the user
5095 finishes entering the command. */
5097 /* As with the notification of thread events, we want to delay
5098 notifying the user that we've switched thread context until
5099 the inferior actually stops.
5101 There's no point in saying anything if the inferior has exited.
5102 Note that SIGNALLED here means "exited with a signal", not
5103 "received a signal". */
5105 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
5106 && target_has_execution
5107 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5108 && last
.kind
!= TARGET_WAITKIND_EXITED
)
5110 target_terminal_ours_for_output ();
5111 printf_filtered (_("[Switching to %s]\n"),
5112 target_pid_to_str (inferior_ptid
));
5113 annotate_thread_changed ();
5114 previous_inferior_ptid
= inferior_ptid
;
5117 if (!breakpoints_always_inserted_mode () && target_has_execution
)
5119 if (remove_breakpoints ())
5121 target_terminal_ours_for_output ();
5122 printf_filtered (_("\
5123 Cannot remove breakpoints because program is no longer writable.\n\
5124 Further execution is probably impossible.\n"));
5128 /* If an auto-display called a function and that got a signal,
5129 delete that auto-display to avoid an infinite recursion. */
5131 if (stopped_by_random_signal
)
5132 disable_current_display ();
5134 /* Don't print a message if in the middle of doing a "step n"
5135 operation for n > 1 */
5136 if (target_has_execution
5137 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5138 && last
.kind
!= TARGET_WAITKIND_EXITED
5139 && inferior_thread ()->step_multi
5140 && inferior_thread ()->stop_step
)
5143 target_terminal_ours ();
5145 /* Set the current source location. This will also happen if we
5146 display the frame below, but the current SAL will be incorrect
5147 during a user hook-stop function. */
5148 if (has_stack_frames () && !stop_stack_dummy
)
5149 set_current_sal_from_frame (get_current_frame (), 1);
5151 /* Let the user/frontend see the threads as stopped. */
5152 do_cleanups (old_chain
);
5154 /* Look up the hook_stop and run it (CLI internally handles problem
5155 of stop_command's pre-hook not existing). */
5157 catch_errors (hook_stop_stub
, stop_command
,
5158 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
5160 if (!has_stack_frames ())
5163 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
5164 || last
.kind
== TARGET_WAITKIND_EXITED
)
5167 /* Select innermost stack frame - i.e., current frame is frame 0,
5168 and current location is based on that.
5169 Don't do this on return from a stack dummy routine,
5170 or if the program has exited. */
5172 if (!stop_stack_dummy
)
5174 select_frame (get_current_frame ());
5176 /* Print current location without a level number, if
5177 we have changed functions or hit a breakpoint.
5178 Print source line if we have one.
5179 bpstat_print() contains the logic deciding in detail
5180 what to print, based on the event(s) that just occurred. */
5182 /* If --batch-silent is enabled then there's no need to print the current
5183 source location, and to try risks causing an error message about
5184 missing source files. */
5185 if (stop_print_frame
&& !batch_silent
)
5189 int do_frame_printing
= 1;
5190 struct thread_info
*tp
= inferior_thread ();
5192 bpstat_ret
= bpstat_print (tp
->stop_bpstat
);
5196 /* If we had hit a shared library event breakpoint,
5197 bpstat_print would print out this message. If we hit
5198 an OS-level shared library event, do the same
5200 if (last
.kind
== TARGET_WAITKIND_LOADED
)
5202 printf_filtered (_("Stopped due to shared library event\n"));
5203 source_flag
= SRC_LINE
; /* something bogus */
5204 do_frame_printing
= 0;
5208 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5209 (or should) carry around the function and does (or
5210 should) use that when doing a frame comparison. */
5212 && frame_id_eq (tp
->step_frame_id
,
5213 get_frame_id (get_current_frame ()))
5214 && step_start_function
== find_pc_function (stop_pc
))
5215 source_flag
= SRC_LINE
; /* finished step, just print source line */
5217 source_flag
= SRC_AND_LOC
; /* print location and source line */
5219 case PRINT_SRC_AND_LOC
:
5220 source_flag
= SRC_AND_LOC
; /* print location and source line */
5222 case PRINT_SRC_ONLY
:
5223 source_flag
= SRC_LINE
;
5226 source_flag
= SRC_LINE
; /* something bogus */
5227 do_frame_printing
= 0;
5230 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
5233 /* The behavior of this routine with respect to the source
5235 SRC_LINE: Print only source line
5236 LOCATION: Print only location
5237 SRC_AND_LOC: Print location and source line */
5238 if (do_frame_printing
)
5239 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
5241 /* Display the auto-display expressions. */
5246 /* Save the function value return registers, if we care.
5247 We might be about to restore their previous contents. */
5248 if (inferior_thread ()->proceed_to_finish
)
5250 /* This should not be necessary. */
5252 regcache_xfree (stop_registers
);
5254 /* NB: The copy goes through to the target picking up the value of
5255 all the registers. */
5256 stop_registers
= regcache_dup (get_current_regcache ());
5259 if (stop_stack_dummy
)
5261 /* Pop the empty frame that contains the stack dummy.
5262 This also restores inferior state prior to the call
5263 (struct inferior_thread_state). */
5264 struct frame_info
*frame
= get_current_frame ();
5265 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
5267 /* frame_pop() calls reinit_frame_cache as the last thing it does
5268 which means there's currently no selected frame. We don't need
5269 to re-establish a selected frame if the dummy call returns normally,
5270 that will be done by restore_inferior_status. However, we do have
5271 to handle the case where the dummy call is returning after being
5272 stopped (e.g. the dummy call previously hit a breakpoint). We
5273 can't know which case we have so just always re-establish a
5274 selected frame here. */
5275 select_frame (get_current_frame ());
5279 annotate_stopped ();
5281 /* Suppress the stop observer if we're in the middle of:
5283 - a step n (n > 1), as there still more steps to be done.
5285 - a "finish" command, as the observer will be called in
5286 finish_command_continuation, so it can include the inferior
5287 function's return value.
5289 - calling an inferior function, as we pretend we inferior didn't
5290 run at all. The return value of the call is handled by the
5291 expression evaluator, through call_function_by_hand. */
5293 if (!target_has_execution
5294 || last
.kind
== TARGET_WAITKIND_SIGNALLED
5295 || last
.kind
== TARGET_WAITKIND_EXITED
5296 || (!inferior_thread ()->step_multi
5297 && !(inferior_thread ()->stop_bpstat
5298 && inferior_thread ()->proceed_to_finish
)
5299 && !inferior_thread ()->in_infcall
))
5301 if (!ptid_equal (inferior_ptid
, null_ptid
))
5302 observer_notify_normal_stop (inferior_thread ()->stop_bpstat
,
5305 observer_notify_normal_stop (NULL
, stop_print_frame
);
5308 if (target_has_execution
)
5310 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5311 && last
.kind
!= TARGET_WAITKIND_EXITED
)
5312 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5313 Delete any breakpoint that is to be deleted at the next stop. */
5314 breakpoint_auto_delete (inferior_thread ()->stop_bpstat
);
5317 /* Try to get rid of automatically added inferiors that are no
5318 longer needed. Keeping those around slows down things linearly.
5319 Note that this never removes the current inferior. */
5324 hook_stop_stub (void *cmd
)
5326 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
5331 signal_stop_state (int signo
)
5333 return signal_stop
[signo
];
5337 signal_print_state (int signo
)
5339 return signal_print
[signo
];
5343 signal_pass_state (int signo
)
5345 return signal_program
[signo
];
5349 signal_stop_update (int signo
, int state
)
5351 int ret
= signal_stop
[signo
];
5352 signal_stop
[signo
] = state
;
5357 signal_print_update (int signo
, int state
)
5359 int ret
= signal_print
[signo
];
5360 signal_print
[signo
] = state
;
5365 signal_pass_update (int signo
, int state
)
5367 int ret
= signal_program
[signo
];
5368 signal_program
[signo
] = state
;
5373 sig_print_header (void)
5375 printf_filtered (_("\
5376 Signal Stop\tPrint\tPass to program\tDescription\n"));
5380 sig_print_info (enum target_signal oursig
)
5382 const char *name
= target_signal_to_name (oursig
);
5383 int name_padding
= 13 - strlen (name
);
5385 if (name_padding
<= 0)
5388 printf_filtered ("%s", name
);
5389 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
5390 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
5391 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
5392 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
5393 printf_filtered ("%s\n", target_signal_to_string (oursig
));
5396 /* Specify how various signals in the inferior should be handled. */
5399 handle_command (char *args
, int from_tty
)
5402 int digits
, wordlen
;
5403 int sigfirst
, signum
, siglast
;
5404 enum target_signal oursig
;
5407 unsigned char *sigs
;
5408 struct cleanup
*old_chain
;
5412 error_no_arg (_("signal to handle"));
5415 /* Allocate and zero an array of flags for which signals to handle. */
5417 nsigs
= (int) TARGET_SIGNAL_LAST
;
5418 sigs
= (unsigned char *) alloca (nsigs
);
5419 memset (sigs
, 0, nsigs
);
5421 /* Break the command line up into args. */
5423 argv
= gdb_buildargv (args
);
5424 old_chain
= make_cleanup_freeargv (argv
);
5426 /* Walk through the args, looking for signal oursigs, signal names, and
5427 actions. Signal numbers and signal names may be interspersed with
5428 actions, with the actions being performed for all signals cumulatively
5429 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
5431 while (*argv
!= NULL
)
5433 wordlen
= strlen (*argv
);
5434 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
5438 sigfirst
= siglast
= -1;
5440 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
5442 /* Apply action to all signals except those used by the
5443 debugger. Silently skip those. */
5446 siglast
= nsigs
- 1;
5448 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
5450 SET_SIGS (nsigs
, sigs
, signal_stop
);
5451 SET_SIGS (nsigs
, sigs
, signal_print
);
5453 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
5455 UNSET_SIGS (nsigs
, sigs
, signal_program
);
5457 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
5459 SET_SIGS (nsigs
, sigs
, signal_print
);
5461 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
5463 SET_SIGS (nsigs
, sigs
, signal_program
);
5465 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
5467 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
5469 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
5471 SET_SIGS (nsigs
, sigs
, signal_program
);
5473 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
5475 UNSET_SIGS (nsigs
, sigs
, signal_print
);
5476 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
5478 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
5480 UNSET_SIGS (nsigs
, sigs
, signal_program
);
5482 else if (digits
> 0)
5484 /* It is numeric. The numeric signal refers to our own
5485 internal signal numbering from target.h, not to host/target
5486 signal number. This is a feature; users really should be
5487 using symbolic names anyway, and the common ones like
5488 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
5490 sigfirst
= siglast
= (int)
5491 target_signal_from_command (atoi (*argv
));
5492 if ((*argv
)[digits
] == '-')
5495 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
5497 if (sigfirst
> siglast
)
5499 /* Bet he didn't figure we'd think of this case... */
5507 oursig
= target_signal_from_name (*argv
);
5508 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
5510 sigfirst
= siglast
= (int) oursig
;
5514 /* Not a number and not a recognized flag word => complain. */
5515 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
5519 /* If any signal numbers or symbol names were found, set flags for
5520 which signals to apply actions to. */
5522 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
5524 switch ((enum target_signal
) signum
)
5526 case TARGET_SIGNAL_TRAP
:
5527 case TARGET_SIGNAL_INT
:
5528 if (!allsigs
&& !sigs
[signum
])
5530 if (query (_("%s is used by the debugger.\n\
5531 Are you sure you want to change it? "), target_signal_to_name ((enum target_signal
) signum
)))
5537 printf_unfiltered (_("Not confirmed, unchanged.\n"));
5538 gdb_flush (gdb_stdout
);
5542 case TARGET_SIGNAL_0
:
5543 case TARGET_SIGNAL_DEFAULT
:
5544 case TARGET_SIGNAL_UNKNOWN
:
5545 /* Make sure that "all" doesn't print these. */
5556 for (signum
= 0; signum
< nsigs
; signum
++)
5559 target_notice_signals (inferior_ptid
);
5563 /* Show the results. */
5564 sig_print_header ();
5565 for (; signum
< nsigs
; signum
++)
5567 sig_print_info (signum
);
5573 do_cleanups (old_chain
);
5577 xdb_handle_command (char *args
, int from_tty
)
5580 struct cleanup
*old_chain
;
5583 error_no_arg (_("xdb command"));
5585 /* Break the command line up into args. */
5587 argv
= gdb_buildargv (args
);
5588 old_chain
= make_cleanup_freeargv (argv
);
5589 if (argv
[1] != (char *) NULL
)
5594 bufLen
= strlen (argv
[0]) + 20;
5595 argBuf
= (char *) xmalloc (bufLen
);
5599 enum target_signal oursig
;
5601 oursig
= target_signal_from_name (argv
[0]);
5602 memset (argBuf
, 0, bufLen
);
5603 if (strcmp (argv
[1], "Q") == 0)
5604 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
5607 if (strcmp (argv
[1], "s") == 0)
5609 if (!signal_stop
[oursig
])
5610 sprintf (argBuf
, "%s %s", argv
[0], "stop");
5612 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
5614 else if (strcmp (argv
[1], "i") == 0)
5616 if (!signal_program
[oursig
])
5617 sprintf (argBuf
, "%s %s", argv
[0], "pass");
5619 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
5621 else if (strcmp (argv
[1], "r") == 0)
5623 if (!signal_print
[oursig
])
5624 sprintf (argBuf
, "%s %s", argv
[0], "print");
5626 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
5632 handle_command (argBuf
, from_tty
);
5634 printf_filtered (_("Invalid signal handling flag.\n"));
5639 do_cleanups (old_chain
);
5642 /* Print current contents of the tables set by the handle command.
5643 It is possible we should just be printing signals actually used
5644 by the current target (but for things to work right when switching
5645 targets, all signals should be in the signal tables). */
5648 signals_info (char *signum_exp
, int from_tty
)
5650 enum target_signal oursig
;
5651 sig_print_header ();
5655 /* First see if this is a symbol name. */
5656 oursig
= target_signal_from_name (signum_exp
);
5657 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
5659 /* No, try numeric. */
5661 target_signal_from_command (parse_and_eval_long (signum_exp
));
5663 sig_print_info (oursig
);
5667 printf_filtered ("\n");
5668 /* These ugly casts brought to you by the native VAX compiler. */
5669 for (oursig
= TARGET_SIGNAL_FIRST
;
5670 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
5671 oursig
= (enum target_signal
) ((int) oursig
+ 1))
5675 if (oursig
!= TARGET_SIGNAL_UNKNOWN
5676 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
5677 sig_print_info (oursig
);
5680 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
5683 /* The $_siginfo convenience variable is a bit special. We don't know
5684 for sure the type of the value until we actually have a chance to
5685 fetch the data. The type can change depending on gdbarch, so it it
5686 also dependent on which thread you have selected.
5688 1. making $_siginfo be an internalvar that creates a new value on
5691 2. making the value of $_siginfo be an lval_computed value. */
5693 /* This function implements the lval_computed support for reading a
5697 siginfo_value_read (struct value
*v
)
5699 LONGEST transferred
;
5702 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
5704 value_contents_all_raw (v
),
5706 TYPE_LENGTH (value_type (v
)));
5708 if (transferred
!= TYPE_LENGTH (value_type (v
)))
5709 error (_("Unable to read siginfo"));
5712 /* This function implements the lval_computed support for writing a
5716 siginfo_value_write (struct value
*v
, struct value
*fromval
)
5718 LONGEST transferred
;
5720 transferred
= target_write (¤t_target
,
5721 TARGET_OBJECT_SIGNAL_INFO
,
5723 value_contents_all_raw (fromval
),
5725 TYPE_LENGTH (value_type (fromval
)));
5727 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
5728 error (_("Unable to write siginfo"));
5731 static struct lval_funcs siginfo_value_funcs
=
5737 /* Return a new value with the correct type for the siginfo object of
5738 the current thread using architecture GDBARCH. Return a void value
5739 if there's no object available. */
5741 static struct value
*
5742 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
)
5744 if (target_has_stack
5745 && !ptid_equal (inferior_ptid
, null_ptid
)
5746 && gdbarch_get_siginfo_type_p (gdbarch
))
5748 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
5749 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
5752 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
5756 /* Inferior thread state.
5757 These are details related to the inferior itself, and don't include
5758 things like what frame the user had selected or what gdb was doing
5759 with the target at the time.
5760 For inferior function calls these are things we want to restore
5761 regardless of whether the function call successfully completes
5762 or the dummy frame has to be manually popped. */
5764 struct inferior_thread_state
5766 enum target_signal stop_signal
;
5768 struct regcache
*registers
;
5771 struct inferior_thread_state
*
5772 save_inferior_thread_state (void)
5774 struct inferior_thread_state
*inf_state
= XMALLOC (struct inferior_thread_state
);
5775 struct thread_info
*tp
= inferior_thread ();
5777 inf_state
->stop_signal
= tp
->stop_signal
;
5778 inf_state
->stop_pc
= stop_pc
;
5780 inf_state
->registers
= regcache_dup (get_current_regcache ());
5785 /* Restore inferior session state to INF_STATE. */
5788 restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5790 struct thread_info
*tp
= inferior_thread ();
5792 tp
->stop_signal
= inf_state
->stop_signal
;
5793 stop_pc
= inf_state
->stop_pc
;
5795 /* The inferior can be gone if the user types "print exit(0)"
5796 (and perhaps other times). */
5797 if (target_has_execution
)
5798 /* NB: The register write goes through to the target. */
5799 regcache_cpy (get_current_regcache (), inf_state
->registers
);
5800 regcache_xfree (inf_state
->registers
);
5805 do_restore_inferior_thread_state_cleanup (void *state
)
5807 restore_inferior_thread_state (state
);
5811 make_cleanup_restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5813 return make_cleanup (do_restore_inferior_thread_state_cleanup
, inf_state
);
5817 discard_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5819 regcache_xfree (inf_state
->registers
);
5824 get_inferior_thread_state_regcache (struct inferior_thread_state
*inf_state
)
5826 return inf_state
->registers
;
5829 /* Session related state for inferior function calls.
5830 These are the additional bits of state that need to be restored
5831 when an inferior function call successfully completes. */
5833 struct inferior_status
5837 int stop_stack_dummy
;
5838 int stopped_by_random_signal
;
5839 int stepping_over_breakpoint
;
5840 CORE_ADDR step_range_start
;
5841 CORE_ADDR step_range_end
;
5842 struct frame_id step_frame_id
;
5843 struct frame_id step_stack_frame_id
;
5844 enum step_over_calls_kind step_over_calls
;
5845 CORE_ADDR step_resume_break_address
;
5846 int stop_after_trap
;
5849 /* ID if the selected frame when the inferior function call was made. */
5850 struct frame_id selected_frame_id
;
5852 int proceed_to_finish
;
5856 /* Save all of the information associated with the inferior<==>gdb
5859 struct inferior_status
*
5860 save_inferior_status (void)
5862 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
5863 struct thread_info
*tp
= inferior_thread ();
5864 struct inferior
*inf
= current_inferior ();
5866 inf_status
->stop_step
= tp
->stop_step
;
5867 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
5868 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
5869 inf_status
->stepping_over_breakpoint
= tp
->trap_expected
;
5870 inf_status
->step_range_start
= tp
->step_range_start
;
5871 inf_status
->step_range_end
= tp
->step_range_end
;
5872 inf_status
->step_frame_id
= tp
->step_frame_id
;
5873 inf_status
->step_stack_frame_id
= tp
->step_stack_frame_id
;
5874 inf_status
->step_over_calls
= tp
->step_over_calls
;
5875 inf_status
->stop_after_trap
= stop_after_trap
;
5876 inf_status
->stop_soon
= inf
->stop_soon
;
5877 /* Save original bpstat chain here; replace it with copy of chain.
5878 If caller's caller is walking the chain, they'll be happier if we
5879 hand them back the original chain when restore_inferior_status is
5881 inf_status
->stop_bpstat
= tp
->stop_bpstat
;
5882 tp
->stop_bpstat
= bpstat_copy (tp
->stop_bpstat
);
5883 inf_status
->proceed_to_finish
= tp
->proceed_to_finish
;
5884 inf_status
->in_infcall
= tp
->in_infcall
;
5886 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
5892 restore_selected_frame (void *args
)
5894 struct frame_id
*fid
= (struct frame_id
*) args
;
5895 struct frame_info
*frame
;
5897 frame
= frame_find_by_id (*fid
);
5899 /* If inf_status->selected_frame_id is NULL, there was no previously
5903 warning (_("Unable to restore previously selected frame."));
5907 select_frame (frame
);
5912 /* Restore inferior session state to INF_STATUS. */
5915 restore_inferior_status (struct inferior_status
*inf_status
)
5917 struct thread_info
*tp
= inferior_thread ();
5918 struct inferior
*inf
= current_inferior ();
5920 tp
->stop_step
= inf_status
->stop_step
;
5921 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
5922 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
5923 tp
->trap_expected
= inf_status
->stepping_over_breakpoint
;
5924 tp
->step_range_start
= inf_status
->step_range_start
;
5925 tp
->step_range_end
= inf_status
->step_range_end
;
5926 tp
->step_frame_id
= inf_status
->step_frame_id
;
5927 tp
->step_stack_frame_id
= inf_status
->step_stack_frame_id
;
5928 tp
->step_over_calls
= inf_status
->step_over_calls
;
5929 stop_after_trap
= inf_status
->stop_after_trap
;
5930 inf
->stop_soon
= inf_status
->stop_soon
;
5931 bpstat_clear (&tp
->stop_bpstat
);
5932 tp
->stop_bpstat
= inf_status
->stop_bpstat
;
5933 inf_status
->stop_bpstat
= NULL
;
5934 tp
->proceed_to_finish
= inf_status
->proceed_to_finish
;
5935 tp
->in_infcall
= inf_status
->in_infcall
;
5937 if (target_has_stack
)
5939 /* The point of catch_errors is that if the stack is clobbered,
5940 walking the stack might encounter a garbage pointer and
5941 error() trying to dereference it. */
5943 (restore_selected_frame
, &inf_status
->selected_frame_id
,
5944 "Unable to restore previously selected frame:\n",
5945 RETURN_MASK_ERROR
) == 0)
5946 /* Error in restoring the selected frame. Select the innermost
5948 select_frame (get_current_frame ());
5955 do_restore_inferior_status_cleanup (void *sts
)
5957 restore_inferior_status (sts
);
5961 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
5963 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
5967 discard_inferior_status (struct inferior_status
*inf_status
)
5969 /* See save_inferior_status for info on stop_bpstat. */
5970 bpstat_clear (&inf_status
->stop_bpstat
);
5975 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
5977 struct target_waitstatus last
;
5980 get_last_target_status (&last_ptid
, &last
);
5982 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
5985 if (!ptid_equal (last_ptid
, pid
))
5988 *child_pid
= last
.value
.related_pid
;
5993 inferior_has_vforked (ptid_t pid
, ptid_t
*child_pid
)
5995 struct target_waitstatus last
;
5998 get_last_target_status (&last_ptid
, &last
);
6000 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
6003 if (!ptid_equal (last_ptid
, pid
))
6006 *child_pid
= last
.value
.related_pid
;
6011 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
6013 struct target_waitstatus last
;
6016 get_last_target_status (&last_ptid
, &last
);
6018 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
6021 if (!ptid_equal (last_ptid
, pid
))
6024 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
6029 inferior_has_called_syscall (ptid_t pid
, int *syscall_number
)
6031 struct target_waitstatus last
;
6034 get_last_target_status (&last_ptid
, &last
);
6036 if (last
.kind
!= TARGET_WAITKIND_SYSCALL_ENTRY
&&
6037 last
.kind
!= TARGET_WAITKIND_SYSCALL_RETURN
)
6040 if (!ptid_equal (last_ptid
, pid
))
6043 *syscall_number
= last
.value
.syscall_number
;
6047 /* Oft used ptids */
6049 ptid_t minus_one_ptid
;
6051 /* Create a ptid given the necessary PID, LWP, and TID components. */
6054 ptid_build (int pid
, long lwp
, long tid
)
6064 /* Create a ptid from just a pid. */
6067 pid_to_ptid (int pid
)
6069 return ptid_build (pid
, 0, 0);
6072 /* Fetch the pid (process id) component from a ptid. */
6075 ptid_get_pid (ptid_t ptid
)
6080 /* Fetch the lwp (lightweight process) component from a ptid. */
6083 ptid_get_lwp (ptid_t ptid
)
6088 /* Fetch the tid (thread id) component from a ptid. */
6091 ptid_get_tid (ptid_t ptid
)
6096 /* ptid_equal() is used to test equality of two ptids. */
6099 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
6101 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
6102 && ptid1
.tid
== ptid2
.tid
);
6105 /* Returns true if PTID represents a process. */
6108 ptid_is_pid (ptid_t ptid
)
6110 if (ptid_equal (minus_one_ptid
, ptid
))
6112 if (ptid_equal (null_ptid
, ptid
))
6115 return (ptid_get_lwp (ptid
) == 0 && ptid_get_tid (ptid
) == 0);
6118 /* restore_inferior_ptid() will be used by the cleanup machinery
6119 to restore the inferior_ptid value saved in a call to
6120 save_inferior_ptid(). */
6123 restore_inferior_ptid (void *arg
)
6125 ptid_t
*saved_ptid_ptr
= arg
;
6126 inferior_ptid
= *saved_ptid_ptr
;
6130 /* Save the value of inferior_ptid so that it may be restored by a
6131 later call to do_cleanups(). Returns the struct cleanup pointer
6132 needed for later doing the cleanup. */
6135 save_inferior_ptid (void)
6137 ptid_t
*saved_ptid_ptr
;
6139 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
6140 *saved_ptid_ptr
= inferior_ptid
;
6141 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
6145 /* User interface for reverse debugging:
6146 Set exec-direction / show exec-direction commands
6147 (returns error unless target implements to_set_exec_direction method). */
6149 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
6150 static const char exec_forward
[] = "forward";
6151 static const char exec_reverse
[] = "reverse";
6152 static const char *exec_direction
= exec_forward
;
6153 static const char *exec_direction_names
[] = {
6160 set_exec_direction_func (char *args
, int from_tty
,
6161 struct cmd_list_element
*cmd
)
6163 if (target_can_execute_reverse
)
6165 if (!strcmp (exec_direction
, exec_forward
))
6166 execution_direction
= EXEC_FORWARD
;
6167 else if (!strcmp (exec_direction
, exec_reverse
))
6168 execution_direction
= EXEC_REVERSE
;
6173 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
6174 struct cmd_list_element
*cmd
, const char *value
)
6176 switch (execution_direction
) {
6178 fprintf_filtered (out
, _("Forward.\n"));
6181 fprintf_filtered (out
, _("Reverse.\n"));
6185 fprintf_filtered (out
,
6186 _("Forward (target `%s' does not support exec-direction).\n"),
6192 /* User interface for non-stop mode. */
6195 static int non_stop_1
= 0;
6198 set_non_stop (char *args
, int from_tty
,
6199 struct cmd_list_element
*c
)
6201 if (target_has_execution
)
6203 non_stop_1
= non_stop
;
6204 error (_("Cannot change this setting while the inferior is running."));
6207 non_stop
= non_stop_1
;
6211 show_non_stop (struct ui_file
*file
, int from_tty
,
6212 struct cmd_list_element
*c
, const char *value
)
6214 fprintf_filtered (file
,
6215 _("Controlling the inferior in non-stop mode is %s.\n"),
6220 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
6221 struct cmd_list_element
*c
, const char *value
)
6223 fprintf_filtered (file
, _("\
6224 Resuming the execution of threads of all processes is %s.\n"), value
);
6228 _initialize_infrun (void)
6232 struct cmd_list_element
*c
;
6234 add_info ("signals", signals_info
, _("\
6235 What debugger does when program gets various signals.\n\
6236 Specify a signal as argument to print info on that signal only."));
6237 add_info_alias ("handle", "signals", 0);
6239 add_com ("handle", class_run
, handle_command
, _("\
6240 Specify how to handle a signal.\n\
6241 Args are signals and actions to apply to those signals.\n\
6242 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6243 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6244 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6245 The special arg \"all\" is recognized to mean all signals except those\n\
6246 used by the debugger, typically SIGTRAP and SIGINT.\n\
6247 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6248 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6249 Stop means reenter debugger if this signal happens (implies print).\n\
6250 Print means print a message if this signal happens.\n\
6251 Pass means let program see this signal; otherwise program doesn't know.\n\
6252 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6253 Pass and Stop may be combined."));
6256 add_com ("lz", class_info
, signals_info
, _("\
6257 What debugger does when program gets various signals.\n\
6258 Specify a signal as argument to print info on that signal only."));
6259 add_com ("z", class_run
, xdb_handle_command
, _("\
6260 Specify how to handle a signal.\n\
6261 Args are signals and actions to apply to those signals.\n\
6262 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6263 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6264 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6265 The special arg \"all\" is recognized to mean all signals except those\n\
6266 used by the debugger, typically SIGTRAP and SIGINT.\n\
6267 Recognized actions include \"s\" (toggles between stop and nostop), \n\
6268 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6269 nopass), \"Q\" (noprint)\n\
6270 Stop means reenter debugger if this signal happens (implies print).\n\
6271 Print means print a message if this signal happens.\n\
6272 Pass means let program see this signal; otherwise program doesn't know.\n\
6273 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6274 Pass and Stop may be combined."));
6278 stop_command
= add_cmd ("stop", class_obscure
,
6279 not_just_help_class_command
, _("\
6280 There is no `stop' command, but you can set a hook on `stop'.\n\
6281 This allows you to set a list of commands to be run each time execution\n\
6282 of the program stops."), &cmdlist
);
6284 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
6285 Set inferior debugging."), _("\
6286 Show inferior debugging."), _("\
6287 When non-zero, inferior specific debugging is enabled."),
6290 &setdebuglist
, &showdebuglist
);
6292 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
6293 Set displaced stepping debugging."), _("\
6294 Show displaced stepping debugging."), _("\
6295 When non-zero, displaced stepping specific debugging is enabled."),
6297 show_debug_displaced
,
6298 &setdebuglist
, &showdebuglist
);
6300 add_setshow_boolean_cmd ("non-stop", no_class
,
6302 Set whether gdb controls the inferior in non-stop mode."), _("\
6303 Show whether gdb controls the inferior in non-stop mode."), _("\
6304 When debugging a multi-threaded program and this setting is\n\
6305 off (the default, also called all-stop mode), when one thread stops\n\
6306 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
6307 all other threads in the program while you interact with the thread of\n\
6308 interest. When you continue or step a thread, you can allow the other\n\
6309 threads to run, or have them remain stopped, but while you inspect any\n\
6310 thread's state, all threads stop.\n\
6312 In non-stop mode, when one thread stops, other threads can continue\n\
6313 to run freely. You'll be able to step each thread independently,\n\
6314 leave it stopped or free to run as needed."),
6320 numsigs
= (int) TARGET_SIGNAL_LAST
;
6321 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
6322 signal_print
= (unsigned char *)
6323 xmalloc (sizeof (signal_print
[0]) * numsigs
);
6324 signal_program
= (unsigned char *)
6325 xmalloc (sizeof (signal_program
[0]) * numsigs
);
6326 for (i
= 0; i
< numsigs
; i
++)
6329 signal_print
[i
] = 1;
6330 signal_program
[i
] = 1;
6333 /* Signals caused by debugger's own actions
6334 should not be given to the program afterwards. */
6335 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
6336 signal_program
[TARGET_SIGNAL_INT
] = 0;
6338 /* Signals that are not errors should not normally enter the debugger. */
6339 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
6340 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
6341 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
6342 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
6343 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
6344 signal_print
[TARGET_SIGNAL_PROF
] = 0;
6345 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
6346 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
6347 signal_stop
[TARGET_SIGNAL_IO
] = 0;
6348 signal_print
[TARGET_SIGNAL_IO
] = 0;
6349 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
6350 signal_print
[TARGET_SIGNAL_POLL
] = 0;
6351 signal_stop
[TARGET_SIGNAL_URG
] = 0;
6352 signal_print
[TARGET_SIGNAL_URG
] = 0;
6353 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
6354 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
6356 /* These signals are used internally by user-level thread
6357 implementations. (See signal(5) on Solaris.) Like the above
6358 signals, a healthy program receives and handles them as part of
6359 its normal operation. */
6360 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
6361 signal_print
[TARGET_SIGNAL_LWP
] = 0;
6362 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
6363 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
6364 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
6365 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
6367 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
6368 &stop_on_solib_events
, _("\
6369 Set stopping for shared library events."), _("\
6370 Show stopping for shared library events."), _("\
6371 If nonzero, gdb will give control to the user when the dynamic linker\n\
6372 notifies gdb of shared library events. The most common event of interest\n\
6373 to the user would be loading/unloading of a new library."),
6375 show_stop_on_solib_events
,
6376 &setlist
, &showlist
);
6378 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
6379 follow_fork_mode_kind_names
,
6380 &follow_fork_mode_string
, _("\
6381 Set debugger response to a program call of fork or vfork."), _("\
6382 Show debugger response to a program call of fork or vfork."), _("\
6383 A fork or vfork creates a new process. follow-fork-mode can be:\n\
6384 parent - the original process is debugged after a fork\n\
6385 child - the new process is debugged after a fork\n\
6386 The unfollowed process will continue to run.\n\
6387 By default, the debugger will follow the parent process."),
6389 show_follow_fork_mode_string
,
6390 &setlist
, &showlist
);
6392 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
6393 follow_exec_mode_names
,
6394 &follow_exec_mode_string
, _("\
6395 Set debugger response to a program call of exec."), _("\
6396 Show debugger response to a program call of exec."), _("\
6397 An exec call replaces the program image of a process.\n\
6399 follow-exec-mode can be:\n\
6401 new - the debugger creates a new inferior and rebinds the process \n\
6402 to this new inferior. The program the process was running before\n\
6403 the exec call can be restarted afterwards by restarting the original\n\
6406 same - the debugger keeps the process bound to the same inferior.\n\
6407 The new executable image replaces the previous executable loaded in\n\
6408 the inferior. Restarting the inferior after the exec call restarts\n\
6409 the executable the process was running after the exec call.\n\
6411 By default, the debugger will use the same inferior."),
6413 show_follow_exec_mode_string
,
6414 &setlist
, &showlist
);
6416 add_setshow_enum_cmd ("scheduler-locking", class_run
,
6417 scheduler_enums
, &scheduler_mode
, _("\
6418 Set mode for locking scheduler during execution."), _("\
6419 Show mode for locking scheduler during execution."), _("\
6420 off == no locking (threads may preempt at any time)\n\
6421 on == full locking (no thread except the current thread may run)\n\
6422 step == scheduler locked during every single-step operation.\n\
6423 In this mode, no other thread may run during a step command.\n\
6424 Other threads may run while stepping over a function call ('next')."),
6425 set_schedlock_func
, /* traps on target vector */
6426 show_scheduler_mode
,
6427 &setlist
, &showlist
);
6429 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
6430 Set mode for resuming threads of all processes."), _("\
6431 Show mode for resuming threads of all processes."), _("\
6432 When on, execution commands (such as 'continue' or 'next') resume all\n\
6433 threads of all processes. When off (which is the default), execution\n\
6434 commands only resume the threads of the current process. The set of\n\
6435 threads that are resumed is further refined by the scheduler-locking\n\
6436 mode (see help set scheduler-locking)."),
6438 show_schedule_multiple
,
6439 &setlist
, &showlist
);
6441 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
6442 Set mode of the step operation."), _("\
6443 Show mode of the step operation."), _("\
6444 When set, doing a step over a function without debug line information\n\
6445 will stop at the first instruction of that function. Otherwise, the\n\
6446 function is skipped and the step command stops at a different source line."),
6448 show_step_stop_if_no_debug
,
6449 &setlist
, &showlist
);
6451 add_setshow_enum_cmd ("displaced-stepping", class_run
,
6452 can_use_displaced_stepping_enum
,
6453 &can_use_displaced_stepping
, _("\
6454 Set debugger's willingness to use displaced stepping."), _("\
6455 Show debugger's willingness to use displaced stepping."), _("\
6456 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
6457 supported by the target architecture. If off, gdb will not use displaced\n\
6458 stepping to step over breakpoints, even if such is supported by the target\n\
6459 architecture. If auto (which is the default), gdb will use displaced stepping\n\
6460 if the target architecture supports it and non-stop mode is active, but will not\n\
6461 use it in all-stop mode (see help set non-stop)."),
6463 show_can_use_displaced_stepping
,
6464 &setlist
, &showlist
);
6466 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
6467 &exec_direction
, _("Set direction of execution.\n\
6468 Options are 'forward' or 'reverse'."),
6469 _("Show direction of execution (forward/reverse)."),
6470 _("Tells gdb whether to execute forward or backward."),
6471 set_exec_direction_func
, show_exec_direction_func
,
6472 &setlist
, &showlist
);
6474 /* Set/show detach-on-fork: user-settable mode. */
6476 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
6477 Set whether gdb will detach the child of a fork."), _("\
6478 Show whether gdb will detach the child of a fork."), _("\
6479 Tells gdb whether to detach the child of a fork."),
6480 NULL
, NULL
, &setlist
, &showlist
);
6482 /* ptid initializations */
6483 null_ptid
= ptid_build (0, 0, 0);
6484 minus_one_ptid
= ptid_build (-1, 0, 0);
6485 inferior_ptid
= null_ptid
;
6486 target_last_wait_ptid
= minus_one_ptid
;
6487 displaced_step_ptid
= null_ptid
;
6489 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
6490 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
6491 observer_attach_thread_exit (infrun_thread_thread_exit
);
6493 /* Explicitly create without lookup, since that tries to create a
6494 value with a void typed value, and when we get here, gdbarch
6495 isn't initialized yet. At this point, we're quite sure there
6496 isn't another convenience variable of the same name. */
6497 create_internalvar_type_lazy ("_siginfo", siginfo_make_value
);