1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2015 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/>. */
27 #include "breakpoint.h"
31 #include "cli/cli-script.h"
33 #include "gdbthread.h"
45 #include "dictionary.h"
47 #include "mi/mi-common.h"
48 #include "event-top.h"
50 #include "record-full.h"
51 #include "inline-frame.h"
53 #include "tracepoint.h"
54 #include "continuations.h"
59 #include "completer.h"
60 #include "target-descriptions.h"
61 #include "target-dcache.h"
65 /* Prototypes for local functions */
67 static void signals_info (char *, int);
69 static void handle_command (char *, int);
71 static void sig_print_info (enum gdb_signal
);
73 static void sig_print_header (void);
75 static void resume_cleanups (void *);
77 static int hook_stop_stub (void *);
79 static int restore_selected_frame (void *);
81 static int follow_fork (void);
83 static int follow_fork_inferior (int follow_child
, int detach_fork
);
85 static void follow_inferior_reset_breakpoints (void);
87 static void set_schedlock_func (char *args
, int from_tty
,
88 struct cmd_list_element
*c
);
90 static int currently_stepping (struct thread_info
*tp
);
92 void _initialize_infrun (void);
94 void nullify_last_target_wait_ptid (void);
96 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
98 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
100 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
102 static int maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
);
104 /* When set, stop the 'step' command if we enter a function which has
105 no line number information. The normal behavior is that we step
106 over such function. */
107 int step_stop_if_no_debug
= 0;
109 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
110 struct cmd_list_element
*c
, const char *value
)
112 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
115 /* In asynchronous mode, but simulating synchronous execution. */
117 int sync_execution
= 0;
119 /* proceed and normal_stop use this to notify the user when the
120 inferior stopped in a different thread than it had been running
123 static ptid_t previous_inferior_ptid
;
125 /* If set (default for legacy reasons), when following a fork, GDB
126 will detach from one of the fork branches, child or parent.
127 Exactly which branch is detached depends on 'set follow-fork-mode'
130 static int detach_fork
= 1;
132 int debug_displaced
= 0;
134 show_debug_displaced (struct ui_file
*file
, int from_tty
,
135 struct cmd_list_element
*c
, const char *value
)
137 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
140 unsigned int debug_infrun
= 0;
142 show_debug_infrun (struct ui_file
*file
, int from_tty
,
143 struct cmd_list_element
*c
, const char *value
)
145 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
149 /* Support for disabling address space randomization. */
151 int disable_randomization
= 1;
154 show_disable_randomization (struct ui_file
*file
, int from_tty
,
155 struct cmd_list_element
*c
, const char *value
)
157 if (target_supports_disable_randomization ())
158 fprintf_filtered (file
,
159 _("Disabling randomization of debuggee's "
160 "virtual address space is %s.\n"),
163 fputs_filtered (_("Disabling randomization of debuggee's "
164 "virtual address space is unsupported on\n"
165 "this platform.\n"), file
);
169 set_disable_randomization (char *args
, int from_tty
,
170 struct cmd_list_element
*c
)
172 if (!target_supports_disable_randomization ())
173 error (_("Disabling randomization of debuggee's "
174 "virtual address space is unsupported on\n"
178 /* User interface for non-stop mode. */
181 static int non_stop_1
= 0;
184 set_non_stop (char *args
, int from_tty
,
185 struct cmd_list_element
*c
)
187 if (target_has_execution
)
189 non_stop_1
= non_stop
;
190 error (_("Cannot change this setting while the inferior is running."));
193 non_stop
= non_stop_1
;
197 show_non_stop (struct ui_file
*file
, int from_tty
,
198 struct cmd_list_element
*c
, const char *value
)
200 fprintf_filtered (file
,
201 _("Controlling the inferior in non-stop mode is %s.\n"),
205 /* "Observer mode" is somewhat like a more extreme version of
206 non-stop, in which all GDB operations that might affect the
207 target's execution have been disabled. */
209 int observer_mode
= 0;
210 static int observer_mode_1
= 0;
213 set_observer_mode (char *args
, int from_tty
,
214 struct cmd_list_element
*c
)
216 if (target_has_execution
)
218 observer_mode_1
= observer_mode
;
219 error (_("Cannot change this setting while the inferior is running."));
222 observer_mode
= observer_mode_1
;
224 may_write_registers
= !observer_mode
;
225 may_write_memory
= !observer_mode
;
226 may_insert_breakpoints
= !observer_mode
;
227 may_insert_tracepoints
= !observer_mode
;
228 /* We can insert fast tracepoints in or out of observer mode,
229 but enable them if we're going into this mode. */
231 may_insert_fast_tracepoints
= 1;
232 may_stop
= !observer_mode
;
233 update_target_permissions ();
235 /* Going *into* observer mode we must force non-stop, then
236 going out we leave it that way. */
239 pagination_enabled
= 0;
240 non_stop
= non_stop_1
= 1;
244 printf_filtered (_("Observer mode is now %s.\n"),
245 (observer_mode
? "on" : "off"));
249 show_observer_mode (struct ui_file
*file
, int from_tty
,
250 struct cmd_list_element
*c
, const char *value
)
252 fprintf_filtered (file
, _("Observer mode is %s.\n"), value
);
255 /* This updates the value of observer mode based on changes in
256 permissions. Note that we are deliberately ignoring the values of
257 may-write-registers and may-write-memory, since the user may have
258 reason to enable these during a session, for instance to turn on a
259 debugging-related global. */
262 update_observer_mode (void)
266 newval
= (!may_insert_breakpoints
267 && !may_insert_tracepoints
268 && may_insert_fast_tracepoints
272 /* Let the user know if things change. */
273 if (newval
!= observer_mode
)
274 printf_filtered (_("Observer mode is now %s.\n"),
275 (newval
? "on" : "off"));
277 observer_mode
= observer_mode_1
= newval
;
280 /* Tables of how to react to signals; the user sets them. */
282 static unsigned char *signal_stop
;
283 static unsigned char *signal_print
;
284 static unsigned char *signal_program
;
286 /* Table of signals that are registered with "catch signal". A
287 non-zero entry indicates that the signal is caught by some "catch
288 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
290 static unsigned char *signal_catch
;
292 /* Table of signals that the target may silently handle.
293 This is automatically determined from the flags above,
294 and simply cached here. */
295 static unsigned char *signal_pass
;
297 #define SET_SIGS(nsigs,sigs,flags) \
299 int signum = (nsigs); \
300 while (signum-- > 0) \
301 if ((sigs)[signum]) \
302 (flags)[signum] = 1; \
305 #define UNSET_SIGS(nsigs,sigs,flags) \
307 int signum = (nsigs); \
308 while (signum-- > 0) \
309 if ((sigs)[signum]) \
310 (flags)[signum] = 0; \
313 /* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
314 this function is to avoid exporting `signal_program'. */
317 update_signals_program_target (void)
319 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
322 /* Value to pass to target_resume() to cause all threads to resume. */
324 #define RESUME_ALL minus_one_ptid
326 /* Command list pointer for the "stop" placeholder. */
328 static struct cmd_list_element
*stop_command
;
330 /* Nonzero if we want to give control to the user when we're notified
331 of shared library events by the dynamic linker. */
332 int stop_on_solib_events
;
334 /* Enable or disable optional shared library event breakpoints
335 as appropriate when the above flag is changed. */
338 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
340 update_solib_breakpoints ();
344 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
345 struct cmd_list_element
*c
, const char *value
)
347 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
351 /* Nonzero means expecting a trace trap
352 and should stop the inferior and return silently when it happens. */
356 /* Nonzero after stop if current stack frame should be printed. */
358 static int stop_print_frame
;
360 /* This is a cached copy of the pid/waitstatus of the last event
361 returned by target_wait()/deprecated_target_wait_hook(). This
362 information is returned by get_last_target_status(). */
363 static ptid_t target_last_wait_ptid
;
364 static struct target_waitstatus target_last_waitstatus
;
366 static void context_switch (ptid_t ptid
);
368 void init_thread_stepping_state (struct thread_info
*tss
);
370 static const char follow_fork_mode_child
[] = "child";
371 static const char follow_fork_mode_parent
[] = "parent";
373 static const char *const follow_fork_mode_kind_names
[] = {
374 follow_fork_mode_child
,
375 follow_fork_mode_parent
,
379 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
381 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
382 struct cmd_list_element
*c
, const char *value
)
384 fprintf_filtered (file
,
385 _("Debugger response to a program "
386 "call of fork or vfork is \"%s\".\n"),
391 /* Handle changes to the inferior list based on the type of fork,
392 which process is being followed, and whether the other process
393 should be detached. On entry inferior_ptid must be the ptid of
394 the fork parent. At return inferior_ptid is the ptid of the
395 followed inferior. */
398 follow_fork_inferior (int follow_child
, int detach_fork
)
401 ptid_t parent_ptid
, child_ptid
;
403 has_vforked
= (inferior_thread ()->pending_follow
.kind
404 == TARGET_WAITKIND_VFORKED
);
405 parent_ptid
= inferior_ptid
;
406 child_ptid
= inferior_thread ()->pending_follow
.value
.related_pid
;
409 && !non_stop
/* Non-stop always resumes both branches. */
410 && (!target_is_async_p () || sync_execution
)
411 && !(follow_child
|| detach_fork
|| sched_multi
))
413 /* The parent stays blocked inside the vfork syscall until the
414 child execs or exits. If we don't let the child run, then
415 the parent stays blocked. If we're telling the parent to run
416 in the foreground, the user will not be able to ctrl-c to get
417 back the terminal, effectively hanging the debug session. */
418 fprintf_filtered (gdb_stderr
, _("\
419 Can not resume the parent process over vfork in the foreground while\n\
420 holding the child stopped. Try \"set detach-on-fork\" or \
421 \"set schedule-multiple\".\n"));
422 /* FIXME output string > 80 columns. */
428 /* Detach new forked process? */
431 struct cleanup
*old_chain
;
433 /* Before detaching from the child, remove all breakpoints
434 from it. If we forked, then this has already been taken
435 care of by infrun.c. If we vforked however, any
436 breakpoint inserted in the parent is visible in the
437 child, even those added while stopped in a vfork
438 catchpoint. This will remove the breakpoints from the
439 parent also, but they'll be reinserted below. */
442 /* Keep breakpoints list in sync. */
443 remove_breakpoints_pid (ptid_get_pid (inferior_ptid
));
446 if (info_verbose
|| debug_infrun
)
448 target_terminal_ours_for_output ();
449 fprintf_filtered (gdb_stdlog
,
450 _("Detaching after %s from child %s.\n"),
451 has_vforked
? "vfork" : "fork",
452 target_pid_to_str (child_ptid
));
457 struct inferior
*parent_inf
, *child_inf
;
458 struct cleanup
*old_chain
;
460 /* Add process to GDB's tables. */
461 child_inf
= add_inferior (ptid_get_pid (child_ptid
));
463 parent_inf
= current_inferior ();
464 child_inf
->attach_flag
= parent_inf
->attach_flag
;
465 copy_terminal_info (child_inf
, parent_inf
);
466 child_inf
->gdbarch
= parent_inf
->gdbarch
;
467 copy_inferior_target_desc_info (child_inf
, parent_inf
);
469 old_chain
= save_inferior_ptid ();
470 save_current_program_space ();
472 inferior_ptid
= child_ptid
;
473 add_thread (inferior_ptid
);
474 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
476 /* If this is a vfork child, then the address-space is
477 shared with the parent. */
480 child_inf
->pspace
= parent_inf
->pspace
;
481 child_inf
->aspace
= parent_inf
->aspace
;
483 /* The parent will be frozen until the child is done
484 with the shared region. Keep track of the
486 child_inf
->vfork_parent
= parent_inf
;
487 child_inf
->pending_detach
= 0;
488 parent_inf
->vfork_child
= child_inf
;
489 parent_inf
->pending_detach
= 0;
493 child_inf
->aspace
= new_address_space ();
494 child_inf
->pspace
= add_program_space (child_inf
->aspace
);
495 child_inf
->removable
= 1;
496 set_current_program_space (child_inf
->pspace
);
497 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
499 /* Let the shared library layer (e.g., solib-svr4) learn
500 about this new process, relocate the cloned exec, pull
501 in shared libraries, and install the solib event
502 breakpoint. If a "cloned-VM" event was propagated
503 better throughout the core, this wouldn't be
505 solib_create_inferior_hook (0);
508 do_cleanups (old_chain
);
513 struct inferior
*parent_inf
;
515 parent_inf
= current_inferior ();
517 /* If we detached from the child, then we have to be careful
518 to not insert breakpoints in the parent until the child
519 is done with the shared memory region. However, if we're
520 staying attached to the child, then we can and should
521 insert breakpoints, so that we can debug it. A
522 subsequent child exec or exit is enough to know when does
523 the child stops using the parent's address space. */
524 parent_inf
->waiting_for_vfork_done
= detach_fork
;
525 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
530 /* Follow the child. */
531 struct inferior
*parent_inf
, *child_inf
;
532 struct program_space
*parent_pspace
;
534 if (info_verbose
|| debug_infrun
)
536 target_terminal_ours_for_output ();
537 fprintf_filtered (gdb_stdlog
,
538 _("Attaching after %s %s to child %s.\n"),
539 target_pid_to_str (parent_ptid
),
540 has_vforked
? "vfork" : "fork",
541 target_pid_to_str (child_ptid
));
544 /* Add the new inferior first, so that the target_detach below
545 doesn't unpush the target. */
547 child_inf
= add_inferior (ptid_get_pid (child_ptid
));
549 parent_inf
= current_inferior ();
550 child_inf
->attach_flag
= parent_inf
->attach_flag
;
551 copy_terminal_info (child_inf
, parent_inf
);
552 child_inf
->gdbarch
= parent_inf
->gdbarch
;
553 copy_inferior_target_desc_info (child_inf
, parent_inf
);
555 parent_pspace
= parent_inf
->pspace
;
557 /* If we're vforking, we want to hold on to the parent until the
558 child exits or execs. At child exec or exit time we can
559 remove the old breakpoints from the parent and detach or
560 resume debugging it. Otherwise, detach the parent now; we'll
561 want to reuse it's program/address spaces, but we can't set
562 them to the child before removing breakpoints from the
563 parent, otherwise, the breakpoints module could decide to
564 remove breakpoints from the wrong process (since they'd be
565 assigned to the same address space). */
569 gdb_assert (child_inf
->vfork_parent
== NULL
);
570 gdb_assert (parent_inf
->vfork_child
== NULL
);
571 child_inf
->vfork_parent
= parent_inf
;
572 child_inf
->pending_detach
= 0;
573 parent_inf
->vfork_child
= child_inf
;
574 parent_inf
->pending_detach
= detach_fork
;
575 parent_inf
->waiting_for_vfork_done
= 0;
577 else if (detach_fork
)
579 if (info_verbose
|| debug_infrun
)
581 target_terminal_ours_for_output ();
582 fprintf_filtered (gdb_stdlog
,
583 _("Detaching after fork from "
585 target_pid_to_str (child_ptid
));
588 target_detach (NULL
, 0);
591 /* Note that the detach above makes PARENT_INF dangling. */
593 /* Add the child thread to the appropriate lists, and switch to
594 this new thread, before cloning the program space, and
595 informing the solib layer about this new process. */
597 inferior_ptid
= child_ptid
;
598 add_thread (inferior_ptid
);
600 /* If this is a vfork child, then the address-space is shared
601 with the parent. If we detached from the parent, then we can
602 reuse the parent's program/address spaces. */
603 if (has_vforked
|| detach_fork
)
605 child_inf
->pspace
= parent_pspace
;
606 child_inf
->aspace
= child_inf
->pspace
->aspace
;
610 child_inf
->aspace
= new_address_space ();
611 child_inf
->pspace
= add_program_space (child_inf
->aspace
);
612 child_inf
->removable
= 1;
613 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
614 set_current_program_space (child_inf
->pspace
);
615 clone_program_space (child_inf
->pspace
, parent_pspace
);
617 /* Let the shared library layer (e.g., solib-svr4) learn
618 about this new process, relocate the cloned exec, pull in
619 shared libraries, and install the solib event breakpoint.
620 If a "cloned-VM" event was propagated better throughout
621 the core, this wouldn't be required. */
622 solib_create_inferior_hook (0);
626 return target_follow_fork (follow_child
, detach_fork
);
629 /* Tell the target to follow the fork we're stopped at. Returns true
630 if the inferior should be resumed; false, if the target for some
631 reason decided it's best not to resume. */
636 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
637 int should_resume
= 1;
638 struct thread_info
*tp
;
640 /* Copy user stepping state to the new inferior thread. FIXME: the
641 followed fork child thread should have a copy of most of the
642 parent thread structure's run control related fields, not just these.
643 Initialized to avoid "may be used uninitialized" warnings from gcc. */
644 struct breakpoint
*step_resume_breakpoint
= NULL
;
645 struct breakpoint
*exception_resume_breakpoint
= NULL
;
646 CORE_ADDR step_range_start
= 0;
647 CORE_ADDR step_range_end
= 0;
648 struct frame_id step_frame_id
= { 0 };
649 struct interp
*command_interp
= NULL
;
654 struct target_waitstatus wait_status
;
656 /* Get the last target status returned by target_wait(). */
657 get_last_target_status (&wait_ptid
, &wait_status
);
659 /* If not stopped at a fork event, then there's nothing else to
661 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
662 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
665 /* Check if we switched over from WAIT_PTID, since the event was
667 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
668 && !ptid_equal (inferior_ptid
, wait_ptid
))
670 /* We did. Switch back to WAIT_PTID thread, to tell the
671 target to follow it (in either direction). We'll
672 afterwards refuse to resume, and inform the user what
674 switch_to_thread (wait_ptid
);
679 tp
= inferior_thread ();
681 /* If there were any forks/vforks that were caught and are now to be
682 followed, then do so now. */
683 switch (tp
->pending_follow
.kind
)
685 case TARGET_WAITKIND_FORKED
:
686 case TARGET_WAITKIND_VFORKED
:
688 ptid_t parent
, child
;
690 /* If the user did a next/step, etc, over a fork call,
691 preserve the stepping state in the fork child. */
692 if (follow_child
&& should_resume
)
694 step_resume_breakpoint
= clone_momentary_breakpoint
695 (tp
->control
.step_resume_breakpoint
);
696 step_range_start
= tp
->control
.step_range_start
;
697 step_range_end
= tp
->control
.step_range_end
;
698 step_frame_id
= tp
->control
.step_frame_id
;
699 exception_resume_breakpoint
700 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
701 command_interp
= tp
->control
.command_interp
;
703 /* For now, delete the parent's sr breakpoint, otherwise,
704 parent/child sr breakpoints are considered duplicates,
705 and the child version will not be installed. Remove
706 this when the breakpoints module becomes aware of
707 inferiors and address spaces. */
708 delete_step_resume_breakpoint (tp
);
709 tp
->control
.step_range_start
= 0;
710 tp
->control
.step_range_end
= 0;
711 tp
->control
.step_frame_id
= null_frame_id
;
712 delete_exception_resume_breakpoint (tp
);
713 tp
->control
.command_interp
= NULL
;
716 parent
= inferior_ptid
;
717 child
= tp
->pending_follow
.value
.related_pid
;
719 /* Set up inferior(s) as specified by the caller, and tell the
720 target to do whatever is necessary to follow either parent
722 if (follow_fork_inferior (follow_child
, detach_fork
))
724 /* Target refused to follow, or there's some other reason
725 we shouldn't resume. */
730 /* This pending follow fork event is now handled, one way
731 or another. The previous selected thread may be gone
732 from the lists by now, but if it is still around, need
733 to clear the pending follow request. */
734 tp
= find_thread_ptid (parent
);
736 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
738 /* This makes sure we don't try to apply the "Switched
739 over from WAIT_PID" logic above. */
740 nullify_last_target_wait_ptid ();
742 /* If we followed the child, switch to it... */
745 switch_to_thread (child
);
747 /* ... and preserve the stepping state, in case the
748 user was stepping over the fork call. */
751 tp
= inferior_thread ();
752 tp
->control
.step_resume_breakpoint
753 = step_resume_breakpoint
;
754 tp
->control
.step_range_start
= step_range_start
;
755 tp
->control
.step_range_end
= step_range_end
;
756 tp
->control
.step_frame_id
= step_frame_id
;
757 tp
->control
.exception_resume_breakpoint
758 = exception_resume_breakpoint
;
759 tp
->control
.command_interp
= command_interp
;
763 /* If we get here, it was because we're trying to
764 resume from a fork catchpoint, but, the user
765 has switched threads away from the thread that
766 forked. In that case, the resume command
767 issued is most likely not applicable to the
768 child, so just warn, and refuse to resume. */
769 warning (_("Not resuming: switched threads "
770 "before following fork child.\n"));
773 /* Reset breakpoints in the child as appropriate. */
774 follow_inferior_reset_breakpoints ();
777 switch_to_thread (parent
);
781 case TARGET_WAITKIND_SPURIOUS
:
782 /* Nothing to follow. */
785 internal_error (__FILE__
, __LINE__
,
786 "Unexpected pending_follow.kind %d\n",
787 tp
->pending_follow
.kind
);
791 return should_resume
;
795 follow_inferior_reset_breakpoints (void)
797 struct thread_info
*tp
= inferior_thread ();
799 /* Was there a step_resume breakpoint? (There was if the user
800 did a "next" at the fork() call.) If so, explicitly reset its
801 thread number. Cloned step_resume breakpoints are disabled on
802 creation, so enable it here now that it is associated with the
805 step_resumes are a form of bp that are made to be per-thread.
806 Since we created the step_resume bp when the parent process
807 was being debugged, and now are switching to the child process,
808 from the breakpoint package's viewpoint, that's a switch of
809 "threads". We must update the bp's notion of which thread
810 it is for, or it'll be ignored when it triggers. */
812 if (tp
->control
.step_resume_breakpoint
)
814 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
815 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
818 /* Treat exception_resume breakpoints like step_resume breakpoints. */
819 if (tp
->control
.exception_resume_breakpoint
)
821 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
822 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
825 /* Reinsert all breakpoints in the child. The user may have set
826 breakpoints after catching the fork, in which case those
827 were never set in the child, but only in the parent. This makes
828 sure the inserted breakpoints match the breakpoint list. */
830 breakpoint_re_set ();
831 insert_breakpoints ();
834 /* The child has exited or execed: resume threads of the parent the
835 user wanted to be executing. */
838 proceed_after_vfork_done (struct thread_info
*thread
,
841 int pid
= * (int *) arg
;
843 if (ptid_get_pid (thread
->ptid
) == pid
844 && is_running (thread
->ptid
)
845 && !is_executing (thread
->ptid
)
846 && !thread
->stop_requested
847 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
850 fprintf_unfiltered (gdb_stdlog
,
851 "infrun: resuming vfork parent thread %s\n",
852 target_pid_to_str (thread
->ptid
));
854 switch_to_thread (thread
->ptid
);
855 clear_proceed_status (0);
856 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
);
862 /* Called whenever we notice an exec or exit event, to handle
863 detaching or resuming a vfork parent. */
866 handle_vfork_child_exec_or_exit (int exec
)
868 struct inferior
*inf
= current_inferior ();
870 if (inf
->vfork_parent
)
872 int resume_parent
= -1;
874 /* This exec or exit marks the end of the shared memory region
875 between the parent and the child. If the user wanted to
876 detach from the parent, now is the time. */
878 if (inf
->vfork_parent
->pending_detach
)
880 struct thread_info
*tp
;
881 struct cleanup
*old_chain
;
882 struct program_space
*pspace
;
883 struct address_space
*aspace
;
885 /* follow-fork child, detach-on-fork on. */
887 inf
->vfork_parent
->pending_detach
= 0;
891 /* If we're handling a child exit, then inferior_ptid
892 points at the inferior's pid, not to a thread. */
893 old_chain
= save_inferior_ptid ();
894 save_current_program_space ();
895 save_current_inferior ();
898 old_chain
= save_current_space_and_thread ();
900 /* We're letting loose of the parent. */
901 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
902 switch_to_thread (tp
->ptid
);
904 /* We're about to detach from the parent, which implicitly
905 removes breakpoints from its address space. There's a
906 catch here: we want to reuse the spaces for the child,
907 but, parent/child are still sharing the pspace at this
908 point, although the exec in reality makes the kernel give
909 the child a fresh set of new pages. The problem here is
910 that the breakpoints module being unaware of this, would
911 likely chose the child process to write to the parent
912 address space. Swapping the child temporarily away from
913 the spaces has the desired effect. Yes, this is "sort
916 pspace
= inf
->pspace
;
917 aspace
= inf
->aspace
;
921 if (debug_infrun
|| info_verbose
)
923 target_terminal_ours_for_output ();
927 fprintf_filtered (gdb_stdlog
,
928 _("Detaching vfork parent process "
929 "%d after child exec.\n"),
930 inf
->vfork_parent
->pid
);
934 fprintf_filtered (gdb_stdlog
,
935 _("Detaching vfork parent process "
936 "%d after child exit.\n"),
937 inf
->vfork_parent
->pid
);
941 target_detach (NULL
, 0);
944 inf
->pspace
= pspace
;
945 inf
->aspace
= aspace
;
947 do_cleanups (old_chain
);
951 /* We're staying attached to the parent, so, really give the
952 child a new address space. */
953 inf
->pspace
= add_program_space (maybe_new_address_space ());
954 inf
->aspace
= inf
->pspace
->aspace
;
956 set_current_program_space (inf
->pspace
);
958 resume_parent
= inf
->vfork_parent
->pid
;
960 /* Break the bonds. */
961 inf
->vfork_parent
->vfork_child
= NULL
;
965 struct cleanup
*old_chain
;
966 struct program_space
*pspace
;
968 /* If this is a vfork child exiting, then the pspace and
969 aspaces were shared with the parent. Since we're
970 reporting the process exit, we'll be mourning all that is
971 found in the address space, and switching to null_ptid,
972 preparing to start a new inferior. But, since we don't
973 want to clobber the parent's address/program spaces, we
974 go ahead and create a new one for this exiting
977 /* Switch to null_ptid, so that clone_program_space doesn't want
978 to read the selected frame of a dead process. */
979 old_chain
= save_inferior_ptid ();
980 inferior_ptid
= null_ptid
;
982 /* This inferior is dead, so avoid giving the breakpoints
983 module the option to write through to it (cloning a
984 program space resets breakpoints). */
987 pspace
= add_program_space (maybe_new_address_space ());
988 set_current_program_space (pspace
);
990 inf
->symfile_flags
= SYMFILE_NO_READ
;
991 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
992 inf
->pspace
= pspace
;
993 inf
->aspace
= pspace
->aspace
;
995 /* Put back inferior_ptid. We'll continue mourning this
997 do_cleanups (old_chain
);
999 resume_parent
= inf
->vfork_parent
->pid
;
1000 /* Break the bonds. */
1001 inf
->vfork_parent
->vfork_child
= NULL
;
1004 inf
->vfork_parent
= NULL
;
1006 gdb_assert (current_program_space
== inf
->pspace
);
1008 if (non_stop
&& resume_parent
!= -1)
1010 /* If the user wanted the parent to be running, let it go
1012 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
1015 fprintf_unfiltered (gdb_stdlog
,
1016 "infrun: resuming vfork parent process %d\n",
1019 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
1021 do_cleanups (old_chain
);
1026 /* Enum strings for "set|show follow-exec-mode". */
1028 static const char follow_exec_mode_new
[] = "new";
1029 static const char follow_exec_mode_same
[] = "same";
1030 static const char *const follow_exec_mode_names
[] =
1032 follow_exec_mode_new
,
1033 follow_exec_mode_same
,
1037 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1039 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1040 struct cmd_list_element
*c
, const char *value
)
1042 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1045 /* EXECD_PATHNAME is assumed to be non-NULL. */
1048 follow_exec (ptid_t ptid
, char *execd_pathname
)
1050 struct thread_info
*th
, *tmp
;
1051 struct inferior
*inf
= current_inferior ();
1052 int pid
= ptid_get_pid (ptid
);
1054 /* This is an exec event that we actually wish to pay attention to.
1055 Refresh our symbol table to the newly exec'd program, remove any
1056 momentary bp's, etc.
1058 If there are breakpoints, they aren't really inserted now,
1059 since the exec() transformed our inferior into a fresh set
1062 We want to preserve symbolic breakpoints on the list, since
1063 we have hopes that they can be reset after the new a.out's
1064 symbol table is read.
1066 However, any "raw" breakpoints must be removed from the list
1067 (e.g., the solib bp's), since their address is probably invalid
1070 And, we DON'T want to call delete_breakpoints() here, since
1071 that may write the bp's "shadow contents" (the instruction
1072 value that was overwritten witha TRAP instruction). Since
1073 we now have a new a.out, those shadow contents aren't valid. */
1075 mark_breakpoints_out ();
1077 /* The target reports the exec event to the main thread, even if
1078 some other thread does the exec, and even if the main thread was
1079 stopped or already gone. We may still have non-leader threads of
1080 the process on our list. E.g., on targets that don't have thread
1081 exit events (like remote); or on native Linux in non-stop mode if
1082 there were only two threads in the inferior and the non-leader
1083 one is the one that execs (and nothing forces an update of the
1084 thread list up to here). When debugging remotely, it's best to
1085 avoid extra traffic, when possible, so avoid syncing the thread
1086 list with the target, and instead go ahead and delete all threads
1087 of the process but one that reported the event. Note this must
1088 be done before calling update_breakpoints_after_exec, as
1089 otherwise clearing the threads' resources would reference stale
1090 thread breakpoints -- it may have been one of these threads that
1091 stepped across the exec. We could just clear their stepping
1092 states, but as long as we're iterating, might as well delete
1093 them. Deleting them now rather than at the next user-visible
1094 stop provides a nicer sequence of events for user and MI
1096 ALL_THREADS_SAFE (th
, tmp
)
1097 if (ptid_get_pid (th
->ptid
) == pid
&& !ptid_equal (th
->ptid
, ptid
))
1098 delete_thread (th
->ptid
);
1100 /* We also need to clear any left over stale state for the
1101 leader/event thread. E.g., if there was any step-resume
1102 breakpoint or similar, it's gone now. We cannot truly
1103 step-to-next statement through an exec(). */
1104 th
= inferior_thread ();
1105 th
->control
.step_resume_breakpoint
= NULL
;
1106 th
->control
.exception_resume_breakpoint
= NULL
;
1107 th
->control
.single_step_breakpoints
= NULL
;
1108 th
->control
.step_range_start
= 0;
1109 th
->control
.step_range_end
= 0;
1111 /* The user may have had the main thread held stopped in the
1112 previous image (e.g., schedlock on, or non-stop). Release
1114 th
->stop_requested
= 0;
1116 update_breakpoints_after_exec ();
1118 /* What is this a.out's name? */
1119 printf_unfiltered (_("%s is executing new program: %s\n"),
1120 target_pid_to_str (inferior_ptid
),
1123 /* We've followed the inferior through an exec. Therefore, the
1124 inferior has essentially been killed & reborn. */
1126 gdb_flush (gdb_stdout
);
1128 breakpoint_init_inferior (inf_execd
);
1130 if (gdb_sysroot
!= NULL
&& *gdb_sysroot
!= '\0')
1132 char *name
= exec_file_find (execd_pathname
, NULL
);
1134 execd_pathname
= alloca (strlen (name
) + 1);
1135 strcpy (execd_pathname
, name
);
1139 /* Reset the shared library package. This ensures that we get a
1140 shlib event when the child reaches "_start", at which point the
1141 dld will have had a chance to initialize the child. */
1142 /* Also, loading a symbol file below may trigger symbol lookups, and
1143 we don't want those to be satisfied by the libraries of the
1144 previous incarnation of this process. */
1145 no_shared_libraries (NULL
, 0);
1147 if (follow_exec_mode_string
== follow_exec_mode_new
)
1149 struct program_space
*pspace
;
1151 /* The user wants to keep the old inferior and program spaces
1152 around. Create a new fresh one, and switch to it. */
1154 inf
= add_inferior (current_inferior ()->pid
);
1155 pspace
= add_program_space (maybe_new_address_space ());
1156 inf
->pspace
= pspace
;
1157 inf
->aspace
= pspace
->aspace
;
1159 exit_inferior_num_silent (current_inferior ()->num
);
1161 set_current_inferior (inf
);
1162 set_current_program_space (pspace
);
1166 /* The old description may no longer be fit for the new image.
1167 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1168 old description; we'll read a new one below. No need to do
1169 this on "follow-exec-mode new", as the old inferior stays
1170 around (its description is later cleared/refetched on
1172 target_clear_description ();
1175 gdb_assert (current_program_space
== inf
->pspace
);
1177 /* That a.out is now the one to use. */
1178 exec_file_attach (execd_pathname
, 0);
1180 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
1181 (Position Independent Executable) main symbol file will get applied by
1182 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
1183 the breakpoints with the zero displacement. */
1185 symbol_file_add (execd_pathname
,
1187 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
1190 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
1191 set_initial_language ();
1193 /* If the target can specify a description, read it. Must do this
1194 after flipping to the new executable (because the target supplied
1195 description must be compatible with the executable's
1196 architecture, and the old executable may e.g., be 32-bit, while
1197 the new one 64-bit), and before anything involving memory or
1199 target_find_description ();
1201 solib_create_inferior_hook (0);
1203 jit_inferior_created_hook ();
1205 breakpoint_re_set ();
1207 /* Reinsert all breakpoints. (Those which were symbolic have
1208 been reset to the proper address in the new a.out, thanks
1209 to symbol_file_command...). */
1210 insert_breakpoints ();
1212 /* The next resume of this inferior should bring it to the shlib
1213 startup breakpoints. (If the user had also set bp's on
1214 "main" from the old (parent) process, then they'll auto-
1215 matically get reset there in the new process.). */
1218 /* Info about an instruction that is being stepped over. */
1220 struct step_over_info
1222 /* If we're stepping past a breakpoint, this is the address space
1223 and address of the instruction the breakpoint is set at. We'll
1224 skip inserting all breakpoints here. Valid iff ASPACE is
1226 struct address_space
*aspace
;
1229 /* The instruction being stepped over triggers a nonsteppable
1230 watchpoint. If true, we'll skip inserting watchpoints. */
1231 int nonsteppable_watchpoint_p
;
1234 /* The step-over info of the location that is being stepped over.
1236 Note that with async/breakpoint always-inserted mode, a user might
1237 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1238 being stepped over. As setting a new breakpoint inserts all
1239 breakpoints, we need to make sure the breakpoint being stepped over
1240 isn't inserted then. We do that by only clearing the step-over
1241 info when the step-over is actually finished (or aborted).
1243 Presently GDB can only step over one breakpoint at any given time.
1244 Given threads that can't run code in the same address space as the
1245 breakpoint's can't really miss the breakpoint, GDB could be taught
1246 to step-over at most one breakpoint per address space (so this info
1247 could move to the address space object if/when GDB is extended).
1248 The set of breakpoints being stepped over will normally be much
1249 smaller than the set of all breakpoints, so a flag in the
1250 breakpoint location structure would be wasteful. A separate list
1251 also saves complexity and run-time, as otherwise we'd have to go
1252 through all breakpoint locations clearing their flag whenever we
1253 start a new sequence. Similar considerations weigh against storing
1254 this info in the thread object. Plus, not all step overs actually
1255 have breakpoint locations -- e.g., stepping past a single-step
1256 breakpoint, or stepping to complete a non-continuable
1258 static struct step_over_info step_over_info
;
1260 /* Record the address of the breakpoint/instruction we're currently
1264 set_step_over_info (struct address_space
*aspace
, CORE_ADDR address
,
1265 int nonsteppable_watchpoint_p
)
1267 step_over_info
.aspace
= aspace
;
1268 step_over_info
.address
= address
;
1269 step_over_info
.nonsteppable_watchpoint_p
= nonsteppable_watchpoint_p
;
1272 /* Called when we're not longer stepping over a breakpoint / an
1273 instruction, so all breakpoints are free to be (re)inserted. */
1276 clear_step_over_info (void)
1278 step_over_info
.aspace
= NULL
;
1279 step_over_info
.address
= 0;
1280 step_over_info
.nonsteppable_watchpoint_p
= 0;
1286 stepping_past_instruction_at (struct address_space
*aspace
,
1289 return (step_over_info
.aspace
!= NULL
1290 && breakpoint_address_match (aspace
, address
,
1291 step_over_info
.aspace
,
1292 step_over_info
.address
));
1298 stepping_past_nonsteppable_watchpoint (void)
1300 return step_over_info
.nonsteppable_watchpoint_p
;
1303 /* Returns true if step-over info is valid. */
1306 step_over_info_valid_p (void)
1308 return (step_over_info
.aspace
!= NULL
1309 || stepping_past_nonsteppable_watchpoint ());
1313 /* Displaced stepping. */
1315 /* In non-stop debugging mode, we must take special care to manage
1316 breakpoints properly; in particular, the traditional strategy for
1317 stepping a thread past a breakpoint it has hit is unsuitable.
1318 'Displaced stepping' is a tactic for stepping one thread past a
1319 breakpoint it has hit while ensuring that other threads running
1320 concurrently will hit the breakpoint as they should.
1322 The traditional way to step a thread T off a breakpoint in a
1323 multi-threaded program in all-stop mode is as follows:
1325 a0) Initially, all threads are stopped, and breakpoints are not
1327 a1) We single-step T, leaving breakpoints uninserted.
1328 a2) We insert breakpoints, and resume all threads.
1330 In non-stop debugging, however, this strategy is unsuitable: we
1331 don't want to have to stop all threads in the system in order to
1332 continue or step T past a breakpoint. Instead, we use displaced
1335 n0) Initially, T is stopped, other threads are running, and
1336 breakpoints are inserted.
1337 n1) We copy the instruction "under" the breakpoint to a separate
1338 location, outside the main code stream, making any adjustments
1339 to the instruction, register, and memory state as directed by
1341 n2) We single-step T over the instruction at its new location.
1342 n3) We adjust the resulting register and memory state as directed
1343 by T's architecture. This includes resetting T's PC to point
1344 back into the main instruction stream.
1347 This approach depends on the following gdbarch methods:
1349 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1350 indicate where to copy the instruction, and how much space must
1351 be reserved there. We use these in step n1.
1353 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1354 address, and makes any necessary adjustments to the instruction,
1355 register contents, and memory. We use this in step n1.
1357 - gdbarch_displaced_step_fixup adjusts registers and memory after
1358 we have successfuly single-stepped the instruction, to yield the
1359 same effect the instruction would have had if we had executed it
1360 at its original address. We use this in step n3.
1362 - gdbarch_displaced_step_free_closure provides cleanup.
1364 The gdbarch_displaced_step_copy_insn and
1365 gdbarch_displaced_step_fixup functions must be written so that
1366 copying an instruction with gdbarch_displaced_step_copy_insn,
1367 single-stepping across the copied instruction, and then applying
1368 gdbarch_displaced_insn_fixup should have the same effects on the
1369 thread's memory and registers as stepping the instruction in place
1370 would have. Exactly which responsibilities fall to the copy and
1371 which fall to the fixup is up to the author of those functions.
1373 See the comments in gdbarch.sh for details.
1375 Note that displaced stepping and software single-step cannot
1376 currently be used in combination, although with some care I think
1377 they could be made to. Software single-step works by placing
1378 breakpoints on all possible subsequent instructions; if the
1379 displaced instruction is a PC-relative jump, those breakpoints
1380 could fall in very strange places --- on pages that aren't
1381 executable, or at addresses that are not proper instruction
1382 boundaries. (We do generally let other threads run while we wait
1383 to hit the software single-step breakpoint, and they might
1384 encounter such a corrupted instruction.) One way to work around
1385 this would be to have gdbarch_displaced_step_copy_insn fully
1386 simulate the effect of PC-relative instructions (and return NULL)
1387 on architectures that use software single-stepping.
1389 In non-stop mode, we can have independent and simultaneous step
1390 requests, so more than one thread may need to simultaneously step
1391 over a breakpoint. The current implementation assumes there is
1392 only one scratch space per process. In this case, we have to
1393 serialize access to the scratch space. If thread A wants to step
1394 over a breakpoint, but we are currently waiting for some other
1395 thread to complete a displaced step, we leave thread A stopped and
1396 place it in the displaced_step_request_queue. Whenever a displaced
1397 step finishes, we pick the next thread in the queue and start a new
1398 displaced step operation on it. See displaced_step_prepare and
1399 displaced_step_fixup for details. */
1401 struct displaced_step_request
1404 struct displaced_step_request
*next
;
1407 /* Per-inferior displaced stepping state. */
1408 struct displaced_step_inferior_state
1410 /* Pointer to next in linked list. */
1411 struct displaced_step_inferior_state
*next
;
1413 /* The process this displaced step state refers to. */
1416 /* A queue of pending displaced stepping requests. One entry per
1417 thread that needs to do a displaced step. */
1418 struct displaced_step_request
*step_request_queue
;
1420 /* If this is not null_ptid, this is the thread carrying out a
1421 displaced single-step in process PID. This thread's state will
1422 require fixing up once it has completed its step. */
1425 /* The architecture the thread had when we stepped it. */
1426 struct gdbarch
*step_gdbarch
;
1428 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1429 for post-step cleanup. */
1430 struct displaced_step_closure
*step_closure
;
1432 /* The address of the original instruction, and the copy we
1434 CORE_ADDR step_original
, step_copy
;
1436 /* Saved contents of copy area. */
1437 gdb_byte
*step_saved_copy
;
1440 /* The list of states of processes involved in displaced stepping
1442 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1444 /* Get the displaced stepping state of process PID. */
1446 static struct displaced_step_inferior_state
*
1447 get_displaced_stepping_state (int pid
)
1449 struct displaced_step_inferior_state
*state
;
1451 for (state
= displaced_step_inferior_states
;
1453 state
= state
->next
)
1454 if (state
->pid
== pid
)
1460 /* Return true if process PID has a thread doing a displaced step. */
1463 displaced_step_in_progress (int pid
)
1465 struct displaced_step_inferior_state
*displaced
;
1467 displaced
= get_displaced_stepping_state (pid
);
1468 if (displaced
!= NULL
&& !ptid_equal (displaced
->step_ptid
, null_ptid
))
1474 /* Add a new displaced stepping state for process PID to the displaced
1475 stepping state list, or return a pointer to an already existing
1476 entry, if it already exists. Never returns NULL. */
1478 static struct displaced_step_inferior_state
*
1479 add_displaced_stepping_state (int pid
)
1481 struct displaced_step_inferior_state
*state
;
1483 for (state
= displaced_step_inferior_states
;
1485 state
= state
->next
)
1486 if (state
->pid
== pid
)
1489 state
= xcalloc (1, sizeof (*state
));
1491 state
->next
= displaced_step_inferior_states
;
1492 displaced_step_inferior_states
= state
;
1497 /* If inferior is in displaced stepping, and ADDR equals to starting address
1498 of copy area, return corresponding displaced_step_closure. Otherwise,
1501 struct displaced_step_closure
*
1502 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1504 struct displaced_step_inferior_state
*displaced
1505 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1507 /* If checking the mode of displaced instruction in copy area. */
1508 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1509 && (displaced
->step_copy
== addr
))
1510 return displaced
->step_closure
;
1515 /* Remove the displaced stepping state of process PID. */
1518 remove_displaced_stepping_state (int pid
)
1520 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1522 gdb_assert (pid
!= 0);
1524 it
= displaced_step_inferior_states
;
1525 prev_next_p
= &displaced_step_inferior_states
;
1530 *prev_next_p
= it
->next
;
1535 prev_next_p
= &it
->next
;
1541 infrun_inferior_exit (struct inferior
*inf
)
1543 remove_displaced_stepping_state (inf
->pid
);
1546 /* If ON, and the architecture supports it, GDB will use displaced
1547 stepping to step over breakpoints. If OFF, or if the architecture
1548 doesn't support it, GDB will instead use the traditional
1549 hold-and-step approach. If AUTO (which is the default), GDB will
1550 decide which technique to use to step over breakpoints depending on
1551 which of all-stop or non-stop mode is active --- displaced stepping
1552 in non-stop mode; hold-and-step in all-stop mode. */
1554 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1557 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1558 struct cmd_list_element
*c
,
1561 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1562 fprintf_filtered (file
,
1563 _("Debugger's willingness to use displaced stepping "
1564 "to step over breakpoints is %s (currently %s).\n"),
1565 value
, non_stop
? "on" : "off");
1567 fprintf_filtered (file
,
1568 _("Debugger's willingness to use displaced stepping "
1569 "to step over breakpoints is %s.\n"), value
);
1572 /* Return non-zero if displaced stepping can/should be used to step
1573 over breakpoints. */
1576 use_displaced_stepping (struct gdbarch
*gdbarch
)
1578 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1579 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1580 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1581 && find_record_target () == NULL
);
1584 /* Clean out any stray displaced stepping state. */
1586 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1588 /* Indicate that there is no cleanup pending. */
1589 displaced
->step_ptid
= null_ptid
;
1591 if (displaced
->step_closure
)
1593 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1594 displaced
->step_closure
);
1595 displaced
->step_closure
= NULL
;
1600 displaced_step_clear_cleanup (void *arg
)
1602 struct displaced_step_inferior_state
*state
= arg
;
1604 displaced_step_clear (state
);
1607 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1609 displaced_step_dump_bytes (struct ui_file
*file
,
1610 const gdb_byte
*buf
,
1615 for (i
= 0; i
< len
; i
++)
1616 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1617 fputs_unfiltered ("\n", file
);
1620 /* Prepare to single-step, using displaced stepping.
1622 Note that we cannot use displaced stepping when we have a signal to
1623 deliver. If we have a signal to deliver and an instruction to step
1624 over, then after the step, there will be no indication from the
1625 target whether the thread entered a signal handler or ignored the
1626 signal and stepped over the instruction successfully --- both cases
1627 result in a simple SIGTRAP. In the first case we mustn't do a
1628 fixup, and in the second case we must --- but we can't tell which.
1629 Comments in the code for 'random signals' in handle_inferior_event
1630 explain how we handle this case instead.
1632 Returns 1 if preparing was successful -- this thread is going to be
1633 stepped now; or 0 if displaced stepping this thread got queued. */
1635 displaced_step_prepare (ptid_t ptid
)
1637 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1638 struct thread_info
*tp
= find_thread_ptid (ptid
);
1639 struct regcache
*regcache
= get_thread_regcache (ptid
);
1640 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1641 CORE_ADDR original
, copy
;
1643 struct displaced_step_closure
*closure
;
1644 struct displaced_step_inferior_state
*displaced
;
1647 /* We should never reach this function if the architecture does not
1648 support displaced stepping. */
1649 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1651 /* Disable range stepping while executing in the scratch pad. We
1652 want a single-step even if executing the displaced instruction in
1653 the scratch buffer lands within the stepping range (e.g., a
1655 tp
->control
.may_range_step
= 0;
1657 /* We have to displaced step one thread at a time, as we only have
1658 access to a single scratch space per inferior. */
1660 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1662 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1664 /* Already waiting for a displaced step to finish. Defer this
1665 request and place in queue. */
1666 struct displaced_step_request
*req
, *new_req
;
1668 if (debug_displaced
)
1669 fprintf_unfiltered (gdb_stdlog
,
1670 "displaced: defering step of %s\n",
1671 target_pid_to_str (ptid
));
1673 new_req
= xmalloc (sizeof (*new_req
));
1674 new_req
->ptid
= ptid
;
1675 new_req
->next
= NULL
;
1677 if (displaced
->step_request_queue
)
1679 for (req
= displaced
->step_request_queue
;
1683 req
->next
= new_req
;
1686 displaced
->step_request_queue
= new_req
;
1692 if (debug_displaced
)
1693 fprintf_unfiltered (gdb_stdlog
,
1694 "displaced: stepping %s now\n",
1695 target_pid_to_str (ptid
));
1698 displaced_step_clear (displaced
);
1700 old_cleanups
= save_inferior_ptid ();
1701 inferior_ptid
= ptid
;
1703 original
= regcache_read_pc (regcache
);
1705 copy
= gdbarch_displaced_step_location (gdbarch
);
1706 len
= gdbarch_max_insn_length (gdbarch
);
1708 /* Save the original contents of the copy area. */
1709 displaced
->step_saved_copy
= xmalloc (len
);
1710 ignore_cleanups
= make_cleanup (free_current_contents
,
1711 &displaced
->step_saved_copy
);
1712 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1714 throw_error (MEMORY_ERROR
,
1715 _("Error accessing memory address %s (%s) for "
1716 "displaced-stepping scratch space."),
1717 paddress (gdbarch
, copy
), safe_strerror (status
));
1718 if (debug_displaced
)
1720 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1721 paddress (gdbarch
, copy
));
1722 displaced_step_dump_bytes (gdb_stdlog
,
1723 displaced
->step_saved_copy
,
1727 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1728 original
, copy
, regcache
);
1730 /* We don't support the fully-simulated case at present. */
1731 gdb_assert (closure
);
1733 /* Save the information we need to fix things up if the step
1735 displaced
->step_ptid
= ptid
;
1736 displaced
->step_gdbarch
= gdbarch
;
1737 displaced
->step_closure
= closure
;
1738 displaced
->step_original
= original
;
1739 displaced
->step_copy
= copy
;
1741 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1743 /* Resume execution at the copy. */
1744 regcache_write_pc (regcache
, copy
);
1746 discard_cleanups (ignore_cleanups
);
1748 do_cleanups (old_cleanups
);
1750 if (debug_displaced
)
1751 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1752 paddress (gdbarch
, copy
));
1758 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1759 const gdb_byte
*myaddr
, int len
)
1761 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1763 inferior_ptid
= ptid
;
1764 write_memory (memaddr
, myaddr
, len
);
1765 do_cleanups (ptid_cleanup
);
1768 /* Restore the contents of the copy area for thread PTID. */
1771 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1774 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1776 write_memory_ptid (ptid
, displaced
->step_copy
,
1777 displaced
->step_saved_copy
, len
);
1778 if (debug_displaced
)
1779 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1780 target_pid_to_str (ptid
),
1781 paddress (displaced
->step_gdbarch
,
1782 displaced
->step_copy
));
1786 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1788 struct cleanup
*old_cleanups
;
1789 struct displaced_step_inferior_state
*displaced
1790 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1792 /* Was any thread of this process doing a displaced step? */
1793 if (displaced
== NULL
)
1796 /* Was this event for the pid we displaced? */
1797 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1798 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1801 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1803 displaced_step_restore (displaced
, displaced
->step_ptid
);
1805 /* Fixup may need to read memory/registers. Switch to the thread
1806 that we're fixing up. Also, target_stopped_by_watchpoint checks
1807 the current thread. */
1808 switch_to_thread (event_ptid
);
1810 /* Did the instruction complete successfully? */
1811 if (signal
== GDB_SIGNAL_TRAP
1812 && !(target_stopped_by_watchpoint ()
1813 && (gdbarch_have_nonsteppable_watchpoint (displaced
->step_gdbarch
)
1814 || target_have_steppable_watchpoint
)))
1816 /* Fix up the resulting state. */
1817 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1818 displaced
->step_closure
,
1819 displaced
->step_original
,
1820 displaced
->step_copy
,
1821 get_thread_regcache (displaced
->step_ptid
));
1825 /* Since the instruction didn't complete, all we can do is
1827 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1828 CORE_ADDR pc
= regcache_read_pc (regcache
);
1830 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1831 regcache_write_pc (regcache
, pc
);
1834 do_cleanups (old_cleanups
);
1836 displaced
->step_ptid
= null_ptid
;
1838 /* Are there any pending displaced stepping requests? If so, run
1839 one now. Leave the state object around, since we're likely to
1840 need it again soon. */
1841 while (displaced
->step_request_queue
)
1843 struct displaced_step_request
*head
;
1845 struct regcache
*regcache
;
1846 struct gdbarch
*gdbarch
;
1847 CORE_ADDR actual_pc
;
1848 struct address_space
*aspace
;
1850 head
= displaced
->step_request_queue
;
1852 displaced
->step_request_queue
= head
->next
;
1855 context_switch (ptid
);
1857 regcache
= get_thread_regcache (ptid
);
1858 actual_pc
= regcache_read_pc (regcache
);
1859 aspace
= get_regcache_aspace (regcache
);
1860 gdbarch
= get_regcache_arch (regcache
);
1862 if (breakpoint_here_p (aspace
, actual_pc
))
1864 if (debug_displaced
)
1865 fprintf_unfiltered (gdb_stdlog
,
1866 "displaced: stepping queued %s now\n",
1867 target_pid_to_str (ptid
));
1869 displaced_step_prepare (ptid
);
1871 if (debug_displaced
)
1873 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1876 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1877 paddress (gdbarch
, actual_pc
));
1878 read_memory (actual_pc
, buf
, sizeof (buf
));
1879 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1882 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1883 displaced
->step_closure
))
1884 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1886 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1888 /* Done, we're stepping a thread. */
1894 struct thread_info
*tp
= inferior_thread ();
1896 /* The breakpoint we were sitting under has since been
1898 tp
->control
.trap_expected
= 0;
1900 /* Go back to what we were trying to do. */
1901 step
= currently_stepping (tp
);
1904 step
= maybe_software_singlestep (gdbarch
, actual_pc
);
1906 if (debug_displaced
)
1907 fprintf_unfiltered (gdb_stdlog
,
1908 "displaced: breakpoint is gone: %s, step(%d)\n",
1909 target_pid_to_str (tp
->ptid
), step
);
1911 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1912 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1914 /* This request was discarded. See if there's any other
1915 thread waiting for its turn. */
1920 /* Update global variables holding ptids to hold NEW_PTID if they were
1921 holding OLD_PTID. */
1923 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1925 struct displaced_step_request
*it
;
1926 struct displaced_step_inferior_state
*displaced
;
1928 if (ptid_equal (inferior_ptid
, old_ptid
))
1929 inferior_ptid
= new_ptid
;
1931 for (displaced
= displaced_step_inferior_states
;
1933 displaced
= displaced
->next
)
1935 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1936 displaced
->step_ptid
= new_ptid
;
1938 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1939 if (ptid_equal (it
->ptid
, old_ptid
))
1940 it
->ptid
= new_ptid
;
1947 /* Things to clean up if we QUIT out of resume (). */
1949 resume_cleanups (void *ignore
)
1951 if (!ptid_equal (inferior_ptid
, null_ptid
))
1952 delete_single_step_breakpoints (inferior_thread ());
1957 static const char schedlock_off
[] = "off";
1958 static const char schedlock_on
[] = "on";
1959 static const char schedlock_step
[] = "step";
1960 static const char *const scheduler_enums
[] = {
1966 static const char *scheduler_mode
= schedlock_off
;
1968 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1969 struct cmd_list_element
*c
, const char *value
)
1971 fprintf_filtered (file
,
1972 _("Mode for locking scheduler "
1973 "during execution is \"%s\".\n"),
1978 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1980 if (!target_can_lock_scheduler
)
1982 scheduler_mode
= schedlock_off
;
1983 error (_("Target '%s' cannot support this command."), target_shortname
);
1987 /* True if execution commands resume all threads of all processes by
1988 default; otherwise, resume only threads of the current inferior
1990 int sched_multi
= 0;
1992 /* Try to setup for software single stepping over the specified location.
1993 Return 1 if target_resume() should use hardware single step.
1995 GDBARCH the current gdbarch.
1996 PC the location to step over. */
1999 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
2003 if (execution_direction
== EXEC_FORWARD
2004 && gdbarch_software_single_step_p (gdbarch
)
2005 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
2015 user_visible_resume_ptid (int step
)
2021 /* With non-stop mode on, threads are always handled
2023 resume_ptid
= inferior_ptid
;
2025 else if ((scheduler_mode
== schedlock_on
)
2026 || (scheduler_mode
== schedlock_step
&& step
))
2028 /* User-settable 'scheduler' mode requires solo thread
2030 resume_ptid
= inferior_ptid
;
2032 else if (!sched_multi
&& target_supports_multi_process ())
2034 /* Resume all threads of the current process (and none of other
2036 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
2040 /* Resume all threads of all processes. */
2041 resume_ptid
= RESUME_ALL
;
2047 /* Wrapper for target_resume, that handles infrun-specific
2051 do_target_resume (ptid_t resume_ptid
, int step
, enum gdb_signal sig
)
2053 struct thread_info
*tp
= inferior_thread ();
2055 /* Install inferior's terminal modes. */
2056 target_terminal_inferior ();
2058 /* Avoid confusing the next resume, if the next stop/resume
2059 happens to apply to another thread. */
2060 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2062 /* Advise target which signals may be handled silently.
2064 If we have removed breakpoints because we are stepping over one
2065 in-line (in any thread), we need to receive all signals to avoid
2066 accidentally skipping a breakpoint during execution of a signal
2069 Likewise if we're displaced stepping, otherwise a trap for a
2070 breakpoint in a signal handler might be confused with the
2071 displaced step finishing. We don't make the displaced_step_fixup
2072 step distinguish the cases instead, because:
2074 - a backtrace while stopped in the signal handler would show the
2075 scratch pad as frame older than the signal handler, instead of
2076 the real mainline code.
2078 - when the thread is later resumed, the signal handler would
2079 return to the scratch pad area, which would no longer be
2081 if (step_over_info_valid_p ()
2082 || displaced_step_in_progress (ptid_get_pid (tp
->ptid
)))
2083 target_pass_signals (0, NULL
);
2085 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
2087 target_resume (resume_ptid
, step
, sig
);
2090 /* Resume the inferior, but allow a QUIT. This is useful if the user
2091 wants to interrupt some lengthy single-stepping operation
2092 (for child processes, the SIGINT goes to the inferior, and so
2093 we get a SIGINT random_signal, but for remote debugging and perhaps
2094 other targets, that's not true).
2096 SIG is the signal to give the inferior (zero for none). */
2098 resume (enum gdb_signal sig
)
2100 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
2101 struct regcache
*regcache
= get_current_regcache ();
2102 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2103 struct thread_info
*tp
= inferior_thread ();
2104 CORE_ADDR pc
= regcache_read_pc (regcache
);
2105 struct address_space
*aspace
= get_regcache_aspace (regcache
);
2107 /* This represents the user's step vs continue request. When
2108 deciding whether "set scheduler-locking step" applies, it's the
2109 user's intention that counts. */
2110 const int user_step
= tp
->control
.stepping_command
;
2111 /* This represents what we'll actually request the target to do.
2112 This can decay from a step to a continue, if e.g., we need to
2113 implement single-stepping with breakpoints (software
2117 tp
->stepped_breakpoint
= 0;
2121 /* Depends on stepped_breakpoint. */
2122 step
= currently_stepping (tp
);
2124 if (current_inferior ()->waiting_for_vfork_done
)
2126 /* Don't try to single-step a vfork parent that is waiting for
2127 the child to get out of the shared memory region (by exec'ing
2128 or exiting). This is particularly important on software
2129 single-step archs, as the child process would trip on the
2130 software single step breakpoint inserted for the parent
2131 process. Since the parent will not actually execute any
2132 instruction until the child is out of the shared region (such
2133 are vfork's semantics), it is safe to simply continue it.
2134 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2135 the parent, and tell it to `keep_going', which automatically
2136 re-sets it stepping. */
2138 fprintf_unfiltered (gdb_stdlog
,
2139 "infrun: resume : clear step\n");
2144 fprintf_unfiltered (gdb_stdlog
,
2145 "infrun: resume (step=%d, signal=%s), "
2146 "trap_expected=%d, current thread [%s] at %s\n",
2147 step
, gdb_signal_to_symbol_string (sig
),
2148 tp
->control
.trap_expected
,
2149 target_pid_to_str (inferior_ptid
),
2150 paddress (gdbarch
, pc
));
2152 /* Normally, by the time we reach `resume', the breakpoints are either
2153 removed or inserted, as appropriate. The exception is if we're sitting
2154 at a permanent breakpoint; we need to step over it, but permanent
2155 breakpoints can't be removed. So we have to test for it here. */
2156 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2158 if (sig
!= GDB_SIGNAL_0
)
2160 /* We have a signal to pass to the inferior. The resume
2161 may, or may not take us to the signal handler. If this
2162 is a step, we'll need to stop in the signal handler, if
2163 there's one, (if the target supports stepping into
2164 handlers), or in the next mainline instruction, if
2165 there's no handler. If this is a continue, we need to be
2166 sure to run the handler with all breakpoints inserted.
2167 In all cases, set a breakpoint at the current address
2168 (where the handler returns to), and once that breakpoint
2169 is hit, resume skipping the permanent breakpoint. If
2170 that breakpoint isn't hit, then we've stepped into the
2171 signal handler (or hit some other event). We'll delete
2172 the step-resume breakpoint then. */
2175 fprintf_unfiltered (gdb_stdlog
,
2176 "infrun: resume: skipping permanent breakpoint, "
2177 "deliver signal first\n");
2179 clear_step_over_info ();
2180 tp
->control
.trap_expected
= 0;
2182 if (tp
->control
.step_resume_breakpoint
== NULL
)
2184 /* Set a "high-priority" step-resume, as we don't want
2185 user breakpoints at PC to trigger (again) when this
2187 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2188 gdb_assert (tp
->control
.step_resume_breakpoint
->loc
->permanent
);
2190 tp
->step_after_step_resume_breakpoint
= step
;
2193 insert_breakpoints ();
2197 /* There's no signal to pass, we can go ahead and skip the
2198 permanent breakpoint manually. */
2200 fprintf_unfiltered (gdb_stdlog
,
2201 "infrun: resume: skipping permanent breakpoint\n");
2202 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2203 /* Update pc to reflect the new address from which we will
2204 execute instructions. */
2205 pc
= regcache_read_pc (regcache
);
2209 /* We've already advanced the PC, so the stepping part
2210 is done. Now we need to arrange for a trap to be
2211 reported to handle_inferior_event. Set a breakpoint
2212 at the current PC, and run to it. Don't update
2213 prev_pc, because if we end in
2214 switch_back_to_stepped_thread, we want the "expected
2215 thread advanced also" branch to be taken. IOW, we
2216 don't want this thread to step further from PC
2218 gdb_assert (!step_over_info_valid_p ());
2219 insert_single_step_breakpoint (gdbarch
, aspace
, pc
);
2220 insert_breakpoints ();
2222 resume_ptid
= user_visible_resume_ptid (user_step
);
2223 do_target_resume (resume_ptid
, 0, GDB_SIGNAL_0
);
2224 discard_cleanups (old_cleanups
);
2230 /* If we have a breakpoint to step over, make sure to do a single
2231 step only. Same if we have software watchpoints. */
2232 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2233 tp
->control
.may_range_step
= 0;
2235 /* If enabled, step over breakpoints by executing a copy of the
2236 instruction at a different address.
2238 We can't use displaced stepping when we have a signal to deliver;
2239 the comments for displaced_step_prepare explain why. The
2240 comments in the handle_inferior event for dealing with 'random
2241 signals' explain what we do instead.
2243 We can't use displaced stepping when we are waiting for vfork_done
2244 event, displaced stepping breaks the vfork child similarly as single
2245 step software breakpoint. */
2246 if (use_displaced_stepping (gdbarch
)
2247 && tp
->control
.trap_expected
2248 && !step_over_info_valid_p ()
2249 && sig
== GDB_SIGNAL_0
2250 && !current_inferior ()->waiting_for_vfork_done
)
2252 struct displaced_step_inferior_state
*displaced
;
2254 if (!displaced_step_prepare (inferior_ptid
))
2256 /* Got placed in displaced stepping queue. Will be resumed
2257 later when all the currently queued displaced stepping
2258 requests finish. The thread is not executing at this
2259 point, and the call to set_executing will be made later.
2260 But we need to call set_running here, since from the
2261 user/frontend's point of view, threads were set running.
2262 Unless we're calling an inferior function, as in that
2263 case we pretend the inferior doesn't run at all. */
2264 if (!tp
->control
.in_infcall
)
2265 set_running (user_visible_resume_ptid (user_step
), 1);
2266 discard_cleanups (old_cleanups
);
2270 /* Update pc to reflect the new address from which we will execute
2271 instructions due to displaced stepping. */
2272 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
2274 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
2275 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
2276 displaced
->step_closure
);
2279 /* Do we need to do it the hard way, w/temp breakpoints? */
2281 step
= maybe_software_singlestep (gdbarch
, pc
);
2283 /* Currently, our software single-step implementation leads to different
2284 results than hardware single-stepping in one situation: when stepping
2285 into delivering a signal which has an associated signal handler,
2286 hardware single-step will stop at the first instruction of the handler,
2287 while software single-step will simply skip execution of the handler.
2289 For now, this difference in behavior is accepted since there is no
2290 easy way to actually implement single-stepping into a signal handler
2291 without kernel support.
2293 However, there is one scenario where this difference leads to follow-on
2294 problems: if we're stepping off a breakpoint by removing all breakpoints
2295 and then single-stepping. In this case, the software single-step
2296 behavior means that even if there is a *breakpoint* in the signal
2297 handler, GDB still would not stop.
2299 Fortunately, we can at least fix this particular issue. We detect
2300 here the case where we are about to deliver a signal while software
2301 single-stepping with breakpoints removed. In this situation, we
2302 revert the decisions to remove all breakpoints and insert single-
2303 step breakpoints, and instead we install a step-resume breakpoint
2304 at the current address, deliver the signal without stepping, and
2305 once we arrive back at the step-resume breakpoint, actually step
2306 over the breakpoint we originally wanted to step over. */
2307 if (thread_has_single_step_breakpoints_set (tp
)
2308 && sig
!= GDB_SIGNAL_0
2309 && step_over_info_valid_p ())
2311 /* If we have nested signals or a pending signal is delivered
2312 immediately after a handler returns, might might already have
2313 a step-resume breakpoint set on the earlier handler. We cannot
2314 set another step-resume breakpoint; just continue on until the
2315 original breakpoint is hit. */
2316 if (tp
->control
.step_resume_breakpoint
== NULL
)
2318 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2319 tp
->step_after_step_resume_breakpoint
= 1;
2322 delete_single_step_breakpoints (tp
);
2324 clear_step_over_info ();
2325 tp
->control
.trap_expected
= 0;
2327 insert_breakpoints ();
2330 /* If STEP is set, it's a request to use hardware stepping
2331 facilities. But in that case, we should never
2332 use singlestep breakpoint. */
2333 gdb_assert (!(thread_has_single_step_breakpoints_set (tp
) && step
));
2335 /* Decide the set of threads to ask the target to resume. Start
2336 by assuming everything will be resumed, than narrow the set
2337 by applying increasingly restricting conditions. */
2338 resume_ptid
= user_visible_resume_ptid (user_step
);
2340 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
2341 (e.g., we might need to step over a breakpoint), from the
2342 user/frontend's point of view, all threads in RESUME_PTID are now
2343 running. Unless we're calling an inferior function, as in that
2344 case pretend we inferior doesn't run at all. */
2345 if (!tp
->control
.in_infcall
)
2346 set_running (resume_ptid
, 1);
2348 /* Maybe resume a single thread after all. */
2349 if ((step
|| thread_has_single_step_breakpoints_set (tp
))
2350 && tp
->control
.trap_expected
)
2352 /* We're allowing a thread to run past a breakpoint it has
2353 hit, by single-stepping the thread with the breakpoint
2354 removed. In which case, we need to single-step only this
2355 thread, and keep others stopped, as they can miss this
2356 breakpoint if allowed to run. */
2357 resume_ptid
= inferior_ptid
;
2360 if (execution_direction
!= EXEC_REVERSE
2361 && step
&& breakpoint_inserted_here_p (aspace
, pc
))
2363 /* The only case we currently need to step a breakpoint
2364 instruction is when we have a signal to deliver. See
2365 handle_signal_stop where we handle random signals that could
2366 take out us out of the stepping range. Normally, in that
2367 case we end up continuing (instead of stepping) over the
2368 signal handler with a breakpoint at PC, but there are cases
2369 where we should _always_ single-step, even if we have a
2370 step-resume breakpoint, like when a software watchpoint is
2371 set. Assuming single-stepping and delivering a signal at the
2372 same time would takes us to the signal handler, then we could
2373 have removed the breakpoint at PC to step over it. However,
2374 some hardware step targets (like e.g., Mac OS) can't step
2375 into signal handlers, and for those, we need to leave the
2376 breakpoint at PC inserted, as otherwise if the handler
2377 recurses and executes PC again, it'll miss the breakpoint.
2378 So we leave the breakpoint inserted anyway, but we need to
2379 record that we tried to step a breakpoint instruction, so
2380 that adjust_pc_after_break doesn't end up confused. */
2381 gdb_assert (sig
!= GDB_SIGNAL_0
);
2383 tp
->stepped_breakpoint
= 1;
2385 /* Most targets can step a breakpoint instruction, thus
2386 executing it normally. But if this one cannot, just
2387 continue and we will hit it anyway. */
2388 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2393 && use_displaced_stepping (gdbarch
)
2394 && tp
->control
.trap_expected
2395 && !step_over_info_valid_p ())
2397 struct regcache
*resume_regcache
= get_thread_regcache (tp
->ptid
);
2398 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
2399 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2402 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
2403 paddress (resume_gdbarch
, actual_pc
));
2404 read_memory (actual_pc
, buf
, sizeof (buf
));
2405 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
2408 if (tp
->control
.may_range_step
)
2410 /* If we're resuming a thread with the PC out of the step
2411 range, then we're doing some nested/finer run control
2412 operation, like stepping the thread out of the dynamic
2413 linker or the displaced stepping scratch pad. We
2414 shouldn't have allowed a range step then. */
2415 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2418 do_target_resume (resume_ptid
, step
, sig
);
2419 discard_cleanups (old_cleanups
);
2424 /* Clear out all variables saying what to do when inferior is continued.
2425 First do this, then set the ones you want, then call `proceed'. */
2428 clear_proceed_status_thread (struct thread_info
*tp
)
2431 fprintf_unfiltered (gdb_stdlog
,
2432 "infrun: clear_proceed_status_thread (%s)\n",
2433 target_pid_to_str (tp
->ptid
));
2435 /* If this signal should not be seen by program, give it zero.
2436 Used for debugging signals. */
2437 if (!signal_pass_state (tp
->suspend
.stop_signal
))
2438 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2440 tp
->control
.trap_expected
= 0;
2441 tp
->control
.step_range_start
= 0;
2442 tp
->control
.step_range_end
= 0;
2443 tp
->control
.may_range_step
= 0;
2444 tp
->control
.step_frame_id
= null_frame_id
;
2445 tp
->control
.step_stack_frame_id
= null_frame_id
;
2446 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2447 tp
->control
.step_start_function
= NULL
;
2448 tp
->stop_requested
= 0;
2450 tp
->control
.stop_step
= 0;
2452 tp
->control
.proceed_to_finish
= 0;
2454 tp
->control
.command_interp
= NULL
;
2455 tp
->control
.stepping_command
= 0;
2457 /* Discard any remaining commands or status from previous stop. */
2458 bpstat_clear (&tp
->control
.stop_bpstat
);
2462 clear_proceed_status (int step
)
2466 struct thread_info
*tp
;
2469 resume_ptid
= user_visible_resume_ptid (step
);
2471 /* In all-stop mode, delete the per-thread status of all threads
2472 we're about to resume, implicitly and explicitly. */
2473 ALL_NON_EXITED_THREADS (tp
)
2475 if (!ptid_match (tp
->ptid
, resume_ptid
))
2477 clear_proceed_status_thread (tp
);
2481 if (!ptid_equal (inferior_ptid
, null_ptid
))
2483 struct inferior
*inferior
;
2487 /* If in non-stop mode, only delete the per-thread status of
2488 the current thread. */
2489 clear_proceed_status_thread (inferior_thread ());
2492 inferior
= current_inferior ();
2493 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2496 stop_after_trap
= 0;
2498 clear_step_over_info ();
2500 observer_notify_about_to_proceed ();
2503 /* Returns true if TP is still stopped at a breakpoint that needs
2504 stepping-over in order to make progress. If the breakpoint is gone
2505 meanwhile, we can skip the whole step-over dance. */
2508 thread_still_needs_step_over (struct thread_info
*tp
)
2510 if (tp
->stepping_over_breakpoint
)
2512 struct regcache
*regcache
= get_thread_regcache (tp
->ptid
);
2514 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2515 regcache_read_pc (regcache
))
2516 == ordinary_breakpoint_here
)
2519 tp
->stepping_over_breakpoint
= 0;
2525 /* Returns true if scheduler locking applies. STEP indicates whether
2526 we're about to do a step/next-like command to a thread. */
2529 schedlock_applies (struct thread_info
*tp
)
2531 return (scheduler_mode
== schedlock_on
2532 || (scheduler_mode
== schedlock_step
2533 && tp
->control
.stepping_command
));
2536 /* Look a thread other than EXCEPT that has previously reported a
2537 breakpoint event, and thus needs a step-over in order to make
2538 progress. Returns NULL is none is found. */
2540 static struct thread_info
*
2541 find_thread_needs_step_over (struct thread_info
*except
)
2543 struct thread_info
*tp
, *current
;
2545 /* With non-stop mode on, threads are always handled individually. */
2546 gdb_assert (! non_stop
);
2548 current
= inferior_thread ();
2550 /* If scheduler locking applies, we can avoid iterating over all
2552 if (schedlock_applies (except
))
2554 if (except
!= current
2555 && thread_still_needs_step_over (current
))
2561 ALL_NON_EXITED_THREADS (tp
)
2563 /* Ignore the EXCEPT thread. */
2566 /* Ignore threads of processes we're not resuming. */
2568 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
2571 if (thread_still_needs_step_over (tp
))
2578 /* Basic routine for continuing the program in various fashions.
2580 ADDR is the address to resume at, or -1 for resume where stopped.
2581 SIGGNAL is the signal to give it, or 0 for none,
2582 or -1 for act according to how it stopped.
2583 STEP is nonzero if should trap after one instruction.
2584 -1 means return after that and print nothing.
2585 You should probably set various step_... variables
2586 before calling here, if you are stepping.
2588 You should call clear_proceed_status before calling proceed. */
2591 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
)
2593 struct regcache
*regcache
;
2594 struct gdbarch
*gdbarch
;
2595 struct thread_info
*tp
;
2597 struct address_space
*aspace
;
2599 /* If we're stopped at a fork/vfork, follow the branch set by the
2600 "set follow-fork-mode" command; otherwise, we'll just proceed
2601 resuming the current thread. */
2602 if (!follow_fork ())
2604 /* The target for some reason decided not to resume. */
2606 if (target_can_async_p ())
2607 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2611 /* We'll update this if & when we switch to a new thread. */
2612 previous_inferior_ptid
= inferior_ptid
;
2614 regcache
= get_current_regcache ();
2615 gdbarch
= get_regcache_arch (regcache
);
2616 aspace
= get_regcache_aspace (regcache
);
2617 pc
= regcache_read_pc (regcache
);
2618 tp
= inferior_thread ();
2620 /* Fill in with reasonable starting values. */
2621 init_thread_stepping_state (tp
);
2623 if (addr
== (CORE_ADDR
) -1)
2626 && breakpoint_here_p (aspace
, pc
) == ordinary_breakpoint_here
2627 && execution_direction
!= EXEC_REVERSE
)
2628 /* There is a breakpoint at the address we will resume at,
2629 step one instruction before inserting breakpoints so that
2630 we do not stop right away (and report a second hit at this
2633 Note, we don't do this in reverse, because we won't
2634 actually be executing the breakpoint insn anyway.
2635 We'll be (un-)executing the previous instruction. */
2636 tp
->stepping_over_breakpoint
= 1;
2637 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2638 && gdbarch_single_step_through_delay (gdbarch
,
2639 get_current_frame ()))
2640 /* We stepped onto an instruction that needs to be stepped
2641 again before re-inserting the breakpoint, do so. */
2642 tp
->stepping_over_breakpoint
= 1;
2646 regcache_write_pc (regcache
, addr
);
2649 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2650 tp
->suspend
.stop_signal
= siggnal
;
2652 /* Record the interpreter that issued the execution command that
2653 caused this thread to resume. If the top level interpreter is
2654 MI/async, and the execution command was a CLI command
2655 (next/step/etc.), we'll want to print stop event output to the MI
2656 console channel (the stepped-to line, etc.), as if the user
2657 entered the execution command on a real GDB console. */
2658 inferior_thread ()->control
.command_interp
= command_interp ();
2661 fprintf_unfiltered (gdb_stdlog
,
2662 "infrun: proceed (addr=%s, signal=%s)\n",
2663 paddress (gdbarch
, addr
),
2664 gdb_signal_to_symbol_string (siggnal
));
2667 /* In non-stop, each thread is handled individually. The context
2668 must already be set to the right thread here. */
2672 struct thread_info
*step_over
;
2674 /* In a multi-threaded task we may select another thread and
2675 then continue or step.
2677 But if the old thread was stopped at a breakpoint, it will
2678 immediately cause another breakpoint stop without any
2679 execution (i.e. it will report a breakpoint hit incorrectly).
2680 So we must step over it first.
2682 Look for a thread other than the current (TP) that reported a
2683 breakpoint hit and hasn't been resumed yet since. */
2684 step_over
= find_thread_needs_step_over (tp
);
2685 if (step_over
!= NULL
)
2688 fprintf_unfiltered (gdb_stdlog
,
2689 "infrun: need to step-over [%s] first\n",
2690 target_pid_to_str (step_over
->ptid
));
2692 /* Store the prev_pc for the stepping thread too, needed by
2693 switch_back_to_stepped_thread. */
2694 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2695 switch_to_thread (step_over
->ptid
);
2700 /* If we need to step over a breakpoint, and we're not using
2701 displaced stepping to do so, insert all breakpoints (watchpoints,
2702 etc.) but the one we're stepping over, step one instruction, and
2703 then re-insert the breakpoint when that step is finished. */
2704 if (tp
->stepping_over_breakpoint
&& !use_displaced_stepping (gdbarch
))
2706 struct regcache
*regcache
= get_current_regcache ();
2708 set_step_over_info (get_regcache_aspace (regcache
),
2709 regcache_read_pc (regcache
), 0);
2712 clear_step_over_info ();
2714 insert_breakpoints ();
2716 tp
->control
.trap_expected
= tp
->stepping_over_breakpoint
;
2718 annotate_starting ();
2720 /* Make sure that output from GDB appears before output from the
2722 gdb_flush (gdb_stdout
);
2724 /* Refresh prev_pc value just prior to resuming. This used to be
2725 done in stop_waiting, however, setting prev_pc there did not handle
2726 scenarios such as inferior function calls or returning from
2727 a function via the return command. In those cases, the prev_pc
2728 value was not set properly for subsequent commands. The prev_pc value
2729 is used to initialize the starting line number in the ecs. With an
2730 invalid value, the gdb next command ends up stopping at the position
2731 represented by the next line table entry past our start position.
2732 On platforms that generate one line table entry per line, this
2733 is not a problem. However, on the ia64, the compiler generates
2734 extraneous line table entries that do not increase the line number.
2735 When we issue the gdb next command on the ia64 after an inferior call
2736 or a return command, we often end up a few instructions forward, still
2737 within the original line we started.
2739 An attempt was made to refresh the prev_pc at the same time the
2740 execution_control_state is initialized (for instance, just before
2741 waiting for an inferior event). But this approach did not work
2742 because of platforms that use ptrace, where the pc register cannot
2743 be read unless the inferior is stopped. At that point, we are not
2744 guaranteed the inferior is stopped and so the regcache_read_pc() call
2745 can fail. Setting the prev_pc value here ensures the value is updated
2746 correctly when the inferior is stopped. */
2747 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2749 /* Resume inferior. */
2750 resume (tp
->suspend
.stop_signal
);
2752 /* Wait for it to stop (if not standalone)
2753 and in any case decode why it stopped, and act accordingly. */
2754 /* Do this only if we are not using the event loop, or if the target
2755 does not support asynchronous execution. */
2756 if (!target_can_async_p ())
2758 wait_for_inferior ();
2764 /* Start remote-debugging of a machine over a serial link. */
2767 start_remote (int from_tty
)
2769 struct inferior
*inferior
;
2771 inferior
= current_inferior ();
2772 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2774 /* Always go on waiting for the target, regardless of the mode. */
2775 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2776 indicate to wait_for_inferior that a target should timeout if
2777 nothing is returned (instead of just blocking). Because of this,
2778 targets expecting an immediate response need to, internally, set
2779 things up so that the target_wait() is forced to eventually
2781 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2782 differentiate to its caller what the state of the target is after
2783 the initial open has been performed. Here we're assuming that
2784 the target has stopped. It should be possible to eventually have
2785 target_open() return to the caller an indication that the target
2786 is currently running and GDB state should be set to the same as
2787 for an async run. */
2788 wait_for_inferior ();
2790 /* Now that the inferior has stopped, do any bookkeeping like
2791 loading shared libraries. We want to do this before normal_stop,
2792 so that the displayed frame is up to date. */
2793 post_create_inferior (¤t_target
, from_tty
);
2798 /* Initialize static vars when a new inferior begins. */
2801 init_wait_for_inferior (void)
2803 /* These are meaningless until the first time through wait_for_inferior. */
2805 breakpoint_init_inferior (inf_starting
);
2807 clear_proceed_status (0);
2809 target_last_wait_ptid
= minus_one_ptid
;
2811 previous_inferior_ptid
= inferior_ptid
;
2813 /* Discard any skipped inlined frames. */
2814 clear_inline_frame_state (minus_one_ptid
);
2818 /* Data to be passed around while handling an event. This data is
2819 discarded between events. */
2820 struct execution_control_state
2823 /* The thread that got the event, if this was a thread event; NULL
2825 struct thread_info
*event_thread
;
2827 struct target_waitstatus ws
;
2828 int stop_func_filled_in
;
2829 CORE_ADDR stop_func_start
;
2830 CORE_ADDR stop_func_end
;
2831 const char *stop_func_name
;
2834 /* True if the event thread hit the single-step breakpoint of
2835 another thread. Thus the event doesn't cause a stop, the thread
2836 needs to be single-stepped past the single-step breakpoint before
2837 we can switch back to the original stepping thread. */
2838 int hit_singlestep_breakpoint
;
2841 static void handle_inferior_event (struct execution_control_state
*ecs
);
2843 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2844 struct execution_control_state
*ecs
);
2845 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2846 struct execution_control_state
*ecs
);
2847 static void handle_signal_stop (struct execution_control_state
*ecs
);
2848 static void check_exception_resume (struct execution_control_state
*,
2849 struct frame_info
*);
2851 static void end_stepping_range (struct execution_control_state
*ecs
);
2852 static void stop_waiting (struct execution_control_state
*ecs
);
2853 static void prepare_to_wait (struct execution_control_state
*ecs
);
2854 static void keep_going (struct execution_control_state
*ecs
);
2855 static void process_event_stop_test (struct execution_control_state
*ecs
);
2856 static int switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
2858 /* Callback for iterate over threads. If the thread is stopped, but
2859 the user/frontend doesn't know about that yet, go through
2860 normal_stop, as if the thread had just stopped now. ARG points at
2861 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2862 ptid_is_pid(PTID) is true, applies to all threads of the process
2863 pointed at by PTID. Otherwise, apply only to the thread pointed by
2867 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2869 ptid_t ptid
= * (ptid_t
*) arg
;
2871 if ((ptid_equal (info
->ptid
, ptid
)
2872 || ptid_equal (minus_one_ptid
, ptid
)
2873 || (ptid_is_pid (ptid
)
2874 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2875 && is_running (info
->ptid
)
2876 && !is_executing (info
->ptid
))
2878 struct cleanup
*old_chain
;
2879 struct execution_control_state ecss
;
2880 struct execution_control_state
*ecs
= &ecss
;
2882 memset (ecs
, 0, sizeof (*ecs
));
2884 old_chain
= make_cleanup_restore_current_thread ();
2886 overlay_cache_invalid
= 1;
2887 /* Flush target cache before starting to handle each event.
2888 Target was running and cache could be stale. This is just a
2889 heuristic. Running threads may modify target memory, but we
2890 don't get any event. */
2891 target_dcache_invalidate ();
2893 /* Go through handle_inferior_event/normal_stop, so we always
2894 have consistent output as if the stop event had been
2896 ecs
->ptid
= info
->ptid
;
2897 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2898 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2899 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2901 handle_inferior_event (ecs
);
2903 if (!ecs
->wait_some_more
)
2905 struct thread_info
*tp
;
2909 /* Finish off the continuations. */
2910 tp
= inferior_thread ();
2911 do_all_intermediate_continuations_thread (tp
, 1);
2912 do_all_continuations_thread (tp
, 1);
2915 do_cleanups (old_chain
);
2921 /* This function is attached as a "thread_stop_requested" observer.
2922 Cleanup local state that assumed the PTID was to be resumed, and
2923 report the stop to the frontend. */
2926 infrun_thread_stop_requested (ptid_t ptid
)
2928 struct displaced_step_inferior_state
*displaced
;
2930 /* PTID was requested to stop. Remove it from the displaced
2931 stepping queue, so we don't try to resume it automatically. */
2933 for (displaced
= displaced_step_inferior_states
;
2935 displaced
= displaced
->next
)
2937 struct displaced_step_request
*it
, **prev_next_p
;
2939 it
= displaced
->step_request_queue
;
2940 prev_next_p
= &displaced
->step_request_queue
;
2943 if (ptid_match (it
->ptid
, ptid
))
2945 *prev_next_p
= it
->next
;
2951 prev_next_p
= &it
->next
;
2958 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2962 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2964 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2965 nullify_last_target_wait_ptid ();
2968 /* Delete the step resume, single-step and longjmp/exception resume
2969 breakpoints of TP. */
2972 delete_thread_infrun_breakpoints (struct thread_info
*tp
)
2974 delete_step_resume_breakpoint (tp
);
2975 delete_exception_resume_breakpoint (tp
);
2976 delete_single_step_breakpoints (tp
);
2979 /* If the target still has execution, call FUNC for each thread that
2980 just stopped. In all-stop, that's all the non-exited threads; in
2981 non-stop, that's the current thread, only. */
2983 typedef void (*for_each_just_stopped_thread_callback_func
)
2984 (struct thread_info
*tp
);
2987 for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func
)
2989 if (!target_has_execution
|| ptid_equal (inferior_ptid
, null_ptid
))
2994 /* If in non-stop mode, only the current thread stopped. */
2995 func (inferior_thread ());
2999 struct thread_info
*tp
;
3001 /* In all-stop mode, all threads have stopped. */
3002 ALL_NON_EXITED_THREADS (tp
)
3009 /* Delete the step resume and longjmp/exception resume breakpoints of
3010 the threads that just stopped. */
3013 delete_just_stopped_threads_infrun_breakpoints (void)
3015 for_each_just_stopped_thread (delete_thread_infrun_breakpoints
);
3018 /* Delete the single-step breakpoints of the threads that just
3022 delete_just_stopped_threads_single_step_breakpoints (void)
3024 for_each_just_stopped_thread (delete_single_step_breakpoints
);
3027 /* A cleanup wrapper. */
3030 delete_just_stopped_threads_infrun_breakpoints_cleanup (void *arg
)
3032 delete_just_stopped_threads_infrun_breakpoints ();
3035 /* Pretty print the results of target_wait, for debugging purposes. */
3038 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
3039 const struct target_waitstatus
*ws
)
3041 char *status_string
= target_waitstatus_to_string (ws
);
3042 struct ui_file
*tmp_stream
= mem_fileopen ();
3045 /* The text is split over several lines because it was getting too long.
3046 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
3047 output as a unit; we want only one timestamp printed if debug_timestamp
3050 fprintf_unfiltered (tmp_stream
,
3051 "infrun: target_wait (%d.%ld.%ld",
3052 ptid_get_pid (waiton_ptid
),
3053 ptid_get_lwp (waiton_ptid
),
3054 ptid_get_tid (waiton_ptid
));
3055 if (ptid_get_pid (waiton_ptid
) != -1)
3056 fprintf_unfiltered (tmp_stream
,
3057 " [%s]", target_pid_to_str (waiton_ptid
));
3058 fprintf_unfiltered (tmp_stream
, ", status) =\n");
3059 fprintf_unfiltered (tmp_stream
,
3060 "infrun: %d.%ld.%ld [%s],\n",
3061 ptid_get_pid (result_ptid
),
3062 ptid_get_lwp (result_ptid
),
3063 ptid_get_tid (result_ptid
),
3064 target_pid_to_str (result_ptid
));
3065 fprintf_unfiltered (tmp_stream
,
3069 text
= ui_file_xstrdup (tmp_stream
, NULL
);
3071 /* This uses %s in part to handle %'s in the text, but also to avoid
3072 a gcc error: the format attribute requires a string literal. */
3073 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
3075 xfree (status_string
);
3077 ui_file_delete (tmp_stream
);
3080 /* Prepare and stabilize the inferior for detaching it. E.g.,
3081 detaching while a thread is displaced stepping is a recipe for
3082 crashing it, as nothing would readjust the PC out of the scratch
3086 prepare_for_detach (void)
3088 struct inferior
*inf
= current_inferior ();
3089 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
3090 struct cleanup
*old_chain_1
;
3091 struct displaced_step_inferior_state
*displaced
;
3093 displaced
= get_displaced_stepping_state (inf
->pid
);
3095 /* Is any thread of this process displaced stepping? If not,
3096 there's nothing else to do. */
3097 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
3101 fprintf_unfiltered (gdb_stdlog
,
3102 "displaced-stepping in-process while detaching");
3104 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
3107 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
3109 struct cleanup
*old_chain_2
;
3110 struct execution_control_state ecss
;
3111 struct execution_control_state
*ecs
;
3114 memset (ecs
, 0, sizeof (*ecs
));
3116 overlay_cache_invalid
= 1;
3117 /* Flush target cache before starting to handle each event.
3118 Target was running and cache could be stale. This is just a
3119 heuristic. Running threads may modify target memory, but we
3120 don't get any event. */
3121 target_dcache_invalidate ();
3123 if (deprecated_target_wait_hook
)
3124 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
3126 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
3129 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
3131 /* If an error happens while handling the event, propagate GDB's
3132 knowledge of the executing state to the frontend/user running
3134 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
3137 /* Now figure out what to do with the result of the result. */
3138 handle_inferior_event (ecs
);
3140 /* No error, don't finish the state yet. */
3141 discard_cleanups (old_chain_2
);
3143 /* Breakpoints and watchpoints are not installed on the target
3144 at this point, and signals are passed directly to the
3145 inferior, so this must mean the process is gone. */
3146 if (!ecs
->wait_some_more
)
3148 discard_cleanups (old_chain_1
);
3149 error (_("Program exited while detaching"));
3153 discard_cleanups (old_chain_1
);
3156 /* Wait for control to return from inferior to debugger.
3158 If inferior gets a signal, we may decide to start it up again
3159 instead of returning. That is why there is a loop in this function.
3160 When this function actually returns it means the inferior
3161 should be left stopped and GDB should read more commands. */
3164 wait_for_inferior (void)
3166 struct cleanup
*old_cleanups
;
3167 struct cleanup
*thread_state_chain
;
3171 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
3174 = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup
,
3177 /* If an error happens while handling the event, propagate GDB's
3178 knowledge of the executing state to the frontend/user running
3180 thread_state_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
3184 struct execution_control_state ecss
;
3185 struct execution_control_state
*ecs
= &ecss
;
3186 ptid_t waiton_ptid
= minus_one_ptid
;
3188 memset (ecs
, 0, sizeof (*ecs
));
3190 overlay_cache_invalid
= 1;
3192 /* Flush target cache before starting to handle each event.
3193 Target was running and cache could be stale. This is just a
3194 heuristic. Running threads may modify target memory, but we
3195 don't get any event. */
3196 target_dcache_invalidate ();
3198 if (deprecated_target_wait_hook
)
3199 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
3201 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
3204 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3206 /* Now figure out what to do with the result of the result. */
3207 handle_inferior_event (ecs
);
3209 if (!ecs
->wait_some_more
)
3213 /* No error, don't finish the state yet. */
3214 discard_cleanups (thread_state_chain
);
3216 do_cleanups (old_cleanups
);
3219 /* Cleanup that reinstalls the readline callback handler, if the
3220 target is running in the background. If while handling the target
3221 event something triggered a secondary prompt, like e.g., a
3222 pagination prompt, we'll have removed the callback handler (see
3223 gdb_readline_wrapper_line). Need to do this as we go back to the
3224 event loop, ready to process further input. Note this has no
3225 effect if the handler hasn't actually been removed, because calling
3226 rl_callback_handler_install resets the line buffer, thus losing
3230 reinstall_readline_callback_handler_cleanup (void *arg
)
3232 if (!interpreter_async
)
3234 /* We're not going back to the top level event loop yet. Don't
3235 install the readline callback, as it'd prep the terminal,
3236 readline-style (raw, noecho) (e.g., --batch). We'll install
3237 it the next time the prompt is displayed, when we're ready
3242 if (async_command_editing_p
&& !sync_execution
)
3243 gdb_rl_callback_handler_reinstall ();
3246 /* Asynchronous version of wait_for_inferior. It is called by the
3247 event loop whenever a change of state is detected on the file
3248 descriptor corresponding to the target. It can be called more than
3249 once to complete a single execution command. In such cases we need
3250 to keep the state in a global variable ECSS. If it is the last time
3251 that this function is called for a single execution command, then
3252 report to the user that the inferior has stopped, and do the
3253 necessary cleanups. */
3256 fetch_inferior_event (void *client_data
)
3258 struct execution_control_state ecss
;
3259 struct execution_control_state
*ecs
= &ecss
;
3260 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
3261 struct cleanup
*ts_old_chain
;
3262 int was_sync
= sync_execution
;
3264 ptid_t waiton_ptid
= minus_one_ptid
;
3266 memset (ecs
, 0, sizeof (*ecs
));
3268 /* End up with readline processing input, if necessary. */
3269 make_cleanup (reinstall_readline_callback_handler_cleanup
, NULL
);
3271 /* We're handling a live event, so make sure we're doing live
3272 debugging. If we're looking at traceframes while the target is
3273 running, we're going to need to get back to that mode after
3274 handling the event. */
3277 make_cleanup_restore_current_traceframe ();
3278 set_current_traceframe (-1);
3282 /* In non-stop mode, the user/frontend should not notice a thread
3283 switch due to internal events. Make sure we reverse to the
3284 user selected thread and frame after handling the event and
3285 running any breakpoint commands. */
3286 make_cleanup_restore_current_thread ();
3288 overlay_cache_invalid
= 1;
3289 /* Flush target cache before starting to handle each event. Target
3290 was running and cache could be stale. This is just a heuristic.
3291 Running threads may modify target memory, but we don't get any
3293 target_dcache_invalidate ();
3295 make_cleanup_restore_integer (&execution_direction
);
3296 execution_direction
= target_execution_direction ();
3298 if (deprecated_target_wait_hook
)
3300 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
3302 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
3305 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3307 /* If an error happens while handling the event, propagate GDB's
3308 knowledge of the executing state to the frontend/user running
3311 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
3313 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
3315 /* Get executed before make_cleanup_restore_current_thread above to apply
3316 still for the thread which has thrown the exception. */
3317 make_bpstat_clear_actions_cleanup ();
3319 make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup
, NULL
);
3321 /* Now figure out what to do with the result of the result. */
3322 handle_inferior_event (ecs
);
3324 if (!ecs
->wait_some_more
)
3326 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
3328 delete_just_stopped_threads_infrun_breakpoints ();
3330 /* We may not find an inferior if this was a process exit. */
3331 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
3334 if (target_has_execution
3335 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
3336 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3337 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3338 && ecs
->event_thread
->step_multi
3339 && ecs
->event_thread
->control
.stop_step
)
3340 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
3343 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
3348 /* No error, don't finish the thread states yet. */
3349 discard_cleanups (ts_old_chain
);
3351 /* Revert thread and frame. */
3352 do_cleanups (old_chain
);
3354 /* If the inferior was in sync execution mode, and now isn't,
3355 restore the prompt (a synchronous execution command has finished,
3356 and we're ready for input). */
3357 if (interpreter_async
&& was_sync
&& !sync_execution
)
3358 observer_notify_sync_execution_done ();
3362 && exec_done_display_p
3363 && (ptid_equal (inferior_ptid
, null_ptid
)
3364 || !is_running (inferior_ptid
)))
3365 printf_unfiltered (_("completed.\n"));
3368 /* Record the frame and location we're currently stepping through. */
3370 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
3372 struct thread_info
*tp
= inferior_thread ();
3374 tp
->control
.step_frame_id
= get_frame_id (frame
);
3375 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
3377 tp
->current_symtab
= sal
.symtab
;
3378 tp
->current_line
= sal
.line
;
3381 /* Clear context switchable stepping state. */
3384 init_thread_stepping_state (struct thread_info
*tss
)
3386 tss
->stepped_breakpoint
= 0;
3387 tss
->stepping_over_breakpoint
= 0;
3388 tss
->stepping_over_watchpoint
= 0;
3389 tss
->step_after_step_resume_breakpoint
= 0;
3392 /* Set the cached copy of the last ptid/waitstatus. */
3395 set_last_target_status (ptid_t ptid
, struct target_waitstatus status
)
3397 target_last_wait_ptid
= ptid
;
3398 target_last_waitstatus
= status
;
3401 /* Return the cached copy of the last pid/waitstatus returned by
3402 target_wait()/deprecated_target_wait_hook(). The data is actually
3403 cached by handle_inferior_event(), which gets called immediately
3404 after target_wait()/deprecated_target_wait_hook(). */
3407 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
3409 *ptidp
= target_last_wait_ptid
;
3410 *status
= target_last_waitstatus
;
3414 nullify_last_target_wait_ptid (void)
3416 target_last_wait_ptid
= minus_one_ptid
;
3419 /* Switch thread contexts. */
3422 context_switch (ptid_t ptid
)
3424 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
3426 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
3427 target_pid_to_str (inferior_ptid
));
3428 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
3429 target_pid_to_str (ptid
));
3432 switch_to_thread (ptid
);
3436 adjust_pc_after_break (struct execution_control_state
*ecs
)
3438 struct regcache
*regcache
;
3439 struct gdbarch
*gdbarch
;
3440 struct address_space
*aspace
;
3441 CORE_ADDR breakpoint_pc
, decr_pc
;
3443 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3444 we aren't, just return.
3446 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3447 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3448 implemented by software breakpoints should be handled through the normal
3451 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3452 different signals (SIGILL or SIGEMT for instance), but it is less
3453 clear where the PC is pointing afterwards. It may not match
3454 gdbarch_decr_pc_after_break. I don't know any specific target that
3455 generates these signals at breakpoints (the code has been in GDB since at
3456 least 1992) so I can not guess how to handle them here.
3458 In earlier versions of GDB, a target with
3459 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3460 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3461 target with both of these set in GDB history, and it seems unlikely to be
3462 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3464 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
3467 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
3470 /* In reverse execution, when a breakpoint is hit, the instruction
3471 under it has already been de-executed. The reported PC always
3472 points at the breakpoint address, so adjusting it further would
3473 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3476 B1 0x08000000 : INSN1
3477 B2 0x08000001 : INSN2
3479 PC -> 0x08000003 : INSN4
3481 Say you're stopped at 0x08000003 as above. Reverse continuing
3482 from that point should hit B2 as below. Reading the PC when the
3483 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3484 been de-executed already.
3486 B1 0x08000000 : INSN1
3487 B2 PC -> 0x08000001 : INSN2
3491 We can't apply the same logic as for forward execution, because
3492 we would wrongly adjust the PC to 0x08000000, since there's a
3493 breakpoint at PC - 1. We'd then report a hit on B1, although
3494 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3496 if (execution_direction
== EXEC_REVERSE
)
3499 /* If the target can tell whether the thread hit a SW breakpoint,
3500 trust it. Targets that can tell also adjust the PC
3502 if (target_supports_stopped_by_sw_breakpoint ())
3505 /* Note that relying on whether a breakpoint is planted in memory to
3506 determine this can fail. E.g,. the breakpoint could have been
3507 removed since. Or the thread could have been told to step an
3508 instruction the size of a breakpoint instruction, and only
3509 _after_ was a breakpoint inserted at its address. */
3511 /* If this target does not decrement the PC after breakpoints, then
3512 we have nothing to do. */
3513 regcache
= get_thread_regcache (ecs
->ptid
);
3514 gdbarch
= get_regcache_arch (regcache
);
3516 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
3520 aspace
= get_regcache_aspace (regcache
);
3522 /* Find the location where (if we've hit a breakpoint) the
3523 breakpoint would be. */
3524 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
3526 /* If the target can't tell whether a software breakpoint triggered,
3527 fallback to figuring it out based on breakpoints we think were
3528 inserted in the target, and on whether the thread was stepped or
3531 /* Check whether there actually is a software breakpoint inserted at
3534 If in non-stop mode, a race condition is possible where we've
3535 removed a breakpoint, but stop events for that breakpoint were
3536 already queued and arrive later. To suppress those spurious
3537 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3538 and retire them after a number of stop events are reported. Note
3539 this is an heuristic and can thus get confused. The real fix is
3540 to get the "stopped by SW BP and needs adjustment" info out of
3541 the target/kernel (and thus never reach here; see above). */
3542 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3543 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3545 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3547 if (record_full_is_used ())
3548 record_full_gdb_operation_disable_set ();
3550 /* When using hardware single-step, a SIGTRAP is reported for both
3551 a completed single-step and a software breakpoint. Need to
3552 differentiate between the two, as the latter needs adjusting
3553 but the former does not.
3555 The SIGTRAP can be due to a completed hardware single-step only if
3556 - we didn't insert software single-step breakpoints
3557 - this thread is currently being stepped
3559 If any of these events did not occur, we must have stopped due
3560 to hitting a software breakpoint, and have to back up to the
3563 As a special case, we could have hardware single-stepped a
3564 software breakpoint. In this case (prev_pc == breakpoint_pc),
3565 we also need to back up to the breakpoint address. */
3567 if (thread_has_single_step_breakpoints_set (ecs
->event_thread
)
3568 || !currently_stepping (ecs
->event_thread
)
3569 || (ecs
->event_thread
->stepped_breakpoint
3570 && ecs
->event_thread
->prev_pc
== breakpoint_pc
))
3571 regcache_write_pc (regcache
, breakpoint_pc
);
3573 do_cleanups (old_cleanups
);
3578 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3580 for (frame
= get_prev_frame (frame
);
3582 frame
= get_prev_frame (frame
))
3584 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3586 if (get_frame_type (frame
) != INLINE_FRAME
)
3593 /* Auxiliary function that handles syscall entry/return events.
3594 It returns 1 if the inferior should keep going (and GDB
3595 should ignore the event), or 0 if the event deserves to be
3599 handle_syscall_event (struct execution_control_state
*ecs
)
3601 struct regcache
*regcache
;
3604 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3605 context_switch (ecs
->ptid
);
3607 regcache
= get_thread_regcache (ecs
->ptid
);
3608 syscall_number
= ecs
->ws
.value
.syscall_number
;
3609 stop_pc
= regcache_read_pc (regcache
);
3611 if (catch_syscall_enabled () > 0
3612 && catching_syscall_number (syscall_number
) > 0)
3615 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3618 ecs
->event_thread
->control
.stop_bpstat
3619 = bpstat_stop_status (get_regcache_aspace (regcache
),
3620 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3622 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3624 /* Catchpoint hit. */
3629 /* If no catchpoint triggered for this, then keep going. */
3634 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3637 fill_in_stop_func (struct gdbarch
*gdbarch
,
3638 struct execution_control_state
*ecs
)
3640 if (!ecs
->stop_func_filled_in
)
3642 /* Don't care about return value; stop_func_start and stop_func_name
3643 will both be 0 if it doesn't work. */
3644 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3645 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3646 ecs
->stop_func_start
3647 += gdbarch_deprecated_function_start_offset (gdbarch
);
3649 if (gdbarch_skip_entrypoint_p (gdbarch
))
3650 ecs
->stop_func_start
= gdbarch_skip_entrypoint (gdbarch
,
3651 ecs
->stop_func_start
);
3653 ecs
->stop_func_filled_in
= 1;
3658 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3660 static enum stop_kind
3661 get_inferior_stop_soon (ptid_t ptid
)
3663 struct inferior
*inf
= find_inferior_ptid (ptid
);
3665 gdb_assert (inf
!= NULL
);
3666 return inf
->control
.stop_soon
;
3669 /* Given an execution control state that has been freshly filled in by
3670 an event from the inferior, figure out what it means and take
3673 The alternatives are:
3675 1) stop_waiting and return; to really stop and return to the
3678 2) keep_going and return; to wait for the next event (set
3679 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3683 handle_inferior_event (struct execution_control_state
*ecs
)
3685 enum stop_kind stop_soon
;
3687 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3689 /* We had an event in the inferior, but we are not interested in
3690 handling it at this level. The lower layers have already
3691 done what needs to be done, if anything.
3693 One of the possible circumstances for this is when the
3694 inferior produces output for the console. The inferior has
3695 not stopped, and we are ignoring the event. Another possible
3696 circumstance is any event which the lower level knows will be
3697 reported multiple times without an intervening resume. */
3699 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3700 prepare_to_wait (ecs
);
3704 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3705 && target_can_async_p () && !sync_execution
)
3707 /* There were no unwaited-for children left in the target, but,
3708 we're not synchronously waiting for events either. Just
3709 ignore. Otherwise, if we were running a synchronous
3710 execution command, we need to cancel it and give the user
3711 back the terminal. */
3713 fprintf_unfiltered (gdb_stdlog
,
3714 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3715 prepare_to_wait (ecs
);
3719 /* Cache the last pid/waitstatus. */
3720 set_last_target_status (ecs
->ptid
, ecs
->ws
);
3722 /* Always clear state belonging to the previous time we stopped. */
3723 stop_stack_dummy
= STOP_NONE
;
3725 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3727 /* No unwaited-for children left. IOW, all resumed children
3730 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3732 stop_print_frame
= 0;
3737 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3738 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3740 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3741 /* If it's a new thread, add it to the thread database. */
3742 if (ecs
->event_thread
== NULL
)
3743 ecs
->event_thread
= add_thread (ecs
->ptid
);
3745 /* Disable range stepping. If the next step request could use a
3746 range, this will be end up re-enabled then. */
3747 ecs
->event_thread
->control
.may_range_step
= 0;
3750 /* Dependent on valid ECS->EVENT_THREAD. */
3751 adjust_pc_after_break (ecs
);
3753 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3754 reinit_frame_cache ();
3756 breakpoint_retire_moribund ();
3758 /* First, distinguish signals caused by the debugger from signals
3759 that have to do with the program's own actions. Note that
3760 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3761 on the operating system version. Here we detect when a SIGILL or
3762 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3763 something similar for SIGSEGV, since a SIGSEGV will be generated
3764 when we're trying to execute a breakpoint instruction on a
3765 non-executable stack. This happens for call dummy breakpoints
3766 for architectures like SPARC that place call dummies on the
3768 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3769 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3770 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3771 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3773 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3775 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3776 regcache_read_pc (regcache
)))
3779 fprintf_unfiltered (gdb_stdlog
,
3780 "infrun: Treating signal as SIGTRAP\n");
3781 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3785 /* Mark the non-executing threads accordingly. In all-stop, all
3786 threads of all processes are stopped when we get any event
3787 reported. In non-stop mode, only the event thread stops. If
3788 we're handling a process exit in non-stop mode, there's nothing
3789 to do, as threads of the dead process are gone, and threads of
3790 any other process were left running. */
3792 set_executing (minus_one_ptid
, 0);
3793 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3794 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3795 set_executing (ecs
->ptid
, 0);
3797 switch (ecs
->ws
.kind
)
3799 case TARGET_WAITKIND_LOADED
:
3801 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3802 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3803 context_switch (ecs
->ptid
);
3804 /* Ignore gracefully during startup of the inferior, as it might
3805 be the shell which has just loaded some objects, otherwise
3806 add the symbols for the newly loaded objects. Also ignore at
3807 the beginning of an attach or remote session; we will query
3808 the full list of libraries once the connection is
3811 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3812 if (stop_soon
== NO_STOP_QUIETLY
)
3814 struct regcache
*regcache
;
3816 regcache
= get_thread_regcache (ecs
->ptid
);
3818 handle_solib_event ();
3820 ecs
->event_thread
->control
.stop_bpstat
3821 = bpstat_stop_status (get_regcache_aspace (regcache
),
3822 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3824 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3826 /* A catchpoint triggered. */
3827 process_event_stop_test (ecs
);
3831 /* If requested, stop when the dynamic linker notifies
3832 gdb of events. This allows the user to get control
3833 and place breakpoints in initializer routines for
3834 dynamically loaded objects (among other things). */
3835 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3836 if (stop_on_solib_events
)
3838 /* Make sure we print "Stopped due to solib-event" in
3840 stop_print_frame
= 1;
3847 /* If we are skipping through a shell, or through shared library
3848 loading that we aren't interested in, resume the program. If
3849 we're running the program normally, also resume. */
3850 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3852 /* Loading of shared libraries might have changed breakpoint
3853 addresses. Make sure new breakpoints are inserted. */
3854 if (stop_soon
== NO_STOP_QUIETLY
)
3855 insert_breakpoints ();
3856 resume (GDB_SIGNAL_0
);
3857 prepare_to_wait (ecs
);
3861 /* But stop if we're attaching or setting up a remote
3863 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3864 || stop_soon
== STOP_QUIETLY_REMOTE
)
3867 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3872 internal_error (__FILE__
, __LINE__
,
3873 _("unhandled stop_soon: %d"), (int) stop_soon
);
3875 case TARGET_WAITKIND_SPURIOUS
:
3877 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3878 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3879 context_switch (ecs
->ptid
);
3880 resume (GDB_SIGNAL_0
);
3881 prepare_to_wait (ecs
);
3884 case TARGET_WAITKIND_EXITED
:
3885 case TARGET_WAITKIND_SIGNALLED
:
3888 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3889 fprintf_unfiltered (gdb_stdlog
,
3890 "infrun: TARGET_WAITKIND_EXITED\n");
3892 fprintf_unfiltered (gdb_stdlog
,
3893 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3896 inferior_ptid
= ecs
->ptid
;
3897 set_current_inferior (find_inferior_ptid (ecs
->ptid
));
3898 set_current_program_space (current_inferior ()->pspace
);
3899 handle_vfork_child_exec_or_exit (0);
3900 target_terminal_ours (); /* Must do this before mourn anyway. */
3902 /* Clearing any previous state of convenience variables. */
3903 clear_exit_convenience_vars ();
3905 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3907 /* Record the exit code in the convenience variable $_exitcode, so
3908 that the user can inspect this again later. */
3909 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3910 (LONGEST
) ecs
->ws
.value
.integer
);
3912 /* Also record this in the inferior itself. */
3913 current_inferior ()->has_exit_code
= 1;
3914 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3916 /* Support the --return-child-result option. */
3917 return_child_result_value
= ecs
->ws
.value
.integer
;
3919 observer_notify_exited (ecs
->ws
.value
.integer
);
3923 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3924 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3926 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
3928 /* Set the value of the internal variable $_exitsignal,
3929 which holds the signal uncaught by the inferior. */
3930 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3931 gdbarch_gdb_signal_to_target (gdbarch
,
3932 ecs
->ws
.value
.sig
));
3936 /* We don't have access to the target's method used for
3937 converting between signal numbers (GDB's internal
3938 representation <-> target's representation).
3939 Therefore, we cannot do a good job at displaying this
3940 information to the user. It's better to just warn
3941 her about it (if infrun debugging is enabled), and
3944 fprintf_filtered (gdb_stdlog
, _("\
3945 Cannot fill $_exitsignal with the correct signal number.\n"));
3948 observer_notify_signal_exited (ecs
->ws
.value
.sig
);
3951 gdb_flush (gdb_stdout
);
3952 target_mourn_inferior ();
3953 stop_print_frame
= 0;
3957 /* The following are the only cases in which we keep going;
3958 the above cases end in a continue or goto. */
3959 case TARGET_WAITKIND_FORKED
:
3960 case TARGET_WAITKIND_VFORKED
:
3963 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3964 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3966 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3969 /* Check whether the inferior is displaced stepping. */
3971 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3972 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3973 struct displaced_step_inferior_state
*displaced
3974 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3976 /* If checking displaced stepping is supported, and thread
3977 ecs->ptid is displaced stepping. */
3978 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3980 struct inferior
*parent_inf
3981 = find_inferior_ptid (ecs
->ptid
);
3982 struct regcache
*child_regcache
;
3983 CORE_ADDR parent_pc
;
3985 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3986 indicating that the displaced stepping of syscall instruction
3987 has been done. Perform cleanup for parent process here. Note
3988 that this operation also cleans up the child process for vfork,
3989 because their pages are shared. */
3990 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3992 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3994 /* Restore scratch pad for child process. */
3995 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3998 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3999 the child's PC is also within the scratchpad. Set the child's PC
4000 to the parent's PC value, which has already been fixed up.
4001 FIXME: we use the parent's aspace here, although we're touching
4002 the child, because the child hasn't been added to the inferior
4003 list yet at this point. */
4006 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
4008 parent_inf
->aspace
);
4009 /* Read PC value of parent process. */
4010 parent_pc
= regcache_read_pc (regcache
);
4012 if (debug_displaced
)
4013 fprintf_unfiltered (gdb_stdlog
,
4014 "displaced: write child pc from %s to %s\n",
4016 regcache_read_pc (child_regcache
)),
4017 paddress (gdbarch
, parent_pc
));
4019 regcache_write_pc (child_regcache
, parent_pc
);
4023 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4024 context_switch (ecs
->ptid
);
4026 /* Immediately detach breakpoints from the child before there's
4027 any chance of letting the user delete breakpoints from the
4028 breakpoint lists. If we don't do this early, it's easy to
4029 leave left over traps in the child, vis: "break foo; catch
4030 fork; c; <fork>; del; c; <child calls foo>". We only follow
4031 the fork on the last `continue', and by that time the
4032 breakpoint at "foo" is long gone from the breakpoint table.
4033 If we vforked, then we don't need to unpatch here, since both
4034 parent and child are sharing the same memory pages; we'll
4035 need to unpatch at follow/detach time instead to be certain
4036 that new breakpoints added between catchpoint hit time and
4037 vfork follow are detached. */
4038 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
4040 /* This won't actually modify the breakpoint list, but will
4041 physically remove the breakpoints from the child. */
4042 detach_breakpoints (ecs
->ws
.value
.related_pid
);
4045 delete_just_stopped_threads_single_step_breakpoints ();
4047 /* In case the event is caught by a catchpoint, remember that
4048 the event is to be followed at the next resume of the thread,
4049 and not immediately. */
4050 ecs
->event_thread
->pending_follow
= ecs
->ws
;
4052 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4054 ecs
->event_thread
->control
.stop_bpstat
4055 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4056 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4058 /* If no catchpoint triggered for this, then keep going. Note
4059 that we're interested in knowing the bpstat actually causes a
4060 stop, not just if it may explain the signal. Software
4061 watchpoints, for example, always appear in the bpstat. */
4062 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4068 = (follow_fork_mode_string
== follow_fork_mode_child
);
4070 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4072 should_resume
= follow_fork ();
4075 child
= ecs
->ws
.value
.related_pid
;
4077 /* In non-stop mode, also resume the other branch. */
4078 if (non_stop
&& !detach_fork
)
4081 switch_to_thread (parent
);
4083 switch_to_thread (child
);
4085 ecs
->event_thread
= inferior_thread ();
4086 ecs
->ptid
= inferior_ptid
;
4091 switch_to_thread (child
);
4093 switch_to_thread (parent
);
4095 ecs
->event_thread
= inferior_thread ();
4096 ecs
->ptid
= inferior_ptid
;
4104 process_event_stop_test (ecs
);
4107 case TARGET_WAITKIND_VFORK_DONE
:
4108 /* Done with the shared memory region. Re-insert breakpoints in
4109 the parent, and keep going. */
4112 fprintf_unfiltered (gdb_stdlog
,
4113 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
4115 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4116 context_switch (ecs
->ptid
);
4118 current_inferior ()->waiting_for_vfork_done
= 0;
4119 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
4120 /* This also takes care of reinserting breakpoints in the
4121 previously locked inferior. */
4125 case TARGET_WAITKIND_EXECD
:
4127 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
4129 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4130 context_switch (ecs
->ptid
);
4132 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4134 /* Do whatever is necessary to the parent branch of the vfork. */
4135 handle_vfork_child_exec_or_exit (1);
4137 /* This causes the eventpoints and symbol table to be reset.
4138 Must do this now, before trying to determine whether to
4140 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
4142 ecs
->event_thread
->control
.stop_bpstat
4143 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4144 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4146 /* Note that this may be referenced from inside
4147 bpstat_stop_status above, through inferior_has_execd. */
4148 xfree (ecs
->ws
.value
.execd_pathname
);
4149 ecs
->ws
.value
.execd_pathname
= NULL
;
4151 /* If no catchpoint triggered for this, then keep going. */
4152 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4154 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4158 process_event_stop_test (ecs
);
4161 /* Be careful not to try to gather much state about a thread
4162 that's in a syscall. It's frequently a losing proposition. */
4163 case TARGET_WAITKIND_SYSCALL_ENTRY
:
4165 fprintf_unfiltered (gdb_stdlog
,
4166 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
4167 /* Getting the current syscall number. */
4168 if (handle_syscall_event (ecs
) == 0)
4169 process_event_stop_test (ecs
);
4172 /* Before examining the threads further, step this thread to
4173 get it entirely out of the syscall. (We get notice of the
4174 event when the thread is just on the verge of exiting a
4175 syscall. Stepping one instruction seems to get it back
4177 case TARGET_WAITKIND_SYSCALL_RETURN
:
4179 fprintf_unfiltered (gdb_stdlog
,
4180 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
4181 if (handle_syscall_event (ecs
) == 0)
4182 process_event_stop_test (ecs
);
4185 case TARGET_WAITKIND_STOPPED
:
4187 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
4188 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
4189 handle_signal_stop (ecs
);
4192 case TARGET_WAITKIND_NO_HISTORY
:
4194 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
4195 /* Reverse execution: target ran out of history info. */
4197 delete_just_stopped_threads_single_step_breakpoints ();
4198 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4199 observer_notify_no_history ();
4205 /* Come here when the program has stopped with a signal. */
4208 handle_signal_stop (struct execution_control_state
*ecs
)
4210 struct frame_info
*frame
;
4211 struct gdbarch
*gdbarch
;
4212 int stopped_by_watchpoint
;
4213 enum stop_kind stop_soon
;
4216 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
4218 /* Do we need to clean up the state of a thread that has
4219 completed a displaced single-step? (Doing so usually affects
4220 the PC, so do it here, before we set stop_pc.) */
4221 displaced_step_fixup (ecs
->ptid
,
4222 ecs
->event_thread
->suspend
.stop_signal
);
4224 /* If we either finished a single-step or hit a breakpoint, but
4225 the user wanted this thread to be stopped, pretend we got a
4226 SIG0 (generic unsignaled stop). */
4227 if (ecs
->event_thread
->stop_requested
4228 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4229 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4231 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4235 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
4236 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4237 struct cleanup
*old_chain
= save_inferior_ptid ();
4239 inferior_ptid
= ecs
->ptid
;
4241 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
4242 paddress (gdbarch
, stop_pc
));
4243 if (target_stopped_by_watchpoint ())
4247 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
4249 if (target_stopped_data_address (¤t_target
, &addr
))
4250 fprintf_unfiltered (gdb_stdlog
,
4251 "infrun: stopped data address = %s\n",
4252 paddress (gdbarch
, addr
));
4254 fprintf_unfiltered (gdb_stdlog
,
4255 "infrun: (no data address available)\n");
4258 do_cleanups (old_chain
);
4261 /* This is originated from start_remote(), start_inferior() and
4262 shared libraries hook functions. */
4263 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
4264 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4266 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4267 context_switch (ecs
->ptid
);
4269 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4270 stop_print_frame
= 1;
4275 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4278 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4279 context_switch (ecs
->ptid
);
4281 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4282 stop_print_frame
= 0;
4287 /* This originates from attach_command(). We need to overwrite
4288 the stop_signal here, because some kernels don't ignore a
4289 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4290 See more comments in inferior.h. On the other hand, if we
4291 get a non-SIGSTOP, report it to the user - assume the backend
4292 will handle the SIGSTOP if it should show up later.
4294 Also consider that the attach is complete when we see a
4295 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4296 target extended-remote report it instead of a SIGSTOP
4297 (e.g. gdbserver). We already rely on SIGTRAP being our
4298 signal, so this is no exception.
4300 Also consider that the attach is complete when we see a
4301 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4302 the target to stop all threads of the inferior, in case the
4303 low level attach operation doesn't stop them implicitly. If
4304 they weren't stopped implicitly, then the stub will report a
4305 GDB_SIGNAL_0, meaning: stopped for no particular reason
4306 other than GDB's request. */
4307 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4308 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4309 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4310 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4312 stop_print_frame
= 1;
4314 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4318 /* See if something interesting happened to the non-current thread. If
4319 so, then switch to that thread. */
4320 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4323 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
4325 context_switch (ecs
->ptid
);
4327 if (deprecated_context_hook
)
4328 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
4331 /* At this point, get hold of the now-current thread's frame. */
4332 frame
= get_current_frame ();
4333 gdbarch
= get_frame_arch (frame
);
4335 /* Pull the single step breakpoints out of the target. */
4336 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4338 struct regcache
*regcache
;
4339 struct address_space
*aspace
;
4342 regcache
= get_thread_regcache (ecs
->ptid
);
4343 aspace
= get_regcache_aspace (regcache
);
4344 pc
= regcache_read_pc (regcache
);
4346 /* However, before doing so, if this single-step breakpoint was
4347 actually for another thread, set this thread up for moving
4349 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
4352 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4356 fprintf_unfiltered (gdb_stdlog
,
4357 "infrun: [%s] hit another thread's "
4358 "single-step breakpoint\n",
4359 target_pid_to_str (ecs
->ptid
));
4361 ecs
->hit_singlestep_breakpoint
= 1;
4368 fprintf_unfiltered (gdb_stdlog
,
4369 "infrun: [%s] hit its "
4370 "single-step breakpoint\n",
4371 target_pid_to_str (ecs
->ptid
));
4375 delete_just_stopped_threads_single_step_breakpoints ();
4377 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4378 && ecs
->event_thread
->control
.trap_expected
4379 && ecs
->event_thread
->stepping_over_watchpoint
)
4380 stopped_by_watchpoint
= 0;
4382 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4384 /* If necessary, step over this watchpoint. We'll be back to display
4386 if (stopped_by_watchpoint
4387 && (target_have_steppable_watchpoint
4388 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4390 /* At this point, we are stopped at an instruction which has
4391 attempted to write to a piece of memory under control of
4392 a watchpoint. The instruction hasn't actually executed
4393 yet. If we were to evaluate the watchpoint expression
4394 now, we would get the old value, and therefore no change
4395 would seem to have occurred.
4397 In order to make watchpoints work `right', we really need
4398 to complete the memory write, and then evaluate the
4399 watchpoint expression. We do this by single-stepping the
4402 It may not be necessary to disable the watchpoint to step over
4403 it. For example, the PA can (with some kernel cooperation)
4404 single step over a watchpoint without disabling the watchpoint.
4406 It is far more common to need to disable a watchpoint to step
4407 the inferior over it. If we have non-steppable watchpoints,
4408 we must disable the current watchpoint; it's simplest to
4409 disable all watchpoints.
4411 Any breakpoint at PC must also be stepped over -- if there's
4412 one, it will have already triggered before the watchpoint
4413 triggered, and we either already reported it to the user, or
4414 it didn't cause a stop and we called keep_going. In either
4415 case, if there was a breakpoint at PC, we must be trying to
4417 ecs
->event_thread
->stepping_over_watchpoint
= 1;
4422 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4423 ecs
->event_thread
->stepping_over_watchpoint
= 0;
4424 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4425 ecs
->event_thread
->control
.stop_step
= 0;
4426 stop_print_frame
= 1;
4427 stopped_by_random_signal
= 0;
4429 /* Hide inlined functions starting here, unless we just performed stepi or
4430 nexti. After stepi and nexti, always show the innermost frame (not any
4431 inline function call sites). */
4432 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4434 struct address_space
*aspace
=
4435 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4437 /* skip_inline_frames is expensive, so we avoid it if we can
4438 determine that the address is one where functions cannot have
4439 been inlined. This improves performance with inferiors that
4440 load a lot of shared libraries, because the solib event
4441 breakpoint is defined as the address of a function (i.e. not
4442 inline). Note that we have to check the previous PC as well
4443 as the current one to catch cases when we have just
4444 single-stepped off a breakpoint prior to reinstating it.
4445 Note that we're assuming that the code we single-step to is
4446 not inline, but that's not definitive: there's nothing
4447 preventing the event breakpoint function from containing
4448 inlined code, and the single-step ending up there. If the
4449 user had set a breakpoint on that inlined code, the missing
4450 skip_inline_frames call would break things. Fortunately
4451 that's an extremely unlikely scenario. */
4452 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4453 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4454 && ecs
->event_thread
->control
.trap_expected
4455 && pc_at_non_inline_function (aspace
,
4456 ecs
->event_thread
->prev_pc
,
4459 skip_inline_frames (ecs
->ptid
);
4461 /* Re-fetch current thread's frame in case that invalidated
4463 frame
= get_current_frame ();
4464 gdbarch
= get_frame_arch (frame
);
4468 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4469 && ecs
->event_thread
->control
.trap_expected
4470 && gdbarch_single_step_through_delay_p (gdbarch
)
4471 && currently_stepping (ecs
->event_thread
))
4473 /* We're trying to step off a breakpoint. Turns out that we're
4474 also on an instruction that needs to be stepped multiple
4475 times before it's been fully executing. E.g., architectures
4476 with a delay slot. It needs to be stepped twice, once for
4477 the instruction and once for the delay slot. */
4478 int step_through_delay
4479 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4481 if (debug_infrun
&& step_through_delay
)
4482 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4483 if (ecs
->event_thread
->control
.step_range_end
== 0
4484 && step_through_delay
)
4486 /* The user issued a continue when stopped at a breakpoint.
4487 Set up for another trap and get out of here. */
4488 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4492 else if (step_through_delay
)
4494 /* The user issued a step when stopped at a breakpoint.
4495 Maybe we should stop, maybe we should not - the delay
4496 slot *might* correspond to a line of source. In any
4497 case, don't decide that here, just set
4498 ecs->stepping_over_breakpoint, making sure we
4499 single-step again before breakpoints are re-inserted. */
4500 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4504 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4505 handles this event. */
4506 ecs
->event_thread
->control
.stop_bpstat
4507 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4508 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4510 /* Following in case break condition called a
4512 stop_print_frame
= 1;
4514 /* This is where we handle "moribund" watchpoints. Unlike
4515 software breakpoints traps, hardware watchpoint traps are
4516 always distinguishable from random traps. If no high-level
4517 watchpoint is associated with the reported stop data address
4518 anymore, then the bpstat does not explain the signal ---
4519 simply make sure to ignore it if `stopped_by_watchpoint' is
4523 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4524 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4526 && stopped_by_watchpoint
)
4527 fprintf_unfiltered (gdb_stdlog
,
4528 "infrun: no user watchpoint explains "
4529 "watchpoint SIGTRAP, ignoring\n");
4531 /* NOTE: cagney/2003-03-29: These checks for a random signal
4532 at one stage in the past included checks for an inferior
4533 function call's call dummy's return breakpoint. The original
4534 comment, that went with the test, read:
4536 ``End of a stack dummy. Some systems (e.g. Sony news) give
4537 another signal besides SIGTRAP, so check here as well as
4540 If someone ever tries to get call dummys on a
4541 non-executable stack to work (where the target would stop
4542 with something like a SIGSEGV), then those tests might need
4543 to be re-instated. Given, however, that the tests were only
4544 enabled when momentary breakpoints were not being used, I
4545 suspect that it won't be the case.
4547 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4548 be necessary for call dummies on a non-executable stack on
4551 /* See if the breakpoints module can explain the signal. */
4553 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4554 ecs
->event_thread
->suspend
.stop_signal
);
4556 /* Maybe this was a trap for a software breakpoint that has since
4558 if (random_signal
&& target_stopped_by_sw_breakpoint ())
4560 if (program_breakpoint_here_p (gdbarch
, stop_pc
))
4562 struct regcache
*regcache
;
4565 /* Re-adjust PC to what the program would see if GDB was not
4567 regcache
= get_thread_regcache (ecs
->event_thread
->ptid
);
4568 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4571 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
4573 if (record_full_is_used ())
4574 record_full_gdb_operation_disable_set ();
4576 regcache_write_pc (regcache
, stop_pc
+ decr_pc
);
4578 do_cleanups (old_cleanups
);
4583 /* A delayed software breakpoint event. Ignore the trap. */
4585 fprintf_unfiltered (gdb_stdlog
,
4586 "infrun: delayed software breakpoint "
4587 "trap, ignoring\n");
4592 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
4593 has since been removed. */
4594 if (random_signal
&& target_stopped_by_hw_breakpoint ())
4596 /* A delayed hardware breakpoint event. Ignore the trap. */
4598 fprintf_unfiltered (gdb_stdlog
,
4599 "infrun: delayed hardware breakpoint/watchpoint "
4600 "trap, ignoring\n");
4604 /* If not, perhaps stepping/nexting can. */
4606 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4607 && currently_stepping (ecs
->event_thread
));
4609 /* Perhaps the thread hit a single-step breakpoint of _another_
4610 thread. Single-step breakpoints are transparent to the
4611 breakpoints module. */
4613 random_signal
= !ecs
->hit_singlestep_breakpoint
;
4615 /* No? Perhaps we got a moribund watchpoint. */
4617 random_signal
= !stopped_by_watchpoint
;
4619 /* For the program's own signals, act according to
4620 the signal handling tables. */
4624 /* Signal not for debugging purposes. */
4625 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
4626 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
4629 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
4630 gdb_signal_to_symbol_string (stop_signal
));
4632 stopped_by_random_signal
= 1;
4634 /* Always stop on signals if we're either just gaining control
4635 of the program, or the user explicitly requested this thread
4636 to remain stopped. */
4637 if (stop_soon
!= NO_STOP_QUIETLY
4638 || ecs
->event_thread
->stop_requested
4640 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4646 /* Notify observers the signal has "handle print" set. Note we
4647 returned early above if stopping; normal_stop handles the
4648 printing in that case. */
4649 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4651 /* The signal table tells us to print about this signal. */
4652 target_terminal_ours_for_output ();
4653 observer_notify_signal_received (ecs
->event_thread
->suspend
.stop_signal
);
4654 target_terminal_inferior ();
4657 /* Clear the signal if it should not be passed. */
4658 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4659 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4661 if (ecs
->event_thread
->prev_pc
== stop_pc
4662 && ecs
->event_thread
->control
.trap_expected
4663 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4665 /* We were just starting a new sequence, attempting to
4666 single-step off of a breakpoint and expecting a SIGTRAP.
4667 Instead this signal arrives. This signal will take us out
4668 of the stepping range so GDB needs to remember to, when
4669 the signal handler returns, resume stepping off that
4671 /* To simplify things, "continue" is forced to use the same
4672 code paths as single-step - set a breakpoint at the
4673 signal return address and then, once hit, step off that
4676 fprintf_unfiltered (gdb_stdlog
,
4677 "infrun: signal arrived while stepping over "
4680 insert_hp_step_resume_breakpoint_at_frame (frame
);
4681 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4682 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4683 ecs
->event_thread
->control
.trap_expected
= 0;
4685 /* If we were nexting/stepping some other thread, switch to
4686 it, so that we don't continue it, losing control. */
4687 if (!switch_back_to_stepped_thread (ecs
))
4692 if (ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4693 && (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4694 || ecs
->event_thread
->control
.step_range_end
== 1)
4695 && frame_id_eq (get_stack_frame_id (frame
),
4696 ecs
->event_thread
->control
.step_stack_frame_id
)
4697 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4699 /* The inferior is about to take a signal that will take it
4700 out of the single step range. Set a breakpoint at the
4701 current PC (which is presumably where the signal handler
4702 will eventually return) and then allow the inferior to
4705 Note that this is only needed for a signal delivered
4706 while in the single-step range. Nested signals aren't a
4707 problem as they eventually all return. */
4709 fprintf_unfiltered (gdb_stdlog
,
4710 "infrun: signal may take us out of "
4711 "single-step range\n");
4713 insert_hp_step_resume_breakpoint_at_frame (frame
);
4714 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4715 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4716 ecs
->event_thread
->control
.trap_expected
= 0;
4721 /* Note: step_resume_breakpoint may be non-NULL. This occures
4722 when either there's a nested signal, or when there's a
4723 pending signal enabled just as the signal handler returns
4724 (leaving the inferior at the step-resume-breakpoint without
4725 actually executing it). Either way continue until the
4726 breakpoint is really hit. */
4728 if (!switch_back_to_stepped_thread (ecs
))
4731 fprintf_unfiltered (gdb_stdlog
,
4732 "infrun: random signal, keep going\n");
4739 process_event_stop_test (ecs
);
4742 /* Come here when we've got some debug event / signal we can explain
4743 (IOW, not a random signal), and test whether it should cause a
4744 stop, or whether we should resume the inferior (transparently).
4745 E.g., could be a breakpoint whose condition evaluates false; we
4746 could be still stepping within the line; etc. */
4749 process_event_stop_test (struct execution_control_state
*ecs
)
4751 struct symtab_and_line stop_pc_sal
;
4752 struct frame_info
*frame
;
4753 struct gdbarch
*gdbarch
;
4754 CORE_ADDR jmp_buf_pc
;
4755 struct bpstat_what what
;
4757 /* Handle cases caused by hitting a breakpoint. */
4759 frame
= get_current_frame ();
4760 gdbarch
= get_frame_arch (frame
);
4762 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4764 if (what
.call_dummy
)
4766 stop_stack_dummy
= what
.call_dummy
;
4769 /* If we hit an internal event that triggers symbol changes, the
4770 current frame will be invalidated within bpstat_what (e.g., if we
4771 hit an internal solib event). Re-fetch it. */
4772 frame
= get_current_frame ();
4773 gdbarch
= get_frame_arch (frame
);
4775 switch (what
.main_action
)
4777 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4778 /* If we hit the breakpoint at longjmp while stepping, we
4779 install a momentary breakpoint at the target of the
4783 fprintf_unfiltered (gdb_stdlog
,
4784 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4786 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4788 if (what
.is_longjmp
)
4790 struct value
*arg_value
;
4792 /* If we set the longjmp breakpoint via a SystemTap probe,
4793 then use it to extract the arguments. The destination PC
4794 is the third argument to the probe. */
4795 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4798 jmp_buf_pc
= value_as_address (arg_value
);
4799 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
4801 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4802 || !gdbarch_get_longjmp_target (gdbarch
,
4803 frame
, &jmp_buf_pc
))
4806 fprintf_unfiltered (gdb_stdlog
,
4807 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4808 "(!gdbarch_get_longjmp_target)\n");
4813 /* Insert a breakpoint at resume address. */
4814 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4817 check_exception_resume (ecs
, frame
);
4821 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4823 struct frame_info
*init_frame
;
4825 /* There are several cases to consider.
4827 1. The initiating frame no longer exists. In this case we
4828 must stop, because the exception or longjmp has gone too
4831 2. The initiating frame exists, and is the same as the
4832 current frame. We stop, because the exception or longjmp
4835 3. The initiating frame exists and is different from the
4836 current frame. This means the exception or longjmp has
4837 been caught beneath the initiating frame, so keep going.
4839 4. longjmp breakpoint has been placed just to protect
4840 against stale dummy frames and user is not interested in
4841 stopping around longjmps. */
4844 fprintf_unfiltered (gdb_stdlog
,
4845 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4847 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4849 delete_exception_resume_breakpoint (ecs
->event_thread
);
4851 if (what
.is_longjmp
)
4853 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
4855 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4863 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4867 struct frame_id current_id
4868 = get_frame_id (get_current_frame ());
4869 if (frame_id_eq (current_id
,
4870 ecs
->event_thread
->initiating_frame
))
4872 /* Case 2. Fall through. */
4882 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4884 delete_step_resume_breakpoint (ecs
->event_thread
);
4886 end_stepping_range (ecs
);
4890 case BPSTAT_WHAT_SINGLE
:
4892 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4893 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4894 /* Still need to check other stuff, at least the case where we
4895 are stepping and step out of the right range. */
4898 case BPSTAT_WHAT_STEP_RESUME
:
4900 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4902 delete_step_resume_breakpoint (ecs
->event_thread
);
4903 if (ecs
->event_thread
->control
.proceed_to_finish
4904 && execution_direction
== EXEC_REVERSE
)
4906 struct thread_info
*tp
= ecs
->event_thread
;
4908 /* We are finishing a function in reverse, and just hit the
4909 step-resume breakpoint at the start address of the
4910 function, and we're almost there -- just need to back up
4911 by one more single-step, which should take us back to the
4913 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4917 fill_in_stop_func (gdbarch
, ecs
);
4918 if (stop_pc
== ecs
->stop_func_start
4919 && execution_direction
== EXEC_REVERSE
)
4921 /* We are stepping over a function call in reverse, and just
4922 hit the step-resume breakpoint at the start address of
4923 the function. Go back to single-stepping, which should
4924 take us back to the function call. */
4925 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4931 case BPSTAT_WHAT_STOP_NOISY
:
4933 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4934 stop_print_frame
= 1;
4936 /* Assume the thread stopped for a breapoint. We'll still check
4937 whether a/the breakpoint is there when the thread is next
4939 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4944 case BPSTAT_WHAT_STOP_SILENT
:
4946 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4947 stop_print_frame
= 0;
4949 /* Assume the thread stopped for a breapoint. We'll still check
4950 whether a/the breakpoint is there when the thread is next
4952 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4956 case BPSTAT_WHAT_HP_STEP_RESUME
:
4958 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4960 delete_step_resume_breakpoint (ecs
->event_thread
);
4961 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4963 /* Back when the step-resume breakpoint was inserted, we
4964 were trying to single-step off a breakpoint. Go back to
4966 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4967 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4973 case BPSTAT_WHAT_KEEP_CHECKING
:
4977 /* If we stepped a permanent breakpoint and we had a high priority
4978 step-resume breakpoint for the address we stepped, but we didn't
4979 hit it, then we must have stepped into the signal handler. The
4980 step-resume was only necessary to catch the case of _not_
4981 stepping into the handler, so delete it, and fall through to
4982 checking whether the step finished. */
4983 if (ecs
->event_thread
->stepped_breakpoint
)
4985 struct breakpoint
*sr_bp
4986 = ecs
->event_thread
->control
.step_resume_breakpoint
;
4989 && sr_bp
->loc
->permanent
4990 && sr_bp
->type
== bp_hp_step_resume
4991 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
4994 fprintf_unfiltered (gdb_stdlog
,
4995 "infrun: stepped permanent breakpoint, stopped in "
4997 delete_step_resume_breakpoint (ecs
->event_thread
);
4998 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
5002 /* We come here if we hit a breakpoint but should not stop for it.
5003 Possibly we also were stepping and should stop for that. So fall
5004 through and test for stepping. But, if not stepping, do not
5007 /* In all-stop mode, if we're currently stepping but have stopped in
5008 some other thread, we need to switch back to the stepped thread. */
5009 if (switch_back_to_stepped_thread (ecs
))
5012 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
5015 fprintf_unfiltered (gdb_stdlog
,
5016 "infrun: step-resume breakpoint is inserted\n");
5018 /* Having a step-resume breakpoint overrides anything
5019 else having to do with stepping commands until
5020 that breakpoint is reached. */
5025 if (ecs
->event_thread
->control
.step_range_end
== 0)
5028 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
5029 /* Likewise if we aren't even stepping. */
5034 /* Re-fetch current thread's frame in case the code above caused
5035 the frame cache to be re-initialized, making our FRAME variable
5036 a dangling pointer. */
5037 frame
= get_current_frame ();
5038 gdbarch
= get_frame_arch (frame
);
5039 fill_in_stop_func (gdbarch
, ecs
);
5041 /* If stepping through a line, keep going if still within it.
5043 Note that step_range_end is the address of the first instruction
5044 beyond the step range, and NOT the address of the last instruction
5047 Note also that during reverse execution, we may be stepping
5048 through a function epilogue and therefore must detect when
5049 the current-frame changes in the middle of a line. */
5051 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
5052 && (execution_direction
!= EXEC_REVERSE
5053 || frame_id_eq (get_frame_id (frame
),
5054 ecs
->event_thread
->control
.step_frame_id
)))
5058 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
5059 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
5060 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
5062 /* Tentatively re-enable range stepping; `resume' disables it if
5063 necessary (e.g., if we're stepping over a breakpoint or we
5064 have software watchpoints). */
5065 ecs
->event_thread
->control
.may_range_step
= 1;
5067 /* When stepping backward, stop at beginning of line range
5068 (unless it's the function entry point, in which case
5069 keep going back to the call point). */
5070 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
5071 && stop_pc
!= ecs
->stop_func_start
5072 && execution_direction
== EXEC_REVERSE
)
5073 end_stepping_range (ecs
);
5080 /* We stepped out of the stepping range. */
5082 /* If we are stepping at the source level and entered the runtime
5083 loader dynamic symbol resolution code...
5085 EXEC_FORWARD: we keep on single stepping until we exit the run
5086 time loader code and reach the callee's address.
5088 EXEC_REVERSE: we've already executed the callee (backward), and
5089 the runtime loader code is handled just like any other
5090 undebuggable function call. Now we need only keep stepping
5091 backward through the trampoline code, and that's handled further
5092 down, so there is nothing for us to do here. */
5094 if (execution_direction
!= EXEC_REVERSE
5095 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5096 && in_solib_dynsym_resolve_code (stop_pc
))
5098 CORE_ADDR pc_after_resolver
=
5099 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
5102 fprintf_unfiltered (gdb_stdlog
,
5103 "infrun: stepped into dynsym resolve code\n");
5105 if (pc_after_resolver
)
5107 /* Set up a step-resume breakpoint at the address
5108 indicated by SKIP_SOLIB_RESOLVER. */
5109 struct symtab_and_line sr_sal
;
5112 sr_sal
.pc
= pc_after_resolver
;
5113 sr_sal
.pspace
= get_frame_program_space (frame
);
5115 insert_step_resume_breakpoint_at_sal (gdbarch
,
5116 sr_sal
, null_frame_id
);
5123 if (ecs
->event_thread
->control
.step_range_end
!= 1
5124 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5125 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5126 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
5129 fprintf_unfiltered (gdb_stdlog
,
5130 "infrun: stepped into signal trampoline\n");
5131 /* The inferior, while doing a "step" or "next", has ended up in
5132 a signal trampoline (either by a signal being delivered or by
5133 the signal handler returning). Just single-step until the
5134 inferior leaves the trampoline (either by calling the handler
5140 /* If we're in the return path from a shared library trampoline,
5141 we want to proceed through the trampoline when stepping. */
5142 /* macro/2012-04-25: This needs to come before the subroutine
5143 call check below as on some targets return trampolines look
5144 like subroutine calls (MIPS16 return thunks). */
5145 if (gdbarch_in_solib_return_trampoline (gdbarch
,
5146 stop_pc
, ecs
->stop_func_name
)
5147 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5149 /* Determine where this trampoline returns. */
5150 CORE_ADDR real_stop_pc
;
5152 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
5155 fprintf_unfiltered (gdb_stdlog
,
5156 "infrun: stepped into solib return tramp\n");
5158 /* Only proceed through if we know where it's going. */
5161 /* And put the step-breakpoint there and go until there. */
5162 struct symtab_and_line sr_sal
;
5164 init_sal (&sr_sal
); /* initialize to zeroes */
5165 sr_sal
.pc
= real_stop_pc
;
5166 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5167 sr_sal
.pspace
= get_frame_program_space (frame
);
5169 /* Do not specify what the fp should be when we stop since
5170 on some machines the prologue is where the new fp value
5172 insert_step_resume_breakpoint_at_sal (gdbarch
,
5173 sr_sal
, null_frame_id
);
5175 /* Restart without fiddling with the step ranges or
5182 /* Check for subroutine calls. The check for the current frame
5183 equalling the step ID is not necessary - the check of the
5184 previous frame's ID is sufficient - but it is a common case and
5185 cheaper than checking the previous frame's ID.
5187 NOTE: frame_id_eq will never report two invalid frame IDs as
5188 being equal, so to get into this block, both the current and
5189 previous frame must have valid frame IDs. */
5190 /* The outer_frame_id check is a heuristic to detect stepping
5191 through startup code. If we step over an instruction which
5192 sets the stack pointer from an invalid value to a valid value,
5193 we may detect that as a subroutine call from the mythical
5194 "outermost" function. This could be fixed by marking
5195 outermost frames as !stack_p,code_p,special_p. Then the
5196 initial outermost frame, before sp was valid, would
5197 have code_addr == &_start. See the comment in frame_id_eq
5199 if (!frame_id_eq (get_stack_frame_id (frame
),
5200 ecs
->event_thread
->control
.step_stack_frame_id
)
5201 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
5202 ecs
->event_thread
->control
.step_stack_frame_id
)
5203 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
5205 || (ecs
->event_thread
->control
.step_start_function
5206 != find_pc_function (stop_pc
)))))
5208 CORE_ADDR real_stop_pc
;
5211 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
5213 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
5215 /* I presume that step_over_calls is only 0 when we're
5216 supposed to be stepping at the assembly language level
5217 ("stepi"). Just stop. */
5218 /* And this works the same backward as frontward. MVS */
5219 end_stepping_range (ecs
);
5223 /* Reverse stepping through solib trampolines. */
5225 if (execution_direction
== EXEC_REVERSE
5226 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
5227 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5228 || (ecs
->stop_func_start
== 0
5229 && in_solib_dynsym_resolve_code (stop_pc
))))
5231 /* Any solib trampoline code can be handled in reverse
5232 by simply continuing to single-step. We have already
5233 executed the solib function (backwards), and a few
5234 steps will take us back through the trampoline to the
5240 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5242 /* We're doing a "next".
5244 Normal (forward) execution: set a breakpoint at the
5245 callee's return address (the address at which the caller
5248 Reverse (backward) execution. set the step-resume
5249 breakpoint at the start of the function that we just
5250 stepped into (backwards), and continue to there. When we
5251 get there, we'll need to single-step back to the caller. */
5253 if (execution_direction
== EXEC_REVERSE
)
5255 /* If we're already at the start of the function, we've either
5256 just stepped backward into a single instruction function,
5257 or stepped back out of a signal handler to the first instruction
5258 of the function. Just keep going, which will single-step back
5260 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
5262 struct symtab_and_line sr_sal
;
5264 /* Normal function call return (static or dynamic). */
5266 sr_sal
.pc
= ecs
->stop_func_start
;
5267 sr_sal
.pspace
= get_frame_program_space (frame
);
5268 insert_step_resume_breakpoint_at_sal (gdbarch
,
5269 sr_sal
, null_frame_id
);
5273 insert_step_resume_breakpoint_at_caller (frame
);
5279 /* If we are in a function call trampoline (a stub between the
5280 calling routine and the real function), locate the real
5281 function. That's what tells us (a) whether we want to step
5282 into it at all, and (b) what prologue we want to run to the
5283 end of, if we do step into it. */
5284 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
5285 if (real_stop_pc
== 0)
5286 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
5287 if (real_stop_pc
!= 0)
5288 ecs
->stop_func_start
= real_stop_pc
;
5290 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
5292 struct symtab_and_line sr_sal
;
5295 sr_sal
.pc
= ecs
->stop_func_start
;
5296 sr_sal
.pspace
= get_frame_program_space (frame
);
5298 insert_step_resume_breakpoint_at_sal (gdbarch
,
5299 sr_sal
, null_frame_id
);
5304 /* If we have line number information for the function we are
5305 thinking of stepping into and the function isn't on the skip
5308 If there are several symtabs at that PC (e.g. with include
5309 files), just want to know whether *any* of them have line
5310 numbers. find_pc_line handles this. */
5312 struct symtab_and_line tmp_sal
;
5314 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5315 if (tmp_sal
.line
!= 0
5316 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
5319 if (execution_direction
== EXEC_REVERSE
)
5320 handle_step_into_function_backward (gdbarch
, ecs
);
5322 handle_step_into_function (gdbarch
, ecs
);
5327 /* If we have no line number and the step-stop-if-no-debug is
5328 set, we stop the step so that the user has a chance to switch
5329 in assembly mode. */
5330 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5331 && step_stop_if_no_debug
)
5333 end_stepping_range (ecs
);
5337 if (execution_direction
== EXEC_REVERSE
)
5339 /* If we're already at the start of the function, we've either just
5340 stepped backward into a single instruction function without line
5341 number info, or stepped back out of a signal handler to the first
5342 instruction of the function without line number info. Just keep
5343 going, which will single-step back to the caller. */
5344 if (ecs
->stop_func_start
!= stop_pc
)
5346 /* Set a breakpoint at callee's start address.
5347 From there we can step once and be back in the caller. */
5348 struct symtab_and_line sr_sal
;
5351 sr_sal
.pc
= ecs
->stop_func_start
;
5352 sr_sal
.pspace
= get_frame_program_space (frame
);
5353 insert_step_resume_breakpoint_at_sal (gdbarch
,
5354 sr_sal
, null_frame_id
);
5358 /* Set a breakpoint at callee's return address (the address
5359 at which the caller will resume). */
5360 insert_step_resume_breakpoint_at_caller (frame
);
5366 /* Reverse stepping through solib trampolines. */
5368 if (execution_direction
== EXEC_REVERSE
5369 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5371 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5372 || (ecs
->stop_func_start
== 0
5373 && in_solib_dynsym_resolve_code (stop_pc
)))
5375 /* Any solib trampoline code can be handled in reverse
5376 by simply continuing to single-step. We have already
5377 executed the solib function (backwards), and a few
5378 steps will take us back through the trampoline to the
5383 else if (in_solib_dynsym_resolve_code (stop_pc
))
5385 /* Stepped backward into the solib dynsym resolver.
5386 Set a breakpoint at its start and continue, then
5387 one more step will take us out. */
5388 struct symtab_and_line sr_sal
;
5391 sr_sal
.pc
= ecs
->stop_func_start
;
5392 sr_sal
.pspace
= get_frame_program_space (frame
);
5393 insert_step_resume_breakpoint_at_sal (gdbarch
,
5394 sr_sal
, null_frame_id
);
5400 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5402 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5403 the trampoline processing logic, however, there are some trampolines
5404 that have no names, so we should do trampoline handling first. */
5405 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5406 && ecs
->stop_func_name
== NULL
5407 && stop_pc_sal
.line
== 0)
5410 fprintf_unfiltered (gdb_stdlog
,
5411 "infrun: stepped into undebuggable function\n");
5413 /* The inferior just stepped into, or returned to, an
5414 undebuggable function (where there is no debugging information
5415 and no line number corresponding to the address where the
5416 inferior stopped). Since we want to skip this kind of code,
5417 we keep going until the inferior returns from this
5418 function - unless the user has asked us not to (via
5419 set step-mode) or we no longer know how to get back
5420 to the call site. */
5421 if (step_stop_if_no_debug
5422 || !frame_id_p (frame_unwind_caller_id (frame
)))
5424 /* If we have no line number and the step-stop-if-no-debug
5425 is set, we stop the step so that the user has a chance to
5426 switch in assembly mode. */
5427 end_stepping_range (ecs
);
5432 /* Set a breakpoint at callee's return address (the address
5433 at which the caller will resume). */
5434 insert_step_resume_breakpoint_at_caller (frame
);
5440 if (ecs
->event_thread
->control
.step_range_end
== 1)
5442 /* It is stepi or nexti. We always want to stop stepping after
5445 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5446 end_stepping_range (ecs
);
5450 if (stop_pc_sal
.line
== 0)
5452 /* We have no line number information. That means to stop
5453 stepping (does this always happen right after one instruction,
5454 when we do "s" in a function with no line numbers,
5455 or can this happen as a result of a return or longjmp?). */
5457 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5458 end_stepping_range (ecs
);
5462 /* Look for "calls" to inlined functions, part one. If the inline
5463 frame machinery detected some skipped call sites, we have entered
5464 a new inline function. */
5466 if (frame_id_eq (get_frame_id (get_current_frame ()),
5467 ecs
->event_thread
->control
.step_frame_id
)
5468 && inline_skipped_frames (ecs
->ptid
))
5470 struct symtab_and_line call_sal
;
5473 fprintf_unfiltered (gdb_stdlog
,
5474 "infrun: stepped into inlined function\n");
5476 find_frame_sal (get_current_frame (), &call_sal
);
5478 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5480 /* For "step", we're going to stop. But if the call site
5481 for this inlined function is on the same source line as
5482 we were previously stepping, go down into the function
5483 first. Otherwise stop at the call site. */
5485 if (call_sal
.line
== ecs
->event_thread
->current_line
5486 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5487 step_into_inline_frame (ecs
->ptid
);
5489 end_stepping_range (ecs
);
5494 /* For "next", we should stop at the call site if it is on a
5495 different source line. Otherwise continue through the
5496 inlined function. */
5497 if (call_sal
.line
== ecs
->event_thread
->current_line
5498 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5501 end_stepping_range (ecs
);
5506 /* Look for "calls" to inlined functions, part two. If we are still
5507 in the same real function we were stepping through, but we have
5508 to go further up to find the exact frame ID, we are stepping
5509 through a more inlined call beyond its call site. */
5511 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5512 && !frame_id_eq (get_frame_id (get_current_frame ()),
5513 ecs
->event_thread
->control
.step_frame_id
)
5514 && stepped_in_from (get_current_frame (),
5515 ecs
->event_thread
->control
.step_frame_id
))
5518 fprintf_unfiltered (gdb_stdlog
,
5519 "infrun: stepping through inlined function\n");
5521 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5524 end_stepping_range (ecs
);
5528 if ((stop_pc
== stop_pc_sal
.pc
)
5529 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5530 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5532 /* We are at the start of a different line. So stop. Note that
5533 we don't stop if we step into the middle of a different line.
5534 That is said to make things like for (;;) statements work
5537 fprintf_unfiltered (gdb_stdlog
,
5538 "infrun: stepped to a different line\n");
5539 end_stepping_range (ecs
);
5543 /* We aren't done stepping.
5545 Optimize by setting the stepping range to the line.
5546 (We might not be in the original line, but if we entered a
5547 new line in mid-statement, we continue stepping. This makes
5548 things like for(;;) statements work better.) */
5550 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5551 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5552 ecs
->event_thread
->control
.may_range_step
= 1;
5553 set_step_info (frame
, stop_pc_sal
);
5556 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5560 /* In all-stop mode, if we're currently stepping but have stopped in
5561 some other thread, we may need to switch back to the stepped
5562 thread. Returns true we set the inferior running, false if we left
5563 it stopped (and the event needs further processing). */
5566 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
5570 struct thread_info
*tp
;
5571 struct thread_info
*stepping_thread
;
5572 struct thread_info
*step_over
;
5574 /* If any thread is blocked on some internal breakpoint, and we
5575 simply need to step over that breakpoint to get it going
5576 again, do that first. */
5578 /* However, if we see an event for the stepping thread, then we
5579 know all other threads have been moved past their breakpoints
5580 already. Let the caller check whether the step is finished,
5581 etc., before deciding to move it past a breakpoint. */
5582 if (ecs
->event_thread
->control
.step_range_end
!= 0)
5585 /* Check if the current thread is blocked on an incomplete
5586 step-over, interrupted by a random signal. */
5587 if (ecs
->event_thread
->control
.trap_expected
5588 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5592 fprintf_unfiltered (gdb_stdlog
,
5593 "infrun: need to finish step-over of [%s]\n",
5594 target_pid_to_str (ecs
->event_thread
->ptid
));
5600 /* Check if the current thread is blocked by a single-step
5601 breakpoint of another thread. */
5602 if (ecs
->hit_singlestep_breakpoint
)
5606 fprintf_unfiltered (gdb_stdlog
,
5607 "infrun: need to step [%s] over single-step "
5609 target_pid_to_str (ecs
->ptid
));
5615 /* Otherwise, we no longer expect a trap in the current thread.
5616 Clear the trap_expected flag before switching back -- this is
5617 what keep_going does as well, if we call it. */
5618 ecs
->event_thread
->control
.trap_expected
= 0;
5620 /* Likewise, clear the signal if it should not be passed. */
5621 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5622 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5624 /* If scheduler locking applies even if not stepping, there's no
5625 need to walk over threads. Above we've checked whether the
5626 current thread is stepping. If some other thread not the
5627 event thread is stepping, then it must be that scheduler
5628 locking is not in effect. */
5629 if (schedlock_applies (ecs
->event_thread
))
5632 /* Look for the stepping/nexting thread, and check if any other
5633 thread other than the stepping thread needs to start a
5634 step-over. Do all step-overs before actually proceeding with
5636 stepping_thread
= NULL
;
5638 ALL_NON_EXITED_THREADS (tp
)
5640 /* Ignore threads of processes we're not resuming. */
5642 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
5645 /* When stepping over a breakpoint, we lock all threads
5646 except the one that needs to move past the breakpoint.
5647 If a non-event thread has this set, the "incomplete
5648 step-over" check above should have caught it earlier. */
5649 gdb_assert (!tp
->control
.trap_expected
);
5651 /* Did we find the stepping thread? */
5652 if (tp
->control
.step_range_end
)
5654 /* Yep. There should only one though. */
5655 gdb_assert (stepping_thread
== NULL
);
5657 /* The event thread is handled at the top, before we
5659 gdb_assert (tp
!= ecs
->event_thread
);
5661 /* If some thread other than the event thread is
5662 stepping, then scheduler locking can't be in effect,
5663 otherwise we wouldn't have resumed the current event
5664 thread in the first place. */
5665 gdb_assert (!schedlock_applies (tp
));
5667 stepping_thread
= tp
;
5669 else if (thread_still_needs_step_over (tp
))
5673 /* At the top we've returned early if the event thread
5674 is stepping. If some other thread not the event
5675 thread is stepping, then scheduler locking can't be
5676 in effect, and we can resume this thread. No need to
5677 keep looking for the stepping thread then. */
5682 if (step_over
!= NULL
)
5687 fprintf_unfiltered (gdb_stdlog
,
5688 "infrun: need to step-over [%s]\n",
5689 target_pid_to_str (tp
->ptid
));
5692 /* Only the stepping thread should have this set. */
5693 gdb_assert (tp
->control
.step_range_end
== 0);
5695 ecs
->ptid
= tp
->ptid
;
5696 ecs
->event_thread
= tp
;
5697 switch_to_thread (ecs
->ptid
);
5702 if (stepping_thread
!= NULL
)
5704 struct frame_info
*frame
;
5705 struct gdbarch
*gdbarch
;
5707 tp
= stepping_thread
;
5709 /* If the stepping thread exited, then don't try to switch
5710 back and resume it, which could fail in several different
5711 ways depending on the target. Instead, just keep going.
5713 We can find a stepping dead thread in the thread list in
5716 - The target supports thread exit events, and when the
5717 target tries to delete the thread from the thread list,
5718 inferior_ptid pointed at the exiting thread. In such
5719 case, calling delete_thread does not really remove the
5720 thread from the list; instead, the thread is left listed,
5721 with 'exited' state.
5723 - The target's debug interface does not support thread
5724 exit events, and so we have no idea whatsoever if the
5725 previously stepping thread is still alive. For that
5726 reason, we need to synchronously query the target
5728 if (is_exited (tp
->ptid
)
5729 || !target_thread_alive (tp
->ptid
))
5732 fprintf_unfiltered (gdb_stdlog
,
5733 "infrun: not switching back to "
5734 "stepped thread, it has vanished\n");
5736 delete_thread (tp
->ptid
);
5742 fprintf_unfiltered (gdb_stdlog
,
5743 "infrun: switching back to stepped thread\n");
5745 ecs
->event_thread
= tp
;
5746 ecs
->ptid
= tp
->ptid
;
5747 context_switch (ecs
->ptid
);
5749 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5750 frame
= get_current_frame ();
5751 gdbarch
= get_frame_arch (frame
);
5753 /* If the PC of the thread we were trying to single-step has
5754 changed, then that thread has trapped or been signaled,
5755 but the event has not been reported to GDB yet. Re-poll
5756 the target looking for this particular thread's event
5757 (i.e. temporarily enable schedlock) by:
5759 - setting a break at the current PC
5760 - resuming that particular thread, only (by setting
5763 This prevents us continuously moving the single-step
5764 breakpoint forward, one instruction at a time,
5767 if (stop_pc
!= tp
->prev_pc
)
5772 fprintf_unfiltered (gdb_stdlog
,
5773 "infrun: expected thread advanced also\n");
5775 /* Clear the info of the previous step-over, as it's no
5776 longer valid. It's what keep_going would do too, if
5777 we called it. Must do this before trying to insert
5778 the sss breakpoint, otherwise if we were previously
5779 trying to step over this exact address in another
5780 thread, the breakpoint ends up not installed. */
5781 clear_step_over_info ();
5783 insert_single_step_breakpoint (get_frame_arch (frame
),
5784 get_frame_address_space (frame
),
5787 resume_ptid
= user_visible_resume_ptid (tp
->control
.stepping_command
);
5788 do_target_resume (resume_ptid
,
5789 currently_stepping (tp
), GDB_SIGNAL_0
);
5790 prepare_to_wait (ecs
);
5795 fprintf_unfiltered (gdb_stdlog
,
5796 "infrun: expected thread still "
5797 "hasn't advanced\n");
5807 /* Is thread TP in the middle of single-stepping? */
5810 currently_stepping (struct thread_info
*tp
)
5812 return ((tp
->control
.step_range_end
5813 && tp
->control
.step_resume_breakpoint
== NULL
)
5814 || tp
->control
.trap_expected
5815 || tp
->stepped_breakpoint
5816 || bpstat_should_step ());
5819 /* Inferior has stepped into a subroutine call with source code that
5820 we should not step over. Do step to the first line of code in
5824 handle_step_into_function (struct gdbarch
*gdbarch
,
5825 struct execution_control_state
*ecs
)
5827 struct compunit_symtab
*cust
;
5828 struct symtab_and_line stop_func_sal
, sr_sal
;
5830 fill_in_stop_func (gdbarch
, ecs
);
5832 cust
= find_pc_compunit_symtab (stop_pc
);
5833 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
5834 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5835 ecs
->stop_func_start
);
5837 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5838 /* Use the step_resume_break to step until the end of the prologue,
5839 even if that involves jumps (as it seems to on the vax under
5841 /* If the prologue ends in the middle of a source line, continue to
5842 the end of that source line (if it is still within the function).
5843 Otherwise, just go to end of prologue. */
5844 if (stop_func_sal
.end
5845 && stop_func_sal
.pc
!= ecs
->stop_func_start
5846 && stop_func_sal
.end
< ecs
->stop_func_end
)
5847 ecs
->stop_func_start
= stop_func_sal
.end
;
5849 /* Architectures which require breakpoint adjustment might not be able
5850 to place a breakpoint at the computed address. If so, the test
5851 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5852 ecs->stop_func_start to an address at which a breakpoint may be
5853 legitimately placed.
5855 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5856 made, GDB will enter an infinite loop when stepping through
5857 optimized code consisting of VLIW instructions which contain
5858 subinstructions corresponding to different source lines. On
5859 FR-V, it's not permitted to place a breakpoint on any but the
5860 first subinstruction of a VLIW instruction. When a breakpoint is
5861 set, GDB will adjust the breakpoint address to the beginning of
5862 the VLIW instruction. Thus, we need to make the corresponding
5863 adjustment here when computing the stop address. */
5865 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5867 ecs
->stop_func_start
5868 = gdbarch_adjust_breakpoint_address (gdbarch
,
5869 ecs
->stop_func_start
);
5872 if (ecs
->stop_func_start
== stop_pc
)
5874 /* We are already there: stop now. */
5875 end_stepping_range (ecs
);
5880 /* Put the step-breakpoint there and go until there. */
5881 init_sal (&sr_sal
); /* initialize to zeroes */
5882 sr_sal
.pc
= ecs
->stop_func_start
;
5883 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5884 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5886 /* Do not specify what the fp should be when we stop since on
5887 some machines the prologue is where the new fp value is
5889 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5891 /* And make sure stepping stops right away then. */
5892 ecs
->event_thread
->control
.step_range_end
5893 = ecs
->event_thread
->control
.step_range_start
;
5898 /* Inferior has stepped backward into a subroutine call with source
5899 code that we should not step over. Do step to the beginning of the
5900 last line of code in it. */
5903 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5904 struct execution_control_state
*ecs
)
5906 struct compunit_symtab
*cust
;
5907 struct symtab_and_line stop_func_sal
;
5909 fill_in_stop_func (gdbarch
, ecs
);
5911 cust
= find_pc_compunit_symtab (stop_pc
);
5912 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
5913 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5914 ecs
->stop_func_start
);
5916 stop_func_sal
= find_pc_line (stop_pc
, 0);
5918 /* OK, we're just going to keep stepping here. */
5919 if (stop_func_sal
.pc
== stop_pc
)
5921 /* We're there already. Just stop stepping now. */
5922 end_stepping_range (ecs
);
5926 /* Else just reset the step range and keep going.
5927 No step-resume breakpoint, they don't work for
5928 epilogues, which can have multiple entry paths. */
5929 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5930 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5936 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5937 This is used to both functions and to skip over code. */
5940 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5941 struct symtab_and_line sr_sal
,
5942 struct frame_id sr_id
,
5943 enum bptype sr_type
)
5945 /* There should never be more than one step-resume or longjmp-resume
5946 breakpoint per thread, so we should never be setting a new
5947 step_resume_breakpoint when one is already active. */
5948 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5949 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5952 fprintf_unfiltered (gdb_stdlog
,
5953 "infrun: inserting step-resume breakpoint at %s\n",
5954 paddress (gdbarch
, sr_sal
.pc
));
5956 inferior_thread ()->control
.step_resume_breakpoint
5957 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5961 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5962 struct symtab_and_line sr_sal
,
5963 struct frame_id sr_id
)
5965 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5970 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5971 This is used to skip a potential signal handler.
5973 This is called with the interrupted function's frame. The signal
5974 handler, when it returns, will resume the interrupted function at
5978 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5980 struct symtab_and_line sr_sal
;
5981 struct gdbarch
*gdbarch
;
5983 gdb_assert (return_frame
!= NULL
);
5984 init_sal (&sr_sal
); /* initialize to zeros */
5986 gdbarch
= get_frame_arch (return_frame
);
5987 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5988 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5989 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5991 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5992 get_stack_frame_id (return_frame
),
5996 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5997 is used to skip a function after stepping into it (for "next" or if
5998 the called function has no debugging information).
6000 The current function has almost always been reached by single
6001 stepping a call or return instruction. NEXT_FRAME belongs to the
6002 current function, and the breakpoint will be set at the caller's
6005 This is a separate function rather than reusing
6006 insert_hp_step_resume_breakpoint_at_frame in order to avoid
6007 get_prev_frame, which may stop prematurely (see the implementation
6008 of frame_unwind_caller_id for an example). */
6011 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
6013 struct symtab_and_line sr_sal
;
6014 struct gdbarch
*gdbarch
;
6016 /* We shouldn't have gotten here if we don't know where the call site
6018 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
6020 init_sal (&sr_sal
); /* initialize to zeros */
6022 gdbarch
= frame_unwind_caller_arch (next_frame
);
6023 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
6024 frame_unwind_caller_pc (next_frame
));
6025 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
6026 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
6028 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
6029 frame_unwind_caller_id (next_frame
));
6032 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
6033 new breakpoint at the target of a jmp_buf. The handling of
6034 longjmp-resume uses the same mechanisms used for handling
6035 "step-resume" breakpoints. */
6038 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6040 /* There should never be more than one longjmp-resume breakpoint per
6041 thread, so we should never be setting a new
6042 longjmp_resume_breakpoint when one is already active. */
6043 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
6046 fprintf_unfiltered (gdb_stdlog
,
6047 "infrun: inserting longjmp-resume breakpoint at %s\n",
6048 paddress (gdbarch
, pc
));
6050 inferior_thread ()->control
.exception_resume_breakpoint
=
6051 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
6054 /* Insert an exception resume breakpoint. TP is the thread throwing
6055 the exception. The block B is the block of the unwinder debug hook
6056 function. FRAME is the frame corresponding to the call to this
6057 function. SYM is the symbol of the function argument holding the
6058 target PC of the exception. */
6061 insert_exception_resume_breakpoint (struct thread_info
*tp
,
6062 const struct block
*b
,
6063 struct frame_info
*frame
,
6068 struct symbol
*vsym
;
6069 struct value
*value
;
6071 struct breakpoint
*bp
;
6073 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
6074 value
= read_var_value (vsym
, frame
);
6075 /* If the value was optimized out, revert to the old behavior. */
6076 if (! value_optimized_out (value
))
6078 handler
= value_as_address (value
);
6081 fprintf_unfiltered (gdb_stdlog
,
6082 "infrun: exception resume at %lx\n",
6083 (unsigned long) handler
);
6085 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
6086 handler
, bp_exception_resume
);
6088 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
6091 bp
->thread
= tp
->num
;
6092 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
6095 CATCH (e
, RETURN_MASK_ERROR
)
6097 /* We want to ignore errors here. */
6102 /* A helper for check_exception_resume that sets an
6103 exception-breakpoint based on a SystemTap probe. */
6106 insert_exception_resume_from_probe (struct thread_info
*tp
,
6107 const struct bound_probe
*probe
,
6108 struct frame_info
*frame
)
6110 struct value
*arg_value
;
6112 struct breakpoint
*bp
;
6114 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
6118 handler
= value_as_address (arg_value
);
6121 fprintf_unfiltered (gdb_stdlog
,
6122 "infrun: exception resume at %s\n",
6123 paddress (get_objfile_arch (probe
->objfile
),
6126 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
6127 handler
, bp_exception_resume
);
6128 bp
->thread
= tp
->num
;
6129 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
6132 /* This is called when an exception has been intercepted. Check to
6133 see whether the exception's destination is of interest, and if so,
6134 set an exception resume breakpoint there. */
6137 check_exception_resume (struct execution_control_state
*ecs
,
6138 struct frame_info
*frame
)
6140 struct bound_probe probe
;
6141 struct symbol
*func
;
6143 /* First see if this exception unwinding breakpoint was set via a
6144 SystemTap probe point. If so, the probe has two arguments: the
6145 CFA and the HANDLER. We ignore the CFA, extract the handler, and
6146 set a breakpoint there. */
6147 probe
= find_probe_by_pc (get_frame_pc (frame
));
6150 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
6154 func
= get_frame_function (frame
);
6160 const struct block
*b
;
6161 struct block_iterator iter
;
6165 /* The exception breakpoint is a thread-specific breakpoint on
6166 the unwinder's debug hook, declared as:
6168 void _Unwind_DebugHook (void *cfa, void *handler);
6170 The CFA argument indicates the frame to which control is
6171 about to be transferred. HANDLER is the destination PC.
6173 We ignore the CFA and set a temporary breakpoint at HANDLER.
6174 This is not extremely efficient but it avoids issues in gdb
6175 with computing the DWARF CFA, and it also works even in weird
6176 cases such as throwing an exception from inside a signal
6179 b
= SYMBOL_BLOCK_VALUE (func
);
6180 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
6182 if (!SYMBOL_IS_ARGUMENT (sym
))
6189 insert_exception_resume_breakpoint (ecs
->event_thread
,
6195 CATCH (e
, RETURN_MASK_ERROR
)
6202 stop_waiting (struct execution_control_state
*ecs
)
6205 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_waiting\n");
6207 clear_step_over_info ();
6209 /* Let callers know we don't want to wait for the inferior anymore. */
6210 ecs
->wait_some_more
= 0;
6213 /* Called when we should continue running the inferior, because the
6214 current event doesn't cause a user visible stop. This does the
6215 resuming part; waiting for the next event is done elsewhere. */
6218 keep_going (struct execution_control_state
*ecs
)
6220 /* Make sure normal_stop is called if we get a QUIT handled before
6222 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
6224 /* Save the pc before execution, to compare with pc after stop. */
6225 ecs
->event_thread
->prev_pc
6226 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
6228 if (ecs
->event_thread
->control
.trap_expected
6229 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
6231 /* We haven't yet gotten our trap, and either: intercepted a
6232 non-signal event (e.g., a fork); or took a signal which we
6233 are supposed to pass through to the inferior. Simply
6235 discard_cleanups (old_cleanups
);
6236 resume (ecs
->event_thread
->suspend
.stop_signal
);
6240 struct regcache
*regcache
= get_current_regcache ();
6244 /* Either the trap was not expected, but we are continuing
6245 anyway (if we got a signal, the user asked it be passed to
6248 We got our expected trap, but decided we should resume from
6251 We're going to run this baby now!
6253 Note that insert_breakpoints won't try to re-insert
6254 already inserted breakpoints. Therefore, we don't
6255 care if breakpoints were already inserted, or not. */
6257 /* If we need to step over a breakpoint, and we're not using
6258 displaced stepping to do so, insert all breakpoints
6259 (watchpoints, etc.) but the one we're stepping over, step one
6260 instruction, and then re-insert the breakpoint when that step
6263 remove_bp
= (ecs
->hit_singlestep_breakpoint
6264 || thread_still_needs_step_over (ecs
->event_thread
));
6265 remove_wps
= (ecs
->event_thread
->stepping_over_watchpoint
6266 && !target_have_steppable_watchpoint
);
6268 /* We can't use displaced stepping if we need to step past a
6269 watchpoint. The instruction copied to the scratch pad would
6270 still trigger the watchpoint. */
6273 || !use_displaced_stepping (get_regcache_arch (regcache
))))
6275 set_step_over_info (get_regcache_aspace (regcache
),
6276 regcache_read_pc (regcache
), remove_wps
);
6278 else if (remove_wps
)
6279 set_step_over_info (NULL
, 0, remove_wps
);
6281 clear_step_over_info ();
6283 /* Stop stepping if inserting breakpoints fails. */
6286 insert_breakpoints ();
6288 CATCH (e
, RETURN_MASK_ERROR
)
6290 exception_print (gdb_stderr
, e
);
6292 discard_cleanups (old_cleanups
);
6297 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
6299 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
6300 explicitly specifies that such a signal should be delivered
6301 to the target program). Typically, that would occur when a
6302 user is debugging a target monitor on a simulator: the target
6303 monitor sets a breakpoint; the simulator encounters this
6304 breakpoint and halts the simulation handing control to GDB;
6305 GDB, noting that the stop address doesn't map to any known
6306 breakpoint, returns control back to the simulator; the
6307 simulator then delivers the hardware equivalent of a
6308 GDB_SIGNAL_TRAP to the program being debugged. */
6309 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6310 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
6311 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6313 discard_cleanups (old_cleanups
);
6314 resume (ecs
->event_thread
->suspend
.stop_signal
);
6317 prepare_to_wait (ecs
);
6320 /* This function normally comes after a resume, before
6321 handle_inferior_event exits. It takes care of any last bits of
6322 housekeeping, and sets the all-important wait_some_more flag. */
6325 prepare_to_wait (struct execution_control_state
*ecs
)
6328 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
6330 /* This is the old end of the while loop. Let everybody know we
6331 want to wait for the inferior some more and get called again
6333 ecs
->wait_some_more
= 1;
6336 /* We are done with the step range of a step/next/si/ni command.
6337 Called once for each n of a "step n" operation. */
6340 end_stepping_range (struct execution_control_state
*ecs
)
6342 ecs
->event_thread
->control
.stop_step
= 1;
6346 /* Several print_*_reason functions to print why the inferior has stopped.
6347 We always print something when the inferior exits, or receives a signal.
6348 The rest of the cases are dealt with later on in normal_stop and
6349 print_it_typical. Ideally there should be a call to one of these
6350 print_*_reason functions functions from handle_inferior_event each time
6351 stop_waiting is called.
6353 Note that we don't call these directly, instead we delegate that to
6354 the interpreters, through observers. Interpreters then call these
6355 with whatever uiout is right. */
6358 print_end_stepping_range_reason (struct ui_out
*uiout
)
6360 /* For CLI-like interpreters, print nothing. */
6362 if (ui_out_is_mi_like_p (uiout
))
6364 ui_out_field_string (uiout
, "reason",
6365 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
6370 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6372 annotate_signalled ();
6373 if (ui_out_is_mi_like_p (uiout
))
6375 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
6376 ui_out_text (uiout
, "\nProgram terminated with signal ");
6377 annotate_signal_name ();
6378 ui_out_field_string (uiout
, "signal-name",
6379 gdb_signal_to_name (siggnal
));
6380 annotate_signal_name_end ();
6381 ui_out_text (uiout
, ", ");
6382 annotate_signal_string ();
6383 ui_out_field_string (uiout
, "signal-meaning",
6384 gdb_signal_to_string (siggnal
));
6385 annotate_signal_string_end ();
6386 ui_out_text (uiout
, ".\n");
6387 ui_out_text (uiout
, "The program no longer exists.\n");
6391 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
6393 struct inferior
*inf
= current_inferior ();
6394 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
6396 annotate_exited (exitstatus
);
6399 if (ui_out_is_mi_like_p (uiout
))
6400 ui_out_field_string (uiout
, "reason",
6401 async_reason_lookup (EXEC_ASYNC_EXITED
));
6402 ui_out_text (uiout
, "[Inferior ");
6403 ui_out_text (uiout
, plongest (inf
->num
));
6404 ui_out_text (uiout
, " (");
6405 ui_out_text (uiout
, pidstr
);
6406 ui_out_text (uiout
, ") exited with code ");
6407 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
6408 ui_out_text (uiout
, "]\n");
6412 if (ui_out_is_mi_like_p (uiout
))
6414 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
6415 ui_out_text (uiout
, "[Inferior ");
6416 ui_out_text (uiout
, plongest (inf
->num
));
6417 ui_out_text (uiout
, " (");
6418 ui_out_text (uiout
, pidstr
);
6419 ui_out_text (uiout
, ") exited normally]\n");
6424 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6428 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
6430 struct thread_info
*t
= inferior_thread ();
6432 ui_out_text (uiout
, "\n[");
6433 ui_out_field_string (uiout
, "thread-name",
6434 target_pid_to_str (t
->ptid
));
6435 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
6436 ui_out_text (uiout
, " stopped");
6440 ui_out_text (uiout
, "\nProgram received signal ");
6441 annotate_signal_name ();
6442 if (ui_out_is_mi_like_p (uiout
))
6444 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
6445 ui_out_field_string (uiout
, "signal-name",
6446 gdb_signal_to_name (siggnal
));
6447 annotate_signal_name_end ();
6448 ui_out_text (uiout
, ", ");
6449 annotate_signal_string ();
6450 ui_out_field_string (uiout
, "signal-meaning",
6451 gdb_signal_to_string (siggnal
));
6452 annotate_signal_string_end ();
6454 ui_out_text (uiout
, ".\n");
6458 print_no_history_reason (struct ui_out
*uiout
)
6460 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
6463 /* Print current location without a level number, if we have changed
6464 functions or hit a breakpoint. Print source line if we have one.
6465 bpstat_print contains the logic deciding in detail what to print,
6466 based on the event(s) that just occurred. */
6469 print_stop_event (struct target_waitstatus
*ws
)
6473 int do_frame_printing
= 1;
6474 struct thread_info
*tp
= inferior_thread ();
6476 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
6480 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6481 should) carry around the function and does (or should) use
6482 that when doing a frame comparison. */
6483 if (tp
->control
.stop_step
6484 && frame_id_eq (tp
->control
.step_frame_id
,
6485 get_frame_id (get_current_frame ()))
6486 && tp
->control
.step_start_function
== find_pc_function (stop_pc
))
6488 /* Finished step, just print source line. */
6489 source_flag
= SRC_LINE
;
6493 /* Print location and source line. */
6494 source_flag
= SRC_AND_LOC
;
6497 case PRINT_SRC_AND_LOC
:
6498 /* Print location and source line. */
6499 source_flag
= SRC_AND_LOC
;
6501 case PRINT_SRC_ONLY
:
6502 source_flag
= SRC_LINE
;
6505 /* Something bogus. */
6506 source_flag
= SRC_LINE
;
6507 do_frame_printing
= 0;
6510 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6513 /* The behavior of this routine with respect to the source
6515 SRC_LINE: Print only source line
6516 LOCATION: Print only location
6517 SRC_AND_LOC: Print location and source line. */
6518 if (do_frame_printing
)
6519 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6521 /* Display the auto-display expressions. */
6525 /* Here to return control to GDB when the inferior stops for real.
6526 Print appropriate messages, remove breakpoints, give terminal our modes.
6528 STOP_PRINT_FRAME nonzero means print the executing frame
6529 (pc, function, args, file, line number and line text).
6530 BREAKPOINTS_FAILED nonzero means stop was due to error
6531 attempting to insert breakpoints. */
6536 struct target_waitstatus last
;
6538 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
6540 get_last_target_status (&last_ptid
, &last
);
6542 /* If an exception is thrown from this point on, make sure to
6543 propagate GDB's knowledge of the executing state to the
6544 frontend/user running state. A QUIT is an easy exception to see
6545 here, so do this before any filtered output. */
6547 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
6548 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6549 && last
.kind
!= TARGET_WAITKIND_EXITED
6550 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6551 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
6553 /* As we're presenting a stop, and potentially removing breakpoints,
6554 update the thread list so we can tell whether there are threads
6555 running on the target. With target remote, for example, we can
6556 only learn about new threads when we explicitly update the thread
6557 list. Do this before notifying the interpreters about signal
6558 stops, end of stepping ranges, etc., so that the "new thread"
6559 output is emitted before e.g., "Program received signal FOO",
6560 instead of after. */
6561 update_thread_list ();
6563 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
6564 observer_notify_signal_received (inferior_thread ()->suspend
.stop_signal
);
6566 /* As with the notification of thread events, we want to delay
6567 notifying the user that we've switched thread context until
6568 the inferior actually stops.
6570 There's no point in saying anything if the inferior has exited.
6571 Note that SIGNALLED here means "exited with a signal", not
6572 "received a signal".
6574 Also skip saying anything in non-stop mode. In that mode, as we
6575 don't want GDB to switch threads behind the user's back, to avoid
6576 races where the user is typing a command to apply to thread x,
6577 but GDB switches to thread y before the user finishes entering
6578 the command, fetch_inferior_event installs a cleanup to restore
6579 the current thread back to the thread the user had selected right
6580 after this event is handled, so we're not really switching, only
6581 informing of a stop. */
6583 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
6584 && target_has_execution
6585 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6586 && last
.kind
!= TARGET_WAITKIND_EXITED
6587 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6589 target_terminal_ours_for_output ();
6590 printf_filtered (_("[Switching to %s]\n"),
6591 target_pid_to_str (inferior_ptid
));
6592 annotate_thread_changed ();
6593 previous_inferior_ptid
= inferior_ptid
;
6596 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
6598 gdb_assert (sync_execution
|| !target_can_async_p ());
6600 target_terminal_ours_for_output ();
6601 printf_filtered (_("No unwaited-for children left.\n"));
6604 /* Note: this depends on the update_thread_list call above. */
6605 if (!breakpoints_should_be_inserted_now () && target_has_execution
)
6607 if (remove_breakpoints ())
6609 target_terminal_ours_for_output ();
6610 printf_filtered (_("Cannot remove breakpoints because "
6611 "program is no longer writable.\nFurther "
6612 "execution is probably impossible.\n"));
6616 /* If an auto-display called a function and that got a signal,
6617 delete that auto-display to avoid an infinite recursion. */
6619 if (stopped_by_random_signal
)
6620 disable_current_display ();
6622 /* Notify observers if we finished a "step"-like command, etc. */
6623 if (target_has_execution
6624 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6625 && last
.kind
!= TARGET_WAITKIND_EXITED
6626 && inferior_thread ()->control
.stop_step
)
6628 /* But not if in the middle of doing a "step n" operation for
6630 if (inferior_thread ()->step_multi
)
6633 observer_notify_end_stepping_range ();
6636 target_terminal_ours ();
6637 async_enable_stdin ();
6639 /* Set the current source location. This will also happen if we
6640 display the frame below, but the current SAL will be incorrect
6641 during a user hook-stop function. */
6642 if (has_stack_frames () && !stop_stack_dummy
)
6643 set_current_sal_from_frame (get_current_frame ());
6645 /* Let the user/frontend see the threads as stopped, but do nothing
6646 if the thread was running an infcall. We may be e.g., evaluating
6647 a breakpoint condition. In that case, the thread had state
6648 THREAD_RUNNING before the infcall, and shall remain set to
6649 running, all without informing the user/frontend about state
6650 transition changes. If this is actually a call command, then the
6651 thread was originally already stopped, so there's no state to
6653 if (target_has_execution
&& inferior_thread ()->control
.in_infcall
)
6654 discard_cleanups (old_chain
);
6656 do_cleanups (old_chain
);
6658 /* Look up the hook_stop and run it (CLI internally handles problem
6659 of stop_command's pre-hook not existing). */
6661 catch_errors (hook_stop_stub
, stop_command
,
6662 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6664 if (!has_stack_frames ())
6667 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6668 || last
.kind
== TARGET_WAITKIND_EXITED
)
6671 /* Select innermost stack frame - i.e., current frame is frame 0,
6672 and current location is based on that.
6673 Don't do this on return from a stack dummy routine,
6674 or if the program has exited. */
6676 if (!stop_stack_dummy
)
6678 select_frame (get_current_frame ());
6680 /* If --batch-silent is enabled then there's no need to print the current
6681 source location, and to try risks causing an error message about
6682 missing source files. */
6683 if (stop_print_frame
&& !batch_silent
)
6684 print_stop_event (&last
);
6687 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6689 /* Pop the empty frame that contains the stack dummy.
6690 This also restores inferior state prior to the call
6691 (struct infcall_suspend_state). */
6692 struct frame_info
*frame
= get_current_frame ();
6694 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6696 /* frame_pop() calls reinit_frame_cache as the last thing it
6697 does which means there's currently no selected frame. We
6698 don't need to re-establish a selected frame if the dummy call
6699 returns normally, that will be done by
6700 restore_infcall_control_state. However, we do have to handle
6701 the case where the dummy call is returning after being
6702 stopped (e.g. the dummy call previously hit a breakpoint).
6703 We can't know which case we have so just always re-establish
6704 a selected frame here. */
6705 select_frame (get_current_frame ());
6709 annotate_stopped ();
6711 /* Suppress the stop observer if we're in the middle of:
6713 - a step n (n > 1), as there still more steps to be done.
6715 - a "finish" command, as the observer will be called in
6716 finish_command_continuation, so it can include the inferior
6717 function's return value.
6719 - calling an inferior function, as we pretend we inferior didn't
6720 run at all. The return value of the call is handled by the
6721 expression evaluator, through call_function_by_hand. */
6723 if (!target_has_execution
6724 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6725 || last
.kind
== TARGET_WAITKIND_EXITED
6726 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6727 || (!(inferior_thread ()->step_multi
6728 && inferior_thread ()->control
.stop_step
)
6729 && !(inferior_thread ()->control
.stop_bpstat
6730 && inferior_thread ()->control
.proceed_to_finish
)
6731 && !inferior_thread ()->control
.in_infcall
))
6733 if (!ptid_equal (inferior_ptid
, null_ptid
))
6734 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6737 observer_notify_normal_stop (NULL
, stop_print_frame
);
6740 if (target_has_execution
)
6742 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6743 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6744 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6745 Delete any breakpoint that is to be deleted at the next stop. */
6746 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6749 /* Try to get rid of automatically added inferiors that are no
6750 longer needed. Keeping those around slows down things linearly.
6751 Note that this never removes the current inferior. */
6756 hook_stop_stub (void *cmd
)
6758 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6763 signal_stop_state (int signo
)
6765 return signal_stop
[signo
];
6769 signal_print_state (int signo
)
6771 return signal_print
[signo
];
6775 signal_pass_state (int signo
)
6777 return signal_program
[signo
];
6781 signal_cache_update (int signo
)
6785 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6786 signal_cache_update (signo
);
6791 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6792 && signal_print
[signo
] == 0
6793 && signal_program
[signo
] == 1
6794 && signal_catch
[signo
] == 0);
6798 signal_stop_update (int signo
, int state
)
6800 int ret
= signal_stop
[signo
];
6802 signal_stop
[signo
] = state
;
6803 signal_cache_update (signo
);
6808 signal_print_update (int signo
, int state
)
6810 int ret
= signal_print
[signo
];
6812 signal_print
[signo
] = state
;
6813 signal_cache_update (signo
);
6818 signal_pass_update (int signo
, int state
)
6820 int ret
= signal_program
[signo
];
6822 signal_program
[signo
] = state
;
6823 signal_cache_update (signo
);
6827 /* Update the global 'signal_catch' from INFO and notify the
6831 signal_catch_update (const unsigned int *info
)
6835 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6836 signal_catch
[i
] = info
[i
] > 0;
6837 signal_cache_update (-1);
6838 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6842 sig_print_header (void)
6844 printf_filtered (_("Signal Stop\tPrint\tPass "
6845 "to program\tDescription\n"));
6849 sig_print_info (enum gdb_signal oursig
)
6851 const char *name
= gdb_signal_to_name (oursig
);
6852 int name_padding
= 13 - strlen (name
);
6854 if (name_padding
<= 0)
6857 printf_filtered ("%s", name
);
6858 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6859 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6860 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6861 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6862 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6865 /* Specify how various signals in the inferior should be handled. */
6868 handle_command (char *args
, int from_tty
)
6871 int digits
, wordlen
;
6872 int sigfirst
, signum
, siglast
;
6873 enum gdb_signal oursig
;
6876 unsigned char *sigs
;
6877 struct cleanup
*old_chain
;
6881 error_no_arg (_("signal to handle"));
6884 /* Allocate and zero an array of flags for which signals to handle. */
6886 nsigs
= (int) GDB_SIGNAL_LAST
;
6887 sigs
= (unsigned char *) alloca (nsigs
);
6888 memset (sigs
, 0, nsigs
);
6890 /* Break the command line up into args. */
6892 argv
= gdb_buildargv (args
);
6893 old_chain
= make_cleanup_freeargv (argv
);
6895 /* Walk through the args, looking for signal oursigs, signal names, and
6896 actions. Signal numbers and signal names may be interspersed with
6897 actions, with the actions being performed for all signals cumulatively
6898 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6900 while (*argv
!= NULL
)
6902 wordlen
= strlen (*argv
);
6903 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6907 sigfirst
= siglast
= -1;
6909 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6911 /* Apply action to all signals except those used by the
6912 debugger. Silently skip those. */
6915 siglast
= nsigs
- 1;
6917 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6919 SET_SIGS (nsigs
, sigs
, signal_stop
);
6920 SET_SIGS (nsigs
, sigs
, signal_print
);
6922 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6924 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6926 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6928 SET_SIGS (nsigs
, sigs
, signal_print
);
6930 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6932 SET_SIGS (nsigs
, sigs
, signal_program
);
6934 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6936 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6938 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6940 SET_SIGS (nsigs
, sigs
, signal_program
);
6942 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6944 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6945 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6947 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6949 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6951 else if (digits
> 0)
6953 /* It is numeric. The numeric signal refers to our own
6954 internal signal numbering from target.h, not to host/target
6955 signal number. This is a feature; users really should be
6956 using symbolic names anyway, and the common ones like
6957 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6959 sigfirst
= siglast
= (int)
6960 gdb_signal_from_command (atoi (*argv
));
6961 if ((*argv
)[digits
] == '-')
6964 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6966 if (sigfirst
> siglast
)
6968 /* Bet he didn't figure we'd think of this case... */
6976 oursig
= gdb_signal_from_name (*argv
);
6977 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6979 sigfirst
= siglast
= (int) oursig
;
6983 /* Not a number and not a recognized flag word => complain. */
6984 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6988 /* If any signal numbers or symbol names were found, set flags for
6989 which signals to apply actions to. */
6991 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6993 switch ((enum gdb_signal
) signum
)
6995 case GDB_SIGNAL_TRAP
:
6996 case GDB_SIGNAL_INT
:
6997 if (!allsigs
&& !sigs
[signum
])
6999 if (query (_("%s is used by the debugger.\n\
7000 Are you sure you want to change it? "),
7001 gdb_signal_to_name ((enum gdb_signal
) signum
)))
7007 printf_unfiltered (_("Not confirmed, unchanged.\n"));
7008 gdb_flush (gdb_stdout
);
7013 case GDB_SIGNAL_DEFAULT
:
7014 case GDB_SIGNAL_UNKNOWN
:
7015 /* Make sure that "all" doesn't print these. */
7026 for (signum
= 0; signum
< nsigs
; signum
++)
7029 signal_cache_update (-1);
7030 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
7031 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
7035 /* Show the results. */
7036 sig_print_header ();
7037 for (; signum
< nsigs
; signum
++)
7039 sig_print_info (signum
);
7045 do_cleanups (old_chain
);
7048 /* Complete the "handle" command. */
7050 static VEC (char_ptr
) *
7051 handle_completer (struct cmd_list_element
*ignore
,
7052 const char *text
, const char *word
)
7054 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
7055 static const char * const keywords
[] =
7069 vec_signals
= signal_completer (ignore
, text
, word
);
7070 vec_keywords
= complete_on_enum (keywords
, word
, word
);
7072 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
7073 VEC_free (char_ptr
, vec_signals
);
7074 VEC_free (char_ptr
, vec_keywords
);
7079 gdb_signal_from_command (int num
)
7081 if (num
>= 1 && num
<= 15)
7082 return (enum gdb_signal
) num
;
7083 error (_("Only signals 1-15 are valid as numeric signals.\n\
7084 Use \"info signals\" for a list of symbolic signals."));
7087 /* Print current contents of the tables set by the handle command.
7088 It is possible we should just be printing signals actually used
7089 by the current target (but for things to work right when switching
7090 targets, all signals should be in the signal tables). */
7093 signals_info (char *signum_exp
, int from_tty
)
7095 enum gdb_signal oursig
;
7097 sig_print_header ();
7101 /* First see if this is a symbol name. */
7102 oursig
= gdb_signal_from_name (signum_exp
);
7103 if (oursig
== GDB_SIGNAL_UNKNOWN
)
7105 /* No, try numeric. */
7107 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
7109 sig_print_info (oursig
);
7113 printf_filtered ("\n");
7114 /* These ugly casts brought to you by the native VAX compiler. */
7115 for (oursig
= GDB_SIGNAL_FIRST
;
7116 (int) oursig
< (int) GDB_SIGNAL_LAST
;
7117 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
7121 if (oursig
!= GDB_SIGNAL_UNKNOWN
7122 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
7123 sig_print_info (oursig
);
7126 printf_filtered (_("\nUse the \"handle\" command "
7127 "to change these tables.\n"));
7130 /* Check if it makes sense to read $_siginfo from the current thread
7131 at this point. If not, throw an error. */
7134 validate_siginfo_access (void)
7136 /* No current inferior, no siginfo. */
7137 if (ptid_equal (inferior_ptid
, null_ptid
))
7138 error (_("No thread selected."));
7140 /* Don't try to read from a dead thread. */
7141 if (is_exited (inferior_ptid
))
7142 error (_("The current thread has terminated"));
7144 /* ... or from a spinning thread. */
7145 if (is_running (inferior_ptid
))
7146 error (_("Selected thread is running."));
7149 /* The $_siginfo convenience variable is a bit special. We don't know
7150 for sure the type of the value until we actually have a chance to
7151 fetch the data. The type can change depending on gdbarch, so it is
7152 also dependent on which thread you have selected.
7154 1. making $_siginfo be an internalvar that creates a new value on
7157 2. making the value of $_siginfo be an lval_computed value. */
7159 /* This function implements the lval_computed support for reading a
7163 siginfo_value_read (struct value
*v
)
7165 LONGEST transferred
;
7167 validate_siginfo_access ();
7170 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
7172 value_contents_all_raw (v
),
7174 TYPE_LENGTH (value_type (v
)));
7176 if (transferred
!= TYPE_LENGTH (value_type (v
)))
7177 error (_("Unable to read siginfo"));
7180 /* This function implements the lval_computed support for writing a
7184 siginfo_value_write (struct value
*v
, struct value
*fromval
)
7186 LONGEST transferred
;
7188 validate_siginfo_access ();
7190 transferred
= target_write (¤t_target
,
7191 TARGET_OBJECT_SIGNAL_INFO
,
7193 value_contents_all_raw (fromval
),
7195 TYPE_LENGTH (value_type (fromval
)));
7197 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
7198 error (_("Unable to write siginfo"));
7201 static const struct lval_funcs siginfo_value_funcs
=
7207 /* Return a new value with the correct type for the siginfo object of
7208 the current thread using architecture GDBARCH. Return a void value
7209 if there's no object available. */
7211 static struct value
*
7212 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
7215 if (target_has_stack
7216 && !ptid_equal (inferior_ptid
, null_ptid
)
7217 && gdbarch_get_siginfo_type_p (gdbarch
))
7219 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7221 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
7224 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
7228 /* infcall_suspend_state contains state about the program itself like its
7229 registers and any signal it received when it last stopped.
7230 This state must be restored regardless of how the inferior function call
7231 ends (either successfully, or after it hits a breakpoint or signal)
7232 if the program is to properly continue where it left off. */
7234 struct infcall_suspend_state
7236 struct thread_suspend_state thread_suspend
;
7237 #if 0 /* Currently unused and empty structures are not valid C. */
7238 struct inferior_suspend_state inferior_suspend
;
7243 struct regcache
*registers
;
7245 /* Format of SIGINFO_DATA or NULL if it is not present. */
7246 struct gdbarch
*siginfo_gdbarch
;
7248 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
7249 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
7250 content would be invalid. */
7251 gdb_byte
*siginfo_data
;
7254 struct infcall_suspend_state
*
7255 save_infcall_suspend_state (void)
7257 struct infcall_suspend_state
*inf_state
;
7258 struct thread_info
*tp
= inferior_thread ();
7260 struct inferior
*inf
= current_inferior ();
7262 struct regcache
*regcache
= get_current_regcache ();
7263 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7264 gdb_byte
*siginfo_data
= NULL
;
7266 if (gdbarch_get_siginfo_type_p (gdbarch
))
7268 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7269 size_t len
= TYPE_LENGTH (type
);
7270 struct cleanup
*back_to
;
7272 siginfo_data
= xmalloc (len
);
7273 back_to
= make_cleanup (xfree
, siginfo_data
);
7275 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7276 siginfo_data
, 0, len
) == len
)
7277 discard_cleanups (back_to
);
7280 /* Errors ignored. */
7281 do_cleanups (back_to
);
7282 siginfo_data
= NULL
;
7286 inf_state
= XCNEW (struct infcall_suspend_state
);
7290 inf_state
->siginfo_gdbarch
= gdbarch
;
7291 inf_state
->siginfo_data
= siginfo_data
;
7294 inf_state
->thread_suspend
= tp
->suspend
;
7295 #if 0 /* Currently unused and empty structures are not valid C. */
7296 inf_state
->inferior_suspend
= inf
->suspend
;
7299 /* run_inferior_call will not use the signal due to its `proceed' call with
7300 GDB_SIGNAL_0 anyway. */
7301 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7303 inf_state
->stop_pc
= stop_pc
;
7305 inf_state
->registers
= regcache_dup (regcache
);
7310 /* Restore inferior session state to INF_STATE. */
7313 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7315 struct thread_info
*tp
= inferior_thread ();
7317 struct inferior
*inf
= current_inferior ();
7319 struct regcache
*regcache
= get_current_regcache ();
7320 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7322 tp
->suspend
= inf_state
->thread_suspend
;
7323 #if 0 /* Currently unused and empty structures are not valid C. */
7324 inf
->suspend
= inf_state
->inferior_suspend
;
7327 stop_pc
= inf_state
->stop_pc
;
7329 if (inf_state
->siginfo_gdbarch
== gdbarch
)
7331 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7333 /* Errors ignored. */
7334 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7335 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
7338 /* The inferior can be gone if the user types "print exit(0)"
7339 (and perhaps other times). */
7340 if (target_has_execution
)
7341 /* NB: The register write goes through to the target. */
7342 regcache_cpy (regcache
, inf_state
->registers
);
7344 discard_infcall_suspend_state (inf_state
);
7348 do_restore_infcall_suspend_state_cleanup (void *state
)
7350 restore_infcall_suspend_state (state
);
7354 make_cleanup_restore_infcall_suspend_state
7355 (struct infcall_suspend_state
*inf_state
)
7357 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
7361 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7363 regcache_xfree (inf_state
->registers
);
7364 xfree (inf_state
->siginfo_data
);
7369 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
7371 return inf_state
->registers
;
7374 /* infcall_control_state contains state regarding gdb's control of the
7375 inferior itself like stepping control. It also contains session state like
7376 the user's currently selected frame. */
7378 struct infcall_control_state
7380 struct thread_control_state thread_control
;
7381 struct inferior_control_state inferior_control
;
7384 enum stop_stack_kind stop_stack_dummy
;
7385 int stopped_by_random_signal
;
7386 int stop_after_trap
;
7388 /* ID if the selected frame when the inferior function call was made. */
7389 struct frame_id selected_frame_id
;
7392 /* Save all of the information associated with the inferior<==>gdb
7395 struct infcall_control_state
*
7396 save_infcall_control_state (void)
7398 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
7399 struct thread_info
*tp
= inferior_thread ();
7400 struct inferior
*inf
= current_inferior ();
7402 inf_status
->thread_control
= tp
->control
;
7403 inf_status
->inferior_control
= inf
->control
;
7405 tp
->control
.step_resume_breakpoint
= NULL
;
7406 tp
->control
.exception_resume_breakpoint
= NULL
;
7408 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7409 chain. If caller's caller is walking the chain, they'll be happier if we
7410 hand them back the original chain when restore_infcall_control_state is
7412 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
7415 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
7416 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
7417 inf_status
->stop_after_trap
= stop_after_trap
;
7419 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
7425 restore_selected_frame (void *args
)
7427 struct frame_id
*fid
= (struct frame_id
*) args
;
7428 struct frame_info
*frame
;
7430 frame
= frame_find_by_id (*fid
);
7432 /* If inf_status->selected_frame_id is NULL, there was no previously
7436 warning (_("Unable to restore previously selected frame."));
7440 select_frame (frame
);
7445 /* Restore inferior session state to INF_STATUS. */
7448 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
7450 struct thread_info
*tp
= inferior_thread ();
7451 struct inferior
*inf
= current_inferior ();
7453 if (tp
->control
.step_resume_breakpoint
)
7454 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
7456 if (tp
->control
.exception_resume_breakpoint
)
7457 tp
->control
.exception_resume_breakpoint
->disposition
7458 = disp_del_at_next_stop
;
7460 /* Handle the bpstat_copy of the chain. */
7461 bpstat_clear (&tp
->control
.stop_bpstat
);
7463 tp
->control
= inf_status
->thread_control
;
7464 inf
->control
= inf_status
->inferior_control
;
7467 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
7468 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
7469 stop_after_trap
= inf_status
->stop_after_trap
;
7471 if (target_has_stack
)
7473 /* The point of catch_errors is that if the stack is clobbered,
7474 walking the stack might encounter a garbage pointer and
7475 error() trying to dereference it. */
7477 (restore_selected_frame
, &inf_status
->selected_frame_id
,
7478 "Unable to restore previously selected frame:\n",
7479 RETURN_MASK_ERROR
) == 0)
7480 /* Error in restoring the selected frame. Select the innermost
7482 select_frame (get_current_frame ());
7489 do_restore_infcall_control_state_cleanup (void *sts
)
7491 restore_infcall_control_state (sts
);
7495 make_cleanup_restore_infcall_control_state
7496 (struct infcall_control_state
*inf_status
)
7498 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7502 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7504 if (inf_status
->thread_control
.step_resume_breakpoint
)
7505 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7506 = disp_del_at_next_stop
;
7508 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7509 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7510 = disp_del_at_next_stop
;
7512 /* See save_infcall_control_state for info on stop_bpstat. */
7513 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7518 /* restore_inferior_ptid() will be used by the cleanup machinery
7519 to restore the inferior_ptid value saved in a call to
7520 save_inferior_ptid(). */
7523 restore_inferior_ptid (void *arg
)
7525 ptid_t
*saved_ptid_ptr
= arg
;
7527 inferior_ptid
= *saved_ptid_ptr
;
7531 /* Save the value of inferior_ptid so that it may be restored by a
7532 later call to do_cleanups(). Returns the struct cleanup pointer
7533 needed for later doing the cleanup. */
7536 save_inferior_ptid (void)
7538 ptid_t
*saved_ptid_ptr
;
7540 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7541 *saved_ptid_ptr
= inferior_ptid
;
7542 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7548 clear_exit_convenience_vars (void)
7550 clear_internalvar (lookup_internalvar ("_exitsignal"));
7551 clear_internalvar (lookup_internalvar ("_exitcode"));
7555 /* User interface for reverse debugging:
7556 Set exec-direction / show exec-direction commands
7557 (returns error unless target implements to_set_exec_direction method). */
7559 int execution_direction
= EXEC_FORWARD
;
7560 static const char exec_forward
[] = "forward";
7561 static const char exec_reverse
[] = "reverse";
7562 static const char *exec_direction
= exec_forward
;
7563 static const char *const exec_direction_names
[] = {
7570 set_exec_direction_func (char *args
, int from_tty
,
7571 struct cmd_list_element
*cmd
)
7573 if (target_can_execute_reverse
)
7575 if (!strcmp (exec_direction
, exec_forward
))
7576 execution_direction
= EXEC_FORWARD
;
7577 else if (!strcmp (exec_direction
, exec_reverse
))
7578 execution_direction
= EXEC_REVERSE
;
7582 exec_direction
= exec_forward
;
7583 error (_("Target does not support this operation."));
7588 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7589 struct cmd_list_element
*cmd
, const char *value
)
7591 switch (execution_direction
) {
7593 fprintf_filtered (out
, _("Forward.\n"));
7596 fprintf_filtered (out
, _("Reverse.\n"));
7599 internal_error (__FILE__
, __LINE__
,
7600 _("bogus execution_direction value: %d"),
7601 (int) execution_direction
);
7606 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7607 struct cmd_list_element
*c
, const char *value
)
7609 fprintf_filtered (file
, _("Resuming the execution of threads "
7610 "of all processes is %s.\n"), value
);
7613 /* Implementation of `siginfo' variable. */
7615 static const struct internalvar_funcs siginfo_funcs
=
7623 _initialize_infrun (void)
7627 struct cmd_list_element
*c
;
7629 add_info ("signals", signals_info
, _("\
7630 What debugger does when program gets various signals.\n\
7631 Specify a signal as argument to print info on that signal only."));
7632 add_info_alias ("handle", "signals", 0);
7634 c
= add_com ("handle", class_run
, handle_command
, _("\
7635 Specify how to handle signals.\n\
7636 Usage: handle SIGNAL [ACTIONS]\n\
7637 Args are signals and actions to apply to those signals.\n\
7638 If no actions are specified, the current settings for the specified signals\n\
7639 will be displayed instead.\n\
7641 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7642 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7643 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7644 The special arg \"all\" is recognized to mean all signals except those\n\
7645 used by the debugger, typically SIGTRAP and SIGINT.\n\
7647 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7648 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7649 Stop means reenter debugger if this signal happens (implies print).\n\
7650 Print means print a message if this signal happens.\n\
7651 Pass means let program see this signal; otherwise program doesn't know.\n\
7652 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7653 Pass and Stop may be combined.\n\
7655 Multiple signals may be specified. Signal numbers and signal names\n\
7656 may be interspersed with actions, with the actions being performed for\n\
7657 all signals cumulatively specified."));
7658 set_cmd_completer (c
, handle_completer
);
7661 stop_command
= add_cmd ("stop", class_obscure
,
7662 not_just_help_class_command
, _("\
7663 There is no `stop' command, but you can set a hook on `stop'.\n\
7664 This allows you to set a list of commands to be run each time execution\n\
7665 of the program stops."), &cmdlist
);
7667 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7668 Set inferior debugging."), _("\
7669 Show inferior debugging."), _("\
7670 When non-zero, inferior specific debugging is enabled."),
7673 &setdebuglist
, &showdebuglist
);
7675 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7676 &debug_displaced
, _("\
7677 Set displaced stepping debugging."), _("\
7678 Show displaced stepping debugging."), _("\
7679 When non-zero, displaced stepping specific debugging is enabled."),
7681 show_debug_displaced
,
7682 &setdebuglist
, &showdebuglist
);
7684 add_setshow_boolean_cmd ("non-stop", no_class
,
7686 Set whether gdb controls the inferior in non-stop mode."), _("\
7687 Show whether gdb controls the inferior in non-stop mode."), _("\
7688 When debugging a multi-threaded program and this setting is\n\
7689 off (the default, also called all-stop mode), when one thread stops\n\
7690 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7691 all other threads in the program while you interact with the thread of\n\
7692 interest. When you continue or step a thread, you can allow the other\n\
7693 threads to run, or have them remain stopped, but while you inspect any\n\
7694 thread's state, all threads stop.\n\
7696 In non-stop mode, when one thread stops, other threads can continue\n\
7697 to run freely. You'll be able to step each thread independently,\n\
7698 leave it stopped or free to run as needed."),
7704 numsigs
= (int) GDB_SIGNAL_LAST
;
7705 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7706 signal_print
= (unsigned char *)
7707 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7708 signal_program
= (unsigned char *)
7709 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7710 signal_catch
= (unsigned char *)
7711 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7712 signal_pass
= (unsigned char *)
7713 xmalloc (sizeof (signal_pass
[0]) * numsigs
);
7714 for (i
= 0; i
< numsigs
; i
++)
7717 signal_print
[i
] = 1;
7718 signal_program
[i
] = 1;
7719 signal_catch
[i
] = 0;
7722 /* Signals caused by debugger's own actions
7723 should not be given to the program afterwards. */
7724 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7725 signal_program
[GDB_SIGNAL_INT
] = 0;
7727 /* Signals that are not errors should not normally enter the debugger. */
7728 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7729 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7730 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7731 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7732 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7733 signal_print
[GDB_SIGNAL_PROF
] = 0;
7734 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7735 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7736 signal_stop
[GDB_SIGNAL_IO
] = 0;
7737 signal_print
[GDB_SIGNAL_IO
] = 0;
7738 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7739 signal_print
[GDB_SIGNAL_POLL
] = 0;
7740 signal_stop
[GDB_SIGNAL_URG
] = 0;
7741 signal_print
[GDB_SIGNAL_URG
] = 0;
7742 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7743 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7744 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7745 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7747 /* These signals are used internally by user-level thread
7748 implementations. (See signal(5) on Solaris.) Like the above
7749 signals, a healthy program receives and handles them as part of
7750 its normal operation. */
7751 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7752 signal_print
[GDB_SIGNAL_LWP
] = 0;
7753 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7754 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7755 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7756 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7758 /* Update cached state. */
7759 signal_cache_update (-1);
7761 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7762 &stop_on_solib_events
, _("\
7763 Set stopping for shared library events."), _("\
7764 Show stopping for shared library events."), _("\
7765 If nonzero, gdb will give control to the user when the dynamic linker\n\
7766 notifies gdb of shared library events. The most common event of interest\n\
7767 to the user would be loading/unloading of a new library."),
7768 set_stop_on_solib_events
,
7769 show_stop_on_solib_events
,
7770 &setlist
, &showlist
);
7772 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7773 follow_fork_mode_kind_names
,
7774 &follow_fork_mode_string
, _("\
7775 Set debugger response to a program call of fork or vfork."), _("\
7776 Show debugger response to a program call of fork or vfork."), _("\
7777 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7778 parent - the original process is debugged after a fork\n\
7779 child - the new process is debugged after a fork\n\
7780 The unfollowed process will continue to run.\n\
7781 By default, the debugger will follow the parent process."),
7783 show_follow_fork_mode_string
,
7784 &setlist
, &showlist
);
7786 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7787 follow_exec_mode_names
,
7788 &follow_exec_mode_string
, _("\
7789 Set debugger response to a program call of exec."), _("\
7790 Show debugger response to a program call of exec."), _("\
7791 An exec call replaces the program image of a process.\n\
7793 follow-exec-mode can be:\n\
7795 new - the debugger creates a new inferior and rebinds the process\n\
7796 to this new inferior. The program the process was running before\n\
7797 the exec call can be restarted afterwards by restarting the original\n\
7800 same - the debugger keeps the process bound to the same inferior.\n\
7801 The new executable image replaces the previous executable loaded in\n\
7802 the inferior. Restarting the inferior after the exec call restarts\n\
7803 the executable the process was running after the exec call.\n\
7805 By default, the debugger will use the same inferior."),
7807 show_follow_exec_mode_string
,
7808 &setlist
, &showlist
);
7810 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7811 scheduler_enums
, &scheduler_mode
, _("\
7812 Set mode for locking scheduler during execution."), _("\
7813 Show mode for locking scheduler during execution."), _("\
7814 off == no locking (threads may preempt at any time)\n\
7815 on == full locking (no thread except the current thread may run)\n\
7816 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
7817 In this mode, other threads may run during other commands."),
7818 set_schedlock_func
, /* traps on target vector */
7819 show_scheduler_mode
,
7820 &setlist
, &showlist
);
7822 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7823 Set mode for resuming threads of all processes."), _("\
7824 Show mode for resuming threads of all processes."), _("\
7825 When on, execution commands (such as 'continue' or 'next') resume all\n\
7826 threads of all processes. When off (which is the default), execution\n\
7827 commands only resume the threads of the current process. The set of\n\
7828 threads that are resumed is further refined by the scheduler-locking\n\
7829 mode (see help set scheduler-locking)."),
7831 show_schedule_multiple
,
7832 &setlist
, &showlist
);
7834 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7835 Set mode of the step operation."), _("\
7836 Show mode of the step operation."), _("\
7837 When set, doing a step over a function without debug line information\n\
7838 will stop at the first instruction of that function. Otherwise, the\n\
7839 function is skipped and the step command stops at a different source line."),
7841 show_step_stop_if_no_debug
,
7842 &setlist
, &showlist
);
7844 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7845 &can_use_displaced_stepping
, _("\
7846 Set debugger's willingness to use displaced stepping."), _("\
7847 Show debugger's willingness to use displaced stepping."), _("\
7848 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7849 supported by the target architecture. If off, gdb will not use displaced\n\
7850 stepping to step over breakpoints, even if such is supported by the target\n\
7851 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7852 if the target architecture supports it and non-stop mode is active, but will not\n\
7853 use it in all-stop mode (see help set non-stop)."),
7855 show_can_use_displaced_stepping
,
7856 &setlist
, &showlist
);
7858 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7859 &exec_direction
, _("Set direction of execution.\n\
7860 Options are 'forward' or 'reverse'."),
7861 _("Show direction of execution (forward/reverse)."),
7862 _("Tells gdb whether to execute forward or backward."),
7863 set_exec_direction_func
, show_exec_direction_func
,
7864 &setlist
, &showlist
);
7866 /* Set/show detach-on-fork: user-settable mode. */
7868 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7869 Set whether gdb will detach the child of a fork."), _("\
7870 Show whether gdb will detach the child of a fork."), _("\
7871 Tells gdb whether to detach the child of a fork."),
7872 NULL
, NULL
, &setlist
, &showlist
);
7874 /* Set/show disable address space randomization mode. */
7876 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7877 &disable_randomization
, _("\
7878 Set disabling of debuggee's virtual address space randomization."), _("\
7879 Show disabling of debuggee's virtual address space randomization."), _("\
7880 When this mode is on (which is the default), randomization of the virtual\n\
7881 address space is disabled. Standalone programs run with the randomization\n\
7882 enabled by default on some platforms."),
7883 &set_disable_randomization
,
7884 &show_disable_randomization
,
7885 &setlist
, &showlist
);
7887 /* ptid initializations */
7888 inferior_ptid
= null_ptid
;
7889 target_last_wait_ptid
= minus_one_ptid
;
7891 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7892 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7893 observer_attach_thread_exit (infrun_thread_thread_exit
);
7894 observer_attach_inferior_exit (infrun_inferior_exit
);
7896 /* Explicitly create without lookup, since that tries to create a
7897 value with a void typed value, and when we get here, gdbarch
7898 isn't initialized yet. At this point, we're quite sure there
7899 isn't another convenience variable of the same name. */
7900 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7902 add_setshow_boolean_cmd ("observer", no_class
,
7903 &observer_mode_1
, _("\
7904 Set whether gdb controls the inferior in observer mode."), _("\
7905 Show whether gdb controls the inferior in observer mode."), _("\
7906 In observer mode, GDB can get data from the inferior, but not\n\
7907 affect its execution. Registers and memory may not be changed,\n\
7908 breakpoints may not be set, and the program cannot be interrupted\n\