1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986-2014 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 "exceptions.h"
28 #include "breakpoint.h"
32 #include "cli/cli-script.h"
34 #include "gdbthread.h"
46 #include "dictionary.h"
48 #include "mi/mi-common.h"
49 #include "event-top.h"
51 #include "record-full.h"
52 #include "inline-frame.h"
54 #include "tracepoint.h"
55 #include "continuations.h"
60 #include "completer.h"
61 #include "target-descriptions.h"
62 #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 static void xdb_handle_command (char *args
, int from_tty
);
94 void _initialize_infrun (void);
96 void nullify_last_target_wait_ptid (void);
98 static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*);
100 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
102 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
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 /* Function inferior was in as of last step command. */
332 static struct symbol
*step_start_function
;
334 /* Nonzero if we want to give control to the user when we're notified
335 of shared library events by the dynamic linker. */
336 int stop_on_solib_events
;
338 /* Enable or disable optional shared library event breakpoints
339 as appropriate when the above flag is changed. */
342 set_stop_on_solib_events (char *args
, int from_tty
, struct cmd_list_element
*c
)
344 update_solib_breakpoints ();
348 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
349 struct cmd_list_element
*c
, const char *value
)
351 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
355 /* Nonzero means expecting a trace trap
356 and should stop the inferior and return silently when it happens. */
360 /* Save register contents here when executing a "finish" command or are
361 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
362 Thus this contains the return value from the called function (assuming
363 values are returned in a register). */
365 struct regcache
*stop_registers
;
367 /* Nonzero after stop if current stack frame should be printed. */
369 static int stop_print_frame
;
371 /* This is a cached copy of the pid/waitstatus of the last event
372 returned by target_wait()/deprecated_target_wait_hook(). This
373 information is returned by get_last_target_status(). */
374 static ptid_t target_last_wait_ptid
;
375 static struct target_waitstatus target_last_waitstatus
;
377 static void context_switch (ptid_t ptid
);
379 void init_thread_stepping_state (struct thread_info
*tss
);
381 static void init_infwait_state (void);
383 static const char follow_fork_mode_child
[] = "child";
384 static const char follow_fork_mode_parent
[] = "parent";
386 static const char *const follow_fork_mode_kind_names
[] = {
387 follow_fork_mode_child
,
388 follow_fork_mode_parent
,
392 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
394 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
395 struct cmd_list_element
*c
, const char *value
)
397 fprintf_filtered (file
,
398 _("Debugger response to a program "
399 "call of fork or vfork is \"%s\".\n"),
404 /* Handle changes to the inferior list based on the type of fork,
405 which process is being followed, and whether the other process
406 should be detached. On entry inferior_ptid must be the ptid of
407 the fork parent. At return inferior_ptid is the ptid of the
408 followed inferior. */
411 follow_fork_inferior (int follow_child
, int detach_fork
)
414 int parent_pid
, child_pid
;
416 has_vforked
= (inferior_thread ()->pending_follow
.kind
417 == TARGET_WAITKIND_VFORKED
);
418 parent_pid
= ptid_get_lwp (inferior_ptid
);
420 parent_pid
= ptid_get_pid (inferior_ptid
);
422 = ptid_get_pid (inferior_thread ()->pending_follow
.value
.related_pid
);
425 && !non_stop
/* Non-stop always resumes both branches. */
426 && (!target_is_async_p () || sync_execution
)
427 && !(follow_child
|| detach_fork
|| sched_multi
))
429 /* The parent stays blocked inside the vfork syscall until the
430 child execs or exits. If we don't let the child run, then
431 the parent stays blocked. If we're telling the parent to run
432 in the foreground, the user will not be able to ctrl-c to get
433 back the terminal, effectively hanging the debug session. */
434 fprintf_filtered (gdb_stderr
, _("\
435 Can not resume the parent process over vfork in the foreground while\n\
436 holding the child stopped. Try \"set detach-on-fork\" or \
437 \"set schedule-multiple\".\n"));
438 /* FIXME output string > 80 columns. */
444 /* Detach new forked process? */
447 struct cleanup
*old_chain
;
449 /* Before detaching from the child, remove all breakpoints
450 from it. If we forked, then this has already been taken
451 care of by infrun.c. If we vforked however, any
452 breakpoint inserted in the parent is visible in the
453 child, even those added while stopped in a vfork
454 catchpoint. This will remove the breakpoints from the
455 parent also, but they'll be reinserted below. */
458 /* Keep breakpoints list in sync. */
459 remove_breakpoints_pid (ptid_get_pid (inferior_ptid
));
462 if (info_verbose
|| debug_infrun
)
464 target_terminal_ours ();
465 fprintf_filtered (gdb_stdlog
,
466 "Detaching after fork from "
467 "child process %d.\n",
473 struct inferior
*parent_inf
, *child_inf
;
474 struct cleanup
*old_chain
;
476 /* Add process to GDB's tables. */
477 child_inf
= add_inferior (child_pid
);
479 parent_inf
= current_inferior ();
480 child_inf
->attach_flag
= parent_inf
->attach_flag
;
481 copy_terminal_info (child_inf
, parent_inf
);
482 child_inf
->gdbarch
= parent_inf
->gdbarch
;
483 copy_inferior_target_desc_info (child_inf
, parent_inf
);
485 old_chain
= save_inferior_ptid ();
486 save_current_program_space ();
488 inferior_ptid
= ptid_build (child_pid
, child_pid
, 0);
489 add_thread (inferior_ptid
);
490 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
492 /* If this is a vfork child, then the address-space is
493 shared with the parent. */
496 child_inf
->pspace
= parent_inf
->pspace
;
497 child_inf
->aspace
= parent_inf
->aspace
;
499 /* The parent will be frozen until the child is done
500 with the shared region. Keep track of the
502 child_inf
->vfork_parent
= parent_inf
;
503 child_inf
->pending_detach
= 0;
504 parent_inf
->vfork_child
= child_inf
;
505 parent_inf
->pending_detach
= 0;
509 child_inf
->aspace
= new_address_space ();
510 child_inf
->pspace
= add_program_space (child_inf
->aspace
);
511 child_inf
->removable
= 1;
512 set_current_program_space (child_inf
->pspace
);
513 clone_program_space (child_inf
->pspace
, parent_inf
->pspace
);
515 /* Let the shared library layer (e.g., solib-svr4) learn
516 about this new process, relocate the cloned exec, pull
517 in shared libraries, and install the solib event
518 breakpoint. If a "cloned-VM" event was propagated
519 better throughout the core, this wouldn't be
521 solib_create_inferior_hook (0);
524 do_cleanups (old_chain
);
529 struct inferior
*parent_inf
;
531 parent_inf
= current_inferior ();
533 /* If we detached from the child, then we have to be careful
534 to not insert breakpoints in the parent until the child
535 is done with the shared memory region. However, if we're
536 staying attached to the child, then we can and should
537 insert breakpoints, so that we can debug it. A
538 subsequent child exec or exit is enough to know when does
539 the child stops using the parent's address space. */
540 parent_inf
->waiting_for_vfork_done
= detach_fork
;
541 parent_inf
->pspace
->breakpoints_not_allowed
= detach_fork
;
546 /* Follow the child. */
547 struct inferior
*parent_inf
, *child_inf
;
548 struct program_space
*parent_pspace
;
550 if (info_verbose
|| debug_infrun
)
552 target_terminal_ours ();
554 fprintf_filtered (gdb_stdlog
,
555 _("Attaching after process %d "
556 "vfork to child process %d.\n"),
557 parent_pid
, child_pid
);
559 fprintf_filtered (gdb_stdlog
,
560 _("Attaching after process %d "
561 "fork to child process %d.\n"),
562 parent_pid
, child_pid
);
565 /* Add the new inferior first, so that the target_detach below
566 doesn't unpush the target. */
568 child_inf
= add_inferior (child_pid
);
570 parent_inf
= current_inferior ();
571 child_inf
->attach_flag
= parent_inf
->attach_flag
;
572 copy_terminal_info (child_inf
, parent_inf
);
573 child_inf
->gdbarch
= parent_inf
->gdbarch
;
574 copy_inferior_target_desc_info (child_inf
, parent_inf
);
576 parent_pspace
= parent_inf
->pspace
;
578 /* If we're vforking, we want to hold on to the parent until the
579 child exits or execs. At child exec or exit time we can
580 remove the old breakpoints from the parent and detach or
581 resume debugging it. Otherwise, detach the parent now; we'll
582 want to reuse it's program/address spaces, but we can't set
583 them to the child before removing breakpoints from the
584 parent, otherwise, the breakpoints module could decide to
585 remove breakpoints from the wrong process (since they'd be
586 assigned to the same address space). */
590 gdb_assert (child_inf
->vfork_parent
== NULL
);
591 gdb_assert (parent_inf
->vfork_child
== NULL
);
592 child_inf
->vfork_parent
= parent_inf
;
593 child_inf
->pending_detach
= 0;
594 parent_inf
->vfork_child
= child_inf
;
595 parent_inf
->pending_detach
= detach_fork
;
596 parent_inf
->waiting_for_vfork_done
= 0;
598 else if (detach_fork
)
599 target_detach (NULL
, 0);
601 /* Note that the detach above makes PARENT_INF dangling. */
603 /* Add the child thread to the appropriate lists, and switch to
604 this new thread, before cloning the program space, and
605 informing the solib layer about this new process. */
607 inferior_ptid
= ptid_build (child_pid
, child_pid
, 0);
608 add_thread (inferior_ptid
);
610 /* If this is a vfork child, then the address-space is shared
611 with the parent. If we detached from the parent, then we can
612 reuse the parent's program/address spaces. */
613 if (has_vforked
|| detach_fork
)
615 child_inf
->pspace
= parent_pspace
;
616 child_inf
->aspace
= child_inf
->pspace
->aspace
;
620 child_inf
->aspace
= new_address_space ();
621 child_inf
->pspace
= add_program_space (child_inf
->aspace
);
622 child_inf
->removable
= 1;
623 child_inf
->symfile_flags
= SYMFILE_NO_READ
;
624 set_current_program_space (child_inf
->pspace
);
625 clone_program_space (child_inf
->pspace
, parent_pspace
);
627 /* Let the shared library layer (e.g., solib-svr4) learn
628 about this new process, relocate the cloned exec, pull in
629 shared libraries, and install the solib event breakpoint.
630 If a "cloned-VM" event was propagated better throughout
631 the core, this wouldn't be required. */
632 solib_create_inferior_hook (0);
636 return target_follow_fork (follow_child
, detach_fork
);
639 /* Tell the target to follow the fork we're stopped at. Returns true
640 if the inferior should be resumed; false, if the target for some
641 reason decided it's best not to resume. */
646 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
647 int should_resume
= 1;
648 struct thread_info
*tp
;
650 /* Copy user stepping state to the new inferior thread. FIXME: the
651 followed fork child thread should have a copy of most of the
652 parent thread structure's run control related fields, not just these.
653 Initialized to avoid "may be used uninitialized" warnings from gcc. */
654 struct breakpoint
*step_resume_breakpoint
= NULL
;
655 struct breakpoint
*exception_resume_breakpoint
= NULL
;
656 CORE_ADDR step_range_start
= 0;
657 CORE_ADDR step_range_end
= 0;
658 struct frame_id step_frame_id
= { 0 };
659 struct interp
*command_interp
= NULL
;
664 struct target_waitstatus wait_status
;
666 /* Get the last target status returned by target_wait(). */
667 get_last_target_status (&wait_ptid
, &wait_status
);
669 /* If not stopped at a fork event, then there's nothing else to
671 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
672 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
675 /* Check if we switched over from WAIT_PTID, since the event was
677 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
678 && !ptid_equal (inferior_ptid
, wait_ptid
))
680 /* We did. Switch back to WAIT_PTID thread, to tell the
681 target to follow it (in either direction). We'll
682 afterwards refuse to resume, and inform the user what
684 switch_to_thread (wait_ptid
);
689 tp
= inferior_thread ();
691 /* If there were any forks/vforks that were caught and are now to be
692 followed, then do so now. */
693 switch (tp
->pending_follow
.kind
)
695 case TARGET_WAITKIND_FORKED
:
696 case TARGET_WAITKIND_VFORKED
:
698 ptid_t parent
, child
;
700 /* If the user did a next/step, etc, over a fork call,
701 preserve the stepping state in the fork child. */
702 if (follow_child
&& should_resume
)
704 step_resume_breakpoint
= clone_momentary_breakpoint
705 (tp
->control
.step_resume_breakpoint
);
706 step_range_start
= tp
->control
.step_range_start
;
707 step_range_end
= tp
->control
.step_range_end
;
708 step_frame_id
= tp
->control
.step_frame_id
;
709 exception_resume_breakpoint
710 = clone_momentary_breakpoint (tp
->control
.exception_resume_breakpoint
);
711 command_interp
= tp
->control
.command_interp
;
713 /* For now, delete the parent's sr breakpoint, otherwise,
714 parent/child sr breakpoints are considered duplicates,
715 and the child version will not be installed. Remove
716 this when the breakpoints module becomes aware of
717 inferiors and address spaces. */
718 delete_step_resume_breakpoint (tp
);
719 tp
->control
.step_range_start
= 0;
720 tp
->control
.step_range_end
= 0;
721 tp
->control
.step_frame_id
= null_frame_id
;
722 delete_exception_resume_breakpoint (tp
);
723 tp
->control
.command_interp
= NULL
;
726 parent
= inferior_ptid
;
727 child
= tp
->pending_follow
.value
.related_pid
;
729 /* Set up inferior(s) as specified by the caller, and tell the
730 target to do whatever is necessary to follow either parent
732 if (follow_fork_inferior (follow_child
, detach_fork
))
734 /* Target refused to follow, or there's some other reason
735 we shouldn't resume. */
740 /* This pending follow fork event is now handled, one way
741 or another. The previous selected thread may be gone
742 from the lists by now, but if it is still around, need
743 to clear the pending follow request. */
744 tp
= find_thread_ptid (parent
);
746 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
748 /* This makes sure we don't try to apply the "Switched
749 over from WAIT_PID" logic above. */
750 nullify_last_target_wait_ptid ();
752 /* If we followed the child, switch to it... */
755 switch_to_thread (child
);
757 /* ... and preserve the stepping state, in case the
758 user was stepping over the fork call. */
761 tp
= inferior_thread ();
762 tp
->control
.step_resume_breakpoint
763 = step_resume_breakpoint
;
764 tp
->control
.step_range_start
= step_range_start
;
765 tp
->control
.step_range_end
= step_range_end
;
766 tp
->control
.step_frame_id
= step_frame_id
;
767 tp
->control
.exception_resume_breakpoint
768 = exception_resume_breakpoint
;
769 tp
->control
.command_interp
= command_interp
;
773 /* If we get here, it was because we're trying to
774 resume from a fork catchpoint, but, the user
775 has switched threads away from the thread that
776 forked. In that case, the resume command
777 issued is most likely not applicable to the
778 child, so just warn, and refuse to resume. */
779 warning (_("Not resuming: switched threads "
780 "before following fork child.\n"));
783 /* Reset breakpoints in the child as appropriate. */
784 follow_inferior_reset_breakpoints ();
787 switch_to_thread (parent
);
791 case TARGET_WAITKIND_SPURIOUS
:
792 /* Nothing to follow. */
795 internal_error (__FILE__
, __LINE__
,
796 "Unexpected pending_follow.kind %d\n",
797 tp
->pending_follow
.kind
);
801 return should_resume
;
805 follow_inferior_reset_breakpoints (void)
807 struct thread_info
*tp
= inferior_thread ();
809 /* Was there a step_resume breakpoint? (There was if the user
810 did a "next" at the fork() call.) If so, explicitly reset its
811 thread number. Cloned step_resume breakpoints are disabled on
812 creation, so enable it here now that it is associated with the
815 step_resumes are a form of bp that are made to be per-thread.
816 Since we created the step_resume bp when the parent process
817 was being debugged, and now are switching to the child process,
818 from the breakpoint package's viewpoint, that's a switch of
819 "threads". We must update the bp's notion of which thread
820 it is for, or it'll be ignored when it triggers. */
822 if (tp
->control
.step_resume_breakpoint
)
824 breakpoint_re_set_thread (tp
->control
.step_resume_breakpoint
);
825 tp
->control
.step_resume_breakpoint
->loc
->enabled
= 1;
828 /* Treat exception_resume breakpoints like step_resume breakpoints. */
829 if (tp
->control
.exception_resume_breakpoint
)
831 breakpoint_re_set_thread (tp
->control
.exception_resume_breakpoint
);
832 tp
->control
.exception_resume_breakpoint
->loc
->enabled
= 1;
835 /* Reinsert all breakpoints in the child. The user may have set
836 breakpoints after catching the fork, in which case those
837 were never set in the child, but only in the parent. This makes
838 sure the inserted breakpoints match the breakpoint list. */
840 breakpoint_re_set ();
841 insert_breakpoints ();
844 /* The child has exited or execed: resume threads of the parent the
845 user wanted to be executing. */
848 proceed_after_vfork_done (struct thread_info
*thread
,
851 int pid
= * (int *) arg
;
853 if (ptid_get_pid (thread
->ptid
) == pid
854 && is_running (thread
->ptid
)
855 && !is_executing (thread
->ptid
)
856 && !thread
->stop_requested
857 && thread
->suspend
.stop_signal
== GDB_SIGNAL_0
)
860 fprintf_unfiltered (gdb_stdlog
,
861 "infrun: resuming vfork parent thread %s\n",
862 target_pid_to_str (thread
->ptid
));
864 switch_to_thread (thread
->ptid
);
865 clear_proceed_status (0);
866 proceed ((CORE_ADDR
) -1, GDB_SIGNAL_DEFAULT
, 0);
872 /* Called whenever we notice an exec or exit event, to handle
873 detaching or resuming a vfork parent. */
876 handle_vfork_child_exec_or_exit (int exec
)
878 struct inferior
*inf
= current_inferior ();
880 if (inf
->vfork_parent
)
882 int resume_parent
= -1;
884 /* This exec or exit marks the end of the shared memory region
885 between the parent and the child. If the user wanted to
886 detach from the parent, now is the time. */
888 if (inf
->vfork_parent
->pending_detach
)
890 struct thread_info
*tp
;
891 struct cleanup
*old_chain
;
892 struct program_space
*pspace
;
893 struct address_space
*aspace
;
895 /* follow-fork child, detach-on-fork on. */
897 inf
->vfork_parent
->pending_detach
= 0;
901 /* If we're handling a child exit, then inferior_ptid
902 points at the inferior's pid, not to a thread. */
903 old_chain
= save_inferior_ptid ();
904 save_current_program_space ();
905 save_current_inferior ();
908 old_chain
= save_current_space_and_thread ();
910 /* We're letting loose of the parent. */
911 tp
= any_live_thread_of_process (inf
->vfork_parent
->pid
);
912 switch_to_thread (tp
->ptid
);
914 /* We're about to detach from the parent, which implicitly
915 removes breakpoints from its address space. There's a
916 catch here: we want to reuse the spaces for the child,
917 but, parent/child are still sharing the pspace at this
918 point, although the exec in reality makes the kernel give
919 the child a fresh set of new pages. The problem here is
920 that the breakpoints module being unaware of this, would
921 likely chose the child process to write to the parent
922 address space. Swapping the child temporarily away from
923 the spaces has the desired effect. Yes, this is "sort
926 pspace
= inf
->pspace
;
927 aspace
= inf
->aspace
;
931 if (debug_infrun
|| info_verbose
)
933 target_terminal_ours ();
936 fprintf_filtered (gdb_stdlog
,
937 "Detaching vfork parent process "
938 "%d after child exec.\n",
939 inf
->vfork_parent
->pid
);
941 fprintf_filtered (gdb_stdlog
,
942 "Detaching vfork parent process "
943 "%d after child exit.\n",
944 inf
->vfork_parent
->pid
);
947 target_detach (NULL
, 0);
950 inf
->pspace
= pspace
;
951 inf
->aspace
= aspace
;
953 do_cleanups (old_chain
);
957 /* We're staying attached to the parent, so, really give the
958 child a new address space. */
959 inf
->pspace
= add_program_space (maybe_new_address_space ());
960 inf
->aspace
= inf
->pspace
->aspace
;
962 set_current_program_space (inf
->pspace
);
964 resume_parent
= inf
->vfork_parent
->pid
;
966 /* Break the bonds. */
967 inf
->vfork_parent
->vfork_child
= NULL
;
971 struct cleanup
*old_chain
;
972 struct program_space
*pspace
;
974 /* If this is a vfork child exiting, then the pspace and
975 aspaces were shared with the parent. Since we're
976 reporting the process exit, we'll be mourning all that is
977 found in the address space, and switching to null_ptid,
978 preparing to start a new inferior. But, since we don't
979 want to clobber the parent's address/program spaces, we
980 go ahead and create a new one for this exiting
983 /* Switch to null_ptid, so that clone_program_space doesn't want
984 to read the selected frame of a dead process. */
985 old_chain
= save_inferior_ptid ();
986 inferior_ptid
= null_ptid
;
988 /* This inferior is dead, so avoid giving the breakpoints
989 module the option to write through to it (cloning a
990 program space resets breakpoints). */
993 pspace
= add_program_space (maybe_new_address_space ());
994 set_current_program_space (pspace
);
996 inf
->symfile_flags
= SYMFILE_NO_READ
;
997 clone_program_space (pspace
, inf
->vfork_parent
->pspace
);
998 inf
->pspace
= pspace
;
999 inf
->aspace
= pspace
->aspace
;
1001 /* Put back inferior_ptid. We'll continue mourning this
1003 do_cleanups (old_chain
);
1005 resume_parent
= inf
->vfork_parent
->pid
;
1006 /* Break the bonds. */
1007 inf
->vfork_parent
->vfork_child
= NULL
;
1010 inf
->vfork_parent
= NULL
;
1012 gdb_assert (current_program_space
== inf
->pspace
);
1014 if (non_stop
&& resume_parent
!= -1)
1016 /* If the user wanted the parent to be running, let it go
1018 struct cleanup
*old_chain
= make_cleanup_restore_current_thread ();
1021 fprintf_unfiltered (gdb_stdlog
,
1022 "infrun: resuming vfork parent process %d\n",
1025 iterate_over_threads (proceed_after_vfork_done
, &resume_parent
);
1027 do_cleanups (old_chain
);
1032 /* Enum strings for "set|show follow-exec-mode". */
1034 static const char follow_exec_mode_new
[] = "new";
1035 static const char follow_exec_mode_same
[] = "same";
1036 static const char *const follow_exec_mode_names
[] =
1038 follow_exec_mode_new
,
1039 follow_exec_mode_same
,
1043 static const char *follow_exec_mode_string
= follow_exec_mode_same
;
1045 show_follow_exec_mode_string (struct ui_file
*file
, int from_tty
,
1046 struct cmd_list_element
*c
, const char *value
)
1048 fprintf_filtered (file
, _("Follow exec mode is \"%s\".\n"), value
);
1051 /* EXECD_PATHNAME is assumed to be non-NULL. */
1054 follow_exec (ptid_t pid
, char *execd_pathname
)
1056 struct thread_info
*th
= inferior_thread ();
1057 struct inferior
*inf
= current_inferior ();
1059 /* This is an exec event that we actually wish to pay attention to.
1060 Refresh our symbol table to the newly exec'd program, remove any
1061 momentary bp's, etc.
1063 If there are breakpoints, they aren't really inserted now,
1064 since the exec() transformed our inferior into a fresh set
1067 We want to preserve symbolic breakpoints on the list, since
1068 we have hopes that they can be reset after the new a.out's
1069 symbol table is read.
1071 However, any "raw" breakpoints must be removed from the list
1072 (e.g., the solib bp's), since their address is probably invalid
1075 And, we DON'T want to call delete_breakpoints() here, since
1076 that may write the bp's "shadow contents" (the instruction
1077 value that was overwritten witha TRAP instruction). Since
1078 we now have a new a.out, those shadow contents aren't valid. */
1080 mark_breakpoints_out ();
1082 update_breakpoints_after_exec ();
1084 /* If there was one, it's gone now. We cannot truly step-to-next
1085 statement through an exec(). */
1086 th
->control
.step_resume_breakpoint
= NULL
;
1087 th
->control
.exception_resume_breakpoint
= NULL
;
1088 th
->control
.step_range_start
= 0;
1089 th
->control
.step_range_end
= 0;
1091 /* The target reports the exec event to the main thread, even if
1092 some other thread does the exec, and even if the main thread was
1093 already stopped --- if debugging in non-stop mode, it's possible
1094 the user had the main thread held stopped in the previous image
1095 --- release it now. This is the same behavior as step-over-exec
1096 with scheduler-locking on in all-stop mode. */
1097 th
->stop_requested
= 0;
1099 /* What is this a.out's name? */
1100 printf_unfiltered (_("%s is executing new program: %s\n"),
1101 target_pid_to_str (inferior_ptid
),
1104 /* We've followed the inferior through an exec. Therefore, the
1105 inferior has essentially been killed & reborn. */
1107 gdb_flush (gdb_stdout
);
1109 breakpoint_init_inferior (inf_execd
);
1111 if (gdb_sysroot
&& *gdb_sysroot
)
1113 char *name
= alloca (strlen (gdb_sysroot
)
1114 + strlen (execd_pathname
)
1117 strcpy (name
, gdb_sysroot
);
1118 strcat (name
, execd_pathname
);
1119 execd_pathname
= name
;
1122 /* Reset the shared library package. This ensures that we get a
1123 shlib event when the child reaches "_start", at which point the
1124 dld will have had a chance to initialize the child. */
1125 /* Also, loading a symbol file below may trigger symbol lookups, and
1126 we don't want those to be satisfied by the libraries of the
1127 previous incarnation of this process. */
1128 no_shared_libraries (NULL
, 0);
1130 if (follow_exec_mode_string
== follow_exec_mode_new
)
1132 struct program_space
*pspace
;
1134 /* The user wants to keep the old inferior and program spaces
1135 around. Create a new fresh one, and switch to it. */
1137 inf
= add_inferior (current_inferior ()->pid
);
1138 pspace
= add_program_space (maybe_new_address_space ());
1139 inf
->pspace
= pspace
;
1140 inf
->aspace
= pspace
->aspace
;
1142 exit_inferior_num_silent (current_inferior ()->num
);
1144 set_current_inferior (inf
);
1145 set_current_program_space (pspace
);
1149 /* The old description may no longer be fit for the new image.
1150 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1151 old description; we'll read a new one below. No need to do
1152 this on "follow-exec-mode new", as the old inferior stays
1153 around (its description is later cleared/refetched on
1155 target_clear_description ();
1158 gdb_assert (current_program_space
== inf
->pspace
);
1160 /* That a.out is now the one to use. */
1161 exec_file_attach (execd_pathname
, 0);
1163 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
1164 (Position Independent Executable) main symbol file will get applied by
1165 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
1166 the breakpoints with the zero displacement. */
1168 symbol_file_add (execd_pathname
,
1170 | SYMFILE_MAINLINE
| SYMFILE_DEFER_BP_RESET
),
1173 if ((inf
->symfile_flags
& SYMFILE_NO_READ
) == 0)
1174 set_initial_language ();
1176 /* If the target can specify a description, read it. Must do this
1177 after flipping to the new executable (because the target supplied
1178 description must be compatible with the executable's
1179 architecture, and the old executable may e.g., be 32-bit, while
1180 the new one 64-bit), and before anything involving memory or
1182 target_find_description ();
1184 solib_create_inferior_hook (0);
1186 jit_inferior_created_hook ();
1188 breakpoint_re_set ();
1190 /* Reinsert all breakpoints. (Those which were symbolic have
1191 been reset to the proper address in the new a.out, thanks
1192 to symbol_file_command...). */
1193 insert_breakpoints ();
1195 /* The next resume of this inferior should bring it to the shlib
1196 startup breakpoints. (If the user had also set bp's on
1197 "main" from the old (parent) process, then they'll auto-
1198 matically get reset there in the new process.). */
1201 /* Non-zero if we just simulating a single-step. This is needed
1202 because we cannot remove the breakpoints in the inferior process
1203 until after the `wait' in `wait_for_inferior'. */
1204 static int singlestep_breakpoints_inserted_p
= 0;
1206 /* The thread we inserted single-step breakpoints for. */
1207 static ptid_t singlestep_ptid
;
1209 /* PC when we started this single-step. */
1210 static CORE_ADDR singlestep_pc
;
1212 /* Info about an instruction that is being stepped over. Invalid if
1215 struct step_over_info
1217 /* The instruction's address space. */
1218 struct address_space
*aspace
;
1220 /* The instruction's address. */
1224 /* The step-over info of the location that is being stepped over.
1226 Note that with async/breakpoint always-inserted mode, a user might
1227 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1228 being stepped over. As setting a new breakpoint inserts all
1229 breakpoints, we need to make sure the breakpoint being stepped over
1230 isn't inserted then. We do that by only clearing the step-over
1231 info when the step-over is actually finished (or aborted).
1233 Presently GDB can only step over one breakpoint at any given time.
1234 Given threads that can't run code in the same address space as the
1235 breakpoint's can't really miss the breakpoint, GDB could be taught
1236 to step-over at most one breakpoint per address space (so this info
1237 could move to the address space object if/when GDB is extended).
1238 The set of breakpoints being stepped over will normally be much
1239 smaller than the set of all breakpoints, so a flag in the
1240 breakpoint location structure would be wasteful. A separate list
1241 also saves complexity and run-time, as otherwise we'd have to go
1242 through all breakpoint locations clearing their flag whenever we
1243 start a new sequence. Similar considerations weigh against storing
1244 this info in the thread object. Plus, not all step overs actually
1245 have breakpoint locations -- e.g., stepping past a single-step
1246 breakpoint, or stepping to complete a non-continuable
1248 static struct step_over_info step_over_info
;
1250 /* Record the address of the breakpoint/instruction we're currently
1254 set_step_over_info (struct address_space
*aspace
, CORE_ADDR address
)
1256 step_over_info
.aspace
= aspace
;
1257 step_over_info
.address
= address
;
1260 /* Called when we're not longer stepping over a breakpoint / an
1261 instruction, so all breakpoints are free to be (re)inserted. */
1264 clear_step_over_info (void)
1266 step_over_info
.aspace
= NULL
;
1267 step_over_info
.address
= 0;
1273 stepping_past_instruction_at (struct address_space
*aspace
,
1276 return (step_over_info
.aspace
!= NULL
1277 && breakpoint_address_match (aspace
, address
,
1278 step_over_info
.aspace
,
1279 step_over_info
.address
));
1283 /* Displaced stepping. */
1285 /* In non-stop debugging mode, we must take special care to manage
1286 breakpoints properly; in particular, the traditional strategy for
1287 stepping a thread past a breakpoint it has hit is unsuitable.
1288 'Displaced stepping' is a tactic for stepping one thread past a
1289 breakpoint it has hit while ensuring that other threads running
1290 concurrently will hit the breakpoint as they should.
1292 The traditional way to step a thread T off a breakpoint in a
1293 multi-threaded program in all-stop mode is as follows:
1295 a0) Initially, all threads are stopped, and breakpoints are not
1297 a1) We single-step T, leaving breakpoints uninserted.
1298 a2) We insert breakpoints, and resume all threads.
1300 In non-stop debugging, however, this strategy is unsuitable: we
1301 don't want to have to stop all threads in the system in order to
1302 continue or step T past a breakpoint. Instead, we use displaced
1305 n0) Initially, T is stopped, other threads are running, and
1306 breakpoints are inserted.
1307 n1) We copy the instruction "under" the breakpoint to a separate
1308 location, outside the main code stream, making any adjustments
1309 to the instruction, register, and memory state as directed by
1311 n2) We single-step T over the instruction at its new location.
1312 n3) We adjust the resulting register and memory state as directed
1313 by T's architecture. This includes resetting T's PC to point
1314 back into the main instruction stream.
1317 This approach depends on the following gdbarch methods:
1319 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1320 indicate where to copy the instruction, and how much space must
1321 be reserved there. We use these in step n1.
1323 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1324 address, and makes any necessary adjustments to the instruction,
1325 register contents, and memory. We use this in step n1.
1327 - gdbarch_displaced_step_fixup adjusts registers and memory after
1328 we have successfuly single-stepped the instruction, to yield the
1329 same effect the instruction would have had if we had executed it
1330 at its original address. We use this in step n3.
1332 - gdbarch_displaced_step_free_closure provides cleanup.
1334 The gdbarch_displaced_step_copy_insn and
1335 gdbarch_displaced_step_fixup functions must be written so that
1336 copying an instruction with gdbarch_displaced_step_copy_insn,
1337 single-stepping across the copied instruction, and then applying
1338 gdbarch_displaced_insn_fixup should have the same effects on the
1339 thread's memory and registers as stepping the instruction in place
1340 would have. Exactly which responsibilities fall to the copy and
1341 which fall to the fixup is up to the author of those functions.
1343 See the comments in gdbarch.sh for details.
1345 Note that displaced stepping and software single-step cannot
1346 currently be used in combination, although with some care I think
1347 they could be made to. Software single-step works by placing
1348 breakpoints on all possible subsequent instructions; if the
1349 displaced instruction is a PC-relative jump, those breakpoints
1350 could fall in very strange places --- on pages that aren't
1351 executable, or at addresses that are not proper instruction
1352 boundaries. (We do generally let other threads run while we wait
1353 to hit the software single-step breakpoint, and they might
1354 encounter such a corrupted instruction.) One way to work around
1355 this would be to have gdbarch_displaced_step_copy_insn fully
1356 simulate the effect of PC-relative instructions (and return NULL)
1357 on architectures that use software single-stepping.
1359 In non-stop mode, we can have independent and simultaneous step
1360 requests, so more than one thread may need to simultaneously step
1361 over a breakpoint. The current implementation assumes there is
1362 only one scratch space per process. In this case, we have to
1363 serialize access to the scratch space. If thread A wants to step
1364 over a breakpoint, but we are currently waiting for some other
1365 thread to complete a displaced step, we leave thread A stopped and
1366 place it in the displaced_step_request_queue. Whenever a displaced
1367 step finishes, we pick the next thread in the queue and start a new
1368 displaced step operation on it. See displaced_step_prepare and
1369 displaced_step_fixup for details. */
1371 struct displaced_step_request
1374 struct displaced_step_request
*next
;
1377 /* Per-inferior displaced stepping state. */
1378 struct displaced_step_inferior_state
1380 /* Pointer to next in linked list. */
1381 struct displaced_step_inferior_state
*next
;
1383 /* The process this displaced step state refers to. */
1386 /* A queue of pending displaced stepping requests. One entry per
1387 thread that needs to do a displaced step. */
1388 struct displaced_step_request
*step_request_queue
;
1390 /* If this is not null_ptid, this is the thread carrying out a
1391 displaced single-step in process PID. This thread's state will
1392 require fixing up once it has completed its step. */
1395 /* The architecture the thread had when we stepped it. */
1396 struct gdbarch
*step_gdbarch
;
1398 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1399 for post-step cleanup. */
1400 struct displaced_step_closure
*step_closure
;
1402 /* The address of the original instruction, and the copy we
1404 CORE_ADDR step_original
, step_copy
;
1406 /* Saved contents of copy area. */
1407 gdb_byte
*step_saved_copy
;
1410 /* The list of states of processes involved in displaced stepping
1412 static struct displaced_step_inferior_state
*displaced_step_inferior_states
;
1414 /* Get the displaced stepping state of process PID. */
1416 static struct displaced_step_inferior_state
*
1417 get_displaced_stepping_state (int pid
)
1419 struct displaced_step_inferior_state
*state
;
1421 for (state
= displaced_step_inferior_states
;
1423 state
= state
->next
)
1424 if (state
->pid
== pid
)
1430 /* Add a new displaced stepping state for process PID to the displaced
1431 stepping state list, or return a pointer to an already existing
1432 entry, if it already exists. Never returns NULL. */
1434 static struct displaced_step_inferior_state
*
1435 add_displaced_stepping_state (int pid
)
1437 struct displaced_step_inferior_state
*state
;
1439 for (state
= displaced_step_inferior_states
;
1441 state
= state
->next
)
1442 if (state
->pid
== pid
)
1445 state
= xcalloc (1, sizeof (*state
));
1447 state
->next
= displaced_step_inferior_states
;
1448 displaced_step_inferior_states
= state
;
1453 /* If inferior is in displaced stepping, and ADDR equals to starting address
1454 of copy area, return corresponding displaced_step_closure. Otherwise,
1457 struct displaced_step_closure
*
1458 get_displaced_step_closure_by_addr (CORE_ADDR addr
)
1460 struct displaced_step_inferior_state
*displaced
1461 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
1463 /* If checking the mode of displaced instruction in copy area. */
1464 if (displaced
&& !ptid_equal (displaced
->step_ptid
, null_ptid
)
1465 && (displaced
->step_copy
== addr
))
1466 return displaced
->step_closure
;
1471 /* Remove the displaced stepping state of process PID. */
1474 remove_displaced_stepping_state (int pid
)
1476 struct displaced_step_inferior_state
*it
, **prev_next_p
;
1478 gdb_assert (pid
!= 0);
1480 it
= displaced_step_inferior_states
;
1481 prev_next_p
= &displaced_step_inferior_states
;
1486 *prev_next_p
= it
->next
;
1491 prev_next_p
= &it
->next
;
1497 infrun_inferior_exit (struct inferior
*inf
)
1499 remove_displaced_stepping_state (inf
->pid
);
1502 /* If ON, and the architecture supports it, GDB will use displaced
1503 stepping to step over breakpoints. If OFF, or if the architecture
1504 doesn't support it, GDB will instead use the traditional
1505 hold-and-step approach. If AUTO (which is the default), GDB will
1506 decide which technique to use to step over breakpoints depending on
1507 which of all-stop or non-stop mode is active --- displaced stepping
1508 in non-stop mode; hold-and-step in all-stop mode. */
1510 static enum auto_boolean can_use_displaced_stepping
= AUTO_BOOLEAN_AUTO
;
1513 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
1514 struct cmd_list_element
*c
,
1517 if (can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
)
1518 fprintf_filtered (file
,
1519 _("Debugger's willingness to use displaced stepping "
1520 "to step over breakpoints is %s (currently %s).\n"),
1521 value
, non_stop
? "on" : "off");
1523 fprintf_filtered (file
,
1524 _("Debugger's willingness to use displaced stepping "
1525 "to step over breakpoints is %s.\n"), value
);
1528 /* Return non-zero if displaced stepping can/should be used to step
1529 over breakpoints. */
1532 use_displaced_stepping (struct gdbarch
*gdbarch
)
1534 return (((can_use_displaced_stepping
== AUTO_BOOLEAN_AUTO
&& non_stop
)
1535 || can_use_displaced_stepping
== AUTO_BOOLEAN_TRUE
)
1536 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
1537 && find_record_target () == NULL
);
1540 /* Clean out any stray displaced stepping state. */
1542 displaced_step_clear (struct displaced_step_inferior_state
*displaced
)
1544 /* Indicate that there is no cleanup pending. */
1545 displaced
->step_ptid
= null_ptid
;
1547 if (displaced
->step_closure
)
1549 gdbarch_displaced_step_free_closure (displaced
->step_gdbarch
,
1550 displaced
->step_closure
);
1551 displaced
->step_closure
= NULL
;
1556 displaced_step_clear_cleanup (void *arg
)
1558 struct displaced_step_inferior_state
*state
= arg
;
1560 displaced_step_clear (state
);
1563 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1565 displaced_step_dump_bytes (struct ui_file
*file
,
1566 const gdb_byte
*buf
,
1571 for (i
= 0; i
< len
; i
++)
1572 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
1573 fputs_unfiltered ("\n", file
);
1576 /* Prepare to single-step, using displaced stepping.
1578 Note that we cannot use displaced stepping when we have a signal to
1579 deliver. If we have a signal to deliver and an instruction to step
1580 over, then after the step, there will be no indication from the
1581 target whether the thread entered a signal handler or ignored the
1582 signal and stepped over the instruction successfully --- both cases
1583 result in a simple SIGTRAP. In the first case we mustn't do a
1584 fixup, and in the second case we must --- but we can't tell which.
1585 Comments in the code for 'random signals' in handle_inferior_event
1586 explain how we handle this case instead.
1588 Returns 1 if preparing was successful -- this thread is going to be
1589 stepped now; or 0 if displaced stepping this thread got queued. */
1591 displaced_step_prepare (ptid_t ptid
)
1593 struct cleanup
*old_cleanups
, *ignore_cleanups
;
1594 struct thread_info
*tp
= find_thread_ptid (ptid
);
1595 struct regcache
*regcache
= get_thread_regcache (ptid
);
1596 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1597 CORE_ADDR original
, copy
;
1599 struct displaced_step_closure
*closure
;
1600 struct displaced_step_inferior_state
*displaced
;
1603 /* We should never reach this function if the architecture does not
1604 support displaced stepping. */
1605 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
1607 /* Disable range stepping while executing in the scratch pad. We
1608 want a single-step even if executing the displaced instruction in
1609 the scratch buffer lands within the stepping range (e.g., a
1611 tp
->control
.may_range_step
= 0;
1613 /* We have to displaced step one thread at a time, as we only have
1614 access to a single scratch space per inferior. */
1616 displaced
= add_displaced_stepping_state (ptid_get_pid (ptid
));
1618 if (!ptid_equal (displaced
->step_ptid
, null_ptid
))
1620 /* Already waiting for a displaced step to finish. Defer this
1621 request and place in queue. */
1622 struct displaced_step_request
*req
, *new_req
;
1624 if (debug_displaced
)
1625 fprintf_unfiltered (gdb_stdlog
,
1626 "displaced: defering step of %s\n",
1627 target_pid_to_str (ptid
));
1629 new_req
= xmalloc (sizeof (*new_req
));
1630 new_req
->ptid
= ptid
;
1631 new_req
->next
= NULL
;
1633 if (displaced
->step_request_queue
)
1635 for (req
= displaced
->step_request_queue
;
1639 req
->next
= new_req
;
1642 displaced
->step_request_queue
= new_req
;
1648 if (debug_displaced
)
1649 fprintf_unfiltered (gdb_stdlog
,
1650 "displaced: stepping %s now\n",
1651 target_pid_to_str (ptid
));
1654 displaced_step_clear (displaced
);
1656 old_cleanups
= save_inferior_ptid ();
1657 inferior_ptid
= ptid
;
1659 original
= regcache_read_pc (regcache
);
1661 copy
= gdbarch_displaced_step_location (gdbarch
);
1662 len
= gdbarch_max_insn_length (gdbarch
);
1664 /* Save the original contents of the copy area. */
1665 displaced
->step_saved_copy
= xmalloc (len
);
1666 ignore_cleanups
= make_cleanup (free_current_contents
,
1667 &displaced
->step_saved_copy
);
1668 status
= target_read_memory (copy
, displaced
->step_saved_copy
, len
);
1670 throw_error (MEMORY_ERROR
,
1671 _("Error accessing memory address %s (%s) for "
1672 "displaced-stepping scratch space."),
1673 paddress (gdbarch
, copy
), safe_strerror (status
));
1674 if (debug_displaced
)
1676 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
1677 paddress (gdbarch
, copy
));
1678 displaced_step_dump_bytes (gdb_stdlog
,
1679 displaced
->step_saved_copy
,
1683 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
1684 original
, copy
, regcache
);
1686 /* We don't support the fully-simulated case at present. */
1687 gdb_assert (closure
);
1689 /* Save the information we need to fix things up if the step
1691 displaced
->step_ptid
= ptid
;
1692 displaced
->step_gdbarch
= gdbarch
;
1693 displaced
->step_closure
= closure
;
1694 displaced
->step_original
= original
;
1695 displaced
->step_copy
= copy
;
1697 make_cleanup (displaced_step_clear_cleanup
, displaced
);
1699 /* Resume execution at the copy. */
1700 regcache_write_pc (regcache
, copy
);
1702 discard_cleanups (ignore_cleanups
);
1704 do_cleanups (old_cleanups
);
1706 if (debug_displaced
)
1707 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
1708 paddress (gdbarch
, copy
));
1714 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
,
1715 const gdb_byte
*myaddr
, int len
)
1717 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
1719 inferior_ptid
= ptid
;
1720 write_memory (memaddr
, myaddr
, len
);
1721 do_cleanups (ptid_cleanup
);
1724 /* Restore the contents of the copy area for thread PTID. */
1727 displaced_step_restore (struct displaced_step_inferior_state
*displaced
,
1730 ULONGEST len
= gdbarch_max_insn_length (displaced
->step_gdbarch
);
1732 write_memory_ptid (ptid
, displaced
->step_copy
,
1733 displaced
->step_saved_copy
, len
);
1734 if (debug_displaced
)
1735 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s %s\n",
1736 target_pid_to_str (ptid
),
1737 paddress (displaced
->step_gdbarch
,
1738 displaced
->step_copy
));
1742 displaced_step_fixup (ptid_t event_ptid
, enum gdb_signal signal
)
1744 struct cleanup
*old_cleanups
;
1745 struct displaced_step_inferior_state
*displaced
1746 = get_displaced_stepping_state (ptid_get_pid (event_ptid
));
1748 /* Was any thread of this process doing a displaced step? */
1749 if (displaced
== NULL
)
1752 /* Was this event for the pid we displaced? */
1753 if (ptid_equal (displaced
->step_ptid
, null_ptid
)
1754 || ! ptid_equal (displaced
->step_ptid
, event_ptid
))
1757 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, displaced
);
1759 displaced_step_restore (displaced
, displaced
->step_ptid
);
1761 /* Did the instruction complete successfully? */
1762 if (signal
== GDB_SIGNAL_TRAP
)
1764 /* Fix up the resulting state. */
1765 gdbarch_displaced_step_fixup (displaced
->step_gdbarch
,
1766 displaced
->step_closure
,
1767 displaced
->step_original
,
1768 displaced
->step_copy
,
1769 get_thread_regcache (displaced
->step_ptid
));
1773 /* Since the instruction didn't complete, all we can do is
1775 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
1776 CORE_ADDR pc
= regcache_read_pc (regcache
);
1778 pc
= displaced
->step_original
+ (pc
- displaced
->step_copy
);
1779 regcache_write_pc (regcache
, pc
);
1782 do_cleanups (old_cleanups
);
1784 displaced
->step_ptid
= null_ptid
;
1786 /* Are there any pending displaced stepping requests? If so, run
1787 one now. Leave the state object around, since we're likely to
1788 need it again soon. */
1789 while (displaced
->step_request_queue
)
1791 struct displaced_step_request
*head
;
1793 struct regcache
*regcache
;
1794 struct gdbarch
*gdbarch
;
1795 CORE_ADDR actual_pc
;
1796 struct address_space
*aspace
;
1798 head
= displaced
->step_request_queue
;
1800 displaced
->step_request_queue
= head
->next
;
1803 context_switch (ptid
);
1805 regcache
= get_thread_regcache (ptid
);
1806 actual_pc
= regcache_read_pc (regcache
);
1807 aspace
= get_regcache_aspace (regcache
);
1809 if (breakpoint_here_p (aspace
, actual_pc
))
1811 if (debug_displaced
)
1812 fprintf_unfiltered (gdb_stdlog
,
1813 "displaced: stepping queued %s now\n",
1814 target_pid_to_str (ptid
));
1816 displaced_step_prepare (ptid
);
1818 gdbarch
= get_regcache_arch (regcache
);
1820 if (debug_displaced
)
1822 CORE_ADDR actual_pc
= regcache_read_pc (regcache
);
1825 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1826 paddress (gdbarch
, actual_pc
));
1827 read_memory (actual_pc
, buf
, sizeof (buf
));
1828 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1831 if (gdbarch_displaced_step_hw_singlestep (gdbarch
,
1832 displaced
->step_closure
))
1833 target_resume (ptid
, 1, GDB_SIGNAL_0
);
1835 target_resume (ptid
, 0, GDB_SIGNAL_0
);
1837 /* Done, we're stepping a thread. */
1843 struct thread_info
*tp
= inferior_thread ();
1845 /* The breakpoint we were sitting under has since been
1847 tp
->control
.trap_expected
= 0;
1849 /* Go back to what we were trying to do. */
1850 step
= currently_stepping (tp
);
1852 if (debug_displaced
)
1853 fprintf_unfiltered (gdb_stdlog
,
1854 "displaced: breakpoint is gone: %s, step(%d)\n",
1855 target_pid_to_str (tp
->ptid
), step
);
1857 target_resume (ptid
, step
, GDB_SIGNAL_0
);
1858 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
1860 /* This request was discarded. See if there's any other
1861 thread waiting for its turn. */
1866 /* Update global variables holding ptids to hold NEW_PTID if they were
1867 holding OLD_PTID. */
1869 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1871 struct displaced_step_request
*it
;
1872 struct displaced_step_inferior_state
*displaced
;
1874 if (ptid_equal (inferior_ptid
, old_ptid
))
1875 inferior_ptid
= new_ptid
;
1877 if (ptid_equal (singlestep_ptid
, old_ptid
))
1878 singlestep_ptid
= new_ptid
;
1880 for (displaced
= displaced_step_inferior_states
;
1882 displaced
= displaced
->next
)
1884 if (ptid_equal (displaced
->step_ptid
, old_ptid
))
1885 displaced
->step_ptid
= new_ptid
;
1887 for (it
= displaced
->step_request_queue
; it
; it
= it
->next
)
1888 if (ptid_equal (it
->ptid
, old_ptid
))
1889 it
->ptid
= new_ptid
;
1896 /* Things to clean up if we QUIT out of resume (). */
1898 resume_cleanups (void *ignore
)
1903 static const char schedlock_off
[] = "off";
1904 static const char schedlock_on
[] = "on";
1905 static const char schedlock_step
[] = "step";
1906 static const char *const scheduler_enums
[] = {
1912 static const char *scheduler_mode
= schedlock_off
;
1914 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1915 struct cmd_list_element
*c
, const char *value
)
1917 fprintf_filtered (file
,
1918 _("Mode for locking scheduler "
1919 "during execution is \"%s\".\n"),
1924 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1926 if (!target_can_lock_scheduler
)
1928 scheduler_mode
= schedlock_off
;
1929 error (_("Target '%s' cannot support this command."), target_shortname
);
1933 /* True if execution commands resume all threads of all processes by
1934 default; otherwise, resume only threads of the current inferior
1936 int sched_multi
= 0;
1938 /* Try to setup for software single stepping over the specified location.
1939 Return 1 if target_resume() should use hardware single step.
1941 GDBARCH the current gdbarch.
1942 PC the location to step over. */
1945 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1949 if (execution_direction
== EXEC_FORWARD
1950 && gdbarch_software_single_step_p (gdbarch
)
1951 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1954 /* Do not pull these breakpoints until after a `wait' in
1955 `wait_for_inferior'. */
1956 singlestep_breakpoints_inserted_p
= 1;
1957 singlestep_ptid
= inferior_ptid
;
1964 user_visible_resume_ptid (int step
)
1966 /* By default, resume all threads of all processes. */
1967 ptid_t resume_ptid
= RESUME_ALL
;
1969 /* Maybe resume only all threads of the current process. */
1970 if (!sched_multi
&& target_supports_multi_process ())
1972 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1975 /* Maybe resume a single thread after all. */
1978 /* With non-stop mode on, threads are always handled
1980 resume_ptid
= inferior_ptid
;
1982 else if ((scheduler_mode
== schedlock_on
)
1983 || (scheduler_mode
== schedlock_step
&& step
))
1985 /* User-settable 'scheduler' mode requires solo thread resume. */
1986 resume_ptid
= inferior_ptid
;
1989 /* We may actually resume fewer threads at first, e.g., if a thread
1990 is stopped at a breakpoint that needs stepping-off, but that
1991 should not be visible to the user/frontend, and neither should
1992 the frontend/user be allowed to proceed any of the threads that
1993 happen to be stopped for internal run control handling, if a
1994 previous command wanted them resumed. */
1998 /* Resume the inferior, but allow a QUIT. This is useful if the user
1999 wants to interrupt some lengthy single-stepping operation
2000 (for child processes, the SIGINT goes to the inferior, and so
2001 we get a SIGINT random_signal, but for remote debugging and perhaps
2002 other targets, that's not true).
2004 STEP nonzero if we should step (zero to continue instead).
2005 SIG is the signal to give the inferior (zero for none). */
2007 resume (int step
, enum gdb_signal sig
)
2009 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
2010 struct regcache
*regcache
= get_current_regcache ();
2011 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2012 struct thread_info
*tp
= inferior_thread ();
2013 CORE_ADDR pc
= regcache_read_pc (regcache
);
2014 struct address_space
*aspace
= get_regcache_aspace (regcache
);
2016 /* From here on, this represents the caller's step vs continue
2017 request, while STEP represents what we'll actually request the
2018 target to do. STEP can decay from a step to a continue, if e.g.,
2019 we need to implement single-stepping with breakpoints (software
2020 single-step). When deciding whether "set scheduler-locking step"
2021 applies, it's the callers intention that counts. */
2022 const int entry_step
= step
;
2026 if (current_inferior ()->waiting_for_vfork_done
)
2028 /* Don't try to single-step a vfork parent that is waiting for
2029 the child to get out of the shared memory region (by exec'ing
2030 or exiting). This is particularly important on software
2031 single-step archs, as the child process would trip on the
2032 software single step breakpoint inserted for the parent
2033 process. Since the parent will not actually execute any
2034 instruction until the child is out of the shared region (such
2035 are vfork's semantics), it is safe to simply continue it.
2036 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2037 the parent, and tell it to `keep_going', which automatically
2038 re-sets it stepping. */
2040 fprintf_unfiltered (gdb_stdlog
,
2041 "infrun: resume : clear step\n");
2046 fprintf_unfiltered (gdb_stdlog
,
2047 "infrun: resume (step=%d, signal=%s), "
2048 "trap_expected=%d, current thread [%s] at %s\n",
2049 step
, gdb_signal_to_symbol_string (sig
),
2050 tp
->control
.trap_expected
,
2051 target_pid_to_str (inferior_ptid
),
2052 paddress (gdbarch
, pc
));
2054 /* Normally, by the time we reach `resume', the breakpoints are either
2055 removed or inserted, as appropriate. The exception is if we're sitting
2056 at a permanent breakpoint; we need to step over it, but permanent
2057 breakpoints can't be removed. So we have to test for it here. */
2058 if (breakpoint_here_p (aspace
, pc
) == permanent_breakpoint_here
)
2060 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
2061 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
2064 The program is stopped at a permanent breakpoint, but GDB does not know\n\
2065 how to step past a permanent breakpoint on this architecture. Try using\n\
2066 a command like `return' or `jump' to continue execution."));
2069 /* If we have a breakpoint to step over, make sure to do a single
2070 step only. Same if we have software watchpoints. */
2071 if (tp
->control
.trap_expected
|| bpstat_should_step ())
2072 tp
->control
.may_range_step
= 0;
2074 /* If enabled, step over breakpoints by executing a copy of the
2075 instruction at a different address.
2077 We can't use displaced stepping when we have a signal to deliver;
2078 the comments for displaced_step_prepare explain why. The
2079 comments in the handle_inferior event for dealing with 'random
2080 signals' explain what we do instead.
2082 We can't use displaced stepping when we are waiting for vfork_done
2083 event, displaced stepping breaks the vfork child similarly as single
2084 step software breakpoint. */
2085 if (use_displaced_stepping (gdbarch
)
2086 && (tp
->control
.trap_expected
2087 || (step
&& gdbarch_software_single_step_p (gdbarch
)))
2088 && sig
== GDB_SIGNAL_0
2089 && !current_inferior ()->waiting_for_vfork_done
)
2091 struct displaced_step_inferior_state
*displaced
;
2093 if (!displaced_step_prepare (inferior_ptid
))
2095 /* Got placed in displaced stepping queue. Will be resumed
2096 later when all the currently queued displaced stepping
2097 requests finish. The thread is not executing at this
2098 point, and the call to set_executing will be made later.
2099 But we need to call set_running here, since from the
2100 user/frontend's point of view, threads were set running.
2101 Unless we're calling an inferior function, as in that
2102 case we pretend the inferior doesn't run at all. */
2103 if (!tp
->control
.in_infcall
)
2104 set_running (user_visible_resume_ptid (entry_step
), 1);
2105 discard_cleanups (old_cleanups
);
2109 /* Update pc to reflect the new address from which we will execute
2110 instructions due to displaced stepping. */
2111 pc
= regcache_read_pc (get_thread_regcache (inferior_ptid
));
2113 displaced
= get_displaced_stepping_state (ptid_get_pid (inferior_ptid
));
2114 step
= gdbarch_displaced_step_hw_singlestep (gdbarch
,
2115 displaced
->step_closure
);
2118 /* Do we need to do it the hard way, w/temp breakpoints? */
2120 step
= maybe_software_singlestep (gdbarch
, pc
);
2122 /* Currently, our software single-step implementation leads to different
2123 results than hardware single-stepping in one situation: when stepping
2124 into delivering a signal which has an associated signal handler,
2125 hardware single-step will stop at the first instruction of the handler,
2126 while software single-step will simply skip execution of the handler.
2128 For now, this difference in behavior is accepted since there is no
2129 easy way to actually implement single-stepping into a signal handler
2130 without kernel support.
2132 However, there is one scenario where this difference leads to follow-on
2133 problems: if we're stepping off a breakpoint by removing all breakpoints
2134 and then single-stepping. In this case, the software single-step
2135 behavior means that even if there is a *breakpoint* in the signal
2136 handler, GDB still would not stop.
2138 Fortunately, we can at least fix this particular issue. We detect
2139 here the case where we are about to deliver a signal while software
2140 single-stepping with breakpoints removed. In this situation, we
2141 revert the decisions to remove all breakpoints and insert single-
2142 step breakpoints, and instead we install a step-resume breakpoint
2143 at the current address, deliver the signal without stepping, and
2144 once we arrive back at the step-resume breakpoint, actually step
2145 over the breakpoint we originally wanted to step over. */
2146 if (singlestep_breakpoints_inserted_p
2147 && tp
->control
.trap_expected
&& sig
!= GDB_SIGNAL_0
)
2149 /* If we have nested signals or a pending signal is delivered
2150 immediately after a handler returns, might might already have
2151 a step-resume breakpoint set on the earlier handler. We cannot
2152 set another step-resume breakpoint; just continue on until the
2153 original breakpoint is hit. */
2154 if (tp
->control
.step_resume_breakpoint
== NULL
)
2156 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2157 tp
->step_after_step_resume_breakpoint
= 1;
2160 remove_single_step_breakpoints ();
2161 singlestep_breakpoints_inserted_p
= 0;
2163 clear_step_over_info ();
2164 tp
->control
.trap_expected
= 0;
2166 insert_breakpoints ();
2169 /* If STEP is set, it's a request to use hardware stepping
2170 facilities. But in that case, we should never
2171 use singlestep breakpoint. */
2172 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
2174 /* Decide the set of threads to ask the target to resume. Start
2175 by assuming everything will be resumed, than narrow the set
2176 by applying increasingly restricting conditions. */
2177 resume_ptid
= user_visible_resume_ptid (entry_step
);
2179 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
2180 (e.g., we might need to step over a breakpoint), from the
2181 user/frontend's point of view, all threads in RESUME_PTID are now
2182 running. Unless we're calling an inferior function, as in that
2183 case pretend we inferior doesn't run at all. */
2184 if (!tp
->control
.in_infcall
)
2185 set_running (resume_ptid
, 1);
2187 /* Maybe resume a single thread after all. */
2188 if ((step
|| singlestep_breakpoints_inserted_p
)
2189 && tp
->control
.trap_expected
)
2191 /* We're allowing a thread to run past a breakpoint it has
2192 hit, by single-stepping the thread with the breakpoint
2193 removed. In which case, we need to single-step only this
2194 thread, and keep others stopped, as they can miss this
2195 breakpoint if allowed to run. */
2196 resume_ptid
= inferior_ptid
;
2199 if (gdbarch_cannot_step_breakpoint (gdbarch
))
2201 /* Most targets can step a breakpoint instruction, thus
2202 executing it normally. But if this one cannot, just
2203 continue and we will hit it anyway. */
2204 if (step
&& breakpoint_inserted_here_p (aspace
, pc
))
2209 && use_displaced_stepping (gdbarch
)
2210 && tp
->control
.trap_expected
)
2212 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
2213 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
2214 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
2217 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
2218 paddress (resume_gdbarch
, actual_pc
));
2219 read_memory (actual_pc
, buf
, sizeof (buf
));
2220 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
2223 if (tp
->control
.may_range_step
)
2225 /* If we're resuming a thread with the PC out of the step
2226 range, then we're doing some nested/finer run control
2227 operation, like stepping the thread out of the dynamic
2228 linker or the displaced stepping scratch pad. We
2229 shouldn't have allowed a range step then. */
2230 gdb_assert (pc_in_thread_step_range (pc
, tp
));
2233 /* Install inferior's terminal modes. */
2234 target_terminal_inferior ();
2236 /* Avoid confusing the next resume, if the next stop/resume
2237 happens to apply to another thread. */
2238 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2240 /* Advise target which signals may be handled silently. If we have
2241 removed breakpoints because we are stepping over one (which can
2242 happen only if we are not using displaced stepping), we need to
2243 receive all signals to avoid accidentally skipping a breakpoint
2244 during execution of a signal handler. */
2245 if ((step
|| singlestep_breakpoints_inserted_p
)
2246 && tp
->control
.trap_expected
2247 && !use_displaced_stepping (gdbarch
))
2248 target_pass_signals (0, NULL
);
2250 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
2252 target_resume (resume_ptid
, step
, sig
);
2254 discard_cleanups (old_cleanups
);
2259 /* Clear out all variables saying what to do when inferior is continued.
2260 First do this, then set the ones you want, then call `proceed'. */
2263 clear_proceed_status_thread (struct thread_info
*tp
)
2266 fprintf_unfiltered (gdb_stdlog
,
2267 "infrun: clear_proceed_status_thread (%s)\n",
2268 target_pid_to_str (tp
->ptid
));
2270 /* If this signal should not be seen by program, give it zero.
2271 Used for debugging signals. */
2272 if (!signal_pass_state (tp
->suspend
.stop_signal
))
2273 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
2275 tp
->control
.trap_expected
= 0;
2276 tp
->control
.step_range_start
= 0;
2277 tp
->control
.step_range_end
= 0;
2278 tp
->control
.may_range_step
= 0;
2279 tp
->control
.step_frame_id
= null_frame_id
;
2280 tp
->control
.step_stack_frame_id
= null_frame_id
;
2281 tp
->control
.step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
2282 tp
->stop_requested
= 0;
2284 tp
->control
.stop_step
= 0;
2286 tp
->control
.proceed_to_finish
= 0;
2288 tp
->control
.command_interp
= NULL
;
2290 /* Discard any remaining commands or status from previous stop. */
2291 bpstat_clear (&tp
->control
.stop_bpstat
);
2295 clear_proceed_status (int step
)
2299 struct thread_info
*tp
;
2302 resume_ptid
= user_visible_resume_ptid (step
);
2304 /* In all-stop mode, delete the per-thread status of all threads
2305 we're about to resume, implicitly and explicitly. */
2306 ALL_NON_EXITED_THREADS (tp
)
2308 if (!ptid_match (tp
->ptid
, resume_ptid
))
2310 clear_proceed_status_thread (tp
);
2314 if (!ptid_equal (inferior_ptid
, null_ptid
))
2316 struct inferior
*inferior
;
2320 /* If in non-stop mode, only delete the per-thread status of
2321 the current thread. */
2322 clear_proceed_status_thread (inferior_thread ());
2325 inferior
= current_inferior ();
2326 inferior
->control
.stop_soon
= NO_STOP_QUIETLY
;
2329 stop_after_trap
= 0;
2331 clear_step_over_info ();
2333 observer_notify_about_to_proceed ();
2337 regcache_xfree (stop_registers
);
2338 stop_registers
= NULL
;
2342 /* Returns true if TP is still stopped at a breakpoint that needs
2343 stepping-over in order to make progress. If the breakpoint is gone
2344 meanwhile, we can skip the whole step-over dance. */
2347 thread_still_needs_step_over (struct thread_info
*tp
)
2349 if (tp
->stepping_over_breakpoint
)
2351 struct regcache
*regcache
= get_thread_regcache (tp
->ptid
);
2353 if (breakpoint_here_p (get_regcache_aspace (regcache
),
2354 regcache_read_pc (regcache
)))
2357 tp
->stepping_over_breakpoint
= 0;
2363 /* Returns true if scheduler locking applies. STEP indicates whether
2364 we're about to do a step/next-like command to a thread. */
2367 schedlock_applies (int step
)
2369 return (scheduler_mode
== schedlock_on
2370 || (scheduler_mode
== schedlock_step
2374 /* Look a thread other than EXCEPT that has previously reported a
2375 breakpoint event, and thus needs a step-over in order to make
2376 progress. Returns NULL is none is found. STEP indicates whether
2377 we're about to step the current thread, in order to decide whether
2378 "set scheduler-locking step" applies. */
2380 static struct thread_info
*
2381 find_thread_needs_step_over (int step
, struct thread_info
*except
)
2383 struct thread_info
*tp
, *current
;
2385 /* With non-stop mode on, threads are always handled individually. */
2386 gdb_assert (! non_stop
);
2388 current
= inferior_thread ();
2390 /* If scheduler locking applies, we can avoid iterating over all
2392 if (schedlock_applies (step
))
2394 if (except
!= current
2395 && thread_still_needs_step_over (current
))
2401 ALL_NON_EXITED_THREADS (tp
)
2403 /* Ignore the EXCEPT thread. */
2406 /* Ignore threads of processes we're not resuming. */
2408 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
2411 if (thread_still_needs_step_over (tp
))
2418 /* Basic routine for continuing the program in various fashions.
2420 ADDR is the address to resume at, or -1 for resume where stopped.
2421 SIGGNAL is the signal to give it, or 0 for none,
2422 or -1 for act according to how it stopped.
2423 STEP is nonzero if should trap after one instruction.
2424 -1 means return after that and print nothing.
2425 You should probably set various step_... variables
2426 before calling here, if you are stepping.
2428 You should call clear_proceed_status before calling proceed. */
2431 proceed (CORE_ADDR addr
, enum gdb_signal siggnal
, int step
)
2433 struct regcache
*regcache
;
2434 struct gdbarch
*gdbarch
;
2435 struct thread_info
*tp
;
2437 struct address_space
*aspace
;
2439 /* If we're stopped at a fork/vfork, follow the branch set by the
2440 "set follow-fork-mode" command; otherwise, we'll just proceed
2441 resuming the current thread. */
2442 if (!follow_fork ())
2444 /* The target for some reason decided not to resume. */
2446 if (target_can_async_p ())
2447 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2451 /* We'll update this if & when we switch to a new thread. */
2452 previous_inferior_ptid
= inferior_ptid
;
2454 regcache
= get_current_regcache ();
2455 gdbarch
= get_regcache_arch (regcache
);
2456 aspace
= get_regcache_aspace (regcache
);
2457 pc
= regcache_read_pc (regcache
);
2458 tp
= inferior_thread ();
2461 step_start_function
= find_pc_function (pc
);
2463 stop_after_trap
= 1;
2465 /* Fill in with reasonable starting values. */
2466 init_thread_stepping_state (tp
);
2468 if (addr
== (CORE_ADDR
) -1)
2470 if (pc
== stop_pc
&& breakpoint_here_p (aspace
, pc
)
2471 && execution_direction
!= EXEC_REVERSE
)
2472 /* There is a breakpoint at the address we will resume at,
2473 step one instruction before inserting breakpoints so that
2474 we do not stop right away (and report a second hit at this
2477 Note, we don't do this in reverse, because we won't
2478 actually be executing the breakpoint insn anyway.
2479 We'll be (un-)executing the previous instruction. */
2480 tp
->stepping_over_breakpoint
= 1;
2481 else if (gdbarch_single_step_through_delay_p (gdbarch
)
2482 && gdbarch_single_step_through_delay (gdbarch
,
2483 get_current_frame ()))
2484 /* We stepped onto an instruction that needs to be stepped
2485 again before re-inserting the breakpoint, do so. */
2486 tp
->stepping_over_breakpoint
= 1;
2490 regcache_write_pc (regcache
, addr
);
2493 if (siggnal
!= GDB_SIGNAL_DEFAULT
)
2494 tp
->suspend
.stop_signal
= siggnal
;
2496 /* Record the interpreter that issued the execution command that
2497 caused this thread to resume. If the top level interpreter is
2498 MI/async, and the execution command was a CLI command
2499 (next/step/etc.), we'll want to print stop event output to the MI
2500 console channel (the stepped-to line, etc.), as if the user
2501 entered the execution command on a real GDB console. */
2502 inferior_thread ()->control
.command_interp
= command_interp ();
2505 fprintf_unfiltered (gdb_stdlog
,
2506 "infrun: proceed (addr=%s, signal=%s, step=%d)\n",
2507 paddress (gdbarch
, addr
),
2508 gdb_signal_to_symbol_string (siggnal
), step
);
2511 /* In non-stop, each thread is handled individually. The context
2512 must already be set to the right thread here. */
2516 struct thread_info
*step_over
;
2518 /* In a multi-threaded task we may select another thread and
2519 then continue or step.
2521 But if the old thread was stopped at a breakpoint, it will
2522 immediately cause another breakpoint stop without any
2523 execution (i.e. it will report a breakpoint hit incorrectly).
2524 So we must step over it first.
2526 Look for a thread other than the current (TP) that reported a
2527 breakpoint hit and hasn't been resumed yet since. */
2528 step_over
= find_thread_needs_step_over (step
, tp
);
2529 if (step_over
!= NULL
)
2532 fprintf_unfiltered (gdb_stdlog
,
2533 "infrun: need to step-over [%s] first\n",
2534 target_pid_to_str (step_over
->ptid
));
2536 /* Store the prev_pc for the stepping thread too, needed by
2537 switch_back_to_stepping thread. */
2538 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2539 switch_to_thread (step_over
->ptid
);
2544 /* If we need to step over a breakpoint, and we're not using
2545 displaced stepping to do so, insert all breakpoints (watchpoints,
2546 etc.) but the one we're stepping over, step one instruction, and
2547 then re-insert the breakpoint when that step is finished. */
2548 if (tp
->stepping_over_breakpoint
&& !use_displaced_stepping (gdbarch
))
2550 struct regcache
*regcache
= get_current_regcache ();
2552 set_step_over_info (get_regcache_aspace (regcache
),
2553 regcache_read_pc (regcache
));
2556 clear_step_over_info ();
2558 insert_breakpoints ();
2560 tp
->control
.trap_expected
= tp
->stepping_over_breakpoint
;
2562 annotate_starting ();
2564 /* Make sure that output from GDB appears before output from the
2566 gdb_flush (gdb_stdout
);
2568 /* Refresh prev_pc value just prior to resuming. This used to be
2569 done in stop_waiting, however, setting prev_pc there did not handle
2570 scenarios such as inferior function calls or returning from
2571 a function via the return command. In those cases, the prev_pc
2572 value was not set properly for subsequent commands. The prev_pc value
2573 is used to initialize the starting line number in the ecs. With an
2574 invalid value, the gdb next command ends up stopping at the position
2575 represented by the next line table entry past our start position.
2576 On platforms that generate one line table entry per line, this
2577 is not a problem. However, on the ia64, the compiler generates
2578 extraneous line table entries that do not increase the line number.
2579 When we issue the gdb next command on the ia64 after an inferior call
2580 or a return command, we often end up a few instructions forward, still
2581 within the original line we started.
2583 An attempt was made to refresh the prev_pc at the same time the
2584 execution_control_state is initialized (for instance, just before
2585 waiting for an inferior event). But this approach did not work
2586 because of platforms that use ptrace, where the pc register cannot
2587 be read unless the inferior is stopped. At that point, we are not
2588 guaranteed the inferior is stopped and so the regcache_read_pc() call
2589 can fail. Setting the prev_pc value here ensures the value is updated
2590 correctly when the inferior is stopped. */
2591 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
2593 /* Reset to normal state. */
2594 init_infwait_state ();
2596 /* Resume inferior. */
2597 resume (tp
->control
.trap_expected
|| step
|| bpstat_should_step (),
2598 tp
->suspend
.stop_signal
);
2600 /* Wait for it to stop (if not standalone)
2601 and in any case decode why it stopped, and act accordingly. */
2602 /* Do this only if we are not using the event loop, or if the target
2603 does not support asynchronous execution. */
2604 if (!target_can_async_p ())
2606 wait_for_inferior ();
2612 /* Start remote-debugging of a machine over a serial link. */
2615 start_remote (int from_tty
)
2617 struct inferior
*inferior
;
2619 inferior
= current_inferior ();
2620 inferior
->control
.stop_soon
= STOP_QUIETLY_REMOTE
;
2622 /* Always go on waiting for the target, regardless of the mode. */
2623 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2624 indicate to wait_for_inferior that a target should timeout if
2625 nothing is returned (instead of just blocking). Because of this,
2626 targets expecting an immediate response need to, internally, set
2627 things up so that the target_wait() is forced to eventually
2629 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2630 differentiate to its caller what the state of the target is after
2631 the initial open has been performed. Here we're assuming that
2632 the target has stopped. It should be possible to eventually have
2633 target_open() return to the caller an indication that the target
2634 is currently running and GDB state should be set to the same as
2635 for an async run. */
2636 wait_for_inferior ();
2638 /* Now that the inferior has stopped, do any bookkeeping like
2639 loading shared libraries. We want to do this before normal_stop,
2640 so that the displayed frame is up to date. */
2641 post_create_inferior (¤t_target
, from_tty
);
2646 /* Initialize static vars when a new inferior begins. */
2649 init_wait_for_inferior (void)
2651 /* These are meaningless until the first time through wait_for_inferior. */
2653 breakpoint_init_inferior (inf_starting
);
2655 clear_proceed_status (0);
2657 target_last_wait_ptid
= minus_one_ptid
;
2659 previous_inferior_ptid
= inferior_ptid
;
2660 init_infwait_state ();
2662 /* Discard any skipped inlined frames. */
2663 clear_inline_frame_state (minus_one_ptid
);
2665 singlestep_ptid
= null_ptid
;
2670 /* This enum encodes possible reasons for doing a target_wait, so that
2671 wfi can call target_wait in one place. (Ultimately the call will be
2672 moved out of the infinite loop entirely.) */
2676 infwait_normal_state
,
2677 infwait_step_watch_state
,
2678 infwait_nonstep_watch_state
2681 /* The PTID we'll do a target_wait on.*/
2684 /* Current inferior wait state. */
2685 static enum infwait_states infwait_state
;
2687 /* Data to be passed around while handling an event. This data is
2688 discarded between events. */
2689 struct execution_control_state
2692 /* The thread that got the event, if this was a thread event; NULL
2694 struct thread_info
*event_thread
;
2696 struct target_waitstatus ws
;
2697 int stop_func_filled_in
;
2698 CORE_ADDR stop_func_start
;
2699 CORE_ADDR stop_func_end
;
2700 const char *stop_func_name
;
2703 /* We were in infwait_step_watch_state or
2704 infwait_nonstep_watch_state state, and the thread reported an
2706 int stepped_after_stopped_by_watchpoint
;
2708 /* True if the event thread hit the single-step breakpoint of
2709 another thread. Thus the event doesn't cause a stop, the thread
2710 needs to be single-stepped past the single-step breakpoint before
2711 we can switch back to the original stepping thread. */
2712 int hit_singlestep_breakpoint
;
2715 static void handle_inferior_event (struct execution_control_state
*ecs
);
2717 static void handle_step_into_function (struct gdbarch
*gdbarch
,
2718 struct execution_control_state
*ecs
);
2719 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
2720 struct execution_control_state
*ecs
);
2721 static void handle_signal_stop (struct execution_control_state
*ecs
);
2722 static void check_exception_resume (struct execution_control_state
*,
2723 struct frame_info
*);
2725 static void end_stepping_range (struct execution_control_state
*ecs
);
2726 static void stop_waiting (struct execution_control_state
*ecs
);
2727 static void prepare_to_wait (struct execution_control_state
*ecs
);
2728 static void keep_going (struct execution_control_state
*ecs
);
2729 static void process_event_stop_test (struct execution_control_state
*ecs
);
2730 static int switch_back_to_stepped_thread (struct execution_control_state
*ecs
);
2732 /* Callback for iterate over threads. If the thread is stopped, but
2733 the user/frontend doesn't know about that yet, go through
2734 normal_stop, as if the thread had just stopped now. ARG points at
2735 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2736 ptid_is_pid(PTID) is true, applies to all threads of the process
2737 pointed at by PTID. Otherwise, apply only to the thread pointed by
2741 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
2743 ptid_t ptid
= * (ptid_t
*) arg
;
2745 if ((ptid_equal (info
->ptid
, ptid
)
2746 || ptid_equal (minus_one_ptid
, ptid
)
2747 || (ptid_is_pid (ptid
)
2748 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
2749 && is_running (info
->ptid
)
2750 && !is_executing (info
->ptid
))
2752 struct cleanup
*old_chain
;
2753 struct execution_control_state ecss
;
2754 struct execution_control_state
*ecs
= &ecss
;
2756 memset (ecs
, 0, sizeof (*ecs
));
2758 old_chain
= make_cleanup_restore_current_thread ();
2760 overlay_cache_invalid
= 1;
2761 /* Flush target cache before starting to handle each event.
2762 Target was running and cache could be stale. This is just a
2763 heuristic. Running threads may modify target memory, but we
2764 don't get any event. */
2765 target_dcache_invalidate ();
2767 /* Go through handle_inferior_event/normal_stop, so we always
2768 have consistent output as if the stop event had been
2770 ecs
->ptid
= info
->ptid
;
2771 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
2772 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2773 ecs
->ws
.value
.sig
= GDB_SIGNAL_0
;
2775 handle_inferior_event (ecs
);
2777 if (!ecs
->wait_some_more
)
2779 struct thread_info
*tp
;
2783 /* Finish off the continuations. */
2784 tp
= inferior_thread ();
2785 do_all_intermediate_continuations_thread (tp
, 1);
2786 do_all_continuations_thread (tp
, 1);
2789 do_cleanups (old_chain
);
2795 /* This function is attached as a "thread_stop_requested" observer.
2796 Cleanup local state that assumed the PTID was to be resumed, and
2797 report the stop to the frontend. */
2800 infrun_thread_stop_requested (ptid_t ptid
)
2802 struct displaced_step_inferior_state
*displaced
;
2804 /* PTID was requested to stop. Remove it from the displaced
2805 stepping queue, so we don't try to resume it automatically. */
2807 for (displaced
= displaced_step_inferior_states
;
2809 displaced
= displaced
->next
)
2811 struct displaced_step_request
*it
, **prev_next_p
;
2813 it
= displaced
->step_request_queue
;
2814 prev_next_p
= &displaced
->step_request_queue
;
2817 if (ptid_match (it
->ptid
, ptid
))
2819 *prev_next_p
= it
->next
;
2825 prev_next_p
= &it
->next
;
2832 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
2836 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
2838 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
2839 nullify_last_target_wait_ptid ();
2842 /* Callback for iterate_over_threads. */
2845 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
2847 if (is_exited (info
->ptid
))
2850 delete_step_resume_breakpoint (info
);
2851 delete_exception_resume_breakpoint (info
);
2855 /* In all-stop, delete the step resume breakpoint of any thread that
2856 had one. In non-stop, delete the step resume breakpoint of the
2857 thread that just stopped. */
2860 delete_step_thread_step_resume_breakpoint (void)
2862 if (!target_has_execution
2863 || ptid_equal (inferior_ptid
, null_ptid
))
2864 /* If the inferior has exited, we have already deleted the step
2865 resume breakpoints out of GDB's lists. */
2870 /* If in non-stop mode, only delete the step-resume or
2871 longjmp-resume breakpoint of the thread that just stopped
2873 struct thread_info
*tp
= inferior_thread ();
2875 delete_step_resume_breakpoint (tp
);
2876 delete_exception_resume_breakpoint (tp
);
2879 /* In all-stop mode, delete all step-resume and longjmp-resume
2880 breakpoints of any thread that had them. */
2881 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
2884 /* A cleanup wrapper. */
2887 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
2889 delete_step_thread_step_resume_breakpoint ();
2892 /* Pretty print the results of target_wait, for debugging purposes. */
2895 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
2896 const struct target_waitstatus
*ws
)
2898 char *status_string
= target_waitstatus_to_string (ws
);
2899 struct ui_file
*tmp_stream
= mem_fileopen ();
2902 /* The text is split over several lines because it was getting too long.
2903 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2904 output as a unit; we want only one timestamp printed if debug_timestamp
2907 fprintf_unfiltered (tmp_stream
,
2908 "infrun: target_wait (%d", ptid_get_pid (waiton_ptid
));
2909 if (ptid_get_pid (waiton_ptid
) != -1)
2910 fprintf_unfiltered (tmp_stream
,
2911 " [%s]", target_pid_to_str (waiton_ptid
));
2912 fprintf_unfiltered (tmp_stream
, ", status) =\n");
2913 fprintf_unfiltered (tmp_stream
,
2914 "infrun: %d [%s],\n",
2915 ptid_get_pid (result_ptid
),
2916 target_pid_to_str (result_ptid
));
2917 fprintf_unfiltered (tmp_stream
,
2921 text
= ui_file_xstrdup (tmp_stream
, NULL
);
2923 /* This uses %s in part to handle %'s in the text, but also to avoid
2924 a gcc error: the format attribute requires a string literal. */
2925 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
2927 xfree (status_string
);
2929 ui_file_delete (tmp_stream
);
2932 /* Prepare and stabilize the inferior for detaching it. E.g.,
2933 detaching while a thread is displaced stepping is a recipe for
2934 crashing it, as nothing would readjust the PC out of the scratch
2938 prepare_for_detach (void)
2940 struct inferior
*inf
= current_inferior ();
2941 ptid_t pid_ptid
= pid_to_ptid (inf
->pid
);
2942 struct cleanup
*old_chain_1
;
2943 struct displaced_step_inferior_state
*displaced
;
2945 displaced
= get_displaced_stepping_state (inf
->pid
);
2947 /* Is any thread of this process displaced stepping? If not,
2948 there's nothing else to do. */
2949 if (displaced
== NULL
|| ptid_equal (displaced
->step_ptid
, null_ptid
))
2953 fprintf_unfiltered (gdb_stdlog
,
2954 "displaced-stepping in-process while detaching");
2956 old_chain_1
= make_cleanup_restore_integer (&inf
->detaching
);
2959 while (!ptid_equal (displaced
->step_ptid
, null_ptid
))
2961 struct cleanup
*old_chain_2
;
2962 struct execution_control_state ecss
;
2963 struct execution_control_state
*ecs
;
2966 memset (ecs
, 0, sizeof (*ecs
));
2968 overlay_cache_invalid
= 1;
2969 /* Flush target cache before starting to handle each event.
2970 Target was running and cache could be stale. This is just a
2971 heuristic. Running threads may modify target memory, but we
2972 don't get any event. */
2973 target_dcache_invalidate ();
2975 if (deprecated_target_wait_hook
)
2976 ecs
->ptid
= deprecated_target_wait_hook (pid_ptid
, &ecs
->ws
, 0);
2978 ecs
->ptid
= target_wait (pid_ptid
, &ecs
->ws
, 0);
2981 print_target_wait_results (pid_ptid
, ecs
->ptid
, &ecs
->ws
);
2983 /* If an error happens while handling the event, propagate GDB's
2984 knowledge of the executing state to the frontend/user running
2986 old_chain_2
= make_cleanup (finish_thread_state_cleanup
,
2989 /* Now figure out what to do with the result of the result. */
2990 handle_inferior_event (ecs
);
2992 /* No error, don't finish the state yet. */
2993 discard_cleanups (old_chain_2
);
2995 /* Breakpoints and watchpoints are not installed on the target
2996 at this point, and signals are passed directly to the
2997 inferior, so this must mean the process is gone. */
2998 if (!ecs
->wait_some_more
)
3000 discard_cleanups (old_chain_1
);
3001 error (_("Program exited while detaching"));
3005 discard_cleanups (old_chain_1
);
3008 /* Wait for control to return from inferior to debugger.
3010 If inferior gets a signal, we may decide to start it up again
3011 instead of returning. That is why there is a loop in this function.
3012 When this function actually returns it means the inferior
3013 should be left stopped and GDB should read more commands. */
3016 wait_for_inferior (void)
3018 struct cleanup
*old_cleanups
;
3022 (gdb_stdlog
, "infrun: wait_for_inferior ()\n");
3025 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
3029 struct execution_control_state ecss
;
3030 struct execution_control_state
*ecs
= &ecss
;
3031 struct cleanup
*old_chain
;
3033 memset (ecs
, 0, sizeof (*ecs
));
3035 overlay_cache_invalid
= 1;
3037 /* Flush target cache before starting to handle each event.
3038 Target was running and cache could be stale. This is just a
3039 heuristic. Running threads may modify target memory, but we
3040 don't get any event. */
3041 target_dcache_invalidate ();
3043 if (deprecated_target_wait_hook
)
3044 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
3046 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
3049 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3051 /* If an error happens while handling the event, propagate GDB's
3052 knowledge of the executing state to the frontend/user running
3054 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
3056 /* Now figure out what to do with the result of the result. */
3057 handle_inferior_event (ecs
);
3059 /* No error, don't finish the state yet. */
3060 discard_cleanups (old_chain
);
3062 if (!ecs
->wait_some_more
)
3066 do_cleanups (old_cleanups
);
3069 /* Asynchronous version of wait_for_inferior. It is called by the
3070 event loop whenever a change of state is detected on the file
3071 descriptor corresponding to the target. It can be called more than
3072 once to complete a single execution command. In such cases we need
3073 to keep the state in a global variable ECSS. If it is the last time
3074 that this function is called for a single execution command, then
3075 report to the user that the inferior has stopped, and do the
3076 necessary cleanups. */
3079 fetch_inferior_event (void *client_data
)
3081 struct execution_control_state ecss
;
3082 struct execution_control_state
*ecs
= &ecss
;
3083 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
3084 struct cleanup
*ts_old_chain
;
3085 int was_sync
= sync_execution
;
3088 memset (ecs
, 0, sizeof (*ecs
));
3090 /* We're handling a live event, so make sure we're doing live
3091 debugging. If we're looking at traceframes while the target is
3092 running, we're going to need to get back to that mode after
3093 handling the event. */
3096 make_cleanup_restore_current_traceframe ();
3097 set_current_traceframe (-1);
3101 /* In non-stop mode, the user/frontend should not notice a thread
3102 switch due to internal events. Make sure we reverse to the
3103 user selected thread and frame after handling the event and
3104 running any breakpoint commands. */
3105 make_cleanup_restore_current_thread ();
3107 overlay_cache_invalid
= 1;
3108 /* Flush target cache before starting to handle each event. Target
3109 was running and cache could be stale. This is just a heuristic.
3110 Running threads may modify target memory, but we don't get any
3112 target_dcache_invalidate ();
3114 make_cleanup_restore_integer (&execution_direction
);
3115 execution_direction
= target_execution_direction ();
3117 if (deprecated_target_wait_hook
)
3119 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
3121 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
3124 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
3126 /* If an error happens while handling the event, propagate GDB's
3127 knowledge of the executing state to the frontend/user running
3130 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
3132 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
3134 /* Get executed before make_cleanup_restore_current_thread above to apply
3135 still for the thread which has thrown the exception. */
3136 make_bpstat_clear_actions_cleanup ();
3138 /* Now figure out what to do with the result of the result. */
3139 handle_inferior_event (ecs
);
3141 if (!ecs
->wait_some_more
)
3143 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3145 delete_step_thread_step_resume_breakpoint ();
3147 /* We may not find an inferior if this was a process exit. */
3148 if (inf
== NULL
|| inf
->control
.stop_soon
== NO_STOP_QUIETLY
)
3151 if (target_has_execution
3152 && ecs
->ws
.kind
!= TARGET_WAITKIND_NO_RESUMED
3153 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3154 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3155 && ecs
->event_thread
->step_multi
3156 && ecs
->event_thread
->control
.stop_step
)
3157 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
3160 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
3165 /* No error, don't finish the thread states yet. */
3166 discard_cleanups (ts_old_chain
);
3168 /* Revert thread and frame. */
3169 do_cleanups (old_chain
);
3171 /* If the inferior was in sync execution mode, and now isn't,
3172 restore the prompt (a synchronous execution command has finished,
3173 and we're ready for input). */
3174 if (interpreter_async
&& was_sync
&& !sync_execution
)
3175 observer_notify_sync_execution_done ();
3179 && exec_done_display_p
3180 && (ptid_equal (inferior_ptid
, null_ptid
)
3181 || !is_running (inferior_ptid
)))
3182 printf_unfiltered (_("completed.\n"));
3185 /* Record the frame and location we're currently stepping through. */
3187 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
3189 struct thread_info
*tp
= inferior_thread ();
3191 tp
->control
.step_frame_id
= get_frame_id (frame
);
3192 tp
->control
.step_stack_frame_id
= get_stack_frame_id (frame
);
3194 tp
->current_symtab
= sal
.symtab
;
3195 tp
->current_line
= sal
.line
;
3198 /* Clear context switchable stepping state. */
3201 init_thread_stepping_state (struct thread_info
*tss
)
3203 tss
->stepping_over_breakpoint
= 0;
3204 tss
->step_after_step_resume_breakpoint
= 0;
3207 /* Set the cached copy of the last ptid/waitstatus. */
3210 set_last_target_status (ptid_t ptid
, struct target_waitstatus status
)
3212 target_last_wait_ptid
= ptid
;
3213 target_last_waitstatus
= status
;
3216 /* Return the cached copy of the last pid/waitstatus returned by
3217 target_wait()/deprecated_target_wait_hook(). The data is actually
3218 cached by handle_inferior_event(), which gets called immediately
3219 after target_wait()/deprecated_target_wait_hook(). */
3222 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
3224 *ptidp
= target_last_wait_ptid
;
3225 *status
= target_last_waitstatus
;
3229 nullify_last_target_wait_ptid (void)
3231 target_last_wait_ptid
= minus_one_ptid
;
3234 /* Switch thread contexts. */
3237 context_switch (ptid_t ptid
)
3239 if (debug_infrun
&& !ptid_equal (ptid
, inferior_ptid
))
3241 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
3242 target_pid_to_str (inferior_ptid
));
3243 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
3244 target_pid_to_str (ptid
));
3247 switch_to_thread (ptid
);
3251 adjust_pc_after_break (struct execution_control_state
*ecs
)
3253 struct regcache
*regcache
;
3254 struct gdbarch
*gdbarch
;
3255 struct address_space
*aspace
;
3256 CORE_ADDR breakpoint_pc
, decr_pc
;
3258 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3259 we aren't, just return.
3261 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3262 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3263 implemented by software breakpoints should be handled through the normal
3266 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3267 different signals (SIGILL or SIGEMT for instance), but it is less
3268 clear where the PC is pointing afterwards. It may not match
3269 gdbarch_decr_pc_after_break. I don't know any specific target that
3270 generates these signals at breakpoints (the code has been in GDB since at
3271 least 1992) so I can not guess how to handle them here.
3273 In earlier versions of GDB, a target with
3274 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3275 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3276 target with both of these set in GDB history, and it seems unlikely to be
3277 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3279 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
3282 if (ecs
->ws
.value
.sig
!= GDB_SIGNAL_TRAP
)
3285 /* In reverse execution, when a breakpoint is hit, the instruction
3286 under it has already been de-executed. The reported PC always
3287 points at the breakpoint address, so adjusting it further would
3288 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3291 B1 0x08000000 : INSN1
3292 B2 0x08000001 : INSN2
3294 PC -> 0x08000003 : INSN4
3296 Say you're stopped at 0x08000003 as above. Reverse continuing
3297 from that point should hit B2 as below. Reading the PC when the
3298 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3299 been de-executed already.
3301 B1 0x08000000 : INSN1
3302 B2 PC -> 0x08000001 : INSN2
3306 We can't apply the same logic as for forward execution, because
3307 we would wrongly adjust the PC to 0x08000000, since there's a
3308 breakpoint at PC - 1. We'd then report a hit on B1, although
3309 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3311 if (execution_direction
== EXEC_REVERSE
)
3314 /* If this target does not decrement the PC after breakpoints, then
3315 we have nothing to do. */
3316 regcache
= get_thread_regcache (ecs
->ptid
);
3317 gdbarch
= get_regcache_arch (regcache
);
3319 decr_pc
= target_decr_pc_after_break (gdbarch
);
3323 aspace
= get_regcache_aspace (regcache
);
3325 /* Find the location where (if we've hit a breakpoint) the
3326 breakpoint would be. */
3327 breakpoint_pc
= regcache_read_pc (regcache
) - decr_pc
;
3329 /* Check whether there actually is a software breakpoint inserted at
3332 If in non-stop mode, a race condition is possible where we've
3333 removed a breakpoint, but stop events for that breakpoint were
3334 already queued and arrive later. To suppress those spurious
3335 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3336 and retire them after a number of stop events are reported. */
3337 if (software_breakpoint_inserted_here_p (aspace
, breakpoint_pc
)
3338 || (non_stop
&& moribund_breakpoint_here_p (aspace
, breakpoint_pc
)))
3340 struct cleanup
*old_cleanups
= make_cleanup (null_cleanup
, NULL
);
3342 if (record_full_is_used ())
3343 record_full_gdb_operation_disable_set ();
3345 /* When using hardware single-step, a SIGTRAP is reported for both
3346 a completed single-step and a software breakpoint. Need to
3347 differentiate between the two, as the latter needs adjusting
3348 but the former does not.
3350 The SIGTRAP can be due to a completed hardware single-step only if
3351 - we didn't insert software single-step breakpoints
3352 - the thread to be examined is still the current thread
3353 - this thread is currently being stepped
3355 If any of these events did not occur, we must have stopped due
3356 to hitting a software breakpoint, and have to back up to the
3359 As a special case, we could have hardware single-stepped a
3360 software breakpoint. In this case (prev_pc == breakpoint_pc),
3361 we also need to back up to the breakpoint address. */
3363 if (singlestep_breakpoints_inserted_p
3364 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
3365 || !currently_stepping (ecs
->event_thread
)
3366 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
3367 regcache_write_pc (regcache
, breakpoint_pc
);
3369 do_cleanups (old_cleanups
);
3374 init_infwait_state (void)
3376 waiton_ptid
= pid_to_ptid (-1);
3377 infwait_state
= infwait_normal_state
;
3381 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
3383 for (frame
= get_prev_frame (frame
);
3385 frame
= get_prev_frame (frame
))
3387 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
3389 if (get_frame_type (frame
) != INLINE_FRAME
)
3396 /* Auxiliary function that handles syscall entry/return events.
3397 It returns 1 if the inferior should keep going (and GDB
3398 should ignore the event), or 0 if the event deserves to be
3402 handle_syscall_event (struct execution_control_state
*ecs
)
3404 struct regcache
*regcache
;
3407 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3408 context_switch (ecs
->ptid
);
3410 regcache
= get_thread_regcache (ecs
->ptid
);
3411 syscall_number
= ecs
->ws
.value
.syscall_number
;
3412 stop_pc
= regcache_read_pc (regcache
);
3414 if (catch_syscall_enabled () > 0
3415 && catching_syscall_number (syscall_number
) > 0)
3418 fprintf_unfiltered (gdb_stdlog
, "infrun: syscall number = '%d'\n",
3421 ecs
->event_thread
->control
.stop_bpstat
3422 = bpstat_stop_status (get_regcache_aspace (regcache
),
3423 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3425 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3427 /* Catchpoint hit. */
3432 /* If no catchpoint triggered for this, then keep going. */
3437 /* Lazily fill in the execution_control_state's stop_func_* fields. */
3440 fill_in_stop_func (struct gdbarch
*gdbarch
,
3441 struct execution_control_state
*ecs
)
3443 if (!ecs
->stop_func_filled_in
)
3445 /* Don't care about return value; stop_func_start and stop_func_name
3446 will both be 0 if it doesn't work. */
3447 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3448 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3449 ecs
->stop_func_start
3450 += gdbarch_deprecated_function_start_offset (gdbarch
);
3452 if (gdbarch_skip_entrypoint_p (gdbarch
))
3453 ecs
->stop_func_start
= gdbarch_skip_entrypoint (gdbarch
,
3454 ecs
->stop_func_start
);
3456 ecs
->stop_func_filled_in
= 1;
3461 /* Return the STOP_SOON field of the inferior pointed at by PTID. */
3463 static enum stop_kind
3464 get_inferior_stop_soon (ptid_t ptid
)
3466 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ptid
));
3468 gdb_assert (inf
!= NULL
);
3469 return inf
->control
.stop_soon
;
3472 /* Given an execution control state that has been freshly filled in by
3473 an event from the inferior, figure out what it means and take
3476 The alternatives are:
3478 1) stop_waiting and return; to really stop and return to the
3481 2) keep_going and return; to wait for the next event (set
3482 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3486 handle_inferior_event (struct execution_control_state
*ecs
)
3488 enum stop_kind stop_soon
;
3490 if (ecs
->ws
.kind
== TARGET_WAITKIND_IGNORE
)
3492 /* We had an event in the inferior, but we are not interested in
3493 handling it at this level. The lower layers have already
3494 done what needs to be done, if anything.
3496 One of the possible circumstances for this is when the
3497 inferior produces output for the console. The inferior has
3498 not stopped, and we are ignoring the event. Another possible
3499 circumstance is any event which the lower level knows will be
3500 reported multiple times without an intervening resume. */
3502 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
3503 prepare_to_wait (ecs
);
3507 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
3508 && target_can_async_p () && !sync_execution
)
3510 /* There were no unwaited-for children left in the target, but,
3511 we're not synchronously waiting for events either. Just
3512 ignore. Otherwise, if we were running a synchronous
3513 execution command, we need to cancel it and give the user
3514 back the terminal. */
3516 fprintf_unfiltered (gdb_stdlog
,
3517 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3518 prepare_to_wait (ecs
);
3522 /* Cache the last pid/waitstatus. */
3523 set_last_target_status (ecs
->ptid
, ecs
->ws
);
3525 /* Always clear state belonging to the previous time we stopped. */
3526 stop_stack_dummy
= STOP_NONE
;
3528 if (ecs
->ws
.kind
== TARGET_WAITKIND_NO_RESUMED
)
3530 /* No unwaited-for children left. IOW, all resumed children
3533 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3535 stop_print_frame
= 0;
3540 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
3541 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
3543 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
3544 /* If it's a new thread, add it to the thread database. */
3545 if (ecs
->event_thread
== NULL
)
3546 ecs
->event_thread
= add_thread (ecs
->ptid
);
3548 /* Disable range stepping. If the next step request could use a
3549 range, this will be end up re-enabled then. */
3550 ecs
->event_thread
->control
.may_range_step
= 0;
3553 /* Dependent on valid ECS->EVENT_THREAD. */
3554 adjust_pc_after_break (ecs
);
3556 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3557 reinit_frame_cache ();
3559 breakpoint_retire_moribund ();
3561 /* First, distinguish signals caused by the debugger from signals
3562 that have to do with the program's own actions. Note that
3563 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3564 on the operating system version. Here we detect when a SIGILL or
3565 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3566 something similar for SIGSEGV, since a SIGSEGV will be generated
3567 when we're trying to execute a breakpoint instruction on a
3568 non-executable stack. This happens for call dummy breakpoints
3569 for architectures like SPARC that place call dummies on the
3571 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
3572 && (ecs
->ws
.value
.sig
== GDB_SIGNAL_ILL
3573 || ecs
->ws
.value
.sig
== GDB_SIGNAL_SEGV
3574 || ecs
->ws
.value
.sig
== GDB_SIGNAL_EMT
))
3576 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3578 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache
),
3579 regcache_read_pc (regcache
)))
3582 fprintf_unfiltered (gdb_stdlog
,
3583 "infrun: Treating signal as SIGTRAP\n");
3584 ecs
->ws
.value
.sig
= GDB_SIGNAL_TRAP
;
3588 /* Mark the non-executing threads accordingly. In all-stop, all
3589 threads of all processes are stopped when we get any event
3590 reported. In non-stop mode, only the event thread stops. If
3591 we're handling a process exit in non-stop mode, there's nothing
3592 to do, as threads of the dead process are gone, and threads of
3593 any other process were left running. */
3595 set_executing (minus_one_ptid
, 0);
3596 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
3597 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
3598 set_executing (ecs
->ptid
, 0);
3600 switch (infwait_state
)
3602 case infwait_normal_state
:
3604 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
3607 case infwait_step_watch_state
:
3609 fprintf_unfiltered (gdb_stdlog
,
3610 "infrun: infwait_step_watch_state\n");
3612 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3615 case infwait_nonstep_watch_state
:
3617 fprintf_unfiltered (gdb_stdlog
,
3618 "infrun: infwait_nonstep_watch_state\n");
3619 insert_breakpoints ();
3621 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3622 handle things like signals arriving and other things happening
3623 in combination correctly? */
3624 ecs
->stepped_after_stopped_by_watchpoint
= 1;
3628 internal_error (__FILE__
, __LINE__
, _("bad switch"));
3631 infwait_state
= infwait_normal_state
;
3632 waiton_ptid
= pid_to_ptid (-1);
3634 switch (ecs
->ws
.kind
)
3636 case TARGET_WAITKIND_LOADED
:
3638 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
3639 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3640 context_switch (ecs
->ptid
);
3641 /* Ignore gracefully during startup of the inferior, as it might
3642 be the shell which has just loaded some objects, otherwise
3643 add the symbols for the newly loaded objects. Also ignore at
3644 the beginning of an attach or remote session; we will query
3645 the full list of libraries once the connection is
3648 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
3649 if (stop_soon
== NO_STOP_QUIETLY
)
3651 struct regcache
*regcache
;
3653 regcache
= get_thread_regcache (ecs
->ptid
);
3655 handle_solib_event ();
3657 ecs
->event_thread
->control
.stop_bpstat
3658 = bpstat_stop_status (get_regcache_aspace (regcache
),
3659 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3661 if (bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3663 /* A catchpoint triggered. */
3664 process_event_stop_test (ecs
);
3668 /* If requested, stop when the dynamic linker notifies
3669 gdb of events. This allows the user to get control
3670 and place breakpoints in initializer routines for
3671 dynamically loaded objects (among other things). */
3672 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3673 if (stop_on_solib_events
)
3675 /* Make sure we print "Stopped due to solib-event" in
3677 stop_print_frame
= 1;
3684 /* If we are skipping through a shell, or through shared library
3685 loading that we aren't interested in, resume the program. If
3686 we're running the program normally, also resume. */
3687 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
3689 /* Loading of shared libraries might have changed breakpoint
3690 addresses. Make sure new breakpoints are inserted. */
3691 if (stop_soon
== NO_STOP_QUIETLY
)
3692 insert_breakpoints ();
3693 resume (0, GDB_SIGNAL_0
);
3694 prepare_to_wait (ecs
);
3698 /* But stop if we're attaching or setting up a remote
3700 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3701 || stop_soon
== STOP_QUIETLY_REMOTE
)
3704 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3709 internal_error (__FILE__
, __LINE__
,
3710 _("unhandled stop_soon: %d"), (int) stop_soon
);
3712 case TARGET_WAITKIND_SPURIOUS
:
3714 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3715 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3716 context_switch (ecs
->ptid
);
3717 resume (0, GDB_SIGNAL_0
);
3718 prepare_to_wait (ecs
);
3721 case TARGET_WAITKIND_EXITED
:
3722 case TARGET_WAITKIND_SIGNALLED
:
3725 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3726 fprintf_unfiltered (gdb_stdlog
,
3727 "infrun: TARGET_WAITKIND_EXITED\n");
3729 fprintf_unfiltered (gdb_stdlog
,
3730 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3733 inferior_ptid
= ecs
->ptid
;
3734 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs
->ptid
)));
3735 set_current_program_space (current_inferior ()->pspace
);
3736 handle_vfork_child_exec_or_exit (0);
3737 target_terminal_ours (); /* Must do this before mourn anyway. */
3739 /* Clearing any previous state of convenience variables. */
3740 clear_exit_convenience_vars ();
3742 if (ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
)
3744 /* Record the exit code in the convenience variable $_exitcode, so
3745 that the user can inspect this again later. */
3746 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3747 (LONGEST
) ecs
->ws
.value
.integer
);
3749 /* Also record this in the inferior itself. */
3750 current_inferior ()->has_exit_code
= 1;
3751 current_inferior ()->exit_code
= (LONGEST
) ecs
->ws
.value
.integer
;
3753 /* Support the --return-child-result option. */
3754 return_child_result_value
= ecs
->ws
.value
.integer
;
3756 observer_notify_exited (ecs
->ws
.value
.integer
);
3760 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3761 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3763 if (gdbarch_gdb_signal_to_target_p (gdbarch
))
3765 /* Set the value of the internal variable $_exitsignal,
3766 which holds the signal uncaught by the inferior. */
3767 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3768 gdbarch_gdb_signal_to_target (gdbarch
,
3769 ecs
->ws
.value
.sig
));
3773 /* We don't have access to the target's method used for
3774 converting between signal numbers (GDB's internal
3775 representation <-> target's representation).
3776 Therefore, we cannot do a good job at displaying this
3777 information to the user. It's better to just warn
3778 her about it (if infrun debugging is enabled), and
3781 fprintf_filtered (gdb_stdlog
, _("\
3782 Cannot fill $_exitsignal with the correct signal number.\n"));
3785 observer_notify_signal_exited (ecs
->ws
.value
.sig
);
3788 gdb_flush (gdb_stdout
);
3789 target_mourn_inferior ();
3790 singlestep_breakpoints_inserted_p
= 0;
3791 cancel_single_step_breakpoints ();
3792 stop_print_frame
= 0;
3796 /* The following are the only cases in which we keep going;
3797 the above cases end in a continue or goto. */
3798 case TARGET_WAITKIND_FORKED
:
3799 case TARGET_WAITKIND_VFORKED
:
3802 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3803 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
3805 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_VFORKED\n");
3808 /* Check whether the inferior is displaced stepping. */
3810 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
3811 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
3812 struct displaced_step_inferior_state
*displaced
3813 = get_displaced_stepping_state (ptid_get_pid (ecs
->ptid
));
3815 /* If checking displaced stepping is supported, and thread
3816 ecs->ptid is displaced stepping. */
3817 if (displaced
&& ptid_equal (displaced
->step_ptid
, ecs
->ptid
))
3819 struct inferior
*parent_inf
3820 = find_inferior_pid (ptid_get_pid (ecs
->ptid
));
3821 struct regcache
*child_regcache
;
3822 CORE_ADDR parent_pc
;
3824 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3825 indicating that the displaced stepping of syscall instruction
3826 has been done. Perform cleanup for parent process here. Note
3827 that this operation also cleans up the child process for vfork,
3828 because their pages are shared. */
3829 displaced_step_fixup (ecs
->ptid
, GDB_SIGNAL_TRAP
);
3831 if (ecs
->ws
.kind
== TARGET_WAITKIND_FORKED
)
3833 /* Restore scratch pad for child process. */
3834 displaced_step_restore (displaced
, ecs
->ws
.value
.related_pid
);
3837 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3838 the child's PC is also within the scratchpad. Set the child's PC
3839 to the parent's PC value, which has already been fixed up.
3840 FIXME: we use the parent's aspace here, although we're touching
3841 the child, because the child hasn't been added to the inferior
3842 list yet at this point. */
3845 = get_thread_arch_aspace_regcache (ecs
->ws
.value
.related_pid
,
3847 parent_inf
->aspace
);
3848 /* Read PC value of parent process. */
3849 parent_pc
= regcache_read_pc (regcache
);
3851 if (debug_displaced
)
3852 fprintf_unfiltered (gdb_stdlog
,
3853 "displaced: write child pc from %s to %s\n",
3855 regcache_read_pc (child_regcache
)),
3856 paddress (gdbarch
, parent_pc
));
3858 regcache_write_pc (child_regcache
, parent_pc
);
3862 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3863 context_switch (ecs
->ptid
);
3865 /* Immediately detach breakpoints from the child before there's
3866 any chance of letting the user delete breakpoints from the
3867 breakpoint lists. If we don't do this early, it's easy to
3868 leave left over traps in the child, vis: "break foo; catch
3869 fork; c; <fork>; del; c; <child calls foo>". We only follow
3870 the fork on the last `continue', and by that time the
3871 breakpoint at "foo" is long gone from the breakpoint table.
3872 If we vforked, then we don't need to unpatch here, since both
3873 parent and child are sharing the same memory pages; we'll
3874 need to unpatch at follow/detach time instead to be certain
3875 that new breakpoints added between catchpoint hit time and
3876 vfork follow are detached. */
3877 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
3879 /* This won't actually modify the breakpoint list, but will
3880 physically remove the breakpoints from the child. */
3881 detach_breakpoints (ecs
->ws
.value
.related_pid
);
3884 if (singlestep_breakpoints_inserted_p
)
3886 /* Pull the single step breakpoints out of the target. */
3887 remove_single_step_breakpoints ();
3888 singlestep_breakpoints_inserted_p
= 0;
3891 /* In case the event is caught by a catchpoint, remember that
3892 the event is to be followed at the next resume of the thread,
3893 and not immediately. */
3894 ecs
->event_thread
->pending_follow
= ecs
->ws
;
3896 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3898 ecs
->event_thread
->control
.stop_bpstat
3899 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3900 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3902 /* If no catchpoint triggered for this, then keep going. Note
3903 that we're interested in knowing the bpstat actually causes a
3904 stop, not just if it may explain the signal. Software
3905 watchpoints, for example, always appear in the bpstat. */
3906 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
3912 = (follow_fork_mode_string
== follow_fork_mode_child
);
3914 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
3916 should_resume
= follow_fork ();
3919 child
= ecs
->ws
.value
.related_pid
;
3921 /* In non-stop mode, also resume the other branch. */
3922 if (non_stop
&& !detach_fork
)
3925 switch_to_thread (parent
);
3927 switch_to_thread (child
);
3929 ecs
->event_thread
= inferior_thread ();
3930 ecs
->ptid
= inferior_ptid
;
3935 switch_to_thread (child
);
3937 switch_to_thread (parent
);
3939 ecs
->event_thread
= inferior_thread ();
3940 ecs
->ptid
= inferior_ptid
;
3948 process_event_stop_test (ecs
);
3951 case TARGET_WAITKIND_VFORK_DONE
:
3952 /* Done with the shared memory region. Re-insert breakpoints in
3953 the parent, and keep going. */
3956 fprintf_unfiltered (gdb_stdlog
,
3957 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3959 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3960 context_switch (ecs
->ptid
);
3962 current_inferior ()->waiting_for_vfork_done
= 0;
3963 current_inferior ()->pspace
->breakpoints_not_allowed
= 0;
3964 /* This also takes care of reinserting breakpoints in the
3965 previously locked inferior. */
3969 case TARGET_WAITKIND_EXECD
:
3971 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
3973 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3974 context_switch (ecs
->ptid
);
3976 singlestep_breakpoints_inserted_p
= 0;
3977 cancel_single_step_breakpoints ();
3979 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
3981 /* Do whatever is necessary to the parent branch of the vfork. */
3982 handle_vfork_child_exec_or_exit (1);
3984 /* This causes the eventpoints and symbol table to be reset.
3985 Must do this now, before trying to determine whether to
3987 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
3989 ecs
->event_thread
->control
.stop_bpstat
3990 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3991 stop_pc
, ecs
->ptid
, &ecs
->ws
);
3993 /* Note that this may be referenced from inside
3994 bpstat_stop_status above, through inferior_has_execd. */
3995 xfree (ecs
->ws
.value
.execd_pathname
);
3996 ecs
->ws
.value
.execd_pathname
= NULL
;
3998 /* If no catchpoint triggered for this, then keep going. */
3999 if (!bpstat_causes_stop (ecs
->event_thread
->control
.stop_bpstat
))
4001 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4005 process_event_stop_test (ecs
);
4008 /* Be careful not to try to gather much state about a thread
4009 that's in a syscall. It's frequently a losing proposition. */
4010 case TARGET_WAITKIND_SYSCALL_ENTRY
:
4012 fprintf_unfiltered (gdb_stdlog
,
4013 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
4014 /* Getting the current syscall number. */
4015 if (handle_syscall_event (ecs
) == 0)
4016 process_event_stop_test (ecs
);
4019 /* Before examining the threads further, step this thread to
4020 get it entirely out of the syscall. (We get notice of the
4021 event when the thread is just on the verge of exiting a
4022 syscall. Stepping one instruction seems to get it back
4024 case TARGET_WAITKIND_SYSCALL_RETURN
:
4026 fprintf_unfiltered (gdb_stdlog
,
4027 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
4028 if (handle_syscall_event (ecs
) == 0)
4029 process_event_stop_test (ecs
);
4032 case TARGET_WAITKIND_STOPPED
:
4034 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
4035 ecs
->event_thread
->suspend
.stop_signal
= ecs
->ws
.value
.sig
;
4036 handle_signal_stop (ecs
);
4039 case TARGET_WAITKIND_NO_HISTORY
:
4041 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
4042 /* Reverse execution: target ran out of history info. */
4044 /* Pull the single step breakpoints out of the target. */
4045 if (singlestep_breakpoints_inserted_p
)
4047 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4048 context_switch (ecs
->ptid
);
4049 remove_single_step_breakpoints ();
4050 singlestep_breakpoints_inserted_p
= 0;
4052 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4053 observer_notify_no_history ();
4059 /* Come here when the program has stopped with a signal. */
4062 handle_signal_stop (struct execution_control_state
*ecs
)
4064 struct frame_info
*frame
;
4065 struct gdbarch
*gdbarch
;
4066 int stopped_by_watchpoint
;
4067 enum stop_kind stop_soon
;
4070 gdb_assert (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
);
4072 /* Do we need to clean up the state of a thread that has
4073 completed a displaced single-step? (Doing so usually affects
4074 the PC, so do it here, before we set stop_pc.) */
4075 displaced_step_fixup (ecs
->ptid
,
4076 ecs
->event_thread
->suspend
.stop_signal
);
4078 /* If we either finished a single-step or hit a breakpoint, but
4079 the user wanted this thread to be stopped, pretend we got a
4080 SIG0 (generic unsignaled stop). */
4081 if (ecs
->event_thread
->stop_requested
4082 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4083 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4085 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4089 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
4090 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
4091 struct cleanup
*old_chain
= save_inferior_ptid ();
4093 inferior_ptid
= ecs
->ptid
;
4095 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
4096 paddress (gdbarch
, stop_pc
));
4097 if (target_stopped_by_watchpoint ())
4101 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
4103 if (target_stopped_data_address (¤t_target
, &addr
))
4104 fprintf_unfiltered (gdb_stdlog
,
4105 "infrun: stopped data address = %s\n",
4106 paddress (gdbarch
, addr
));
4108 fprintf_unfiltered (gdb_stdlog
,
4109 "infrun: (no data address available)\n");
4112 do_cleanups (old_chain
);
4115 /* This is originated from start_remote(), start_inferior() and
4116 shared libraries hook functions. */
4117 stop_soon
= get_inferior_stop_soon (ecs
->ptid
);
4118 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
4120 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4121 context_switch (ecs
->ptid
);
4123 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
4124 stop_print_frame
= 1;
4129 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4132 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4133 context_switch (ecs
->ptid
);
4135 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
4136 stop_print_frame
= 0;
4141 /* This originates from attach_command(). We need to overwrite
4142 the stop_signal here, because some kernels don't ignore a
4143 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4144 See more comments in inferior.h. On the other hand, if we
4145 get a non-SIGSTOP, report it to the user - assume the backend
4146 will handle the SIGSTOP if it should show up later.
4148 Also consider that the attach is complete when we see a
4149 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4150 target extended-remote report it instead of a SIGSTOP
4151 (e.g. gdbserver). We already rely on SIGTRAP being our
4152 signal, so this is no exception.
4154 Also consider that the attach is complete when we see a
4155 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4156 the target to stop all threads of the inferior, in case the
4157 low level attach operation doesn't stop them implicitly. If
4158 they weren't stopped implicitly, then the stub will report a
4159 GDB_SIGNAL_0, meaning: stopped for no particular reason
4160 other than GDB's request. */
4161 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
4162 && (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_STOP
4163 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4164 || ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_0
))
4166 stop_print_frame
= 1;
4168 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4172 /* See if something interesting happened to the non-current thread. If
4173 so, then switch to that thread. */
4174 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
4177 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
4179 context_switch (ecs
->ptid
);
4181 if (deprecated_context_hook
)
4182 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
4185 /* At this point, get hold of the now-current thread's frame. */
4186 frame
= get_current_frame ();
4187 gdbarch
= get_frame_arch (frame
);
4189 /* Pull the single step breakpoints out of the target. */
4190 if (singlestep_breakpoints_inserted_p
)
4192 /* However, before doing so, if this single-step breakpoint was
4193 actually for another thread, set this thread up for moving
4195 if (!ptid_equal (ecs
->ptid
, singlestep_ptid
)
4196 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
)
4198 struct regcache
*regcache
;
4199 struct address_space
*aspace
;
4202 regcache
= get_thread_regcache (ecs
->ptid
);
4203 aspace
= get_regcache_aspace (regcache
);
4204 pc
= regcache_read_pc (regcache
);
4205 if (single_step_breakpoint_inserted_here_p (aspace
, pc
))
4209 fprintf_unfiltered (gdb_stdlog
,
4210 "infrun: [%s] hit step over single-step"
4211 " breakpoint of [%s]\n",
4212 target_pid_to_str (ecs
->ptid
),
4213 target_pid_to_str (singlestep_ptid
));
4215 ecs
->hit_singlestep_breakpoint
= 1;
4219 remove_single_step_breakpoints ();
4220 singlestep_breakpoints_inserted_p
= 0;
4223 if (ecs
->stepped_after_stopped_by_watchpoint
)
4224 stopped_by_watchpoint
= 0;
4226 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
4228 /* If necessary, step over this watchpoint. We'll be back to display
4230 if (stopped_by_watchpoint
4231 && (target_have_steppable_watchpoint
4232 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
4234 /* At this point, we are stopped at an instruction which has
4235 attempted to write to a piece of memory under control of
4236 a watchpoint. The instruction hasn't actually executed
4237 yet. If we were to evaluate the watchpoint expression
4238 now, we would get the old value, and therefore no change
4239 would seem to have occurred.
4241 In order to make watchpoints work `right', we really need
4242 to complete the memory write, and then evaluate the
4243 watchpoint expression. We do this by single-stepping the
4246 It may not be necessary to disable the watchpoint to step over
4247 it. For example, the PA can (with some kernel cooperation)
4248 single step over a watchpoint without disabling the watchpoint.
4250 It is far more common to need to disable a watchpoint to step
4251 the inferior over it. If we have non-steppable watchpoints,
4252 we must disable the current watchpoint; it's simplest to
4253 disable all watchpoints and breakpoints. */
4256 if (!target_have_steppable_watchpoint
)
4258 remove_breakpoints ();
4259 /* See comment in resume why we need to stop bypassing signals
4260 while breakpoints have been removed. */
4261 target_pass_signals (0, NULL
);
4264 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
4265 target_resume (ecs
->ptid
, hw_step
, GDB_SIGNAL_0
);
4266 waiton_ptid
= ecs
->ptid
;
4267 if (target_have_steppable_watchpoint
)
4268 infwait_state
= infwait_step_watch_state
;
4270 infwait_state
= infwait_nonstep_watch_state
;
4271 prepare_to_wait (ecs
);
4275 ecs
->event_thread
->stepping_over_breakpoint
= 0;
4276 bpstat_clear (&ecs
->event_thread
->control
.stop_bpstat
);
4277 ecs
->event_thread
->control
.stop_step
= 0;
4278 stop_print_frame
= 1;
4279 stopped_by_random_signal
= 0;
4281 /* Hide inlined functions starting here, unless we just performed stepi or
4282 nexti. After stepi and nexti, always show the innermost frame (not any
4283 inline function call sites). */
4284 if (ecs
->event_thread
->control
.step_range_end
!= 1)
4286 struct address_space
*aspace
=
4287 get_regcache_aspace (get_thread_regcache (ecs
->ptid
));
4289 /* skip_inline_frames is expensive, so we avoid it if we can
4290 determine that the address is one where functions cannot have
4291 been inlined. This improves performance with inferiors that
4292 load a lot of shared libraries, because the solib event
4293 breakpoint is defined as the address of a function (i.e. not
4294 inline). Note that we have to check the previous PC as well
4295 as the current one to catch cases when we have just
4296 single-stepped off a breakpoint prior to reinstating it.
4297 Note that we're assuming that the code we single-step to is
4298 not inline, but that's not definitive: there's nothing
4299 preventing the event breakpoint function from containing
4300 inlined code, and the single-step ending up there. If the
4301 user had set a breakpoint on that inlined code, the missing
4302 skip_inline_frames call would break things. Fortunately
4303 that's an extremely unlikely scenario. */
4304 if (!pc_at_non_inline_function (aspace
, stop_pc
, &ecs
->ws
)
4305 && !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4306 && ecs
->event_thread
->control
.trap_expected
4307 && pc_at_non_inline_function (aspace
,
4308 ecs
->event_thread
->prev_pc
,
4311 skip_inline_frames (ecs
->ptid
);
4313 /* Re-fetch current thread's frame in case that invalidated
4315 frame
= get_current_frame ();
4316 gdbarch
= get_frame_arch (frame
);
4320 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4321 && ecs
->event_thread
->control
.trap_expected
4322 && gdbarch_single_step_through_delay_p (gdbarch
)
4323 && currently_stepping (ecs
->event_thread
))
4325 /* We're trying to step off a breakpoint. Turns out that we're
4326 also on an instruction that needs to be stepped multiple
4327 times before it's been fully executing. E.g., architectures
4328 with a delay slot. It needs to be stepped twice, once for
4329 the instruction and once for the delay slot. */
4330 int step_through_delay
4331 = gdbarch_single_step_through_delay (gdbarch
, frame
);
4333 if (debug_infrun
&& step_through_delay
)
4334 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
4335 if (ecs
->event_thread
->control
.step_range_end
== 0
4336 && step_through_delay
)
4338 /* The user issued a continue when stopped at a breakpoint.
4339 Set up for another trap and get out of here. */
4340 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4344 else if (step_through_delay
)
4346 /* The user issued a step when stopped at a breakpoint.
4347 Maybe we should stop, maybe we should not - the delay
4348 slot *might* correspond to a line of source. In any
4349 case, don't decide that here, just set
4350 ecs->stepping_over_breakpoint, making sure we
4351 single-step again before breakpoints are re-inserted. */
4352 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4356 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4357 handles this event. */
4358 ecs
->event_thread
->control
.stop_bpstat
4359 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4360 stop_pc
, ecs
->ptid
, &ecs
->ws
);
4362 /* Following in case break condition called a
4364 stop_print_frame
= 1;
4366 /* This is where we handle "moribund" watchpoints. Unlike
4367 software breakpoints traps, hardware watchpoint traps are
4368 always distinguishable from random traps. If no high-level
4369 watchpoint is associated with the reported stop data address
4370 anymore, then the bpstat does not explain the signal ---
4371 simply make sure to ignore it if `stopped_by_watchpoint' is
4375 && ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4376 && !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4378 && stopped_by_watchpoint
)
4379 fprintf_unfiltered (gdb_stdlog
,
4380 "infrun: no user watchpoint explains "
4381 "watchpoint SIGTRAP, ignoring\n");
4383 /* NOTE: cagney/2003-03-29: These checks for a random signal
4384 at one stage in the past included checks for an inferior
4385 function call's call dummy's return breakpoint. The original
4386 comment, that went with the test, read:
4388 ``End of a stack dummy. Some systems (e.g. Sony news) give
4389 another signal besides SIGTRAP, so check here as well as
4392 If someone ever tries to get call dummys on a
4393 non-executable stack to work (where the target would stop
4394 with something like a SIGSEGV), then those tests might need
4395 to be re-instated. Given, however, that the tests were only
4396 enabled when momentary breakpoints were not being used, I
4397 suspect that it won't be the case.
4399 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4400 be necessary for call dummies on a non-executable stack on
4403 /* See if the breakpoints module can explain the signal. */
4405 = !bpstat_explains_signal (ecs
->event_thread
->control
.stop_bpstat
,
4406 ecs
->event_thread
->suspend
.stop_signal
);
4408 /* If not, perhaps stepping/nexting can. */
4410 random_signal
= !(ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
4411 && currently_stepping (ecs
->event_thread
));
4413 /* Perhaps the thread hit a single-step breakpoint of _another_
4414 thread. Single-step breakpoints are transparent to the
4415 breakpoints module. */
4417 random_signal
= !ecs
->hit_singlestep_breakpoint
;
4419 /* No? Perhaps we got a moribund watchpoint. */
4421 random_signal
= !stopped_by_watchpoint
;
4423 /* For the program's own signals, act according to
4424 the signal handling tables. */
4428 /* Signal not for debugging purposes. */
4430 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
4431 enum gdb_signal stop_signal
= ecs
->event_thread
->suspend
.stop_signal
;
4434 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal (%s)\n",
4435 gdb_signal_to_symbol_string (stop_signal
));
4437 stopped_by_random_signal
= 1;
4439 /* Always stop on signals if we're either just gaining control
4440 of the program, or the user explicitly requested this thread
4441 to remain stopped. */
4442 if (stop_soon
!= NO_STOP_QUIETLY
4443 || ecs
->event_thread
->stop_requested
4445 && signal_stop_state (ecs
->event_thread
->suspend
.stop_signal
)))
4451 /* Notify observers the signal has "handle print" set. Note we
4452 returned early above if stopping; normal_stop handles the
4453 printing in that case. */
4454 if (signal_print
[ecs
->event_thread
->suspend
.stop_signal
])
4456 /* The signal table tells us to print about this signal. */
4457 target_terminal_ours_for_output ();
4458 observer_notify_signal_received (ecs
->event_thread
->suspend
.stop_signal
);
4459 target_terminal_inferior ();
4462 /* Clear the signal if it should not be passed. */
4463 if (signal_program
[ecs
->event_thread
->suspend
.stop_signal
] == 0)
4464 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
4466 if (ecs
->event_thread
->prev_pc
== stop_pc
4467 && ecs
->event_thread
->control
.trap_expected
4468 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4470 /* We were just starting a new sequence, attempting to
4471 single-step off of a breakpoint and expecting a SIGTRAP.
4472 Instead this signal arrives. This signal will take us out
4473 of the stepping range so GDB needs to remember to, when
4474 the signal handler returns, resume stepping off that
4476 /* To simplify things, "continue" is forced to use the same
4477 code paths as single-step - set a breakpoint at the
4478 signal return address and then, once hit, step off that
4481 fprintf_unfiltered (gdb_stdlog
,
4482 "infrun: signal arrived while stepping over "
4485 insert_hp_step_resume_breakpoint_at_frame (frame
);
4486 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
4487 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4488 ecs
->event_thread
->control
.trap_expected
= 0;
4490 /* If we were nexting/stepping some other thread, switch to
4491 it, so that we don't continue it, losing control. */
4492 if (!switch_back_to_stepped_thread (ecs
))
4497 if (ecs
->event_thread
->control
.step_range_end
!= 0
4498 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_0
4499 && pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4500 && frame_id_eq (get_stack_frame_id (frame
),
4501 ecs
->event_thread
->control
.step_stack_frame_id
)
4502 && ecs
->event_thread
->control
.step_resume_breakpoint
== NULL
)
4504 /* The inferior is about to take a signal that will take it
4505 out of the single step range. Set a breakpoint at the
4506 current PC (which is presumably where the signal handler
4507 will eventually return) and then allow the inferior to
4510 Note that this is only needed for a signal delivered
4511 while in the single-step range. Nested signals aren't a
4512 problem as they eventually all return. */
4514 fprintf_unfiltered (gdb_stdlog
,
4515 "infrun: signal may take us out of "
4516 "single-step range\n");
4518 insert_hp_step_resume_breakpoint_at_frame (frame
);
4519 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4520 ecs
->event_thread
->control
.trap_expected
= 0;
4525 /* Note: step_resume_breakpoint may be non-NULL. This occures
4526 when either there's a nested signal, or when there's a
4527 pending signal enabled just as the signal handler returns
4528 (leaving the inferior at the step-resume-breakpoint without
4529 actually executing it). Either way continue until the
4530 breakpoint is really hit. */
4532 if (!switch_back_to_stepped_thread (ecs
))
4535 fprintf_unfiltered (gdb_stdlog
,
4536 "infrun: random signal, keep going\n");
4543 process_event_stop_test (ecs
);
4546 /* Come here when we've got some debug event / signal we can explain
4547 (IOW, not a random signal), and test whether it should cause a
4548 stop, or whether we should resume the inferior (transparently).
4549 E.g., could be a breakpoint whose condition evaluates false; we
4550 could be still stepping within the line; etc. */
4553 process_event_stop_test (struct execution_control_state
*ecs
)
4555 struct symtab_and_line stop_pc_sal
;
4556 struct frame_info
*frame
;
4557 struct gdbarch
*gdbarch
;
4558 CORE_ADDR jmp_buf_pc
;
4559 struct bpstat_what what
;
4561 /* Handle cases caused by hitting a breakpoint. */
4563 frame
= get_current_frame ();
4564 gdbarch
= get_frame_arch (frame
);
4566 what
= bpstat_what (ecs
->event_thread
->control
.stop_bpstat
);
4568 if (what
.call_dummy
)
4570 stop_stack_dummy
= what
.call_dummy
;
4573 /* If we hit an internal event that triggers symbol changes, the
4574 current frame will be invalidated within bpstat_what (e.g., if we
4575 hit an internal solib event). Re-fetch it. */
4576 frame
= get_current_frame ();
4577 gdbarch
= get_frame_arch (frame
);
4579 switch (what
.main_action
)
4581 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
4582 /* If we hit the breakpoint at longjmp while stepping, we
4583 install a momentary breakpoint at the target of the
4587 fprintf_unfiltered (gdb_stdlog
,
4588 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4590 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4592 if (what
.is_longjmp
)
4594 struct value
*arg_value
;
4596 /* If we set the longjmp breakpoint via a SystemTap probe,
4597 then use it to extract the arguments. The destination PC
4598 is the third argument to the probe. */
4599 arg_value
= probe_safe_evaluate_at_pc (frame
, 2);
4601 jmp_buf_pc
= value_as_address (arg_value
);
4602 else if (!gdbarch_get_longjmp_target_p (gdbarch
)
4603 || !gdbarch_get_longjmp_target (gdbarch
,
4604 frame
, &jmp_buf_pc
))
4607 fprintf_unfiltered (gdb_stdlog
,
4608 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4609 "(!gdbarch_get_longjmp_target)\n");
4614 /* Insert a breakpoint at resume address. */
4615 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
4618 check_exception_resume (ecs
, frame
);
4622 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
4624 struct frame_info
*init_frame
;
4626 /* There are several cases to consider.
4628 1. The initiating frame no longer exists. In this case we
4629 must stop, because the exception or longjmp has gone too
4632 2. The initiating frame exists, and is the same as the
4633 current frame. We stop, because the exception or longjmp
4636 3. The initiating frame exists and is different from the
4637 current frame. This means the exception or longjmp has
4638 been caught beneath the initiating frame, so keep going.
4640 4. longjmp breakpoint has been placed just to protect
4641 against stale dummy frames and user is not interested in
4642 stopping around longjmps. */
4645 fprintf_unfiltered (gdb_stdlog
,
4646 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4648 gdb_assert (ecs
->event_thread
->control
.exception_resume_breakpoint
4650 delete_exception_resume_breakpoint (ecs
->event_thread
);
4652 if (what
.is_longjmp
)
4654 check_longjmp_breakpoint_for_call_dummy (ecs
->event_thread
);
4656 if (!frame_id_p (ecs
->event_thread
->initiating_frame
))
4664 init_frame
= frame_find_by_id (ecs
->event_thread
->initiating_frame
);
4668 struct frame_id current_id
4669 = get_frame_id (get_current_frame ());
4670 if (frame_id_eq (current_id
,
4671 ecs
->event_thread
->initiating_frame
))
4673 /* Case 2. Fall through. */
4683 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4685 delete_step_resume_breakpoint (ecs
->event_thread
);
4687 end_stepping_range (ecs
);
4691 case BPSTAT_WHAT_SINGLE
:
4693 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
4694 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4695 /* Still need to check other stuff, at least the case where we
4696 are stepping and step out of the right range. */
4699 case BPSTAT_WHAT_STEP_RESUME
:
4701 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4703 delete_step_resume_breakpoint (ecs
->event_thread
);
4704 if (ecs
->event_thread
->control
.proceed_to_finish
4705 && execution_direction
== EXEC_REVERSE
)
4707 struct thread_info
*tp
= ecs
->event_thread
;
4709 /* We are finishing a function in reverse, and just hit the
4710 step-resume breakpoint at the start address of the
4711 function, and we're almost there -- just need to back up
4712 by one more single-step, which should take us back to the
4714 tp
->control
.step_range_start
= tp
->control
.step_range_end
= 1;
4718 fill_in_stop_func (gdbarch
, ecs
);
4719 if (stop_pc
== ecs
->stop_func_start
4720 && execution_direction
== EXEC_REVERSE
)
4722 /* We are stepping over a function call in reverse, and just
4723 hit the step-resume breakpoint at the start address of
4724 the function. Go back to single-stepping, which should
4725 take us back to the function call. */
4726 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4732 case BPSTAT_WHAT_STOP_NOISY
:
4734 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4735 stop_print_frame
= 1;
4737 /* Assume the thread stopped for a breapoint. We'll still check
4738 whether a/the breakpoint is there when the thread is next
4740 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4745 case BPSTAT_WHAT_STOP_SILENT
:
4747 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4748 stop_print_frame
= 0;
4750 /* Assume the thread stopped for a breapoint. We'll still check
4751 whether a/the breakpoint is there when the thread is next
4753 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4757 case BPSTAT_WHAT_HP_STEP_RESUME
:
4759 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4761 delete_step_resume_breakpoint (ecs
->event_thread
);
4762 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
4764 /* Back when the step-resume breakpoint was inserted, we
4765 were trying to single-step off a breakpoint. Go back to
4767 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
4768 ecs
->event_thread
->stepping_over_breakpoint
= 1;
4774 case BPSTAT_WHAT_KEEP_CHECKING
:
4778 /* We come here if we hit a breakpoint but should not stop for it.
4779 Possibly we also were stepping and should stop for that. So fall
4780 through and test for stepping. But, if not stepping, do not
4783 /* In all-stop mode, if we're currently stepping but have stopped in
4784 some other thread, we need to switch back to the stepped thread. */
4785 if (switch_back_to_stepped_thread (ecs
))
4788 if (ecs
->event_thread
->control
.step_resume_breakpoint
)
4791 fprintf_unfiltered (gdb_stdlog
,
4792 "infrun: step-resume breakpoint is inserted\n");
4794 /* Having a step-resume breakpoint overrides anything
4795 else having to do with stepping commands until
4796 that breakpoint is reached. */
4801 if (ecs
->event_thread
->control
.step_range_end
== 0)
4804 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
4805 /* Likewise if we aren't even stepping. */
4810 /* Re-fetch current thread's frame in case the code above caused
4811 the frame cache to be re-initialized, making our FRAME variable
4812 a dangling pointer. */
4813 frame
= get_current_frame ();
4814 gdbarch
= get_frame_arch (frame
);
4815 fill_in_stop_func (gdbarch
, ecs
);
4817 /* If stepping through a line, keep going if still within it.
4819 Note that step_range_end is the address of the first instruction
4820 beyond the step range, and NOT the address of the last instruction
4823 Note also that during reverse execution, we may be stepping
4824 through a function epilogue and therefore must detect when
4825 the current-frame changes in the middle of a line. */
4827 if (pc_in_thread_step_range (stop_pc
, ecs
->event_thread
)
4828 && (execution_direction
!= EXEC_REVERSE
4829 || frame_id_eq (get_frame_id (frame
),
4830 ecs
->event_thread
->control
.step_frame_id
)))
4834 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
4835 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_start
),
4836 paddress (gdbarch
, ecs
->event_thread
->control
.step_range_end
));
4838 /* Tentatively re-enable range stepping; `resume' disables it if
4839 necessary (e.g., if we're stepping over a breakpoint or we
4840 have software watchpoints). */
4841 ecs
->event_thread
->control
.may_range_step
= 1;
4843 /* When stepping backward, stop at beginning of line range
4844 (unless it's the function entry point, in which case
4845 keep going back to the call point). */
4846 if (stop_pc
== ecs
->event_thread
->control
.step_range_start
4847 && stop_pc
!= ecs
->stop_func_start
4848 && execution_direction
== EXEC_REVERSE
)
4849 end_stepping_range (ecs
);
4856 /* We stepped out of the stepping range. */
4858 /* If we are stepping at the source level and entered the runtime
4859 loader dynamic symbol resolution code...
4861 EXEC_FORWARD: we keep on single stepping until we exit the run
4862 time loader code and reach the callee's address.
4864 EXEC_REVERSE: we've already executed the callee (backward), and
4865 the runtime loader code is handled just like any other
4866 undebuggable function call. Now we need only keep stepping
4867 backward through the trampoline code, and that's handled further
4868 down, so there is nothing for us to do here. */
4870 if (execution_direction
!= EXEC_REVERSE
4871 && ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4872 && in_solib_dynsym_resolve_code (stop_pc
))
4874 CORE_ADDR pc_after_resolver
=
4875 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
4878 fprintf_unfiltered (gdb_stdlog
,
4879 "infrun: stepped into dynsym resolve code\n");
4881 if (pc_after_resolver
)
4883 /* Set up a step-resume breakpoint at the address
4884 indicated by SKIP_SOLIB_RESOLVER. */
4885 struct symtab_and_line sr_sal
;
4888 sr_sal
.pc
= pc_after_resolver
;
4889 sr_sal
.pspace
= get_frame_program_space (frame
);
4891 insert_step_resume_breakpoint_at_sal (gdbarch
,
4892 sr_sal
, null_frame_id
);
4899 if (ecs
->event_thread
->control
.step_range_end
!= 1
4900 && (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
4901 || ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
4902 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
4905 fprintf_unfiltered (gdb_stdlog
,
4906 "infrun: stepped into signal trampoline\n");
4907 /* The inferior, while doing a "step" or "next", has ended up in
4908 a signal trampoline (either by a signal being delivered or by
4909 the signal handler returning). Just single-step until the
4910 inferior leaves the trampoline (either by calling the handler
4916 /* If we're in the return path from a shared library trampoline,
4917 we want to proceed through the trampoline when stepping. */
4918 /* macro/2012-04-25: This needs to come before the subroutine
4919 call check below as on some targets return trampolines look
4920 like subroutine calls (MIPS16 return thunks). */
4921 if (gdbarch_in_solib_return_trampoline (gdbarch
,
4922 stop_pc
, ecs
->stop_func_name
)
4923 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
4925 /* Determine where this trampoline returns. */
4926 CORE_ADDR real_stop_pc
;
4928 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
4931 fprintf_unfiltered (gdb_stdlog
,
4932 "infrun: stepped into solib return tramp\n");
4934 /* Only proceed through if we know where it's going. */
4937 /* And put the step-breakpoint there and go until there. */
4938 struct symtab_and_line sr_sal
;
4940 init_sal (&sr_sal
); /* initialize to zeroes */
4941 sr_sal
.pc
= real_stop_pc
;
4942 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4943 sr_sal
.pspace
= get_frame_program_space (frame
);
4945 /* Do not specify what the fp should be when we stop since
4946 on some machines the prologue is where the new fp value
4948 insert_step_resume_breakpoint_at_sal (gdbarch
,
4949 sr_sal
, null_frame_id
);
4951 /* Restart without fiddling with the step ranges or
4958 /* Check for subroutine calls. The check for the current frame
4959 equalling the step ID is not necessary - the check of the
4960 previous frame's ID is sufficient - but it is a common case and
4961 cheaper than checking the previous frame's ID.
4963 NOTE: frame_id_eq will never report two invalid frame IDs as
4964 being equal, so to get into this block, both the current and
4965 previous frame must have valid frame IDs. */
4966 /* The outer_frame_id check is a heuristic to detect stepping
4967 through startup code. If we step over an instruction which
4968 sets the stack pointer from an invalid value to a valid value,
4969 we may detect that as a subroutine call from the mythical
4970 "outermost" function. This could be fixed by marking
4971 outermost frames as !stack_p,code_p,special_p. Then the
4972 initial outermost frame, before sp was valid, would
4973 have code_addr == &_start. See the comment in frame_id_eq
4975 if (!frame_id_eq (get_stack_frame_id (frame
),
4976 ecs
->event_thread
->control
.step_stack_frame_id
)
4977 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4978 ecs
->event_thread
->control
.step_stack_frame_id
)
4979 && (!frame_id_eq (ecs
->event_thread
->control
.step_stack_frame_id
,
4981 || step_start_function
!= find_pc_function (stop_pc
))))
4983 CORE_ADDR real_stop_pc
;
4986 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
4988 if ((ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_NONE
)
4989 || ((ecs
->event_thread
->control
.step_range_end
== 1)
4990 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
4991 ecs
->stop_func_start
)))
4993 /* I presume that step_over_calls is only 0 when we're
4994 supposed to be stepping at the assembly language level
4995 ("stepi"). Just stop. */
4996 /* Also, maybe we just did a "nexti" inside a prolog, so we
4997 thought it was a subroutine call but it was not. Stop as
4999 /* And this works the same backward as frontward. MVS */
5000 end_stepping_range (ecs
);
5004 /* Reverse stepping through solib trampolines. */
5006 if (execution_direction
== EXEC_REVERSE
5007 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
5008 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5009 || (ecs
->stop_func_start
== 0
5010 && in_solib_dynsym_resolve_code (stop_pc
))))
5012 /* Any solib trampoline code can be handled in reverse
5013 by simply continuing to single-step. We have already
5014 executed the solib function (backwards), and a few
5015 steps will take us back through the trampoline to the
5021 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5023 /* We're doing a "next".
5025 Normal (forward) execution: set a breakpoint at the
5026 callee's return address (the address at which the caller
5029 Reverse (backward) execution. set the step-resume
5030 breakpoint at the start of the function that we just
5031 stepped into (backwards), and continue to there. When we
5032 get there, we'll need to single-step back to the caller. */
5034 if (execution_direction
== EXEC_REVERSE
)
5036 /* If we're already at the start of the function, we've either
5037 just stepped backward into a single instruction function,
5038 or stepped back out of a signal handler to the first instruction
5039 of the function. Just keep going, which will single-step back
5041 if (ecs
->stop_func_start
!= stop_pc
&& ecs
->stop_func_start
!= 0)
5043 struct symtab_and_line sr_sal
;
5045 /* Normal function call return (static or dynamic). */
5047 sr_sal
.pc
= ecs
->stop_func_start
;
5048 sr_sal
.pspace
= get_frame_program_space (frame
);
5049 insert_step_resume_breakpoint_at_sal (gdbarch
,
5050 sr_sal
, null_frame_id
);
5054 insert_step_resume_breakpoint_at_caller (frame
);
5060 /* If we are in a function call trampoline (a stub between the
5061 calling routine and the real function), locate the real
5062 function. That's what tells us (a) whether we want to step
5063 into it at all, and (b) what prologue we want to run to the
5064 end of, if we do step into it. */
5065 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
5066 if (real_stop_pc
== 0)
5067 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
5068 if (real_stop_pc
!= 0)
5069 ecs
->stop_func_start
= real_stop_pc
;
5071 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
5073 struct symtab_and_line sr_sal
;
5076 sr_sal
.pc
= ecs
->stop_func_start
;
5077 sr_sal
.pspace
= get_frame_program_space (frame
);
5079 insert_step_resume_breakpoint_at_sal (gdbarch
,
5080 sr_sal
, null_frame_id
);
5085 /* If we have line number information for the function we are
5086 thinking of stepping into and the function isn't on the skip
5089 If there are several symtabs at that PC (e.g. with include
5090 files), just want to know whether *any* of them have line
5091 numbers. find_pc_line handles this. */
5093 struct symtab_and_line tmp_sal
;
5095 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5096 if (tmp_sal
.line
!= 0
5097 && !function_name_is_marked_for_skip (ecs
->stop_func_name
,
5100 if (execution_direction
== EXEC_REVERSE
)
5101 handle_step_into_function_backward (gdbarch
, ecs
);
5103 handle_step_into_function (gdbarch
, ecs
);
5108 /* If we have no line number and the step-stop-if-no-debug is
5109 set, we stop the step so that the user has a chance to switch
5110 in assembly mode. */
5111 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5112 && step_stop_if_no_debug
)
5114 end_stepping_range (ecs
);
5118 if (execution_direction
== EXEC_REVERSE
)
5120 /* If we're already at the start of the function, we've either just
5121 stepped backward into a single instruction function without line
5122 number info, or stepped back out of a signal handler to the first
5123 instruction of the function without line number info. Just keep
5124 going, which will single-step back to the caller. */
5125 if (ecs
->stop_func_start
!= stop_pc
)
5127 /* Set a breakpoint at callee's start address.
5128 From there we can step once and be back in the caller. */
5129 struct symtab_and_line sr_sal
;
5132 sr_sal
.pc
= ecs
->stop_func_start
;
5133 sr_sal
.pspace
= get_frame_program_space (frame
);
5134 insert_step_resume_breakpoint_at_sal (gdbarch
,
5135 sr_sal
, null_frame_id
);
5139 /* Set a breakpoint at callee's return address (the address
5140 at which the caller will resume). */
5141 insert_step_resume_breakpoint_at_caller (frame
);
5147 /* Reverse stepping through solib trampolines. */
5149 if (execution_direction
== EXEC_REVERSE
5150 && ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_NONE
)
5152 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
5153 || (ecs
->stop_func_start
== 0
5154 && in_solib_dynsym_resolve_code (stop_pc
)))
5156 /* Any solib trampoline code can be handled in reverse
5157 by simply continuing to single-step. We have already
5158 executed the solib function (backwards), and a few
5159 steps will take us back through the trampoline to the
5164 else if (in_solib_dynsym_resolve_code (stop_pc
))
5166 /* Stepped backward into the solib dynsym resolver.
5167 Set a breakpoint at its start and continue, then
5168 one more step will take us out. */
5169 struct symtab_and_line sr_sal
;
5172 sr_sal
.pc
= ecs
->stop_func_start
;
5173 sr_sal
.pspace
= get_frame_program_space (frame
);
5174 insert_step_resume_breakpoint_at_sal (gdbarch
,
5175 sr_sal
, null_frame_id
);
5181 stop_pc_sal
= find_pc_line (stop_pc
, 0);
5183 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5184 the trampoline processing logic, however, there are some trampolines
5185 that have no names, so we should do trampoline handling first. */
5186 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_UNDEBUGGABLE
5187 && ecs
->stop_func_name
== NULL
5188 && stop_pc_sal
.line
== 0)
5191 fprintf_unfiltered (gdb_stdlog
,
5192 "infrun: stepped into undebuggable function\n");
5194 /* The inferior just stepped into, or returned to, an
5195 undebuggable function (where there is no debugging information
5196 and no line number corresponding to the address where the
5197 inferior stopped). Since we want to skip this kind of code,
5198 we keep going until the inferior returns from this
5199 function - unless the user has asked us not to (via
5200 set step-mode) or we no longer know how to get back
5201 to the call site. */
5202 if (step_stop_if_no_debug
5203 || !frame_id_p (frame_unwind_caller_id (frame
)))
5205 /* If we have no line number and the step-stop-if-no-debug
5206 is set, we stop the step so that the user has a chance to
5207 switch in assembly mode. */
5208 end_stepping_range (ecs
);
5213 /* Set a breakpoint at callee's return address (the address
5214 at which the caller will resume). */
5215 insert_step_resume_breakpoint_at_caller (frame
);
5221 if (ecs
->event_thread
->control
.step_range_end
== 1)
5223 /* It is stepi or nexti. We always want to stop stepping after
5226 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
5227 end_stepping_range (ecs
);
5231 if (stop_pc_sal
.line
== 0)
5233 /* We have no line number information. That means to stop
5234 stepping (does this always happen right after one instruction,
5235 when we do "s" in a function with no line numbers,
5236 or can this happen as a result of a return or longjmp?). */
5238 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
5239 end_stepping_range (ecs
);
5243 /* Look for "calls" to inlined functions, part one. If the inline
5244 frame machinery detected some skipped call sites, we have entered
5245 a new inline function. */
5247 if (frame_id_eq (get_frame_id (get_current_frame ()),
5248 ecs
->event_thread
->control
.step_frame_id
)
5249 && inline_skipped_frames (ecs
->ptid
))
5251 struct symtab_and_line call_sal
;
5254 fprintf_unfiltered (gdb_stdlog
,
5255 "infrun: stepped into inlined function\n");
5257 find_frame_sal (get_current_frame (), &call_sal
);
5259 if (ecs
->event_thread
->control
.step_over_calls
!= STEP_OVER_ALL
)
5261 /* For "step", we're going to stop. But if the call site
5262 for this inlined function is on the same source line as
5263 we were previously stepping, go down into the function
5264 first. Otherwise stop at the call site. */
5266 if (call_sal
.line
== ecs
->event_thread
->current_line
5267 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5268 step_into_inline_frame (ecs
->ptid
);
5270 end_stepping_range (ecs
);
5275 /* For "next", we should stop at the call site if it is on a
5276 different source line. Otherwise continue through the
5277 inlined function. */
5278 if (call_sal
.line
== ecs
->event_thread
->current_line
5279 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
5282 end_stepping_range (ecs
);
5287 /* Look for "calls" to inlined functions, part two. If we are still
5288 in the same real function we were stepping through, but we have
5289 to go further up to find the exact frame ID, we are stepping
5290 through a more inlined call beyond its call site. */
5292 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5293 && !frame_id_eq (get_frame_id (get_current_frame ()),
5294 ecs
->event_thread
->control
.step_frame_id
)
5295 && stepped_in_from (get_current_frame (),
5296 ecs
->event_thread
->control
.step_frame_id
))
5299 fprintf_unfiltered (gdb_stdlog
,
5300 "infrun: stepping through inlined function\n");
5302 if (ecs
->event_thread
->control
.step_over_calls
== STEP_OVER_ALL
)
5305 end_stepping_range (ecs
);
5309 if ((stop_pc
== stop_pc_sal
.pc
)
5310 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
5311 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
5313 /* We are at the start of a different line. So stop. Note that
5314 we don't stop if we step into the middle of a different line.
5315 That is said to make things like for (;;) statements work
5318 fprintf_unfiltered (gdb_stdlog
,
5319 "infrun: stepped to a different line\n");
5320 end_stepping_range (ecs
);
5324 /* We aren't done stepping.
5326 Optimize by setting the stepping range to the line.
5327 (We might not be in the original line, but if we entered a
5328 new line in mid-statement, we continue stepping. This makes
5329 things like for(;;) statements work better.) */
5331 ecs
->event_thread
->control
.step_range_start
= stop_pc_sal
.pc
;
5332 ecs
->event_thread
->control
.step_range_end
= stop_pc_sal
.end
;
5333 ecs
->event_thread
->control
.may_range_step
= 1;
5334 set_step_info (frame
, stop_pc_sal
);
5337 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
5341 /* In all-stop mode, if we're currently stepping but have stopped in
5342 some other thread, we may need to switch back to the stepped
5343 thread. Returns true we set the inferior running, false if we left
5344 it stopped (and the event needs further processing). */
5347 switch_back_to_stepped_thread (struct execution_control_state
*ecs
)
5351 struct thread_info
*tp
;
5352 struct thread_info
*stepping_thread
;
5353 struct thread_info
*step_over
;
5355 /* If any thread is blocked on some internal breakpoint, and we
5356 simply need to step over that breakpoint to get it going
5357 again, do that first. */
5359 /* However, if we see an event for the stepping thread, then we
5360 know all other threads have been moved past their breakpoints
5361 already. Let the caller check whether the step is finished,
5362 etc., before deciding to move it past a breakpoint. */
5363 if (ecs
->event_thread
->control
.step_range_end
!= 0)
5366 /* Check if the current thread is blocked on an incomplete
5367 step-over, interrupted by a random signal. */
5368 if (ecs
->event_thread
->control
.trap_expected
5369 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5373 fprintf_unfiltered (gdb_stdlog
,
5374 "infrun: need to finish step-over of [%s]\n",
5375 target_pid_to_str (ecs
->event_thread
->ptid
));
5381 /* Check if the current thread is blocked by a single-step
5382 breakpoint of another thread. */
5383 if (ecs
->hit_singlestep_breakpoint
)
5387 fprintf_unfiltered (gdb_stdlog
,
5388 "infrun: need to step [%s] over single-step "
5390 target_pid_to_str (ecs
->ptid
));
5396 /* Otherwise, we no longer expect a trap in the current thread.
5397 Clear the trap_expected flag before switching back -- this is
5398 what keep_going does as well, if we call it. */
5399 ecs
->event_thread
->control
.trap_expected
= 0;
5401 /* Likewise, clear the signal if it should not be passed. */
5402 if (!signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
5403 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
5405 /* If scheduler locking applies even if not stepping, there's no
5406 need to walk over threads. Above we've checked whether the
5407 current thread is stepping. If some other thread not the
5408 event thread is stepping, then it must be that scheduler
5409 locking is not in effect. */
5410 if (schedlock_applies (0))
5413 /* Look for the stepping/nexting thread, and check if any other
5414 thread other than the stepping thread needs to start a
5415 step-over. Do all step-overs before actually proceeding with
5417 stepping_thread
= NULL
;
5419 ALL_NON_EXITED_THREADS (tp
)
5421 /* Ignore threads of processes we're not resuming. */
5423 && ptid_get_pid (tp
->ptid
) != ptid_get_pid (inferior_ptid
))
5426 /* When stepping over a breakpoint, we lock all threads
5427 except the one that needs to move past the breakpoint.
5428 If a non-event thread has this set, the "incomplete
5429 step-over" check above should have caught it earlier. */
5430 gdb_assert (!tp
->control
.trap_expected
);
5432 /* Did we find the stepping thread? */
5433 if (tp
->control
.step_range_end
)
5435 /* Yep. There should only one though. */
5436 gdb_assert (stepping_thread
== NULL
);
5438 /* The event thread is handled at the top, before we
5440 gdb_assert (tp
!= ecs
->event_thread
);
5442 /* If some thread other than the event thread is
5443 stepping, then scheduler locking can't be in effect,
5444 otherwise we wouldn't have resumed the current event
5445 thread in the first place. */
5446 gdb_assert (!schedlock_applies (1));
5448 stepping_thread
= tp
;
5450 else if (thread_still_needs_step_over (tp
))
5454 /* At the top we've returned early if the event thread
5455 is stepping. If some other thread not the event
5456 thread is stepping, then scheduler locking can't be
5457 in effect, and we can resume this thread. No need to
5458 keep looking for the stepping thread then. */
5463 if (step_over
!= NULL
)
5468 fprintf_unfiltered (gdb_stdlog
,
5469 "infrun: need to step-over [%s]\n",
5470 target_pid_to_str (tp
->ptid
));
5473 /* Only the stepping thread should have this set. */
5474 gdb_assert (tp
->control
.step_range_end
== 0);
5476 ecs
->ptid
= tp
->ptid
;
5477 ecs
->event_thread
= tp
;
5478 switch_to_thread (ecs
->ptid
);
5483 if (stepping_thread
!= NULL
)
5485 struct frame_info
*frame
;
5486 struct gdbarch
*gdbarch
;
5488 tp
= stepping_thread
;
5490 /* If the stepping thread exited, then don't try to switch
5491 back and resume it, which could fail in several different
5492 ways depending on the target. Instead, just keep going.
5494 We can find a stepping dead thread in the thread list in
5497 - The target supports thread exit events, and when the
5498 target tries to delete the thread from the thread list,
5499 inferior_ptid pointed at the exiting thread. In such
5500 case, calling delete_thread does not really remove the
5501 thread from the list; instead, the thread is left listed,
5502 with 'exited' state.
5504 - The target's debug interface does not support thread
5505 exit events, and so we have no idea whatsoever if the
5506 previously stepping thread is still alive. For that
5507 reason, we need to synchronously query the target
5509 if (is_exited (tp
->ptid
)
5510 || !target_thread_alive (tp
->ptid
))
5513 fprintf_unfiltered (gdb_stdlog
,
5514 "infrun: not switching back to "
5515 "stepped thread, it has vanished\n");
5517 delete_thread (tp
->ptid
);
5523 fprintf_unfiltered (gdb_stdlog
,
5524 "infrun: switching back to stepped thread\n");
5526 ecs
->event_thread
= tp
;
5527 ecs
->ptid
= tp
->ptid
;
5528 context_switch (ecs
->ptid
);
5530 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5531 frame
= get_current_frame ();
5532 gdbarch
= get_frame_arch (frame
);
5534 /* If the PC of the thread we were trying to single-step has
5535 changed, then that thread has trapped or been signaled,
5536 but the event has not been reported to GDB yet. Re-poll
5537 the target looking for this particular thread's event
5538 (i.e. temporarily enable schedlock) by:
5540 - setting a break at the current PC
5541 - resuming that particular thread, only (by setting
5544 This prevents us continuously moving the single-step
5545 breakpoint forward, one instruction at a time,
5548 if (gdbarch_software_single_step_p (gdbarch
)
5549 && stop_pc
!= tp
->prev_pc
)
5552 fprintf_unfiltered (gdb_stdlog
,
5553 "infrun: expected thread advanced also\n");
5555 insert_single_step_breakpoint (get_frame_arch (frame
),
5556 get_frame_address_space (frame
),
5558 singlestep_breakpoints_inserted_p
= 1;
5559 ecs
->event_thread
->control
.trap_expected
= 1;
5560 singlestep_ptid
= inferior_ptid
;
5561 singlestep_pc
= stop_pc
;
5563 resume (0, GDB_SIGNAL_0
);
5564 prepare_to_wait (ecs
);
5569 fprintf_unfiltered (gdb_stdlog
,
5570 "infrun: expected thread still "
5571 "hasn't advanced\n");
5581 /* Is thread TP in the middle of single-stepping? */
5584 currently_stepping (struct thread_info
*tp
)
5586 return ((tp
->control
.step_range_end
5587 && tp
->control
.step_resume_breakpoint
== NULL
)
5588 || tp
->control
.trap_expected
5589 || bpstat_should_step ());
5592 /* Inferior has stepped into a subroutine call with source code that
5593 we should not step over. Do step to the first line of code in
5597 handle_step_into_function (struct gdbarch
*gdbarch
,
5598 struct execution_control_state
*ecs
)
5601 struct symtab_and_line stop_func_sal
, sr_sal
;
5603 fill_in_stop_func (gdbarch
, ecs
);
5605 s
= find_pc_symtab (stop_pc
);
5606 if (s
&& s
->language
!= language_asm
)
5607 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5608 ecs
->stop_func_start
);
5610 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
5611 /* Use the step_resume_break to step until the end of the prologue,
5612 even if that involves jumps (as it seems to on the vax under
5614 /* If the prologue ends in the middle of a source line, continue to
5615 the end of that source line (if it is still within the function).
5616 Otherwise, just go to end of prologue. */
5617 if (stop_func_sal
.end
5618 && stop_func_sal
.pc
!= ecs
->stop_func_start
5619 && stop_func_sal
.end
< ecs
->stop_func_end
)
5620 ecs
->stop_func_start
= stop_func_sal
.end
;
5622 /* Architectures which require breakpoint adjustment might not be able
5623 to place a breakpoint at the computed address. If so, the test
5624 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5625 ecs->stop_func_start to an address at which a breakpoint may be
5626 legitimately placed.
5628 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5629 made, GDB will enter an infinite loop when stepping through
5630 optimized code consisting of VLIW instructions which contain
5631 subinstructions corresponding to different source lines. On
5632 FR-V, it's not permitted to place a breakpoint on any but the
5633 first subinstruction of a VLIW instruction. When a breakpoint is
5634 set, GDB will adjust the breakpoint address to the beginning of
5635 the VLIW instruction. Thus, we need to make the corresponding
5636 adjustment here when computing the stop address. */
5638 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
5640 ecs
->stop_func_start
5641 = gdbarch_adjust_breakpoint_address (gdbarch
,
5642 ecs
->stop_func_start
);
5645 if (ecs
->stop_func_start
== stop_pc
)
5647 /* We are already there: stop now. */
5648 end_stepping_range (ecs
);
5653 /* Put the step-breakpoint there and go until there. */
5654 init_sal (&sr_sal
); /* initialize to zeroes */
5655 sr_sal
.pc
= ecs
->stop_func_start
;
5656 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
5657 sr_sal
.pspace
= get_frame_program_space (get_current_frame ());
5659 /* Do not specify what the fp should be when we stop since on
5660 some machines the prologue is where the new fp value is
5662 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
5664 /* And make sure stepping stops right away then. */
5665 ecs
->event_thread
->control
.step_range_end
5666 = ecs
->event_thread
->control
.step_range_start
;
5671 /* Inferior has stepped backward into a subroutine call with source
5672 code that we should not step over. Do step to the beginning of the
5673 last line of code in it. */
5676 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
5677 struct execution_control_state
*ecs
)
5680 struct symtab_and_line stop_func_sal
;
5682 fill_in_stop_func (gdbarch
, ecs
);
5684 s
= find_pc_symtab (stop_pc
);
5685 if (s
&& s
->language
!= language_asm
)
5686 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
5687 ecs
->stop_func_start
);
5689 stop_func_sal
= find_pc_line (stop_pc
, 0);
5691 /* OK, we're just going to keep stepping here. */
5692 if (stop_func_sal
.pc
== stop_pc
)
5694 /* We're there already. Just stop stepping now. */
5695 end_stepping_range (ecs
);
5699 /* Else just reset the step range and keep going.
5700 No step-resume breakpoint, they don't work for
5701 epilogues, which can have multiple entry paths. */
5702 ecs
->event_thread
->control
.step_range_start
= stop_func_sal
.pc
;
5703 ecs
->event_thread
->control
.step_range_end
= stop_func_sal
.end
;
5709 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5710 This is used to both functions and to skip over code. */
5713 insert_step_resume_breakpoint_at_sal_1 (struct gdbarch
*gdbarch
,
5714 struct symtab_and_line sr_sal
,
5715 struct frame_id sr_id
,
5716 enum bptype sr_type
)
5718 /* There should never be more than one step-resume or longjmp-resume
5719 breakpoint per thread, so we should never be setting a new
5720 step_resume_breakpoint when one is already active. */
5721 gdb_assert (inferior_thread ()->control
.step_resume_breakpoint
== NULL
);
5722 gdb_assert (sr_type
== bp_step_resume
|| sr_type
== bp_hp_step_resume
);
5725 fprintf_unfiltered (gdb_stdlog
,
5726 "infrun: inserting step-resume breakpoint at %s\n",
5727 paddress (gdbarch
, sr_sal
.pc
));
5729 inferior_thread ()->control
.step_resume_breakpoint
5730 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, sr_type
);
5734 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
5735 struct symtab_and_line sr_sal
,
5736 struct frame_id sr_id
)
5738 insert_step_resume_breakpoint_at_sal_1 (gdbarch
,
5743 /* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5744 This is used to skip a potential signal handler.
5746 This is called with the interrupted function's frame. The signal
5747 handler, when it returns, will resume the interrupted function at
5751 insert_hp_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
5753 struct symtab_and_line sr_sal
;
5754 struct gdbarch
*gdbarch
;
5756 gdb_assert (return_frame
!= NULL
);
5757 init_sal (&sr_sal
); /* initialize to zeros */
5759 gdbarch
= get_frame_arch (return_frame
);
5760 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
5761 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5762 sr_sal
.pspace
= get_frame_program_space (return_frame
);
5764 insert_step_resume_breakpoint_at_sal_1 (gdbarch
, sr_sal
,
5765 get_stack_frame_id (return_frame
),
5769 /* Insert a "step-resume breakpoint" at the previous frame's PC. This
5770 is used to skip a function after stepping into it (for "next" or if
5771 the called function has no debugging information).
5773 The current function has almost always been reached by single
5774 stepping a call or return instruction. NEXT_FRAME belongs to the
5775 current function, and the breakpoint will be set at the caller's
5778 This is a separate function rather than reusing
5779 insert_hp_step_resume_breakpoint_at_frame in order to avoid
5780 get_prev_frame, which may stop prematurely (see the implementation
5781 of frame_unwind_caller_id for an example). */
5784 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
5786 struct symtab_and_line sr_sal
;
5787 struct gdbarch
*gdbarch
;
5789 /* We shouldn't have gotten here if we don't know where the call site
5791 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
5793 init_sal (&sr_sal
); /* initialize to zeros */
5795 gdbarch
= frame_unwind_caller_arch (next_frame
);
5796 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
5797 frame_unwind_caller_pc (next_frame
));
5798 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
5799 sr_sal
.pspace
= frame_unwind_program_space (next_frame
);
5801 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
5802 frame_unwind_caller_id (next_frame
));
5805 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5806 new breakpoint at the target of a jmp_buf. The handling of
5807 longjmp-resume uses the same mechanisms used for handling
5808 "step-resume" breakpoints. */
5811 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
5813 /* There should never be more than one longjmp-resume breakpoint per
5814 thread, so we should never be setting a new
5815 longjmp_resume_breakpoint when one is already active. */
5816 gdb_assert (inferior_thread ()->control
.exception_resume_breakpoint
== NULL
);
5819 fprintf_unfiltered (gdb_stdlog
,
5820 "infrun: inserting longjmp-resume breakpoint at %s\n",
5821 paddress (gdbarch
, pc
));
5823 inferior_thread ()->control
.exception_resume_breakpoint
=
5824 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
5827 /* Insert an exception resume breakpoint. TP is the thread throwing
5828 the exception. The block B is the block of the unwinder debug hook
5829 function. FRAME is the frame corresponding to the call to this
5830 function. SYM is the symbol of the function argument holding the
5831 target PC of the exception. */
5834 insert_exception_resume_breakpoint (struct thread_info
*tp
,
5835 const struct block
*b
,
5836 struct frame_info
*frame
,
5839 volatile struct gdb_exception e
;
5841 /* We want to ignore errors here. */
5842 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5844 struct symbol
*vsym
;
5845 struct value
*value
;
5847 struct breakpoint
*bp
;
5849 vsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (sym
), b
, VAR_DOMAIN
, NULL
);
5850 value
= read_var_value (vsym
, frame
);
5851 /* If the value was optimized out, revert to the old behavior. */
5852 if (! value_optimized_out (value
))
5854 handler
= value_as_address (value
);
5857 fprintf_unfiltered (gdb_stdlog
,
5858 "infrun: exception resume at %lx\n",
5859 (unsigned long) handler
);
5861 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5862 handler
, bp_exception_resume
);
5864 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
5867 bp
->thread
= tp
->num
;
5868 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5873 /* A helper for check_exception_resume that sets an
5874 exception-breakpoint based on a SystemTap probe. */
5877 insert_exception_resume_from_probe (struct thread_info
*tp
,
5878 const struct bound_probe
*probe
,
5879 struct frame_info
*frame
)
5881 struct value
*arg_value
;
5883 struct breakpoint
*bp
;
5885 arg_value
= probe_safe_evaluate_at_pc (frame
, 1);
5889 handler
= value_as_address (arg_value
);
5892 fprintf_unfiltered (gdb_stdlog
,
5893 "infrun: exception resume at %s\n",
5894 paddress (get_objfile_arch (probe
->objfile
),
5897 bp
= set_momentary_breakpoint_at_pc (get_frame_arch (frame
),
5898 handler
, bp_exception_resume
);
5899 bp
->thread
= tp
->num
;
5900 inferior_thread ()->control
.exception_resume_breakpoint
= bp
;
5903 /* This is called when an exception has been intercepted. Check to
5904 see whether the exception's destination is of interest, and if so,
5905 set an exception resume breakpoint there. */
5908 check_exception_resume (struct execution_control_state
*ecs
,
5909 struct frame_info
*frame
)
5911 volatile struct gdb_exception e
;
5912 struct bound_probe probe
;
5913 struct symbol
*func
;
5915 /* First see if this exception unwinding breakpoint was set via a
5916 SystemTap probe point. If so, the probe has two arguments: the
5917 CFA and the HANDLER. We ignore the CFA, extract the handler, and
5918 set a breakpoint there. */
5919 probe
= find_probe_by_pc (get_frame_pc (frame
));
5922 insert_exception_resume_from_probe (ecs
->event_thread
, &probe
, frame
);
5926 func
= get_frame_function (frame
);
5930 TRY_CATCH (e
, RETURN_MASK_ERROR
)
5932 const struct block
*b
;
5933 struct block_iterator iter
;
5937 /* The exception breakpoint is a thread-specific breakpoint on
5938 the unwinder's debug hook, declared as:
5940 void _Unwind_DebugHook (void *cfa, void *handler);
5942 The CFA argument indicates the frame to which control is
5943 about to be transferred. HANDLER is the destination PC.
5945 We ignore the CFA and set a temporary breakpoint at HANDLER.
5946 This is not extremely efficient but it avoids issues in gdb
5947 with computing the DWARF CFA, and it also works even in weird
5948 cases such as throwing an exception from inside a signal
5951 b
= SYMBOL_BLOCK_VALUE (func
);
5952 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
5954 if (!SYMBOL_IS_ARGUMENT (sym
))
5961 insert_exception_resume_breakpoint (ecs
->event_thread
,
5970 stop_waiting (struct execution_control_state
*ecs
)
5973 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_waiting\n");
5975 clear_step_over_info ();
5977 /* Let callers know we don't want to wait for the inferior anymore. */
5978 ecs
->wait_some_more
= 0;
5981 /* Called when we should continue running the inferior, because the
5982 current event doesn't cause a user visible stop. This does the
5983 resuming part; waiting for the next event is done elsewhere. */
5986 keep_going (struct execution_control_state
*ecs
)
5988 /* Make sure normal_stop is called if we get a QUIT handled before
5990 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
5992 /* Save the pc before execution, to compare with pc after stop. */
5993 ecs
->event_thread
->prev_pc
5994 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
5996 if (ecs
->event_thread
->control
.trap_expected
5997 && ecs
->event_thread
->suspend
.stop_signal
!= GDB_SIGNAL_TRAP
)
5999 /* We haven't yet gotten our trap, and either: intercepted a
6000 non-signal event (e.g., a fork); or took a signal which we
6001 are supposed to pass through to the inferior. Simply
6003 discard_cleanups (old_cleanups
);
6004 resume (currently_stepping (ecs
->event_thread
),
6005 ecs
->event_thread
->suspend
.stop_signal
);
6009 volatile struct gdb_exception e
;
6010 struct regcache
*regcache
= get_current_regcache ();
6012 /* Either the trap was not expected, but we are continuing
6013 anyway (if we got a signal, the user asked it be passed to
6016 We got our expected trap, but decided we should resume from
6019 We're going to run this baby now!
6021 Note that insert_breakpoints won't try to re-insert
6022 already inserted breakpoints. Therefore, we don't
6023 care if breakpoints were already inserted, or not. */
6025 /* If we need to step over a breakpoint, and we're not using
6026 displaced stepping to do so, insert all breakpoints
6027 (watchpoints, etc.) but the one we're stepping over, step one
6028 instruction, and then re-insert the breakpoint when that step
6030 if ((ecs
->hit_singlestep_breakpoint
6031 || thread_still_needs_step_over (ecs
->event_thread
))
6032 && !use_displaced_stepping (get_regcache_arch (regcache
)))
6034 set_step_over_info (get_regcache_aspace (regcache
),
6035 regcache_read_pc (regcache
));
6038 clear_step_over_info ();
6040 /* Stop stepping if inserting breakpoints fails. */
6041 TRY_CATCH (e
, RETURN_MASK_ERROR
)
6043 insert_breakpoints ();
6047 exception_print (gdb_stderr
, e
);
6052 ecs
->event_thread
->control
.trap_expected
6053 = (ecs
->event_thread
->stepping_over_breakpoint
6054 || ecs
->hit_singlestep_breakpoint
);
6056 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
6057 explicitly specifies that such a signal should be delivered
6058 to the target program). Typically, that would occur when a
6059 user is debugging a target monitor on a simulator: the target
6060 monitor sets a breakpoint; the simulator encounters this
6061 breakpoint and halts the simulation handing control to GDB;
6062 GDB, noting that the stop address doesn't map to any known
6063 breakpoint, returns control back to the simulator; the
6064 simulator then delivers the hardware equivalent of a
6065 GDB_SIGNAL_TRAP to the program being debugged. */
6066 if (ecs
->event_thread
->suspend
.stop_signal
== GDB_SIGNAL_TRAP
6067 && !signal_program
[ecs
->event_thread
->suspend
.stop_signal
])
6068 ecs
->event_thread
->suspend
.stop_signal
= GDB_SIGNAL_0
;
6070 discard_cleanups (old_cleanups
);
6071 resume (currently_stepping (ecs
->event_thread
),
6072 ecs
->event_thread
->suspend
.stop_signal
);
6075 prepare_to_wait (ecs
);
6078 /* This function normally comes after a resume, before
6079 handle_inferior_event exits. It takes care of any last bits of
6080 housekeeping, and sets the all-important wait_some_more flag. */
6083 prepare_to_wait (struct execution_control_state
*ecs
)
6086 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
6088 /* This is the old end of the while loop. Let everybody know we
6089 want to wait for the inferior some more and get called again
6091 ecs
->wait_some_more
= 1;
6094 /* We are done with the step range of a step/next/si/ni command.
6095 Called once for each n of a "step n" operation. */
6098 end_stepping_range (struct execution_control_state
*ecs
)
6100 ecs
->event_thread
->control
.stop_step
= 1;
6104 /* Several print_*_reason functions to print why the inferior has stopped.
6105 We always print something when the inferior exits, or receives a signal.
6106 The rest of the cases are dealt with later on in normal_stop and
6107 print_it_typical. Ideally there should be a call to one of these
6108 print_*_reason functions functions from handle_inferior_event each time
6109 stop_waiting is called.
6111 Note that we don't call these directly, instead we delegate that to
6112 the interpreters, through observers. Interpreters then call these
6113 with whatever uiout is right. */
6116 print_end_stepping_range_reason (struct ui_out
*uiout
)
6118 /* For CLI-like interpreters, print nothing. */
6120 if (ui_out_is_mi_like_p (uiout
))
6122 ui_out_field_string (uiout
, "reason",
6123 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
6128 print_signal_exited_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6130 annotate_signalled ();
6131 if (ui_out_is_mi_like_p (uiout
))
6133 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
6134 ui_out_text (uiout
, "\nProgram terminated with signal ");
6135 annotate_signal_name ();
6136 ui_out_field_string (uiout
, "signal-name",
6137 gdb_signal_to_name (siggnal
));
6138 annotate_signal_name_end ();
6139 ui_out_text (uiout
, ", ");
6140 annotate_signal_string ();
6141 ui_out_field_string (uiout
, "signal-meaning",
6142 gdb_signal_to_string (siggnal
));
6143 annotate_signal_string_end ();
6144 ui_out_text (uiout
, ".\n");
6145 ui_out_text (uiout
, "The program no longer exists.\n");
6149 print_exited_reason (struct ui_out
*uiout
, int exitstatus
)
6151 struct inferior
*inf
= current_inferior ();
6152 const char *pidstr
= target_pid_to_str (pid_to_ptid (inf
->pid
));
6154 annotate_exited (exitstatus
);
6157 if (ui_out_is_mi_like_p (uiout
))
6158 ui_out_field_string (uiout
, "reason",
6159 async_reason_lookup (EXEC_ASYNC_EXITED
));
6160 ui_out_text (uiout
, "[Inferior ");
6161 ui_out_text (uiout
, plongest (inf
->num
));
6162 ui_out_text (uiout
, " (");
6163 ui_out_text (uiout
, pidstr
);
6164 ui_out_text (uiout
, ") exited with code ");
6165 ui_out_field_fmt (uiout
, "exit-code", "0%o", (unsigned int) exitstatus
);
6166 ui_out_text (uiout
, "]\n");
6170 if (ui_out_is_mi_like_p (uiout
))
6172 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
6173 ui_out_text (uiout
, "[Inferior ");
6174 ui_out_text (uiout
, plongest (inf
->num
));
6175 ui_out_text (uiout
, " (");
6176 ui_out_text (uiout
, pidstr
);
6177 ui_out_text (uiout
, ") exited normally]\n");
6182 print_signal_received_reason (struct ui_out
*uiout
, enum gdb_signal siggnal
)
6186 if (siggnal
== GDB_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
6188 struct thread_info
*t
= inferior_thread ();
6190 ui_out_text (uiout
, "\n[");
6191 ui_out_field_string (uiout
, "thread-name",
6192 target_pid_to_str (t
->ptid
));
6193 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
6194 ui_out_text (uiout
, " stopped");
6198 ui_out_text (uiout
, "\nProgram received signal ");
6199 annotate_signal_name ();
6200 if (ui_out_is_mi_like_p (uiout
))
6202 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
6203 ui_out_field_string (uiout
, "signal-name",
6204 gdb_signal_to_name (siggnal
));
6205 annotate_signal_name_end ();
6206 ui_out_text (uiout
, ", ");
6207 annotate_signal_string ();
6208 ui_out_field_string (uiout
, "signal-meaning",
6209 gdb_signal_to_string (siggnal
));
6210 annotate_signal_string_end ();
6212 ui_out_text (uiout
, ".\n");
6216 print_no_history_reason (struct ui_out
*uiout
)
6218 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
6221 /* Print current location without a level number, if we have changed
6222 functions or hit a breakpoint. Print source line if we have one.
6223 bpstat_print contains the logic deciding in detail what to print,
6224 based on the event(s) that just occurred. */
6227 print_stop_event (struct target_waitstatus
*ws
)
6231 int do_frame_printing
= 1;
6232 struct thread_info
*tp
= inferior_thread ();
6234 bpstat_ret
= bpstat_print (tp
->control
.stop_bpstat
, ws
->kind
);
6238 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6239 should) carry around the function and does (or should) use
6240 that when doing a frame comparison. */
6241 if (tp
->control
.stop_step
6242 && frame_id_eq (tp
->control
.step_frame_id
,
6243 get_frame_id (get_current_frame ()))
6244 && step_start_function
== find_pc_function (stop_pc
))
6246 /* Finished step, just print source line. */
6247 source_flag
= SRC_LINE
;
6251 /* Print location and source line. */
6252 source_flag
= SRC_AND_LOC
;
6255 case PRINT_SRC_AND_LOC
:
6256 /* Print location and source line. */
6257 source_flag
= SRC_AND_LOC
;
6259 case PRINT_SRC_ONLY
:
6260 source_flag
= SRC_LINE
;
6263 /* Something bogus. */
6264 source_flag
= SRC_LINE
;
6265 do_frame_printing
= 0;
6268 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
6271 /* The behavior of this routine with respect to the source
6273 SRC_LINE: Print only source line
6274 LOCATION: Print only location
6275 SRC_AND_LOC: Print location and source line. */
6276 if (do_frame_printing
)
6277 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
, 1);
6279 /* Display the auto-display expressions. */
6283 /* Here to return control to GDB when the inferior stops for real.
6284 Print appropriate messages, remove breakpoints, give terminal our modes.
6286 STOP_PRINT_FRAME nonzero means print the executing frame
6287 (pc, function, args, file, line number and line text).
6288 BREAKPOINTS_FAILED nonzero means stop was due to error
6289 attempting to insert breakpoints. */
6294 struct target_waitstatus last
;
6296 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
6298 get_last_target_status (&last_ptid
, &last
);
6300 /* If an exception is thrown from this point on, make sure to
6301 propagate GDB's knowledge of the executing state to the
6302 frontend/user running state. A QUIT is an easy exception to see
6303 here, so do this before any filtered output. */
6305 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
6306 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6307 && last
.kind
!= TARGET_WAITKIND_EXITED
6308 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6309 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
6311 /* As we're presenting a stop, and potentially removing breakpoints,
6312 update the thread list so we can tell whether there are threads
6313 running on the target. With target remote, for example, we can
6314 only learn about new threads when we explicitly update the thread
6315 list. Do this before notifying the interpreters about signal
6316 stops, end of stepping ranges, etc., so that the "new thread"
6317 output is emitted before e.g., "Program received signal FOO",
6318 instead of after. */
6319 update_thread_list ();
6321 if (last
.kind
== TARGET_WAITKIND_STOPPED
&& stopped_by_random_signal
)
6322 observer_notify_signal_received (inferior_thread ()->suspend
.stop_signal
);
6324 /* As with the notification of thread events, we want to delay
6325 notifying the user that we've switched thread context until
6326 the inferior actually stops.
6328 There's no point in saying anything if the inferior has exited.
6329 Note that SIGNALLED here means "exited with a signal", not
6330 "received a signal".
6332 Also skip saying anything in non-stop mode. In that mode, as we
6333 don't want GDB to switch threads behind the user's back, to avoid
6334 races where the user is typing a command to apply to thread x,
6335 but GDB switches to thread y before the user finishes entering
6336 the command, fetch_inferior_event installs a cleanup to restore
6337 the current thread back to the thread the user had selected right
6338 after this event is handled, so we're not really switching, only
6339 informing of a stop. */
6341 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
6342 && target_has_execution
6343 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6344 && last
.kind
!= TARGET_WAITKIND_EXITED
6345 && last
.kind
!= TARGET_WAITKIND_NO_RESUMED
)
6347 target_terminal_ours_for_output ();
6348 printf_filtered (_("[Switching to %s]\n"),
6349 target_pid_to_str (inferior_ptid
));
6350 annotate_thread_changed ();
6351 previous_inferior_ptid
= inferior_ptid
;
6354 if (last
.kind
== TARGET_WAITKIND_NO_RESUMED
)
6356 gdb_assert (sync_execution
|| !target_can_async_p ());
6358 target_terminal_ours_for_output ();
6359 printf_filtered (_("No unwaited-for children left.\n"));
6362 /* Note: this depends on the update_thread_list call above. */
6363 if (!breakpoints_should_be_inserted_now () && target_has_execution
)
6365 if (remove_breakpoints ())
6367 target_terminal_ours_for_output ();
6368 printf_filtered (_("Cannot remove breakpoints because "
6369 "program is no longer writable.\nFurther "
6370 "execution is probably impossible.\n"));
6374 /* If an auto-display called a function and that got a signal,
6375 delete that auto-display to avoid an infinite recursion. */
6377 if (stopped_by_random_signal
)
6378 disable_current_display ();
6380 /* Notify observers if we finished a "step"-like command, etc. */
6381 if (target_has_execution
6382 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
6383 && last
.kind
!= TARGET_WAITKIND_EXITED
6384 && inferior_thread ()->control
.stop_step
)
6386 /* But not if if in the middle of doing a "step n" operation for
6388 if (inferior_thread ()->step_multi
)
6391 observer_notify_end_stepping_range ();
6394 target_terminal_ours ();
6395 async_enable_stdin ();
6397 /* Set the current source location. This will also happen if we
6398 display the frame below, but the current SAL will be incorrect
6399 during a user hook-stop function. */
6400 if (has_stack_frames () && !stop_stack_dummy
)
6401 set_current_sal_from_frame (get_current_frame ());
6403 /* Let the user/frontend see the threads as stopped, but do nothing
6404 if the thread was running an infcall. We may be e.g., evaluating
6405 a breakpoint condition. In that case, the thread had state
6406 THREAD_RUNNING before the infcall, and shall remain set to
6407 running, all without informing the user/frontend about state
6408 transition changes. If this is actually a call command, then the
6409 thread was originally already stopped, so there's no state to
6411 if (target_has_execution
&& inferior_thread ()->control
.in_infcall
)
6412 discard_cleanups (old_chain
);
6414 do_cleanups (old_chain
);
6416 /* Look up the hook_stop and run it (CLI internally handles problem
6417 of stop_command's pre-hook not existing). */
6419 catch_errors (hook_stop_stub
, stop_command
,
6420 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
6422 if (!has_stack_frames ())
6425 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
6426 || last
.kind
== TARGET_WAITKIND_EXITED
)
6429 /* Select innermost stack frame - i.e., current frame is frame 0,
6430 and current location is based on that.
6431 Don't do this on return from a stack dummy routine,
6432 or if the program has exited. */
6434 if (!stop_stack_dummy
)
6436 select_frame (get_current_frame ());
6438 /* If --batch-silent is enabled then there's no need to print the current
6439 source location, and to try risks causing an error message about
6440 missing source files. */
6441 if (stop_print_frame
&& !batch_silent
)
6442 print_stop_event (&last
);
6445 /* Save the function value return registers, if we care.
6446 We might be about to restore their previous contents. */
6447 if (inferior_thread ()->control
.proceed_to_finish
6448 && execution_direction
!= EXEC_REVERSE
)
6450 /* This should not be necessary. */
6452 regcache_xfree (stop_registers
);
6454 /* NB: The copy goes through to the target picking up the value of
6455 all the registers. */
6456 stop_registers
= regcache_dup (get_current_regcache ());
6459 if (stop_stack_dummy
== STOP_STACK_DUMMY
)
6461 /* Pop the empty frame that contains the stack dummy.
6462 This also restores inferior state prior to the call
6463 (struct infcall_suspend_state). */
6464 struct frame_info
*frame
= get_current_frame ();
6466 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
6468 /* frame_pop() calls reinit_frame_cache as the last thing it
6469 does which means there's currently no selected frame. We
6470 don't need to re-establish a selected frame if the dummy call
6471 returns normally, that will be done by
6472 restore_infcall_control_state. However, we do have to handle
6473 the case where the dummy call is returning after being
6474 stopped (e.g. the dummy call previously hit a breakpoint).
6475 We can't know which case we have so just always re-establish
6476 a selected frame here. */
6477 select_frame (get_current_frame ());
6481 annotate_stopped ();
6483 /* Suppress the stop observer if we're in the middle of:
6485 - a step n (n > 1), as there still more steps to be done.
6487 - a "finish" command, as the observer will be called in
6488 finish_command_continuation, so it can include the inferior
6489 function's return value.
6491 - calling an inferior function, as we pretend we inferior didn't
6492 run at all. The return value of the call is handled by the
6493 expression evaluator, through call_function_by_hand. */
6495 if (!target_has_execution
6496 || last
.kind
== TARGET_WAITKIND_SIGNALLED
6497 || last
.kind
== TARGET_WAITKIND_EXITED
6498 || last
.kind
== TARGET_WAITKIND_NO_RESUMED
6499 || (!(inferior_thread ()->step_multi
6500 && inferior_thread ()->control
.stop_step
)
6501 && !(inferior_thread ()->control
.stop_bpstat
6502 && inferior_thread ()->control
.proceed_to_finish
)
6503 && !inferior_thread ()->control
.in_infcall
))
6505 if (!ptid_equal (inferior_ptid
, null_ptid
))
6506 observer_notify_normal_stop (inferior_thread ()->control
.stop_bpstat
,
6509 observer_notify_normal_stop (NULL
, stop_print_frame
);
6512 if (target_has_execution
)
6514 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
6515 && last
.kind
!= TARGET_WAITKIND_EXITED
)
6516 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6517 Delete any breakpoint that is to be deleted at the next stop. */
6518 breakpoint_auto_delete (inferior_thread ()->control
.stop_bpstat
);
6521 /* Try to get rid of automatically added inferiors that are no
6522 longer needed. Keeping those around slows down things linearly.
6523 Note that this never removes the current inferior. */
6528 hook_stop_stub (void *cmd
)
6530 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
6535 signal_stop_state (int signo
)
6537 return signal_stop
[signo
];
6541 signal_print_state (int signo
)
6543 return signal_print
[signo
];
6547 signal_pass_state (int signo
)
6549 return signal_program
[signo
];
6553 signal_cache_update (int signo
)
6557 for (signo
= 0; signo
< (int) GDB_SIGNAL_LAST
; signo
++)
6558 signal_cache_update (signo
);
6563 signal_pass
[signo
] = (signal_stop
[signo
] == 0
6564 && signal_print
[signo
] == 0
6565 && signal_program
[signo
] == 1
6566 && signal_catch
[signo
] == 0);
6570 signal_stop_update (int signo
, int state
)
6572 int ret
= signal_stop
[signo
];
6574 signal_stop
[signo
] = state
;
6575 signal_cache_update (signo
);
6580 signal_print_update (int signo
, int state
)
6582 int ret
= signal_print
[signo
];
6584 signal_print
[signo
] = state
;
6585 signal_cache_update (signo
);
6590 signal_pass_update (int signo
, int state
)
6592 int ret
= signal_program
[signo
];
6594 signal_program
[signo
] = state
;
6595 signal_cache_update (signo
);
6599 /* Update the global 'signal_catch' from INFO and notify the
6603 signal_catch_update (const unsigned int *info
)
6607 for (i
= 0; i
< GDB_SIGNAL_LAST
; ++i
)
6608 signal_catch
[i
] = info
[i
] > 0;
6609 signal_cache_update (-1);
6610 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6614 sig_print_header (void)
6616 printf_filtered (_("Signal Stop\tPrint\tPass "
6617 "to program\tDescription\n"));
6621 sig_print_info (enum gdb_signal oursig
)
6623 const char *name
= gdb_signal_to_name (oursig
);
6624 int name_padding
= 13 - strlen (name
);
6626 if (name_padding
<= 0)
6629 printf_filtered ("%s", name
);
6630 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
6631 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
6632 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
6633 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
6634 printf_filtered ("%s\n", gdb_signal_to_string (oursig
));
6637 /* Specify how various signals in the inferior should be handled. */
6640 handle_command (char *args
, int from_tty
)
6643 int digits
, wordlen
;
6644 int sigfirst
, signum
, siglast
;
6645 enum gdb_signal oursig
;
6648 unsigned char *sigs
;
6649 struct cleanup
*old_chain
;
6653 error_no_arg (_("signal to handle"));
6656 /* Allocate and zero an array of flags for which signals to handle. */
6658 nsigs
= (int) GDB_SIGNAL_LAST
;
6659 sigs
= (unsigned char *) alloca (nsigs
);
6660 memset (sigs
, 0, nsigs
);
6662 /* Break the command line up into args. */
6664 argv
= gdb_buildargv (args
);
6665 old_chain
= make_cleanup_freeargv (argv
);
6667 /* Walk through the args, looking for signal oursigs, signal names, and
6668 actions. Signal numbers and signal names may be interspersed with
6669 actions, with the actions being performed for all signals cumulatively
6670 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6672 while (*argv
!= NULL
)
6674 wordlen
= strlen (*argv
);
6675 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
6679 sigfirst
= siglast
= -1;
6681 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
6683 /* Apply action to all signals except those used by the
6684 debugger. Silently skip those. */
6687 siglast
= nsigs
- 1;
6689 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
6691 SET_SIGS (nsigs
, sigs
, signal_stop
);
6692 SET_SIGS (nsigs
, sigs
, signal_print
);
6694 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
6696 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6698 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
6700 SET_SIGS (nsigs
, sigs
, signal_print
);
6702 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
6704 SET_SIGS (nsigs
, sigs
, signal_program
);
6706 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
6708 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6710 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
6712 SET_SIGS (nsigs
, sigs
, signal_program
);
6714 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
6716 UNSET_SIGS (nsigs
, sigs
, signal_print
);
6717 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
6719 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
6721 UNSET_SIGS (nsigs
, sigs
, signal_program
);
6723 else if (digits
> 0)
6725 /* It is numeric. The numeric signal refers to our own
6726 internal signal numbering from target.h, not to host/target
6727 signal number. This is a feature; users really should be
6728 using symbolic names anyway, and the common ones like
6729 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6731 sigfirst
= siglast
= (int)
6732 gdb_signal_from_command (atoi (*argv
));
6733 if ((*argv
)[digits
] == '-')
6736 gdb_signal_from_command (atoi ((*argv
) + digits
+ 1));
6738 if (sigfirst
> siglast
)
6740 /* Bet he didn't figure we'd think of this case... */
6748 oursig
= gdb_signal_from_name (*argv
);
6749 if (oursig
!= GDB_SIGNAL_UNKNOWN
)
6751 sigfirst
= siglast
= (int) oursig
;
6755 /* Not a number and not a recognized flag word => complain. */
6756 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
6760 /* If any signal numbers or symbol names were found, set flags for
6761 which signals to apply actions to. */
6763 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
6765 switch ((enum gdb_signal
) signum
)
6767 case GDB_SIGNAL_TRAP
:
6768 case GDB_SIGNAL_INT
:
6769 if (!allsigs
&& !sigs
[signum
])
6771 if (query (_("%s is used by the debugger.\n\
6772 Are you sure you want to change it? "),
6773 gdb_signal_to_name ((enum gdb_signal
) signum
)))
6779 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6780 gdb_flush (gdb_stdout
);
6785 case GDB_SIGNAL_DEFAULT
:
6786 case GDB_SIGNAL_UNKNOWN
:
6787 /* Make sure that "all" doesn't print these. */
6798 for (signum
= 0; signum
< nsigs
; signum
++)
6801 signal_cache_update (-1);
6802 target_pass_signals ((int) GDB_SIGNAL_LAST
, signal_pass
);
6803 target_program_signals ((int) GDB_SIGNAL_LAST
, signal_program
);
6807 /* Show the results. */
6808 sig_print_header ();
6809 for (; signum
< nsigs
; signum
++)
6811 sig_print_info (signum
);
6817 do_cleanups (old_chain
);
6820 /* Complete the "handle" command. */
6822 static VEC (char_ptr
) *
6823 handle_completer (struct cmd_list_element
*ignore
,
6824 const char *text
, const char *word
)
6826 VEC (char_ptr
) *vec_signals
, *vec_keywords
, *return_val
;
6827 static const char * const keywords
[] =
6841 vec_signals
= signal_completer (ignore
, text
, word
);
6842 vec_keywords
= complete_on_enum (keywords
, word
, word
);
6844 return_val
= VEC_merge (char_ptr
, vec_signals
, vec_keywords
);
6845 VEC_free (char_ptr
, vec_signals
);
6846 VEC_free (char_ptr
, vec_keywords
);
6851 xdb_handle_command (char *args
, int from_tty
)
6854 struct cleanup
*old_chain
;
6857 error_no_arg (_("xdb command"));
6859 /* Break the command line up into args. */
6861 argv
= gdb_buildargv (args
);
6862 old_chain
= make_cleanup_freeargv (argv
);
6863 if (argv
[1] != (char *) NULL
)
6868 bufLen
= strlen (argv
[0]) + 20;
6869 argBuf
= (char *) xmalloc (bufLen
);
6873 enum gdb_signal oursig
;
6875 oursig
= gdb_signal_from_name (argv
[0]);
6876 memset (argBuf
, 0, bufLen
);
6877 if (strcmp (argv
[1], "Q") == 0)
6878 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6881 if (strcmp (argv
[1], "s") == 0)
6883 if (!signal_stop
[oursig
])
6884 sprintf (argBuf
, "%s %s", argv
[0], "stop");
6886 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
6888 else if (strcmp (argv
[1], "i") == 0)
6890 if (!signal_program
[oursig
])
6891 sprintf (argBuf
, "%s %s", argv
[0], "pass");
6893 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
6895 else if (strcmp (argv
[1], "r") == 0)
6897 if (!signal_print
[oursig
])
6898 sprintf (argBuf
, "%s %s", argv
[0], "print");
6900 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
6906 handle_command (argBuf
, from_tty
);
6908 printf_filtered (_("Invalid signal handling flag.\n"));
6913 do_cleanups (old_chain
);
6917 gdb_signal_from_command (int num
)
6919 if (num
>= 1 && num
<= 15)
6920 return (enum gdb_signal
) num
;
6921 error (_("Only signals 1-15 are valid as numeric signals.\n\
6922 Use \"info signals\" for a list of symbolic signals."));
6925 /* Print current contents of the tables set by the handle command.
6926 It is possible we should just be printing signals actually used
6927 by the current target (but for things to work right when switching
6928 targets, all signals should be in the signal tables). */
6931 signals_info (char *signum_exp
, int from_tty
)
6933 enum gdb_signal oursig
;
6935 sig_print_header ();
6939 /* First see if this is a symbol name. */
6940 oursig
= gdb_signal_from_name (signum_exp
);
6941 if (oursig
== GDB_SIGNAL_UNKNOWN
)
6943 /* No, try numeric. */
6945 gdb_signal_from_command (parse_and_eval_long (signum_exp
));
6947 sig_print_info (oursig
);
6951 printf_filtered ("\n");
6952 /* These ugly casts brought to you by the native VAX compiler. */
6953 for (oursig
= GDB_SIGNAL_FIRST
;
6954 (int) oursig
< (int) GDB_SIGNAL_LAST
;
6955 oursig
= (enum gdb_signal
) ((int) oursig
+ 1))
6959 if (oursig
!= GDB_SIGNAL_UNKNOWN
6960 && oursig
!= GDB_SIGNAL_DEFAULT
&& oursig
!= GDB_SIGNAL_0
)
6961 sig_print_info (oursig
);
6964 printf_filtered (_("\nUse the \"handle\" command "
6965 "to change these tables.\n"));
6968 /* Check if it makes sense to read $_siginfo from the current thread
6969 at this point. If not, throw an error. */
6972 validate_siginfo_access (void)
6974 /* No current inferior, no siginfo. */
6975 if (ptid_equal (inferior_ptid
, null_ptid
))
6976 error (_("No thread selected."));
6978 /* Don't try to read from a dead thread. */
6979 if (is_exited (inferior_ptid
))
6980 error (_("The current thread has terminated"));
6982 /* ... or from a spinning thread. */
6983 if (is_running (inferior_ptid
))
6984 error (_("Selected thread is running."));
6987 /* The $_siginfo convenience variable is a bit special. We don't know
6988 for sure the type of the value until we actually have a chance to
6989 fetch the data. The type can change depending on gdbarch, so it is
6990 also dependent on which thread you have selected.
6992 1. making $_siginfo be an internalvar that creates a new value on
6995 2. making the value of $_siginfo be an lval_computed value. */
6997 /* This function implements the lval_computed support for reading a
7001 siginfo_value_read (struct value
*v
)
7003 LONGEST transferred
;
7005 validate_siginfo_access ();
7008 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
7010 value_contents_all_raw (v
),
7012 TYPE_LENGTH (value_type (v
)));
7014 if (transferred
!= TYPE_LENGTH (value_type (v
)))
7015 error (_("Unable to read siginfo"));
7018 /* This function implements the lval_computed support for writing a
7022 siginfo_value_write (struct value
*v
, struct value
*fromval
)
7024 LONGEST transferred
;
7026 validate_siginfo_access ();
7028 transferred
= target_write (¤t_target
,
7029 TARGET_OBJECT_SIGNAL_INFO
,
7031 value_contents_all_raw (fromval
),
7033 TYPE_LENGTH (value_type (fromval
)));
7035 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
7036 error (_("Unable to write siginfo"));
7039 static const struct lval_funcs siginfo_value_funcs
=
7045 /* Return a new value with the correct type for the siginfo object of
7046 the current thread using architecture GDBARCH. Return a void value
7047 if there's no object available. */
7049 static struct value
*
7050 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
,
7053 if (target_has_stack
7054 && !ptid_equal (inferior_ptid
, null_ptid
)
7055 && gdbarch_get_siginfo_type_p (gdbarch
))
7057 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7059 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
7062 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
7066 /* infcall_suspend_state contains state about the program itself like its
7067 registers and any signal it received when it last stopped.
7068 This state must be restored regardless of how the inferior function call
7069 ends (either successfully, or after it hits a breakpoint or signal)
7070 if the program is to properly continue where it left off. */
7072 struct infcall_suspend_state
7074 struct thread_suspend_state thread_suspend
;
7075 #if 0 /* Currently unused and empty structures are not valid C. */
7076 struct inferior_suspend_state inferior_suspend
;
7081 struct regcache
*registers
;
7083 /* Format of SIGINFO_DATA or NULL if it is not present. */
7084 struct gdbarch
*siginfo_gdbarch
;
7086 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
7087 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
7088 content would be invalid. */
7089 gdb_byte
*siginfo_data
;
7092 struct infcall_suspend_state
*
7093 save_infcall_suspend_state (void)
7095 struct infcall_suspend_state
*inf_state
;
7096 struct thread_info
*tp
= inferior_thread ();
7098 struct inferior
*inf
= current_inferior ();
7100 struct regcache
*regcache
= get_current_regcache ();
7101 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7102 gdb_byte
*siginfo_data
= NULL
;
7104 if (gdbarch_get_siginfo_type_p (gdbarch
))
7106 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7107 size_t len
= TYPE_LENGTH (type
);
7108 struct cleanup
*back_to
;
7110 siginfo_data
= xmalloc (len
);
7111 back_to
= make_cleanup (xfree
, siginfo_data
);
7113 if (target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7114 siginfo_data
, 0, len
) == len
)
7115 discard_cleanups (back_to
);
7118 /* Errors ignored. */
7119 do_cleanups (back_to
);
7120 siginfo_data
= NULL
;
7124 inf_state
= XCNEW (struct infcall_suspend_state
);
7128 inf_state
->siginfo_gdbarch
= gdbarch
;
7129 inf_state
->siginfo_data
= siginfo_data
;
7132 inf_state
->thread_suspend
= tp
->suspend
;
7133 #if 0 /* Currently unused and empty structures are not valid C. */
7134 inf_state
->inferior_suspend
= inf
->suspend
;
7137 /* run_inferior_call will not use the signal due to its `proceed' call with
7138 GDB_SIGNAL_0 anyway. */
7139 tp
->suspend
.stop_signal
= GDB_SIGNAL_0
;
7141 inf_state
->stop_pc
= stop_pc
;
7143 inf_state
->registers
= regcache_dup (regcache
);
7148 /* Restore inferior session state to INF_STATE. */
7151 restore_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7153 struct thread_info
*tp
= inferior_thread ();
7155 struct inferior
*inf
= current_inferior ();
7157 struct regcache
*regcache
= get_current_regcache ();
7158 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
7160 tp
->suspend
= inf_state
->thread_suspend
;
7161 #if 0 /* Currently unused and empty structures are not valid C. */
7162 inf
->suspend
= inf_state
->inferior_suspend
;
7165 stop_pc
= inf_state
->stop_pc
;
7167 if (inf_state
->siginfo_gdbarch
== gdbarch
)
7169 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
7171 /* Errors ignored. */
7172 target_write (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
, NULL
,
7173 inf_state
->siginfo_data
, 0, TYPE_LENGTH (type
));
7176 /* The inferior can be gone if the user types "print exit(0)"
7177 (and perhaps other times). */
7178 if (target_has_execution
)
7179 /* NB: The register write goes through to the target. */
7180 regcache_cpy (regcache
, inf_state
->registers
);
7182 discard_infcall_suspend_state (inf_state
);
7186 do_restore_infcall_suspend_state_cleanup (void *state
)
7188 restore_infcall_suspend_state (state
);
7192 make_cleanup_restore_infcall_suspend_state
7193 (struct infcall_suspend_state
*inf_state
)
7195 return make_cleanup (do_restore_infcall_suspend_state_cleanup
, inf_state
);
7199 discard_infcall_suspend_state (struct infcall_suspend_state
*inf_state
)
7201 regcache_xfree (inf_state
->registers
);
7202 xfree (inf_state
->siginfo_data
);
7207 get_infcall_suspend_state_regcache (struct infcall_suspend_state
*inf_state
)
7209 return inf_state
->registers
;
7212 /* infcall_control_state contains state regarding gdb's control of the
7213 inferior itself like stepping control. It also contains session state like
7214 the user's currently selected frame. */
7216 struct infcall_control_state
7218 struct thread_control_state thread_control
;
7219 struct inferior_control_state inferior_control
;
7222 enum stop_stack_kind stop_stack_dummy
;
7223 int stopped_by_random_signal
;
7224 int stop_after_trap
;
7226 /* ID if the selected frame when the inferior function call was made. */
7227 struct frame_id selected_frame_id
;
7230 /* Save all of the information associated with the inferior<==>gdb
7233 struct infcall_control_state
*
7234 save_infcall_control_state (void)
7236 struct infcall_control_state
*inf_status
= xmalloc (sizeof (*inf_status
));
7237 struct thread_info
*tp
= inferior_thread ();
7238 struct inferior
*inf
= current_inferior ();
7240 inf_status
->thread_control
= tp
->control
;
7241 inf_status
->inferior_control
= inf
->control
;
7243 tp
->control
.step_resume_breakpoint
= NULL
;
7244 tp
->control
.exception_resume_breakpoint
= NULL
;
7246 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7247 chain. If caller's caller is walking the chain, they'll be happier if we
7248 hand them back the original chain when restore_infcall_control_state is
7250 tp
->control
.stop_bpstat
= bpstat_copy (tp
->control
.stop_bpstat
);
7253 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
7254 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
7255 inf_status
->stop_after_trap
= stop_after_trap
;
7257 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
7263 restore_selected_frame (void *args
)
7265 struct frame_id
*fid
= (struct frame_id
*) args
;
7266 struct frame_info
*frame
;
7268 frame
= frame_find_by_id (*fid
);
7270 /* If inf_status->selected_frame_id is NULL, there was no previously
7274 warning (_("Unable to restore previously selected frame."));
7278 select_frame (frame
);
7283 /* Restore inferior session state to INF_STATUS. */
7286 restore_infcall_control_state (struct infcall_control_state
*inf_status
)
7288 struct thread_info
*tp
= inferior_thread ();
7289 struct inferior
*inf
= current_inferior ();
7291 if (tp
->control
.step_resume_breakpoint
)
7292 tp
->control
.step_resume_breakpoint
->disposition
= disp_del_at_next_stop
;
7294 if (tp
->control
.exception_resume_breakpoint
)
7295 tp
->control
.exception_resume_breakpoint
->disposition
7296 = disp_del_at_next_stop
;
7298 /* Handle the bpstat_copy of the chain. */
7299 bpstat_clear (&tp
->control
.stop_bpstat
);
7301 tp
->control
= inf_status
->thread_control
;
7302 inf
->control
= inf_status
->inferior_control
;
7305 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
7306 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
7307 stop_after_trap
= inf_status
->stop_after_trap
;
7309 if (target_has_stack
)
7311 /* The point of catch_errors is that if the stack is clobbered,
7312 walking the stack might encounter a garbage pointer and
7313 error() trying to dereference it. */
7315 (restore_selected_frame
, &inf_status
->selected_frame_id
,
7316 "Unable to restore previously selected frame:\n",
7317 RETURN_MASK_ERROR
) == 0)
7318 /* Error in restoring the selected frame. Select the innermost
7320 select_frame (get_current_frame ());
7327 do_restore_infcall_control_state_cleanup (void *sts
)
7329 restore_infcall_control_state (sts
);
7333 make_cleanup_restore_infcall_control_state
7334 (struct infcall_control_state
*inf_status
)
7336 return make_cleanup (do_restore_infcall_control_state_cleanup
, inf_status
);
7340 discard_infcall_control_state (struct infcall_control_state
*inf_status
)
7342 if (inf_status
->thread_control
.step_resume_breakpoint
)
7343 inf_status
->thread_control
.step_resume_breakpoint
->disposition
7344 = disp_del_at_next_stop
;
7346 if (inf_status
->thread_control
.exception_resume_breakpoint
)
7347 inf_status
->thread_control
.exception_resume_breakpoint
->disposition
7348 = disp_del_at_next_stop
;
7350 /* See save_infcall_control_state for info on stop_bpstat. */
7351 bpstat_clear (&inf_status
->thread_control
.stop_bpstat
);
7356 /* restore_inferior_ptid() will be used by the cleanup machinery
7357 to restore the inferior_ptid value saved in a call to
7358 save_inferior_ptid(). */
7361 restore_inferior_ptid (void *arg
)
7363 ptid_t
*saved_ptid_ptr
= arg
;
7365 inferior_ptid
= *saved_ptid_ptr
;
7369 /* Save the value of inferior_ptid so that it may be restored by a
7370 later call to do_cleanups(). Returns the struct cleanup pointer
7371 needed for later doing the cleanup. */
7374 save_inferior_ptid (void)
7376 ptid_t
*saved_ptid_ptr
;
7378 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
7379 *saved_ptid_ptr
= inferior_ptid
;
7380 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
7386 clear_exit_convenience_vars (void)
7388 clear_internalvar (lookup_internalvar ("_exitsignal"));
7389 clear_internalvar (lookup_internalvar ("_exitcode"));
7393 /* User interface for reverse debugging:
7394 Set exec-direction / show exec-direction commands
7395 (returns error unless target implements to_set_exec_direction method). */
7397 int execution_direction
= EXEC_FORWARD
;
7398 static const char exec_forward
[] = "forward";
7399 static const char exec_reverse
[] = "reverse";
7400 static const char *exec_direction
= exec_forward
;
7401 static const char *const exec_direction_names
[] = {
7408 set_exec_direction_func (char *args
, int from_tty
,
7409 struct cmd_list_element
*cmd
)
7411 if (target_can_execute_reverse
)
7413 if (!strcmp (exec_direction
, exec_forward
))
7414 execution_direction
= EXEC_FORWARD
;
7415 else if (!strcmp (exec_direction
, exec_reverse
))
7416 execution_direction
= EXEC_REVERSE
;
7420 exec_direction
= exec_forward
;
7421 error (_("Target does not support this operation."));
7426 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
7427 struct cmd_list_element
*cmd
, const char *value
)
7429 switch (execution_direction
) {
7431 fprintf_filtered (out
, _("Forward.\n"));
7434 fprintf_filtered (out
, _("Reverse.\n"));
7437 internal_error (__FILE__
, __LINE__
,
7438 _("bogus execution_direction value: %d"),
7439 (int) execution_direction
);
7444 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
7445 struct cmd_list_element
*c
, const char *value
)
7447 fprintf_filtered (file
, _("Resuming the execution of threads "
7448 "of all processes is %s.\n"), value
);
7451 /* Implementation of `siginfo' variable. */
7453 static const struct internalvar_funcs siginfo_funcs
=
7461 _initialize_infrun (void)
7465 struct cmd_list_element
*c
;
7467 add_info ("signals", signals_info
, _("\
7468 What debugger does when program gets various signals.\n\
7469 Specify a signal as argument to print info on that signal only."));
7470 add_info_alias ("handle", "signals", 0);
7472 c
= add_com ("handle", class_run
, handle_command
, _("\
7473 Specify how to handle signals.\n\
7474 Usage: handle SIGNAL [ACTIONS]\n\
7475 Args are signals and actions to apply to those signals.\n\
7476 If no actions are specified, the current settings for the specified signals\n\
7477 will be displayed instead.\n\
7479 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7480 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7481 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7482 The special arg \"all\" is recognized to mean all signals except those\n\
7483 used by the debugger, typically SIGTRAP and SIGINT.\n\
7485 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7486 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7487 Stop means reenter debugger if this signal happens (implies print).\n\
7488 Print means print a message if this signal happens.\n\
7489 Pass means let program see this signal; otherwise program doesn't know.\n\
7490 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7491 Pass and Stop may be combined.\n\
7493 Multiple signals may be specified. Signal numbers and signal names\n\
7494 may be interspersed with actions, with the actions being performed for\n\
7495 all signals cumulatively specified."));
7496 set_cmd_completer (c
, handle_completer
);
7500 add_com ("lz", class_info
, signals_info
, _("\
7501 What debugger does when program gets various signals.\n\
7502 Specify a signal as argument to print info on that signal only."));
7503 add_com ("z", class_run
, xdb_handle_command
, _("\
7504 Specify how to handle a signal.\n\
7505 Args are signals and actions to apply to those signals.\n\
7506 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7507 from 1-15 are allowed for compatibility with old versions of GDB.\n\
7508 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7509 The special arg \"all\" is recognized to mean all signals except those\n\
7510 used by the debugger, typically SIGTRAP and SIGINT.\n\
7511 Recognized actions include \"s\" (toggles between stop and nostop),\n\
7512 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
7513 nopass), \"Q\" (noprint)\n\
7514 Stop means reenter debugger if this signal happens (implies print).\n\
7515 Print means print a message if this signal happens.\n\
7516 Pass means let program see this signal; otherwise program doesn't know.\n\
7517 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7518 Pass and Stop may be combined."));
7522 stop_command
= add_cmd ("stop", class_obscure
,
7523 not_just_help_class_command
, _("\
7524 There is no `stop' command, but you can set a hook on `stop'.\n\
7525 This allows you to set a list of commands to be run each time execution\n\
7526 of the program stops."), &cmdlist
);
7528 add_setshow_zuinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
7529 Set inferior debugging."), _("\
7530 Show inferior debugging."), _("\
7531 When non-zero, inferior specific debugging is enabled."),
7534 &setdebuglist
, &showdebuglist
);
7536 add_setshow_boolean_cmd ("displaced", class_maintenance
,
7537 &debug_displaced
, _("\
7538 Set displaced stepping debugging."), _("\
7539 Show displaced stepping debugging."), _("\
7540 When non-zero, displaced stepping specific debugging is enabled."),
7542 show_debug_displaced
,
7543 &setdebuglist
, &showdebuglist
);
7545 add_setshow_boolean_cmd ("non-stop", no_class
,
7547 Set whether gdb controls the inferior in non-stop mode."), _("\
7548 Show whether gdb controls the inferior in non-stop mode."), _("\
7549 When debugging a multi-threaded program and this setting is\n\
7550 off (the default, also called all-stop mode), when one thread stops\n\
7551 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7552 all other threads in the program while you interact with the thread of\n\
7553 interest. When you continue or step a thread, you can allow the other\n\
7554 threads to run, or have them remain stopped, but while you inspect any\n\
7555 thread's state, all threads stop.\n\
7557 In non-stop mode, when one thread stops, other threads can continue\n\
7558 to run freely. You'll be able to step each thread independently,\n\
7559 leave it stopped or free to run as needed."),
7565 numsigs
= (int) GDB_SIGNAL_LAST
;
7566 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
7567 signal_print
= (unsigned char *)
7568 xmalloc (sizeof (signal_print
[0]) * numsigs
);
7569 signal_program
= (unsigned char *)
7570 xmalloc (sizeof (signal_program
[0]) * numsigs
);
7571 signal_catch
= (unsigned char *)
7572 xmalloc (sizeof (signal_catch
[0]) * numsigs
);
7573 signal_pass
= (unsigned char *)
7574 xmalloc (sizeof (signal_pass
[0]) * numsigs
);
7575 for (i
= 0; i
< numsigs
; i
++)
7578 signal_print
[i
] = 1;
7579 signal_program
[i
] = 1;
7580 signal_catch
[i
] = 0;
7583 /* Signals caused by debugger's own actions
7584 should not be given to the program afterwards. */
7585 signal_program
[GDB_SIGNAL_TRAP
] = 0;
7586 signal_program
[GDB_SIGNAL_INT
] = 0;
7588 /* Signals that are not errors should not normally enter the debugger. */
7589 signal_stop
[GDB_SIGNAL_ALRM
] = 0;
7590 signal_print
[GDB_SIGNAL_ALRM
] = 0;
7591 signal_stop
[GDB_SIGNAL_VTALRM
] = 0;
7592 signal_print
[GDB_SIGNAL_VTALRM
] = 0;
7593 signal_stop
[GDB_SIGNAL_PROF
] = 0;
7594 signal_print
[GDB_SIGNAL_PROF
] = 0;
7595 signal_stop
[GDB_SIGNAL_CHLD
] = 0;
7596 signal_print
[GDB_SIGNAL_CHLD
] = 0;
7597 signal_stop
[GDB_SIGNAL_IO
] = 0;
7598 signal_print
[GDB_SIGNAL_IO
] = 0;
7599 signal_stop
[GDB_SIGNAL_POLL
] = 0;
7600 signal_print
[GDB_SIGNAL_POLL
] = 0;
7601 signal_stop
[GDB_SIGNAL_URG
] = 0;
7602 signal_print
[GDB_SIGNAL_URG
] = 0;
7603 signal_stop
[GDB_SIGNAL_WINCH
] = 0;
7604 signal_print
[GDB_SIGNAL_WINCH
] = 0;
7605 signal_stop
[GDB_SIGNAL_PRIO
] = 0;
7606 signal_print
[GDB_SIGNAL_PRIO
] = 0;
7608 /* These signals are used internally by user-level thread
7609 implementations. (See signal(5) on Solaris.) Like the above
7610 signals, a healthy program receives and handles them as part of
7611 its normal operation. */
7612 signal_stop
[GDB_SIGNAL_LWP
] = 0;
7613 signal_print
[GDB_SIGNAL_LWP
] = 0;
7614 signal_stop
[GDB_SIGNAL_WAITING
] = 0;
7615 signal_print
[GDB_SIGNAL_WAITING
] = 0;
7616 signal_stop
[GDB_SIGNAL_CANCEL
] = 0;
7617 signal_print
[GDB_SIGNAL_CANCEL
] = 0;
7619 /* Update cached state. */
7620 signal_cache_update (-1);
7622 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
7623 &stop_on_solib_events
, _("\
7624 Set stopping for shared library events."), _("\
7625 Show stopping for shared library events."), _("\
7626 If nonzero, gdb will give control to the user when the dynamic linker\n\
7627 notifies gdb of shared library events. The most common event of interest\n\
7628 to the user would be loading/unloading of a new library."),
7629 set_stop_on_solib_events
,
7630 show_stop_on_solib_events
,
7631 &setlist
, &showlist
);
7633 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
7634 follow_fork_mode_kind_names
,
7635 &follow_fork_mode_string
, _("\
7636 Set debugger response to a program call of fork or vfork."), _("\
7637 Show debugger response to a program call of fork or vfork."), _("\
7638 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7639 parent - the original process is debugged after a fork\n\
7640 child - the new process is debugged after a fork\n\
7641 The unfollowed process will continue to run.\n\
7642 By default, the debugger will follow the parent process."),
7644 show_follow_fork_mode_string
,
7645 &setlist
, &showlist
);
7647 add_setshow_enum_cmd ("follow-exec-mode", class_run
,
7648 follow_exec_mode_names
,
7649 &follow_exec_mode_string
, _("\
7650 Set debugger response to a program call of exec."), _("\
7651 Show debugger response to a program call of exec."), _("\
7652 An exec call replaces the program image of a process.\n\
7654 follow-exec-mode can be:\n\
7656 new - the debugger creates a new inferior and rebinds the process\n\
7657 to this new inferior. The program the process was running before\n\
7658 the exec call can be restarted afterwards by restarting the original\n\
7661 same - the debugger keeps the process bound to the same inferior.\n\
7662 The new executable image replaces the previous executable loaded in\n\
7663 the inferior. Restarting the inferior after the exec call restarts\n\
7664 the executable the process was running after the exec call.\n\
7666 By default, the debugger will use the same inferior."),
7668 show_follow_exec_mode_string
,
7669 &setlist
, &showlist
);
7671 add_setshow_enum_cmd ("scheduler-locking", class_run
,
7672 scheduler_enums
, &scheduler_mode
, _("\
7673 Set mode for locking scheduler during execution."), _("\
7674 Show mode for locking scheduler during execution."), _("\
7675 off == no locking (threads may preempt at any time)\n\
7676 on == full locking (no thread except the current thread may run)\n\
7677 step == scheduler locked during every single-step operation.\n\
7678 In this mode, no other thread may run during a step command.\n\
7679 Other threads may run while stepping over a function call ('next')."),
7680 set_schedlock_func
, /* traps on target vector */
7681 show_scheduler_mode
,
7682 &setlist
, &showlist
);
7684 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
7685 Set mode for resuming threads of all processes."), _("\
7686 Show mode for resuming threads of all processes."), _("\
7687 When on, execution commands (such as 'continue' or 'next') resume all\n\
7688 threads of all processes. When off (which is the default), execution\n\
7689 commands only resume the threads of the current process. The set of\n\
7690 threads that are resumed is further refined by the scheduler-locking\n\
7691 mode (see help set scheduler-locking)."),
7693 show_schedule_multiple
,
7694 &setlist
, &showlist
);
7696 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
7697 Set mode of the step operation."), _("\
7698 Show mode of the step operation."), _("\
7699 When set, doing a step over a function without debug line information\n\
7700 will stop at the first instruction of that function. Otherwise, the\n\
7701 function is skipped and the step command stops at a different source line."),
7703 show_step_stop_if_no_debug
,
7704 &setlist
, &showlist
);
7706 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run
,
7707 &can_use_displaced_stepping
, _("\
7708 Set debugger's willingness to use displaced stepping."), _("\
7709 Show debugger's willingness to use displaced stepping."), _("\
7710 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7711 supported by the target architecture. If off, gdb will not use displaced\n\
7712 stepping to step over breakpoints, even if such is supported by the target\n\
7713 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7714 if the target architecture supports it and non-stop mode is active, but will not\n\
7715 use it in all-stop mode (see help set non-stop)."),
7717 show_can_use_displaced_stepping
,
7718 &setlist
, &showlist
);
7720 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
7721 &exec_direction
, _("Set direction of execution.\n\
7722 Options are 'forward' or 'reverse'."),
7723 _("Show direction of execution (forward/reverse)."),
7724 _("Tells gdb whether to execute forward or backward."),
7725 set_exec_direction_func
, show_exec_direction_func
,
7726 &setlist
, &showlist
);
7728 /* Set/show detach-on-fork: user-settable mode. */
7730 add_setshow_boolean_cmd ("detach-on-fork", class_run
, &detach_fork
, _("\
7731 Set whether gdb will detach the child of a fork."), _("\
7732 Show whether gdb will detach the child of a fork."), _("\
7733 Tells gdb whether to detach the child of a fork."),
7734 NULL
, NULL
, &setlist
, &showlist
);
7736 /* Set/show disable address space randomization mode. */
7738 add_setshow_boolean_cmd ("disable-randomization", class_support
,
7739 &disable_randomization
, _("\
7740 Set disabling of debuggee's virtual address space randomization."), _("\
7741 Show disabling of debuggee's virtual address space randomization."), _("\
7742 When this mode is on (which is the default), randomization of the virtual\n\
7743 address space is disabled. Standalone programs run with the randomization\n\
7744 enabled by default on some platforms."),
7745 &set_disable_randomization
,
7746 &show_disable_randomization
,
7747 &setlist
, &showlist
);
7749 /* ptid initializations */
7750 inferior_ptid
= null_ptid
;
7751 target_last_wait_ptid
= minus_one_ptid
;
7753 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
7754 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
7755 observer_attach_thread_exit (infrun_thread_thread_exit
);
7756 observer_attach_inferior_exit (infrun_inferior_exit
);
7758 /* Explicitly create without lookup, since that tries to create a
7759 value with a void typed value, and when we get here, gdbarch
7760 isn't initialized yet. At this point, we're quite sure there
7761 isn't another convenience variable of the same name. */
7762 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs
, NULL
);
7764 add_setshow_boolean_cmd ("observer", no_class
,
7765 &observer_mode_1
, _("\
7766 Set whether gdb controls the inferior in observer mode."), _("\
7767 Show whether gdb controls the inferior in observer mode."), _("\
7768 In observer mode, GDB can get data from the inferior, but not\n\
7769 affect its execution. Registers and memory may not be changed,\n\
7770 breakpoints may not be set, and the program cannot be interrupted\n\