1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2013 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_string.h"
27 #include "exceptions.h"
28 #include "breakpoint.h"
32 #include "cli/cli-script.h"
34 #include "gdbthread.h"
46 #include "dictionary.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
52 #include "record-full.h"
53 #include "inline-frame.h"
55 #include "tracepoint.h"
56 #include "continuations.h"
61 #include "completer.h"
62 #include "target-descriptions.h"
64 /* Prototypes for local functions */
66 static void signals_info (char *, int);
68 static void handle_command (char *, int);
70 static void sig_print_info (enum gdb_signal
);
72 static void sig_print_header (void);
74 static void resume_cleanups (void *);
76 static int hook_stop_stub (void *);
78 static int restore_selected_frame (void *);
80 static int follow_fork (void);
82 static void set_schedlock_func (char *args
, int from_tty
,
83 struct cmd_list_element
*c
);
85 static int currently_stepping (struct thread_info
*tp
);
87 static int currently_stepping_or_nexting_callback (struct thread_info
*tp
,
90 static void xdb_handle_command (char *args
, int from_tty
);
92 static int prepare_to_proceed (int);
94 static void print_exited_reason (int exitstatus
);
96 static void print_signal_exited_reason (enum gdb_signal siggnal
);
98 static void print_no_history_reason (void);
100 static void print_signal_received_reason (enum gdb_signal siggnal
);
102 static void print_end_stepping_range_reason (void);
104 void _initialize_infrun (void);
106 void nullify_last_target_wait_ptid (void);
108 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
110 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
112 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
114 /* When set, stop the 'step' command if we enter a function which has
115 no line number information. The normal behavior is that we step
116 over such function. */
117 int step_stop_if_no_debug
= 0;
119 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
120 struct cmd_list_element
*c
, const char *value
)
122 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
125 /* In asynchronous mode, but simulating synchronous execution. */
127 int sync_execution
= 0;
129 /* wait_for_inferior and normal_stop use this to notify the user
130 when the inferior stopped in a different thread than it had been
133 static ptid_t previous_inferior_ptid
;
135 /* Default behavior is to detach newly forked processes (legacy). */
138 int debug_displaced
= 0;
140 show_debug_displaced (struct ui_file
*file
, int from_tty
,
141 struct cmd_list_element
*c
, const char *value
)
143 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
146 unsigned int debug_infrun
= 0;
148 show_debug_infrun (struct ui_file
*file
, int from_tty
,
149 struct cmd_list_element
*c
, const char *value
)
151 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
155 /* Support for disabling address space randomization. */
157 int disable_randomization
= 1;
160 show_disable_randomization (struct ui_file
*file
, int from_tty
,
161 struct cmd_list_element
*c
, const char *value
)
163 if (target_supports_disable_randomization ())
164 fprintf_filtered (file
,
165 _("Disabling randomization of debuggee's "
166 "virtual address space is %s.\n"),
169 fputs_filtered (_("Disabling randomization of debuggee's "
170 "virtual address space is unsupported on\n"
171 "this platform.\n"), file
);
175 set_disable_randomization (char *args
, int from_tty
,
176 struct cmd_list_element
*c
)
178 if (!target_supports_disable_randomization ())
179 error (_("Disabling randomization of debuggee's "
180 "virtual address space is unsupported on\n"
185 /* If the program uses ELF-style shared libraries, then calls to
186 functions in shared libraries go through stubs, which live in a
187 table called the PLT (Procedure Linkage Table). The first time the
188 function is called, the stub sends control to the dynamic linker,
189 which looks up the function's real address, patches the stub so
190 that future calls will go directly to the function, and then passes
191 control to the function.
193 If we are stepping at the source level, we don't want to see any of
194 this --- we just want to skip over the stub and the dynamic linker.
195 The simple approach is to single-step until control leaves the
198 However, on some systems (e.g., Red Hat's 5.2 distribution) the
199 dynamic linker calls functions in the shared C library, so you
200 can't tell from the PC alone whether the dynamic linker is still
201 running. In this case, we use a step-resume breakpoint to get us
202 past the dynamic linker, as if we were using "next" to step over a
205 in_solib_dynsym_resolve_code() says whether we're in the dynamic
206 linker code or not. Normally, this means we single-step. However,
207 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
208 address where we can place a step-resume breakpoint to get past the
209 linker's symbol resolution function.
211 in_solib_dynsym_resolve_code() can generally be implemented in a
212 pretty portable way, by comparing the PC against the address ranges
213 of the dynamic linker's sections.
215 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
216 it depends on internal details of the dynamic linker. It's usually
217 not too hard to figure out where to put a breakpoint, but it
218 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
219 sanity checking. If it can't figure things out, returning zero and
220 getting the (possibly confusing) stepping behavior is better than
221 signalling an error, which will obscure the change in the
224 /* This function returns TRUE if pc is the address of an instruction
225 that lies within the dynamic linker (such as the event hook, or the
228 This function must be used only when a dynamic linker event has
229 been caught, and the inferior is being stepped out of the hook, or
230 undefined results are guaranteed. */
232 #ifndef SOLIB_IN_DYNAMIC_LINKER
233 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
236 /* "Observer mode" is somewhat like a more extreme version of
237 non-stop, in which all GDB operations that might affect the
238 target's execution have been disabled. */
240 static int non_stop_1
= 0;
242 int observer_mode
= 0;
243 static int observer_mode_1
= 0;
246 set_observer_mode (char *args
, int from_tty
,
247 struct cmd_list_element
*c
)
249 extern int pagination_enabled
;
251 if (target_has_execution
)
253 observer_mode_1
= observer_mode
;
254 error (_("Cannot change this setting while the inferior is running."));
257 observer_mode
= observer_mode_1
;
259 may_write_registers
= !observer_mode
;
260 may_write_memory
= !observer_mode
;
261 may_insert_breakpoints
= !observer_mode
;
262 may_insert_tracepoints
= !observer_mode
;
263 /* We can insert fast tracepoints in or out of observer mode,
264 but enable them if we're going into this mode. */
266 may_insert_fast_tracepoints
= 1;
267 may_stop
= !observer_mode
;
268 update_target_permissions ();
270 /* Going *into* observer mode we must force non-stop, then
271 going out we leave it that way. */
274 target_async_permitted
= 1;
275 pagination_enabled
= 0;
276 non_stop
= non_stop_1
= 1;
280 printf_filtered (_("Observer mode is now %s.\n"),
281 (observer_mode
? "on" : "off"));
285 show_observer_mode (struct ui_file
*file
, int from_tty
,
286 struct cmd_list_element
*c
, const char *value
)
288 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
291 /* This updates the value of observer mode based on changes in
292 permissions. Note that we are deliberately ignoring the values of
293 may-write-registers and may-write-memory, since the user may have
294 reason to enable these during a session, for instance to turn on a
295 debugging-related global. */
298 update_observer_mode (void)
302 newval
= (!may_insert_breakpoints
303 && !may_insert_tracepoints
304 && may_insert_fast_tracepoints
308 /* Let the user know if things change. */
309 if (newval
!= observer_mode
)
310 printf_filtered (_("Observer mode is now %s.\n"),
311 (newval
? "on" : "off"));
313 observer_mode
= observer_mode_1
= newval
;
316 /* Tables of how to react to signals; the user sets them. */
318 static unsigned char *signal_stop
;
319 static unsigned char *signal_print
;
320 static unsigned char *signal_program
;
322 /* Table of signals that are registered with "catch signal". A
323 non-zero entry indicates that the signal is caught by some "catch
324 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
326 static unsigned char *signal_catch
;
328 /* Table of signals that the target may silently handle.
329 This is automatically determined from the flags above,
330 and simply cached here. */
331 static unsigned char *signal_pass
;
333 #define SET_SIGS(nsigs,sigs,flags) \
335 int signum = (nsigs); \
336 while (signum-- > 0) \
337 if ((sigs)[signum]) \
338 (flags)[signum] = 1; \
341 #define UNSET_SIGS(nsigs,sigs,flags) \
343 int signum = (nsigs); \
344 while (signum-- > 0) \
345 if ((sigs)[signum]) \
346 (flags)[signum] = 0; \
349 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
350 this function is to avoid exporting `signal_program'. */
353 update_signals_program_target (void)
355 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
358 /* Value to pass to target_resume() to cause all threads to resume. */
360 #define RESUME_ALL minus_one_ptid
362 /* Command list pointer for the "stop" placeholder. */
364 static struct cmd_list_element
*stop_command
;
366 /* Function inferior was in as of last step command. */
368 static struct symbol
*step_start_function
;
370 /* Nonzero if we want to give control to the user when we're notified
371 of shared library events by the dynamic linker. */
372 int stop_on_solib_events
;
374 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
375 struct cmd_list_element
*c
, const char *value
)
377 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
381 /* Nonzero means expecting a trace trap
382 and should stop the inferior and return silently when it happens. */
386 /* Save register contents here when executing a "finish" command or are
387 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
388 Thus this contains the return value from the called function (assuming
389 values are returned in a register). */
391 struct regcache
*stop_registers
;
393 /* Nonzero after stop if current stack frame should be printed. */
395 static int stop_print_frame
;
397 /* This is a cached copy of the pid/waitstatus of the last event
398 returned by target_wait()/deprecated_target_wait_hook(). This
399 information is returned by get_last_target_status(). */
400 static ptid_t target_last_wait_ptid
;
401 static struct target_waitstatus target_last_waitstatus
;
403 static void context_switch (ptid_t ptid
);
405 void init_thread_stepping_state (struct thread_info
*tss
);
407 static void init_infwait_state (void);
409 static const char follow_fork_mode_child
[] = "child";
410 static const char follow_fork_mode_parent
[] = "parent";
412 static const char *const follow_fork_mode_kind_names
[] = {
413 follow_fork_mode_child
,
414 follow_fork_mode_parent
,
418 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
420 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
421 struct cmd_list_element
*c
, const char *value
)
423 fprintf_filtered (file
,
424 _("Debugger response to a program "
425 "call of fork or vfork is \"%s\".\n"),
430 /* Tell the target to follow the fork we're stopped at. Returns true
431 if the inferior should be resumed; false, if the target for some
432 reason decided it's best not to resume. */
437 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
438 int should_resume
= 1;
439 struct thread_info
*tp
;
441 /* Copy user stepping state to the new inferior thread. FIXME: the
442 followed fork child thread should have a copy of most of the
443 parent thread structure's run control related fields, not just these.
444 Initialized to avoid "may be used uninitialized" warnings from gcc. */
445 struct breakpoint
*step_resume_breakpoint
= NULL
;
446 struct breakpoint
*exception_resume_breakpoint
= NULL
;
447 CORE_ADDR step_range_start
= 0;
448 CORE_ADDR step_range_end
= 0;
449 struct frame_id step_frame_id
= { 0 };
454 struct target_waitstatus wait_status
;
456 /* Get the last target status returned by target_wait(). */
457 get_last_target_status (&wait_ptid
, &wait_status
);
459 /* If not stopped at a fork event, then there's nothing else to
461 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
462 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
465 /* Check if we switched over from WAIT_PTID, since the event was
467 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
468 && !ptid_equal (inferior_ptid
, wait_ptid
))
470 /* We did. Switch back to WAIT_PTID thread, to tell the
471 target to follow it (in either direction). We'll
472 afterwards refuse to resume, and inform the user what
474 switch_to_thread (wait_ptid
);
479 tp
= inferior_thread ();
481 /* If there were any forks/vforks that were caught and are now to be
482 followed, then do so now. */
483 switch (tp
->pending_follow
.kind
)
485 case TARGET_WAITKIND_FORKED
:
486 case TARGET_WAITKIND_VFORKED
:
488 ptid_t parent
, child
;
490 /* If the user did a next/step, etc, over a fork call,
491 preserve the stepping state in the fork child. */
492 if (follow_child
&& should_resume
)
494 step_resume_breakpoint
= clone_momentary_breakpoint
495 (tp
->control
.step_resume_breakpoint
);
496 step_range_start
= tp
->control
.step_range_start
;
497 step_range_end
= tp
->control
.step_range_end
;
498 step_frame_id
= tp
->control
.step_frame_id
;
499 exception_resume_breakpoint
500 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
502 /* For now, delete the parent's sr breakpoint, otherwise,
503 parent/child sr breakpoints are considered duplicates,
504 and the child version will not be installed. Remove
505 this when the breakpoints module becomes aware of
506 inferiors and address spaces. */
507 delete_step_resume_breakpoint (tp
);
508 tp
->control
.step_range_start
= 0;
509 tp
->control
.step_range_end
= 0;
510 tp
->control
.step_frame_id
= null_frame_id
;
511 delete_exception_resume_breakpoint (tp
);
514 parent
= inferior_ptid
;
515 child
= tp
->pending_follow
.value
.related_pid
;
517 /* Tell the target to do whatever is necessary to follow
518 either parent or child. */
519 if (target_follow_fork (follow_child
))
521 /* Target refused to follow, or there's some other reason
522 we shouldn't resume. */
527 /* This pending follow fork event is now handled, one way
528 or another. The previous selected thread may be gone
529 from the lists by now, but if it is still around, need
530 to clear the pending follow request. */
531 tp
= find_thread_ptid (parent
);
533 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
535 /* This makes sure we don't try to apply the "Switched
536 over from WAIT_PID" logic above. */
537 nullify_last_target_wait_ptid ();
539 /* If we followed the child, switch to it... */
542 switch_to_thread (child
);
544 /* ... and preserve the stepping state, in case the
545 user was stepping over the fork call. */
548 tp
= inferior_thread ();
549 tp
->control
.step_resume_breakpoint
550 = step_resume_breakpoint
;
551 tp
->control
.step_range_start
= step_range_start
;
552 tp
->control
.step_range_end
= step_range_end
;
553 tp
->control
.step_frame_id
= step_frame_id
;
554 tp
->control
.exception_resume_breakpoint
555 = exception_resume_breakpoint
;
559 /* If we get here, it was because we're trying to
560 resume from a fork catchpoint, but, the user
561 has switched threads away from the thread that
562 forked. In that case, the resume command
563 issued is most likely not applicable to the
564 child, so just warn, and refuse to resume. */
565 warning (_("Not resuming: switched threads "
566 "before following fork child.\n"));
569 /* Reset breakpoints in the child as appropriate. */
570 follow_inferior_reset_breakpoints ();
573 switch_to_thread (parent
);
577 case TARGET_WAITKIND_SPURIOUS
:
578 /* Nothing to follow. */
581 internal_error (__FILE__
, __LINE__
,
582 "Unexpected pending_follow.kind %d\n",
583 tp
->pending_follow
.kind
);
587 return should_resume
;
591 follow_inferior_reset_breakpoints (void)
593 struct thread_info
*tp
= inferior_thread ();
595 /* Was there a step_resume breakpoint? (There was if the user
596 did a "next" at the fork() call.) If so, explicitly reset its
599 step_resumes are a form of bp that are made to be per-thread.
600 Since we created the step_resume bp when the parent process
601 was being debugged, and now are switching to the child process,
602 from the breakpoint package's viewpoint, that's a switch of
603 "threads". We must update the bp's notion of which thread
604 it is for, or it'll be ignored when it triggers. */
606 if (tp
->control
.step_resume_breakpoint
)
607 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
609 if (tp
->control
.exception_resume_breakpoint
)
610 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
612 /* Reinsert all breakpoints in the child. The user may have set
613 breakpoints after catching the fork, in which case those
614 were never set in the child, but only in the parent. This makes
615 sure the inserted breakpoints match the breakpoint list. */
617 breakpoint_re_set ();
618 insert_breakpoints ();
621 /* The child has exited or execed: resume threads of the parent the
622 user wanted to be executing. */
625 proceed_after_vfork_done (struct thread_info
*thread
,
628 int pid
= * (int *) arg
;
630 if (ptid_get_pid (thread
->ptid
) == pid
631 && is_running (thread
->ptid
)
632 && !is_executing (thread
->ptid
)
633 && !thread
->stop_requested
634 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
637 fprintf_unfiltered (gdb_stdlog
,
638 "infrun: resuming vfork parent thread %s\n",
639 target_pid_to_str (thread
->ptid
));
641 switch_to_thread (thread
->ptid
);
642 clear_proceed_status ();
643 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
649 /* Called whenever we notice an exec or exit event, to handle
650 detaching or resuming a vfork parent. */
653 handle_vfork_child_exec_or_exit (int exec
)
655 struct inferior
*inf
= current_inferior ();
657 if (inf
->vfork_parent
)
659 int resume_parent
= -1;
661 /* This exec or exit marks the end of the shared memory region
662 between the parent and the child. If the user wanted to
663 detach from the parent, now is the time. */
665 if (inf
->vfork_parent
->pending_detach
)
667 struct thread_info
*tp
;
668 struct cleanup
*old_chain
;
669 struct program_space
*pspace
;
670 struct address_space
*aspace
;
672 /* follow-fork child, detach-on-fork on. */
674 inf
->vfork_parent
->pending_detach
= 0;
678 /* If we're handling a child exit, then inferior_ptid
679 points at the inferior's pid, not to a thread. */
680 old_chain
= save_inferior_ptid ();
681 save_current_program_space ();
682 save_current_inferior ();
685 old_chain
= save_current_space_and_thread ();
687 /* We're letting loose of the parent. */
688 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
689 switch_to_thread (tp
->ptid
);
691 /* We're about to detach from the parent, which implicitly
692 removes breakpoints from its address space. There's a
693 catch here: we want to reuse the spaces for the child,
694 but, parent/child are still sharing the pspace at this
695 point, although the exec in reality makes the kernel give
696 the child a fresh set of new pages. The problem here is
697 that the breakpoints module being unaware of this, would
698 likely chose the child process to write to the parent
699 address space. Swapping the child temporarily away from
700 the spaces has the desired effect. Yes, this is "sort
703 pspace
= inf
->pspace
;
704 aspace
= inf
->aspace
;
708 if (debug_infrun
|| info_verbose
)
710 target_terminal_ours ();
713 fprintf_filtered (gdb_stdlog
,
714 "Detaching vfork parent process "
715 "%d after child exec.\n",
716 inf
->vfork_parent
->pid
);
718 fprintf_filtered (gdb_stdlog
,
719 "Detaching vfork parent process "
720 "%d after child exit.\n",
721 inf
->vfork_parent
->pid
);
724 target_detach (NULL
, 0);
727 inf
->pspace
= pspace
;
728 inf
->aspace
= aspace
;
730 do_cleanups (old_chain
);
734 /* We're staying attached to the parent, so, really give the
735 child a new address space. */
736 inf
->pspace
= add_program_space (maybe_new_address_space ());
737 inf
->aspace
= inf
->pspace
->aspace
;
739 set_current_program_space (inf
->pspace
);
741 resume_parent
= inf
->vfork_parent
->pid
;
743 /* Break the bonds. */
744 inf
->vfork_parent
->vfork_child
= NULL
;
748 struct cleanup
*old_chain
;
749 struct program_space
*pspace
;
751 /* If this is a vfork child exiting, then the pspace and
752 aspaces were shared with the parent. Since we're
753 reporting the process exit, we'll be mourning all that is
754 found in the address space, and switching to null_ptid,
755 preparing to start a new inferior. But, since we don't
756 want to clobber the parent's address/program spaces, we
757 go ahead and create a new one for this exiting
760 /* Switch to null_ptid, so that clone_program_space doesn't want
761 to read the selected frame of a dead process. */
762 old_chain
= save_inferior_ptid ();
763 inferior_ptid
= null_ptid
;
765 /* This inferior is dead, so avoid giving the breakpoints
766 module the option to write through to it (cloning a
767 program space resets breakpoints). */
770 pspace
= add_program_space (maybe_new_address_space ());
771 set_current_program_space (pspace
);
773 inf
->symfile_flags
= SYMFILE_NO_READ
;
774 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
775 inf
->pspace
= pspace
;
776 inf
->aspace
= pspace
->aspace
;
778 /* Put back inferior_ptid. We'll continue mourning this
780 do_cleanups (old_chain
);
782 resume_parent
= inf
->vfork_parent
->pid
;
783 /* Break the bonds. */
784 inf
->vfork_parent
->vfork_child
= NULL
;
787 inf
->vfork_parent
= NULL
;
789 gdb_assert (current_program_space
== inf
->pspace
);
791 if (non_stop
&& resume_parent
!= -1)
793 /* If the user wanted the parent to be running, let it go
795 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
798 fprintf_unfiltered (gdb_stdlog
,
799 "infrun: resuming vfork parent process %d\n",
802 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
804 do_cleanups (old_chain
);
809 /* Enum strings for "set|show follow-exec-mode". */
811 static const char follow_exec_mode_new
[] = "new";
812 static const char follow_exec_mode_same
[] = "same";
813 static const char *const follow_exec_mode_names
[] =
815 follow_exec_mode_new
,
816 follow_exec_mode_same
,
820 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
822 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
823 struct cmd_list_element
*c
, const char *value
)
825 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
828 /* EXECD_PATHNAME is assumed to be non-NULL. */
831 follow_exec (ptid_t pid
, char *execd_pathname
)
833 struct thread_info
*th
= inferior_thread ();
834 struct inferior
*inf
= current_inferior ();
836 /* This is an exec event that we actually wish to pay attention to.
837 Refresh our symbol table to the newly exec'd program, remove any
840 If there are breakpoints, they aren't really inserted now,
841 since the exec() transformed our inferior into a fresh set
844 We want to preserve symbolic breakpoints on the list, since
845 we have hopes that they can be reset after the new a.out's
846 symbol table is read.
848 However, any "raw" breakpoints must be removed from the list
849 (e.g., the solib bp's), since their address is probably invalid
852 And, we DON'T want to call delete_breakpoints() here, since
853 that may write the bp's "shadow contents" (the instruction
854 value that was overwritten witha TRAP instruction). Since
855 we now have a new a.out, those shadow contents aren't valid. */
857 mark_breakpoints_out ();
859 update_breakpoints_after_exec ();
861 /* If there was one, it's gone now. We cannot truly step-to-next
862 statement through an exec(). */
863 th
->control
.step_resume_breakpoint
= NULL
;
864 th
->control
.exception_resume_breakpoint
= NULL
;
865 th
->control
.step_range_start
= 0;
866 th
->control
.step_range_end
= 0;
868 /* The target reports the exec event to the main thread, even if
869 some other thread does the exec, and even if the main thread was
870 already stopped --- if debugging in non-stop mode, it's possible
871 the user had the main thread held stopped in the previous image
872 --- release it now. This is the same behavior as step-over-exec
873 with scheduler-locking on in all-stop mode. */
874 th
->stop_requested
= 0;
876 /* What is this a.out's name? */
877 printf_unfiltered (_("%s is executing new program: %s\n"),
878 target_pid_to_str (inferior_ptid
),
881 /* We've followed the inferior through an exec. Therefore, the
882 inferior has essentially been killed & reborn. */
884 gdb_flush (gdb_stdout
);
886 breakpoint_init_inferior (inf_execd
);
888 if (gdb_sysroot
&& *gdb_sysroot
)
890 char *name
= alloca (strlen (gdb_sysroot
)
891 + strlen (execd_pathname
)
894 strcpy (name
, gdb_sysroot
);
895 strcat (name
, execd_pathname
);
896 execd_pathname
= name
;
899 /* Reset the shared library package. This ensures that we get a
900 shlib event when the child reaches "_start", at which point the
901 dld will have had a chance to initialize the child. */
902 /* Also, loading a symbol file below may trigger symbol lookups, and
903 we don't want those to be satisfied by the libraries of the
904 previous incarnation of this process. */
905 no_shared_libraries (NULL
, 0);
907 if (follow_exec_mode_string
== follow_exec_mode_new
)
909 struct program_space
*pspace
;
911 /* The user wants to keep the old inferior and program spaces
912 around. Create a new fresh one, and switch to it. */
914 inf
= add_inferior (current_inferior ()->pid
);
915 pspace
= add_program_space (maybe_new_address_space ());
916 inf
->pspace
= pspace
;
917 inf
->aspace
= pspace
->aspace
;
919 exit_inferior_num_silent (current_inferior ()->num
);
921 set_current_inferior (inf
);
922 set_current_program_space (pspace
);
926 /* The old description may no longer be fit for the new image.
927 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
928 old description; we'll read a new one below. No need to do
929 this on "follow-exec-mode new", as the old inferior stays
930 around (its description is later cleared/refetched on
932 target_clear_description ();
935 gdb_assert (current_program_space
== inf
->pspace
);
937 /* That a.out is now the one to use. */
938 exec_file_attach (execd_pathname
, 0);
940 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
941 (Position Independent Executable) main symbol file will get applied by
942 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
943 the breakpoints with the zero displacement. */
945 symbol_file_add (execd_pathname
,
947 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
950 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
951 set_initial_language ();
953 /* If the target can specify a description, read it. Must do this
954 after flipping to the new executable (because the target supplied
955 description must be compatible with the executable's
956 architecture, and the old executable may e.g., be 32-bit, while
957 the new one 64-bit), and before anything involving memory or
959 target_find_description ();
961 solib_create_inferior_hook (0);
963 jit_inferior_created_hook ();
965 breakpoint_re_set ();
967 /* Reinsert all breakpoints. (Those which were symbolic have
968 been reset to the proper address in the new a.out, thanks
969 to symbol_file_command...). */
970 insert_breakpoints ();
972 /* The next resume of this inferior should bring it to the shlib
973 startup breakpoints. (If the user had also set bp's on
974 "main" from the old (parent) process, then they'll auto-
975 matically get reset there in the new process.). */
978 /* Non-zero if we just simulating a single-step. This is needed
979 because we cannot remove the breakpoints in the inferior process
980 until after the `wait' in `wait_for_inferior'. */
981 static int singlestep_breakpoints_inserted_p
= 0;
983 /* The thread we inserted single-step breakpoints for. */
984 static ptid_t singlestep_ptid
;
986 /* PC when we started this single-step. */
987 static CORE_ADDR singlestep_pc
;
989 /* If another thread hit the singlestep breakpoint, we save the original
990 thread here so that we can resume single-stepping it later. */
991 static ptid_t saved_singlestep_ptid
;
992 static int stepping_past_singlestep_breakpoint
;
994 /* If not equal to null_ptid, this means that after stepping over breakpoint
995 is finished, we need to switch to deferred_step_ptid, and step it.
997 The use case is when one thread has hit a breakpoint, and then the user
998 has switched to another thread and issued 'step'. We need to step over
999 breakpoint in the thread which hit the breakpoint, but then continue
1000 stepping the thread user has selected. */
1001 static ptid_t deferred_step_ptid
;
1003 /* Displaced stepping. */
1005 /* In non-stop debugging mode, we must take special care to manage
1006 breakpoints properly; in particular, the traditional strategy for
1007 stepping a thread past a breakpoint it has hit is unsuitable.
1008 'Displaced stepping' is a tactic for stepping one thread past a
1009 breakpoint it has hit while ensuring that other threads running
1010 concurrently will hit the breakpoint as they should.
1012 The traditional way to step a thread T off a breakpoint in a
1013 multi-threaded program in all-stop mode is as follows:
1015 a0) Initially, all threads are stopped, and breakpoints are not
1017 a1) We single-step T, leaving breakpoints uninserted.
1018 a2) We insert breakpoints, and resume all threads.
1020 In non-stop debugging, however, this strategy is unsuitable: we
1021 don't want to have to stop all threads in the system in order to
1022 continue or step T past a breakpoint. Instead, we use displaced
1025 n0) Initially, T is stopped, other threads are running, and
1026 breakpoints are inserted.
1027 n1) We copy the instruction "under" the breakpoint to a separate
1028 location, outside the main code stream, making any adjustments
1029 to the instruction, register, and memory state as directed by
1031 n2) We single-step T over the instruction at its new location.
1032 n3) We adjust the resulting register and memory state as directed
1033 by T's architecture. This includes resetting T's PC to point
1034 back into the main instruction stream.
1037 This approach depends on the following gdbarch methods:
1039 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1040 indicate where to copy the instruction, and how much space must
1041 be reserved there. We use these in step n1.
1043 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1044 address, and makes any necessary adjustments to the instruction,
1045 register contents, and memory. We use this in step n1.
1047 - gdbarch_displaced_step_fixup adjusts registers and memory after
1048 we have successfuly single-stepped the instruction, to yield the
1049 same effect the instruction would have had if we had executed it
1050 at its original address. We use this in step n3.
1052 - gdbarch_displaced_step_free_closure provides cleanup.
1054 The gdbarch_displaced_step_copy_insn and
1055 gdbarch_displaced_step_fixup functions must be written so that
1056 copying an instruction with gdbarch_displaced_step_copy_insn,
1057 single-stepping across the copied instruction, and then applying
1058 gdbarch_displaced_insn_fixup should have the same effects on the
1059 thread's memory and registers as stepping the instruction in place
1060 would have. Exactly which responsibilities fall to the copy and
1061 which fall to the fixup is up to the author of those functions.
1063 See the comments in gdbarch.sh for details.
1065 Note that displaced stepping and software single-step cannot
1066 currently be used in combination, although with some care I think
1067 they could be made to. Software single-step works by placing
1068 breakpoints on all possible subsequent instructions; if the
1069 displaced instruction is a PC-relative jump, those breakpoints
1070 could fall in very strange places --- on pages that aren't
1071 executable, or at addresses that are not proper instruction
1072 boundaries. (We do generally let other threads run while we wait
1073 to hit the software single-step breakpoint, and they might
1074 encounter such a corrupted instruction.) One way to work around
1075 this would be to have gdbarch_displaced_step_copy_insn fully
1076 simulate the effect of PC-relative instructions (and return NULL)
1077 on architectures that use software single-stepping.
1079 In non-stop mode, we can have independent and simultaneous step
1080 requests, so more than one thread may need to simultaneously step
1081 over a breakpoint. The current implementation assumes there is
1082 only one scratch space per process. In this case, we have to
1083 serialize access to the scratch space. If thread A wants to step
1084 over a breakpoint, but we are currently waiting for some other
1085 thread to complete a displaced step, we leave thread A stopped and
1086 place it in the displaced_step_request_queue. Whenever a displaced
1087 step finishes, we pick the next thread in the queue and start a new
1088 displaced step operation on it. See displaced_step_prepare and
1089 displaced_step_fixup for details. */
1091 struct displaced_step_request
1094 struct displaced_step_request
*next
;
1097 /* Per-inferior displaced stepping state. */
1098 struct displaced_step_inferior_state
1100 /* Pointer to next in linked list. */
1101 struct displaced_step_inferior_state
*next
;
1103 /* The process this displaced step state refers to. */
1106 /* A queue of pending displaced stepping requests. One entry per
1107 thread that needs to do a displaced step. */
1108 struct displaced_step_request
*step_request_queue
;
1110 /* If this is not null_ptid, this is the thread carrying out a
1111 displaced single-step in process PID. This thread's state will
1112 require fixing up once it has completed its step. */
1115 /* The architecture the thread had when we stepped it. */
1116 struct gdbarch
*step_gdbarch
;
1118 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1119 for post-step cleanup. */
1120 struct displaced_step_closure
*step_closure
;
1122 /* The address of the original instruction, and the copy we
1124 CORE_ADDR step_original
, step_copy
;
1126 /* Saved contents of copy area. */
1127 gdb_byte
*step_saved_copy
;
1130 /* The list of states of processes involved in displaced stepping
1132 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1134 /* Get the displaced stepping state of process PID. */
1136 static struct displaced_step_inferior_state
*
1137 get_displaced_stepping_state (int pid
)
1139 struct displaced_step_inferior_state
*state
;
1141 for (state
= displaced_step_inferior_states
;
1143 state
= state
->next
)
1144 if (state
->pid
== pid
)
1150 /* Add a new displaced stepping state for process PID to the displaced
1151 stepping state list, or return a pointer to an already existing
1152 entry, if it already exists. Never returns NULL. */
1154 static struct displaced_step_inferior_state
*
1155 add_displaced_stepping_state (int pid
)
1157 struct displaced_step_inferior_state
*state
;
1159 for (state
= displaced_step_inferior_states
;
1161 state
= state
->next
)
1162 if (state
->pid
== pid
)
1165 state
= xcalloc (1, sizeof (*state
));
1167 state
->next
= displaced_step_inferior_states
;
1168 displaced_step_inferior_states
= state
;
1173 /* If inferior is in displaced stepping, and ADDR equals to starting address
1174 of copy area, return corresponding displaced_step_closure. Otherwise,
1177 struct displaced_step_closure
*
1178 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1180 struct displaced_step_inferior_state
*displaced
1181 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1183 /* If checking the mode of displaced instruction in copy area. */
1184 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1185 && (displaced
->step_copy
== addr
))
1186 return displaced
->step_closure
;
1191 /* Remove the displaced stepping state of process PID. */
1194 remove_displaced_stepping_state (int pid
)
1196 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1198 gdb_assert (pid
!= 0);
1200 it
= displaced_step_inferior_states
;
1201 prev_next_p
= &displaced_step_inferior_states
;
1206 *prev_next_p
= it
->next
;
1211 prev_next_p
= &it
->next
;
1217 infrun_inferior_exit (struct inferior
*inf
)
1219 remove_displaced_stepping_state (inf
->pid
);
1222 /* If ON, and the architecture supports it, GDB will use displaced
1223 stepping to step over breakpoints. If OFF, or if the architecture
1224 doesn't support it, GDB will instead use the traditional
1225 hold-and-step approach. If AUTO (which is the default), GDB will
1226 decide which technique to use to step over breakpoints depending on
1227 which of all-stop or non-stop mode is active --- displaced stepping
1228 in non-stop mode; hold-and-step in all-stop mode. */
1230 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1233 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1234 struct cmd_list_element
*c
,
1237 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1238 fprintf_filtered (file
,
1239 _("Debugger's willingness to use displaced stepping "
1240 "to step over breakpoints is %s (currently %s).\n"),
1241 value
, non_stop
? "on" : "off");
1243 fprintf_filtered (file
,
1244 _("Debugger's willingness to use displaced stepping "
1245 "to step over breakpoints is %s.\n"), value
);
1248 /* Return non-zero if displaced stepping can/should be used to step
1249 over breakpoints. */
1252 use_displaced_stepping (struct gdbarch
*gdbarch
)
1254 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1255 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1256 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1257 && !RECORD_IS_USED
);
1260 /* Clean out any stray displaced stepping state. */
1262 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1264 /* Indicate that there is no cleanup pending. */
1265 displaced
->step_ptid
= null_ptid
;
1267 if (displaced
->step_closure
)
1269 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1270 displaced
->step_closure
);
1271 displaced
->step_closure
= NULL
;
1276 displaced_step_clear_cleanup (void *arg
)
1278 struct displaced_step_inferior_state
*state
= arg
;
1280 displaced_step_clear (state
);
1283 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1285 displaced_step_dump_bytes (struct ui_file
*file
,
1286 const gdb_byte
*buf
,
1291 for (i
= 0; i
< len
; i
++)
1292 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1293 fputs_unfiltered ("\n", file
);
1296 /* Prepare to single-step, using displaced stepping.
1298 Note that we cannot use displaced stepping when we have a signal to
1299 deliver. If we have a signal to deliver and an instruction to step
1300 over, then after the step, there will be no indication from the
1301 target whether the thread entered a signal handler or ignored the
1302 signal and stepped over the instruction successfully --- both cases
1303 result in a simple SIGTRAP. In the first case we mustn't do a
1304 fixup, and in the second case we must --- but we can't tell which.
1305 Comments in the code for 'random signals' in handle_inferior_event
1306 explain how we handle this case instead.
1308 Returns 1 if preparing was successful -- this thread is going to be
1309 stepped now; or 0 if displaced stepping this thread got queued. */
1311 displaced_step_prepare (ptid_t ptid
)
1313 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1314 struct thread_info
*tp
= find_thread_ptid (ptid
);
1315 struct regcache
*regcache
= get_thread_regcache (ptid
);
1316 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1317 CORE_ADDR original
, copy
;
1319 struct displaced_step_closure
*closure
;
1320 struct displaced_step_inferior_state
*displaced
;
1323 /* We should never reach this function if the architecture does not
1324 support displaced stepping. */
1325 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1327 /* Disable range stepping while executing in the scratch pad. We
1328 want a single-step even if executing the displaced instruction in
1329 the scratch buffer lands within the stepping range (e.g., a
1331 tp
->control
.may_range_step
= 0;
1333 /* We have to displaced step one thread at a time, as we only have
1334 access to a single scratch space per inferior. */
1336 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1338 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1340 /* Already waiting for a displaced step to finish. Defer this
1341 request and place in queue. */
1342 struct displaced_step_request
*req
, *new_req
;
1344 if (debug_displaced
)
1345 fprintf_unfiltered (gdb_stdlog
,
1346 "displaced: defering step of %s\n",
1347 target_pid_to_str (ptid
));
1349 new_req
= xmalloc (sizeof (*new_req
));
1350 new_req
->ptid
= ptid
;
1351 new_req
->next
= NULL
;
1353 if (displaced
->step_request_queue
)
1355 for (req
= displaced
->step_request_queue
;
1359 req
->next
= new_req
;
1362 displaced
->step_request_queue
= new_req
;
1368 if (debug_displaced
)
1369 fprintf_unfiltered (gdb_stdlog
,
1370 "displaced: stepping %s now\n",
1371 target_pid_to_str (ptid
));
1374 displaced_step_clear (displaced
);
1376 old_cleanups
= save_inferior_ptid ();
1377 inferior_ptid
= ptid
;
1379 original
= regcache_read_pc (regcache
);
1381 copy
= gdbarch_displaced_step_location (gdbarch
);
1382 len
= gdbarch_max_insn_length (gdbarch
);
1384 /* Save the original contents of the copy area. */
1385 displaced
->step_saved_copy
= xmalloc (len
);
1386 ignore_cleanups
= make_cleanup (free_current_contents
,
1387 &displaced
->step_saved_copy
);
1388 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1390 throw_error (MEMORY_ERROR
,
1391 _("Error accessing memory address %s (%s) for "
1392 "displaced-stepping scratch space."),
1393 paddress (gdbarch
, copy
), safe_strerror (status
));
1394 if (debug_displaced
)
1396 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1397 paddress (gdbarch
, copy
));
1398 displaced_step_dump_bytes (gdb_stdlog
,
1399 displaced
->step_saved_copy
,
1403 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1404 original
, copy
, regcache
);
1406 /* We don't support the fully-simulated case at present. */
1407 gdb_assert (closure
);
1409 /* Save the information we need to fix things up if the step
1411 displaced
->step_ptid
= ptid
;
1412 displaced
->step_gdbarch
= gdbarch
;
1413 displaced
->step_closure
= closure
;
1414 displaced
->step_original
= original
;
1415 displaced
->step_copy
= copy
;
1417 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1419 /* Resume execution at the copy. */
1420 regcache_write_pc (regcache
, copy
);
1422 discard_cleanups (ignore_cleanups
);
1424 do_cleanups (old_cleanups
);
1426 if (debug_displaced
)
1427 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1428 paddress (gdbarch
, copy
));
1434 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1435 const gdb_byte
*myaddr
, int len
)
1437 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1439 inferior_ptid
= ptid
;
1440 write_memory (memaddr
, myaddr
, len
);
1441 do_cleanups (ptid_cleanup
);
1444 /* Restore the contents of the copy area for thread PTID. */
1447 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1450 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1452 write_memory_ptid (ptid
, displaced
->step_copy
,
1453 displaced
->step_saved_copy
, len
);
1454 if (debug_displaced
)
1455 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1456 target_pid_to_str (ptid
),
1457 paddress (displaced
->step_gdbarch
,
1458 displaced
->step_copy
));
1462 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1464 struct cleanup
*old_cleanups
;
1465 struct displaced_step_inferior_state
*displaced
1466 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1468 /* Was any thread of this process doing a displaced step? */
1469 if (displaced
== NULL
)
1472 /* Was this event for the pid we displaced? */
1473 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1474 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1477 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1479 displaced_step_restore (displaced
, displaced
->step_ptid
);
1481 /* Did the instruction complete successfully? */
1482 if (signal
== GDB_SIGNAL_TRAP
)
1484 /* Fix up the resulting state. */
1485 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1486 displaced
->step_closure
,
1487 displaced
->step_original
,
1488 displaced
->step_copy
,
1489 get_thread_regcache (displaced
->step_ptid
));
1493 /* Since the instruction didn't complete, all we can do is
1495 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1496 CORE_ADDR pc
= regcache_read_pc (regcache
);
1498 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1499 regcache_write_pc (regcache
, pc
);
1502 do_cleanups (old_cleanups
);
1504 displaced
->step_ptid
= null_ptid
;
1506 /* Are there any pending displaced stepping requests? If so, run
1507 one now. Leave the state object around, since we're likely to
1508 need it again soon. */
1509 while (displaced
->step_request_queue
)
1511 struct displaced_step_request
*head
;
1513 struct regcache
*regcache
;
1514 struct gdbarch
*gdbarch
;
1515 CORE_ADDR actual_pc
;
1516 struct address_space
*aspace
;
1518 head
= displaced
->step_request_queue
;
1520 displaced
->step_request_queue
= head
->next
;
1523 context_switch (ptid
);
1525 regcache
= get_thread_regcache (ptid
);
1526 actual_pc
= regcache_read_pc (regcache
);
1527 aspace
= get_regcache_aspace (regcache
);
1529 if (breakpoint_here_p (aspace
, actual_pc
))
1531 if (debug_displaced
)
1532 fprintf_unfiltered (gdb_stdlog
,
1533 "displaced: stepping queued %s now\n",
1534 target_pid_to_str (ptid
));
1536 displaced_step_prepare (ptid
);
1538 gdbarch
= get_regcache_arch (regcache
);
1540 if (debug_displaced
)
1542 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1545 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1546 paddress (gdbarch
, actual_pc
));
1547 read_memory (actual_pc
, buf
, sizeof (buf
));
1548 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1551 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1552 displaced
->step_closure
))
1553 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1555 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1557 /* Done, we're stepping a thread. */
1563 struct thread_info
*tp
= inferior_thread ();
1565 /* The breakpoint we were sitting under has since been
1567 tp
->control
.trap_expected
= 0;
1569 /* Go back to what we were trying to do. */
1570 step
= currently_stepping (tp
);
1572 if (debug_displaced
)
1573 fprintf_unfiltered (gdb_stdlog
,
1574 "displaced: breakpoint is gone: %s, step(%d)\n",
1575 target_pid_to_str (tp
->ptid
), step
);
1577 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1578 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1580 /* This request was discarded. See if there's any other
1581 thread waiting for its turn. */
1586 /* Update global variables holding ptids to hold NEW_PTID if they were
1587 holding OLD_PTID. */
1589 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1591 struct displaced_step_request
*it
;
1592 struct displaced_step_inferior_state
*displaced
;
1594 if (ptid_equal (inferior_ptid
, old_ptid
))
1595 inferior_ptid
= new_ptid
;
1597 if (ptid_equal (singlestep_ptid
, old_ptid
))
1598 singlestep_ptid
= new_ptid
;
1600 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1601 deferred_step_ptid
= new_ptid
;
1603 for (displaced
= displaced_step_inferior_states
;
1605 displaced
= displaced
->next
)
1607 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1608 displaced
->step_ptid
= new_ptid
;
1610 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1611 if (ptid_equal (it
->ptid
, old_ptid
))
1612 it
->ptid
= new_ptid
;
1619 /* Things to clean up if we QUIT out of resume (). */
1621 resume_cleanups (void *ignore
)
1626 static const char schedlock_off
[] = "off";
1627 static const char schedlock_on
[] = "on";
1628 static const char schedlock_step
[] = "step";
1629 static const char *const scheduler_enums
[] = {
1635 static const char *scheduler_mode
= schedlock_off
;
1637 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1638 struct cmd_list_element
*c
, const char *value
)
1640 fprintf_filtered (file
,
1641 _("Mode for locking scheduler "
1642 "during execution is \"%s\".\n"),
1647 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1649 if (!target_can_lock_scheduler
)
1651 scheduler_mode
= schedlock_off
;
1652 error (_("Target '%s' cannot support this command."), target_shortname
);
1656 /* True if execution commands resume all threads of all processes by
1657 default; otherwise, resume only threads of the current inferior
1659 int sched_multi
= 0;
1661 /* Try to setup for software single stepping over the specified location.
1662 Return 1 if target_resume() should use hardware single step.
1664 GDBARCH the current gdbarch.
1665 PC the location to step over. */
1668 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1672 if (execution_direction
== EXEC_FORWARD
1673 && gdbarch_software_single_step_p (gdbarch
)
1674 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1677 /* Do not pull these breakpoints until after a `wait' in
1678 `wait_for_inferior'. */
1679 singlestep_breakpoints_inserted_p
= 1;
1680 singlestep_ptid
= inferior_ptid
;
1686 /* Return a ptid representing the set of threads that we will proceed,
1687 in the perspective of the user/frontend. We may actually resume
1688 fewer threads at first, e.g., if a thread is stopped at a
1689 breakpoint that needs stepping-off, but that should not be visible
1690 to the user/frontend, and neither should the frontend/user be
1691 allowed to proceed any of the threads that happen to be stopped for
1692 internal run control handling, if a previous command wanted them
1696 user_visible_resume_ptid (int step
)
1698 /* By default, resume all threads of all processes. */
1699 ptid_t resume_ptid
= RESUME_ALL
;
1701 /* Maybe resume only all threads of the current process. */
1702 if (!sched_multi
&& target_supports_multi_process ())
1704 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1707 /* Maybe resume a single thread after all. */
1710 /* With non-stop mode on, threads are always handled
1712 resume_ptid
= inferior_ptid
;
1714 else if ((scheduler_mode
== schedlock_on
)
1715 || (scheduler_mode
== schedlock_step
1716 && (step
|| singlestep_breakpoints_inserted_p
)))
1718 /* User-settable 'scheduler' mode requires solo thread resume. */
1719 resume_ptid
= inferior_ptid
;
1725 /* Resume the inferior, but allow a QUIT. This is useful if the user
1726 wants to interrupt some lengthy single-stepping operation
1727 (for child processes, the SIGINT goes to the inferior, and so
1728 we get a SIGINT random_signal, but for remote debugging and perhaps
1729 other targets, that's not true).
1731 STEP nonzero if we should step (zero to continue instead).
1732 SIG is the signal to give the inferior (zero for none). */
1734 resume (int step
, enum gdb_signal sig
)
1736 int should_resume
= 1;
1737 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1738 struct regcache
*regcache
= get_current_regcache ();
1739 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1740 struct thread_info
*tp
= inferior_thread ();
1741 CORE_ADDR pc
= regcache_read_pc (regcache
);
1742 struct address_space
*aspace
= get_regcache_aspace (regcache
);
1746 if (current_inferior ()->waiting_for_vfork_done
)
1748 /* Don't try to single-step a vfork parent that is waiting for
1749 the child to get out of the shared memory region (by exec'ing
1750 or exiting). This is particularly important on software
1751 single-step archs, as the child process would trip on the
1752 software single step breakpoint inserted for the parent
1753 process. Since the parent will not actually execute any
1754 instruction until the child is out of the shared region (such
1755 are vfork's semantics), it is safe to simply continue it.
1756 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1757 the parent, and tell it to `keep_going', which automatically
1758 re-sets it stepping. */
1760 fprintf_unfiltered (gdb_stdlog
,
1761 "infrun: resume : clear step\n");
1766 fprintf_unfiltered (gdb_stdlog
,
1767 "infrun: resume (step=%d, signal=%d), "
1768 "trap_expected=%d, current thread [%s] at %s\n",
1769 step
, sig
, tp
->control
.trap_expected
,
1770 target_pid_to_str (inferior_ptid
),
1771 paddress (gdbarch
, pc
));
1773 /* Normally, by the time we reach `resume', the breakpoints are either
1774 removed or inserted, as appropriate. The exception is if we're sitting
1775 at a permanent breakpoint; we need to step over it, but permanent
1776 breakpoints can't be removed. So we have to test for it here. */
1777 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
1779 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1780 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1783 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1784 how to step past a permanent breakpoint on this architecture. Try using\n\
1785 a command like `return' or `jump' to continue execution."));
1788 /* If we have a breakpoint to step over, make sure to do a single
1789 step only. Same if we have software watchpoints. */
1790 if (tp
->control
.trap_expected
|| bpstat_should_step ())
1791 tp
->control
.may_range_step
= 0;
1793 /* If enabled, step over breakpoints by executing a copy of the
1794 instruction at a different address.
1796 We can't use displaced stepping when we have a signal to deliver;
1797 the comments for displaced_step_prepare explain why. The
1798 comments in the handle_inferior event for dealing with 'random
1799 signals' explain what we do instead.
1801 We can't use displaced stepping when we are waiting for vfork_done
1802 event, displaced stepping breaks the vfork child similarly as single
1803 step software breakpoint. */
1804 if (use_displaced_stepping (gdbarch
)
1805 && (tp
->control
.trap_expected
1806 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
1807 && sig
== GDB_SIGNAL_0
1808 && !current_inferior ()->waiting_for_vfork_done
)
1810 struct displaced_step_inferior_state
*displaced
;
1812 if (!displaced_step_prepare (inferior_ptid
))
1814 /* Got placed in displaced stepping queue. Will be resumed
1815 later when all the currently queued displaced stepping
1816 requests finish. The thread is not executing at this point,
1817 and the call to set_executing will be made later. But we
1818 need to call set_running here, since from frontend point of view,
1819 the thread is running. */
1820 set_running (inferior_ptid
, 1);
1821 discard_cleanups (old_cleanups
);
1825 /* Update pc to reflect the new address from which we will execute
1826 instructions due to displaced stepping. */
1827 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
1829 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1830 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
1831 displaced
->step_closure
);
1834 /* Do we need to do it the hard way, w/temp breakpoints? */
1836 step
= maybe_software_singlestep (gdbarch
, pc
);
1838 /* Currently, our software single-step implementation leads to different
1839 results than hardware single-stepping in one situation: when stepping
1840 into delivering a signal which has an associated signal handler,
1841 hardware single-step will stop at the first instruction of the handler,
1842 while software single-step will simply skip execution of the handler.
1844 For now, this difference in behavior is accepted since there is no
1845 easy way to actually implement single-stepping into a signal handler
1846 without kernel support.
1848 However, there is one scenario where this difference leads to follow-on
1849 problems: if we're stepping off a breakpoint by removing all breakpoints
1850 and then single-stepping. In this case, the software single-step
1851 behavior means that even if there is a *breakpoint* in the signal
1852 handler, GDB still would not stop.
1854 Fortunately, we can at least fix this particular issue. We detect
1855 here the case where we are about to deliver a signal while software
1856 single-stepping with breakpoints removed. In this situation, we
1857 revert the decisions to remove all breakpoints and insert single-
1858 step breakpoints, and instead we install a step-resume breakpoint
1859 at the current address, deliver the signal without stepping, and
1860 once we arrive back at the step-resume breakpoint, actually step
1861 over the breakpoint we originally wanted to step over. */
1862 if (singlestep_breakpoints_inserted_p
1863 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
1865 /* If we have nested signals or a pending signal is delivered
1866 immediately after a handler returns, might might already have
1867 a step-resume breakpoint set on the earlier handler. We cannot
1868 set another step-resume breakpoint; just continue on until the
1869 original breakpoint is hit. */
1870 if (tp
->control
.step_resume_breakpoint
== NULL
)
1872 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
1873 tp
->step_after_step_resume_breakpoint
= 1;
1876 remove_single_step_breakpoints ();
1877 singlestep_breakpoints_inserted_p
= 0;
1879 insert_breakpoints ();
1880 tp
->control
.trap_expected
= 0;
1887 /* If STEP is set, it's a request to use hardware stepping
1888 facilities. But in that case, we should never
1889 use singlestep breakpoint. */
1890 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1892 /* Decide the set of threads to ask the target to resume. Start
1893 by assuming everything will be resumed, than narrow the set
1894 by applying increasingly restricting conditions. */
1895 resume_ptid
= user_visible_resume_ptid (step
);
1897 /* Maybe resume a single thread after all. */
1898 if (singlestep_breakpoints_inserted_p
1899 && stepping_past_singlestep_breakpoint
)
1901 /* The situation here is as follows. In thread T1 we wanted to
1902 single-step. Lacking hardware single-stepping we've
1903 set breakpoint at the PC of the next instruction -- call it
1904 P. After resuming, we've hit that breakpoint in thread T2.
1905 Now we've removed original breakpoint, inserted breakpoint
1906 at P+1, and try to step to advance T2 past breakpoint.
1907 We need to step only T2, as if T1 is allowed to freely run,
1908 it can run past P, and if other threads are allowed to run,
1909 they can hit breakpoint at P+1, and nested hits of single-step
1910 breakpoints is not something we'd want -- that's complicated
1911 to support, and has no value. */
1912 resume_ptid
= inferior_ptid
;
1914 else if ((step
|| singlestep_breakpoints_inserted_p
)
1915 && tp
->control
.trap_expected
)
1917 /* We're allowing a thread to run past a breakpoint it has
1918 hit, by single-stepping the thread with the breakpoint
1919 removed. In which case, we need to single-step only this
1920 thread, and keep others stopped, as they can miss this
1921 breakpoint if allowed to run.
1923 The current code actually removes all breakpoints when
1924 doing this, not just the one being stepped over, so if we
1925 let other threads run, we can actually miss any
1926 breakpoint, not just the one at PC. */
1927 resume_ptid
= inferior_ptid
;
1930 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1932 /* Most targets can step a breakpoint instruction, thus
1933 executing it normally. But if this one cannot, just
1934 continue and we will hit it anyway. */
1935 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
1940 && use_displaced_stepping (gdbarch
)
1941 && tp
->control
.trap_expected
)
1943 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1944 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1945 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1948 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1949 paddress (resume_gdbarch
, actual_pc
));
1950 read_memory (actual_pc
, buf
, sizeof (buf
));
1951 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1954 if (tp
->control
.may_range_step
)
1956 /* If we're resuming a thread with the PC out of the step
1957 range, then we're doing some nested/finer run control
1958 operation, like stepping the thread out of the dynamic
1959 linker or the displaced stepping scratch pad. We
1960 shouldn't have allowed a range step then. */
1961 gdb_assert (pc_in_thread_step_range (pc
, tp
));
1964 /* Install inferior's terminal modes. */
1965 target_terminal_inferior ();
1967 /* Avoid confusing the next resume, if the next stop/resume
1968 happens to apply to another thread. */
1969 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1971 /* Advise target which signals may be handled silently. If we have
1972 removed breakpoints because we are stepping over one (which can
1973 happen only if we are not using displaced stepping), we need to
1974 receive all signals to avoid accidentally skipping a breakpoint
1975 during execution of a signal handler. */
1976 if ((step
|| singlestep_breakpoints_inserted_p
)
1977 && tp
->control
.trap_expected
1978 && !use_displaced_stepping (gdbarch
))
1979 target_pass_signals (0, NULL
);
1981 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
1983 target_resume (resume_ptid
, step
, sig
);
1986 discard_cleanups (old_cleanups
);
1991 /* Clear out all variables saying what to do when inferior is continued.
1992 First do this, then set the ones you want, then call `proceed'. */
1995 clear_proceed_status_thread (struct thread_info
*tp
)
1998 fprintf_unfiltered (gdb_stdlog
,
1999 "infrun: clear_proceed_status_thread (%s)\n",
2000 target_pid_to_str (tp
->ptid
));
2002 tp
->control
.trap_expected
= 0;
2003 tp
->control
.step_range_start
= 0;
2004 tp
->control
.step_range_end
= 0;
2005 tp
->control
.may_range_step
= 0;
2006 tp
->control
.step_frame_id
= null_frame_id
;
2007 tp
->control
.step_stack_frame_id
= null_frame_id
;
2008 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2009 tp
->stop_requested
= 0;
2011 tp
->control
.stop_step
= 0;
2013 tp
->control
.proceed_to_finish
= 0;
2015 /* Discard any remaining commands or status from previous stop. */
2016 bpstat_clear (&tp
->control
.stop_bpstat
);
2020 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
2022 if (is_exited (tp
->ptid
))
2025 clear_proceed_status_thread (tp
);
2030 clear_proceed_status (void)
2034 /* In all-stop mode, delete the per-thread status of all
2035 threads, even if inferior_ptid is null_ptid, there may be
2036 threads on the list. E.g., we may be launching a new
2037 process, while selecting the executable. */
2038 iterate_over_threads (clear_proceed_status_callback
, NULL
);
2041 if (!ptid_equal (inferior_ptid
, null_ptid
))
2043 struct inferior
*inferior
;
2047 /* If in non-stop mode, only delete the per-thread status of
2048 the current thread. */
2049 clear_proceed_status_thread (inferior_thread ());
2052 inferior
= current_inferior ();
2053 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2056 stop_after_trap
= 0;
2058 observer_notify_about_to_proceed ();
2062 regcache_xfree (stop_registers
);
2063 stop_registers
= NULL
;
2067 /* Check the current thread against the thread that reported the most recent
2068 event. If a step-over is required return TRUE and set the current thread
2069 to the old thread. Otherwise return FALSE.
2071 This should be suitable for any targets that support threads. */
2074 prepare_to_proceed (int step
)
2077 struct target_waitstatus wait_status
;
2078 int schedlock_enabled
;
2080 /* With non-stop mode on, threads are always handled individually. */
2081 gdb_assert (! non_stop
);
2083 /* Get the last target status returned by target_wait(). */
2084 get_last_target_status (&wait_ptid
, &wait_status
);
2086 /* Make sure we were stopped at a breakpoint. */
2087 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
2088 || (wait_status
.value
.sig
!= GDB_SIGNAL_TRAP
2089 && wait_status
.value
.sig
!= GDB_SIGNAL_ILL
2090 && wait_status
.value
.sig
!= GDB_SIGNAL_SEGV
2091 && wait_status
.value
.sig
!= GDB_SIGNAL_EMT
))
2096 schedlock_enabled
= (scheduler_mode
== schedlock_on
2097 || (scheduler_mode
== schedlock_step
2100 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
2101 if (schedlock_enabled
)
2104 /* Don't switch over if we're about to resume some other process
2105 other than WAIT_PTID's, and schedule-multiple is off. */
2107 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
2110 /* Switched over from WAIT_PID. */
2111 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
2112 && !ptid_equal (inferior_ptid
, wait_ptid
))
2114 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
2116 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2117 regcache_read_pc (regcache
)))
2119 /* If stepping, remember current thread to switch back to. */
2121 deferred_step_ptid
= inferior_ptid
;
2123 /* Switch back to WAIT_PID thread. */
2124 switch_to_thread (wait_ptid
);
2127 fprintf_unfiltered (gdb_stdlog
,
2128 "infrun: prepare_to_proceed (step=%d), "
2129 "switched to [%s]\n",
2130 step
, target_pid_to_str (inferior_ptid
));
2132 /* We return 1 to indicate that there is a breakpoint here,
2133 so we need to step over it before continuing to avoid
2134 hitting it straight away. */
2142 /* Basic routine for continuing the program in various fashions.
2144 ADDR is the address to resume at, or -1 for resume where stopped.
2145 SIGGNAL is the signal to give it, or 0 for none,
2146 or -1 for act according to how it stopped.
2147 STEP is nonzero if should trap after one instruction.
2148 -1 means return after that and print nothing.
2149 You should probably set various step_... variables
2150 before calling here, if you are stepping.
2152 You should call clear_proceed_status before calling proceed. */
2155 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2157 struct regcache
*regcache
;
2158 struct gdbarch
*gdbarch
;
2159 struct thread_info
*tp
;
2161 struct address_space
*aspace
;
2162 /* GDB may force the inferior to step due to various reasons. */
2165 /* If we're stopped at a fork/vfork, follow the branch set by the
2166 "set follow-fork-mode" command; otherwise, we'll just proceed
2167 resuming the current thread. */
2168 if (!follow_fork ())
2170 /* The target for some reason decided not to resume. */
2172 if (target_can_async_p ())
2173 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2177 /* We'll update this if & when we switch to a new thread. */
2178 previous_inferior_ptid
= inferior_ptid
;
2180 regcache
= get_current_regcache ();
2181 gdbarch
= get_regcache_arch (regcache
);
2182 aspace
= get_regcache_aspace (regcache
);
2183 pc
= regcache_read_pc (regcache
);
2186 step_start_function
= find_pc_function (pc
);
2188 stop_after_trap
= 1;
2190 if (addr
== (CORE_ADDR
) -1)
2192 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2193 && execution_direction
!= EXEC_REVERSE
)
2194 /* There is a breakpoint at the address we will resume at,
2195 step one instruction before inserting breakpoints so that
2196 we do not stop right away (and report a second hit at this
2199 Note, we don't do this in reverse, because we won't
2200 actually be executing the breakpoint insn anyway.
2201 We'll be (un-)executing the previous instruction. */
2204 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2205 && gdbarch_single_step_through_delay (gdbarch
,
2206 get_current_frame ()))
2207 /* We stepped onto an instruction that needs to be stepped
2208 again before re-inserting the breakpoint, do so. */
2213 regcache_write_pc (regcache
, addr
);
2217 fprintf_unfiltered (gdb_stdlog
,
2218 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2219 paddress (gdbarch
, addr
), siggnal
, step
);
2222 /* In non-stop, each thread is handled individually. The context
2223 must already be set to the right thread here. */
2227 /* In a multi-threaded task we may select another thread and
2228 then continue or step.
2230 But if the old thread was stopped at a breakpoint, it will
2231 immediately cause another breakpoint stop without any
2232 execution (i.e. it will report a breakpoint hit incorrectly).
2233 So we must step over it first.
2235 prepare_to_proceed checks the current thread against the
2236 thread that reported the most recent event. If a step-over
2237 is required it returns TRUE and sets the current thread to
2239 if (prepare_to_proceed (step
))
2243 /* prepare_to_proceed may change the current thread. */
2244 tp
= inferior_thread ();
2248 tp
->control
.trap_expected
= 1;
2249 /* If displaced stepping is enabled, we can step over the
2250 breakpoint without hitting it, so leave all breakpoints
2251 inserted. Otherwise we need to disable all breakpoints, step
2252 one instruction, and then re-add them when that step is
2254 if (!use_displaced_stepping (gdbarch
))
2255 remove_breakpoints ();
2258 /* We can insert breakpoints if we're not trying to step over one,
2259 or if we are stepping over one but we're using displaced stepping
2261 if (! tp
->control
.trap_expected
|| use_displaced_stepping (gdbarch
))
2262 insert_breakpoints ();
2266 /* Pass the last stop signal to the thread we're resuming,
2267 irrespective of whether the current thread is the thread that
2268 got the last event or not. This was historically GDB's
2269 behaviour before keeping a stop_signal per thread. */
2271 struct thread_info
*last_thread
;
2273 struct target_waitstatus last_status
;
2275 get_last_target_status (&last_ptid
, &last_status
);
2276 if (!ptid_equal (inferior_ptid
, last_ptid
)
2277 && !ptid_equal (last_ptid
, null_ptid
)
2278 && !ptid_equal (last_ptid
, minus_one_ptid
))
2280 last_thread
= find_thread_ptid (last_ptid
);
2283 tp
->suspend
.stop_signal
= last_thread
->suspend
.stop_signal
;
2284 last_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2289 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2290 tp
->suspend
.stop_signal
= siggnal
;
2291 /* If this signal should not be seen by program,
2292 give it zero. Used for debugging signals. */
2293 else if (!signal_program
[tp
->suspend
.stop_signal
])
2294 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2296 annotate_starting ();
2298 /* Make sure that output from GDB appears before output from the
2300 gdb_flush (gdb_stdout
);
2302 /* Refresh prev_pc value just prior to resuming. This used to be
2303 done in stop_stepping, however, setting prev_pc there did not handle
2304 scenarios such as inferior function calls or returning from
2305 a function via the return command. In those cases, the prev_pc
2306 value was not set properly for subsequent commands. The prev_pc value
2307 is used to initialize the starting line number in the ecs. With an
2308 invalid value, the gdb next command ends up stopping at the position
2309 represented by the next line table entry past our start position.
2310 On platforms that generate one line table entry per line, this
2311 is not a problem. However, on the ia64, the compiler generates
2312 extraneous line table entries that do not increase the line number.
2313 When we issue the gdb next command on the ia64 after an inferior call
2314 or a return command, we often end up a few instructions forward, still
2315 within the original line we started.
2317 An attempt was made to refresh the prev_pc at the same time the
2318 execution_control_state is initialized (for instance, just before
2319 waiting for an inferior event). But this approach did not work
2320 because of platforms that use ptrace, where the pc register cannot
2321 be read unless the inferior is stopped. At that point, we are not
2322 guaranteed the inferior is stopped and so the regcache_read_pc() call
2323 can fail. Setting the prev_pc value here ensures the value is updated
2324 correctly when the inferior is stopped. */
2325 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2327 /* Fill in with reasonable starting values. */
2328 init_thread_stepping_state (tp
);
2330 /* Reset to normal state. */
2331 init_infwait_state ();
2333 /* Resume inferior. */
2334 resume (force_step
|| step
|| bpstat_should_step (),
2335 tp
->suspend
.stop_signal
);
2337 /* Wait for it to stop (if not standalone)
2338 and in any case decode why it stopped, and act accordingly. */
2339 /* Do this only if we are not using the event loop, or if the target
2340 does not support asynchronous execution. */
2341 if (!target_can_async_p ())
2343 wait_for_inferior ();
2349 /* Start remote-debugging of a machine over a serial link. */
2352 start_remote (int from_tty
)
2354 struct inferior
*inferior
;
2356 inferior
= current_inferior ();
2357 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2359 /* Always go on waiting for the target, regardless of the mode. */
2360 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2361 indicate to wait_for_inferior that a target should timeout if
2362 nothing is returned (instead of just blocking). Because of this,
2363 targets expecting an immediate response need to, internally, set
2364 things up so that the target_wait() is forced to eventually
2366 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2367 differentiate to its caller what the state of the target is after
2368 the initial open has been performed. Here we're assuming that
2369 the target has stopped. It should be possible to eventually have
2370 target_open() return to the caller an indication that the target
2371 is currently running and GDB state should be set to the same as
2372 for an async run. */
2373 wait_for_inferior ();
2375 /* Now that the inferior has stopped, do any bookkeeping like
2376 loading shared libraries. We want to do this before normal_stop,
2377 so that the displayed frame is up to date. */
2378 post_create_inferior (¤t_target
, from_tty
);
2383 /* Initialize static vars when a new inferior begins. */
2386 init_wait_for_inferior (void)
2388 /* These are meaningless until the first time through wait_for_inferior. */
2390 breakpoint_init_inferior (inf_starting
);
2392 clear_proceed_status ();
2394 stepping_past_singlestep_breakpoint
= 0;
2395 deferred_step_ptid
= null_ptid
;
2397 target_last_wait_ptid
= minus_one_ptid
;
2399 previous_inferior_ptid
= inferior_ptid
;
2400 init_infwait_state ();
2402 /* Discard any skipped inlined frames. */
2403 clear_inline_frame_state (minus_one_ptid
);
2407 /* This enum encodes possible reasons for doing a target_wait, so that
2408 wfi can call target_wait in one place. (Ultimately the call will be
2409 moved out of the infinite loop entirely.) */
2413 infwait_normal_state
,
2414 infwait_thread_hop_state
,
2415 infwait_step_watch_state
,
2416 infwait_nonstep_watch_state
2419 /* The PTID we'll do a target_wait on.*/
2422 /* Current inferior wait state. */
2423 static enum infwait_states infwait_state
;
2425 /* Data to be passed around while handling an event. This data is
2426 discarded between events. */
2427 struct execution_control_state
2430 /* The thread that got the event, if this was a thread event; NULL
2432 struct thread_info
*event_thread
;
2434 struct target_waitstatus ws
;
2436 int stop_func_filled_in
;
2437 CORE_ADDR stop_func_start
;
2438 CORE_ADDR stop_func_end
;
2439 const char *stop_func_name
;
2443 static void handle_inferior_event (struct execution_control_state
*ecs
);
2445 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2446 struct execution_control_state
*ecs
);
2447 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2448 struct execution_control_state
*ecs
);
2449 static void check_exception_resume (struct execution_control_state
*,
2450 struct frame_info
*);
2452 static void stop_stepping (struct execution_control_state
*ecs
);
2453 static void prepare_to_wait (struct execution_control_state
*ecs
);
2454 static void keep_going (struct execution_control_state
*ecs
);
2456 /* Callback for iterate over threads. If the thread is stopped, but
2457 the user/frontend doesn't know about that yet, go through
2458 normal_stop, as if the thread had just stopped now. ARG points at
2459 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2460 ptid_is_pid(PTID) is true, applies to all threads of the process
2461 pointed at by PTID. Otherwise, apply only to the thread pointed by
2465 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2467 ptid_t ptid
= * (ptid_t
*) arg
;
2469 if ((ptid_equal (info
->ptid
, ptid
)
2470 || ptid_equal (minus_one_ptid
, ptid
)
2471 || (ptid_is_pid (ptid
)
2472 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2473 && is_running (info
->ptid
)
2474 && !is_executing (info
->ptid
))
2476 struct cleanup
*old_chain
;
2477 struct execution_control_state ecss
;
2478 struct execution_control_state
*ecs
= &ecss
;
2480 memset (ecs
, 0, sizeof (*ecs
));
2482 old_chain
= make_cleanup_restore_current_thread ();
2484 /* Go through handle_inferior_event/normal_stop, so we always
2485 have consistent output as if the stop event had been
2487 ecs
->ptid
= info
->ptid
;
2488 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2489 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2490 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2492 handle_inferior_event (ecs
);
2494 if (!ecs
->wait_some_more
)
2496 struct thread_info
*tp
;
2500 /* Finish off the continuations. */
2501 tp
= inferior_thread ();
2502 do_all_intermediate_continuations_thread (tp
, 1);
2503 do_all_continuations_thread (tp
, 1);
2506 do_cleanups (old_chain
);
2512 /* This function is attached as a "thread_stop_requested" observer.
2513 Cleanup local state that assumed the PTID was to be resumed, and
2514 report the stop to the frontend. */
2517 infrun_thread_stop_requested (ptid_t ptid
)
2519 struct displaced_step_inferior_state
*displaced
;
2521 /* PTID was requested to stop. Remove it from the displaced
2522 stepping queue, so we don't try to resume it automatically. */
2524 for (displaced
= displaced_step_inferior_states
;
2526 displaced
= displaced
->next
)
2528 struct displaced_step_request
*it
, **prev_next_p
;
2530 it
= displaced
->step_request_queue
;
2531 prev_next_p
= &displaced
->step_request_queue
;
2534 if (ptid_match (it
->ptid
, ptid
))
2536 *prev_next_p
= it
->next
;
2542 prev_next_p
= &it
->next
;
2549 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2553 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2555 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2556 nullify_last_target_wait_ptid ();
2559 /* Callback for iterate_over_threads. */
2562 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2564 if (is_exited (info
->ptid
))
2567 delete_step_resume_breakpoint (info
);
2568 delete_exception_resume_breakpoint (info
);
2572 /* In all-stop, delete the step resume breakpoint of any thread that
2573 had one. In non-stop, delete the step resume breakpoint of the
2574 thread that just stopped. */
2577 delete_step_thread_step_resume_breakpoint (void)
2579 if (!target_has_execution
2580 || ptid_equal (inferior_ptid
, null_ptid
))
2581 /* If the inferior has exited, we have already deleted the step
2582 resume breakpoints out of GDB's lists. */
2587 /* If in non-stop mode, only delete the step-resume or
2588 longjmp-resume breakpoint of the thread that just stopped
2590 struct thread_info
*tp
= inferior_thread ();
2592 delete_step_resume_breakpoint (tp
);
2593 delete_exception_resume_breakpoint (tp
);
2596 /* In all-stop mode, delete all step-resume and longjmp-resume
2597 breakpoints of any thread that had them. */
2598 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2601 /* A cleanup wrapper. */
2604 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2606 delete_step_thread_step_resume_breakpoint ();
2609 /* Pretty print the results of target_wait, for debugging purposes. */
2612 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2613 const struct target_waitstatus
*ws
)
2615 char *status_string
= target_waitstatus_to_string (ws
);
2616 struct ui_file
*tmp_stream
= mem_fileopen ();
2619 /* The text is split over several lines because it was getting too long.
2620 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2621 output as a unit; we want only one timestamp printed if debug_timestamp
2624 fprintf_unfiltered (tmp_stream
,
2625 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
2626 if (PIDGET (waiton_ptid
) != -1)
2627 fprintf_unfiltered (tmp_stream
,
2628 " [%s]", target_pid_to_str (waiton_ptid
));
2629 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2630 fprintf_unfiltered (tmp_stream
,
2631 "infrun: %d [%s],\n",
2632 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
2633 fprintf_unfiltered (tmp_stream
,
2637 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2639 /* This uses %s in part to handle %'s in the text, but also to avoid
2640 a gcc error: the format attribute requires a string literal. */
2641 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2643 xfree (status_string
);
2645 ui_file_delete (tmp_stream
);
2648 /* Prepare and stabilize the inferior for detaching it. E.g.,
2649 detaching while a thread is displaced stepping is a recipe for
2650 crashing it, as nothing would readjust the PC out of the scratch
2654 prepare_for_detach (void)
2656 struct inferior
*inf
= current_inferior ();
2657 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2658 struct cleanup
*old_chain_1
;
2659 struct displaced_step_inferior_state
*displaced
;
2661 displaced
= get_displaced_stepping_state (inf
->pid
);
2663 /* Is any thread of this process displaced stepping? If not,
2664 there's nothing else to do. */
2665 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2669 fprintf_unfiltered (gdb_stdlog
,
2670 "displaced-stepping in-process while detaching");
2672 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2675 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2677 struct cleanup
*old_chain_2
;
2678 struct execution_control_state ecss
;
2679 struct execution_control_state
*ecs
;
2682 memset (ecs
, 0, sizeof (*ecs
));
2684 overlay_cache_invalid
= 1;
2686 if (deprecated_target_wait_hook
)
2687 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2689 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2692 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2694 /* If an error happens while handling the event, propagate GDB's
2695 knowledge of the executing state to the frontend/user running
2697 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2700 /* Now figure out what to do with the result of the result. */
2701 handle_inferior_event (ecs
);
2703 /* No error, don't finish the state yet. */
2704 discard_cleanups (old_chain_2
);
2706 /* Breakpoints and watchpoints are not installed on the target
2707 at this point, and signals are passed directly to the
2708 inferior, so this must mean the process is gone. */
2709 if (!ecs
->wait_some_more
)
2711 discard_cleanups (old_chain_1
);
2712 error (_("Program exited while detaching"));
2716 discard_cleanups (old_chain_1
);
2719 /* Wait for control to return from inferior to debugger.
2721 If inferior gets a signal, we may decide to start it up again
2722 instead of returning. That is why there is a loop in this function.
2723 When this function actually returns it means the inferior
2724 should be left stopped and GDB should read more commands. */
2727 wait_for_inferior (void)
2729 struct cleanup
*old_cleanups
;
2733 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
2736 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
2740 struct execution_control_state ecss
;
2741 struct execution_control_state
*ecs
= &ecss
;
2742 struct cleanup
*old_chain
;
2744 memset (ecs
, 0, sizeof (*ecs
));
2746 overlay_cache_invalid
= 1;
2748 if (deprecated_target_wait_hook
)
2749 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2751 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2754 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2756 /* If an error happens while handling the event, propagate GDB's
2757 knowledge of the executing state to the frontend/user running
2759 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2761 /* Now figure out what to do with the result of the result. */
2762 handle_inferior_event (ecs
);
2764 /* No error, don't finish the state yet. */
2765 discard_cleanups (old_chain
);
2767 if (!ecs
->wait_some_more
)
2771 do_cleanups (old_cleanups
);
2774 /* Asynchronous version of wait_for_inferior. It is called by the
2775 event loop whenever a change of state is detected on the file
2776 descriptor corresponding to the target. It can be called more than
2777 once to complete a single execution command. In such cases we need
2778 to keep the state in a global variable ECSS. If it is the last time
2779 that this function is called for a single execution command, then
2780 report to the user that the inferior has stopped, and do the
2781 necessary cleanups. */
2784 fetch_inferior_event (void *client_data
)
2786 struct execution_control_state ecss
;
2787 struct execution_control_state
*ecs
= &ecss
;
2788 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2789 struct cleanup
*ts_old_chain
;
2790 int was_sync
= sync_execution
;
2793 memset (ecs
, 0, sizeof (*ecs
));
2795 /* We're handling a live event, so make sure we're doing live
2796 debugging. If we're looking at traceframes while the target is
2797 running, we're going to need to get back to that mode after
2798 handling the event. */
2801 make_cleanup_restore_current_traceframe ();
2802 set_current_traceframe (-1);
2806 /* In non-stop mode, the user/frontend should not notice a thread
2807 switch due to internal events. Make sure we reverse to the
2808 user selected thread and frame after handling the event and
2809 running any breakpoint commands. */
2810 make_cleanup_restore_current_thread ();
2812 overlay_cache_invalid
= 1;
2814 make_cleanup_restore_integer (&execution_direction
);
2815 execution_direction
= target_execution_direction ();
2817 if (deprecated_target_wait_hook
)
2819 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2821 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2824 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2826 /* If an error happens while handling the event, propagate GDB's
2827 knowledge of the executing state to the frontend/user running
2830 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2832 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2834 /* Get executed before make_cleanup_restore_current_thread above to apply
2835 still for the thread which has thrown the exception. */
2836 make_bpstat_clear_actions_cleanup ();
2838 /* Now figure out what to do with the result of the result. */
2839 handle_inferior_event (ecs
);
2841 if (!ecs
->wait_some_more
)
2843 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2845 delete_step_thread_step_resume_breakpoint ();
2847 /* We may not find an inferior if this was a process exit. */
2848 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
2851 if (target_has_execution
2852 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
2853 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2854 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2855 && ecs
->event_thread
->step_multi
2856 && ecs
->event_thread
->control
.stop_step
)
2857 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2860 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2865 /* No error, don't finish the thread states yet. */
2866 discard_cleanups (ts_old_chain
);
2868 /* Revert thread and frame. */
2869 do_cleanups (old_chain
);
2871 /* If the inferior was in sync execution mode, and now isn't,
2872 restore the prompt (a synchronous execution command has finished,
2873 and we're ready for input). */
2874 if (interpreter_async
&& was_sync
&& !sync_execution
)
2875 display_gdb_prompt (0);
2879 && exec_done_display_p
2880 && (ptid_equal (inferior_ptid
, null_ptid
)
2881 || !is_running (inferior_ptid
)))
2882 printf_unfiltered (_("completed.\n"));
2885 /* Record the frame and location we're currently stepping through. */
2887 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2889 struct thread_info
*tp
= inferior_thread ();
2891 tp
->control
.step_frame_id
= get_frame_id (frame
);
2892 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
2894 tp
->current_symtab
= sal
.symtab
;
2895 tp
->current_line
= sal
.line
;
2898 /* Clear context switchable stepping state. */
2901 init_thread_stepping_state (struct thread_info
*tss
)
2903 tss
->stepping_over_breakpoint
= 0;
2904 tss
->step_after_step_resume_breakpoint
= 0;
2907 /* Return the cached copy of the last pid/waitstatus returned by
2908 target_wait()/deprecated_target_wait_hook(). The data is actually
2909 cached by handle_inferior_event(), which gets called immediately
2910 after target_wait()/deprecated_target_wait_hook(). */
2913 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2915 *ptidp
= target_last_wait_ptid
;
2916 *status
= target_last_waitstatus
;
2920 nullify_last_target_wait_ptid (void)
2922 target_last_wait_ptid
= minus_one_ptid
;
2925 /* Switch thread contexts. */
2928 context_switch (ptid_t ptid
)
2930 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
2932 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2933 target_pid_to_str (inferior_ptid
));
2934 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2935 target_pid_to_str (ptid
));
2938 switch_to_thread (ptid
);
2942 adjust_pc_after_break (struct execution_control_state
*ecs
)
2944 struct regcache
*regcache
;
2945 struct gdbarch
*gdbarch
;
2946 struct address_space
*aspace
;
2947 CORE_ADDR breakpoint_pc
;
2949 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2950 we aren't, just return.
2952 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2953 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2954 implemented by software breakpoints should be handled through the normal
2957 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2958 different signals (SIGILL or SIGEMT for instance), but it is less
2959 clear where the PC is pointing afterwards. It may not match
2960 gdbarch_decr_pc_after_break. I don't know any specific target that
2961 generates these signals at breakpoints (the code has been in GDB since at
2962 least 1992) so I can not guess how to handle them here.
2964 In earlier versions of GDB, a target with
2965 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2966 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2967 target with both of these set in GDB history, and it seems unlikely to be
2968 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2970 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2973 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
2976 /* In reverse execution, when a breakpoint is hit, the instruction
2977 under it has already been de-executed. The reported PC always
2978 points at the breakpoint address, so adjusting it further would
2979 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2982 B1 0x08000000 : INSN1
2983 B2 0x08000001 : INSN2
2985 PC -> 0x08000003 : INSN4
2987 Say you're stopped at 0x08000003 as above. Reverse continuing
2988 from that point should hit B2 as below. Reading the PC when the
2989 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2990 been de-executed already.
2992 B1 0x08000000 : INSN1
2993 B2 PC -> 0x08000001 : INSN2
2997 We can't apply the same logic as for forward execution, because
2998 we would wrongly adjust the PC to 0x08000000, since there's a
2999 breakpoint at PC - 1. We'd then report a hit on B1, although
3000 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3002 if (execution_direction
== EXEC_REVERSE
)
3005 /* If this target does not decrement the PC after breakpoints, then
3006 we have nothing to do. */
3007 regcache
= get_thread_regcache (ecs
->ptid
);
3008 gdbarch
= get_regcache_arch (regcache
);
3009 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
3012 aspace
= get_regcache_aspace (regcache
);
3014 /* Find the location where (if we've hit a breakpoint) the
3015 breakpoint would be. */
3016 breakpoint_pc
= regcache_read_pc (regcache
)
3017 - gdbarch_decr_pc_after_break (gdbarch
);
3019 /* Check whether there actually is a software breakpoint inserted at
3022 If in non-stop mode, a race condition is possible where we've
3023 removed a breakpoint, but stop events for that breakpoint were
3024 already queued and arrive later. To suppress those spurious
3025 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3026 and retire them after a number of stop events are reported. */
3027 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3028 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3030 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3033 record_full_gdb_operation_disable_set ();
3035 /* When using hardware single-step, a SIGTRAP is reported for both
3036 a completed single-step and a software breakpoint. Need to
3037 differentiate between the two, as the latter needs adjusting
3038 but the former does not.
3040 The SIGTRAP can be due to a completed hardware single-step only if
3041 - we didn't insert software single-step breakpoints
3042 - the thread to be examined is still the current thread
3043 - this thread is currently being stepped
3045 If any of these events did not occur, we must have stopped due
3046 to hitting a software breakpoint, and have to back up to the
3049 As a special case, we could have hardware single-stepped a
3050 software breakpoint. In this case (prev_pc == breakpoint_pc),
3051 we also need to back up to the breakpoint address. */
3053 if (singlestep_breakpoints_inserted_p
3054 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3055 || !currently_stepping (ecs
->event_thread
)
3056 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3057 regcache_write_pc (regcache
, breakpoint_pc
);
3059 do_cleanups (old_cleanups
);
3064 init_infwait_state (void)
3066 waiton_ptid
= pid_to_ptid (-1);
3067 infwait_state
= infwait_normal_state
;
3071 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3073 for (frame
= get_prev_frame (frame
);
3075 frame
= get_prev_frame (frame
))
3077 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3079 if (get_frame_type (frame
) != INLINE_FRAME
)
3086 /* Auxiliary function that handles syscall entry/return events.
3087 It returns 1 if the inferior should keep going (and GDB
3088 should ignore the event), or 0 if the event deserves to be
3092 handle_syscall_event (struct execution_control_state
*ecs
)
3094 struct regcache
*regcache
;
3097 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3098 context_switch (ecs
->ptid
);
3100 regcache
= get_thread_regcache (ecs
->ptid
);
3101 syscall_number
= ecs
->ws
.value
.syscall_number
;
3102 stop_pc
= regcache_read_pc (regcache
);
3104 if (catch_syscall_enabled () > 0
3105 && catching_syscall_number (syscall_number
) > 0)
3107 enum bpstat_signal_value sval
;
3110 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3113 ecs
->event_thread
->control
.stop_bpstat
3114 = bpstat_stop_status (get_regcache_aspace (regcache
),
3115 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3117 sval
= bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3118 ecs
->random_signal
= sval
== BPSTAT_SIGNAL_NO
;
3120 if (!ecs
->random_signal
)
3122 /* Catchpoint hit. */
3123 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3128 /* If no catchpoint triggered for this, then keep going. */
3129 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3134 /* Clear the supplied execution_control_state's stop_func_* fields. */
3137 clear_stop_func (struct execution_control_state
*ecs
)
3139 ecs
->stop_func_filled_in
= 0;
3140 ecs
->stop_func_start
= 0;
3141 ecs
->stop_func_end
= 0;
3142 ecs
->stop_func_name
= NULL
;
3145 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3148 fill_in_stop_func (struct gdbarch
*gdbarch
,
3149 struct execution_control_state
*ecs
)
3151 if (!ecs
->stop_func_filled_in
)
3153 /* Don't care about return value; stop_func_start and stop_func_name
3154 will both be 0 if it doesn't work. */
3155 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3156 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3157 ecs
->stop_func_start
3158 += gdbarch_deprecated_function_start_offset (gdbarch
);
3160 ecs
->stop_func_filled_in
= 1;
3164 /* Given an execution control state that has been freshly filled in
3165 by an event from the inferior, figure out what it means and take
3166 appropriate action. */
3169 handle_inferior_event (struct execution_control_state
*ecs
)
3171 struct frame_info
*frame
;
3172 struct gdbarch
*gdbarch
;
3173 int stopped_by_watchpoint
;
3174 int stepped_after_stopped_by_watchpoint
= 0;
3175 struct symtab_and_line stop_pc_sal
;
3176 enum stop_kind stop_soon
;
3178 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3180 /* We had an event in the inferior, but we are not interested in
3181 handling it at this level. The lower layers have already
3182 done what needs to be done, if anything.
3184 One of the possible circumstances for this is when the
3185 inferior produces output for the console. The inferior has
3186 not stopped, and we are ignoring the event. Another possible
3187 circumstance is any event which the lower level knows will be
3188 reported multiple times without an intervening resume. */
3190 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3191 prepare_to_wait (ecs
);
3195 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3196 && target_can_async_p () && !sync_execution
)
3198 /* There were no unwaited-for children left in the target, but,
3199 we're not synchronously waiting for events either. Just
3200 ignore. Otherwise, if we were running a synchronous
3201 execution command, we need to cancel it and give the user
3202 back the terminal. */
3204 fprintf_unfiltered (gdb_stdlog
,
3205 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3206 prepare_to_wait (ecs
);
3210 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3211 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3212 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
3214 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3217 stop_soon
= inf
->control
.stop_soon
;
3220 stop_soon
= NO_STOP_QUIETLY
;
3222 /* Cache the last pid/waitstatus. */
3223 target_last_wait_ptid
= ecs
->ptid
;
3224 target_last_waitstatus
= ecs
->ws
;
3226 /* Always clear state belonging to the previous time we stopped. */
3227 stop_stack_dummy
= STOP_NONE
;
3229 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3231 /* No unwaited-for children left. IOW, all resumed children
3234 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3236 stop_print_frame
= 0;
3237 stop_stepping (ecs
);
3241 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3242 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3244 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3245 /* If it's a new thread, add it to the thread database. */
3246 if (ecs
->event_thread
== NULL
)
3247 ecs
->event_thread
= add_thread (ecs
->ptid
);
3249 /* Disable range stepping. If the next step request could use a
3250 range, this will be end up re-enabled then. */
3251 ecs
->event_thread
->control
.may_range_step
= 0;
3254 /* Dependent on valid ECS->EVENT_THREAD. */
3255 adjust_pc_after_break (ecs
);
3257 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3258 reinit_frame_cache ();
3260 breakpoint_retire_moribund ();
3262 /* First, distinguish signals caused by the debugger from signals
3263 that have to do with the program's own actions. Note that
3264 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3265 on the operating system version. Here we detect when a SIGILL or
3266 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3267 something similar for SIGSEGV, since a SIGSEGV will be generated
3268 when we're trying to execute a breakpoint instruction on a
3269 non-executable stack. This happens for call dummy breakpoints
3270 for architectures like SPARC that place call dummies on the
3272 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3273 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3274 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3275 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3277 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3279 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3280 regcache_read_pc (regcache
)))
3283 fprintf_unfiltered (gdb_stdlog
,
3284 "infrun: Treating signal as SIGTRAP\n");
3285 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3289 /* Mark the non-executing threads accordingly. In all-stop, all
3290 threads of all processes are stopped when we get any event
3291 reported. In non-stop mode, only the event thread stops. If
3292 we're handling a process exit in non-stop mode, there's nothing
3293 to do, as threads of the dead process are gone, and threads of
3294 any other process were left running. */
3296 set_executing (minus_one_ptid
, 0);
3297 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3298 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3299 set_executing (ecs
->ptid
, 0);
3301 switch (infwait_state
)
3303 case infwait_thread_hop_state
:
3305 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
3308 case infwait_normal_state
:
3310 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3313 case infwait_step_watch_state
:
3315 fprintf_unfiltered (gdb_stdlog
,
3316 "infrun: infwait_step_watch_state\n");
3318 stepped_after_stopped_by_watchpoint
= 1;
3321 case infwait_nonstep_watch_state
:
3323 fprintf_unfiltered (gdb_stdlog
,
3324 "infrun: infwait_nonstep_watch_state\n");
3325 insert_breakpoints ();
3327 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3328 handle things like signals arriving and other things happening
3329 in combination correctly? */
3330 stepped_after_stopped_by_watchpoint
= 1;
3334 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3337 infwait_state
= infwait_normal_state
;
3338 waiton_ptid
= pid_to_ptid (-1);
3340 switch (ecs
->ws
.kind
)
3342 case TARGET_WAITKIND_LOADED
:
3344 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3345 /* Ignore gracefully during startup of the inferior, as it might
3346 be the shell which has just loaded some objects, otherwise
3347 add the symbols for the newly loaded objects. Also ignore at
3348 the beginning of an attach or remote session; we will query
3349 the full list of libraries once the connection is
3351 if (stop_soon
== NO_STOP_QUIETLY
)
3353 struct regcache
*regcache
;
3354 enum bpstat_signal_value sval
;
3356 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3357 context_switch (ecs
->ptid
);
3358 regcache
= get_thread_regcache (ecs
->ptid
);
3360 handle_solib_event ();
3362 ecs
->event_thread
->control
.stop_bpstat
3363 = bpstat_stop_status (get_regcache_aspace (regcache
),
3364 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3367 = bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
3368 ecs
->random_signal
= sval
== BPSTAT_SIGNAL_NO
;
3370 if (!ecs
->random_signal
)
3372 /* A catchpoint triggered. */
3373 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3374 goto process_event_stop_test
;
3377 /* If requested, stop when the dynamic linker notifies
3378 gdb of events. This allows the user to get control
3379 and place breakpoints in initializer routines for
3380 dynamically loaded objects (among other things). */
3381 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3382 if (stop_on_solib_events
)
3384 /* Make sure we print "Stopped due to solib-event" in
3386 stop_print_frame
= 1;
3388 stop_stepping (ecs
);
3393 /* If we are skipping through a shell, or through shared library
3394 loading that we aren't interested in, resume the program. If
3395 we're running the program normally, also resume. But stop if
3396 we're attaching or setting up a remote connection. */
3397 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3399 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3400 context_switch (ecs
->ptid
);
3402 /* Loading of shared libraries might have changed breakpoint
3403 addresses. Make sure new breakpoints are inserted. */
3404 if (stop_soon
== NO_STOP_QUIETLY
3405 && !breakpoints_always_inserted_mode ())
3406 insert_breakpoints ();
3407 resume (0, GDB_SIGNAL_0
);
3408 prepare_to_wait (ecs
);
3414 case TARGET_WAITKIND_SPURIOUS
:
3416 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3417 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3418 context_switch (ecs
->ptid
);
3419 resume (0, GDB_SIGNAL_0
);
3420 prepare_to_wait (ecs
);
3423 case TARGET_WAITKIND_EXITED
:
3424 case TARGET_WAITKIND_SIGNALLED
:
3427 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3428 fprintf_unfiltered (gdb_stdlog
,
3429 "infrun: TARGET_WAITKIND_EXITED\n");
3431 fprintf_unfiltered (gdb_stdlog
,
3432 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3435 inferior_ptid
= ecs
->ptid
;
3436 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3437 set_current_program_space (current_inferior ()->pspace
);
3438 handle_vfork_child_exec_or_exit (0);
3439 target_terminal_ours (); /* Must do this before mourn anyway. */
3441 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3443 /* Record the exit code in the convenience variable $_exitcode, so
3444 that the user can inspect this again later. */
3445 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3446 (LONGEST
) ecs
->ws
.value
.integer
);
3448 /* Also record this in the inferior itself. */
3449 current_inferior ()->has_exit_code
= 1;
3450 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3452 print_exited_reason (ecs
->ws
.value
.integer
);
3455 print_signal_exited_reason (ecs
->ws
.value
.sig
);
3457 gdb_flush (gdb_stdout
);
3458 target_mourn_inferior ();
3459 singlestep_breakpoints_inserted_p
= 0;
3460 cancel_single_step_breakpoints ();
3461 stop_print_frame
= 0;
3462 stop_stepping (ecs
);
3465 /* The following are the only cases in which we keep going;
3466 the above cases end in a continue or goto. */
3467 case TARGET_WAITKIND_FORKED
:
3468 case TARGET_WAITKIND_VFORKED
:
3471 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3472 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3474 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3477 /* Check whether the inferior is displaced stepping. */
3479 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3480 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3481 struct displaced_step_inferior_state
*displaced
3482 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3484 /* If checking displaced stepping is supported, and thread
3485 ecs->ptid is displaced stepping. */
3486 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3488 struct inferior
*parent_inf
3489 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3490 struct regcache
*child_regcache
;
3491 CORE_ADDR parent_pc
;
3493 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3494 indicating that the displaced stepping of syscall instruction
3495 has been done. Perform cleanup for parent process here. Note
3496 that this operation also cleans up the child process for vfork,
3497 because their pages are shared. */
3498 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3500 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3502 /* Restore scratch pad for child process. */
3503 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3506 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3507 the child's PC is also within the scratchpad. Set the child's PC
3508 to the parent's PC value, which has already been fixed up.
3509 FIXME: we use the parent's aspace here, although we're touching
3510 the child, because the child hasn't been added to the inferior
3511 list yet at this point. */
3514 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3516 parent_inf
->aspace
);
3517 /* Read PC value of parent process. */
3518 parent_pc
= regcache_read_pc (regcache
);
3520 if (debug_displaced
)
3521 fprintf_unfiltered (gdb_stdlog
,
3522 "displaced: write child pc from %s to %s\n",
3524 regcache_read_pc (child_regcache
)),
3525 paddress (gdbarch
, parent_pc
));
3527 regcache_write_pc (child_regcache
, parent_pc
);
3531 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3532 context_switch (ecs
->ptid
);
3534 /* Immediately detach breakpoints from the child before there's
3535 any chance of letting the user delete breakpoints from the
3536 breakpoint lists. If we don't do this early, it's easy to
3537 leave left over traps in the child, vis: "break foo; catch
3538 fork; c; <fork>; del; c; <child calls foo>". We only follow
3539 the fork on the last `continue', and by that time the
3540 breakpoint at "foo" is long gone from the breakpoint table.
3541 If we vforked, then we don't need to unpatch here, since both
3542 parent and child are sharing the same memory pages; we'll
3543 need to unpatch at follow/detach time instead to be certain
3544 that new breakpoints added between catchpoint hit time and
3545 vfork follow are detached. */
3546 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3548 /* This won't actually modify the breakpoint list, but will
3549 physically remove the breakpoints from the child. */
3550 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3553 if (singlestep_breakpoints_inserted_p
)
3555 /* Pull the single step breakpoints out of the target. */
3556 remove_single_step_breakpoints ();
3557 singlestep_breakpoints_inserted_p
= 0;
3560 /* In case the event is caught by a catchpoint, remember that
3561 the event is to be followed at the next resume of the thread,
3562 and not immediately. */
3563 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3565 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3567 ecs
->event_thread
->control
.stop_bpstat
3568 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3569 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3571 /* Note that we're interested in knowing the bpstat actually
3572 causes a stop, not just if it may explain the signal.
3573 Software watchpoints, for example, always appear in the
3576 = !bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
);
3578 /* If no catchpoint triggered for this, then keep going. */
3579 if (ecs
->random_signal
)
3585 = (follow_fork_mode_string
== follow_fork_mode_child
);
3587 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3589 should_resume
= follow_fork ();
3592 child
= ecs
->ws
.value
.related_pid
;
3594 /* In non-stop mode, also resume the other branch. */
3595 if (non_stop
&& !detach_fork
)
3598 switch_to_thread (parent
);
3600 switch_to_thread (child
);
3602 ecs
->event_thread
= inferior_thread ();
3603 ecs
->ptid
= inferior_ptid
;
3608 switch_to_thread (child
);
3610 switch_to_thread (parent
);
3612 ecs
->event_thread
= inferior_thread ();
3613 ecs
->ptid
= inferior_ptid
;
3618 stop_stepping (ecs
);
3621 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3622 goto process_event_stop_test
;
3624 case TARGET_WAITKIND_VFORK_DONE
:
3625 /* Done with the shared memory region. Re-insert breakpoints in
3626 the parent, and keep going. */
3629 fprintf_unfiltered (gdb_stdlog
,
3630 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3632 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3633 context_switch (ecs
->ptid
);
3635 current_inferior ()->waiting_for_vfork_done
= 0;
3636 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3637 /* This also takes care of reinserting breakpoints in the
3638 previously locked inferior. */
3642 case TARGET_WAITKIND_EXECD
:
3644 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3646 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3647 context_switch (ecs
->ptid
);
3649 singlestep_breakpoints_inserted_p
= 0;
3650 cancel_single_step_breakpoints ();
3652 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3654 /* Do whatever is necessary to the parent branch of the vfork. */
3655 handle_vfork_child_exec_or_exit (1);
3657 /* This causes the eventpoints and symbol table to be reset.
3658 Must do this now, before trying to determine whether to
3660 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3662 ecs
->event_thread
->control
.stop_bpstat
3663 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3664 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3666 = (bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
)
3667 == BPSTAT_SIGNAL_NO
);
3669 /* Note that this may be referenced from inside
3670 bpstat_stop_status above, through inferior_has_execd. */
3671 xfree (ecs
->ws
.value
.execd_pathname
);
3672 ecs
->ws
.value
.execd_pathname
= NULL
;
3674 /* If no catchpoint triggered for this, then keep going. */
3675 if (ecs
->random_signal
)
3677 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3681 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
3682 goto process_event_stop_test
;
3684 /* Be careful not to try to gather much state about a thread
3685 that's in a syscall. It's frequently a losing proposition. */
3686 case TARGET_WAITKIND_SYSCALL_ENTRY
:
3688 fprintf_unfiltered (gdb_stdlog
,
3689 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3690 /* Getting the current syscall number. */
3691 if (handle_syscall_event (ecs
) != 0)
3693 goto process_event_stop_test
;
3695 /* Before examining the threads further, step this thread to
3696 get it entirely out of the syscall. (We get notice of the
3697 event when the thread is just on the verge of exiting a
3698 syscall. Stepping one instruction seems to get it back
3700 case TARGET_WAITKIND_SYSCALL_RETURN
:
3702 fprintf_unfiltered (gdb_stdlog
,
3703 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3704 if (handle_syscall_event (ecs
) != 0)
3706 goto process_event_stop_test
;
3708 case TARGET_WAITKIND_STOPPED
:
3710 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
3711 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
3714 case TARGET_WAITKIND_NO_HISTORY
:
3716 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
3717 /* Reverse execution: target ran out of history info. */
3719 /* Pull the single step breakpoints out of the target. */
3720 if (singlestep_breakpoints_inserted_p
)
3722 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3723 context_switch (ecs
->ptid
);
3724 remove_single_step_breakpoints ();
3725 singlestep_breakpoints_inserted_p
= 0;
3727 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3728 print_no_history_reason ();
3729 stop_stepping (ecs
);
3733 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
3735 /* Do we need to clean up the state of a thread that has
3736 completed a displaced single-step? (Doing so usually affects
3737 the PC, so do it here, before we set stop_pc.) */
3738 displaced_step_fixup (ecs
->ptid
,
3739 ecs
->event_thread
->suspend
.stop_signal
);
3741 /* If we either finished a single-step or hit a breakpoint, but
3742 the user wanted this thread to be stopped, pretend we got a
3743 SIG0 (generic unsignaled stop). */
3745 if (ecs
->event_thread
->stop_requested
3746 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3747 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3750 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3754 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3755 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3756 struct cleanup
*old_chain
= save_inferior_ptid ();
3758 inferior_ptid
= ecs
->ptid
;
3760 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
3761 paddress (gdbarch
, stop_pc
));
3762 if (target_stopped_by_watchpoint ())
3766 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
3768 if (target_stopped_data_address (¤t_target
, &addr
))
3769 fprintf_unfiltered (gdb_stdlog
,
3770 "infrun: stopped data address = %s\n",
3771 paddress (gdbarch
, addr
));
3773 fprintf_unfiltered (gdb_stdlog
,
3774 "infrun: (no data address available)\n");
3777 do_cleanups (old_chain
);
3780 if (stepping_past_singlestep_breakpoint
)
3782 gdb_assert (singlestep_breakpoints_inserted_p
);
3783 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
3784 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
3786 stepping_past_singlestep_breakpoint
= 0;
3788 /* We've either finished single-stepping past the single-step
3789 breakpoint, or stopped for some other reason. It would be nice if
3790 we could tell, but we can't reliably. */
3791 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3794 fprintf_unfiltered (gdb_stdlog
,
3795 "infrun: stepping_past_"
3796 "singlestep_breakpoint\n");
3797 /* Pull the single step breakpoints out of the target. */
3798 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3799 context_switch (ecs
->ptid
);
3800 remove_single_step_breakpoints ();
3801 singlestep_breakpoints_inserted_p
= 0;
3803 ecs
->random_signal
= 0;
3804 ecs
->event_thread
->control
.trap_expected
= 0;
3806 context_switch (saved_singlestep_ptid
);
3807 if (deprecated_context_hook
)
3808 deprecated_context_hook (pid_to_thread_id (saved_singlestep_ptid
));
3810 resume (1, GDB_SIGNAL_0
);
3811 prepare_to_wait (ecs
);
3816 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
3818 /* In non-stop mode, there's never a deferred_step_ptid set. */
3819 gdb_assert (!non_stop
);
3821 /* If we stopped for some other reason than single-stepping, ignore
3822 the fact that we were supposed to switch back. */
3823 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3826 fprintf_unfiltered (gdb_stdlog
,
3827 "infrun: handling deferred step\n");
3829 /* Pull the single step breakpoints out of the target. */
3830 if (singlestep_breakpoints_inserted_p
)
3832 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3833 context_switch (ecs
->ptid
);
3834 remove_single_step_breakpoints ();
3835 singlestep_breakpoints_inserted_p
= 0;
3838 ecs
->event_thread
->control
.trap_expected
= 0;
3840 context_switch (deferred_step_ptid
);
3841 deferred_step_ptid
= null_ptid
;
3842 /* Suppress spurious "Switching to ..." message. */
3843 previous_inferior_ptid
= inferior_ptid
;
3845 resume (1, GDB_SIGNAL_0
);
3846 prepare_to_wait (ecs
);
3850 deferred_step_ptid
= null_ptid
;
3853 /* See if a thread hit a thread-specific breakpoint that was meant for
3854 another thread. If so, then step that thread past the breakpoint,
3857 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
3859 int thread_hop_needed
= 0;
3860 struct address_space
*aspace
=
3861 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
3863 /* Check if a regular breakpoint has been hit before checking
3864 for a potential single step breakpoint. Otherwise, GDB will
3865 not see this breakpoint hit when stepping onto breakpoints. */
3866 if (regular_breakpoint_inserted_here_p (aspace
, stop_pc
))
3868 ecs
->random_signal
= 0;
3869 if (!breakpoint_thread_match (aspace
, stop_pc
, ecs
->ptid
))
3870 thread_hop_needed
= 1;
3872 else if (singlestep_breakpoints_inserted_p
)
3874 /* We have not context switched yet, so this should be true
3875 no matter which thread hit the singlestep breakpoint. */
3876 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
3878 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
3880 target_pid_to_str (ecs
->ptid
));
3882 ecs
->random_signal
= 0;
3883 /* The call to in_thread_list is necessary because PTIDs sometimes
3884 change when we go from single-threaded to multi-threaded. If
3885 the singlestep_ptid is still in the list, assume that it is
3886 really different from ecs->ptid. */
3887 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
3888 && in_thread_list (singlestep_ptid
))
3890 /* If the PC of the thread we were trying to single-step
3891 has changed, discard this event (which we were going
3892 to ignore anyway), and pretend we saw that thread
3893 trap. This prevents us continuously moving the
3894 single-step breakpoint forward, one instruction at a
3895 time. If the PC has changed, then the thread we were
3896 trying to single-step has trapped or been signalled,
3897 but the event has not been reported to GDB yet.
3899 There might be some cases where this loses signal
3900 information, if a signal has arrived at exactly the
3901 same time that the PC changed, but this is the best
3902 we can do with the information available. Perhaps we
3903 should arrange to report all events for all threads
3904 when they stop, or to re-poll the remote looking for
3905 this particular thread (i.e. temporarily enable
3908 CORE_ADDR new_singlestep_pc
3909 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
3911 if (new_singlestep_pc
!= singlestep_pc
)
3913 enum gdb_signal stop_signal
;
3916 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
3917 " but expected thread advanced also\n");
3919 /* The current context still belongs to
3920 singlestep_ptid. Don't swap here, since that's
3921 the context we want to use. Just fudge our
3922 state and continue. */
3923 stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
3924 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3925 ecs
->ptid
= singlestep_ptid
;
3926 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3927 ecs
->event_thread
->suspend
.stop_signal
= stop_signal
;
3928 stop_pc
= new_singlestep_pc
;
3933 fprintf_unfiltered (gdb_stdlog
,
3934 "infrun: unexpected thread\n");
3936 thread_hop_needed
= 1;
3937 stepping_past_singlestep_breakpoint
= 1;
3938 saved_singlestep_ptid
= singlestep_ptid
;
3943 if (thread_hop_needed
)
3945 struct regcache
*thread_regcache
;
3946 int remove_status
= 0;
3949 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
3951 /* Switch context before touching inferior memory, the
3952 previous thread may have exited. */
3953 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
3954 context_switch (ecs
->ptid
);
3956 /* Saw a breakpoint, but it was hit by the wrong thread.
3959 if (singlestep_breakpoints_inserted_p
)
3961 /* Pull the single step breakpoints out of the target. */
3962 remove_single_step_breakpoints ();
3963 singlestep_breakpoints_inserted_p
= 0;
3966 /* If the arch can displace step, don't remove the
3968 thread_regcache
= get_thread_regcache (ecs
->ptid
);
3969 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
3970 remove_status
= remove_breakpoints ();
3972 /* Did we fail to remove breakpoints? If so, try
3973 to set the PC past the bp. (There's at least
3974 one situation in which we can fail to remove
3975 the bp's: On HP-UX's that use ttrace, we can't
3976 change the address space of a vforking child
3977 process until the child exits (well, okay, not
3978 then either :-) or execs. */
3979 if (remove_status
!= 0)
3980 error (_("Cannot step over breakpoint hit in wrong thread"));
3985 /* Only need to require the next event from this
3986 thread in all-stop mode. */
3987 waiton_ptid
= ecs
->ptid
;
3988 infwait_state
= infwait_thread_hop_state
;
3991 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3996 else if (singlestep_breakpoints_inserted_p
)
3998 ecs
->random_signal
= 0;
4002 ecs
->random_signal
= 1;
4004 /* See if something interesting happened to the non-current thread. If
4005 so, then switch to that thread. */
4006 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4009 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
4011 context_switch (ecs
->ptid
);
4013 if (deprecated_context_hook
)
4014 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
4017 /* At this point, get hold of the now-current thread's frame. */
4018 frame
= get_current_frame ();
4019 gdbarch
= get_frame_arch (frame
);
4021 if (singlestep_breakpoints_inserted_p
)
4023 /* Pull the single step breakpoints out of the target. */
4024 remove_single_step_breakpoints ();
4025 singlestep_breakpoints_inserted_p
= 0;
4028 if (stepped_after_stopped_by_watchpoint
)
4029 stopped_by_watchpoint
= 0;
4031 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4033 /* If necessary, step over this watchpoint. We'll be back to display
4035 if (stopped_by_watchpoint
4036 && (target_have_steppable_watchpoint
4037 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4039 /* At this point, we are stopped at an instruction which has
4040 attempted to write to a piece of memory under control of
4041 a watchpoint. The instruction hasn't actually executed
4042 yet. If we were to evaluate the watchpoint expression
4043 now, we would get the old value, and therefore no change
4044 would seem to have occurred.
4046 In order to make watchpoints work `right', we really need
4047 to complete the memory write, and then evaluate the
4048 watchpoint expression. We do this by single-stepping the
4051 It may not be necessary to disable the watchpoint to stop over
4052 it. For example, the PA can (with some kernel cooperation)
4053 single step over a watchpoint without disabling the watchpoint.
4055 It is far more common to need to disable a watchpoint to step
4056 the inferior over it. If we have non-steppable watchpoints,
4057 we must disable the current watchpoint; it's simplest to
4058 disable all watchpoints and breakpoints. */
4061 if (!target_have_steppable_watchpoint
)
4063 remove_breakpoints ();
4064 /* See comment in resume why we need to stop bypassing signals
4065 while breakpoints have been removed. */
4066 target_pass_signals (0, NULL
);
4069 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4070 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4071 waiton_ptid
= ecs
->ptid
;
4072 if (target_have_steppable_watchpoint
)
4073 infwait_state
= infwait_step_watch_state
;
4075 infwait_state
= infwait_nonstep_watch_state
;
4076 prepare_to_wait (ecs
);
4080 clear_stop_func (ecs
);
4081 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4082 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4083 ecs
->event_thread
->control
.stop_step
= 0;
4084 stop_print_frame
= 1;
4085 ecs
->random_signal
= 0;
4086 stopped_by_random_signal
= 0;
4088 /* Hide inlined functions starting here, unless we just performed stepi or
4089 nexti. After stepi and nexti, always show the innermost frame (not any
4090 inline function call sites). */
4091 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4093 struct address_space
*aspace
=
4094 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4096 /* skip_inline_frames is expensive, so we avoid it if we can
4097 determine that the address is one where functions cannot have
4098 been inlined. This improves performance with inferiors that
4099 load a lot of shared libraries, because the solib event
4100 breakpoint is defined as the address of a function (i.e. not
4101 inline). Note that we have to check the previous PC as well
4102 as the current one to catch cases when we have just
4103 single-stepped off a breakpoint prior to reinstating it.
4104 Note that we're assuming that the code we single-step to is
4105 not inline, but that's not definitive: there's nothing
4106 preventing the event breakpoint function from containing
4107 inlined code, and the single-step ending up there. If the
4108 user had set a breakpoint on that inlined code, the missing
4109 skip_inline_frames call would break things. Fortunately
4110 that's an extremely unlikely scenario. */
4111 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4112 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4113 && ecs
->event_thread
->control
.trap_expected
4114 && pc_at_non_inline_function (aspace
,
4115 ecs
->event_thread
->prev_pc
,
4118 skip_inline_frames (ecs
->ptid
);
4120 /* Re-fetch current thread's frame in case that invalidated
4122 frame
= get_current_frame ();
4123 gdbarch
= get_frame_arch (frame
);
4127 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4128 && ecs
->event_thread
->control
.trap_expected
4129 && gdbarch_single_step_through_delay_p (gdbarch
)
4130 && currently_stepping (ecs
->event_thread
))
4132 /* We're trying to step off a breakpoint. Turns out that we're
4133 also on an instruction that needs to be stepped multiple
4134 times before it's been fully executing. E.g., architectures
4135 with a delay slot. It needs to be stepped twice, once for
4136 the instruction and once for the delay slot. */
4137 int step_through_delay
4138 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4140 if (debug_infrun
&& step_through_delay
)
4141 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4142 if (ecs
->event_thread
->control
.step_range_end
== 0
4143 && step_through_delay
)
4145 /* The user issued a continue when stopped at a breakpoint.
4146 Set up for another trap and get out of here. */
4147 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4151 else if (step_through_delay
)
4153 /* The user issued a step when stopped at a breakpoint.
4154 Maybe we should stop, maybe we should not - the delay
4155 slot *might* correspond to a line of source. In any
4156 case, don't decide that here, just set
4157 ecs->stepping_over_breakpoint, making sure we
4158 single-step again before breakpoints are re-inserted. */
4159 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4163 /* Look at the cause of the stop, and decide what to do.
4164 The alternatives are:
4165 1) stop_stepping and return; to really stop and return to the debugger,
4166 2) keep_going and return to start up again
4167 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
4168 3) set ecs->random_signal to 1, and the decision between 1 and 2
4169 will be made according to the signal handling tables. */
4171 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4175 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4176 stop_print_frame
= 0;
4177 stop_stepping (ecs
);
4181 /* This is originated from start_remote(), start_inferior() and
4182 shared libraries hook functions. */
4183 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4186 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4187 stop_stepping (ecs
);
4191 /* This originates from attach_command(). We need to overwrite
4192 the stop_signal here, because some kernels don't ignore a
4193 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4194 See more comments in inferior.h. On the other hand, if we
4195 get a non-SIGSTOP, report it to the user - assume the backend
4196 will handle the SIGSTOP if it should show up later.
4198 Also consider that the attach is complete when we see a
4199 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4200 target extended-remote report it instead of a SIGSTOP
4201 (e.g. gdbserver). We already rely on SIGTRAP being our
4202 signal, so this is no exception.
4204 Also consider that the attach is complete when we see a
4205 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4206 the target to stop all threads of the inferior, in case the
4207 low level attach operation doesn't stop them implicitly. If
4208 they weren't stopped implicitly, then the stub will report a
4209 GDB_SIGNAL_0, meaning: stopped for no particular reason
4210 other than GDB's request. */
4211 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4212 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4213 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4214 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4216 stop_stepping (ecs
);
4217 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4221 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4222 handles this event. */
4223 ecs
->event_thread
->control
.stop_bpstat
4224 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4225 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4227 /* Following in case break condition called a
4229 stop_print_frame
= 1;
4231 /* This is where we handle "moribund" watchpoints. Unlike
4232 software breakpoints traps, hardware watchpoint traps are
4233 always distinguishable from random traps. If no high-level
4234 watchpoint is associated with the reported stop data address
4235 anymore, then the bpstat does not explain the signal ---
4236 simply make sure to ignore it if `stopped_by_watchpoint' is
4240 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4241 && (bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
)
4242 == BPSTAT_SIGNAL_NO
)
4243 && stopped_by_watchpoint
)
4244 fprintf_unfiltered (gdb_stdlog
,
4245 "infrun: no user watchpoint explains "
4246 "watchpoint SIGTRAP, ignoring\n");
4248 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4249 at one stage in the past included checks for an inferior
4250 function call's call dummy's return breakpoint. The original
4251 comment, that went with the test, read:
4253 ``End of a stack dummy. Some systems (e.g. Sony news) give
4254 another signal besides SIGTRAP, so check here as well as
4257 If someone ever tries to get call dummys on a
4258 non-executable stack to work (where the target would stop
4259 with something like a SIGSEGV), then those tests might need
4260 to be re-instated. Given, however, that the tests were only
4261 enabled when momentary breakpoints were not being used, I
4262 suspect that it won't be the case.
4264 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4265 be necessary for call dummies on a non-executable stack on
4268 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4270 = !((bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
)
4271 != BPSTAT_SIGNAL_NO
)
4272 || stopped_by_watchpoint
4273 || ecs
->event_thread
->control
.trap_expected
4274 || (ecs
->event_thread
->control
.step_range_end
4275 && (ecs
->event_thread
->control
.step_resume_breakpoint
4279 enum bpstat_signal_value sval
;
4281 sval
= bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
);
4282 ecs
->random_signal
= (sval
== BPSTAT_SIGNAL_NO
);
4284 if (sval
== BPSTAT_SIGNAL_HIDE
)
4285 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_TRAP
;
4288 process_event_stop_test
:
4290 /* Re-fetch current thread's frame in case we did a
4291 "goto process_event_stop_test" above. */
4292 frame
= get_current_frame ();
4293 gdbarch
= get_frame_arch (frame
);
4295 /* For the program's own signals, act according to
4296 the signal handling tables. */
4298 if (ecs
->random_signal
)
4300 /* Signal not for debugging purposes. */
4302 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4305 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
4306 ecs
->event_thread
->suspend
.stop_signal
);
4308 stopped_by_random_signal
= 1;
4310 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4313 target_terminal_ours_for_output ();
4314 print_signal_received_reason
4315 (ecs
->event_thread
->suspend
.stop_signal
);
4317 /* Always stop on signals if we're either just gaining control
4318 of the program, or the user explicitly requested this thread
4319 to remain stopped. */
4320 if (stop_soon
!= NO_STOP_QUIETLY
4321 || ecs
->event_thread
->stop_requested
4323 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4325 stop_stepping (ecs
);
4328 /* If not going to stop, give terminal back
4329 if we took it away. */
4331 target_terminal_inferior ();
4333 /* Clear the signal if it should not be passed. */
4334 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4335 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4337 if (ecs
->event_thread
->prev_pc
== stop_pc
4338 && ecs
->event_thread
->control
.trap_expected
4339 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4341 /* We were just starting a new sequence, attempting to
4342 single-step off of a breakpoint and expecting a SIGTRAP.
4343 Instead this signal arrives. This signal will take us out
4344 of the stepping range so GDB needs to remember to, when
4345 the signal handler returns, resume stepping off that
4347 /* To simplify things, "continue" is forced to use the same
4348 code paths as single-step - set a breakpoint at the
4349 signal return address and then, once hit, step off that
4352 fprintf_unfiltered (gdb_stdlog
,
4353 "infrun: signal arrived while stepping over "
4356 insert_hp_step_resume_breakpoint_at_frame (frame
);
4357 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4358 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4359 ecs
->event_thread
->control
.trap_expected
= 0;
4364 if (ecs
->event_thread
->control
.step_range_end
!= 0
4365 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4366 && pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4367 && frame_id_eq (get_stack_frame_id (frame
),
4368 ecs
->event_thread
->control
.step_stack_frame_id
)
4369 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4371 /* The inferior is about to take a signal that will take it
4372 out of the single step range. Set a breakpoint at the
4373 current PC (which is presumably where the signal handler
4374 will eventually return) and then allow the inferior to
4377 Note that this is only needed for a signal delivered
4378 while in the single-step range. Nested signals aren't a
4379 problem as they eventually all return. */
4381 fprintf_unfiltered (gdb_stdlog
,
4382 "infrun: signal may take us out of "
4383 "single-step range\n");
4385 insert_hp_step_resume_breakpoint_at_frame (frame
);
4386 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4387 ecs
->event_thread
->control
.trap_expected
= 0;
4392 /* Note: step_resume_breakpoint may be non-NULL. This occures
4393 when either there's a nested signal, or when there's a
4394 pending signal enabled just as the signal handler returns
4395 (leaving the inferior at the step-resume-breakpoint without
4396 actually executing it). Either way continue until the
4397 breakpoint is really hit. */
4401 /* Handle cases caused by hitting a breakpoint. */
4403 CORE_ADDR jmp_buf_pc
;
4404 struct bpstat_what what
;
4406 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4408 if (what
.call_dummy
)
4410 stop_stack_dummy
= what
.call_dummy
;
4413 /* If we hit an internal event that triggers symbol changes, the
4414 current frame will be invalidated within bpstat_what (e.g.,
4415 if we hit an internal solib event). Re-fetch it. */
4416 frame
= get_current_frame ();
4417 gdbarch
= get_frame_arch (frame
);
4419 switch (what
.main_action
)
4421 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4422 /* If we hit the breakpoint at longjmp while stepping, we
4423 install a momentary breakpoint at the target of the
4427 fprintf_unfiltered (gdb_stdlog
,
4428 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4430 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4432 if (what
.is_longjmp
)
4434 struct value
*arg_value
;
4436 /* If we set the longjmp breakpoint via a SystemTap
4437 probe, then use it to extract the arguments. The
4438 destination PC is the third argument to the
4440 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4442 jmp_buf_pc
= value_as_address (arg_value
);
4443 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4444 || !gdbarch_get_longjmp_target (gdbarch
,
4445 frame
, &jmp_buf_pc
))
4448 fprintf_unfiltered (gdb_stdlog
,
4449 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4450 "(!gdbarch_get_longjmp_target)\n");
4455 /* Insert a breakpoint at resume address. */
4456 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4459 check_exception_resume (ecs
, frame
);
4463 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4465 struct frame_info
*init_frame
;
4467 /* There are several cases to consider.
4469 1. The initiating frame no longer exists. In this case
4470 we must stop, because the exception or longjmp has gone
4473 2. The initiating frame exists, and is the same as the
4474 current frame. We stop, because the exception or
4475 longjmp has been caught.
4477 3. The initiating frame exists and is different from
4478 the current frame. This means the exception or longjmp
4479 has been caught beneath the initiating frame, so keep
4482 4. longjmp breakpoint has been placed just to protect
4483 against stale dummy frames and user is not interested
4484 in stopping around longjmps. */
4487 fprintf_unfiltered (gdb_stdlog
,
4488 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4490 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4492 delete_exception_resume_breakpoint (ecs
->event_thread
);
4494 if (what
.is_longjmp
)
4496 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
->num
);
4498 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4506 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4510 struct frame_id current_id
4511 = get_frame_id (get_current_frame ());
4512 if (frame_id_eq (current_id
,
4513 ecs
->event_thread
->initiating_frame
))
4515 /* Case 2. Fall through. */
4525 /* For Cases 1 and 2, remove the step-resume breakpoint,
4527 delete_step_resume_breakpoint (ecs
->event_thread
);
4529 ecs
->event_thread
->control
.stop_step
= 1;
4530 print_end_stepping_range_reason ();
4531 stop_stepping (ecs
);
4535 case BPSTAT_WHAT_SINGLE
:
4537 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4538 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4539 /* Still need to check other stuff, at least the case where
4540 we are stepping and step out of the right range. */
4543 case BPSTAT_WHAT_STEP_RESUME
:
4545 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4547 delete_step_resume_breakpoint (ecs
->event_thread
);
4548 if (ecs
->event_thread
->control
.proceed_to_finish
4549 && execution_direction
== EXEC_REVERSE
)
4551 struct thread_info
*tp
= ecs
->event_thread
;
4553 /* We are finishing a function in reverse, and just hit
4554 the step-resume breakpoint at the start address of
4555 the function, and we're almost there -- just need to
4556 back up by one more single-step, which should take us
4557 back to the function call. */
4558 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4562 fill_in_stop_func (gdbarch
, ecs
);
4563 if (stop_pc
== ecs
->stop_func_start
4564 && execution_direction
== EXEC_REVERSE
)
4566 /* We are stepping over a function call in reverse, and
4567 just hit the step-resume breakpoint at the start
4568 address of the function. Go back to single-stepping,
4569 which should take us back to the function call. */
4570 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4576 case BPSTAT_WHAT_STOP_NOISY
:
4578 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4579 stop_print_frame
= 1;
4581 /* We are about to nuke the step_resume_breakpointt via the
4582 cleanup chain, so no need to worry about it here. */
4584 stop_stepping (ecs
);
4587 case BPSTAT_WHAT_STOP_SILENT
:
4589 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4590 stop_print_frame
= 0;
4592 /* We are about to nuke the step_resume_breakpoin via the
4593 cleanup chain, so no need to worry about it here. */
4595 stop_stepping (ecs
);
4598 case BPSTAT_WHAT_HP_STEP_RESUME
:
4600 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4602 delete_step_resume_breakpoint (ecs
->event_thread
);
4603 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4605 /* Back when the step-resume breakpoint was inserted, we
4606 were trying to single-step off a breakpoint. Go back
4608 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4609 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4615 case BPSTAT_WHAT_KEEP_CHECKING
:
4620 /* We come here if we hit a breakpoint but should not
4621 stop for it. Possibly we also were stepping
4622 and should stop for that. So fall through and
4623 test for stepping. But, if not stepping,
4626 /* In all-stop mode, if we're currently stepping but have stopped in
4627 some other thread, we need to switch back to the stepped thread. */
4630 struct thread_info
*tp
;
4632 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
4636 /* However, if the current thread is blocked on some internal
4637 breakpoint, and we simply need to step over that breakpoint
4638 to get it going again, do that first. */
4639 if ((ecs
->event_thread
->control
.trap_expected
4640 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
4641 || ecs
->event_thread
->stepping_over_breakpoint
)
4647 /* If the stepping thread exited, then don't try to switch
4648 back and resume it, which could fail in several different
4649 ways depending on the target. Instead, just keep going.
4651 We can find a stepping dead thread in the thread list in
4654 - The target supports thread exit events, and when the
4655 target tries to delete the thread from the thread list,
4656 inferior_ptid pointed at the exiting thread. In such
4657 case, calling delete_thread does not really remove the
4658 thread from the list; instead, the thread is left listed,
4659 with 'exited' state.
4661 - The target's debug interface does not support thread
4662 exit events, and so we have no idea whatsoever if the
4663 previously stepping thread is still alive. For that
4664 reason, we need to synchronously query the target
4666 if (is_exited (tp
->ptid
)
4667 || !target_thread_alive (tp
->ptid
))
4670 fprintf_unfiltered (gdb_stdlog
,
4671 "infrun: not switching back to "
4672 "stepped thread, it has vanished\n");
4674 delete_thread (tp
->ptid
);
4679 /* Otherwise, we no longer expect a trap in the current thread.
4680 Clear the trap_expected flag before switching back -- this is
4681 what keep_going would do as well, if we called it. */
4682 ecs
->event_thread
->control
.trap_expected
= 0;
4685 fprintf_unfiltered (gdb_stdlog
,
4686 "infrun: switching back to stepped thread\n");
4688 ecs
->event_thread
= tp
;
4689 ecs
->ptid
= tp
->ptid
;
4690 context_switch (ecs
->ptid
);
4696 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4699 fprintf_unfiltered (gdb_stdlog
,
4700 "infrun: step-resume breakpoint is inserted\n");
4702 /* Having a step-resume breakpoint overrides anything
4703 else having to do with stepping commands until
4704 that breakpoint is reached. */
4709 if (ecs
->event_thread
->control
.step_range_end
== 0)
4712 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4713 /* Likewise if we aren't even stepping. */
4718 /* Re-fetch current thread's frame in case the code above caused
4719 the frame cache to be re-initialized, making our FRAME variable
4720 a dangling pointer. */
4721 frame
= get_current_frame ();
4722 gdbarch
= get_frame_arch (frame
);
4723 fill_in_stop_func (gdbarch
, ecs
);
4725 /* If stepping through a line, keep going if still within it.
4727 Note that step_range_end is the address of the first instruction
4728 beyond the step range, and NOT the address of the last instruction
4731 Note also that during reverse execution, we may be stepping
4732 through a function epilogue and therefore must detect when
4733 the current-frame changes in the middle of a line. */
4735 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4736 && (execution_direction
!= EXEC_REVERSE
4737 || frame_id_eq (get_frame_id (frame
),
4738 ecs
->event_thread
->control
.step_frame_id
)))
4742 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4743 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4744 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4746 /* Tentatively re-enable range stepping; `resume' disables it if
4747 necessary (e.g., if we're stepping over a breakpoint or we
4748 have software watchpoints). */
4749 ecs
->event_thread
->control
.may_range_step
= 1;
4751 /* When stepping backward, stop at beginning of line range
4752 (unless it's the function entry point, in which case
4753 keep going back to the call point). */
4754 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4755 && stop_pc
!= ecs
->stop_func_start
4756 && execution_direction
== EXEC_REVERSE
)
4758 ecs
->event_thread
->control
.stop_step
= 1;
4759 print_end_stepping_range_reason ();
4760 stop_stepping (ecs
);
4768 /* We stepped out of the stepping range. */
4770 /* If we are stepping at the source level and entered the runtime
4771 loader dynamic symbol resolution code...
4773 EXEC_FORWARD: we keep on single stepping until we exit the run
4774 time loader code and reach the callee's address.
4776 EXEC_REVERSE: we've already executed the callee (backward), and
4777 the runtime loader code is handled just like any other
4778 undebuggable function call. Now we need only keep stepping
4779 backward through the trampoline code, and that's handled further
4780 down, so there is nothing for us to do here. */
4782 if (execution_direction
!= EXEC_REVERSE
4783 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4784 && in_solib_dynsym_resolve_code (stop_pc
))
4786 CORE_ADDR pc_after_resolver
=
4787 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4790 fprintf_unfiltered (gdb_stdlog
,
4791 "infrun: stepped into dynsym resolve code\n");
4793 if (pc_after_resolver
)
4795 /* Set up a step-resume breakpoint at the address
4796 indicated by SKIP_SOLIB_RESOLVER. */
4797 struct symtab_and_line sr_sal
;
4800 sr_sal
.pc
= pc_after_resolver
;
4801 sr_sal
.pspace
= get_frame_program_space (frame
);
4803 insert_step_resume_breakpoint_at_sal (gdbarch
,
4804 sr_sal
, null_frame_id
);
4811 if (ecs
->event_thread
->control
.step_range_end
!= 1
4812 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4813 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4814 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4817 fprintf_unfiltered (gdb_stdlog
,
4818 "infrun: stepped into signal trampoline\n");
4819 /* The inferior, while doing a "step" or "next", has ended up in
4820 a signal trampoline (either by a signal being delivered or by
4821 the signal handler returning). Just single-step until the
4822 inferior leaves the trampoline (either by calling the handler
4828 /* If we're in the return path from a shared library trampoline,
4829 we want to proceed through the trampoline when stepping. */
4830 /* macro/2012-04-25: This needs to come before the subroutine
4831 call check below as on some targets return trampolines look
4832 like subroutine calls (MIPS16 return thunks). */
4833 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4834 stop_pc
, ecs
->stop_func_name
)
4835 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4837 /* Determine where this trampoline returns. */
4838 CORE_ADDR real_stop_pc
;
4840 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4843 fprintf_unfiltered (gdb_stdlog
,
4844 "infrun: stepped into solib return tramp\n");
4846 /* Only proceed through if we know where it's going. */
4849 /* And put the step-breakpoint there and go until there. */
4850 struct symtab_and_line sr_sal
;
4852 init_sal (&sr_sal
); /* initialize to zeroes */
4853 sr_sal
.pc
= real_stop_pc
;
4854 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4855 sr_sal
.pspace
= get_frame_program_space (frame
);
4857 /* Do not specify what the fp should be when we stop since
4858 on some machines the prologue is where the new fp value
4860 insert_step_resume_breakpoint_at_sal (gdbarch
,
4861 sr_sal
, null_frame_id
);
4863 /* Restart without fiddling with the step ranges or
4870 /* Check for subroutine calls. The check for the current frame
4871 equalling the step ID is not necessary - the check of the
4872 previous frame's ID is sufficient - but it is a common case and
4873 cheaper than checking the previous frame's ID.
4875 NOTE: frame_id_eq will never report two invalid frame IDs as
4876 being equal, so to get into this block, both the current and
4877 previous frame must have valid frame IDs. */
4878 /* The outer_frame_id check is a heuristic to detect stepping
4879 through startup code. If we step over an instruction which
4880 sets the stack pointer from an invalid value to a valid value,
4881 we may detect that as a subroutine call from the mythical
4882 "outermost" function. This could be fixed by marking
4883 outermost frames as !stack_p,code_p,special_p. Then the
4884 initial outermost frame, before sp was valid, would
4885 have code_addr == &_start. See the comment in frame_id_eq
4887 if (!frame_id_eq (get_stack_frame_id (frame
),
4888 ecs
->event_thread
->control
.step_stack_frame_id
)
4889 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4890 ecs
->event_thread
->control
.step_stack_frame_id
)
4891 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4893 || step_start_function
!= find_pc_function (stop_pc
))))
4895 CORE_ADDR real_stop_pc
;
4898 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4900 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4901 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4902 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4903 ecs
->stop_func_start
)))
4905 /* I presume that step_over_calls is only 0 when we're
4906 supposed to be stepping at the assembly language level
4907 ("stepi"). Just stop. */
4908 /* Also, maybe we just did a "nexti" inside a prolog, so we
4909 thought it was a subroutine call but it was not. Stop as
4911 /* And this works the same backward as frontward. MVS */
4912 ecs
->event_thread
->control
.stop_step
= 1;
4913 print_end_stepping_range_reason ();
4914 stop_stepping (ecs
);
4918 /* Reverse stepping through solib trampolines. */
4920 if (execution_direction
== EXEC_REVERSE
4921 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
4922 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
4923 || (ecs
->stop_func_start
== 0
4924 && in_solib_dynsym_resolve_code (stop_pc
))))
4926 /* Any solib trampoline code can be handled in reverse
4927 by simply continuing to single-step. We have already
4928 executed the solib function (backwards), and a few
4929 steps will take us back through the trampoline to the
4935 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4937 /* We're doing a "next".
4939 Normal (forward) execution: set a breakpoint at the
4940 callee's return address (the address at which the caller
4943 Reverse (backward) execution. set the step-resume
4944 breakpoint at the start of the function that we just
4945 stepped into (backwards), and continue to there. When we
4946 get there, we'll need to single-step back to the caller. */
4948 if (execution_direction
== EXEC_REVERSE
)
4950 /* If we're already at the start of the function, we've either
4951 just stepped backward into a single instruction function,
4952 or stepped back out of a signal handler to the first instruction
4953 of the function. Just keep going, which will single-step back
4955 if (ecs
->stop_func_start
!= stop_pc
)
4957 struct symtab_and_line sr_sal
;
4959 /* Normal function call return (static or dynamic). */
4961 sr_sal
.pc
= ecs
->stop_func_start
;
4962 sr_sal
.pspace
= get_frame_program_space (frame
);
4963 insert_step_resume_breakpoint_at_sal (gdbarch
,
4964 sr_sal
, null_frame_id
);
4968 insert_step_resume_breakpoint_at_caller (frame
);
4974 /* If we are in a function call trampoline (a stub between the
4975 calling routine and the real function), locate the real
4976 function. That's what tells us (a) whether we want to step
4977 into it at all, and (b) what prologue we want to run to the
4978 end of, if we do step into it. */
4979 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
4980 if (real_stop_pc
== 0)
4981 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4982 if (real_stop_pc
!= 0)
4983 ecs
->stop_func_start
= real_stop_pc
;
4985 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
4987 struct symtab_and_line sr_sal
;
4990 sr_sal
.pc
= ecs
->stop_func_start
;
4991 sr_sal
.pspace
= get_frame_program_space (frame
);
4993 insert_step_resume_breakpoint_at_sal (gdbarch
,
4994 sr_sal
, null_frame_id
);
4999 /* If we have line number information for the function we are
5000 thinking of stepping into and the function isn't on the skip
5003 If there are several symtabs at that PC (e.g. with include
5004 files), just want to know whether *any* of them have line
5005 numbers. find_pc_line handles this. */
5007 struct symtab_and_line tmp_sal
;
5009 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5010 if (tmp_sal
.line
!= 0
5011 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
5014 if (execution_direction
== EXEC_REVERSE
)
5015 handle_step_into_function_backward (gdbarch
, ecs
);
5017 handle_step_into_function (gdbarch
, ecs
);
5022 /* If we have no line number and the step-stop-if-no-debug is
5023 set, we stop the step so that the user has a chance to switch
5024 in assembly mode. */
5025 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5026 && step_stop_if_no_debug
)
5028 ecs
->event_thread
->control
.stop_step
= 1;
5029 print_end_stepping_range_reason ();
5030 stop_stepping (ecs
);
5034 if (execution_direction
== EXEC_REVERSE
)
5036 /* If we're already at the start of the function, we've either just
5037 stepped backward into a single instruction function without line
5038 number info, or stepped back out of a signal handler to the first
5039 instruction of the function without line number info. Just keep
5040 going, which will single-step back to the caller. */
5041 if (ecs
->stop_func_start
!= stop_pc
)
5043 /* Set a breakpoint at callee's start address.
5044 From there we can step once and be back in the caller. */
5045 struct symtab_and_line sr_sal
;
5048 sr_sal
.pc
= ecs
->stop_func_start
;
5049 sr_sal
.pspace
= get_frame_program_space (frame
);
5050 insert_step_resume_breakpoint_at_sal (gdbarch
,
5051 sr_sal
, null_frame_id
);
5055 /* Set a breakpoint at callee's return address (the address
5056 at which the caller will resume). */
5057 insert_step_resume_breakpoint_at_caller (frame
);
5063 /* Reverse stepping through solib trampolines. */
5065 if (execution_direction
== EXEC_REVERSE
5066 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5068 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5069 || (ecs
->stop_func_start
== 0
5070 && in_solib_dynsym_resolve_code (stop_pc
)))
5072 /* Any solib trampoline code can be handled in reverse
5073 by simply continuing to single-step. We have already
5074 executed the solib function (backwards), and a few
5075 steps will take us back through the trampoline to the
5080 else if (in_solib_dynsym_resolve_code (stop_pc
))
5082 /* Stepped backward into the solib dynsym resolver.
5083 Set a breakpoint at its start and continue, then
5084 one more step will take us out. */
5085 struct symtab_and_line sr_sal
;
5088 sr_sal
.pc
= ecs
->stop_func_start
;
5089 sr_sal
.pspace
= get_frame_program_space (frame
);
5090 insert_step_resume_breakpoint_at_sal (gdbarch
,
5091 sr_sal
, null_frame_id
);
5097 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5099 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5100 the trampoline processing logic, however, there are some trampolines
5101 that have no names, so we should do trampoline handling first. */
5102 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5103 && ecs
->stop_func_name
== NULL
5104 && stop_pc_sal
.line
== 0)
5107 fprintf_unfiltered (gdb_stdlog
,
5108 "infrun: stepped into undebuggable function\n");
5110 /* The inferior just stepped into, or returned to, an
5111 undebuggable function (where there is no debugging information
5112 and no line number corresponding to the address where the
5113 inferior stopped). Since we want to skip this kind of code,
5114 we keep going until the inferior returns from this
5115 function - unless the user has asked us not to (via
5116 set step-mode) or we no longer know how to get back
5117 to the call site. */
5118 if (step_stop_if_no_debug
5119 || !frame_id_p (frame_unwind_caller_id (frame
)))
5121 /* If we have no line number and the step-stop-if-no-debug
5122 is set, we stop the step so that the user has a chance to
5123 switch in assembly mode. */
5124 ecs
->event_thread
->control
.stop_step
= 1;
5125 print_end_stepping_range_reason ();
5126 stop_stepping (ecs
);
5131 /* Set a breakpoint at callee's return address (the address
5132 at which the caller will resume). */
5133 insert_step_resume_breakpoint_at_caller (frame
);
5139 if (ecs
->event_thread
->control
.step_range_end
== 1)
5141 /* It is stepi or nexti. We always want to stop stepping after
5144 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5145 ecs
->event_thread
->control
.stop_step
= 1;
5146 print_end_stepping_range_reason ();
5147 stop_stepping (ecs
);
5151 if (stop_pc_sal
.line
== 0)
5153 /* We have no line number information. That means to stop
5154 stepping (does this always happen right after one instruction,
5155 when we do "s" in a function with no line numbers,
5156 or can this happen as a result of a return or longjmp?). */
5158 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5159 ecs
->event_thread
->control
.stop_step
= 1;
5160 print_end_stepping_range_reason ();
5161 stop_stepping (ecs
);
5165 /* Look for "calls" to inlined functions, part one. If the inline
5166 frame machinery detected some skipped call sites, we have entered
5167 a new inline function. */
5169 if (frame_id_eq (get_frame_id (get_current_frame ()),
5170 ecs
->event_thread
->control
.step_frame_id
)
5171 && inline_skipped_frames (ecs
->ptid
))
5173 struct symtab_and_line call_sal
;
5176 fprintf_unfiltered (gdb_stdlog
,
5177 "infrun: stepped into inlined function\n");
5179 find_frame_sal (get_current_frame (), &call_sal
);
5181 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5183 /* For "step", we're going to stop. But if the call site
5184 for this inlined function is on the same source line as
5185 we were previously stepping, go down into the function
5186 first. Otherwise stop at the call site. */
5188 if (call_sal
.line
== ecs
->event_thread
->current_line
5189 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5190 step_into_inline_frame (ecs
->ptid
);
5192 ecs
->event_thread
->control
.stop_step
= 1;
5193 print_end_stepping_range_reason ();
5194 stop_stepping (ecs
);
5199 /* For "next", we should stop at the call site if it is on a
5200 different source line. Otherwise continue through the
5201 inlined function. */
5202 if (call_sal
.line
== ecs
->event_thread
->current_line
5203 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5207 ecs
->event_thread
->control
.stop_step
= 1;
5208 print_end_stepping_range_reason ();
5209 stop_stepping (ecs
);
5215 /* Look for "calls" to inlined functions, part two. If we are still
5216 in the same real function we were stepping through, but we have
5217 to go further up to find the exact frame ID, we are stepping
5218 through a more inlined call beyond its call site. */
5220 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5221 && !frame_id_eq (get_frame_id (get_current_frame ()),
5222 ecs
->event_thread
->control
.step_frame_id
)
5223 && stepped_in_from (get_current_frame (),
5224 ecs
->event_thread
->control
.step_frame_id
))
5227 fprintf_unfiltered (gdb_stdlog
,
5228 "infrun: stepping through inlined function\n");
5230 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5234 ecs
->event_thread
->control
.stop_step
= 1;
5235 print_end_stepping_range_reason ();
5236 stop_stepping (ecs
);
5241 if ((stop_pc
== stop_pc_sal
.pc
)
5242 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5243 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5245 /* We are at the start of a different line. So stop. Note that
5246 we don't stop if we step into the middle of a different line.
5247 That is said to make things like for (;;) statements work
5250 fprintf_unfiltered (gdb_stdlog
,
5251 "infrun: stepped to a different line\n");
5252 ecs
->event_thread
->control
.stop_step
= 1;
5253 print_end_stepping_range_reason ();
5254 stop_stepping (ecs
);
5258 /* We aren't done stepping.
5260 Optimize by setting the stepping range to the line.
5261 (We might not be in the original line, but if we entered a
5262 new line in mid-statement, we continue stepping. This makes
5263 things like for(;;) statements work better.) */
5265 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5266 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5267 ecs
->event_thread
->control
.may_range_step
= 1;
5268 set_step_info (frame
, stop_pc_sal
);
5271 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5275 /* Is thread TP in the middle of single-stepping? */
5278 currently_stepping (struct thread_info
*tp
)
5280 return ((tp
->control
.step_range_end
5281 && tp
->control
.step_resume_breakpoint
== NULL
)
5282 || tp
->control
.trap_expected
5283 || bpstat_should_step ());
5286 /* Returns true if any thread *but* the one passed in "data" is in the
5287 middle of stepping or of handling a "next". */
5290 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
5295 return (tp
->control
.step_range_end
5296 || tp
->control
.trap_expected
);
5299 /* Inferior has stepped into a subroutine call with source code that
5300 we should not step over. Do step to the first line of code in
5304 handle_step_into_function (struct gdbarch
*gdbarch
,
5305 struct execution_control_state
*ecs
)
5308 struct symtab_and_line stop_func_sal
, sr_sal
;
5310 fill_in_stop_func (gdbarch
, ecs
);
5312 s
= find_pc_symtab (stop_pc
);
5313 if (s
&& s
->language
!= language_asm
)
5314 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5315 ecs
->stop_func_start
);
5317 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5318 /* Use the step_resume_break to step until the end of the prologue,
5319 even if that involves jumps (as it seems to on the vax under
5321 /* If the prologue ends in the middle of a source line, continue to
5322 the end of that source line (if it is still within the function).
5323 Otherwise, just go to end of prologue. */
5324 if (stop_func_sal
.end
5325 && stop_func_sal
.pc
!= ecs
->stop_func_start
5326 && stop_func_sal
.end
< ecs
->stop_func_end
)
5327 ecs
->stop_func_start
= stop_func_sal
.end
;
5329 /* Architectures which require breakpoint adjustment might not be able
5330 to place a breakpoint at the computed address. If so, the test
5331 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5332 ecs->stop_func_start to an address at which a breakpoint may be
5333 legitimately placed.
5335 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5336 made, GDB will enter an infinite loop when stepping through
5337 optimized code consisting of VLIW instructions which contain
5338 subinstructions corresponding to different source lines. On
5339 FR-V, it's not permitted to place a breakpoint on any but the
5340 first subinstruction of a VLIW instruction. When a breakpoint is
5341 set, GDB will adjust the breakpoint address to the beginning of
5342 the VLIW instruction. Thus, we need to make the corresponding
5343 adjustment here when computing the stop address. */
5345 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5347 ecs
->stop_func_start
5348 = gdbarch_adjust_breakpoint_address (gdbarch
,
5349 ecs
->stop_func_start
);
5352 if (ecs
->stop_func_start
== stop_pc
)
5354 /* We are already there: stop now. */
5355 ecs
->event_thread
->control
.stop_step
= 1;
5356 print_end_stepping_range_reason ();
5357 stop_stepping (ecs
);
5362 /* Put the step-breakpoint there and go until there. */
5363 init_sal (&sr_sal
); /* initialize to zeroes */
5364 sr_sal
.pc
= ecs
->stop_func_start
;
5365 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5366 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5368 /* Do not specify what the fp should be when we stop since on
5369 some machines the prologue is where the new fp value is
5371 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5373 /* And make sure stepping stops right away then. */
5374 ecs
->event_thread
->control
.step_range_end
5375 = ecs
->event_thread
->control
.step_range_start
;
5380 /* Inferior has stepped backward into a subroutine call with source
5381 code that we should not step over. Do step to the beginning of the
5382 last line of code in it. */
5385 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5386 struct execution_control_state
*ecs
)
5389 struct symtab_and_line stop_func_sal
;
5391 fill_in_stop_func (gdbarch
, ecs
);
5393 s
= find_pc_symtab (stop_pc
);
5394 if (s
&& s
->language
!= language_asm
)
5395 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5396 ecs
->stop_func_start
);
5398 stop_func_sal
= find_pc_line (stop_pc
, 0);
5400 /* OK, we're just going to keep stepping here. */
5401 if (stop_func_sal
.pc
== stop_pc
)
5403 /* We're there already. Just stop stepping now. */
5404 ecs
->event_thread
->control
.stop_step
= 1;
5405 print_end_stepping_range_reason ();
5406 stop_stepping (ecs
);
5410 /* Else just reset the step range and keep going.
5411 No step-resume breakpoint, they don't work for
5412 epilogues, which can have multiple entry paths. */
5413 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5414 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5420 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5421 This is used to both functions and to skip over code. */
5424 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5425 struct symtab_and_line sr_sal
,
5426 struct frame_id sr_id
,
5427 enum bptype sr_type
)
5429 /* There should never be more than one step-resume or longjmp-resume
5430 breakpoint per thread, so we should never be setting a new
5431 step_resume_breakpoint when one is already active. */
5432 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5433 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5436 fprintf_unfiltered (gdb_stdlog
,
5437 "infrun: inserting step-resume breakpoint at %s\n",
5438 paddress (gdbarch
, sr_sal
.pc
));
5440 inferior_thread ()->control
.step_resume_breakpoint
5441 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5445 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5446 struct symtab_and_line sr_sal
,
5447 struct frame_id sr_id
)
5449 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5454 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5455 This is used to skip a potential signal handler.
5457 This is called with the interrupted function's frame. The signal
5458 handler, when it returns, will resume the interrupted function at
5462 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5464 struct symtab_and_line sr_sal
;
5465 struct gdbarch
*gdbarch
;
5467 gdb_assert (return_frame
!= NULL
);
5468 init_sal (&sr_sal
); /* initialize to zeros */
5470 gdbarch
= get_frame_arch (return_frame
);
5471 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5472 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5473 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5475 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5476 get_stack_frame_id (return_frame
),
5480 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5481 is used to skip a function after stepping into it (for "next" or if
5482 the called function has no debugging information).
5484 The current function has almost always been reached by single
5485 stepping a call or return instruction. NEXT_FRAME belongs to the
5486 current function, and the breakpoint will be set at the caller's
5489 This is a separate function rather than reusing
5490 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5491 get_prev_frame, which may stop prematurely (see the implementation
5492 of frame_unwind_caller_id for an example). */
5495 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5497 struct symtab_and_line sr_sal
;
5498 struct gdbarch
*gdbarch
;
5500 /* We shouldn't have gotten here if we don't know where the call site
5502 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5504 init_sal (&sr_sal
); /* initialize to zeros */
5506 gdbarch
= frame_unwind_caller_arch (next_frame
);
5507 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5508 frame_unwind_caller_pc (next_frame
));
5509 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5510 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5512 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5513 frame_unwind_caller_id (next_frame
));
5516 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5517 new breakpoint at the target of a jmp_buf. The handling of
5518 longjmp-resume uses the same mechanisms used for handling
5519 "step-resume" breakpoints. */
5522 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5524 /* There should never be more than one longjmp-resume breakpoint per
5525 thread, so we should never be setting a new
5526 longjmp_resume_breakpoint when one is already active. */
5527 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5530 fprintf_unfiltered (gdb_stdlog
,
5531 "infrun: inserting longjmp-resume breakpoint at %s\n",
5532 paddress (gdbarch
, pc
));
5534 inferior_thread ()->control
.exception_resume_breakpoint
=
5535 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5538 /* Insert an exception resume breakpoint. TP is the thread throwing
5539 the exception. The block B is the block of the unwinder debug hook
5540 function. FRAME is the frame corresponding to the call to this
5541 function. SYM is the symbol of the function argument holding the
5542 target PC of the exception. */
5545 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5547 struct frame_info
*frame
,
5550 volatile struct gdb_exception e
;
5552 /* We want to ignore errors here. */
5553 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5555 struct symbol
*vsym
;
5556 struct value
*value
;
5558 struct breakpoint
*bp
;
5560 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5561 value
= read_var_value (vsym
, frame
);
5562 /* If the value was optimized out, revert to the old behavior. */
5563 if (! value_optimized_out (value
))
5565 handler
= value_as_address (value
);
5568 fprintf_unfiltered (gdb_stdlog
,
5569 "infrun: exception resume at %lx\n",
5570 (unsigned long) handler
);
5572 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5573 handler
, bp_exception_resume
);
5575 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5578 bp
->thread
= tp
->num
;
5579 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5584 /* A helper for check_exception_resume that sets an
5585 exception-breakpoint based on a SystemTap probe. */
5588 insert_exception_resume_from_probe (struct thread_info
*tp
,
5589 const struct probe
*probe
,
5590 struct frame_info
*frame
)
5592 struct value
*arg_value
;
5594 struct breakpoint
*bp
;
5596 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5600 handler
= value_as_address (arg_value
);
5603 fprintf_unfiltered (gdb_stdlog
,
5604 "infrun: exception resume at %s\n",
5605 paddress (get_objfile_arch (probe
->objfile
),
5608 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5609 handler
, bp_exception_resume
);
5610 bp
->thread
= tp
->num
;
5611 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5614 /* This is called when an exception has been intercepted. Check to
5615 see whether the exception's destination is of interest, and if so,
5616 set an exception resume breakpoint there. */
5619 check_exception_resume (struct execution_control_state
*ecs
,
5620 struct frame_info
*frame
)
5622 volatile struct gdb_exception e
;
5623 const struct probe
*probe
;
5624 struct symbol
*func
;
5626 /* First see if this exception unwinding breakpoint was set via a
5627 SystemTap probe point. If so, the probe has two arguments: the
5628 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5629 set a breakpoint there. */
5630 probe
= find_probe_by_pc (get_frame_pc (frame
));
5633 insert_exception_resume_from_probe (ecs
->event_thread
, probe
, frame
);
5637 func
= get_frame_function (frame
);
5641 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5644 struct block_iterator iter
;
5648 /* The exception breakpoint is a thread-specific breakpoint on
5649 the unwinder's debug hook, declared as:
5651 void _Unwind_DebugHook (void *cfa, void *handler);
5653 The CFA argument indicates the frame to which control is
5654 about to be transferred. HANDLER is the destination PC.
5656 We ignore the CFA and set a temporary breakpoint at HANDLER.
5657 This is not extremely efficient but it avoids issues in gdb
5658 with computing the DWARF CFA, and it also works even in weird
5659 cases such as throwing an exception from inside a signal
5662 b
= SYMBOL_BLOCK_VALUE (func
);
5663 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5665 if (!SYMBOL_IS_ARGUMENT (sym
))
5672 insert_exception_resume_breakpoint (ecs
->event_thread
,
5681 stop_stepping (struct execution_control_state
*ecs
)
5684 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
5686 /* Let callers know we don't want to wait for the inferior anymore. */
5687 ecs
->wait_some_more
= 0;
5690 /* This function handles various cases where we need to continue
5691 waiting for the inferior. */
5692 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5695 keep_going (struct execution_control_state
*ecs
)
5697 /* Make sure normal_stop is called if we get a QUIT handled before
5699 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5701 /* Save the pc before execution, to compare with pc after stop. */
5702 ecs
->event_thread
->prev_pc
5703 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5705 /* If we did not do break;, it means we should keep running the
5706 inferior and not return to debugger. */
5708 if (ecs
->event_thread
->control
.trap_expected
5709 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5711 /* We took a signal (which we are supposed to pass through to
5712 the inferior, else we'd not get here) and we haven't yet
5713 gotten our trap. Simply continue. */
5715 discard_cleanups (old_cleanups
);
5716 resume (currently_stepping (ecs
->event_thread
),
5717 ecs
->event_thread
->suspend
.stop_signal
);
5721 /* Either the trap was not expected, but we are continuing
5722 anyway (the user asked that this signal be passed to the
5725 The signal was SIGTRAP, e.g. it was our signal, but we
5726 decided we should resume from it.
5728 We're going to run this baby now!
5730 Note that insert_breakpoints won't try to re-insert
5731 already inserted breakpoints. Therefore, we don't
5732 care if breakpoints were already inserted, or not. */
5734 if (ecs
->event_thread
->stepping_over_breakpoint
)
5736 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
5738 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
5739 /* Since we can't do a displaced step, we have to remove
5740 the breakpoint while we step it. To keep things
5741 simple, we remove them all. */
5742 remove_breakpoints ();
5746 volatile struct gdb_exception e
;
5748 /* Stop stepping when inserting breakpoints
5750 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5752 insert_breakpoints ();
5756 exception_print (gdb_stderr
, e
);
5757 stop_stepping (ecs
);
5762 ecs
->event_thread
->control
.trap_expected
5763 = ecs
->event_thread
->stepping_over_breakpoint
;
5765 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5766 specifies that such a signal should be delivered to the
5769 Typically, this would occure when a user is debugging a
5770 target monitor on a simulator: the target monitor sets a
5771 breakpoint; the simulator encounters this break-point and
5772 halts the simulation handing control to GDB; GDB, noteing
5773 that the break-point isn't valid, returns control back to the
5774 simulator; the simulator then delivers the hardware
5775 equivalent of a SIGNAL_TRAP to the program being debugged. */
5777 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
5778 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5779 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5781 discard_cleanups (old_cleanups
);
5782 resume (currently_stepping (ecs
->event_thread
),
5783 ecs
->event_thread
->suspend
.stop_signal
);
5786 prepare_to_wait (ecs
);
5789 /* This function normally comes after a resume, before
5790 handle_inferior_event exits. It takes care of any last bits of
5791 housekeeping, and sets the all-important wait_some_more flag. */
5794 prepare_to_wait (struct execution_control_state
*ecs
)
5797 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
5799 /* This is the old end of the while loop. Let everybody know we
5800 want to wait for the inferior some more and get called again
5802 ecs
->wait_some_more
= 1;
5805 /* Several print_*_reason functions to print why the inferior has stopped.
5806 We always print something when the inferior exits, or receives a signal.
5807 The rest of the cases are dealt with later on in normal_stop and
5808 print_it_typical. Ideally there should be a call to one of these
5809 print_*_reason functions functions from handle_inferior_event each time
5810 stop_stepping is called. */
5812 /* Print why the inferior has stopped.
5813 We are done with a step/next/si/ni command, print why the inferior has
5814 stopped. For now print nothing. Print a message only if not in the middle
5815 of doing a "step n" operation for n > 1. */
5818 print_end_stepping_range_reason (void)
5820 if ((!inferior_thread ()->step_multi
5821 || !inferior_thread ()->control
.stop_step
)
5822 && ui_out_is_mi_like_p (current_uiout
))
5823 ui_out_field_string (current_uiout
, "reason",
5824 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
5827 /* The inferior was terminated by a signal, print why it stopped. */
5830 print_signal_exited_reason (enum gdb_signal siggnal
)
5832 struct ui_out
*uiout
= current_uiout
;
5834 annotate_signalled ();
5835 if (ui_out_is_mi_like_p (uiout
))
5837 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
5838 ui_out_text (uiout
, "\nProgram terminated with signal ");
5839 annotate_signal_name ();
5840 ui_out_field_string (uiout
, "signal-name",
5841 gdb_signal_to_name (siggnal
));
5842 annotate_signal_name_end ();
5843 ui_out_text (uiout
, ", ");
5844 annotate_signal_string ();
5845 ui_out_field_string (uiout
, "signal-meaning",
5846 gdb_signal_to_string (siggnal
));
5847 annotate_signal_string_end ();
5848 ui_out_text (uiout
, ".\n");
5849 ui_out_text (uiout
, "The program no longer exists.\n");
5852 /* The inferior program is finished, print why it stopped. */
5855 print_exited_reason (int exitstatus
)
5857 struct inferior
*inf
= current_inferior ();
5858 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
5859 struct ui_out
*uiout
= current_uiout
;
5861 annotate_exited (exitstatus
);
5864 if (ui_out_is_mi_like_p (uiout
))
5865 ui_out_field_string (uiout
, "reason",
5866 async_reason_lookup (EXEC_ASYNC_EXITED
));
5867 ui_out_text (uiout
, "[Inferior ");
5868 ui_out_text (uiout
, plongest (inf
->num
));
5869 ui_out_text (uiout
, " (");
5870 ui_out_text (uiout
, pidstr
);
5871 ui_out_text (uiout
, ") exited with code ");
5872 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
5873 ui_out_text (uiout
, "]\n");
5877 if (ui_out_is_mi_like_p (uiout
))
5879 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
5880 ui_out_text (uiout
, "[Inferior ");
5881 ui_out_text (uiout
, plongest (inf
->num
));
5882 ui_out_text (uiout
, " (");
5883 ui_out_text (uiout
, pidstr
);
5884 ui_out_text (uiout
, ") exited normally]\n");
5886 /* Support the --return-child-result option. */
5887 return_child_result_value
= exitstatus
;
5890 /* Signal received, print why the inferior has stopped. The signal table
5891 tells us to print about it. */
5894 print_signal_received_reason (enum gdb_signal siggnal
)
5896 struct ui_out
*uiout
= current_uiout
;
5900 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
5902 struct thread_info
*t
= inferior_thread ();
5904 ui_out_text (uiout
, "\n[");
5905 ui_out_field_string (uiout
, "thread-name",
5906 target_pid_to_str (t
->ptid
));
5907 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
5908 ui_out_text (uiout
, " stopped");
5912 ui_out_text (uiout
, "\nProgram received signal ");
5913 annotate_signal_name ();
5914 if (ui_out_is_mi_like_p (uiout
))
5916 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
5917 ui_out_field_string (uiout
, "signal-name",
5918 gdb_signal_to_name (siggnal
));
5919 annotate_signal_name_end ();
5920 ui_out_text (uiout
, ", ");
5921 annotate_signal_string ();
5922 ui_out_field_string (uiout
, "signal-meaning",
5923 gdb_signal_to_string (siggnal
));
5924 annotate_signal_string_end ();
5926 ui_out_text (uiout
, ".\n");
5929 /* Reverse execution: target ran out of history info, print why the inferior
5933 print_no_history_reason (void)
5935 ui_out_text (current_uiout
, "\nNo more reverse-execution history.\n");
5938 /* Here to return control to GDB when the inferior stops for real.
5939 Print appropriate messages, remove breakpoints, give terminal our modes.
5941 STOP_PRINT_FRAME nonzero means print the executing frame
5942 (pc, function, args, file, line number and line text).
5943 BREAKPOINTS_FAILED nonzero means stop was due to error
5944 attempting to insert breakpoints. */
5949 struct target_waitstatus last
;
5951 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
5953 get_last_target_status (&last_ptid
, &last
);
5955 /* If an exception is thrown from this point on, make sure to
5956 propagate GDB's knowledge of the executing state to the
5957 frontend/user running state. A QUIT is an easy exception to see
5958 here, so do this before any filtered output. */
5960 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
5961 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
5962 && last
.kind
!= TARGET_WAITKIND_EXITED
5963 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5964 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
5966 /* In non-stop mode, we don't want GDB to switch threads behind the
5967 user's back, to avoid races where the user is typing a command to
5968 apply to thread x, but GDB switches to thread y before the user
5969 finishes entering the command. */
5971 /* As with the notification of thread events, we want to delay
5972 notifying the user that we've switched thread context until
5973 the inferior actually stops.
5975 There's no point in saying anything if the inferior has exited.
5976 Note that SIGNALLED here means "exited with a signal", not
5977 "received a signal". */
5979 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
5980 && target_has_execution
5981 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
5982 && last
.kind
!= TARGET_WAITKIND_EXITED
5983 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
5985 target_terminal_ours_for_output ();
5986 printf_filtered (_("[Switching to %s]\n"),
5987 target_pid_to_str (inferior_ptid
));
5988 annotate_thread_changed ();
5989 previous_inferior_ptid
= inferior_ptid
;
5992 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
5994 gdb_assert (sync_execution
|| !target_can_async_p ());
5996 target_terminal_ours_for_output ();
5997 printf_filtered (_("No unwaited-for children left.\n"));
6000 if (!breakpoints_always_inserted_mode () && target_has_execution
)
6002 if (remove_breakpoints ())
6004 target_terminal_ours_for_output ();
6005 printf_filtered (_("Cannot remove breakpoints because "
6006 "program is no longer writable.\nFurther "
6007 "execution is probably impossible.\n"));
6011 /* If an auto-display called a function and that got a signal,
6012 delete that auto-display to avoid an infinite recursion. */
6014 if (stopped_by_random_signal
)
6015 disable_current_display ();
6017 /* Don't print a message if in the middle of doing a "step n"
6018 operation for n > 1 */
6019 if (target_has_execution
6020 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6021 && last
.kind
!= TARGET_WAITKIND_EXITED
6022 && inferior_thread ()->step_multi
6023 && inferior_thread ()->control
.stop_step
)
6026 target_terminal_ours ();
6027 async_enable_stdin ();
6029 /* Set the current source location. This will also happen if we
6030 display the frame below, but the current SAL will be incorrect
6031 during a user hook-stop function. */
6032 if (has_stack_frames () && !stop_stack_dummy
)
6033 set_current_sal_from_frame (get_current_frame (), 1);
6035 /* Let the user/frontend see the threads as stopped. */
6036 do_cleanups (old_chain
);
6038 /* Look up the hook_stop and run it (CLI internally handles problem
6039 of stop_command's pre-hook not existing). */
6041 catch_errors (hook_stop_stub
, stop_command
,
6042 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6044 if (!has_stack_frames ())
6047 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6048 || last
.kind
== TARGET_WAITKIND_EXITED
)
6051 /* Select innermost stack frame - i.e., current frame is frame 0,
6052 and current location is based on that.
6053 Don't do this on return from a stack dummy routine,
6054 or if the program has exited. */
6056 if (!stop_stack_dummy
)
6058 select_frame (get_current_frame ());
6060 /* Print current location without a level number, if
6061 we have changed functions or hit a breakpoint.
6062 Print source line if we have one.
6063 bpstat_print() contains the logic deciding in detail
6064 what to print, based on the event(s) that just occurred. */
6066 /* If --batch-silent is enabled then there's no need to print the current
6067 source location, and to try risks causing an error message about
6068 missing source files. */
6069 if (stop_print_frame
&& !batch_silent
)
6073 int do_frame_printing
= 1;
6074 struct thread_info
*tp
= inferior_thread ();
6076 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, last
.kind
);
6080 /* FIXME: cagney/2002-12-01: Given that a frame ID does
6081 (or should) carry around the function and does (or
6082 should) use that when doing a frame comparison. */
6083 if (tp
->control
.stop_step
6084 && frame_id_eq (tp
->control
.step_frame_id
,
6085 get_frame_id (get_current_frame ()))
6086 && step_start_function
== find_pc_function (stop_pc
))
6087 source_flag
= SRC_LINE
; /* Finished step, just
6088 print source line. */
6090 source_flag
= SRC_AND_LOC
; /* Print location and
6093 case PRINT_SRC_AND_LOC
:
6094 source_flag
= SRC_AND_LOC
; /* Print location and
6097 case PRINT_SRC_ONLY
:
6098 source_flag
= SRC_LINE
;
6101 source_flag
= SRC_LINE
; /* something bogus */
6102 do_frame_printing
= 0;
6105 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6108 /* The behavior of this routine with respect to the source
6110 SRC_LINE: Print only source line
6111 LOCATION: Print only location
6112 SRC_AND_LOC: Print location and source line. */
6113 if (do_frame_printing
)
6114 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
6116 /* Display the auto-display expressions. */
6121 /* Save the function value return registers, if we care.
6122 We might be about to restore their previous contents. */
6123 if (inferior_thread ()->control
.proceed_to_finish
6124 && execution_direction
!= EXEC_REVERSE
)
6126 /* This should not be necessary. */
6128 regcache_xfree (stop_registers
);
6130 /* NB: The copy goes through to the target picking up the value of
6131 all the registers. */
6132 stop_registers
= regcache_dup (get_current_regcache ());
6135 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6137 /* Pop the empty frame that contains the stack dummy.
6138 This also restores inferior state prior to the call
6139 (struct infcall_suspend_state). */
6140 struct frame_info
*frame
= get_current_frame ();
6142 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6144 /* frame_pop() calls reinit_frame_cache as the last thing it
6145 does which means there's currently no selected frame. We
6146 don't need to re-establish a selected frame if the dummy call
6147 returns normally, that will be done by
6148 restore_infcall_control_state. However, we do have to handle
6149 the case where the dummy call is returning after being
6150 stopped (e.g. the dummy call previously hit a breakpoint).
6151 We can't know which case we have so just always re-establish
6152 a selected frame here. */
6153 select_frame (get_current_frame ());
6157 annotate_stopped ();
6159 /* Suppress the stop observer if we're in the middle of:
6161 - a step n (n > 1), as there still more steps to be done.
6163 - a "finish" command, as the observer will be called in
6164 finish_command_continuation, so it can include the inferior
6165 function's return value.
6167 - calling an inferior function, as we pretend we inferior didn't
6168 run at all. The return value of the call is handled by the
6169 expression evaluator, through call_function_by_hand. */
6171 if (!target_has_execution
6172 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6173 || last
.kind
== TARGET_WAITKIND_EXITED
6174 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6175 || (!(inferior_thread ()->step_multi
6176 && inferior_thread ()->control
.stop_step
)
6177 && !(inferior_thread ()->control
.stop_bpstat
6178 && inferior_thread ()->control
.proceed_to_finish
)
6179 && !inferior_thread ()->control
.in_infcall
))
6181 if (!ptid_equal (inferior_ptid
, null_ptid
))
6182 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6185 observer_notify_normal_stop (NULL
, stop_print_frame
);
6188 if (target_has_execution
)
6190 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6191 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6192 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6193 Delete any breakpoint that is to be deleted at the next stop. */
6194 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6197 /* Try to get rid of automatically added inferiors that are no
6198 longer needed. Keeping those around slows down things linearly.
6199 Note that this never removes the current inferior. */
6204 hook_stop_stub (void *cmd
)
6206 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6211 signal_stop_state (int signo
)
6213 return signal_stop
[signo
];
6217 signal_print_state (int signo
)
6219 return signal_print
[signo
];
6223 signal_pass_state (int signo
)
6225 return signal_program
[signo
];
6229 signal_cache_update (int signo
)
6233 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6234 signal_cache_update (signo
);
6239 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6240 && signal_print
[signo
] == 0
6241 && signal_program
[signo
] == 1
6242 && signal_catch
[signo
] == 0);
6246 signal_stop_update (int signo
, int state
)
6248 int ret
= signal_stop
[signo
];
6250 signal_stop
[signo
] = state
;
6251 signal_cache_update (signo
);
6256 signal_print_update (int signo
, int state
)
6258 int ret
= signal_print
[signo
];
6260 signal_print
[signo
] = state
;
6261 signal_cache_update (signo
);
6266 signal_pass_update (int signo
, int state
)
6268 int ret
= signal_program
[signo
];
6270 signal_program
[signo
] = state
;
6271 signal_cache_update (signo
);
6275 /* Update the global 'signal_catch' from INFO and notify the
6279 signal_catch_update (const unsigned int *info
)
6283 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6284 signal_catch
[i
] = info
[i
] > 0;
6285 signal_cache_update (-1);
6286 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6290 sig_print_header (void)
6292 printf_filtered (_("Signal Stop\tPrint\tPass "
6293 "to program\tDescription\n"));
6297 sig_print_info (enum gdb_signal oursig
)
6299 const char *name
= gdb_signal_to_name (oursig
);
6300 int name_padding
= 13 - strlen (name
);
6302 if (name_padding
<= 0)
6305 printf_filtered ("%s", name
);
6306 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6307 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6308 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6309 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6310 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6313 /* Specify how various signals in the inferior should be handled. */
6316 handle_command (char *args
, int from_tty
)
6319 int digits
, wordlen
;
6320 int sigfirst
, signum
, siglast
;
6321 enum gdb_signal oursig
;
6324 unsigned char *sigs
;
6325 struct cleanup
*old_chain
;
6329 error_no_arg (_("signal to handle"));
6332 /* Allocate and zero an array of flags for which signals to handle. */
6334 nsigs
= (int) GDB_SIGNAL_LAST
;
6335 sigs
= (unsigned char *) alloca (nsigs
);
6336 memset (sigs
, 0, nsigs
);
6338 /* Break the command line up into args. */
6340 argv
= gdb_buildargv (args
);
6341 old_chain
= make_cleanup_freeargv (argv
);
6343 /* Walk through the args, looking for signal oursigs, signal names, and
6344 actions. Signal numbers and signal names may be interspersed with
6345 actions, with the actions being performed for all signals cumulatively
6346 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6348 while (*argv
!= NULL
)
6350 wordlen
= strlen (*argv
);
6351 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6355 sigfirst
= siglast
= -1;
6357 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6359 /* Apply action to all signals except those used by the
6360 debugger. Silently skip those. */
6363 siglast
= nsigs
- 1;
6365 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6367 SET_SIGS (nsigs
, sigs
, signal_stop
);
6368 SET_SIGS (nsigs
, sigs
, signal_print
);
6370 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6372 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6374 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6376 SET_SIGS (nsigs
, sigs
, signal_print
);
6378 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6380 SET_SIGS (nsigs
, sigs
, signal_program
);
6382 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6384 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6386 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6388 SET_SIGS (nsigs
, sigs
, signal_program
);
6390 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6392 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6393 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6395 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6397 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6399 else if (digits
> 0)
6401 /* It is numeric. The numeric signal refers to our own
6402 internal signal numbering from target.h, not to host/target
6403 signal number. This is a feature; users really should be
6404 using symbolic names anyway, and the common ones like
6405 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6407 sigfirst
= siglast
= (int)
6408 gdb_signal_from_command (atoi (*argv
));
6409 if ((*argv
)[digits
] == '-')
6412 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6414 if (sigfirst
> siglast
)
6416 /* Bet he didn't figure we'd think of this case... */
6424 oursig
= gdb_signal_from_name (*argv
);
6425 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6427 sigfirst
= siglast
= (int) oursig
;
6431 /* Not a number and not a recognized flag word => complain. */
6432 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6436 /* If any signal numbers or symbol names were found, set flags for
6437 which signals to apply actions to. */
6439 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6441 switch ((enum gdb_signal
) signum
)
6443 case GDB_SIGNAL_TRAP
:
6444 case GDB_SIGNAL_INT
:
6445 if (!allsigs
&& !sigs
[signum
])
6447 if (query (_("%s is used by the debugger.\n\
6448 Are you sure you want to change it? "),
6449 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6455 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6456 gdb_flush (gdb_stdout
);
6461 case GDB_SIGNAL_DEFAULT
:
6462 case GDB_SIGNAL_UNKNOWN
:
6463 /* Make sure that "all" doesn't print these. */
6474 for (signum
= 0; signum
< nsigs
; signum
++)
6477 signal_cache_update (-1);
6478 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6479 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6483 /* Show the results. */
6484 sig_print_header ();
6485 for (; signum
< nsigs
; signum
++)
6487 sig_print_info (signum
);
6493 do_cleanups (old_chain
);
6496 /* Complete the "handle" command. */
6498 static VEC (char_ptr
) *
6499 handle_completer (struct cmd_list_element
*ignore
,
6500 const char *text
, const char *word
)
6502 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6503 static const char * const keywords
[] =
6517 vec_signals
= signal_completer (ignore
, text
, word
);
6518 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6520 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6521 VEC_free (char_ptr
, vec_signals
);
6522 VEC_free (char_ptr
, vec_keywords
);
6527 xdb_handle_command (char *args
, int from_tty
)
6530 struct cleanup
*old_chain
;
6533 error_no_arg (_("xdb command"));
6535 /* Break the command line up into args. */
6537 argv
= gdb_buildargv (args
);
6538 old_chain
= make_cleanup_freeargv (argv
);
6539 if (argv
[1] != (char *) NULL
)
6544 bufLen
= strlen (argv
[0]) + 20;
6545 argBuf
= (char *) xmalloc (bufLen
);
6549 enum gdb_signal oursig
;
6551 oursig
= gdb_signal_from_name (argv
[0]);
6552 memset (argBuf
, 0, bufLen
);
6553 if (strcmp (argv
[1], "Q") == 0)
6554 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6557 if (strcmp (argv
[1], "s") == 0)
6559 if (!signal_stop
[oursig
])
6560 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6562 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6564 else if (strcmp (argv
[1], "i") == 0)
6566 if (!signal_program
[oursig
])
6567 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6569 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6571 else if (strcmp (argv
[1], "r") == 0)
6573 if (!signal_print
[oursig
])
6574 sprintf (argBuf
, "%s %s", argv
[0], "print");
6576 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6582 handle_command (argBuf
, from_tty
);
6584 printf_filtered (_("Invalid signal handling flag.\n"));
6589 do_cleanups (old_chain
);
6593 gdb_signal_from_command (int num
)
6595 if (num
>= 1 && num
<= 15)
6596 return (enum gdb_signal
) num
;
6597 error (_("Only signals 1-15 are valid as numeric signals.\n\
6598 Use \"info signals\" for a list of symbolic signals."));
6601 /* Print current contents of the tables set by the handle command.
6602 It is possible we should just be printing signals actually used
6603 by the current target (but for things to work right when switching
6604 targets, all signals should be in the signal tables). */
6607 signals_info (char *signum_exp
, int from_tty
)
6609 enum gdb_signal oursig
;
6611 sig_print_header ();
6615 /* First see if this is a symbol name. */
6616 oursig
= gdb_signal_from_name (signum_exp
);
6617 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6619 /* No, try numeric. */
6621 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6623 sig_print_info (oursig
);
6627 printf_filtered ("\n");
6628 /* These ugly casts brought to you by the native VAX compiler. */
6629 for (oursig
= GDB_SIGNAL_FIRST
;
6630 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6631 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6635 if (oursig
!= GDB_SIGNAL_UNKNOWN
6636 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6637 sig_print_info (oursig
);
6640 printf_filtered (_("\nUse the \"handle\" command "
6641 "to change these tables.\n"));
6644 /* Check if it makes sense to read $_siginfo from the current thread
6645 at this point. If not, throw an error. */
6648 validate_siginfo_access (void)
6650 /* No current inferior, no siginfo. */
6651 if (ptid_equal (inferior_ptid
, null_ptid
))
6652 error (_("No thread selected."));
6654 /* Don't try to read from a dead thread. */
6655 if (is_exited (inferior_ptid
))
6656 error (_("The current thread has terminated"));
6658 /* ... or from a spinning thread. */
6659 if (is_running (inferior_ptid
))
6660 error (_("Selected thread is running."));
6663 /* The $_siginfo convenience variable is a bit special. We don't know
6664 for sure the type of the value until we actually have a chance to
6665 fetch the data. The type can change depending on gdbarch, so it is
6666 also dependent on which thread you have selected.
6668 1. making $_siginfo be an internalvar that creates a new value on
6671 2. making the value of $_siginfo be an lval_computed value. */
6673 /* This function implements the lval_computed support for reading a
6677 siginfo_value_read (struct value
*v
)
6679 LONGEST transferred
;
6681 validate_siginfo_access ();
6684 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
6686 value_contents_all_raw (v
),
6688 TYPE_LENGTH (value_type (v
)));
6690 if (transferred
!= TYPE_LENGTH (value_type (v
)))
6691 error (_("Unable to read siginfo"));
6694 /* This function implements the lval_computed support for writing a
6698 siginfo_value_write (struct value
*v
, struct value
*fromval
)
6700 LONGEST transferred
;
6702 validate_siginfo_access ();
6704 transferred
= target_write (¤t_target
,
6705 TARGET_OBJECT_SIGNAL_INFO
,
6707 value_contents_all_raw (fromval
),
6709 TYPE_LENGTH (value_type (fromval
)));
6711 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
6712 error (_("Unable to write siginfo"));
6715 static const struct lval_funcs siginfo_value_funcs
=
6721 /* Return a new value with the correct type for the siginfo object of
6722 the current thread using architecture GDBARCH. Return a void value
6723 if there's no object available. */
6725 static struct value
*
6726 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
6729 if (target_has_stack
6730 && !ptid_equal (inferior_ptid
, null_ptid
)
6731 && gdbarch_get_siginfo_type_p (gdbarch
))
6733 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6735 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
6738 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
6742 /* infcall_suspend_state contains state about the program itself like its
6743 registers and any signal it received when it last stopped.
6744 This state must be restored regardless of how the inferior function call
6745 ends (either successfully, or after it hits a breakpoint or signal)
6746 if the program is to properly continue where it left off. */
6748 struct infcall_suspend_state
6750 struct thread_suspend_state thread_suspend
;
6751 #if 0 /* Currently unused and empty structures are not valid C. */
6752 struct inferior_suspend_state inferior_suspend
;
6757 struct regcache
*registers
;
6759 /* Format of SIGINFO_DATA or NULL if it is not present. */
6760 struct gdbarch
*siginfo_gdbarch
;
6762 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6763 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6764 content would be invalid. */
6765 gdb_byte
*siginfo_data
;
6768 struct infcall_suspend_state
*
6769 save_infcall_suspend_state (void)
6771 struct infcall_suspend_state
*inf_state
;
6772 struct thread_info
*tp
= inferior_thread ();
6774 struct inferior
*inf
= current_inferior ();
6776 struct regcache
*regcache
= get_current_regcache ();
6777 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6778 gdb_byte
*siginfo_data
= NULL
;
6780 if (gdbarch_get_siginfo_type_p (gdbarch
))
6782 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6783 size_t len
= TYPE_LENGTH (type
);
6784 struct cleanup
*back_to
;
6786 siginfo_data
= xmalloc (len
);
6787 back_to
= make_cleanup (xfree
, siginfo_data
);
6789 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6790 siginfo_data
, 0, len
) == len
)
6791 discard_cleanups (back_to
);
6794 /* Errors ignored. */
6795 do_cleanups (back_to
);
6796 siginfo_data
= NULL
;
6800 inf_state
= XZALLOC (struct infcall_suspend_state
);
6804 inf_state
->siginfo_gdbarch
= gdbarch
;
6805 inf_state
->siginfo_data
= siginfo_data
;
6808 inf_state
->thread_suspend
= tp
->suspend
;
6809 #if 0 /* Currently unused and empty structures are not valid C. */
6810 inf_state
->inferior_suspend
= inf
->suspend
;
6813 /* run_inferior_call will not use the signal due to its `proceed' call with
6814 GDB_SIGNAL_0 anyway. */
6815 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6817 inf_state
->stop_pc
= stop_pc
;
6819 inf_state
->registers
= regcache_dup (regcache
);
6824 /* Restore inferior session state to INF_STATE. */
6827 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6829 struct thread_info
*tp
= inferior_thread ();
6831 struct inferior
*inf
= current_inferior ();
6833 struct regcache
*regcache
= get_current_regcache ();
6834 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
6836 tp
->suspend
= inf_state
->thread_suspend
;
6837 #if 0 /* Currently unused and empty structures are not valid C. */
6838 inf
->suspend
= inf_state
->inferior_suspend
;
6841 stop_pc
= inf_state
->stop_pc
;
6843 if (inf_state
->siginfo_gdbarch
== gdbarch
)
6845 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
6847 /* Errors ignored. */
6848 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
6849 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
6852 /* The inferior can be gone if the user types "print exit(0)"
6853 (and perhaps other times). */
6854 if (target_has_execution
)
6855 /* NB: The register write goes through to the target. */
6856 regcache_cpy (regcache
, inf_state
->registers
);
6858 discard_infcall_suspend_state (inf_state
);
6862 do_restore_infcall_suspend_state_cleanup (void *state
)
6864 restore_infcall_suspend_state (state
);
6868 make_cleanup_restore_infcall_suspend_state
6869 (struct infcall_suspend_state
*inf_state
)
6871 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
6875 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
6877 regcache_xfree (inf_state
->registers
);
6878 xfree (inf_state
->siginfo_data
);
6883 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
6885 return inf_state
->registers
;
6888 /* infcall_control_state contains state regarding gdb's control of the
6889 inferior itself like stepping control. It also contains session state like
6890 the user's currently selected frame. */
6892 struct infcall_control_state
6894 struct thread_control_state thread_control
;
6895 struct inferior_control_state inferior_control
;
6898 enum stop_stack_kind stop_stack_dummy
;
6899 int stopped_by_random_signal
;
6900 int stop_after_trap
;
6902 /* ID if the selected frame when the inferior function call was made. */
6903 struct frame_id selected_frame_id
;
6906 /* Save all of the information associated with the inferior<==>gdb
6909 struct infcall_control_state
*
6910 save_infcall_control_state (void)
6912 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
6913 struct thread_info
*tp
= inferior_thread ();
6914 struct inferior
*inf
= current_inferior ();
6916 inf_status
->thread_control
= tp
->control
;
6917 inf_status
->inferior_control
= inf
->control
;
6919 tp
->control
.step_resume_breakpoint
= NULL
;
6920 tp
->control
.exception_resume_breakpoint
= NULL
;
6922 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6923 chain. If caller's caller is walking the chain, they'll be happier if we
6924 hand them back the original chain when restore_infcall_control_state is
6926 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
6929 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
6930 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
6931 inf_status
->stop_after_trap
= stop_after_trap
;
6933 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
6939 restore_selected_frame (void *args
)
6941 struct frame_id
*fid
= (struct frame_id
*) args
;
6942 struct frame_info
*frame
;
6944 frame
= frame_find_by_id (*fid
);
6946 /* If inf_status->selected_frame_id is NULL, there was no previously
6950 warning (_("Unable to restore previously selected frame."));
6954 select_frame (frame
);
6959 /* Restore inferior session state to INF_STATUS. */
6962 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
6964 struct thread_info
*tp
= inferior_thread ();
6965 struct inferior
*inf
= current_inferior ();
6967 if (tp
->control
.step_resume_breakpoint
)
6968 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
6970 if (tp
->control
.exception_resume_breakpoint
)
6971 tp
->control
.exception_resume_breakpoint
->disposition
6972 = disp_del_at_next_stop
;
6974 /* Handle the bpstat_copy of the chain. */
6975 bpstat_clear (&tp
->control
.stop_bpstat
);
6977 tp
->control
= inf_status
->thread_control
;
6978 inf
->control
= inf_status
->inferior_control
;
6981 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
6982 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
6983 stop_after_trap
= inf_status
->stop_after_trap
;
6985 if (target_has_stack
)
6987 /* The point of catch_errors is that if the stack is clobbered,
6988 walking the stack might encounter a garbage pointer and
6989 error() trying to dereference it. */
6991 (restore_selected_frame
, &inf_status
->selected_frame_id
,
6992 "Unable to restore previously selected frame:\n",
6993 RETURN_MASK_ERROR
) == 0)
6994 /* Error in restoring the selected frame. Select the innermost
6996 select_frame (get_current_frame ());
7003 do_restore_infcall_control_state_cleanup (void *sts
)
7005 restore_infcall_control_state (sts
);
7009 make_cleanup_restore_infcall_control_state
7010 (struct infcall_control_state
*inf_status
)
7012 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7016 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7018 if (inf_status
->thread_control
.step_resume_breakpoint
)
7019 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7020 = disp_del_at_next_stop
;
7022 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7023 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7024 = disp_del_at_next_stop
;
7026 /* See save_infcall_control_state for info on stop_bpstat. */
7027 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7033 ptid_match (ptid_t ptid
, ptid_t filter
)
7035 if (ptid_equal (filter
, minus_one_ptid
))
7037 if (ptid_is_pid (filter
)
7038 && ptid_get_pid (ptid
) == ptid_get_pid (filter
))
7040 else if (ptid_equal (ptid
, filter
))
7046 /* restore_inferior_ptid() will be used by the cleanup machinery
7047 to restore the inferior_ptid value saved in a call to
7048 save_inferior_ptid(). */
7051 restore_inferior_ptid (void *arg
)
7053 ptid_t
*saved_ptid_ptr
= arg
;
7055 inferior_ptid
= *saved_ptid_ptr
;
7059 /* Save the value of inferior_ptid so that it may be restored by a
7060 later call to do_cleanups(). Returns the struct cleanup pointer
7061 needed for later doing the cleanup. */
7064 save_inferior_ptid (void)
7066 ptid_t
*saved_ptid_ptr
;
7068 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7069 *saved_ptid_ptr
= inferior_ptid
;
7070 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7074 /* User interface for reverse debugging:
7075 Set exec-direction / show exec-direction commands
7076 (returns error unless target implements to_set_exec_direction method). */
7078 int execution_direction
= EXEC_FORWARD
;
7079 static const char exec_forward
[] = "forward";
7080 static const char exec_reverse
[] = "reverse";
7081 static const char *exec_direction
= exec_forward
;
7082 static const char *const exec_direction_names
[] = {
7089 set_exec_direction_func (char *args
, int from_tty
,
7090 struct cmd_list_element
*cmd
)
7092 if (target_can_execute_reverse
)
7094 if (!strcmp (exec_direction
, exec_forward
))
7095 execution_direction
= EXEC_FORWARD
;
7096 else if (!strcmp (exec_direction
, exec_reverse
))
7097 execution_direction
= EXEC_REVERSE
;
7101 exec_direction
= exec_forward
;
7102 error (_("Target does not support this operation."));
7107 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7108 struct cmd_list_element
*cmd
, const char *value
)
7110 switch (execution_direction
) {
7112 fprintf_filtered (out
, _("Forward.\n"));
7115 fprintf_filtered (out
, _("Reverse.\n"));
7118 internal_error (__FILE__
, __LINE__
,
7119 _("bogus execution_direction value: %d"),
7120 (int) execution_direction
);
7124 /* User interface for non-stop mode. */
7129 set_non_stop (char *args
, int from_tty
,
7130 struct cmd_list_element
*c
)
7132 if (target_has_execution
)
7134 non_stop_1
= non_stop
;
7135 error (_("Cannot change this setting while the inferior is running."));
7138 non_stop
= non_stop_1
;
7142 show_non_stop (struct ui_file
*file
, int from_tty
,
7143 struct cmd_list_element
*c
, const char *value
)
7145 fprintf_filtered (file
,
7146 _("Controlling the inferior in non-stop mode is %s.\n"),
7151 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7152 struct cmd_list_element
*c
, const char *value
)
7154 fprintf_filtered (file
, _("Resuming the execution of threads "
7155 "of all processes is %s.\n"), value
);
7158 /* Implementation of `siginfo' variable. */
7160 static const struct internalvar_funcs siginfo_funcs
=
7168 _initialize_infrun (void)
7172 struct cmd_list_element
*c
;
7174 add_info ("signals", signals_info
, _("\
7175 What debugger does when program gets various signals.\n\
7176 Specify a signal as argument to print info on that signal only."));
7177 add_info_alias ("handle", "signals", 0);
7179 c
= add_com ("handle", class_run
, handle_command
, _("\
7180 Specify how to handle signals.\n\
7181 Usage: handle SIGNAL [ACTIONS]\n\
7182 Args are signals and actions to apply to those signals.\n\
7183 If no actions are specified, the current settings for the specified signals\n\
7184 will be displayed instead.\n\
7186 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7187 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7188 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7189 The special arg \"all\" is recognized to mean all signals except those\n\
7190 used by the debugger, typically SIGTRAP and SIGINT.\n\
7192 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7193 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7194 Stop means reenter debugger if this signal happens (implies print).\n\
7195 Print means print a message if this signal happens.\n\
7196 Pass means let program see this signal; otherwise program doesn't know.\n\
7197 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7198 Pass and Stop may be combined.\n\
7200 Multiple signals may be specified. Signal numbers and signal names\n\
7201 may be interspersed with actions, with the actions being performed for\n\
7202 all signals cumulatively specified."));
7203 set_cmd_completer (c
, handle_completer
);
7207 add_com ("lz", class_info
, signals_info
, _("\
7208 What debugger does when program gets various signals.\n\
7209 Specify a signal as argument to print info on that signal only."));
7210 add_com ("z", class_run
, xdb_handle_command
, _("\
7211 Specify how to handle a signal.\n\
7212 Args are signals and actions to apply to those signals.\n\
7213 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7214 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7215 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7216 The special arg \"all\" is recognized to mean all signals except those\n\
7217 used by the debugger, typically SIGTRAP and SIGINT.\n\
7218 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7219 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7220 nopass), \"Q\" (noprint)\n\
7221 Stop means reenter debugger if this signal happens (implies print).\n\
7222 Print means print a message if this signal happens.\n\
7223 Pass means let program see this signal; otherwise program doesn't know.\n\
7224 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7225 Pass and Stop may be combined."));
7229 stop_command
= add_cmd ("stop", class_obscure
,
7230 not_just_help_class_command
, _("\
7231 There is no `stop' command, but you can set a hook on `stop'.\n\
7232 This allows you to set a list of commands to be run each time execution\n\
7233 of the program stops."), &cmdlist
);
7235 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7236 Set inferior debugging."), _("\
7237 Show inferior debugging."), _("\
7238 When non-zero, inferior specific debugging is enabled."),
7241 &setdebuglist
, &showdebuglist
);
7243 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7244 &debug_displaced
, _("\
7245 Set displaced stepping debugging."), _("\
7246 Show displaced stepping debugging."), _("\
7247 When non-zero, displaced stepping specific debugging is enabled."),
7249 show_debug_displaced
,
7250 &setdebuglist
, &showdebuglist
);
7252 add_setshow_boolean_cmd ("non-stop", no_class
,
7254 Set whether gdb controls the inferior in non-stop mode."), _("\
7255 Show whether gdb controls the inferior in non-stop mode."), _("\
7256 When debugging a multi-threaded program and this setting is\n\
7257 off (the default, also called all-stop mode), when one thread stops\n\
7258 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7259 all other threads in the program while you interact with the thread of\n\
7260 interest. When you continue or step a thread, you can allow the other\n\
7261 threads to run, or have them remain stopped, but while you inspect any\n\
7262 thread's state, all threads stop.\n\
7264 In non-stop mode, when one thread stops, other threads can continue\n\
7265 to run freely. You'll be able to step each thread independently,\n\
7266 leave it stopped or free to run as needed."),
7272 numsigs
= (int) GDB_SIGNAL_LAST
;
7273 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7274 signal_print
= (unsigned char *)
7275 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7276 signal_program
= (unsigned char *)
7277 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7278 signal_catch
= (unsigned char *)
7279 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7280 signal_pass
= (unsigned char *)
7281 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7282 for (i
= 0; i
< numsigs
; i
++)
7285 signal_print
[i
] = 1;
7286 signal_program
[i
] = 1;
7287 signal_catch
[i
] = 0;
7290 /* Signals caused by debugger's own actions
7291 should not be given to the program afterwards. */
7292 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7293 signal_program
[GDB_SIGNAL_INT
] = 0;
7295 /* Signals that are not errors should not normally enter the debugger. */
7296 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7297 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7298 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7299 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7300 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7301 signal_print
[GDB_SIGNAL_PROF
] = 0;
7302 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7303 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7304 signal_stop
[GDB_SIGNAL_IO
] = 0;
7305 signal_print
[GDB_SIGNAL_IO
] = 0;
7306 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7307 signal_print
[GDB_SIGNAL_POLL
] = 0;
7308 signal_stop
[GDB_SIGNAL_URG
] = 0;
7309 signal_print
[GDB_SIGNAL_URG
] = 0;
7310 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7311 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7312 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7313 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7315 /* These signals are used internally by user-level thread
7316 implementations. (See signal(5) on Solaris.) Like the above
7317 signals, a healthy program receives and handles them as part of
7318 its normal operation. */
7319 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7320 signal_print
[GDB_SIGNAL_LWP
] = 0;
7321 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7322 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7323 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7324 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7326 /* Update cached state. */
7327 signal_cache_update (-1);
7329 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7330 &stop_on_solib_events
, _("\
7331 Set stopping for shared library events."), _("\
7332 Show stopping for shared library events."), _("\
7333 If nonzero, gdb will give control to the user when the dynamic linker\n\
7334 notifies gdb of shared library events. The most common event of interest\n\
7335 to the user would be loading/unloading of a new library."),
7337 show_stop_on_solib_events
,
7338 &setlist
, &showlist
);
7340 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7341 follow_fork_mode_kind_names
,
7342 &follow_fork_mode_string
, _("\
7343 Set debugger response to a program call of fork or vfork."), _("\
7344 Show debugger response to a program call of fork or vfork."), _("\
7345 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7346 parent - the original process is debugged after a fork\n\
7347 child - the new process is debugged after a fork\n\
7348 The unfollowed process will continue to run.\n\
7349 By default, the debugger will follow the parent process."),
7351 show_follow_fork_mode_string
,
7352 &setlist
, &showlist
);
7354 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7355 follow_exec_mode_names
,
7356 &follow_exec_mode_string
, _("\
7357 Set debugger response to a program call of exec."), _("\
7358 Show debugger response to a program call of exec."), _("\
7359 An exec call replaces the program image of a process.\n\
7361 follow-exec-mode can be:\n\
7363 new - the debugger creates a new inferior and rebinds the process\n\
7364 to this new inferior. The program the process was running before\n\
7365 the exec call can be restarted afterwards by restarting the original\n\
7368 same - the debugger keeps the process bound to the same inferior.\n\
7369 The new executable image replaces the previous executable loaded in\n\
7370 the inferior. Restarting the inferior after the exec call restarts\n\
7371 the executable the process was running after the exec call.\n\
7373 By default, the debugger will use the same inferior."),
7375 show_follow_exec_mode_string
,
7376 &setlist
, &showlist
);
7378 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7379 scheduler_enums
, &scheduler_mode
, _("\
7380 Set mode for locking scheduler during execution."), _("\
7381 Show mode for locking scheduler during execution."), _("\
7382 off == no locking (threads may preempt at any time)\n\
7383 on == full locking (no thread except the current thread may run)\n\
7384 step == scheduler locked during every single-step operation.\n\
7385 In this mode, no other thread may run during a step command.\n\
7386 Other threads may run while stepping over a function call ('next')."),
7387 set_schedlock_func
, /* traps on target vector */
7388 show_scheduler_mode
,
7389 &setlist
, &showlist
);
7391 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7392 Set mode for resuming threads of all processes."), _("\
7393 Show mode for resuming threads of all processes."), _("\
7394 When on, execution commands (such as 'continue' or 'next') resume all\n\
7395 threads of all processes. When off (which is the default), execution\n\
7396 commands only resume the threads of the current process. The set of\n\
7397 threads that are resumed is further refined by the scheduler-locking\n\
7398 mode (see help set scheduler-locking)."),
7400 show_schedule_multiple
,
7401 &setlist
, &showlist
);
7403 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7404 Set mode of the step operation."), _("\
7405 Show mode of the step operation."), _("\
7406 When set, doing a step over a function without debug line information\n\
7407 will stop at the first instruction of that function. Otherwise, the\n\
7408 function is skipped and the step command stops at a different source line."),
7410 show_step_stop_if_no_debug
,
7411 &setlist
, &showlist
);
7413 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7414 &can_use_displaced_stepping
, _("\
7415 Set debugger's willingness to use displaced stepping."), _("\
7416 Show debugger's willingness to use displaced stepping."), _("\
7417 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7418 supported by the target architecture. If off, gdb will not use displaced\n\
7419 stepping to step over breakpoints, even if such is supported by the target\n\
7420 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7421 if the target architecture supports it and non-stop mode is active, but will not\n\
7422 use it in all-stop mode (see help set non-stop)."),
7424 show_can_use_displaced_stepping
,
7425 &setlist
, &showlist
);
7427 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7428 &exec_direction
, _("Set direction of execution.\n\
7429 Options are 'forward' or 'reverse'."),
7430 _("Show direction of execution (forward/reverse)."),
7431 _("Tells gdb whether to execute forward or backward."),
7432 set_exec_direction_func
, show_exec_direction_func
,
7433 &setlist
, &showlist
);
7435 /* Set/show detach-on-fork: user-settable mode. */
7437 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7438 Set whether gdb will detach the child of a fork."), _("\
7439 Show whether gdb will detach the child of a fork."), _("\
7440 Tells gdb whether to detach the child of a fork."),
7441 NULL
, NULL
, &setlist
, &showlist
);
7443 /* Set/show disable address space randomization mode. */
7445 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7446 &disable_randomization
, _("\
7447 Set disabling of debuggee's virtual address space randomization."), _("\
7448 Show disabling of debuggee's virtual address space randomization."), _("\
7449 When this mode is on (which is the default), randomization of the virtual\n\
7450 address space is disabled. Standalone programs run with the randomization\n\
7451 enabled by default on some platforms."),
7452 &set_disable_randomization
,
7453 &show_disable_randomization
,
7454 &setlist
, &showlist
);
7456 /* ptid initializations */
7457 inferior_ptid
= null_ptid
;
7458 target_last_wait_ptid
= minus_one_ptid
;
7460 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7461 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7462 observer_attach_thread_exit (infrun_thread_thread_exit
);
7463 observer_attach_inferior_exit (infrun_inferior_exit
);
7465 /* Explicitly create without lookup, since that tries to create a
7466 value with a void typed value, and when we get here, gdbarch
7467 isn't initialized yet. At this point, we're quite sure there
7468 isn't another convenience variable of the same name. */
7469 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7471 add_setshow_boolean_cmd ("observer", no_class
,
7472 &observer_mode_1
, _("\
7473 Set whether gdb controls the inferior in observer mode."), _("\
7474 Show whether gdb controls the inferior in observer mode."), _("\
7475 In observer mode, GDB can get data from the inferior, but not\n\
7476 affect its execution. Registers and memory may not be changed,\n\
7477 breakpoints may not be set, and the program cannot be interrupted\n\