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_1 (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 /* A wrapper around handle_inferior_event_1, which also makes sure
4206 that all temporary struct value objects that were created during
4207 the handling of the event get deleted at the end. */
4210 handle_inferior_event (struct execution_control_state
*ecs
)
4212 struct value
*mark
= value_mark ();
4214 handle_inferior_event_1 (ecs
);
4215 /* Purge all temporary values created during the event handling,
4216 as it could be a long time before we return to the command level
4217 where such values would otherwise be purged. */
4218 value_free_to_mark (mark
);
4221 /* Come here when the program has stopped with a signal. */
4224 handle_signal_stop (struct execution_control_state
*ecs
)
4226 struct frame_info
*frame
;
4227 struct gdbarch
*gdbarch
;
4228 int stopped_by_watchpoint
;
4229 enum stop_kind stop_soon
;
4232 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
4234 /* Do we need to clean up the state of a thread that has
4235 completed a displaced single-step? (Doing so usually affects
4236 the PC, so do it here, before we set stop_pc.) */
4237 displaced_step_fixup (ecs
->ptid
,
4238 ecs
->event_thread
->suspend
.stop_signal
);
4240 /* If we either finished a single-step or hit a breakpoint, but
4241 the user wanted this thread to be stopped, pretend we got a
4242 SIG0 (generic unsignaled stop). */
4243 if (ecs
->event_thread
->stop_requested
4244 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4245 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4247 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4251 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
4252 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4253 struct cleanup
*old_chain
= save_inferior_ptid ();
4255 inferior_ptid
= ecs
->ptid
;
4257 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
4258 paddress (gdbarch
, stop_pc
));
4259 if (target_stopped_by_watchpoint ())
4263 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
4265 if (target_stopped_data_address (¤t_target
, &addr
))
4266 fprintf_unfiltered (gdb_stdlog
,
4267 "infrun: stopped data address = %s\n",
4268 paddress (gdbarch
, addr
));
4270 fprintf_unfiltered (gdb_stdlog
,
4271 "infrun: (no data address available)\n");
4274 do_cleanups (old_chain
);
4277 /* This is originated from start_remote(), start_inferior() and
4278 shared libraries hook functions. */
4279 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
4280 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4282 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4283 context_switch (ecs
->ptid
);
4285 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4286 stop_print_frame
= 1;
4291 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4294 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4295 context_switch (ecs
->ptid
);
4297 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4298 stop_print_frame
= 0;
4303 /* This originates from attach_command(). We need to overwrite
4304 the stop_signal here, because some kernels don't ignore a
4305 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4306 See more comments in inferior.h. On the other hand, if we
4307 get a non-SIGSTOP, report it to the user - assume the backend
4308 will handle the SIGSTOP if it should show up later.
4310 Also consider that the attach is complete when we see a
4311 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4312 target extended-remote report it instead of a SIGSTOP
4313 (e.g. gdbserver). We already rely on SIGTRAP being our
4314 signal, so this is no exception.
4316 Also consider that the attach is complete when we see a
4317 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4318 the target to stop all threads of the inferior, in case the
4319 low level attach operation doesn't stop them implicitly. If
4320 they weren't stopped implicitly, then the stub will report a
4321 GDB_SIGNAL_0, meaning: stopped for no particular reason
4322 other than GDB's request. */
4323 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4324 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4325 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4326 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4328 stop_print_frame
= 1;
4330 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4334 /* See if something interesting happened to the non-current thread. If
4335 so, then switch to that thread. */
4336 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4339 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
4341 context_switch (ecs
->ptid
);
4343 if (deprecated_context_hook
)
4344 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
4347 /* At this point, get hold of the now-current thread's frame. */
4348 frame
= get_current_frame ();
4349 gdbarch
= get_frame_arch (frame
);
4351 /* Pull the single step breakpoints out of the target. */
4352 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4354 struct regcache
*regcache
;
4355 struct address_space
*aspace
;
4358 regcache
= get_thread_regcache (ecs
->ptid
);
4359 aspace
= get_regcache_aspace (regcache
);
4360 pc
= regcache_read_pc (regcache
);
4362 /* However, before doing so, if this single-step breakpoint was
4363 actually for another thread, set this thread up for moving
4365 if (!thread_has_single_step_breakpoint_here (ecs
->event_thread
,
4368 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4372 fprintf_unfiltered (gdb_stdlog
,
4373 "infrun: [%s] hit another thread's "
4374 "single-step breakpoint\n",
4375 target_pid_to_str (ecs
->ptid
));
4377 ecs
->hit_singlestep_breakpoint
= 1;
4384 fprintf_unfiltered (gdb_stdlog
,
4385 "infrun: [%s] hit its "
4386 "single-step breakpoint\n",
4387 target_pid_to_str (ecs
->ptid
));
4391 delete_just_stopped_threads_single_step_breakpoints ();
4393 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4394 && ecs
->event_thread
->control
.trap_expected
4395 && ecs
->event_thread
->stepping_over_watchpoint
)
4396 stopped_by_watchpoint
= 0;
4398 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4400 /* If necessary, step over this watchpoint. We'll be back to display
4402 if (stopped_by_watchpoint
4403 && (target_have_steppable_watchpoint
4404 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4406 /* At this point, we are stopped at an instruction which has
4407 attempted to write to a piece of memory under control of
4408 a watchpoint. The instruction hasn't actually executed
4409 yet. If we were to evaluate the watchpoint expression
4410 now, we would get the old value, and therefore no change
4411 would seem to have occurred.
4413 In order to make watchpoints work `right', we really need
4414 to complete the memory write, and then evaluate the
4415 watchpoint expression. We do this by single-stepping the
4418 It may not be necessary to disable the watchpoint to step over
4419 it. For example, the PA can (with some kernel cooperation)
4420 single step over a watchpoint without disabling the watchpoint.
4422 It is far more common to need to disable a watchpoint to step
4423 the inferior over it. If we have non-steppable watchpoints,
4424 we must disable the current watchpoint; it's simplest to
4425 disable all watchpoints.
4427 Any breakpoint at PC must also be stepped over -- if there's
4428 one, it will have already triggered before the watchpoint
4429 triggered, and we either already reported it to the user, or
4430 it didn't cause a stop and we called keep_going. In either
4431 case, if there was a breakpoint at PC, we must be trying to
4433 ecs
->event_thread
->stepping_over_watchpoint
= 1;
4438 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4439 ecs
->event_thread
->stepping_over_watchpoint
= 0;
4440 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4441 ecs
->event_thread
->control
.stop_step
= 0;
4442 stop_print_frame
= 1;
4443 stopped_by_random_signal
= 0;
4445 /* Hide inlined functions starting here, unless we just performed stepi or
4446 nexti. After stepi and nexti, always show the innermost frame (not any
4447 inline function call sites). */
4448 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4450 struct address_space
*aspace
=
4451 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4453 /* skip_inline_frames is expensive, so we avoid it if we can
4454 determine that the address is one where functions cannot have
4455 been inlined. This improves performance with inferiors that
4456 load a lot of shared libraries, because the solib event
4457 breakpoint is defined as the address of a function (i.e. not
4458 inline). Note that we have to check the previous PC as well
4459 as the current one to catch cases when we have just
4460 single-stepped off a breakpoint prior to reinstating it.
4461 Note that we're assuming that the code we single-step to is
4462 not inline, but that's not definitive: there's nothing
4463 preventing the event breakpoint function from containing
4464 inlined code, and the single-step ending up there. If the
4465 user had set a breakpoint on that inlined code, the missing
4466 skip_inline_frames call would break things. Fortunately
4467 that's an extremely unlikely scenario. */
4468 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4469 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4470 && ecs
->event_thread
->control
.trap_expected
4471 && pc_at_non_inline_function (aspace
,
4472 ecs
->event_thread
->prev_pc
,
4475 skip_inline_frames (ecs
->ptid
);
4477 /* Re-fetch current thread's frame in case that invalidated
4479 frame
= get_current_frame ();
4480 gdbarch
= get_frame_arch (frame
);
4484 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4485 && ecs
->event_thread
->control
.trap_expected
4486 && gdbarch_single_step_through_delay_p (gdbarch
)
4487 && currently_stepping (ecs
->event_thread
))
4489 /* We're trying to step off a breakpoint. Turns out that we're
4490 also on an instruction that needs to be stepped multiple
4491 times before it's been fully executing. E.g., architectures
4492 with a delay slot. It needs to be stepped twice, once for
4493 the instruction and once for the delay slot. */
4494 int step_through_delay
4495 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4497 if (debug_infrun
&& step_through_delay
)
4498 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4499 if (ecs
->event_thread
->control
.step_range_end
== 0
4500 && step_through_delay
)
4502 /* The user issued a continue when stopped at a breakpoint.
4503 Set up for another trap and get out of here. */
4504 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4508 else if (step_through_delay
)
4510 /* The user issued a step when stopped at a breakpoint.
4511 Maybe we should stop, maybe we should not - the delay
4512 slot *might* correspond to a line of source. In any
4513 case, don't decide that here, just set
4514 ecs->stepping_over_breakpoint, making sure we
4515 single-step again before breakpoints are re-inserted. */
4516 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4520 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4521 handles this event. */
4522 ecs
->event_thread
->control
.stop_bpstat
4523 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4524 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4526 /* Following in case break condition called a
4528 stop_print_frame
= 1;
4530 /* This is where we handle "moribund" watchpoints. Unlike
4531 software breakpoints traps, hardware watchpoint traps are
4532 always distinguishable from random traps. If no high-level
4533 watchpoint is associated with the reported stop data address
4534 anymore, then the bpstat does not explain the signal ---
4535 simply make sure to ignore it if `stopped_by_watchpoint' is
4539 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4540 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4542 && stopped_by_watchpoint
)
4543 fprintf_unfiltered (gdb_stdlog
,
4544 "infrun: no user watchpoint explains "
4545 "watchpoint SIGTRAP, ignoring\n");
4547 /* NOTE: cagney/2003-03-29: These checks for a random signal
4548 at one stage in the past included checks for an inferior
4549 function call's call dummy's return breakpoint. The original
4550 comment, that went with the test, read:
4552 ``End of a stack dummy. Some systems (e.g. Sony news) give
4553 another signal besides SIGTRAP, so check here as well as
4556 If someone ever tries to get call dummys on a
4557 non-executable stack to work (where the target would stop
4558 with something like a SIGSEGV), then those tests might need
4559 to be re-instated. Given, however, that the tests were only
4560 enabled when momentary breakpoints were not being used, I
4561 suspect that it won't be the case.
4563 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4564 be necessary for call dummies on a non-executable stack on
4567 /* See if the breakpoints module can explain the signal. */
4569 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4570 ecs
->event_thread
->suspend
.stop_signal
);
4572 /* Maybe this was a trap for a software breakpoint that has since
4574 if (random_signal
&& target_stopped_by_sw_breakpoint ())
4576 if (program_breakpoint_here_p (gdbarch
, stop_pc
))
4578 struct regcache
*regcache
;
4581 /* Re-adjust PC to what the program would see if GDB was not
4583 regcache
= get_thread_regcache (ecs
->event_thread
->ptid
);
4584 decr_pc
= gdbarch_decr_pc_after_break (gdbarch
);
4587 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
4589 if (record_full_is_used ())
4590 record_full_gdb_operation_disable_set ();
4592 regcache_write_pc (regcache
, stop_pc
+ decr_pc
);
4594 do_cleanups (old_cleanups
);
4599 /* A delayed software breakpoint event. Ignore the trap. */
4601 fprintf_unfiltered (gdb_stdlog
,
4602 "infrun: delayed software breakpoint "
4603 "trap, ignoring\n");
4608 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
4609 has since been removed. */
4610 if (random_signal
&& target_stopped_by_hw_breakpoint ())
4612 /* A delayed hardware breakpoint event. Ignore the trap. */
4614 fprintf_unfiltered (gdb_stdlog
,
4615 "infrun: delayed hardware breakpoint/watchpoint "
4616 "trap, ignoring\n");
4620 /* If not, perhaps stepping/nexting can. */
4622 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4623 && currently_stepping (ecs
->event_thread
));
4625 /* Perhaps the thread hit a single-step breakpoint of _another_
4626 thread. Single-step breakpoints are transparent to the
4627 breakpoints module. */
4629 random_signal
= !ecs
->hit_singlestep_breakpoint
;
4631 /* No? Perhaps we got a moribund watchpoint. */
4633 random_signal
= !stopped_by_watchpoint
;
4635 /* For the program's own signals, act according to
4636 the signal handling tables. */
4640 /* Signal not for debugging purposes. */
4641 struct inferior
*inf
= find_inferior_ptid (ecs
->ptid
);
4642 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
4645 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
4646 gdb_signal_to_symbol_string (stop_signal
));
4648 stopped_by_random_signal
= 1;
4650 /* Always stop on signals if we're either just gaining control
4651 of the program, or the user explicitly requested this thread
4652 to remain stopped. */
4653 if (stop_soon
!= NO_STOP_QUIETLY
4654 || ecs
->event_thread
->stop_requested
4656 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4662 /* Notify observers the signal has "handle print" set. Note we
4663 returned early above if stopping; normal_stop handles the
4664 printing in that case. */
4665 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4667 /* The signal table tells us to print about this signal. */
4668 target_terminal_ours_for_output ();
4669 observer_notify_signal_received (ecs
->event_thread
->suspend
.stop_signal
);
4670 target_terminal_inferior ();
4673 /* Clear the signal if it should not be passed. */
4674 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4675 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4677 if (ecs
->event_thread
->prev_pc
== stop_pc
4678 && ecs
->event_thread
->control
.trap_expected
4679 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4681 /* We were just starting a new sequence, attempting to
4682 single-step off of a breakpoint and expecting a SIGTRAP.
4683 Instead this signal arrives. This signal will take us out
4684 of the stepping range so GDB needs to remember to, when
4685 the signal handler returns, resume stepping off that
4687 /* To simplify things, "continue" is forced to use the same
4688 code paths as single-step - set a breakpoint at the
4689 signal return address and then, once hit, step off that
4692 fprintf_unfiltered (gdb_stdlog
,
4693 "infrun: signal arrived while stepping over "
4696 insert_hp_step_resume_breakpoint_at_frame (frame
);
4697 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4698 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4699 ecs
->event_thread
->control
.trap_expected
= 0;
4701 /* If we were nexting/stepping some other thread, switch to
4702 it, so that we don't continue it, losing control. */
4703 if (!switch_back_to_stepped_thread (ecs
))
4708 if (ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4709 && (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4710 || ecs
->event_thread
->control
.step_range_end
== 1)
4711 && frame_id_eq (get_stack_frame_id (frame
),
4712 ecs
->event_thread
->control
.step_stack_frame_id
)
4713 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4715 /* The inferior is about to take a signal that will take it
4716 out of the single step range. Set a breakpoint at the
4717 current PC (which is presumably where the signal handler
4718 will eventually return) and then allow the inferior to
4721 Note that this is only needed for a signal delivered
4722 while in the single-step range. Nested signals aren't a
4723 problem as they eventually all return. */
4725 fprintf_unfiltered (gdb_stdlog
,
4726 "infrun: signal may take us out of "
4727 "single-step range\n");
4729 insert_hp_step_resume_breakpoint_at_frame (frame
);
4730 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4731 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4732 ecs
->event_thread
->control
.trap_expected
= 0;
4737 /* Note: step_resume_breakpoint may be non-NULL. This occures
4738 when either there's a nested signal, or when there's a
4739 pending signal enabled just as the signal handler returns
4740 (leaving the inferior at the step-resume-breakpoint without
4741 actually executing it). Either way continue until the
4742 breakpoint is really hit. */
4744 if (!switch_back_to_stepped_thread (ecs
))
4747 fprintf_unfiltered (gdb_stdlog
,
4748 "infrun: random signal, keep going\n");
4755 process_event_stop_test (ecs
);
4758 /* Come here when we've got some debug event / signal we can explain
4759 (IOW, not a random signal), and test whether it should cause a
4760 stop, or whether we should resume the inferior (transparently).
4761 E.g., could be a breakpoint whose condition evaluates false; we
4762 could be still stepping within the line; etc. */
4765 process_event_stop_test (struct execution_control_state
*ecs
)
4767 struct symtab_and_line stop_pc_sal
;
4768 struct frame_info
*frame
;
4769 struct gdbarch
*gdbarch
;
4770 CORE_ADDR jmp_buf_pc
;
4771 struct bpstat_what what
;
4773 /* Handle cases caused by hitting a breakpoint. */
4775 frame
= get_current_frame ();
4776 gdbarch
= get_frame_arch (frame
);
4778 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4780 if (what
.call_dummy
)
4782 stop_stack_dummy
= what
.call_dummy
;
4785 /* If we hit an internal event that triggers symbol changes, the
4786 current frame will be invalidated within bpstat_what (e.g., if we
4787 hit an internal solib event). Re-fetch it. */
4788 frame
= get_current_frame ();
4789 gdbarch
= get_frame_arch (frame
);
4791 switch (what
.main_action
)
4793 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4794 /* If we hit the breakpoint at longjmp while stepping, we
4795 install a momentary breakpoint at the target of the
4799 fprintf_unfiltered (gdb_stdlog
,
4800 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4802 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4804 if (what
.is_longjmp
)
4806 struct value
*arg_value
;
4808 /* If we set the longjmp breakpoint via a SystemTap probe,
4809 then use it to extract the arguments. The destination PC
4810 is the third argument to the probe. */
4811 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4814 jmp_buf_pc
= value_as_address (arg_value
);
4815 jmp_buf_pc
= gdbarch_addr_bits_remove (gdbarch
, jmp_buf_pc
);
4817 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4818 || !gdbarch_get_longjmp_target (gdbarch
,
4819 frame
, &jmp_buf_pc
))
4822 fprintf_unfiltered (gdb_stdlog
,
4823 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4824 "(!gdbarch_get_longjmp_target)\n");
4829 /* Insert a breakpoint at resume address. */
4830 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4833 check_exception_resume (ecs
, frame
);
4837 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4839 struct frame_info
*init_frame
;
4841 /* There are several cases to consider.
4843 1. The initiating frame no longer exists. In this case we
4844 must stop, because the exception or longjmp has gone too
4847 2. The initiating frame exists, and is the same as the
4848 current frame. We stop, because the exception or longjmp
4851 3. The initiating frame exists and is different from the
4852 current frame. This means the exception or longjmp has
4853 been caught beneath the initiating frame, so keep going.
4855 4. longjmp breakpoint has been placed just to protect
4856 against stale dummy frames and user is not interested in
4857 stopping around longjmps. */
4860 fprintf_unfiltered (gdb_stdlog
,
4861 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4863 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4865 delete_exception_resume_breakpoint (ecs
->event_thread
);
4867 if (what
.is_longjmp
)
4869 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
4871 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4879 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4883 struct frame_id current_id
4884 = get_frame_id (get_current_frame ());
4885 if (frame_id_eq (current_id
,
4886 ecs
->event_thread
->initiating_frame
))
4888 /* Case 2. Fall through. */
4898 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4900 delete_step_resume_breakpoint (ecs
->event_thread
);
4902 end_stepping_range (ecs
);
4906 case BPSTAT_WHAT_SINGLE
:
4908 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4909 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4910 /* Still need to check other stuff, at least the case where we
4911 are stepping and step out of the right range. */
4914 case BPSTAT_WHAT_STEP_RESUME
:
4916 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4918 delete_step_resume_breakpoint (ecs
->event_thread
);
4919 if (ecs
->event_thread
->control
.proceed_to_finish
4920 && execution_direction
== EXEC_REVERSE
)
4922 struct thread_info
*tp
= ecs
->event_thread
;
4924 /* We are finishing a function in reverse, and just hit the
4925 step-resume breakpoint at the start address of the
4926 function, and we're almost there -- just need to back up
4927 by one more single-step, which should take us back to the
4929 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4933 fill_in_stop_func (gdbarch
, ecs
);
4934 if (stop_pc
== ecs
->stop_func_start
4935 && execution_direction
== EXEC_REVERSE
)
4937 /* We are stepping over a function call in reverse, and just
4938 hit the step-resume breakpoint at the start address of
4939 the function. Go back to single-stepping, which should
4940 take us back to the function call. */
4941 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4947 case BPSTAT_WHAT_STOP_NOISY
:
4949 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4950 stop_print_frame
= 1;
4952 /* Assume the thread stopped for a breapoint. We'll still check
4953 whether a/the breakpoint is there when the thread is next
4955 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4960 case BPSTAT_WHAT_STOP_SILENT
:
4962 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4963 stop_print_frame
= 0;
4965 /* Assume the thread stopped for a breapoint. We'll still check
4966 whether a/the breakpoint is there when the thread is next
4968 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4972 case BPSTAT_WHAT_HP_STEP_RESUME
:
4974 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4976 delete_step_resume_breakpoint (ecs
->event_thread
);
4977 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4979 /* Back when the step-resume breakpoint was inserted, we
4980 were trying to single-step off a breakpoint. Go back to
4982 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4983 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4989 case BPSTAT_WHAT_KEEP_CHECKING
:
4993 /* If we stepped a permanent breakpoint and we had a high priority
4994 step-resume breakpoint for the address we stepped, but we didn't
4995 hit it, then we must have stepped into the signal handler. The
4996 step-resume was only necessary to catch the case of _not_
4997 stepping into the handler, so delete it, and fall through to
4998 checking whether the step finished. */
4999 if (ecs
->event_thread
->stepped_breakpoint
)
5001 struct breakpoint
*sr_bp
5002 = ecs
->event_thread
->control
.step_resume_breakpoint
;
5005 && sr_bp
->loc
->permanent
5006 && sr_bp
->type
== bp_hp_step_resume
5007 && sr_bp
->loc
->address
== ecs
->event_thread
->prev_pc
)
5010 fprintf_unfiltered (gdb_stdlog
,
5011 "infrun: stepped permanent breakpoint, stopped in "
5013 delete_step_resume_breakpoint (ecs
->event_thread
);
5014 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
5018 /* We come here if we hit a breakpoint but should not stop for it.
5019 Possibly we also were stepping and should stop for that. So fall
5020 through and test for stepping. But, if not stepping, do not
5023 /* In all-stop mode, if we're currently stepping but have stopped in
5024 some other thread, we need to switch back to the stepped thread. */
5025 if (switch_back_to_stepped_thread (ecs
))
5028 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
5031 fprintf_unfiltered (gdb_stdlog
,
5032 "infrun: step-resume breakpoint is inserted\n");
5034 /* Having a step-resume breakpoint overrides anything
5035 else having to do with stepping commands until
5036 that breakpoint is reached. */
5041 if (ecs
->event_thread
->control
.step_range_end
== 0)
5044 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
5045 /* Likewise if we aren't even stepping. */
5050 /* Re-fetch current thread's frame in case the code above caused
5051 the frame cache to be re-initialized, making our FRAME variable
5052 a dangling pointer. */
5053 frame
= get_current_frame ();
5054 gdbarch
= get_frame_arch (frame
);
5055 fill_in_stop_func (gdbarch
, ecs
);
5057 /* If stepping through a line, keep going if still within it.
5059 Note that step_range_end is the address of the first instruction
5060 beyond the step range, and NOT the address of the last instruction
5063 Note also that during reverse execution, we may be stepping
5064 through a function epilogue and therefore must detect when
5065 the current-frame changes in the middle of a line. */
5067 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
5068 && (execution_direction
!= EXEC_REVERSE
5069 || frame_id_eq (get_frame_id (frame
),
5070 ecs
->event_thread
->control
.step_frame_id
)))
5074 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
5075 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
5076 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
5078 /* Tentatively re-enable range stepping; `resume' disables it if
5079 necessary (e.g., if we're stepping over a breakpoint or we
5080 have software watchpoints). */
5081 ecs
->event_thread
->control
.may_range_step
= 1;
5083 /* When stepping backward, stop at beginning of line range
5084 (unless it's the function entry point, in which case
5085 keep going back to the call point). */
5086 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
5087 && stop_pc
!= ecs
->stop_func_start
5088 && execution_direction
== EXEC_REVERSE
)
5089 end_stepping_range (ecs
);
5096 /* We stepped out of the stepping range. */
5098 /* If we are stepping at the source level and entered the runtime
5099 loader dynamic symbol resolution code...
5101 EXEC_FORWARD: we keep on single stepping until we exit the run
5102 time loader code and reach the callee's address.
5104 EXEC_REVERSE: we've already executed the callee (backward), and
5105 the runtime loader code is handled just like any other
5106 undebuggable function call. Now we need only keep stepping
5107 backward through the trampoline code, and that's handled further
5108 down, so there is nothing for us to do here. */
5110 if (execution_direction
!= EXEC_REVERSE
5111 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5112 && in_solib_dynsym_resolve_code (stop_pc
))
5114 CORE_ADDR pc_after_resolver
=
5115 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
5118 fprintf_unfiltered (gdb_stdlog
,
5119 "infrun: stepped into dynsym resolve code\n");
5121 if (pc_after_resolver
)
5123 /* Set up a step-resume breakpoint at the address
5124 indicated by SKIP_SOLIB_RESOLVER. */
5125 struct symtab_and_line sr_sal
;
5128 sr_sal
.pc
= pc_after_resolver
;
5129 sr_sal
.pspace
= get_frame_program_space (frame
);
5131 insert_step_resume_breakpoint_at_sal (gdbarch
,
5132 sr_sal
, null_frame_id
);
5139 if (ecs
->event_thread
->control
.step_range_end
!= 1
5140 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5141 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5142 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
5145 fprintf_unfiltered (gdb_stdlog
,
5146 "infrun: stepped into signal trampoline\n");
5147 /* The inferior, while doing a "step" or "next", has ended up in
5148 a signal trampoline (either by a signal being delivered or by
5149 the signal handler returning). Just single-step until the
5150 inferior leaves the trampoline (either by calling the handler
5156 /* If we're in the return path from a shared library trampoline,
5157 we want to proceed through the trampoline when stepping. */
5158 /* macro/2012-04-25: This needs to come before the subroutine
5159 call check below as on some targets return trampolines look
5160 like subroutine calls (MIPS16 return thunks). */
5161 if (gdbarch_in_solib_return_trampoline (gdbarch
,
5162 stop_pc
, ecs
->stop_func_name
)
5163 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5165 /* Determine where this trampoline returns. */
5166 CORE_ADDR real_stop_pc
;
5168 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
5171 fprintf_unfiltered (gdb_stdlog
,
5172 "infrun: stepped into solib return tramp\n");
5174 /* Only proceed through if we know where it's going. */
5177 /* And put the step-breakpoint there and go until there. */
5178 struct symtab_and_line sr_sal
;
5180 init_sal (&sr_sal
); /* initialize to zeroes */
5181 sr_sal
.pc
= real_stop_pc
;
5182 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5183 sr_sal
.pspace
= get_frame_program_space (frame
);
5185 /* Do not specify what the fp should be when we stop since
5186 on some machines the prologue is where the new fp value
5188 insert_step_resume_breakpoint_at_sal (gdbarch
,
5189 sr_sal
, null_frame_id
);
5191 /* Restart without fiddling with the step ranges or
5198 /* Check for subroutine calls. The check for the current frame
5199 equalling the step ID is not necessary - the check of the
5200 previous frame's ID is sufficient - but it is a common case and
5201 cheaper than checking the previous frame's ID.
5203 NOTE: frame_id_eq will never report two invalid frame IDs as
5204 being equal, so to get into this block, both the current and
5205 previous frame must have valid frame IDs. */
5206 /* The outer_frame_id check is a heuristic to detect stepping
5207 through startup code. If we step over an instruction which
5208 sets the stack pointer from an invalid value to a valid value,
5209 we may detect that as a subroutine call from the mythical
5210 "outermost" function. This could be fixed by marking
5211 outermost frames as !stack_p,code_p,special_p. Then the
5212 initial outermost frame, before sp was valid, would
5213 have code_addr == &_start. See the comment in frame_id_eq
5215 if (!frame_id_eq (get_stack_frame_id (frame
),
5216 ecs
->event_thread
->control
.step_stack_frame_id
)
5217 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
5218 ecs
->event_thread
->control
.step_stack_frame_id
)
5219 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
5221 || (ecs
->event_thread
->control
.step_start_function
5222 != find_pc_function (stop_pc
)))))
5224 CORE_ADDR real_stop_pc
;
5227 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
5229 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
5231 /* I presume that step_over_calls is only 0 when we're
5232 supposed to be stepping at the assembly language level
5233 ("stepi"). Just stop. */
5234 /* And this works the same backward as frontward. MVS */
5235 end_stepping_range (ecs
);
5239 /* Reverse stepping through solib trampolines. */
5241 if (execution_direction
== EXEC_REVERSE
5242 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
5243 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5244 || (ecs
->stop_func_start
== 0
5245 && in_solib_dynsym_resolve_code (stop_pc
))))
5247 /* Any solib trampoline code can be handled in reverse
5248 by simply continuing to single-step. We have already
5249 executed the solib function (backwards), and a few
5250 steps will take us back through the trampoline to the
5256 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5258 /* We're doing a "next".
5260 Normal (forward) execution: set a breakpoint at the
5261 callee's return address (the address at which the caller
5264 Reverse (backward) execution. set the step-resume
5265 breakpoint at the start of the function that we just
5266 stepped into (backwards), and continue to there. When we
5267 get there, we'll need to single-step back to the caller. */
5269 if (execution_direction
== EXEC_REVERSE
)
5271 /* If we're already at the start of the function, we've either
5272 just stepped backward into a single instruction function,
5273 or stepped back out of a signal handler to the first instruction
5274 of the function. Just keep going, which will single-step back
5276 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
5278 struct symtab_and_line sr_sal
;
5280 /* Normal function call return (static or dynamic). */
5282 sr_sal
.pc
= ecs
->stop_func_start
;
5283 sr_sal
.pspace
= get_frame_program_space (frame
);
5284 insert_step_resume_breakpoint_at_sal (gdbarch
,
5285 sr_sal
, null_frame_id
);
5289 insert_step_resume_breakpoint_at_caller (frame
);
5295 /* If we are in a function call trampoline (a stub between the
5296 calling routine and the real function), locate the real
5297 function. That's what tells us (a) whether we want to step
5298 into it at all, and (b) what prologue we want to run to the
5299 end of, if we do step into it. */
5300 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
5301 if (real_stop_pc
== 0)
5302 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
5303 if (real_stop_pc
!= 0)
5304 ecs
->stop_func_start
= real_stop_pc
;
5306 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
5308 struct symtab_and_line sr_sal
;
5311 sr_sal
.pc
= ecs
->stop_func_start
;
5312 sr_sal
.pspace
= get_frame_program_space (frame
);
5314 insert_step_resume_breakpoint_at_sal (gdbarch
,
5315 sr_sal
, null_frame_id
);
5320 /* If we have line number information for the function we are
5321 thinking of stepping into and the function isn't on the skip
5324 If there are several symtabs at that PC (e.g. with include
5325 files), just want to know whether *any* of them have line
5326 numbers. find_pc_line handles this. */
5328 struct symtab_and_line tmp_sal
;
5330 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5331 if (tmp_sal
.line
!= 0
5332 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
5335 if (execution_direction
== EXEC_REVERSE
)
5336 handle_step_into_function_backward (gdbarch
, ecs
);
5338 handle_step_into_function (gdbarch
, ecs
);
5343 /* If we have no line number and the step-stop-if-no-debug is
5344 set, we stop the step so that the user has a chance to switch
5345 in assembly mode. */
5346 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5347 && step_stop_if_no_debug
)
5349 end_stepping_range (ecs
);
5353 if (execution_direction
== EXEC_REVERSE
)
5355 /* If we're already at the start of the function, we've either just
5356 stepped backward into a single instruction function without line
5357 number info, or stepped back out of a signal handler to the first
5358 instruction of the function without line number info. Just keep
5359 going, which will single-step back to the caller. */
5360 if (ecs
->stop_func_start
!= stop_pc
)
5362 /* Set a breakpoint at callee's start address.
5363 From there we can step once and be back in the caller. */
5364 struct symtab_and_line sr_sal
;
5367 sr_sal
.pc
= ecs
->stop_func_start
;
5368 sr_sal
.pspace
= get_frame_program_space (frame
);
5369 insert_step_resume_breakpoint_at_sal (gdbarch
,
5370 sr_sal
, null_frame_id
);
5374 /* Set a breakpoint at callee's return address (the address
5375 at which the caller will resume). */
5376 insert_step_resume_breakpoint_at_caller (frame
);
5382 /* Reverse stepping through solib trampolines. */
5384 if (execution_direction
== EXEC_REVERSE
5385 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5387 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5388 || (ecs
->stop_func_start
== 0
5389 && in_solib_dynsym_resolve_code (stop_pc
)))
5391 /* Any solib trampoline code can be handled in reverse
5392 by simply continuing to single-step. We have already
5393 executed the solib function (backwards), and a few
5394 steps will take us back through the trampoline to the
5399 else if (in_solib_dynsym_resolve_code (stop_pc
))
5401 /* Stepped backward into the solib dynsym resolver.
5402 Set a breakpoint at its start and continue, then
5403 one more step will take us out. */
5404 struct symtab_and_line sr_sal
;
5407 sr_sal
.pc
= ecs
->stop_func_start
;
5408 sr_sal
.pspace
= get_frame_program_space (frame
);
5409 insert_step_resume_breakpoint_at_sal (gdbarch
,
5410 sr_sal
, null_frame_id
);
5416 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5418 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5419 the trampoline processing logic, however, there are some trampolines
5420 that have no names, so we should do trampoline handling first. */
5421 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5422 && ecs
->stop_func_name
== NULL
5423 && stop_pc_sal
.line
== 0)
5426 fprintf_unfiltered (gdb_stdlog
,
5427 "infrun: stepped into undebuggable function\n");
5429 /* The inferior just stepped into, or returned to, an
5430 undebuggable function (where there is no debugging information
5431 and no line number corresponding to the address where the
5432 inferior stopped). Since we want to skip this kind of code,
5433 we keep going until the inferior returns from this
5434 function - unless the user has asked us not to (via
5435 set step-mode) or we no longer know how to get back
5436 to the call site. */
5437 if (step_stop_if_no_debug
5438 || !frame_id_p (frame_unwind_caller_id (frame
)))
5440 /* If we have no line number and the step-stop-if-no-debug
5441 is set, we stop the step so that the user has a chance to
5442 switch in assembly mode. */
5443 end_stepping_range (ecs
);
5448 /* Set a breakpoint at callee's return address (the address
5449 at which the caller will resume). */
5450 insert_step_resume_breakpoint_at_caller (frame
);
5456 if (ecs
->event_thread
->control
.step_range_end
== 1)
5458 /* It is stepi or nexti. We always want to stop stepping after
5461 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5462 end_stepping_range (ecs
);
5466 if (stop_pc_sal
.line
== 0)
5468 /* We have no line number information. That means to stop
5469 stepping (does this always happen right after one instruction,
5470 when we do "s" in a function with no line numbers,
5471 or can this happen as a result of a return or longjmp?). */
5473 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5474 end_stepping_range (ecs
);
5478 /* Look for "calls" to inlined functions, part one. If the inline
5479 frame machinery detected some skipped call sites, we have entered
5480 a new inline function. */
5482 if (frame_id_eq (get_frame_id (get_current_frame ()),
5483 ecs
->event_thread
->control
.step_frame_id
)
5484 && inline_skipped_frames (ecs
->ptid
))
5486 struct symtab_and_line call_sal
;
5489 fprintf_unfiltered (gdb_stdlog
,
5490 "infrun: stepped into inlined function\n");
5492 find_frame_sal (get_current_frame (), &call_sal
);
5494 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5496 /* For "step", we're going to stop. But if the call site
5497 for this inlined function is on the same source line as
5498 we were previously stepping, go down into the function
5499 first. Otherwise stop at the call site. */
5501 if (call_sal
.line
== ecs
->event_thread
->current_line
5502 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5503 step_into_inline_frame (ecs
->ptid
);
5505 end_stepping_range (ecs
);
5510 /* For "next", we should stop at the call site if it is on a
5511 different source line. Otherwise continue through the
5512 inlined function. */
5513 if (call_sal
.line
== ecs
->event_thread
->current_line
5514 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5517 end_stepping_range (ecs
);
5522 /* Look for "calls" to inlined functions, part two. If we are still
5523 in the same real function we were stepping through, but we have
5524 to go further up to find the exact frame ID, we are stepping
5525 through a more inlined call beyond its call site. */
5527 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5528 && !frame_id_eq (get_frame_id (get_current_frame ()),
5529 ecs
->event_thread
->control
.step_frame_id
)
5530 && stepped_in_from (get_current_frame (),
5531 ecs
->event_thread
->control
.step_frame_id
))
5534 fprintf_unfiltered (gdb_stdlog
,
5535 "infrun: stepping through inlined function\n");
5537 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5540 end_stepping_range (ecs
);
5544 if ((stop_pc
== stop_pc_sal
.pc
)
5545 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5546 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5548 /* We are at the start of a different line. So stop. Note that
5549 we don't stop if we step into the middle of a different line.
5550 That is said to make things like for (;;) statements work
5553 fprintf_unfiltered (gdb_stdlog
,
5554 "infrun: stepped to a different line\n");
5555 end_stepping_range (ecs
);
5559 /* We aren't done stepping.
5561 Optimize by setting the stepping range to the line.
5562 (We might not be in the original line, but if we entered a
5563 new line in mid-statement, we continue stepping. This makes
5564 things like for(;;) statements work better.) */
5566 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5567 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5568 ecs
->event_thread
->control
.may_range_step
= 1;
5569 set_step_info (frame
, stop_pc_sal
);
5572 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5576 /* In all-stop mode, if we're currently stepping but have stopped in
5577 some other thread, we may need to switch back to the stepped
5578 thread. Returns true we set the inferior running, false if we left
5579 it stopped (and the event needs further processing). */
5582 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
5586 struct thread_info
*tp
;
5587 struct thread_info
*stepping_thread
;
5588 struct thread_info
*step_over
;
5590 /* If any thread is blocked on some internal breakpoint, and we
5591 simply need to step over that breakpoint to get it going
5592 again, do that first. */
5594 /* However, if we see an event for the stepping thread, then we
5595 know all other threads have been moved past their breakpoints
5596 already. Let the caller check whether the step is finished,
5597 etc., before deciding to move it past a breakpoint. */
5598 if (ecs
->event_thread
->control
.step_range_end
!= 0)
5601 /* Check if the current thread is blocked on an incomplete
5602 step-over, interrupted by a random signal. */
5603 if (ecs
->event_thread
->control
.trap_expected
5604 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5608 fprintf_unfiltered (gdb_stdlog
,
5609 "infrun: need to finish step-over of [%s]\n",
5610 target_pid_to_str (ecs
->event_thread
->ptid
));
5616 /* Check if the current thread is blocked by a single-step
5617 breakpoint of another thread. */
5618 if (ecs
->hit_singlestep_breakpoint
)
5622 fprintf_unfiltered (gdb_stdlog
,
5623 "infrun: need to step [%s] over single-step "
5625 target_pid_to_str (ecs
->ptid
));
5631 /* Otherwise, we no longer expect a trap in the current thread.
5632 Clear the trap_expected flag before switching back -- this is
5633 what keep_going does as well, if we call it. */
5634 ecs
->event_thread
->control
.trap_expected
= 0;
5636 /* Likewise, clear the signal if it should not be passed. */
5637 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5638 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5640 /* If scheduler locking applies even if not stepping, there's no
5641 need to walk over threads. Above we've checked whether the
5642 current thread is stepping. If some other thread not the
5643 event thread is stepping, then it must be that scheduler
5644 locking is not in effect. */
5645 if (schedlock_applies (ecs
->event_thread
))
5648 /* Look for the stepping/nexting thread, and check if any other
5649 thread other than the stepping thread needs to start a
5650 step-over. Do all step-overs before actually proceeding with
5652 stepping_thread
= NULL
;
5654 ALL_NON_EXITED_THREADS (tp
)
5656 /* Ignore threads of processes we're not resuming. */
5658 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
5661 /* When stepping over a breakpoint, we lock all threads
5662 except the one that needs to move past the breakpoint.
5663 If a non-event thread has this set, the "incomplete
5664 step-over" check above should have caught it earlier. */
5665 gdb_assert (!tp
->control
.trap_expected
);
5667 /* Did we find the stepping thread? */
5668 if (tp
->control
.step_range_end
)
5670 /* Yep. There should only one though. */
5671 gdb_assert (stepping_thread
== NULL
);
5673 /* The event thread is handled at the top, before we
5675 gdb_assert (tp
!= ecs
->event_thread
);
5677 /* If some thread other than the event thread is
5678 stepping, then scheduler locking can't be in effect,
5679 otherwise we wouldn't have resumed the current event
5680 thread in the first place. */
5681 gdb_assert (!schedlock_applies (tp
));
5683 stepping_thread
= tp
;
5685 else if (thread_still_needs_step_over (tp
))
5689 /* At the top we've returned early if the event thread
5690 is stepping. If some other thread not the event
5691 thread is stepping, then scheduler locking can't be
5692 in effect, and we can resume this thread. No need to
5693 keep looking for the stepping thread then. */
5698 if (step_over
!= NULL
)
5703 fprintf_unfiltered (gdb_stdlog
,
5704 "infrun: need to step-over [%s]\n",
5705 target_pid_to_str (tp
->ptid
));
5708 /* Only the stepping thread should have this set. */
5709 gdb_assert (tp
->control
.step_range_end
== 0);
5711 ecs
->ptid
= tp
->ptid
;
5712 ecs
->event_thread
= tp
;
5713 switch_to_thread (ecs
->ptid
);
5718 if (stepping_thread
!= NULL
)
5720 struct frame_info
*frame
;
5721 struct gdbarch
*gdbarch
;
5723 tp
= stepping_thread
;
5725 /* If the stepping thread exited, then don't try to switch
5726 back and resume it, which could fail in several different
5727 ways depending on the target. Instead, just keep going.
5729 We can find a stepping dead thread in the thread list in
5732 - The target supports thread exit events, and when the
5733 target tries to delete the thread from the thread list,
5734 inferior_ptid pointed at the exiting thread. In such
5735 case, calling delete_thread does not really remove the
5736 thread from the list; instead, the thread is left listed,
5737 with 'exited' state.
5739 - The target's debug interface does not support thread
5740 exit events, and so we have no idea whatsoever if the
5741 previously stepping thread is still alive. For that
5742 reason, we need to synchronously query the target
5744 if (is_exited (tp
->ptid
)
5745 || !target_thread_alive (tp
->ptid
))
5748 fprintf_unfiltered (gdb_stdlog
,
5749 "infrun: not switching back to "
5750 "stepped thread, it has vanished\n");
5752 delete_thread (tp
->ptid
);
5758 fprintf_unfiltered (gdb_stdlog
,
5759 "infrun: switching back to stepped thread\n");
5761 ecs
->event_thread
= tp
;
5762 ecs
->ptid
= tp
->ptid
;
5763 context_switch (ecs
->ptid
);
5765 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5766 frame
= get_current_frame ();
5767 gdbarch
= get_frame_arch (frame
);
5769 /* If the PC of the thread we were trying to single-step has
5770 changed, then that thread has trapped or been signaled,
5771 but the event has not been reported to GDB yet. Re-poll
5772 the target looking for this particular thread's event
5773 (i.e. temporarily enable schedlock) by:
5775 - setting a break at the current PC
5776 - resuming that particular thread, only (by setting
5779 This prevents us continuously moving the single-step
5780 breakpoint forward, one instruction at a time,
5783 if (stop_pc
!= tp
->prev_pc
)
5788 fprintf_unfiltered (gdb_stdlog
,
5789 "infrun: expected thread advanced also\n");
5791 /* Clear the info of the previous step-over, as it's no
5792 longer valid. It's what keep_going would do too, if
5793 we called it. Must do this before trying to insert
5794 the sss breakpoint, otherwise if we were previously
5795 trying to step over this exact address in another
5796 thread, the breakpoint ends up not installed. */
5797 clear_step_over_info ();
5799 insert_single_step_breakpoint (get_frame_arch (frame
),
5800 get_frame_address_space (frame
),
5803 resume_ptid
= user_visible_resume_ptid (tp
->control
.stepping_command
);
5804 do_target_resume (resume_ptid
,
5805 currently_stepping (tp
), GDB_SIGNAL_0
);
5806 prepare_to_wait (ecs
);
5811 fprintf_unfiltered (gdb_stdlog
,
5812 "infrun: expected thread still "
5813 "hasn't advanced\n");
5823 /* Is thread TP in the middle of single-stepping? */
5826 currently_stepping (struct thread_info
*tp
)
5828 return ((tp
->control
.step_range_end
5829 && tp
->control
.step_resume_breakpoint
== NULL
)
5830 || tp
->control
.trap_expected
5831 || tp
->stepped_breakpoint
5832 || bpstat_should_step ());
5835 /* Inferior has stepped into a subroutine call with source code that
5836 we should not step over. Do step to the first line of code in
5840 handle_step_into_function (struct gdbarch
*gdbarch
,
5841 struct execution_control_state
*ecs
)
5843 struct compunit_symtab
*cust
;
5844 struct symtab_and_line stop_func_sal
, sr_sal
;
5846 fill_in_stop_func (gdbarch
, ecs
);
5848 cust
= find_pc_compunit_symtab (stop_pc
);
5849 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
5850 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5851 ecs
->stop_func_start
);
5853 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5854 /* Use the step_resume_break to step until the end of the prologue,
5855 even if that involves jumps (as it seems to on the vax under
5857 /* If the prologue ends in the middle of a source line, continue to
5858 the end of that source line (if it is still within the function).
5859 Otherwise, just go to end of prologue. */
5860 if (stop_func_sal
.end
5861 && stop_func_sal
.pc
!= ecs
->stop_func_start
5862 && stop_func_sal
.end
< ecs
->stop_func_end
)
5863 ecs
->stop_func_start
= stop_func_sal
.end
;
5865 /* Architectures which require breakpoint adjustment might not be able
5866 to place a breakpoint at the computed address. If so, the test
5867 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5868 ecs->stop_func_start to an address at which a breakpoint may be
5869 legitimately placed.
5871 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5872 made, GDB will enter an infinite loop when stepping through
5873 optimized code consisting of VLIW instructions which contain
5874 subinstructions corresponding to different source lines. On
5875 FR-V, it's not permitted to place a breakpoint on any but the
5876 first subinstruction of a VLIW instruction. When a breakpoint is
5877 set, GDB will adjust the breakpoint address to the beginning of
5878 the VLIW instruction. Thus, we need to make the corresponding
5879 adjustment here when computing the stop address. */
5881 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5883 ecs
->stop_func_start
5884 = gdbarch_adjust_breakpoint_address (gdbarch
,
5885 ecs
->stop_func_start
);
5888 if (ecs
->stop_func_start
== stop_pc
)
5890 /* We are already there: stop now. */
5891 end_stepping_range (ecs
);
5896 /* Put the step-breakpoint there and go until there. */
5897 init_sal (&sr_sal
); /* initialize to zeroes */
5898 sr_sal
.pc
= ecs
->stop_func_start
;
5899 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5900 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5902 /* Do not specify what the fp should be when we stop since on
5903 some machines the prologue is where the new fp value is
5905 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5907 /* And make sure stepping stops right away then. */
5908 ecs
->event_thread
->control
.step_range_end
5909 = ecs
->event_thread
->control
.step_range_start
;
5914 /* Inferior has stepped backward into a subroutine call with source
5915 code that we should not step over. Do step to the beginning of the
5916 last line of code in it. */
5919 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5920 struct execution_control_state
*ecs
)
5922 struct compunit_symtab
*cust
;
5923 struct symtab_and_line stop_func_sal
;
5925 fill_in_stop_func (gdbarch
, ecs
);
5927 cust
= find_pc_compunit_symtab (stop_pc
);
5928 if (cust
!= NULL
&& compunit_language (cust
) != language_asm
)
5929 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5930 ecs
->stop_func_start
);
5932 stop_func_sal
= find_pc_line (stop_pc
, 0);
5934 /* OK, we're just going to keep stepping here. */
5935 if (stop_func_sal
.pc
== stop_pc
)
5937 /* We're there already. Just stop stepping now. */
5938 end_stepping_range (ecs
);
5942 /* Else just reset the step range and keep going.
5943 No step-resume breakpoint, they don't work for
5944 epilogues, which can have multiple entry paths. */
5945 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5946 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5952 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5953 This is used to both functions and to skip over code. */
5956 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5957 struct symtab_and_line sr_sal
,
5958 struct frame_id sr_id
,
5959 enum bptype sr_type
)
5961 /* There should never be more than one step-resume or longjmp-resume
5962 breakpoint per thread, so we should never be setting a new
5963 step_resume_breakpoint when one is already active. */
5964 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5965 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5968 fprintf_unfiltered (gdb_stdlog
,
5969 "infrun: inserting step-resume breakpoint at %s\n",
5970 paddress (gdbarch
, sr_sal
.pc
));
5972 inferior_thread ()->control
.step_resume_breakpoint
5973 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5977 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5978 struct symtab_and_line sr_sal
,
5979 struct frame_id sr_id
)
5981 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5986 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5987 This is used to skip a potential signal handler.
5989 This is called with the interrupted function's frame. The signal
5990 handler, when it returns, will resume the interrupted function at
5994 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5996 struct symtab_and_line sr_sal
;
5997 struct gdbarch
*gdbarch
;
5999 gdb_assert (return_frame
!= NULL
);
6000 init_sal (&sr_sal
); /* initialize to zeros */
6002 gdbarch
= get_frame_arch (return_frame
);
6003 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
6004 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
6005 sr_sal
.pspace
= get_frame_program_space (return_frame
);
6007 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
6008 get_stack_frame_id (return_frame
),
6012 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
6013 is used to skip a function after stepping into it (for "next" or if
6014 the called function has no debugging information).
6016 The current function has almost always been reached by single
6017 stepping a call or return instruction. NEXT_FRAME belongs to the
6018 current function, and the breakpoint will be set at the caller's
6021 This is a separate function rather than reusing
6022 insert_hp_step_resume_breakpoint_at_frame in order to avoid
6023 get_prev_frame, which may stop prematurely (see the implementation
6024 of frame_unwind_caller_id for an example). */
6027 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
6029 struct symtab_and_line sr_sal
;
6030 struct gdbarch
*gdbarch
;
6032 /* We shouldn't have gotten here if we don't know where the call site
6034 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
6036 init_sal (&sr_sal
); /* initialize to zeros */
6038 gdbarch
= frame_unwind_caller_arch (next_frame
);
6039 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
6040 frame_unwind_caller_pc (next_frame
));
6041 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
6042 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
6044 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
6045 frame_unwind_caller_id (next_frame
));
6048 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
6049 new breakpoint at the target of a jmp_buf. The handling of
6050 longjmp-resume uses the same mechanisms used for handling
6051 "step-resume" breakpoints. */
6054 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
6056 /* There should never be more than one longjmp-resume breakpoint per
6057 thread, so we should never be setting a new
6058 longjmp_resume_breakpoint when one is already active. */
6059 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
6062 fprintf_unfiltered (gdb_stdlog
,
6063 "infrun: inserting longjmp-resume breakpoint at %s\n",
6064 paddress (gdbarch
, pc
));
6066 inferior_thread ()->control
.exception_resume_breakpoint
=
6067 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
6070 /* Insert an exception resume breakpoint. TP is the thread throwing
6071 the exception. The block B is the block of the unwinder debug hook
6072 function. FRAME is the frame corresponding to the call to this
6073 function. SYM is the symbol of the function argument holding the
6074 target PC of the exception. */
6077 insert_exception_resume_breakpoint (struct thread_info
*tp
,
6078 const struct block
*b
,
6079 struct frame_info
*frame
,
6084 struct symbol
*vsym
;
6085 struct value
*value
;
6087 struct breakpoint
*bp
;
6089 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
6090 value
= read_var_value (vsym
, frame
);
6091 /* If the value was optimized out, revert to the old behavior. */
6092 if (! value_optimized_out (value
))
6094 handler
= value_as_address (value
);
6097 fprintf_unfiltered (gdb_stdlog
,
6098 "infrun: exception resume at %lx\n",
6099 (unsigned long) handler
);
6101 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
6102 handler
, bp_exception_resume
);
6104 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
6107 bp
->thread
= tp
->num
;
6108 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
6111 CATCH (e
, RETURN_MASK_ERROR
)
6113 /* We want to ignore errors here. */
6118 /* A helper for check_exception_resume that sets an
6119 exception-breakpoint based on a SystemTap probe. */
6122 insert_exception_resume_from_probe (struct thread_info
*tp
,
6123 const struct bound_probe
*probe
,
6124 struct frame_info
*frame
)
6126 struct value
*arg_value
;
6128 struct breakpoint
*bp
;
6130 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
6134 handler
= value_as_address (arg_value
);
6137 fprintf_unfiltered (gdb_stdlog
,
6138 "infrun: exception resume at %s\n",
6139 paddress (get_objfile_arch (probe
->objfile
),
6142 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
6143 handler
, bp_exception_resume
);
6144 bp
->thread
= tp
->num
;
6145 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
6148 /* This is called when an exception has been intercepted. Check to
6149 see whether the exception's destination is of interest, and if so,
6150 set an exception resume breakpoint there. */
6153 check_exception_resume (struct execution_control_state
*ecs
,
6154 struct frame_info
*frame
)
6156 struct bound_probe probe
;
6157 struct symbol
*func
;
6159 /* First see if this exception unwinding breakpoint was set via a
6160 SystemTap probe point. If so, the probe has two arguments: the
6161 CFA and the HANDLER. We ignore the CFA, extract the handler, and
6162 set a breakpoint there. */
6163 probe
= find_probe_by_pc (get_frame_pc (frame
));
6166 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
6170 func
= get_frame_function (frame
);
6176 const struct block
*b
;
6177 struct block_iterator iter
;
6181 /* The exception breakpoint is a thread-specific breakpoint on
6182 the unwinder's debug hook, declared as:
6184 void _Unwind_DebugHook (void *cfa, void *handler);
6186 The CFA argument indicates the frame to which control is
6187 about to be transferred. HANDLER is the destination PC.
6189 We ignore the CFA and set a temporary breakpoint at HANDLER.
6190 This is not extremely efficient but it avoids issues in gdb
6191 with computing the DWARF CFA, and it also works even in weird
6192 cases such as throwing an exception from inside a signal
6195 b
= SYMBOL_BLOCK_VALUE (func
);
6196 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
6198 if (!SYMBOL_IS_ARGUMENT (sym
))
6205 insert_exception_resume_breakpoint (ecs
->event_thread
,
6211 CATCH (e
, RETURN_MASK_ERROR
)
6218 stop_waiting (struct execution_control_state
*ecs
)
6221 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_waiting\n");
6223 clear_step_over_info ();
6225 /* Let callers know we don't want to wait for the inferior anymore. */
6226 ecs
->wait_some_more
= 0;
6229 /* Called when we should continue running the inferior, because the
6230 current event doesn't cause a user visible stop. This does the
6231 resuming part; waiting for the next event is done elsewhere. */
6234 keep_going (struct execution_control_state
*ecs
)
6236 /* Make sure normal_stop is called if we get a QUIT handled before
6238 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
6240 /* Save the pc before execution, to compare with pc after stop. */
6241 ecs
->event_thread
->prev_pc
6242 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
6244 if (ecs
->event_thread
->control
.trap_expected
6245 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
6247 /* We haven't yet gotten our trap, and either: intercepted a
6248 non-signal event (e.g., a fork); or took a signal which we
6249 are supposed to pass through to the inferior. Simply
6251 discard_cleanups (old_cleanups
);
6252 resume (ecs
->event_thread
->suspend
.stop_signal
);
6256 struct regcache
*regcache
= get_current_regcache ();
6260 /* Either the trap was not expected, but we are continuing
6261 anyway (if we got a signal, the user asked it be passed to
6264 We got our expected trap, but decided we should resume from
6267 We're going to run this baby now!
6269 Note that insert_breakpoints won't try to re-insert
6270 already inserted breakpoints. Therefore, we don't
6271 care if breakpoints were already inserted, or not. */
6273 /* If we need to step over a breakpoint, and we're not using
6274 displaced stepping to do so, insert all breakpoints
6275 (watchpoints, etc.) but the one we're stepping over, step one
6276 instruction, and then re-insert the breakpoint when that step
6279 remove_bp
= (ecs
->hit_singlestep_breakpoint
6280 || thread_still_needs_step_over (ecs
->event_thread
));
6281 remove_wps
= (ecs
->event_thread
->stepping_over_watchpoint
6282 && !target_have_steppable_watchpoint
);
6284 /* We can't use displaced stepping if we need to step past a
6285 watchpoint. The instruction copied to the scratch pad would
6286 still trigger the watchpoint. */
6289 || !use_displaced_stepping (get_regcache_arch (regcache
))))
6291 set_step_over_info (get_regcache_aspace (regcache
),
6292 regcache_read_pc (regcache
), remove_wps
);
6294 else if (remove_wps
)
6295 set_step_over_info (NULL
, 0, remove_wps
);
6297 clear_step_over_info ();
6299 /* Stop stepping if inserting breakpoints fails. */
6302 insert_breakpoints ();
6304 CATCH (e
, RETURN_MASK_ERROR
)
6306 exception_print (gdb_stderr
, e
);
6308 discard_cleanups (old_cleanups
);
6313 ecs
->event_thread
->control
.trap_expected
= (remove_bp
|| remove_wps
);
6315 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
6316 explicitly specifies that such a signal should be delivered
6317 to the target program). Typically, that would occur when a
6318 user is debugging a target monitor on a simulator: the target
6319 monitor sets a breakpoint; the simulator encounters this
6320 breakpoint and halts the simulation handing control to GDB;
6321 GDB, noting that the stop address doesn't map to any known
6322 breakpoint, returns control back to the simulator; the
6323 simulator then delivers the hardware equivalent of a
6324 GDB_SIGNAL_TRAP to the program being debugged. */
6325 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6326 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
6327 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6329 discard_cleanups (old_cleanups
);
6330 resume (ecs
->event_thread
->suspend
.stop_signal
);
6333 prepare_to_wait (ecs
);
6336 /* This function normally comes after a resume, before
6337 handle_inferior_event exits. It takes care of any last bits of
6338 housekeeping, and sets the all-important wait_some_more flag. */
6341 prepare_to_wait (struct execution_control_state
*ecs
)
6344 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
6346 /* This is the old end of the while loop. Let everybody know we
6347 want to wait for the inferior some more and get called again
6349 ecs
->wait_some_more
= 1;
6352 /* We are done with the step range of a step/next/si/ni command.
6353 Called once for each n of a "step n" operation. */
6356 end_stepping_range (struct execution_control_state
*ecs
)
6358 ecs
->event_thread
->control
.stop_step
= 1;
6362 /* Several print_*_reason functions to print why the inferior has stopped.
6363 We always print something when the inferior exits, or receives a signal.
6364 The rest of the cases are dealt with later on in normal_stop and
6365 print_it_typical. Ideally there should be a call to one of these
6366 print_*_reason functions functions from handle_inferior_event each time
6367 stop_waiting is called.
6369 Note that we don't call these directly, instead we delegate that to
6370 the interpreters, through observers. Interpreters then call these
6371 with whatever uiout is right. */
6374 print_end_stepping_range_reason (struct ui_out
*uiout
)
6376 /* For CLI-like interpreters, print nothing. */
6378 if (ui_out_is_mi_like_p (uiout
))
6380 ui_out_field_string (uiout
, "reason",
6381 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
6386 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6388 annotate_signalled ();
6389 if (ui_out_is_mi_like_p (uiout
))
6391 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
6392 ui_out_text (uiout
, "\nProgram terminated with signal ");
6393 annotate_signal_name ();
6394 ui_out_field_string (uiout
, "signal-name",
6395 gdb_signal_to_name (siggnal
));
6396 annotate_signal_name_end ();
6397 ui_out_text (uiout
, ", ");
6398 annotate_signal_string ();
6399 ui_out_field_string (uiout
, "signal-meaning",
6400 gdb_signal_to_string (siggnal
));
6401 annotate_signal_string_end ();
6402 ui_out_text (uiout
, ".\n");
6403 ui_out_text (uiout
, "The program no longer exists.\n");
6407 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
6409 struct inferior
*inf
= current_inferior ();
6410 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
6412 annotate_exited (exitstatus
);
6415 if (ui_out_is_mi_like_p (uiout
))
6416 ui_out_field_string (uiout
, "reason",
6417 async_reason_lookup (EXEC_ASYNC_EXITED
));
6418 ui_out_text (uiout
, "[Inferior ");
6419 ui_out_text (uiout
, plongest (inf
->num
));
6420 ui_out_text (uiout
, " (");
6421 ui_out_text (uiout
, pidstr
);
6422 ui_out_text (uiout
, ") exited with code ");
6423 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
6424 ui_out_text (uiout
, "]\n");
6428 if (ui_out_is_mi_like_p (uiout
))
6430 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
6431 ui_out_text (uiout
, "[Inferior ");
6432 ui_out_text (uiout
, plongest (inf
->num
));
6433 ui_out_text (uiout
, " (");
6434 ui_out_text (uiout
, pidstr
);
6435 ui_out_text (uiout
, ") exited normally]\n");
6440 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6444 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
6446 struct thread_info
*t
= inferior_thread ();
6448 ui_out_text (uiout
, "\n[");
6449 ui_out_field_string (uiout
, "thread-name",
6450 target_pid_to_str (t
->ptid
));
6451 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
6452 ui_out_text (uiout
, " stopped");
6456 ui_out_text (uiout
, "\nProgram received signal ");
6457 annotate_signal_name ();
6458 if (ui_out_is_mi_like_p (uiout
))
6460 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
6461 ui_out_field_string (uiout
, "signal-name",
6462 gdb_signal_to_name (siggnal
));
6463 annotate_signal_name_end ();
6464 ui_out_text (uiout
, ", ");
6465 annotate_signal_string ();
6466 ui_out_field_string (uiout
, "signal-meaning",
6467 gdb_signal_to_string (siggnal
));
6468 annotate_signal_string_end ();
6470 ui_out_text (uiout
, ".\n");
6474 print_no_history_reason (struct ui_out
*uiout
)
6476 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
6479 /* Print current location without a level number, if we have changed
6480 functions or hit a breakpoint. Print source line if we have one.
6481 bpstat_print contains the logic deciding in detail what to print,
6482 based on the event(s) that just occurred. */
6485 print_stop_event (struct target_waitstatus
*ws
)
6489 int do_frame_printing
= 1;
6490 struct thread_info
*tp
= inferior_thread ();
6492 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
6496 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6497 should) carry around the function and does (or should) use
6498 that when doing a frame comparison. */
6499 if (tp
->control
.stop_step
6500 && frame_id_eq (tp
->control
.step_frame_id
,
6501 get_frame_id (get_current_frame ()))
6502 && tp
->control
.step_start_function
== find_pc_function (stop_pc
))
6504 /* Finished step, just print source line. */
6505 source_flag
= SRC_LINE
;
6509 /* Print location and source line. */
6510 source_flag
= SRC_AND_LOC
;
6513 case PRINT_SRC_AND_LOC
:
6514 /* Print location and source line. */
6515 source_flag
= SRC_AND_LOC
;
6517 case PRINT_SRC_ONLY
:
6518 source_flag
= SRC_LINE
;
6521 /* Something bogus. */
6522 source_flag
= SRC_LINE
;
6523 do_frame_printing
= 0;
6526 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6529 /* The behavior of this routine with respect to the source
6531 SRC_LINE: Print only source line
6532 LOCATION: Print only location
6533 SRC_AND_LOC: Print location and source line. */
6534 if (do_frame_printing
)
6535 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6537 /* Display the auto-display expressions. */
6541 /* Here to return control to GDB when the inferior stops for real.
6542 Print appropriate messages, remove breakpoints, give terminal our modes.
6544 STOP_PRINT_FRAME nonzero means print the executing frame
6545 (pc, function, args, file, line number and line text).
6546 BREAKPOINTS_FAILED nonzero means stop was due to error
6547 attempting to insert breakpoints. */
6552 struct target_waitstatus last
;
6554 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
6556 get_last_target_status (&last_ptid
, &last
);
6558 /* If an exception is thrown from this point on, make sure to
6559 propagate GDB's knowledge of the executing state to the
6560 frontend/user running state. A QUIT is an easy exception to see
6561 here, so do this before any filtered output. */
6563 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
6564 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6565 && last
.kind
!= TARGET_WAITKIND_EXITED
6566 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6567 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
6569 /* As we're presenting a stop, and potentially removing breakpoints,
6570 update the thread list so we can tell whether there are threads
6571 running on the target. With target remote, for example, we can
6572 only learn about new threads when we explicitly update the thread
6573 list. Do this before notifying the interpreters about signal
6574 stops, end of stepping ranges, etc., so that the "new thread"
6575 output is emitted before e.g., "Program received signal FOO",
6576 instead of after. */
6577 update_thread_list ();
6579 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
6580 observer_notify_signal_received (inferior_thread ()->suspend
.stop_signal
);
6582 /* As with the notification of thread events, we want to delay
6583 notifying the user that we've switched thread context until
6584 the inferior actually stops.
6586 There's no point in saying anything if the inferior has exited.
6587 Note that SIGNALLED here means "exited with a signal", not
6588 "received a signal".
6590 Also skip saying anything in non-stop mode. In that mode, as we
6591 don't want GDB to switch threads behind the user's back, to avoid
6592 races where the user is typing a command to apply to thread x,
6593 but GDB switches to thread y before the user finishes entering
6594 the command, fetch_inferior_event installs a cleanup to restore
6595 the current thread back to the thread the user had selected right
6596 after this event is handled, so we're not really switching, only
6597 informing of a stop. */
6599 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
6600 && target_has_execution
6601 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6602 && last
.kind
!= TARGET_WAITKIND_EXITED
6603 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6605 target_terminal_ours_for_output ();
6606 printf_filtered (_("[Switching to %s]\n"),
6607 target_pid_to_str (inferior_ptid
));
6608 annotate_thread_changed ();
6609 previous_inferior_ptid
= inferior_ptid
;
6612 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
6614 gdb_assert (sync_execution
|| !target_can_async_p ());
6616 target_terminal_ours_for_output ();
6617 printf_filtered (_("No unwaited-for children left.\n"));
6620 /* Note: this depends on the update_thread_list call above. */
6621 if (!breakpoints_should_be_inserted_now () && target_has_execution
)
6623 if (remove_breakpoints ())
6625 target_terminal_ours_for_output ();
6626 printf_filtered (_("Cannot remove breakpoints because "
6627 "program is no longer writable.\nFurther "
6628 "execution is probably impossible.\n"));
6632 /* If an auto-display called a function and that got a signal,
6633 delete that auto-display to avoid an infinite recursion. */
6635 if (stopped_by_random_signal
)
6636 disable_current_display ();
6638 /* Notify observers if we finished a "step"-like command, etc. */
6639 if (target_has_execution
6640 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6641 && last
.kind
!= TARGET_WAITKIND_EXITED
6642 && inferior_thread ()->control
.stop_step
)
6644 /* But not if in the middle of doing a "step n" operation for
6646 if (inferior_thread ()->step_multi
)
6649 observer_notify_end_stepping_range ();
6652 target_terminal_ours ();
6653 async_enable_stdin ();
6655 /* Set the current source location. This will also happen if we
6656 display the frame below, but the current SAL will be incorrect
6657 during a user hook-stop function. */
6658 if (has_stack_frames () && !stop_stack_dummy
)
6659 set_current_sal_from_frame (get_current_frame ());
6661 /* Let the user/frontend see the threads as stopped, but do nothing
6662 if the thread was running an infcall. We may be e.g., evaluating
6663 a breakpoint condition. In that case, the thread had state
6664 THREAD_RUNNING before the infcall, and shall remain set to
6665 running, all without informing the user/frontend about state
6666 transition changes. If this is actually a call command, then the
6667 thread was originally already stopped, so there's no state to
6669 if (target_has_execution
&& inferior_thread ()->control
.in_infcall
)
6670 discard_cleanups (old_chain
);
6672 do_cleanups (old_chain
);
6674 /* Look up the hook_stop and run it (CLI internally handles problem
6675 of stop_command's pre-hook not existing). */
6677 catch_errors (hook_stop_stub
, stop_command
,
6678 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6680 if (!has_stack_frames ())
6683 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6684 || last
.kind
== TARGET_WAITKIND_EXITED
)
6687 /* Select innermost stack frame - i.e., current frame is frame 0,
6688 and current location is based on that.
6689 Don't do this on return from a stack dummy routine,
6690 or if the program has exited. */
6692 if (!stop_stack_dummy
)
6694 select_frame (get_current_frame ());
6696 /* If --batch-silent is enabled then there's no need to print the current
6697 source location, and to try risks causing an error message about
6698 missing source files. */
6699 if (stop_print_frame
&& !batch_silent
)
6700 print_stop_event (&last
);
6703 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6705 /* Pop the empty frame that contains the stack dummy.
6706 This also restores inferior state prior to the call
6707 (struct infcall_suspend_state). */
6708 struct frame_info
*frame
= get_current_frame ();
6710 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6712 /* frame_pop() calls reinit_frame_cache as the last thing it
6713 does which means there's currently no selected frame. We
6714 don't need to re-establish a selected frame if the dummy call
6715 returns normally, that will be done by
6716 restore_infcall_control_state. However, we do have to handle
6717 the case where the dummy call is returning after being
6718 stopped (e.g. the dummy call previously hit a breakpoint).
6719 We can't know which case we have so just always re-establish
6720 a selected frame here. */
6721 select_frame (get_current_frame ());
6725 annotate_stopped ();
6727 /* Suppress the stop observer if we're in the middle of:
6729 - a step n (n > 1), as there still more steps to be done.
6731 - a "finish" command, as the observer will be called in
6732 finish_command_continuation, so it can include the inferior
6733 function's return value.
6735 - calling an inferior function, as we pretend we inferior didn't
6736 run at all. The return value of the call is handled by the
6737 expression evaluator, through call_function_by_hand. */
6739 if (!target_has_execution
6740 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6741 || last
.kind
== TARGET_WAITKIND_EXITED
6742 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6743 || (!(inferior_thread ()->step_multi
6744 && inferior_thread ()->control
.stop_step
)
6745 && !(inferior_thread ()->control
.stop_bpstat
6746 && inferior_thread ()->control
.proceed_to_finish
)
6747 && !inferior_thread ()->control
.in_infcall
))
6749 if (!ptid_equal (inferior_ptid
, null_ptid
))
6750 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6753 observer_notify_normal_stop (NULL
, stop_print_frame
);
6756 if (target_has_execution
)
6758 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6759 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6760 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6761 Delete any breakpoint that is to be deleted at the next stop. */
6762 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6765 /* Try to get rid of automatically added inferiors that are no
6766 longer needed. Keeping those around slows down things linearly.
6767 Note that this never removes the current inferior. */
6772 hook_stop_stub (void *cmd
)
6774 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6779 signal_stop_state (int signo
)
6781 return signal_stop
[signo
];
6785 signal_print_state (int signo
)
6787 return signal_print
[signo
];
6791 signal_pass_state (int signo
)
6793 return signal_program
[signo
];
6797 signal_cache_update (int signo
)
6801 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6802 signal_cache_update (signo
);
6807 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6808 && signal_print
[signo
] == 0
6809 && signal_program
[signo
] == 1
6810 && signal_catch
[signo
] == 0);
6814 signal_stop_update (int signo
, int state
)
6816 int ret
= signal_stop
[signo
];
6818 signal_stop
[signo
] = state
;
6819 signal_cache_update (signo
);
6824 signal_print_update (int signo
, int state
)
6826 int ret
= signal_print
[signo
];
6828 signal_print
[signo
] = state
;
6829 signal_cache_update (signo
);
6834 signal_pass_update (int signo
, int state
)
6836 int ret
= signal_program
[signo
];
6838 signal_program
[signo
] = state
;
6839 signal_cache_update (signo
);
6843 /* Update the global 'signal_catch' from INFO and notify the
6847 signal_catch_update (const unsigned int *info
)
6851 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6852 signal_catch
[i
] = info
[i
] > 0;
6853 signal_cache_update (-1);
6854 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6858 sig_print_header (void)
6860 printf_filtered (_("Signal Stop\tPrint\tPass "
6861 "to program\tDescription\n"));
6865 sig_print_info (enum gdb_signal oursig
)
6867 const char *name
= gdb_signal_to_name (oursig
);
6868 int name_padding
= 13 - strlen (name
);
6870 if (name_padding
<= 0)
6873 printf_filtered ("%s", name
);
6874 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6875 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6876 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6877 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6878 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6881 /* Specify how various signals in the inferior should be handled. */
6884 handle_command (char *args
, int from_tty
)
6887 int digits
, wordlen
;
6888 int sigfirst
, signum
, siglast
;
6889 enum gdb_signal oursig
;
6892 unsigned char *sigs
;
6893 struct cleanup
*old_chain
;
6897 error_no_arg (_("signal to handle"));
6900 /* Allocate and zero an array of flags for which signals to handle. */
6902 nsigs
= (int) GDB_SIGNAL_LAST
;
6903 sigs
= (unsigned char *) alloca (nsigs
);
6904 memset (sigs
, 0, nsigs
);
6906 /* Break the command line up into args. */
6908 argv
= gdb_buildargv (args
);
6909 old_chain
= make_cleanup_freeargv (argv
);
6911 /* Walk through the args, looking for signal oursigs, signal names, and
6912 actions. Signal numbers and signal names may be interspersed with
6913 actions, with the actions being performed for all signals cumulatively
6914 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6916 while (*argv
!= NULL
)
6918 wordlen
= strlen (*argv
);
6919 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6923 sigfirst
= siglast
= -1;
6925 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6927 /* Apply action to all signals except those used by the
6928 debugger. Silently skip those. */
6931 siglast
= nsigs
- 1;
6933 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6935 SET_SIGS (nsigs
, sigs
, signal_stop
);
6936 SET_SIGS (nsigs
, sigs
, signal_print
);
6938 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6940 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6942 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6944 SET_SIGS (nsigs
, sigs
, signal_print
);
6946 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6948 SET_SIGS (nsigs
, sigs
, signal_program
);
6950 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6952 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6954 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6956 SET_SIGS (nsigs
, sigs
, signal_program
);
6958 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6960 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6961 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6963 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6965 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6967 else if (digits
> 0)
6969 /* It is numeric. The numeric signal refers to our own
6970 internal signal numbering from target.h, not to host/target
6971 signal number. This is a feature; users really should be
6972 using symbolic names anyway, and the common ones like
6973 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6975 sigfirst
= siglast
= (int)
6976 gdb_signal_from_command (atoi (*argv
));
6977 if ((*argv
)[digits
] == '-')
6980 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6982 if (sigfirst
> siglast
)
6984 /* Bet he didn't figure we'd think of this case... */
6992 oursig
= gdb_signal_from_name (*argv
);
6993 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6995 sigfirst
= siglast
= (int) oursig
;
6999 /* Not a number and not a recognized flag word => complain. */
7000 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
7004 /* If any signal numbers or symbol names were found, set flags for
7005 which signals to apply actions to. */
7007 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
7009 switch ((enum gdb_signal
) signum
)
7011 case GDB_SIGNAL_TRAP
:
7012 case GDB_SIGNAL_INT
:
7013 if (!allsigs
&& !sigs
[signum
])
7015 if (query (_("%s is used by the debugger.\n\
7016 Are you sure you want to change it? "),
7017 gdb_signal_to_name ((enum gdb_signal
) signum
)))
7023 printf_unfiltered (_("Not confirmed, unchanged.\n"));
7024 gdb_flush (gdb_stdout
);
7029 case GDB_SIGNAL_DEFAULT
:
7030 case GDB_SIGNAL_UNKNOWN
:
7031 /* Make sure that "all" doesn't print these. */
7042 for (signum
= 0; signum
< nsigs
; signum
++)
7045 signal_cache_update (-1);
7046 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
7047 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
7051 /* Show the results. */
7052 sig_print_header ();
7053 for (; signum
< nsigs
; signum
++)
7055 sig_print_info (signum
);
7061 do_cleanups (old_chain
);
7064 /* Complete the "handle" command. */
7066 static VEC (char_ptr
) *
7067 handle_completer (struct cmd_list_element
*ignore
,
7068 const char *text
, const char *word
)
7070 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
7071 static const char * const keywords
[] =
7085 vec_signals
= signal_completer (ignore
, text
, word
);
7086 vec_keywords
= complete_on_enum (keywords
, word
, word
);
7088 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
7089 VEC_free (char_ptr
, vec_signals
);
7090 VEC_free (char_ptr
, vec_keywords
);
7095 gdb_signal_from_command (int num
)
7097 if (num
>= 1 && num
<= 15)
7098 return (enum gdb_signal
) num
;
7099 error (_("Only signals 1-15 are valid as numeric signals.\n\
7100 Use \"info signals\" for a list of symbolic signals."));
7103 /* Print current contents of the tables set by the handle command.
7104 It is possible we should just be printing signals actually used
7105 by the current target (but for things to work right when switching
7106 targets, all signals should be in the signal tables). */
7109 signals_info (char *signum_exp
, int from_tty
)
7111 enum gdb_signal oursig
;
7113 sig_print_header ();
7117 /* First see if this is a symbol name. */
7118 oursig
= gdb_signal_from_name (signum_exp
);
7119 if (oursig
== GDB_SIGNAL_UNKNOWN
)
7121 /* No, try numeric. */
7123 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
7125 sig_print_info (oursig
);
7129 printf_filtered ("\n");
7130 /* These ugly casts brought to you by the native VAX compiler. */
7131 for (oursig
= GDB_SIGNAL_FIRST
;
7132 (int) oursig
< (int) GDB_SIGNAL_LAST
;
7133 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
7137 if (oursig
!= GDB_SIGNAL_UNKNOWN
7138 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
7139 sig_print_info (oursig
);
7142 printf_filtered (_("\nUse the \"handle\" command "
7143 "to change these tables.\n"));
7146 /* Check if it makes sense to read $_siginfo from the current thread
7147 at this point. If not, throw an error. */
7150 validate_siginfo_access (void)
7152 /* No current inferior, no siginfo. */
7153 if (ptid_equal (inferior_ptid
, null_ptid
))
7154 error (_("No thread selected."));
7156 /* Don't try to read from a dead thread. */
7157 if (is_exited (inferior_ptid
))
7158 error (_("The current thread has terminated"));
7160 /* ... or from a spinning thread. */
7161 if (is_running (inferior_ptid
))
7162 error (_("Selected thread is running."));
7165 /* The $_siginfo convenience variable is a bit special. We don't know
7166 for sure the type of the value until we actually have a chance to
7167 fetch the data. The type can change depending on gdbarch, so it is
7168 also dependent on which thread you have selected.
7170 1. making $_siginfo be an internalvar that creates a new value on
7173 2. making the value of $_siginfo be an lval_computed value. */
7175 /* This function implements the lval_computed support for reading a
7179 siginfo_value_read (struct value
*v
)
7181 LONGEST transferred
;
7183 validate_siginfo_access ();
7186 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
7188 value_contents_all_raw (v
),
7190 TYPE_LENGTH (value_type (v
)));
7192 if (transferred
!= TYPE_LENGTH (value_type (v
)))
7193 error (_("Unable to read siginfo"));
7196 /* This function implements the lval_computed support for writing a
7200 siginfo_value_write (struct value
*v
, struct value
*fromval
)
7202 LONGEST transferred
;
7204 validate_siginfo_access ();
7206 transferred
= target_write (¤t_target
,
7207 TARGET_OBJECT_SIGNAL_INFO
,
7209 value_contents_all_raw (fromval
),
7211 TYPE_LENGTH (value_type (fromval
)));
7213 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
7214 error (_("Unable to write siginfo"));
7217 static const struct lval_funcs siginfo_value_funcs
=
7223 /* Return a new value with the correct type for the siginfo object of
7224 the current thread using architecture GDBARCH. Return a void value
7225 if there's no object available. */
7227 static struct value
*
7228 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
7231 if (target_has_stack
7232 && !ptid_equal (inferior_ptid
, null_ptid
)
7233 && gdbarch_get_siginfo_type_p (gdbarch
))
7235 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7237 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
7240 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
7244 /* infcall_suspend_state contains state about the program itself like its
7245 registers and any signal it received when it last stopped.
7246 This state must be restored regardless of how the inferior function call
7247 ends (either successfully, or after it hits a breakpoint or signal)
7248 if the program is to properly continue where it left off. */
7250 struct infcall_suspend_state
7252 struct thread_suspend_state thread_suspend
;
7253 #if 0 /* Currently unused and empty structures are not valid C. */
7254 struct inferior_suspend_state inferior_suspend
;
7259 struct regcache
*registers
;
7261 /* Format of SIGINFO_DATA or NULL if it is not present. */
7262 struct gdbarch
*siginfo_gdbarch
;
7264 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
7265 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
7266 content would be invalid. */
7267 gdb_byte
*siginfo_data
;
7270 struct infcall_suspend_state
*
7271 save_infcall_suspend_state (void)
7273 struct infcall_suspend_state
*inf_state
;
7274 struct thread_info
*tp
= inferior_thread ();
7276 struct inferior
*inf
= current_inferior ();
7278 struct regcache
*regcache
= get_current_regcache ();
7279 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7280 gdb_byte
*siginfo_data
= NULL
;
7282 if (gdbarch_get_siginfo_type_p (gdbarch
))
7284 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7285 size_t len
= TYPE_LENGTH (type
);
7286 struct cleanup
*back_to
;
7288 siginfo_data
= xmalloc (len
);
7289 back_to
= make_cleanup (xfree
, siginfo_data
);
7291 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7292 siginfo_data
, 0, len
) == len
)
7293 discard_cleanups (back_to
);
7296 /* Errors ignored. */
7297 do_cleanups (back_to
);
7298 siginfo_data
= NULL
;
7302 inf_state
= XCNEW (struct infcall_suspend_state
);
7306 inf_state
->siginfo_gdbarch
= gdbarch
;
7307 inf_state
->siginfo_data
= siginfo_data
;
7310 inf_state
->thread_suspend
= tp
->suspend
;
7311 #if 0 /* Currently unused and empty structures are not valid C. */
7312 inf_state
->inferior_suspend
= inf
->suspend
;
7315 /* run_inferior_call will not use the signal due to its `proceed' call with
7316 GDB_SIGNAL_0 anyway. */
7317 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7319 inf_state
->stop_pc
= stop_pc
;
7321 inf_state
->registers
= regcache_dup (regcache
);
7326 /* Restore inferior session state to INF_STATE. */
7329 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7331 struct thread_info
*tp
= inferior_thread ();
7333 struct inferior
*inf
= current_inferior ();
7335 struct regcache
*regcache
= get_current_regcache ();
7336 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7338 tp
->suspend
= inf_state
->thread_suspend
;
7339 #if 0 /* Currently unused and empty structures are not valid C. */
7340 inf
->suspend
= inf_state
->inferior_suspend
;
7343 stop_pc
= inf_state
->stop_pc
;
7345 if (inf_state
->siginfo_gdbarch
== gdbarch
)
7347 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7349 /* Errors ignored. */
7350 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7351 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
7354 /* The inferior can be gone if the user types "print exit(0)"
7355 (and perhaps other times). */
7356 if (target_has_execution
)
7357 /* NB: The register write goes through to the target. */
7358 regcache_cpy (regcache
, inf_state
->registers
);
7360 discard_infcall_suspend_state (inf_state
);
7364 do_restore_infcall_suspend_state_cleanup (void *state
)
7366 restore_infcall_suspend_state (state
);
7370 make_cleanup_restore_infcall_suspend_state
7371 (struct infcall_suspend_state
*inf_state
)
7373 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
7377 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7379 regcache_xfree (inf_state
->registers
);
7380 xfree (inf_state
->siginfo_data
);
7385 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
7387 return inf_state
->registers
;
7390 /* infcall_control_state contains state regarding gdb's control of the
7391 inferior itself like stepping control. It also contains session state like
7392 the user's currently selected frame. */
7394 struct infcall_control_state
7396 struct thread_control_state thread_control
;
7397 struct inferior_control_state inferior_control
;
7400 enum stop_stack_kind stop_stack_dummy
;
7401 int stopped_by_random_signal
;
7402 int stop_after_trap
;
7404 /* ID if the selected frame when the inferior function call was made. */
7405 struct frame_id selected_frame_id
;
7408 /* Save all of the information associated with the inferior<==>gdb
7411 struct infcall_control_state
*
7412 save_infcall_control_state (void)
7414 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
7415 struct thread_info
*tp
= inferior_thread ();
7416 struct inferior
*inf
= current_inferior ();
7418 inf_status
->thread_control
= tp
->control
;
7419 inf_status
->inferior_control
= inf
->control
;
7421 tp
->control
.step_resume_breakpoint
= NULL
;
7422 tp
->control
.exception_resume_breakpoint
= NULL
;
7424 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7425 chain. If caller's caller is walking the chain, they'll be happier if we
7426 hand them back the original chain when restore_infcall_control_state is
7428 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
7431 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
7432 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
7433 inf_status
->stop_after_trap
= stop_after_trap
;
7435 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
7441 restore_selected_frame (void *args
)
7443 struct frame_id
*fid
= (struct frame_id
*) args
;
7444 struct frame_info
*frame
;
7446 frame
= frame_find_by_id (*fid
);
7448 /* If inf_status->selected_frame_id is NULL, there was no previously
7452 warning (_("Unable to restore previously selected frame."));
7456 select_frame (frame
);
7461 /* Restore inferior session state to INF_STATUS. */
7464 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
7466 struct thread_info
*tp
= inferior_thread ();
7467 struct inferior
*inf
= current_inferior ();
7469 if (tp
->control
.step_resume_breakpoint
)
7470 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
7472 if (tp
->control
.exception_resume_breakpoint
)
7473 tp
->control
.exception_resume_breakpoint
->disposition
7474 = disp_del_at_next_stop
;
7476 /* Handle the bpstat_copy of the chain. */
7477 bpstat_clear (&tp
->control
.stop_bpstat
);
7479 tp
->control
= inf_status
->thread_control
;
7480 inf
->control
= inf_status
->inferior_control
;
7483 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
7484 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
7485 stop_after_trap
= inf_status
->stop_after_trap
;
7487 if (target_has_stack
)
7489 /* The point of catch_errors is that if the stack is clobbered,
7490 walking the stack might encounter a garbage pointer and
7491 error() trying to dereference it. */
7493 (restore_selected_frame
, &inf_status
->selected_frame_id
,
7494 "Unable to restore previously selected frame:\n",
7495 RETURN_MASK_ERROR
) == 0)
7496 /* Error in restoring the selected frame. Select the innermost
7498 select_frame (get_current_frame ());
7505 do_restore_infcall_control_state_cleanup (void *sts
)
7507 restore_infcall_control_state (sts
);
7511 make_cleanup_restore_infcall_control_state
7512 (struct infcall_control_state
*inf_status
)
7514 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7518 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7520 if (inf_status
->thread_control
.step_resume_breakpoint
)
7521 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7522 = disp_del_at_next_stop
;
7524 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7525 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7526 = disp_del_at_next_stop
;
7528 /* See save_infcall_control_state for info on stop_bpstat. */
7529 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7534 /* restore_inferior_ptid() will be used by the cleanup machinery
7535 to restore the inferior_ptid value saved in a call to
7536 save_inferior_ptid(). */
7539 restore_inferior_ptid (void *arg
)
7541 ptid_t
*saved_ptid_ptr
= arg
;
7543 inferior_ptid
= *saved_ptid_ptr
;
7547 /* Save the value of inferior_ptid so that it may be restored by a
7548 later call to do_cleanups(). Returns the struct cleanup pointer
7549 needed for later doing the cleanup. */
7552 save_inferior_ptid (void)
7554 ptid_t
*saved_ptid_ptr
;
7556 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7557 *saved_ptid_ptr
= inferior_ptid
;
7558 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7564 clear_exit_convenience_vars (void)
7566 clear_internalvar (lookup_internalvar ("_exitsignal"));
7567 clear_internalvar (lookup_internalvar ("_exitcode"));
7571 /* User interface for reverse debugging:
7572 Set exec-direction / show exec-direction commands
7573 (returns error unless target implements to_set_exec_direction method). */
7575 int execution_direction
= EXEC_FORWARD
;
7576 static const char exec_forward
[] = "forward";
7577 static const char exec_reverse
[] = "reverse";
7578 static const char *exec_direction
= exec_forward
;
7579 static const char *const exec_direction_names
[] = {
7586 set_exec_direction_func (char *args
, int from_tty
,
7587 struct cmd_list_element
*cmd
)
7589 if (target_can_execute_reverse
)
7591 if (!strcmp (exec_direction
, exec_forward
))
7592 execution_direction
= EXEC_FORWARD
;
7593 else if (!strcmp (exec_direction
, exec_reverse
))
7594 execution_direction
= EXEC_REVERSE
;
7598 exec_direction
= exec_forward
;
7599 error (_("Target does not support this operation."));
7604 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7605 struct cmd_list_element
*cmd
, const char *value
)
7607 switch (execution_direction
) {
7609 fprintf_filtered (out
, _("Forward.\n"));
7612 fprintf_filtered (out
, _("Reverse.\n"));
7615 internal_error (__FILE__
, __LINE__
,
7616 _("bogus execution_direction value: %d"),
7617 (int) execution_direction
);
7622 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7623 struct cmd_list_element
*c
, const char *value
)
7625 fprintf_filtered (file
, _("Resuming the execution of threads "
7626 "of all processes is %s.\n"), value
);
7629 /* Implementation of `siginfo' variable. */
7631 static const struct internalvar_funcs siginfo_funcs
=
7639 _initialize_infrun (void)
7643 struct cmd_list_element
*c
;
7645 add_info ("signals", signals_info
, _("\
7646 What debugger does when program gets various signals.\n\
7647 Specify a signal as argument to print info on that signal only."));
7648 add_info_alias ("handle", "signals", 0);
7650 c
= add_com ("handle", class_run
, handle_command
, _("\
7651 Specify how to handle signals.\n\
7652 Usage: handle SIGNAL [ACTIONS]\n\
7653 Args are signals and actions to apply to those signals.\n\
7654 If no actions are specified, the current settings for the specified signals\n\
7655 will be displayed instead.\n\
7657 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7658 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7659 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7660 The special arg \"all\" is recognized to mean all signals except those\n\
7661 used by the debugger, typically SIGTRAP and SIGINT.\n\
7663 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7664 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7665 Stop means reenter debugger if this signal happens (implies print).\n\
7666 Print means print a message if this signal happens.\n\
7667 Pass means let program see this signal; otherwise program doesn't know.\n\
7668 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7669 Pass and Stop may be combined.\n\
7671 Multiple signals may be specified. Signal numbers and signal names\n\
7672 may be interspersed with actions, with the actions being performed for\n\
7673 all signals cumulatively specified."));
7674 set_cmd_completer (c
, handle_completer
);
7677 stop_command
= add_cmd ("stop", class_obscure
,
7678 not_just_help_class_command
, _("\
7679 There is no `stop' command, but you can set a hook on `stop'.\n\
7680 This allows you to set a list of commands to be run each time execution\n\
7681 of the program stops."), &cmdlist
);
7683 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7684 Set inferior debugging."), _("\
7685 Show inferior debugging."), _("\
7686 When non-zero, inferior specific debugging is enabled."),
7689 &setdebuglist
, &showdebuglist
);
7691 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7692 &debug_displaced
, _("\
7693 Set displaced stepping debugging."), _("\
7694 Show displaced stepping debugging."), _("\
7695 When non-zero, displaced stepping specific debugging is enabled."),
7697 show_debug_displaced
,
7698 &setdebuglist
, &showdebuglist
);
7700 add_setshow_boolean_cmd ("non-stop", no_class
,
7702 Set whether gdb controls the inferior in non-stop mode."), _("\
7703 Show whether gdb controls the inferior in non-stop mode."), _("\
7704 When debugging a multi-threaded program and this setting is\n\
7705 off (the default, also called all-stop mode), when one thread stops\n\
7706 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7707 all other threads in the program while you interact with the thread of\n\
7708 interest. When you continue or step a thread, you can allow the other\n\
7709 threads to run, or have them remain stopped, but while you inspect any\n\
7710 thread's state, all threads stop.\n\
7712 In non-stop mode, when one thread stops, other threads can continue\n\
7713 to run freely. You'll be able to step each thread independently,\n\
7714 leave it stopped or free to run as needed."),
7720 numsigs
= (int) GDB_SIGNAL_LAST
;
7721 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7722 signal_print
= (unsigned char *)
7723 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7724 signal_program
= (unsigned char *)
7725 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7726 signal_catch
= (unsigned char *)
7727 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7728 signal_pass
= (unsigned char *)
7729 xmalloc (sizeof (signal_pass
[0]) * numsigs
);
7730 for (i
= 0; i
< numsigs
; i
++)
7733 signal_print
[i
] = 1;
7734 signal_program
[i
] = 1;
7735 signal_catch
[i
] = 0;
7738 /* Signals caused by debugger's own actions
7739 should not be given to the program afterwards. */
7740 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7741 signal_program
[GDB_SIGNAL_INT
] = 0;
7743 /* Signals that are not errors should not normally enter the debugger. */
7744 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7745 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7746 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7747 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7748 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7749 signal_print
[GDB_SIGNAL_PROF
] = 0;
7750 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7751 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7752 signal_stop
[GDB_SIGNAL_IO
] = 0;
7753 signal_print
[GDB_SIGNAL_IO
] = 0;
7754 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7755 signal_print
[GDB_SIGNAL_POLL
] = 0;
7756 signal_stop
[GDB_SIGNAL_URG
] = 0;
7757 signal_print
[GDB_SIGNAL_URG
] = 0;
7758 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7759 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7760 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7761 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7763 /* These signals are used internally by user-level thread
7764 implementations. (See signal(5) on Solaris.) Like the above
7765 signals, a healthy program receives and handles them as part of
7766 its normal operation. */
7767 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7768 signal_print
[GDB_SIGNAL_LWP
] = 0;
7769 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7770 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7771 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7772 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7774 /* Update cached state. */
7775 signal_cache_update (-1);
7777 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7778 &stop_on_solib_events
, _("\
7779 Set stopping for shared library events."), _("\
7780 Show stopping for shared library events."), _("\
7781 If nonzero, gdb will give control to the user when the dynamic linker\n\
7782 notifies gdb of shared library events. The most common event of interest\n\
7783 to the user would be loading/unloading of a new library."),
7784 set_stop_on_solib_events
,
7785 show_stop_on_solib_events
,
7786 &setlist
, &showlist
);
7788 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7789 follow_fork_mode_kind_names
,
7790 &follow_fork_mode_string
, _("\
7791 Set debugger response to a program call of fork or vfork."), _("\
7792 Show debugger response to a program call of fork or vfork."), _("\
7793 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7794 parent - the original process is debugged after a fork\n\
7795 child - the new process is debugged after a fork\n\
7796 The unfollowed process will continue to run.\n\
7797 By default, the debugger will follow the parent process."),
7799 show_follow_fork_mode_string
,
7800 &setlist
, &showlist
);
7802 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7803 follow_exec_mode_names
,
7804 &follow_exec_mode_string
, _("\
7805 Set debugger response to a program call of exec."), _("\
7806 Show debugger response to a program call of exec."), _("\
7807 An exec call replaces the program image of a process.\n\
7809 follow-exec-mode can be:\n\
7811 new - the debugger creates a new inferior and rebinds the process\n\
7812 to this new inferior. The program the process was running before\n\
7813 the exec call can be restarted afterwards by restarting the original\n\
7816 same - the debugger keeps the process bound to the same inferior.\n\
7817 The new executable image replaces the previous executable loaded in\n\
7818 the inferior. Restarting the inferior after the exec call restarts\n\
7819 the executable the process was running after the exec call.\n\
7821 By default, the debugger will use the same inferior."),
7823 show_follow_exec_mode_string
,
7824 &setlist
, &showlist
);
7826 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7827 scheduler_enums
, &scheduler_mode
, _("\
7828 Set mode for locking scheduler during execution."), _("\
7829 Show mode for locking scheduler during execution."), _("\
7830 off == no locking (threads may preempt at any time)\n\
7831 on == full locking (no thread except the current thread may run)\n\
7832 step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
7833 In this mode, other threads may run during other commands."),
7834 set_schedlock_func
, /* traps on target vector */
7835 show_scheduler_mode
,
7836 &setlist
, &showlist
);
7838 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7839 Set mode for resuming threads of all processes."), _("\
7840 Show mode for resuming threads of all processes."), _("\
7841 When on, execution commands (such as 'continue' or 'next') resume all\n\
7842 threads of all processes. When off (which is the default), execution\n\
7843 commands only resume the threads of the current process. The set of\n\
7844 threads that are resumed is further refined by the scheduler-locking\n\
7845 mode (see help set scheduler-locking)."),
7847 show_schedule_multiple
,
7848 &setlist
, &showlist
);
7850 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7851 Set mode of the step operation."), _("\
7852 Show mode of the step operation."), _("\
7853 When set, doing a step over a function without debug line information\n\
7854 will stop at the first instruction of that function. Otherwise, the\n\
7855 function is skipped and the step command stops at a different source line."),
7857 show_step_stop_if_no_debug
,
7858 &setlist
, &showlist
);
7860 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7861 &can_use_displaced_stepping
, _("\
7862 Set debugger's willingness to use displaced stepping."), _("\
7863 Show debugger's willingness to use displaced stepping."), _("\
7864 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7865 supported by the target architecture. If off, gdb will not use displaced\n\
7866 stepping to step over breakpoints, even if such is supported by the target\n\
7867 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7868 if the target architecture supports it and non-stop mode is active, but will not\n\
7869 use it in all-stop mode (see help set non-stop)."),
7871 show_can_use_displaced_stepping
,
7872 &setlist
, &showlist
);
7874 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7875 &exec_direction
, _("Set direction of execution.\n\
7876 Options are 'forward' or 'reverse'."),
7877 _("Show direction of execution (forward/reverse)."),
7878 _("Tells gdb whether to execute forward or backward."),
7879 set_exec_direction_func
, show_exec_direction_func
,
7880 &setlist
, &showlist
);
7882 /* Set/show detach-on-fork: user-settable mode. */
7884 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7885 Set whether gdb will detach the child of a fork."), _("\
7886 Show whether gdb will detach the child of a fork."), _("\
7887 Tells gdb whether to detach the child of a fork."),
7888 NULL
, NULL
, &setlist
, &showlist
);
7890 /* Set/show disable address space randomization mode. */
7892 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7893 &disable_randomization
, _("\
7894 Set disabling of debuggee's virtual address space randomization."), _("\
7895 Show disabling of debuggee's virtual address space randomization."), _("\
7896 When this mode is on (which is the default), randomization of the virtual\n\
7897 address space is disabled. Standalone programs run with the randomization\n\
7898 enabled by default on some platforms."),
7899 &set_disable_randomization
,
7900 &show_disable_randomization
,
7901 &setlist
, &showlist
);
7903 /* ptid initializations */
7904 inferior_ptid
= null_ptid
;
7905 target_last_wait_ptid
= minus_one_ptid
;
7907 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7908 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7909 observer_attach_thread_exit (infrun_thread_thread_exit
);
7910 observer_attach_inferior_exit (infrun_inferior_exit
);
7912 /* Explicitly create without lookup, since that tries to create a
7913 value with a void typed value, and when we get here, gdbarch
7914 isn't initialized yet. At this point, we're quite sure there
7915 isn't another convenience variable of the same name. */
7916 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7918 add_setshow_boolean_cmd ("observer", no_class
,
7919 &observer_mode_1
, _("\
7920 Set whether gdb controls the inferior in observer mode."), _("\
7921 Show whether gdb controls the inferior in observer mode."), _("\
7922 In observer mode, GDB can get data from the inferior, but not\n\
7923 affect its execution. Registers and memory may not be changed,\n\
7924 breakpoints may not be set, and the program cannot be interrupted\n\