1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
6 2008, 2009 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
53 /* Prototypes for local functions */
55 static void signals_info (char *, int);
57 static void handle_command (char *, int);
59 static void sig_print_info (enum target_signal
);
61 static void sig_print_header (void);
63 static void resume_cleanups (void *);
65 static int hook_stop_stub (void *);
67 static int restore_selected_frame (void *);
69 static void build_infrun (void);
71 static int follow_fork (void);
73 static void set_schedlock_func (char *args
, int from_tty
,
74 struct cmd_list_element
*c
);
76 static int currently_stepping (struct thread_info
*tp
);
78 static int currently_stepping_callback (struct thread_info
*tp
, void *data
);
80 static void xdb_handle_command (char *args
, int from_tty
);
82 static int prepare_to_proceed (int);
84 void _initialize_infrun (void);
86 void nullify_last_target_wait_ptid (void);
88 /* When set, stop the 'step' command if we enter a function which has
89 no line number information. The normal behavior is that we step
90 over such function. */
91 int step_stop_if_no_debug
= 0;
93 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
94 struct cmd_list_element
*c
, const char *value
)
96 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
99 /* In asynchronous mode, but simulating synchronous execution. */
101 int sync_execution
= 0;
103 /* wait_for_inferior and normal_stop use this to notify the user
104 when the inferior stopped in a different thread than it had been
107 static ptid_t previous_inferior_ptid
;
109 int debug_displaced
= 0;
111 show_debug_displaced (struct ui_file
*file
, int from_tty
,
112 struct cmd_list_element
*c
, const char *value
)
114 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
117 static int debug_infrun
= 0;
119 show_debug_infrun (struct ui_file
*file
, int from_tty
,
120 struct cmd_list_element
*c
, const char *value
)
122 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
125 /* If the program uses ELF-style shared libraries, then calls to
126 functions in shared libraries go through stubs, which live in a
127 table called the PLT (Procedure Linkage Table). The first time the
128 function is called, the stub sends control to the dynamic linker,
129 which looks up the function's real address, patches the stub so
130 that future calls will go directly to the function, and then passes
131 control to the function.
133 If we are stepping at the source level, we don't want to see any of
134 this --- we just want to skip over the stub and the dynamic linker.
135 The simple approach is to single-step until control leaves the
138 However, on some systems (e.g., Red Hat's 5.2 distribution) the
139 dynamic linker calls functions in the shared C library, so you
140 can't tell from the PC alone whether the dynamic linker is still
141 running. In this case, we use a step-resume breakpoint to get us
142 past the dynamic linker, as if we were using "next" to step over a
145 in_solib_dynsym_resolve_code() says whether we're in the dynamic
146 linker code or not. Normally, this means we single-step. However,
147 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
148 address where we can place a step-resume breakpoint to get past the
149 linker's symbol resolution function.
151 in_solib_dynsym_resolve_code() can generally be implemented in a
152 pretty portable way, by comparing the PC against the address ranges
153 of the dynamic linker's sections.
155 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
156 it depends on internal details of the dynamic linker. It's usually
157 not too hard to figure out where to put a breakpoint, but it
158 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
159 sanity checking. If it can't figure things out, returning zero and
160 getting the (possibly confusing) stepping behavior is better than
161 signalling an error, which will obscure the change in the
164 /* This function returns TRUE if pc is the address of an instruction
165 that lies within the dynamic linker (such as the event hook, or the
168 This function must be used only when a dynamic linker event has
169 been caught, and the inferior is being stepped out of the hook, or
170 undefined results are guaranteed. */
172 #ifndef SOLIB_IN_DYNAMIC_LINKER
173 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
177 /* Convert the #defines into values. This is temporary until wfi control
178 flow is completely sorted out. */
180 #ifndef CANNOT_STEP_HW_WATCHPOINTS
181 #define CANNOT_STEP_HW_WATCHPOINTS 0
183 #undef CANNOT_STEP_HW_WATCHPOINTS
184 #define CANNOT_STEP_HW_WATCHPOINTS 1
187 /* Tables of how to react to signals; the user sets them. */
189 static unsigned char *signal_stop
;
190 static unsigned char *signal_print
;
191 static unsigned char *signal_program
;
193 #define SET_SIGS(nsigs,sigs,flags) \
195 int signum = (nsigs); \
196 while (signum-- > 0) \
197 if ((sigs)[signum]) \
198 (flags)[signum] = 1; \
201 #define UNSET_SIGS(nsigs,sigs,flags) \
203 int signum = (nsigs); \
204 while (signum-- > 0) \
205 if ((sigs)[signum]) \
206 (flags)[signum] = 0; \
209 /* Value to pass to target_resume() to cause all threads to resume */
211 #define RESUME_ALL (pid_to_ptid (-1))
213 /* Command list pointer for the "stop" placeholder. */
215 static struct cmd_list_element
*stop_command
;
217 /* Function inferior was in as of last step command. */
219 static struct symbol
*step_start_function
;
221 /* Nonzero if we want to give control to the user when we're notified
222 of shared library events by the dynamic linker. */
223 static int stop_on_solib_events
;
225 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
226 struct cmd_list_element
*c
, const char *value
)
228 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
232 /* Nonzero means expecting a trace trap
233 and should stop the inferior and return silently when it happens. */
237 /* Save register contents here when executing a "finish" command or are
238 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
239 Thus this contains the return value from the called function (assuming
240 values are returned in a register). */
242 struct regcache
*stop_registers
;
244 /* Nonzero after stop if current stack frame should be printed. */
246 static int stop_print_frame
;
248 /* This is a cached copy of the pid/waitstatus of the last event
249 returned by target_wait()/deprecated_target_wait_hook(). This
250 information is returned by get_last_target_status(). */
251 static ptid_t target_last_wait_ptid
;
252 static struct target_waitstatus target_last_waitstatus
;
254 static void context_switch (ptid_t ptid
);
256 void init_thread_stepping_state (struct thread_info
*tss
);
258 void init_infwait_state (void);
260 static const char follow_fork_mode_child
[] = "child";
261 static const char follow_fork_mode_parent
[] = "parent";
263 static const char *follow_fork_mode_kind_names
[] = {
264 follow_fork_mode_child
,
265 follow_fork_mode_parent
,
269 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
271 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
272 struct cmd_list_element
*c
, const char *value
)
274 fprintf_filtered (file
, _("\
275 Debugger response to a program call of fork or vfork is \"%s\".\n"),
280 /* Tell the target to follow the fork we're stopped at. Returns true
281 if the inferior should be resumed; false, if the target for some
282 reason decided it's best not to resume. */
287 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
288 int should_resume
= 1;
289 struct thread_info
*tp
;
291 /* Copy user stepping state to the new inferior thread. FIXME: the
292 followed fork child thread should have a copy of most of the
293 parent thread structure's run control related fields, not just these.
294 Initialized to avoid "may be used uninitialized" warnings from gcc. */
295 struct breakpoint
*step_resume_breakpoint
= NULL
;
296 CORE_ADDR step_range_start
= 0;
297 CORE_ADDR step_range_end
= 0;
298 struct frame_id step_frame_id
= { 0 };
303 struct target_waitstatus wait_status
;
305 /* Get the last target status returned by target_wait(). */
306 get_last_target_status (&wait_ptid
, &wait_status
);
308 /* If not stopped at a fork event, then there's nothing else to
310 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
311 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
314 /* Check if we switched over from WAIT_PTID, since the event was
316 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
317 && !ptid_equal (inferior_ptid
, wait_ptid
))
319 /* We did. Switch back to WAIT_PTID thread, to tell the
320 target to follow it (in either direction). We'll
321 afterwards refuse to resume, and inform the user what
323 switch_to_thread (wait_ptid
);
328 tp
= inferior_thread ();
330 /* If there were any forks/vforks that were caught and are now to be
331 followed, then do so now. */
332 switch (tp
->pending_follow
.kind
)
334 case TARGET_WAITKIND_FORKED
:
335 case TARGET_WAITKIND_VFORKED
:
337 ptid_t parent
, child
;
339 /* If the user did a next/step, etc, over a fork call,
340 preserve the stepping state in the fork child. */
341 if (follow_child
&& should_resume
)
343 step_resume_breakpoint
344 = clone_momentary_breakpoint (tp
->step_resume_breakpoint
);
345 step_range_start
= tp
->step_range_start
;
346 step_range_end
= tp
->step_range_end
;
347 step_frame_id
= tp
->step_frame_id
;
349 /* For now, delete the parent's sr breakpoint, otherwise,
350 parent/child sr breakpoints are considered duplicates,
351 and the child version will not be installed. Remove
352 this when the breakpoints module becomes aware of
353 inferiors and address spaces. */
354 delete_step_resume_breakpoint (tp
);
355 tp
->step_range_start
= 0;
356 tp
->step_range_end
= 0;
357 tp
->step_frame_id
= null_frame_id
;
360 parent
= inferior_ptid
;
361 child
= tp
->pending_follow
.value
.related_pid
;
363 /* Tell the target to do whatever is necessary to follow
364 either parent or child. */
365 if (target_follow_fork (follow_child
))
367 /* Target refused to follow, or there's some other reason
368 we shouldn't resume. */
373 /* This pending follow fork event is now handled, one way
374 or another. The previous selected thread may be gone
375 from the lists by now, but if it is still around, need
376 to clear the pending follow request. */
377 tp
= find_thread_pid (parent
);
379 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
381 /* This makes sure we don't try to apply the "Switched
382 over from WAIT_PID" logic above. */
383 nullify_last_target_wait_ptid ();
385 /* If we followed the child, switch to it... */
388 switch_to_thread (child
);
390 /* ... and preserve the stepping state, in case the
391 user was stepping over the fork call. */
394 tp
= inferior_thread ();
395 tp
->step_resume_breakpoint
= step_resume_breakpoint
;
396 tp
->step_range_start
= step_range_start
;
397 tp
->step_range_end
= step_range_end
;
398 tp
->step_frame_id
= step_frame_id
;
402 /* If we get here, it was because we're trying to
403 resume from a fork catchpoint, but, the user
404 has switched threads away from the thread that
405 forked. In that case, the resume command
406 issued is most likely not applicable to the
407 child, so just warn, and refuse to resume. */
409 Not resuming: switched threads before following fork child.\n"));
412 /* Reset breakpoints in the child as appropriate. */
413 follow_inferior_reset_breakpoints ();
416 switch_to_thread (parent
);
420 case TARGET_WAITKIND_SPURIOUS
:
421 /* Nothing to follow. */
424 internal_error (__FILE__
, __LINE__
,
425 "Unexpected pending_follow.kind %d\n",
426 tp
->pending_follow
.kind
);
430 return should_resume
;
434 follow_inferior_reset_breakpoints (void)
436 struct thread_info
*tp
= inferior_thread ();
438 /* Was there a step_resume breakpoint? (There was if the user
439 did a "next" at the fork() call.) If so, explicitly reset its
442 step_resumes are a form of bp that are made to be per-thread.
443 Since we created the step_resume bp when the parent process
444 was being debugged, and now are switching to the child process,
445 from the breakpoint package's viewpoint, that's a switch of
446 "threads". We must update the bp's notion of which thread
447 it is for, or it'll be ignored when it triggers. */
449 if (tp
->step_resume_breakpoint
)
450 breakpoint_re_set_thread (tp
->step_resume_breakpoint
);
452 /* Reinsert all breakpoints in the child. The user may have set
453 breakpoints after catching the fork, in which case those
454 were never set in the child, but only in the parent. This makes
455 sure the inserted breakpoints match the breakpoint list. */
457 breakpoint_re_set ();
458 insert_breakpoints ();
461 /* EXECD_PATHNAME is assumed to be non-NULL. */
464 follow_exec (ptid_t pid
, char *execd_pathname
)
466 struct target_ops
*tgt
;
467 struct thread_info
*th
= inferior_thread ();
469 /* This is an exec event that we actually wish to pay attention to.
470 Refresh our symbol table to the newly exec'd program, remove any
473 If there are breakpoints, they aren't really inserted now,
474 since the exec() transformed our inferior into a fresh set
477 We want to preserve symbolic breakpoints on the list, since
478 we have hopes that they can be reset after the new a.out's
479 symbol table is read.
481 However, any "raw" breakpoints must be removed from the list
482 (e.g., the solib bp's), since their address is probably invalid
485 And, we DON'T want to call delete_breakpoints() here, since
486 that may write the bp's "shadow contents" (the instruction
487 value that was overwritten witha TRAP instruction). Since
488 we now have a new a.out, those shadow contents aren't valid. */
489 update_breakpoints_after_exec ();
491 /* If there was one, it's gone now. We cannot truly step-to-next
492 statement through an exec(). */
493 th
->step_resume_breakpoint
= NULL
;
494 th
->step_range_start
= 0;
495 th
->step_range_end
= 0;
497 /* What is this a.out's name? */
498 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
500 /* We've followed the inferior through an exec. Therefore, the
501 inferior has essentially been killed & reborn. */
503 gdb_flush (gdb_stdout
);
505 breakpoint_init_inferior (inf_execd
);
507 if (gdb_sysroot
&& *gdb_sysroot
)
509 char *name
= alloca (strlen (gdb_sysroot
)
510 + strlen (execd_pathname
)
512 strcpy (name
, gdb_sysroot
);
513 strcat (name
, execd_pathname
);
514 execd_pathname
= name
;
517 /* That a.out is now the one to use. */
518 exec_file_attach (execd_pathname
, 0);
520 /* Reset the shared library package. This ensures that we get a
521 shlib event when the child reaches "_start", at which point the
522 dld will have had a chance to initialize the child. */
523 /* Also, loading a symbol file below may trigger symbol lookups, and
524 we don't want those to be satisfied by the libraries of the
525 previous incarnation of this process. */
526 no_shared_libraries (NULL
, 0);
528 /* Load the main file's symbols. */
529 symbol_file_add_main (execd_pathname
, 0);
531 #ifdef SOLIB_CREATE_INFERIOR_HOOK
532 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
534 solib_create_inferior_hook ();
537 /* Reinsert all breakpoints. (Those which were symbolic have
538 been reset to the proper address in the new a.out, thanks
539 to symbol_file_command...) */
540 insert_breakpoints ();
542 /* The next resume of this inferior should bring it to the shlib
543 startup breakpoints. (If the user had also set bp's on
544 "main" from the old (parent) process, then they'll auto-
545 matically get reset there in the new process.) */
548 /* Non-zero if we just simulating a single-step. This is needed
549 because we cannot remove the breakpoints in the inferior process
550 until after the `wait' in `wait_for_inferior'. */
551 static int singlestep_breakpoints_inserted_p
= 0;
553 /* The thread we inserted single-step breakpoints for. */
554 static ptid_t singlestep_ptid
;
556 /* PC when we started this single-step. */
557 static CORE_ADDR singlestep_pc
;
559 /* If another thread hit the singlestep breakpoint, we save the original
560 thread here so that we can resume single-stepping it later. */
561 static ptid_t saved_singlestep_ptid
;
562 static int stepping_past_singlestep_breakpoint
;
564 /* If not equal to null_ptid, this means that after stepping over breakpoint
565 is finished, we need to switch to deferred_step_ptid, and step it.
567 The use case is when one thread has hit a breakpoint, and then the user
568 has switched to another thread and issued 'step'. We need to step over
569 breakpoint in the thread which hit the breakpoint, but then continue
570 stepping the thread user has selected. */
571 static ptid_t deferred_step_ptid
;
573 /* Displaced stepping. */
575 /* In non-stop debugging mode, we must take special care to manage
576 breakpoints properly; in particular, the traditional strategy for
577 stepping a thread past a breakpoint it has hit is unsuitable.
578 'Displaced stepping' is a tactic for stepping one thread past a
579 breakpoint it has hit while ensuring that other threads running
580 concurrently will hit the breakpoint as they should.
582 The traditional way to step a thread T off a breakpoint in a
583 multi-threaded program in all-stop mode is as follows:
585 a0) Initially, all threads are stopped, and breakpoints are not
587 a1) We single-step T, leaving breakpoints uninserted.
588 a2) We insert breakpoints, and resume all threads.
590 In non-stop debugging, however, this strategy is unsuitable: we
591 don't want to have to stop all threads in the system in order to
592 continue or step T past a breakpoint. Instead, we use displaced
595 n0) Initially, T is stopped, other threads are running, and
596 breakpoints are inserted.
597 n1) We copy the instruction "under" the breakpoint to a separate
598 location, outside the main code stream, making any adjustments
599 to the instruction, register, and memory state as directed by
601 n2) We single-step T over the instruction at its new location.
602 n3) We adjust the resulting register and memory state as directed
603 by T's architecture. This includes resetting T's PC to point
604 back into the main instruction stream.
607 This approach depends on the following gdbarch methods:
609 - gdbarch_max_insn_length and gdbarch_displaced_step_location
610 indicate where to copy the instruction, and how much space must
611 be reserved there. We use these in step n1.
613 - gdbarch_displaced_step_copy_insn copies a instruction to a new
614 address, and makes any necessary adjustments to the instruction,
615 register contents, and memory. We use this in step n1.
617 - gdbarch_displaced_step_fixup adjusts registers and memory after
618 we have successfuly single-stepped the instruction, to yield the
619 same effect the instruction would have had if we had executed it
620 at its original address. We use this in step n3.
622 - gdbarch_displaced_step_free_closure provides cleanup.
624 The gdbarch_displaced_step_copy_insn and
625 gdbarch_displaced_step_fixup functions must be written so that
626 copying an instruction with gdbarch_displaced_step_copy_insn,
627 single-stepping across the copied instruction, and then applying
628 gdbarch_displaced_insn_fixup should have the same effects on the
629 thread's memory and registers as stepping the instruction in place
630 would have. Exactly which responsibilities fall to the copy and
631 which fall to the fixup is up to the author of those functions.
633 See the comments in gdbarch.sh for details.
635 Note that displaced stepping and software single-step cannot
636 currently be used in combination, although with some care I think
637 they could be made to. Software single-step works by placing
638 breakpoints on all possible subsequent instructions; if the
639 displaced instruction is a PC-relative jump, those breakpoints
640 could fall in very strange places --- on pages that aren't
641 executable, or at addresses that are not proper instruction
642 boundaries. (We do generally let other threads run while we wait
643 to hit the software single-step breakpoint, and they might
644 encounter such a corrupted instruction.) One way to work around
645 this would be to have gdbarch_displaced_step_copy_insn fully
646 simulate the effect of PC-relative instructions (and return NULL)
647 on architectures that use software single-stepping.
649 In non-stop mode, we can have independent and simultaneous step
650 requests, so more than one thread may need to simultaneously step
651 over a breakpoint. The current implementation assumes there is
652 only one scratch space per process. In this case, we have to
653 serialize access to the scratch space. If thread A wants to step
654 over a breakpoint, but we are currently waiting for some other
655 thread to complete a displaced step, we leave thread A stopped and
656 place it in the displaced_step_request_queue. Whenever a displaced
657 step finishes, we pick the next thread in the queue and start a new
658 displaced step operation on it. See displaced_step_prepare and
659 displaced_step_fixup for details. */
661 /* If this is not null_ptid, this is the thread carrying out a
662 displaced single-step. This thread's state will require fixing up
663 once it has completed its step. */
664 static ptid_t displaced_step_ptid
;
666 struct displaced_step_request
669 struct displaced_step_request
*next
;
672 /* A queue of pending displaced stepping requests. */
673 struct displaced_step_request
*displaced_step_request_queue
;
675 /* The architecture the thread had when we stepped it. */
676 static struct gdbarch
*displaced_step_gdbarch
;
678 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
679 for post-step cleanup. */
680 static struct displaced_step_closure
*displaced_step_closure
;
682 /* The address of the original instruction, and the copy we made. */
683 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
685 /* Saved contents of copy area. */
686 static gdb_byte
*displaced_step_saved_copy
;
688 /* Enum strings for "set|show displaced-stepping". */
690 static const char can_use_displaced_stepping_auto
[] = "auto";
691 static const char can_use_displaced_stepping_on
[] = "on";
692 static const char can_use_displaced_stepping_off
[] = "off";
693 static const char *can_use_displaced_stepping_enum
[] =
695 can_use_displaced_stepping_auto
,
696 can_use_displaced_stepping_on
,
697 can_use_displaced_stepping_off
,
701 /* If ON, and the architecture supports it, GDB will use displaced
702 stepping to step over breakpoints. If OFF, or if the architecture
703 doesn't support it, GDB will instead use the traditional
704 hold-and-step approach. If AUTO (which is the default), GDB will
705 decide which technique to use to step over breakpoints depending on
706 which of all-stop or non-stop mode is active --- displaced stepping
707 in non-stop mode; hold-and-step in all-stop mode. */
709 static const char *can_use_displaced_stepping
=
710 can_use_displaced_stepping_auto
;
713 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
714 struct cmd_list_element
*c
,
717 if (can_use_displaced_stepping
== can_use_displaced_stepping_auto
)
718 fprintf_filtered (file
, _("\
719 Debugger's willingness to use displaced stepping to step over \
720 breakpoints is %s (currently %s).\n"),
721 value
, non_stop
? "on" : "off");
723 fprintf_filtered (file
, _("\
724 Debugger's willingness to use displaced stepping to step over \
725 breakpoints is %s.\n"), value
);
728 /* Return non-zero if displaced stepping can/should be used to step
732 use_displaced_stepping (struct gdbarch
*gdbarch
)
734 return (((can_use_displaced_stepping
== can_use_displaced_stepping_auto
736 || can_use_displaced_stepping
== can_use_displaced_stepping_on
)
737 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
741 /* Clean out any stray displaced stepping state. */
743 displaced_step_clear (void)
745 /* Indicate that there is no cleanup pending. */
746 displaced_step_ptid
= null_ptid
;
748 if (displaced_step_closure
)
750 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
751 displaced_step_closure
);
752 displaced_step_closure
= NULL
;
757 cleanup_displaced_step_closure (void *ptr
)
759 struct displaced_step_closure
*closure
= ptr
;
761 gdbarch_displaced_step_free_closure (current_gdbarch
, closure
);
764 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
766 displaced_step_dump_bytes (struct ui_file
*file
,
772 for (i
= 0; i
< len
; i
++)
773 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
774 fputs_unfiltered ("\n", file
);
777 /* Prepare to single-step, using displaced stepping.
779 Note that we cannot use displaced stepping when we have a signal to
780 deliver. If we have a signal to deliver and an instruction to step
781 over, then after the step, there will be no indication from the
782 target whether the thread entered a signal handler or ignored the
783 signal and stepped over the instruction successfully --- both cases
784 result in a simple SIGTRAP. In the first case we mustn't do a
785 fixup, and in the second case we must --- but we can't tell which.
786 Comments in the code for 'random signals' in handle_inferior_event
787 explain how we handle this case instead.
789 Returns 1 if preparing was successful -- this thread is going to be
790 stepped now; or 0 if displaced stepping this thread got queued. */
792 displaced_step_prepare (ptid_t ptid
)
794 struct cleanup
*old_cleanups
, *ignore_cleanups
;
795 struct regcache
*regcache
= get_thread_regcache (ptid
);
796 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
797 CORE_ADDR original
, copy
;
799 struct displaced_step_closure
*closure
;
801 /* We should never reach this function if the architecture does not
802 support displaced stepping. */
803 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
805 /* For the first cut, we're displaced stepping one thread at a
808 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
810 /* Already waiting for a displaced step to finish. Defer this
811 request and place in queue. */
812 struct displaced_step_request
*req
, *new_req
;
815 fprintf_unfiltered (gdb_stdlog
,
816 "displaced: defering step of %s\n",
817 target_pid_to_str (ptid
));
819 new_req
= xmalloc (sizeof (*new_req
));
820 new_req
->ptid
= ptid
;
821 new_req
->next
= NULL
;
823 if (displaced_step_request_queue
)
825 for (req
= displaced_step_request_queue
;
832 displaced_step_request_queue
= new_req
;
839 fprintf_unfiltered (gdb_stdlog
,
840 "displaced: stepping %s now\n",
841 target_pid_to_str (ptid
));
844 displaced_step_clear ();
846 old_cleanups
= save_inferior_ptid ();
847 inferior_ptid
= ptid
;
849 original
= regcache_read_pc (regcache
);
851 copy
= gdbarch_displaced_step_location (gdbarch
);
852 len
= gdbarch_max_insn_length (gdbarch
);
854 /* Save the original contents of the copy area. */
855 displaced_step_saved_copy
= xmalloc (len
);
856 ignore_cleanups
= make_cleanup (free_current_contents
,
857 &displaced_step_saved_copy
);
858 read_memory (copy
, displaced_step_saved_copy
, len
);
861 fprintf_unfiltered (gdb_stdlog
, "displaced: saved 0x%s: ",
863 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
866 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
867 original
, copy
, regcache
);
869 /* We don't support the fully-simulated case at present. */
870 gdb_assert (closure
);
872 make_cleanup (cleanup_displaced_step_closure
, closure
);
874 /* Resume execution at the copy. */
875 regcache_write_pc (regcache
, copy
);
877 discard_cleanups (ignore_cleanups
);
879 do_cleanups (old_cleanups
);
882 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to 0x%s\n",
885 /* Save the information we need to fix things up if the step
887 displaced_step_ptid
= ptid
;
888 displaced_step_gdbarch
= gdbarch
;
889 displaced_step_closure
= closure
;
890 displaced_step_original
= original
;
891 displaced_step_copy
= copy
;
896 displaced_step_clear_cleanup (void *ignore
)
898 displaced_step_clear ();
902 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
904 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
905 inferior_ptid
= ptid
;
906 write_memory (memaddr
, myaddr
, len
);
907 do_cleanups (ptid_cleanup
);
911 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
913 struct cleanup
*old_cleanups
;
915 /* Was this event for the pid we displaced? */
916 if (ptid_equal (displaced_step_ptid
, null_ptid
)
917 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
920 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
922 /* Restore the contents of the copy area. */
924 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
925 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
926 displaced_step_saved_copy
, len
);
928 fprintf_unfiltered (gdb_stdlog
, "displaced: restored 0x%s\n",
929 paddr_nz (displaced_step_copy
));
932 /* Did the instruction complete successfully? */
933 if (signal
== TARGET_SIGNAL_TRAP
)
935 /* Fix up the resulting state. */
936 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
937 displaced_step_closure
,
938 displaced_step_original
,
940 get_thread_regcache (displaced_step_ptid
));
944 /* Since the instruction didn't complete, all we can do is
946 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
947 CORE_ADDR pc
= regcache_read_pc (regcache
);
948 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
949 regcache_write_pc (regcache
, pc
);
952 do_cleanups (old_cleanups
);
954 displaced_step_ptid
= null_ptid
;
956 /* Are there any pending displaced stepping requests? If so, run
958 while (displaced_step_request_queue
)
960 struct displaced_step_request
*head
;
964 head
= displaced_step_request_queue
;
966 displaced_step_request_queue
= head
->next
;
969 context_switch (ptid
);
971 actual_pc
= regcache_read_pc (get_thread_regcache (ptid
));
973 if (breakpoint_here_p (actual_pc
))
976 fprintf_unfiltered (gdb_stdlog
,
977 "displaced: stepping queued %s now\n",
978 target_pid_to_str (ptid
));
980 displaced_step_prepare (ptid
);
986 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
987 paddr_nz (actual_pc
));
988 read_memory (actual_pc
, buf
, sizeof (buf
));
989 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
992 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
994 /* Done, we're stepping a thread. */
1000 struct thread_info
*tp
= inferior_thread ();
1002 /* The breakpoint we were sitting under has since been
1004 tp
->trap_expected
= 0;
1006 /* Go back to what we were trying to do. */
1007 step
= currently_stepping (tp
);
1009 if (debug_displaced
)
1010 fprintf_unfiltered (gdb_stdlog
, "breakpoint is gone %s: step(%d)\n",
1011 target_pid_to_str (tp
->ptid
), step
);
1013 target_resume (ptid
, step
, TARGET_SIGNAL_0
);
1014 tp
->stop_signal
= TARGET_SIGNAL_0
;
1016 /* This request was discarded. See if there's any other
1017 thread waiting for its turn. */
1022 /* Update global variables holding ptids to hold NEW_PTID if they were
1023 holding OLD_PTID. */
1025 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1027 struct displaced_step_request
*it
;
1029 if (ptid_equal (inferior_ptid
, old_ptid
))
1030 inferior_ptid
= new_ptid
;
1032 if (ptid_equal (singlestep_ptid
, old_ptid
))
1033 singlestep_ptid
= new_ptid
;
1035 if (ptid_equal (displaced_step_ptid
, old_ptid
))
1036 displaced_step_ptid
= new_ptid
;
1038 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1039 deferred_step_ptid
= new_ptid
;
1041 for (it
= displaced_step_request_queue
; it
; it
= it
->next
)
1042 if (ptid_equal (it
->ptid
, old_ptid
))
1043 it
->ptid
= new_ptid
;
1049 /* Things to clean up if we QUIT out of resume (). */
1051 resume_cleanups (void *ignore
)
1056 static const char schedlock_off
[] = "off";
1057 static const char schedlock_on
[] = "on";
1058 static const char schedlock_step
[] = "step";
1059 static const char *scheduler_enums
[] = {
1065 static const char *scheduler_mode
= schedlock_off
;
1067 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1068 struct cmd_list_element
*c
, const char *value
)
1070 fprintf_filtered (file
, _("\
1071 Mode for locking scheduler during execution is \"%s\".\n"),
1076 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1078 if (!target_can_lock_scheduler
)
1080 scheduler_mode
= schedlock_off
;
1081 error (_("Target '%s' cannot support this command."), target_shortname
);
1085 /* Try to setup for software single stepping over the specified location.
1086 Return 1 if target_resume() should use hardware single step.
1088 GDBARCH the current gdbarch.
1089 PC the location to step over. */
1092 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1096 if (gdbarch_software_single_step_p (gdbarch
)
1097 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1100 /* Do not pull these breakpoints until after a `wait' in
1101 `wait_for_inferior' */
1102 singlestep_breakpoints_inserted_p
= 1;
1103 singlestep_ptid
= inferior_ptid
;
1109 /* Resume the inferior, but allow a QUIT. This is useful if the user
1110 wants to interrupt some lengthy single-stepping operation
1111 (for child processes, the SIGINT goes to the inferior, and so
1112 we get a SIGINT random_signal, but for remote debugging and perhaps
1113 other targets, that's not true).
1115 STEP nonzero if we should step (zero to continue instead).
1116 SIG is the signal to give the inferior (zero for none). */
1118 resume (int step
, enum target_signal sig
)
1120 int should_resume
= 1;
1121 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1122 struct regcache
*regcache
= get_current_regcache ();
1123 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1124 struct thread_info
*tp
= inferior_thread ();
1125 CORE_ADDR pc
= regcache_read_pc (regcache
);
1130 fprintf_unfiltered (gdb_stdlog
,
1131 "infrun: resume (step=%d, signal=%d), "
1132 "trap_expected=%d\n",
1133 step
, sig
, tp
->trap_expected
);
1135 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
1136 over an instruction that causes a page fault without triggering
1137 a hardware watchpoint. The kernel properly notices that it shouldn't
1138 stop, because the hardware watchpoint is not triggered, but it forgets
1139 the step request and continues the program normally.
1140 Work around the problem by removing hardware watchpoints if a step is
1141 requested, GDB will check for a hardware watchpoint trigger after the
1143 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
1144 remove_hw_watchpoints ();
1147 /* Normally, by the time we reach `resume', the breakpoints are either
1148 removed or inserted, as appropriate. The exception is if we're sitting
1149 at a permanent breakpoint; we need to step over it, but permanent
1150 breakpoints can't be removed. So we have to test for it here. */
1151 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
1153 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1154 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1157 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1158 how to step past a permanent breakpoint on this architecture. Try using\n\
1159 a command like `return' or `jump' to continue execution."));
1162 /* If enabled, step over breakpoints by executing a copy of the
1163 instruction at a different address.
1165 We can't use displaced stepping when we have a signal to deliver;
1166 the comments for displaced_step_prepare explain why. The
1167 comments in the handle_inferior event for dealing with 'random
1168 signals' explain what we do instead. */
1169 if (use_displaced_stepping (gdbarch
)
1170 && tp
->trap_expected
1171 && sig
== TARGET_SIGNAL_0
)
1173 if (!displaced_step_prepare (inferior_ptid
))
1175 /* Got placed in displaced stepping queue. Will be resumed
1176 later when all the currently queued displaced stepping
1177 requests finish. The thread is not executing at this point,
1178 and the call to set_executing will be made later. But we
1179 need to call set_running here, since from frontend point of view,
1180 the thread is running. */
1181 set_running (inferior_ptid
, 1);
1182 discard_cleanups (old_cleanups
);
1187 /* Do we need to do it the hard way, w/temp breakpoints? */
1189 step
= maybe_software_singlestep (gdbarch
, pc
);
1195 resume_ptid
= RESUME_ALL
; /* Default */
1197 /* If STEP is set, it's a request to use hardware stepping
1198 facilities. But in that case, we should never
1199 use singlestep breakpoint. */
1200 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1202 if (singlestep_breakpoints_inserted_p
1203 && stepping_past_singlestep_breakpoint
)
1205 /* The situation here is as follows. In thread T1 we wanted to
1206 single-step. Lacking hardware single-stepping we've
1207 set breakpoint at the PC of the next instruction -- call it
1208 P. After resuming, we've hit that breakpoint in thread T2.
1209 Now we've removed original breakpoint, inserted breakpoint
1210 at P+1, and try to step to advance T2 past breakpoint.
1211 We need to step only T2, as if T1 is allowed to freely run,
1212 it can run past P, and if other threads are allowed to run,
1213 they can hit breakpoint at P+1, and nested hits of single-step
1214 breakpoints is not something we'd want -- that's complicated
1215 to support, and has no value. */
1216 resume_ptid
= inferior_ptid
;
1219 if ((step
|| singlestep_breakpoints_inserted_p
)
1220 && tp
->trap_expected
)
1222 /* We're allowing a thread to run past a breakpoint it has
1223 hit, by single-stepping the thread with the breakpoint
1224 removed. In which case, we need to single-step only this
1225 thread, and keep others stopped, as they can miss this
1226 breakpoint if allowed to run.
1228 The current code actually removes all breakpoints when
1229 doing this, not just the one being stepped over, so if we
1230 let other threads run, we can actually miss any
1231 breakpoint, not just the one at PC. */
1232 resume_ptid
= inferior_ptid
;
1237 /* With non-stop mode on, threads are always handled
1239 resume_ptid
= inferior_ptid
;
1241 else if ((scheduler_mode
== schedlock_on
)
1242 || (scheduler_mode
== schedlock_step
1243 && (step
|| singlestep_breakpoints_inserted_p
)))
1245 /* User-settable 'scheduler' mode requires solo thread resume. */
1246 resume_ptid
= inferior_ptid
;
1249 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1251 /* Most targets can step a breakpoint instruction, thus
1252 executing it normally. But if this one cannot, just
1253 continue and we will hit it anyway. */
1254 if (step
&& breakpoint_inserted_here_p (pc
))
1259 && use_displaced_stepping (gdbarch
)
1260 && tp
->trap_expected
)
1262 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1263 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1266 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
1267 paddr_nz (actual_pc
));
1268 read_memory (actual_pc
, buf
, sizeof (buf
));
1269 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1272 /* Install inferior's terminal modes. */
1273 target_terminal_inferior ();
1275 /* Avoid confusing the next resume, if the next stop/resume
1276 happens to apply to another thread. */
1277 tp
->stop_signal
= TARGET_SIGNAL_0
;
1279 target_resume (resume_ptid
, step
, sig
);
1282 discard_cleanups (old_cleanups
);
1287 /* Clear out all variables saying what to do when inferior is continued.
1288 First do this, then set the ones you want, then call `proceed'. */
1291 clear_proceed_status_thread (struct thread_info
*tp
)
1294 fprintf_unfiltered (gdb_stdlog
,
1295 "infrun: clear_proceed_status_thread (%s)\n",
1296 target_pid_to_str (tp
->ptid
));
1298 tp
->trap_expected
= 0;
1299 tp
->step_range_start
= 0;
1300 tp
->step_range_end
= 0;
1301 tp
->step_frame_id
= null_frame_id
;
1302 tp
->step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1303 tp
->stop_requested
= 0;
1307 tp
->proceed_to_finish
= 0;
1309 /* Discard any remaining commands or status from previous stop. */
1310 bpstat_clear (&tp
->stop_bpstat
);
1314 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
1316 if (is_exited (tp
->ptid
))
1319 clear_proceed_status_thread (tp
);
1324 clear_proceed_status (void)
1326 if (!ptid_equal (inferior_ptid
, null_ptid
))
1328 struct inferior
*inferior
;
1332 /* If in non-stop mode, only delete the per-thread status
1333 of the current thread. */
1334 clear_proceed_status_thread (inferior_thread ());
1338 /* In all-stop mode, delete the per-thread status of
1340 iterate_over_threads (clear_proceed_status_callback
, NULL
);
1343 inferior
= current_inferior ();
1344 inferior
->stop_soon
= NO_STOP_QUIETLY
;
1347 stop_after_trap
= 0;
1349 observer_notify_about_to_proceed ();
1353 regcache_xfree (stop_registers
);
1354 stop_registers
= NULL
;
1358 /* This should be suitable for any targets that support threads. */
1361 prepare_to_proceed (int step
)
1364 struct target_waitstatus wait_status
;
1366 /* Get the last target status returned by target_wait(). */
1367 get_last_target_status (&wait_ptid
, &wait_status
);
1369 /* Make sure we were stopped at a breakpoint. */
1370 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1371 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1376 /* Switched over from WAIT_PID. */
1377 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1378 && !ptid_equal (inferior_ptid
, wait_ptid
))
1380 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1382 if (breakpoint_here_p (regcache_read_pc (regcache
)))
1384 /* If stepping, remember current thread to switch back to. */
1386 deferred_step_ptid
= inferior_ptid
;
1388 /* Switch back to WAIT_PID thread. */
1389 switch_to_thread (wait_ptid
);
1391 /* We return 1 to indicate that there is a breakpoint here,
1392 so we need to step over it before continuing to avoid
1393 hitting it straight away. */
1401 /* Basic routine for continuing the program in various fashions.
1403 ADDR is the address to resume at, or -1 for resume where stopped.
1404 SIGGNAL is the signal to give it, or 0 for none,
1405 or -1 for act according to how it stopped.
1406 STEP is nonzero if should trap after one instruction.
1407 -1 means return after that and print nothing.
1408 You should probably set various step_... variables
1409 before calling here, if you are stepping.
1411 You should call clear_proceed_status before calling proceed. */
1414 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1416 struct regcache
*regcache
;
1417 struct gdbarch
*gdbarch
;
1418 struct thread_info
*tp
;
1422 /* If we're stopped at a fork/vfork, follow the branch set by the
1423 "set follow-fork-mode" command; otherwise, we'll just proceed
1424 resuming the current thread. */
1425 if (!follow_fork ())
1427 /* The target for some reason decided not to resume. */
1432 regcache
= get_current_regcache ();
1433 gdbarch
= get_regcache_arch (regcache
);
1434 pc
= regcache_read_pc (regcache
);
1437 step_start_function
= find_pc_function (pc
);
1439 stop_after_trap
= 1;
1441 if (addr
== (CORE_ADDR
) -1)
1443 if (pc
== stop_pc
&& breakpoint_here_p (pc
)
1444 && execution_direction
!= EXEC_REVERSE
)
1445 /* There is a breakpoint at the address we will resume at,
1446 step one instruction before inserting breakpoints so that
1447 we do not stop right away (and report a second hit at this
1450 Note, we don't do this in reverse, because we won't
1451 actually be executing the breakpoint insn anyway.
1452 We'll be (un-)executing the previous instruction. */
1455 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1456 && gdbarch_single_step_through_delay (gdbarch
,
1457 get_current_frame ()))
1458 /* We stepped onto an instruction that needs to be stepped
1459 again before re-inserting the breakpoint, do so. */
1464 regcache_write_pc (regcache
, addr
);
1468 fprintf_unfiltered (gdb_stdlog
,
1469 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1470 paddr_nz (addr
), siggnal
, step
);
1473 /* In non-stop, each thread is handled individually. The context
1474 must already be set to the right thread here. */
1478 /* In a multi-threaded task we may select another thread and
1479 then continue or step.
1481 But if the old thread was stopped at a breakpoint, it will
1482 immediately cause another breakpoint stop without any
1483 execution (i.e. it will report a breakpoint hit incorrectly).
1484 So we must step over it first.
1486 prepare_to_proceed checks the current thread against the
1487 thread that reported the most recent event. If a step-over
1488 is required it returns TRUE and sets the current thread to
1490 if (prepare_to_proceed (step
))
1494 /* prepare_to_proceed may change the current thread. */
1495 tp
= inferior_thread ();
1499 tp
->trap_expected
= 1;
1500 /* If displaced stepping is enabled, we can step over the
1501 breakpoint without hitting it, so leave all breakpoints
1502 inserted. Otherwise we need to disable all breakpoints, step
1503 one instruction, and then re-add them when that step is
1505 if (!use_displaced_stepping (gdbarch
))
1506 remove_breakpoints ();
1509 /* We can insert breakpoints if we're not trying to step over one,
1510 or if we are stepping over one but we're using displaced stepping
1512 if (! tp
->trap_expected
|| use_displaced_stepping (gdbarch
))
1513 insert_breakpoints ();
1517 /* Pass the last stop signal to the thread we're resuming,
1518 irrespective of whether the current thread is the thread that
1519 got the last event or not. This was historically GDB's
1520 behaviour before keeping a stop_signal per thread. */
1522 struct thread_info
*last_thread
;
1524 struct target_waitstatus last_status
;
1526 get_last_target_status (&last_ptid
, &last_status
);
1527 if (!ptid_equal (inferior_ptid
, last_ptid
)
1528 && !ptid_equal (last_ptid
, null_ptid
)
1529 && !ptid_equal (last_ptid
, minus_one_ptid
))
1531 last_thread
= find_thread_pid (last_ptid
);
1534 tp
->stop_signal
= last_thread
->stop_signal
;
1535 last_thread
->stop_signal
= TARGET_SIGNAL_0
;
1540 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1541 tp
->stop_signal
= siggnal
;
1542 /* If this signal should not be seen by program,
1543 give it zero. Used for debugging signals. */
1544 else if (!signal_program
[tp
->stop_signal
])
1545 tp
->stop_signal
= TARGET_SIGNAL_0
;
1547 annotate_starting ();
1549 /* Make sure that output from GDB appears before output from the
1551 gdb_flush (gdb_stdout
);
1553 /* Refresh prev_pc value just prior to resuming. This used to be
1554 done in stop_stepping, however, setting prev_pc there did not handle
1555 scenarios such as inferior function calls or returning from
1556 a function via the return command. In those cases, the prev_pc
1557 value was not set properly for subsequent commands. The prev_pc value
1558 is used to initialize the starting line number in the ecs. With an
1559 invalid value, the gdb next command ends up stopping at the position
1560 represented by the next line table entry past our start position.
1561 On platforms that generate one line table entry per line, this
1562 is not a problem. However, on the ia64, the compiler generates
1563 extraneous line table entries that do not increase the line number.
1564 When we issue the gdb next command on the ia64 after an inferior call
1565 or a return command, we often end up a few instructions forward, still
1566 within the original line we started.
1568 An attempt was made to have init_execution_control_state () refresh
1569 the prev_pc value before calculating the line number. This approach
1570 did not work because on platforms that use ptrace, the pc register
1571 cannot be read unless the inferior is stopped. At that point, we
1572 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1573 call can fail. Setting the prev_pc value here ensures the value is
1574 updated correctly when the inferior is stopped. */
1575 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
1577 /* Fill in with reasonable starting values. */
1578 init_thread_stepping_state (tp
);
1580 /* Reset to normal state. */
1581 init_infwait_state ();
1583 /* Resume inferior. */
1584 resume (oneproc
|| step
|| bpstat_should_step (), tp
->stop_signal
);
1586 /* Wait for it to stop (if not standalone)
1587 and in any case decode why it stopped, and act accordingly. */
1588 /* Do this only if we are not using the event loop, or if the target
1589 does not support asynchronous execution. */
1590 if (!target_can_async_p ())
1592 wait_for_inferior (0);
1598 /* Start remote-debugging of a machine over a serial link. */
1601 start_remote (int from_tty
)
1603 struct inferior
*inferior
;
1604 init_wait_for_inferior ();
1606 inferior
= current_inferior ();
1607 inferior
->stop_soon
= STOP_QUIETLY_REMOTE
;
1609 /* Always go on waiting for the target, regardless of the mode. */
1610 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1611 indicate to wait_for_inferior that a target should timeout if
1612 nothing is returned (instead of just blocking). Because of this,
1613 targets expecting an immediate response need to, internally, set
1614 things up so that the target_wait() is forced to eventually
1616 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1617 differentiate to its caller what the state of the target is after
1618 the initial open has been performed. Here we're assuming that
1619 the target has stopped. It should be possible to eventually have
1620 target_open() return to the caller an indication that the target
1621 is currently running and GDB state should be set to the same as
1622 for an async run. */
1623 wait_for_inferior (0);
1625 /* Now that the inferior has stopped, do any bookkeeping like
1626 loading shared libraries. We want to do this before normal_stop,
1627 so that the displayed frame is up to date. */
1628 post_create_inferior (¤t_target
, from_tty
);
1633 /* Initialize static vars when a new inferior begins. */
1636 init_wait_for_inferior (void)
1638 /* These are meaningless until the first time through wait_for_inferior. */
1640 breakpoint_init_inferior (inf_starting
);
1642 clear_proceed_status ();
1644 stepping_past_singlestep_breakpoint
= 0;
1645 deferred_step_ptid
= null_ptid
;
1647 target_last_wait_ptid
= minus_one_ptid
;
1649 previous_inferior_ptid
= null_ptid
;
1650 init_infwait_state ();
1652 displaced_step_clear ();
1656 /* This enum encodes possible reasons for doing a target_wait, so that
1657 wfi can call target_wait in one place. (Ultimately the call will be
1658 moved out of the infinite loop entirely.) */
1662 infwait_normal_state
,
1663 infwait_thread_hop_state
,
1664 infwait_step_watch_state
,
1665 infwait_nonstep_watch_state
1668 /* Why did the inferior stop? Used to print the appropriate messages
1669 to the interface from within handle_inferior_event(). */
1670 enum inferior_stop_reason
1672 /* Step, next, nexti, stepi finished. */
1674 /* Inferior terminated by signal. */
1676 /* Inferior exited. */
1678 /* Inferior received signal, and user asked to be notified. */
1680 /* Reverse execution -- target ran out of history info. */
1684 /* The PTID we'll do a target_wait on.*/
1687 /* Current inferior wait state. */
1688 enum infwait_states infwait_state
;
1690 /* Data to be passed around while handling an event. This data is
1691 discarded between events. */
1692 struct execution_control_state
1695 /* The thread that got the event, if this was a thread event; NULL
1697 struct thread_info
*event_thread
;
1699 struct target_waitstatus ws
;
1701 CORE_ADDR stop_func_start
;
1702 CORE_ADDR stop_func_end
;
1703 char *stop_func_name
;
1704 int new_thread_event
;
1708 void init_execution_control_state (struct execution_control_state
*ecs
);
1710 void handle_inferior_event (struct execution_control_state
*ecs
);
1712 static void handle_step_into_function (struct execution_control_state
*ecs
);
1713 static void handle_step_into_function_backward (struct execution_control_state
*ecs
);
1714 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1715 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1716 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
1717 struct frame_id sr_id
);
1718 static void insert_longjmp_resume_breakpoint (CORE_ADDR
);
1720 static void stop_stepping (struct execution_control_state
*ecs
);
1721 static void prepare_to_wait (struct execution_control_state
*ecs
);
1722 static void keep_going (struct execution_control_state
*ecs
);
1723 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1726 /* Callback for iterate over threads. If the thread is stopped, but
1727 the user/frontend doesn't know about that yet, go through
1728 normal_stop, as if the thread had just stopped now. ARG points at
1729 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
1730 ptid_is_pid(PTID) is true, applies to all threads of the process
1731 pointed at by PTID. Otherwise, apply only to the thread pointed by
1735 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
1737 ptid_t ptid
= * (ptid_t
*) arg
;
1739 if ((ptid_equal (info
->ptid
, ptid
)
1740 || ptid_equal (minus_one_ptid
, ptid
)
1741 || (ptid_is_pid (ptid
)
1742 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
1743 && is_running (info
->ptid
)
1744 && !is_executing (info
->ptid
))
1746 struct cleanup
*old_chain
;
1747 struct execution_control_state ecss
;
1748 struct execution_control_state
*ecs
= &ecss
;
1750 memset (ecs
, 0, sizeof (*ecs
));
1752 old_chain
= make_cleanup_restore_current_thread ();
1754 switch_to_thread (info
->ptid
);
1756 /* Go through handle_inferior_event/normal_stop, so we always
1757 have consistent output as if the stop event had been
1759 ecs
->ptid
= info
->ptid
;
1760 ecs
->event_thread
= find_thread_pid (info
->ptid
);
1761 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1762 ecs
->ws
.value
.sig
= TARGET_SIGNAL_0
;
1764 handle_inferior_event (ecs
);
1766 if (!ecs
->wait_some_more
)
1768 struct thread_info
*tp
;
1772 /* Finish off the continuations. The continations
1773 themselves are responsible for realising the thread
1774 didn't finish what it was supposed to do. */
1775 tp
= inferior_thread ();
1776 do_all_intermediate_continuations_thread (tp
);
1777 do_all_continuations_thread (tp
);
1780 do_cleanups (old_chain
);
1786 /* This function is attached as a "thread_stop_requested" observer.
1787 Cleanup local state that assumed the PTID was to be resumed, and
1788 report the stop to the frontend. */
1791 infrun_thread_stop_requested (ptid_t ptid
)
1793 struct displaced_step_request
*it
, *next
, *prev
= NULL
;
1795 /* PTID was requested to stop. Remove it from the displaced
1796 stepping queue, so we don't try to resume it automatically. */
1797 for (it
= displaced_step_request_queue
; it
; it
= next
)
1801 if (ptid_equal (it
->ptid
, ptid
)
1802 || ptid_equal (minus_one_ptid
, ptid
)
1803 || (ptid_is_pid (ptid
)
1804 && ptid_get_pid (ptid
) == ptid_get_pid (it
->ptid
)))
1806 if (displaced_step_request_queue
== it
)
1807 displaced_step_request_queue
= it
->next
;
1809 prev
->next
= it
->next
;
1817 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
1821 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
1823 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
1824 nullify_last_target_wait_ptid ();
1827 /* Callback for iterate_over_threads. */
1830 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
1832 if (is_exited (info
->ptid
))
1835 delete_step_resume_breakpoint (info
);
1839 /* In all-stop, delete the step resume breakpoint of any thread that
1840 had one. In non-stop, delete the step resume breakpoint of the
1841 thread that just stopped. */
1844 delete_step_thread_step_resume_breakpoint (void)
1846 if (!target_has_execution
1847 || ptid_equal (inferior_ptid
, null_ptid
))
1848 /* If the inferior has exited, we have already deleted the step
1849 resume breakpoints out of GDB's lists. */
1854 /* If in non-stop mode, only delete the step-resume or
1855 longjmp-resume breakpoint of the thread that just stopped
1857 struct thread_info
*tp
= inferior_thread ();
1858 delete_step_resume_breakpoint (tp
);
1861 /* In all-stop mode, delete all step-resume and longjmp-resume
1862 breakpoints of any thread that had them. */
1863 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
1866 /* A cleanup wrapper. */
1869 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
1871 delete_step_thread_step_resume_breakpoint ();
1874 /* Pretty print the results of target_wait, for debugging purposes. */
1877 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
1878 const struct target_waitstatus
*ws
)
1880 char *status_string
= target_waitstatus_to_string (ws
);
1881 struct ui_file
*tmp_stream
= mem_fileopen ();
1885 /* The text is split over several lines because it was getting too long.
1886 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
1887 output as a unit; we want only one timestamp printed if debug_timestamp
1890 fprintf_unfiltered (tmp_stream
,
1891 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
1892 if (PIDGET (waiton_ptid
) != -1)
1893 fprintf_unfiltered (tmp_stream
,
1894 " [%s]", target_pid_to_str (waiton_ptid
));
1895 fprintf_unfiltered (tmp_stream
, ", status) =\n");
1896 fprintf_unfiltered (tmp_stream
,
1897 "infrun: %d [%s],\n",
1898 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
1899 fprintf_unfiltered (tmp_stream
,
1903 text
= ui_file_xstrdup (tmp_stream
, &len
);
1905 /* This uses %s in part to handle %'s in the text, but also to avoid
1906 a gcc error: the format attribute requires a string literal. */
1907 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
1909 xfree (status_string
);
1911 ui_file_delete (tmp_stream
);
1914 /* Wait for control to return from inferior to debugger.
1916 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1917 as if they were SIGTRAP signals. This can be useful during
1918 the startup sequence on some targets such as HP/UX, where
1919 we receive an EXEC event instead of the expected SIGTRAP.
1921 If inferior gets a signal, we may decide to start it up again
1922 instead of returning. That is why there is a loop in this function.
1923 When this function actually returns it means the inferior
1924 should be left stopped and GDB should read more commands. */
1927 wait_for_inferior (int treat_exec_as_sigtrap
)
1929 struct cleanup
*old_cleanups
;
1930 struct execution_control_state ecss
;
1931 struct execution_control_state
*ecs
;
1935 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1936 treat_exec_as_sigtrap
);
1939 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
1942 memset (ecs
, 0, sizeof (*ecs
));
1944 overlay_cache_invalid
= 1;
1946 /* We'll update this if & when we switch to a new thread. */
1947 previous_inferior_ptid
= inferior_ptid
;
1949 /* We have to invalidate the registers BEFORE calling target_wait
1950 because they can be loaded from the target while in target_wait.
1951 This makes remote debugging a bit more efficient for those
1952 targets that provide critical registers as part of their normal
1953 status mechanism. */
1955 registers_changed ();
1959 struct cleanup
*old_chain
;
1961 if (deprecated_target_wait_hook
)
1962 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
1964 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
1967 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
1969 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1971 xfree (ecs
->ws
.value
.execd_pathname
);
1972 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1973 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
1976 /* If an error happens while handling the event, propagate GDB's
1977 knowledge of the executing state to the frontend/user running
1979 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
1981 /* Now figure out what to do with the result of the result. */
1982 handle_inferior_event (ecs
);
1984 /* No error, don't finish the state yet. */
1985 discard_cleanups (old_chain
);
1987 if (!ecs
->wait_some_more
)
1991 do_cleanups (old_cleanups
);
1994 /* Asynchronous version of wait_for_inferior. It is called by the
1995 event loop whenever a change of state is detected on the file
1996 descriptor corresponding to the target. It can be called more than
1997 once to complete a single execution command. In such cases we need
1998 to keep the state in a global variable ECSS. If it is the last time
1999 that this function is called for a single execution command, then
2000 report to the user that the inferior has stopped, and do the
2001 necessary cleanups. */
2004 fetch_inferior_event (void *client_data
)
2006 struct execution_control_state ecss
;
2007 struct execution_control_state
*ecs
= &ecss
;
2008 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2009 struct cleanup
*ts_old_chain
;
2010 int was_sync
= sync_execution
;
2012 memset (ecs
, 0, sizeof (*ecs
));
2014 overlay_cache_invalid
= 1;
2016 /* We can only rely on wait_for_more being correct before handling
2017 the event in all-stop, but previous_inferior_ptid isn't used in
2019 if (!ecs
->wait_some_more
)
2020 /* We'll update this if & when we switch to a new thread. */
2021 previous_inferior_ptid
= inferior_ptid
;
2024 /* In non-stop mode, the user/frontend should not notice a thread
2025 switch due to internal events. Make sure we reverse to the
2026 user selected thread and frame after handling the event and
2027 running any breakpoint commands. */
2028 make_cleanup_restore_current_thread ();
2030 /* We have to invalidate the registers BEFORE calling target_wait
2031 because they can be loaded from the target while in target_wait.
2032 This makes remote debugging a bit more efficient for those
2033 targets that provide critical registers as part of their normal
2034 status mechanism. */
2036 registers_changed ();
2038 if (deprecated_target_wait_hook
)
2040 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2042 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2045 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2048 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
2049 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2050 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2051 /* In non-stop mode, each thread is handled individually. Switch
2052 early, so the global state is set correctly for this
2054 context_switch (ecs
->ptid
);
2056 /* If an error happens while handling the event, propagate GDB's
2057 knowledge of the executing state to the frontend/user running
2060 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2062 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2064 /* Now figure out what to do with the result of the result. */
2065 handle_inferior_event (ecs
);
2067 if (!ecs
->wait_some_more
)
2069 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2071 delete_step_thread_step_resume_breakpoint ();
2073 /* We may not find an inferior if this was a process exit. */
2074 if (inf
== NULL
|| inf
->stop_soon
== NO_STOP_QUIETLY
)
2077 if (target_has_execution
2078 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2079 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2080 && ecs
->event_thread
->step_multi
2081 && ecs
->event_thread
->stop_step
)
2082 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2084 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2087 /* No error, don't finish the thread states yet. */
2088 discard_cleanups (ts_old_chain
);
2090 /* Revert thread and frame. */
2091 do_cleanups (old_chain
);
2093 /* If the inferior was in sync execution mode, and now isn't,
2094 restore the prompt. */
2095 if (was_sync
&& !sync_execution
)
2096 display_gdb_prompt (0);
2099 /* Prepare an execution control state for looping through a
2100 wait_for_inferior-type loop. */
2103 init_execution_control_state (struct execution_control_state
*ecs
)
2105 ecs
->random_signal
= 0;
2108 /* Clear context switchable stepping state. */
2111 init_thread_stepping_state (struct thread_info
*tss
)
2113 struct symtab_and_line sal
;
2115 tss
->stepping_over_breakpoint
= 0;
2116 tss
->step_after_step_resume_breakpoint
= 0;
2117 tss
->stepping_through_solib_after_catch
= 0;
2118 tss
->stepping_through_solib_catchpoints
= NULL
;
2120 sal
= find_pc_line (tss
->prev_pc
, 0);
2121 tss
->current_line
= sal
.line
;
2122 tss
->current_symtab
= sal
.symtab
;
2125 /* Return the cached copy of the last pid/waitstatus returned by
2126 target_wait()/deprecated_target_wait_hook(). The data is actually
2127 cached by handle_inferior_event(), which gets called immediately
2128 after target_wait()/deprecated_target_wait_hook(). */
2131 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2133 *ptidp
= target_last_wait_ptid
;
2134 *status
= target_last_waitstatus
;
2138 nullify_last_target_wait_ptid (void)
2140 target_last_wait_ptid
= minus_one_ptid
;
2143 /* Switch thread contexts. */
2146 context_switch (ptid_t ptid
)
2150 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2151 target_pid_to_str (inferior_ptid
));
2152 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2153 target_pid_to_str (ptid
));
2156 switch_to_thread (ptid
);
2160 adjust_pc_after_break (struct execution_control_state
*ecs
)
2162 struct regcache
*regcache
;
2163 struct gdbarch
*gdbarch
;
2164 CORE_ADDR breakpoint_pc
;
2166 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2167 we aren't, just return.
2169 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2170 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2171 implemented by software breakpoints should be handled through the normal
2174 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2175 different signals (SIGILL or SIGEMT for instance), but it is less
2176 clear where the PC is pointing afterwards. It may not match
2177 gdbarch_decr_pc_after_break. I don't know any specific target that
2178 generates these signals at breakpoints (the code has been in GDB since at
2179 least 1992) so I can not guess how to handle them here.
2181 In earlier versions of GDB, a target with
2182 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2183 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2184 target with both of these set in GDB history, and it seems unlikely to be
2185 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2187 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2190 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
2193 /* In reverse execution, when a breakpoint is hit, the instruction
2194 under it has already been de-executed. The reported PC always
2195 points at the breakpoint address, so adjusting it further would
2196 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2199 B1 0x08000000 : INSN1
2200 B2 0x08000001 : INSN2
2202 PC -> 0x08000003 : INSN4
2204 Say you're stopped at 0x08000003 as above. Reverse continuing
2205 from that point should hit B2 as below. Reading the PC when the
2206 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2207 been de-executed already.
2209 B1 0x08000000 : INSN1
2210 B2 PC -> 0x08000001 : INSN2
2214 We can't apply the same logic as for forward execution, because
2215 we would wrongly adjust the PC to 0x08000000, since there's a
2216 breakpoint at PC - 1. We'd then report a hit on B1, although
2217 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2219 if (execution_direction
== EXEC_REVERSE
)
2222 /* If this target does not decrement the PC after breakpoints, then
2223 we have nothing to do. */
2224 regcache
= get_thread_regcache (ecs
->ptid
);
2225 gdbarch
= get_regcache_arch (regcache
);
2226 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2229 /* Find the location where (if we've hit a breakpoint) the
2230 breakpoint would be. */
2231 breakpoint_pc
= regcache_read_pc (regcache
)
2232 - gdbarch_decr_pc_after_break (gdbarch
);
2234 /* Check whether there actually is a software breakpoint inserted at
2237 If in non-stop mode, a race condition is possible where we've
2238 removed a breakpoint, but stop events for that breakpoint were
2239 already queued and arrive later. To suppress those spurious
2240 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2241 and retire them after a number of stop events are reported. */
2242 if (software_breakpoint_inserted_here_p (breakpoint_pc
)
2243 || (non_stop
&& moribund_breakpoint_here_p (breakpoint_pc
)))
2245 struct cleanup
*old_cleanups
= NULL
;
2247 old_cleanups
= record_gdb_operation_disable_set ();
2249 /* When using hardware single-step, a SIGTRAP is reported for both
2250 a completed single-step and a software breakpoint. Need to
2251 differentiate between the two, as the latter needs adjusting
2252 but the former does not.
2254 The SIGTRAP can be due to a completed hardware single-step only if
2255 - we didn't insert software single-step breakpoints
2256 - the thread to be examined is still the current thread
2257 - this thread is currently being stepped
2259 If any of these events did not occur, we must have stopped due
2260 to hitting a software breakpoint, and have to back up to the
2263 As a special case, we could have hardware single-stepped a
2264 software breakpoint. In this case (prev_pc == breakpoint_pc),
2265 we also need to back up to the breakpoint address. */
2267 if (singlestep_breakpoints_inserted_p
2268 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
2269 || !currently_stepping (ecs
->event_thread
)
2270 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
2271 regcache_write_pc (regcache
, breakpoint_pc
);
2274 do_cleanups (old_cleanups
);
2279 init_infwait_state (void)
2281 waiton_ptid
= pid_to_ptid (-1);
2282 infwait_state
= infwait_normal_state
;
2286 error_is_running (void)
2289 Cannot execute this command while the selected thread is running."));
2293 ensure_not_running (void)
2295 if (is_running (inferior_ptid
))
2296 error_is_running ();
2299 /* Given an execution control state that has been freshly filled in
2300 by an event from the inferior, figure out what it means and take
2301 appropriate action. */
2304 handle_inferior_event (struct execution_control_state
*ecs
)
2306 int sw_single_step_trap_p
= 0;
2307 int stopped_by_watchpoint
;
2308 int stepped_after_stopped_by_watchpoint
= 0;
2309 struct symtab_and_line stop_pc_sal
;
2310 enum stop_kind stop_soon
;
2312 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2313 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2314 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
2316 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2318 stop_soon
= inf
->stop_soon
;
2321 stop_soon
= NO_STOP_QUIETLY
;
2323 /* Cache the last pid/waitstatus. */
2324 target_last_wait_ptid
= ecs
->ptid
;
2325 target_last_waitstatus
= ecs
->ws
;
2327 /* Always clear state belonging to the previous time we stopped. */
2328 stop_stack_dummy
= 0;
2330 /* If it's a new process, add it to the thread database */
2332 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
2333 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
2334 && !in_thread_list (ecs
->ptid
));
2336 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2337 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
2338 add_thread (ecs
->ptid
);
2340 ecs
->event_thread
= find_thread_pid (ecs
->ptid
);
2342 /* Dependent on valid ECS->EVENT_THREAD. */
2343 adjust_pc_after_break (ecs
);
2345 /* Dependent on the current PC value modified by adjust_pc_after_break. */
2346 reinit_frame_cache ();
2348 if (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
2350 breakpoint_retire_moribund ();
2352 /* Mark the non-executing threads accordingly. In all-stop, all
2353 threads of all processes are stopped when we get any event
2354 reported. In non-stop mode, only the event thread stops. If
2355 we're handling a process exit in non-stop mode, there's
2356 nothing to do, as threads of the dead process are gone, and
2357 threads of any other process were left running. */
2359 set_executing (minus_one_ptid
, 0);
2360 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2361 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
2362 set_executing (inferior_ptid
, 0);
2365 switch (infwait_state
)
2367 case infwait_thread_hop_state
:
2369 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
2370 /* Cancel the waiton_ptid. */
2371 waiton_ptid
= pid_to_ptid (-1);
2374 case infwait_normal_state
:
2376 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
2379 case infwait_step_watch_state
:
2381 fprintf_unfiltered (gdb_stdlog
,
2382 "infrun: infwait_step_watch_state\n");
2384 stepped_after_stopped_by_watchpoint
= 1;
2387 case infwait_nonstep_watch_state
:
2389 fprintf_unfiltered (gdb_stdlog
,
2390 "infrun: infwait_nonstep_watch_state\n");
2391 insert_breakpoints ();
2393 /* FIXME-maybe: is this cleaner than setting a flag? Does it
2394 handle things like signals arriving and other things happening
2395 in combination correctly? */
2396 stepped_after_stopped_by_watchpoint
= 1;
2400 internal_error (__FILE__
, __LINE__
, _("bad switch"));
2402 infwait_state
= infwait_normal_state
;
2404 switch (ecs
->ws
.kind
)
2406 case TARGET_WAITKIND_LOADED
:
2408 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
2409 /* Ignore gracefully during startup of the inferior, as it might
2410 be the shell which has just loaded some objects, otherwise
2411 add the symbols for the newly loaded objects. Also ignore at
2412 the beginning of an attach or remote session; we will query
2413 the full list of libraries once the connection is
2415 if (stop_soon
== NO_STOP_QUIETLY
)
2417 /* Check for any newly added shared libraries if we're
2418 supposed to be adding them automatically. Switch
2419 terminal for any messages produced by
2420 breakpoint_re_set. */
2421 target_terminal_ours_for_output ();
2422 /* NOTE: cagney/2003-11-25: Make certain that the target
2423 stack's section table is kept up-to-date. Architectures,
2424 (e.g., PPC64), use the section table to perform
2425 operations such as address => section name and hence
2426 require the table to contain all sections (including
2427 those found in shared libraries). */
2428 /* NOTE: cagney/2003-11-25: Pass current_target and not
2429 exec_ops to SOLIB_ADD. This is because current GDB is
2430 only tooled to propagate section_table changes out from
2431 the "current_target" (see target_resize_to_sections), and
2432 not up from the exec stratum. This, of course, isn't
2433 right. "infrun.c" should only interact with the
2434 exec/process stratum, instead relying on the target stack
2435 to propagate relevant changes (stop, section table
2436 changed, ...) up to other layers. */
2438 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2440 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2442 target_terminal_inferior ();
2444 /* If requested, stop when the dynamic linker notifies
2445 gdb of events. This allows the user to get control
2446 and place breakpoints in initializer routines for
2447 dynamically loaded objects (among other things). */
2448 if (stop_on_solib_events
)
2450 stop_stepping (ecs
);
2454 /* NOTE drow/2007-05-11: This might be a good place to check
2455 for "catch load". */
2458 /* If we are skipping through a shell, or through shared library
2459 loading that we aren't interested in, resume the program. If
2460 we're running the program normally, also resume. But stop if
2461 we're attaching or setting up a remote connection. */
2462 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
2464 /* Loading of shared libraries might have changed breakpoint
2465 addresses. Make sure new breakpoints are inserted. */
2466 if (stop_soon
== NO_STOP_QUIETLY
2467 && !breakpoints_always_inserted_mode ())
2468 insert_breakpoints ();
2469 resume (0, TARGET_SIGNAL_0
);
2470 prepare_to_wait (ecs
);
2476 case TARGET_WAITKIND_SPURIOUS
:
2478 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
2479 resume (0, TARGET_SIGNAL_0
);
2480 prepare_to_wait (ecs
);
2483 case TARGET_WAITKIND_EXITED
:
2485 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
2486 inferior_ptid
= ecs
->ptid
;
2487 target_terminal_ours (); /* Must do this before mourn anyway */
2488 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
2490 /* Record the exit code in the convenience variable $_exitcode, so
2491 that the user can inspect this again later. */
2492 set_internalvar (lookup_internalvar ("_exitcode"),
2493 value_from_longest (builtin_type_int32
,
2494 (LONGEST
) ecs
->ws
.value
.integer
));
2495 gdb_flush (gdb_stdout
);
2496 target_mourn_inferior ();
2497 singlestep_breakpoints_inserted_p
= 0;
2498 stop_print_frame
= 0;
2499 stop_stepping (ecs
);
2502 case TARGET_WAITKIND_SIGNALLED
:
2504 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2505 inferior_ptid
= ecs
->ptid
;
2506 stop_print_frame
= 0;
2507 target_terminal_ours (); /* Must do this before mourn anyway */
2509 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
2510 reach here unless the inferior is dead. However, for years
2511 target_kill() was called here, which hints that fatal signals aren't
2512 really fatal on some systems. If that's true, then some changes
2514 target_mourn_inferior ();
2516 print_stop_reason (SIGNAL_EXITED
, ecs
->ws
.value
.sig
);
2517 singlestep_breakpoints_inserted_p
= 0;
2518 stop_stepping (ecs
);
2521 /* The following are the only cases in which we keep going;
2522 the above cases end in a continue or goto. */
2523 case TARGET_WAITKIND_FORKED
:
2524 case TARGET_WAITKIND_VFORKED
:
2526 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
2528 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2530 context_switch (ecs
->ptid
);
2531 reinit_frame_cache ();
2534 /* Immediately detach breakpoints from the child before there's
2535 any chance of letting the user delete breakpoints from the
2536 breakpoint lists. If we don't do this early, it's easy to
2537 leave left over traps in the child, vis: "break foo; catch
2538 fork; c; <fork>; del; c; <child calls foo>". We only follow
2539 the fork on the last `continue', and by that time the
2540 breakpoint at "foo" is long gone from the breakpoint table.
2541 If we vforked, then we don't need to unpatch here, since both
2542 parent and child are sharing the same memory pages; we'll
2543 need to unpatch at follow/detach time instead to be certain
2544 that new breakpoints added between catchpoint hit time and
2545 vfork follow are detached. */
2546 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
2548 int child_pid
= ptid_get_pid (ecs
->ws
.value
.related_pid
);
2550 /* This won't actually modify the breakpoint list, but will
2551 physically remove the breakpoints from the child. */
2552 detach_breakpoints (child_pid
);
2555 /* In case the event is caught by a catchpoint, remember that
2556 the event is to be followed at the next resume of the thread,
2557 and not immediately. */
2558 ecs
->event_thread
->pending_follow
= ecs
->ws
;
2560 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2562 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2564 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2566 /* If no catchpoint triggered for this, then keep going. */
2567 if (ecs
->random_signal
)
2571 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2573 should_resume
= follow_fork ();
2575 ecs
->event_thread
= inferior_thread ();
2576 ecs
->ptid
= inferior_ptid
;
2581 stop_stepping (ecs
);
2584 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2585 goto process_event_stop_test
;
2587 case TARGET_WAITKIND_EXECD
:
2589 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
2591 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2593 context_switch (ecs
->ptid
);
2594 reinit_frame_cache ();
2597 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2599 /* This causes the eventpoints and symbol table to be reset.
2600 Must do this now, before trying to determine whether to
2602 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
2604 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2605 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2607 /* Note that this may be referenced from inside
2608 bpstat_stop_status above, through inferior_has_execd. */
2609 xfree (ecs
->ws
.value
.execd_pathname
);
2610 ecs
->ws
.value
.execd_pathname
= NULL
;
2612 /* If no catchpoint triggered for this, then keep going. */
2613 if (ecs
->random_signal
)
2615 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2619 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2620 goto process_event_stop_test
;
2622 /* Be careful not to try to gather much state about a thread
2623 that's in a syscall. It's frequently a losing proposition. */
2624 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2626 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2627 resume (0, TARGET_SIGNAL_0
);
2628 prepare_to_wait (ecs
);
2631 /* Before examining the threads further, step this thread to
2632 get it entirely out of the syscall. (We get notice of the
2633 event when the thread is just on the verge of exiting a
2634 syscall. Stepping one instruction seems to get it back
2636 case TARGET_WAITKIND_SYSCALL_RETURN
:
2638 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2639 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2640 prepare_to_wait (ecs
);
2643 case TARGET_WAITKIND_STOPPED
:
2645 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
2646 ecs
->event_thread
->stop_signal
= ecs
->ws
.value
.sig
;
2649 case TARGET_WAITKIND_NO_HISTORY
:
2650 /* Reverse execution: target ran out of history info. */
2651 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2652 print_stop_reason (NO_HISTORY
, 0);
2653 stop_stepping (ecs
);
2656 /* We had an event in the inferior, but we are not interested
2657 in handling it at this level. The lower layers have already
2658 done what needs to be done, if anything.
2660 One of the possible circumstances for this is when the
2661 inferior produces output for the console. The inferior has
2662 not stopped, and we are ignoring the event. Another possible
2663 circumstance is any event which the lower level knows will be
2664 reported multiple times without an intervening resume. */
2665 case TARGET_WAITKIND_IGNORE
:
2667 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2668 prepare_to_wait (ecs
);
2672 if (ecs
->new_thread_event
)
2675 /* Non-stop assumes that the target handles adding new threads
2676 to the thread list. */
2677 internal_error (__FILE__
, __LINE__
, "\
2678 targets should add new threads to the thread list themselves in non-stop mode.");
2680 /* We may want to consider not doing a resume here in order to
2681 give the user a chance to play with the new thread. It might
2682 be good to make that a user-settable option. */
2684 /* At this point, all threads are stopped (happens automatically
2685 in either the OS or the native code). Therefore we need to
2686 continue all threads in order to make progress. */
2688 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
2689 prepare_to_wait (ecs
);
2693 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
2695 /* Do we need to clean up the state of a thread that has
2696 completed a displaced single-step? (Doing so usually affects
2697 the PC, so do it here, before we set stop_pc.) */
2698 displaced_step_fixup (ecs
->ptid
, ecs
->event_thread
->stop_signal
);
2700 /* If we either finished a single-step or hit a breakpoint, but
2701 the user wanted this thread to be stopped, pretend we got a
2702 SIG0 (generic unsignaled stop). */
2704 if (ecs
->event_thread
->stop_requested
2705 && ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2706 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2709 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2713 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n",
2714 paddr_nz (stop_pc
));
2715 if (target_stopped_by_watchpoint ())
2718 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2720 if (target_stopped_data_address (¤t_target
, &addr
))
2721 fprintf_unfiltered (gdb_stdlog
,
2722 "infrun: stopped data address = 0x%s\n",
2725 fprintf_unfiltered (gdb_stdlog
,
2726 "infrun: (no data address available)\n");
2730 if (stepping_past_singlestep_breakpoint
)
2732 gdb_assert (singlestep_breakpoints_inserted_p
);
2733 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2734 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2736 stepping_past_singlestep_breakpoint
= 0;
2738 /* We've either finished single-stepping past the single-step
2739 breakpoint, or stopped for some other reason. It would be nice if
2740 we could tell, but we can't reliably. */
2741 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2744 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2745 /* Pull the single step breakpoints out of the target. */
2746 remove_single_step_breakpoints ();
2747 singlestep_breakpoints_inserted_p
= 0;
2749 ecs
->random_signal
= 0;
2751 context_switch (saved_singlestep_ptid
);
2752 if (deprecated_context_hook
)
2753 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2755 resume (1, TARGET_SIGNAL_0
);
2756 prepare_to_wait (ecs
);
2761 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2763 /* In non-stop mode, there's never a deferred_step_ptid set. */
2764 gdb_assert (!non_stop
);
2766 /* If we stopped for some other reason than single-stepping, ignore
2767 the fact that we were supposed to switch back. */
2768 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2771 fprintf_unfiltered (gdb_stdlog
,
2772 "infrun: handling deferred step\n");
2774 /* Pull the single step breakpoints out of the target. */
2775 if (singlestep_breakpoints_inserted_p
)
2777 remove_single_step_breakpoints ();
2778 singlestep_breakpoints_inserted_p
= 0;
2781 /* Note: We do not call context_switch at this point, as the
2782 context is already set up for stepping the original thread. */
2783 switch_to_thread (deferred_step_ptid
);
2784 deferred_step_ptid
= null_ptid
;
2785 /* Suppress spurious "Switching to ..." message. */
2786 previous_inferior_ptid
= inferior_ptid
;
2788 resume (1, TARGET_SIGNAL_0
);
2789 prepare_to_wait (ecs
);
2793 deferred_step_ptid
= null_ptid
;
2796 /* See if a thread hit a thread-specific breakpoint that was meant for
2797 another thread. If so, then step that thread past the breakpoint,
2800 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2802 int thread_hop_needed
= 0;
2804 /* Check if a regular breakpoint has been hit before checking
2805 for a potential single step breakpoint. Otherwise, GDB will
2806 not see this breakpoint hit when stepping onto breakpoints. */
2807 if (regular_breakpoint_inserted_here_p (stop_pc
))
2809 ecs
->random_signal
= 0;
2810 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2811 thread_hop_needed
= 1;
2813 else if (singlestep_breakpoints_inserted_p
)
2815 /* We have not context switched yet, so this should be true
2816 no matter which thread hit the singlestep breakpoint. */
2817 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2819 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2821 target_pid_to_str (ecs
->ptid
));
2823 ecs
->random_signal
= 0;
2824 /* The call to in_thread_list is necessary because PTIDs sometimes
2825 change when we go from single-threaded to multi-threaded. If
2826 the singlestep_ptid is still in the list, assume that it is
2827 really different from ecs->ptid. */
2828 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2829 && in_thread_list (singlestep_ptid
))
2831 /* If the PC of the thread we were trying to single-step
2832 has changed, discard this event (which we were going
2833 to ignore anyway), and pretend we saw that thread
2834 trap. This prevents us continuously moving the
2835 single-step breakpoint forward, one instruction at a
2836 time. If the PC has changed, then the thread we were
2837 trying to single-step has trapped or been signalled,
2838 but the event has not been reported to GDB yet.
2840 There might be some cases where this loses signal
2841 information, if a signal has arrived at exactly the
2842 same time that the PC changed, but this is the best
2843 we can do with the information available. Perhaps we
2844 should arrange to report all events for all threads
2845 when they stop, or to re-poll the remote looking for
2846 this particular thread (i.e. temporarily enable
2849 CORE_ADDR new_singlestep_pc
2850 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
2852 if (new_singlestep_pc
!= singlestep_pc
)
2854 enum target_signal stop_signal
;
2857 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2858 " but expected thread advanced also\n");
2860 /* The current context still belongs to
2861 singlestep_ptid. Don't swap here, since that's
2862 the context we want to use. Just fudge our
2863 state and continue. */
2864 stop_signal
= ecs
->event_thread
->stop_signal
;
2865 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2866 ecs
->ptid
= singlestep_ptid
;
2867 ecs
->event_thread
= find_thread_pid (ecs
->ptid
);
2868 ecs
->event_thread
->stop_signal
= stop_signal
;
2869 stop_pc
= new_singlestep_pc
;
2874 fprintf_unfiltered (gdb_stdlog
,
2875 "infrun: unexpected thread\n");
2877 thread_hop_needed
= 1;
2878 stepping_past_singlestep_breakpoint
= 1;
2879 saved_singlestep_ptid
= singlestep_ptid
;
2884 if (thread_hop_needed
)
2886 int remove_status
= 0;
2889 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2891 /* Saw a breakpoint, but it was hit by the wrong thread.
2894 if (singlestep_breakpoints_inserted_p
)
2896 /* Pull the single step breakpoints out of the target. */
2897 remove_single_step_breakpoints ();
2898 singlestep_breakpoints_inserted_p
= 0;
2901 /* If the arch can displace step, don't remove the
2903 if (!use_displaced_stepping (current_gdbarch
))
2904 remove_status
= remove_breakpoints ();
2906 /* Did we fail to remove breakpoints? If so, try
2907 to set the PC past the bp. (There's at least
2908 one situation in which we can fail to remove
2909 the bp's: On HP-UX's that use ttrace, we can't
2910 change the address space of a vforking child
2911 process until the child exits (well, okay, not
2912 then either :-) or execs. */
2913 if (remove_status
!= 0)
2914 error (_("Cannot step over breakpoint hit in wrong thread"));
2917 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2918 context_switch (ecs
->ptid
);
2922 /* Only need to require the next event from this
2923 thread in all-stop mode. */
2924 waiton_ptid
= ecs
->ptid
;
2925 infwait_state
= infwait_thread_hop_state
;
2928 ecs
->event_thread
->stepping_over_breakpoint
= 1;
2930 registers_changed ();
2934 else if (singlestep_breakpoints_inserted_p
)
2936 sw_single_step_trap_p
= 1;
2937 ecs
->random_signal
= 0;
2941 ecs
->random_signal
= 1;
2943 /* See if something interesting happened to the non-current thread. If
2944 so, then switch to that thread. */
2945 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2948 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
2950 context_switch (ecs
->ptid
);
2952 if (deprecated_context_hook
)
2953 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2956 if (singlestep_breakpoints_inserted_p
)
2958 /* Pull the single step breakpoints out of the target. */
2959 remove_single_step_breakpoints ();
2960 singlestep_breakpoints_inserted_p
= 0;
2963 if (stepped_after_stopped_by_watchpoint
)
2964 stopped_by_watchpoint
= 0;
2966 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
2968 /* If necessary, step over this watchpoint. We'll be back to display
2970 if (stopped_by_watchpoint
2971 && (target_have_steppable_watchpoint
2972 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
2974 /* At this point, we are stopped at an instruction which has
2975 attempted to write to a piece of memory under control of
2976 a watchpoint. The instruction hasn't actually executed
2977 yet. If we were to evaluate the watchpoint expression
2978 now, we would get the old value, and therefore no change
2979 would seem to have occurred.
2981 In order to make watchpoints work `right', we really need
2982 to complete the memory write, and then evaluate the
2983 watchpoint expression. We do this by single-stepping the
2986 It may not be necessary to disable the watchpoint to stop over
2987 it. For example, the PA can (with some kernel cooperation)
2988 single step over a watchpoint without disabling the watchpoint.
2990 It is far more common to need to disable a watchpoint to step
2991 the inferior over it. If we have non-steppable watchpoints,
2992 we must disable the current watchpoint; it's simplest to
2993 disable all watchpoints and breakpoints. */
2996 if (!target_have_steppable_watchpoint
)
2997 remove_breakpoints ();
2999 hw_step
= maybe_software_singlestep (current_gdbarch
, stop_pc
);
3000 target_resume (ecs
->ptid
, hw_step
, TARGET_SIGNAL_0
);
3001 registers_changed ();
3002 waiton_ptid
= ecs
->ptid
;
3003 if (target_have_steppable_watchpoint
)
3004 infwait_state
= infwait_step_watch_state
;
3006 infwait_state
= infwait_nonstep_watch_state
;
3007 prepare_to_wait (ecs
);
3011 ecs
->stop_func_start
= 0;
3012 ecs
->stop_func_end
= 0;
3013 ecs
->stop_func_name
= 0;
3014 /* Don't care about return value; stop_func_start and stop_func_name
3015 will both be 0 if it doesn't work. */
3016 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3017 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3018 ecs
->stop_func_start
3019 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
3020 ecs
->event_thread
->stepping_over_breakpoint
= 0;
3021 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
3022 ecs
->event_thread
->stop_step
= 0;
3023 stop_print_frame
= 1;
3024 ecs
->random_signal
= 0;
3025 stopped_by_random_signal
= 0;
3027 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3028 && ecs
->event_thread
->trap_expected
3029 && gdbarch_single_step_through_delay_p (current_gdbarch
)
3030 && currently_stepping (ecs
->event_thread
))
3032 /* We're trying to step off a breakpoint. Turns out that we're
3033 also on an instruction that needs to be stepped multiple
3034 times before it's been fully executing. E.g., architectures
3035 with a delay slot. It needs to be stepped twice, once for
3036 the instruction and once for the delay slot. */
3037 int step_through_delay
3038 = gdbarch_single_step_through_delay (current_gdbarch
,
3039 get_current_frame ());
3040 if (debug_infrun
&& step_through_delay
)
3041 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
3042 if (ecs
->event_thread
->step_range_end
== 0 && step_through_delay
)
3044 /* The user issued a continue when stopped at a breakpoint.
3045 Set up for another trap and get out of here. */
3046 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3050 else if (step_through_delay
)
3052 /* The user issued a step when stopped at a breakpoint.
3053 Maybe we should stop, maybe we should not - the delay
3054 slot *might* correspond to a line of source. In any
3055 case, don't decide that here, just set
3056 ecs->stepping_over_breakpoint, making sure we
3057 single-step again before breakpoints are re-inserted. */
3058 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3062 /* Look at the cause of the stop, and decide what to do.
3063 The alternatives are:
3064 1) stop_stepping and return; to really stop and return to the debugger,
3065 2) keep_going and return to start up again
3066 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3067 3) set ecs->random_signal to 1, and the decision between 1 and 2
3068 will be made according to the signal handling tables. */
3070 /* First, distinguish signals caused by the debugger from signals
3071 that have to do with the program's own actions. Note that
3072 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3073 on the operating system version. Here we detect when a SIGILL or
3074 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3075 something similar for SIGSEGV, since a SIGSEGV will be generated
3076 when we're trying to execute a breakpoint instruction on a
3077 non-executable stack. This happens for call dummy breakpoints
3078 for architectures like SPARC that place call dummies on the
3081 If we're doing a displaced step past a breakpoint, then the
3082 breakpoint is always inserted at the original instruction;
3083 non-standard signals can't be explained by the breakpoint. */
3084 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3085 || (! ecs
->event_thread
->trap_expected
3086 && breakpoint_inserted_here_p (stop_pc
)
3087 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_ILL
3088 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_SEGV
3089 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_EMT
))
3090 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3091 || stop_soon
== STOP_QUIETLY_REMOTE
)
3093 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
3096 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
3097 stop_print_frame
= 0;
3098 stop_stepping (ecs
);
3102 /* This is originated from start_remote(), start_inferior() and
3103 shared libraries hook functions. */
3104 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
3107 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3108 stop_stepping (ecs
);
3112 /* This originates from attach_command(). We need to overwrite
3113 the stop_signal here, because some kernels don't ignore a
3114 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3115 See more comments in inferior.h. On the other hand, if we
3116 get a non-SIGSTOP, report it to the user - assume the backend
3117 will handle the SIGSTOP if it should show up later.
3119 Also consider that the attach is complete when we see a
3120 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3121 target extended-remote report it instead of a SIGSTOP
3122 (e.g. gdbserver). We already rely on SIGTRAP being our
3123 signal, so this is no exception.
3125 Also consider that the attach is complete when we see a
3126 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3127 the target to stop all threads of the inferior, in case the
3128 low level attach operation doesn't stop them implicitly. If
3129 they weren't stopped implicitly, then the stub will report a
3130 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3131 other than GDB's request. */
3132 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3133 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_STOP
3134 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3135 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_0
))
3137 stop_stepping (ecs
);
3138 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3142 /* See if there is a breakpoint at the current PC. */
3143 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
3145 /* Following in case break condition called a
3147 stop_print_frame
= 1;
3149 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3150 at one stage in the past included checks for an inferior
3151 function call's call dummy's return breakpoint. The original
3152 comment, that went with the test, read:
3154 ``End of a stack dummy. Some systems (e.g. Sony news) give
3155 another signal besides SIGTRAP, so check here as well as
3158 If someone ever tries to get call dummys on a
3159 non-executable stack to work (where the target would stop
3160 with something like a SIGSEGV), then those tests might need
3161 to be re-instated. Given, however, that the tests were only
3162 enabled when momentary breakpoints were not being used, I
3163 suspect that it won't be the case.
3165 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3166 be necessary for call dummies on a non-executable stack on
3169 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3171 = !(bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
)
3172 || ecs
->event_thread
->trap_expected
3173 || (ecs
->event_thread
->step_range_end
3174 && ecs
->event_thread
->step_resume_breakpoint
== NULL
));
3177 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
3178 if (!ecs
->random_signal
)
3179 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3183 /* When we reach this point, we've pretty much decided
3184 that the reason for stopping must've been a random
3185 (unexpected) signal. */
3188 ecs
->random_signal
= 1;
3190 process_event_stop_test
:
3191 /* For the program's own signals, act according to
3192 the signal handling tables. */
3194 if (ecs
->random_signal
)
3196 /* Signal not for debugging purposes. */
3200 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
3201 ecs
->event_thread
->stop_signal
);
3203 stopped_by_random_signal
= 1;
3205 if (signal_print
[ecs
->event_thread
->stop_signal
])
3208 target_terminal_ours_for_output ();
3209 print_stop_reason (SIGNAL_RECEIVED
, ecs
->event_thread
->stop_signal
);
3211 /* Always stop on signals if we're either just gaining control
3212 of the program, or the user explicitly requested this thread
3213 to remain stopped. */
3214 if (stop_soon
!= NO_STOP_QUIETLY
3215 || ecs
->event_thread
->stop_requested
3216 || signal_stop_state (ecs
->event_thread
->stop_signal
))
3218 stop_stepping (ecs
);
3221 /* If not going to stop, give terminal back
3222 if we took it away. */
3224 target_terminal_inferior ();
3226 /* Clear the signal if it should not be passed. */
3227 if (signal_program
[ecs
->event_thread
->stop_signal
] == 0)
3228 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3230 if (ecs
->event_thread
->prev_pc
== stop_pc
3231 && ecs
->event_thread
->trap_expected
3232 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3234 /* We were just starting a new sequence, attempting to
3235 single-step off of a breakpoint and expecting a SIGTRAP.
3236 Instead this signal arrives. This signal will take us out
3237 of the stepping range so GDB needs to remember to, when
3238 the signal handler returns, resume stepping off that
3240 /* To simplify things, "continue" is forced to use the same
3241 code paths as single-step - set a breakpoint at the
3242 signal return address and then, once hit, step off that
3245 fprintf_unfiltered (gdb_stdlog
,
3246 "infrun: signal arrived while stepping over "
3249 insert_step_resume_breakpoint_at_frame (get_current_frame ());
3250 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
3255 if (ecs
->event_thread
->step_range_end
!= 0
3256 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_0
3257 && (ecs
->event_thread
->step_range_start
<= stop_pc
3258 && stop_pc
< ecs
->event_thread
->step_range_end
)
3259 && frame_id_eq (get_frame_id (get_current_frame ()),
3260 ecs
->event_thread
->step_frame_id
)
3261 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3263 /* The inferior is about to take a signal that will take it
3264 out of the single step range. Set a breakpoint at the
3265 current PC (which is presumably where the signal handler
3266 will eventually return) and then allow the inferior to
3269 Note that this is only needed for a signal delivered
3270 while in the single-step range. Nested signals aren't a
3271 problem as they eventually all return. */
3273 fprintf_unfiltered (gdb_stdlog
,
3274 "infrun: signal may take us out of "
3275 "single-step range\n");
3277 insert_step_resume_breakpoint_at_frame (get_current_frame ());
3282 /* Note: step_resume_breakpoint may be non-NULL. This occures
3283 when either there's a nested signal, or when there's a
3284 pending signal enabled just as the signal handler returns
3285 (leaving the inferior at the step-resume-breakpoint without
3286 actually executing it). Either way continue until the
3287 breakpoint is really hit. */
3292 /* Handle cases caused by hitting a breakpoint. */
3294 CORE_ADDR jmp_buf_pc
;
3295 struct bpstat_what what
;
3297 what
= bpstat_what (ecs
->event_thread
->stop_bpstat
);
3299 if (what
.call_dummy
)
3301 stop_stack_dummy
= 1;
3304 switch (what
.main_action
)
3306 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
3307 /* If we hit the breakpoint at longjmp while stepping, we
3308 install a momentary breakpoint at the target of the
3312 fprintf_unfiltered (gdb_stdlog
,
3313 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
3315 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3317 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
3318 || !gdbarch_get_longjmp_target (current_gdbarch
,
3319 get_current_frame (), &jmp_buf_pc
))
3322 fprintf_unfiltered (gdb_stdlog
, "\
3323 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
3328 /* We're going to replace the current step-resume breakpoint
3329 with a longjmp-resume breakpoint. */
3330 delete_step_resume_breakpoint (ecs
->event_thread
);
3332 /* Insert a breakpoint at resume address. */
3333 insert_longjmp_resume_breakpoint (jmp_buf_pc
);
3338 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
3340 fprintf_unfiltered (gdb_stdlog
,
3341 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
3343 gdb_assert (ecs
->event_thread
->step_resume_breakpoint
!= NULL
);
3344 delete_step_resume_breakpoint (ecs
->event_thread
);
3346 ecs
->event_thread
->stop_step
= 1;
3347 print_stop_reason (END_STEPPING_RANGE
, 0);
3348 stop_stepping (ecs
);
3351 case BPSTAT_WHAT_SINGLE
:
3353 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
3354 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3355 /* Still need to check other stuff, at least the case
3356 where we are stepping and step out of the right range. */
3359 case BPSTAT_WHAT_STOP_NOISY
:
3361 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
3362 stop_print_frame
= 1;
3364 /* We are about to nuke the step_resume_breakpointt via the
3365 cleanup chain, so no need to worry about it here. */
3367 stop_stepping (ecs
);
3370 case BPSTAT_WHAT_STOP_SILENT
:
3372 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
3373 stop_print_frame
= 0;
3375 /* We are about to nuke the step_resume_breakpoin via the
3376 cleanup chain, so no need to worry about it here. */
3378 stop_stepping (ecs
);
3381 case BPSTAT_WHAT_STEP_RESUME
:
3383 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
3385 delete_step_resume_breakpoint (ecs
->event_thread
);
3386 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
3388 /* Back when the step-resume breakpoint was inserted, we
3389 were trying to single-step off a breakpoint. Go back
3391 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
3392 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3396 if (stop_pc
== ecs
->stop_func_start
3397 && execution_direction
== EXEC_REVERSE
)
3399 /* We are stepping over a function call in reverse, and
3400 just hit the step-resume breakpoint at the start
3401 address of the function. Go back to single-stepping,
3402 which should take us back to the function call. */
3403 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3409 case BPSTAT_WHAT_CHECK_SHLIBS
:
3412 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
3414 /* Check for any newly added shared libraries if we're
3415 supposed to be adding them automatically. Switch
3416 terminal for any messages produced by
3417 breakpoint_re_set. */
3418 target_terminal_ours_for_output ();
3419 /* NOTE: cagney/2003-11-25: Make certain that the target
3420 stack's section table is kept up-to-date. Architectures,
3421 (e.g., PPC64), use the section table to perform
3422 operations such as address => section name and hence
3423 require the table to contain all sections (including
3424 those found in shared libraries). */
3425 /* NOTE: cagney/2003-11-25: Pass current_target and not
3426 exec_ops to SOLIB_ADD. This is because current GDB is
3427 only tooled to propagate section_table changes out from
3428 the "current_target" (see target_resize_to_sections), and
3429 not up from the exec stratum. This, of course, isn't
3430 right. "infrun.c" should only interact with the
3431 exec/process stratum, instead relying on the target stack
3432 to propagate relevant changes (stop, section table
3433 changed, ...) up to other layers. */
3435 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
3437 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
3439 target_terminal_inferior ();
3441 /* If requested, stop when the dynamic linker notifies
3442 gdb of events. This allows the user to get control
3443 and place breakpoints in initializer routines for
3444 dynamically loaded objects (among other things). */
3445 if (stop_on_solib_events
|| stop_stack_dummy
)
3447 stop_stepping (ecs
);
3452 /* We want to step over this breakpoint, then keep going. */
3453 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3459 case BPSTAT_WHAT_LAST
:
3460 /* Not a real code, but listed here to shut up gcc -Wall. */
3462 case BPSTAT_WHAT_KEEP_CHECKING
:
3467 /* We come here if we hit a breakpoint but should not
3468 stop for it. Possibly we also were stepping
3469 and should stop for that. So fall through and
3470 test for stepping. But, if not stepping,
3473 /* In all-stop mode, if we're currently stepping but have stopped in
3474 some other thread, we need to switch back to the stepped thread. */
3477 struct thread_info
*tp
;
3478 tp
= iterate_over_threads (currently_stepping_callback
,
3482 /* However, if the current thread is blocked on some internal
3483 breakpoint, and we simply need to step over that breakpoint
3484 to get it going again, do that first. */
3485 if ((ecs
->event_thread
->trap_expected
3486 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
3487 || ecs
->event_thread
->stepping_over_breakpoint
)
3493 /* Otherwise, we no longer expect a trap in the current thread.
3494 Clear the trap_expected flag before switching back -- this is
3495 what keep_going would do as well, if we called it. */
3496 ecs
->event_thread
->trap_expected
= 0;
3499 fprintf_unfiltered (gdb_stdlog
,
3500 "infrun: switching back to stepped thread\n");
3502 ecs
->event_thread
= tp
;
3503 ecs
->ptid
= tp
->ptid
;
3504 context_switch (ecs
->ptid
);
3510 /* Are we stepping to get the inferior out of the dynamic linker's
3511 hook (and possibly the dld itself) after catching a shlib
3513 if (ecs
->event_thread
->stepping_through_solib_after_catch
)
3515 #if defined(SOLIB_ADD)
3516 /* Have we reached our destination? If not, keep going. */
3517 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
3520 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
3521 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3527 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
3528 /* Else, stop and report the catchpoint(s) whose triggering
3529 caused us to begin stepping. */
3530 ecs
->event_thread
->stepping_through_solib_after_catch
= 0;
3531 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
3532 ecs
->event_thread
->stop_bpstat
3533 = bpstat_copy (ecs
->event_thread
->stepping_through_solib_catchpoints
);
3534 bpstat_clear (&ecs
->event_thread
->stepping_through_solib_catchpoints
);
3535 stop_print_frame
= 1;
3536 stop_stepping (ecs
);
3540 if (ecs
->event_thread
->step_resume_breakpoint
)
3543 fprintf_unfiltered (gdb_stdlog
,
3544 "infrun: step-resume breakpoint is inserted\n");
3546 /* Having a step-resume breakpoint overrides anything
3547 else having to do with stepping commands until
3548 that breakpoint is reached. */
3553 if (ecs
->event_thread
->step_range_end
== 0)
3556 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
3557 /* Likewise if we aren't even stepping. */
3562 /* If stepping through a line, keep going if still within it.
3564 Note that step_range_end is the address of the first instruction
3565 beyond the step range, and NOT the address of the last instruction
3567 if (stop_pc
>= ecs
->event_thread
->step_range_start
3568 && stop_pc
< ecs
->event_thread
->step_range_end
)
3571 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
3572 paddr_nz (ecs
->event_thread
->step_range_start
),
3573 paddr_nz (ecs
->event_thread
->step_range_end
));
3575 /* When stepping backward, stop at beginning of line range
3576 (unless it's the function entry point, in which case
3577 keep going back to the call point). */
3578 if (stop_pc
== ecs
->event_thread
->step_range_start
3579 && stop_pc
!= ecs
->stop_func_start
3580 && execution_direction
== EXEC_REVERSE
)
3582 ecs
->event_thread
->stop_step
= 1;
3583 print_stop_reason (END_STEPPING_RANGE
, 0);
3584 stop_stepping (ecs
);
3592 /* We stepped out of the stepping range. */
3594 /* If we are stepping at the source level and entered the runtime
3595 loader dynamic symbol resolution code, we keep on single stepping
3596 until we exit the run time loader code and reach the callee's
3598 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3599 && in_solib_dynsym_resolve_code (stop_pc
))
3601 CORE_ADDR pc_after_resolver
=
3602 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
3605 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
3607 if (pc_after_resolver
)
3609 /* Set up a step-resume breakpoint at the address
3610 indicated by SKIP_SOLIB_RESOLVER. */
3611 struct symtab_and_line sr_sal
;
3613 sr_sal
.pc
= pc_after_resolver
;
3615 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3622 if (ecs
->event_thread
->step_range_end
!= 1
3623 && (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3624 || ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
3625 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
3628 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
3629 /* The inferior, while doing a "step" or "next", has ended up in
3630 a signal trampoline (either by a signal being delivered or by
3631 the signal handler returning). Just single-step until the
3632 inferior leaves the trampoline (either by calling the handler
3638 /* Check for subroutine calls. The check for the current frame
3639 equalling the step ID is not necessary - the check of the
3640 previous frame's ID is sufficient - but it is a common case and
3641 cheaper than checking the previous frame's ID.
3643 NOTE: frame_id_eq will never report two invalid frame IDs as
3644 being equal, so to get into this block, both the current and
3645 previous frame must have valid frame IDs. */
3646 if (!frame_id_eq (get_frame_id (get_current_frame ()),
3647 ecs
->event_thread
->step_frame_id
)
3648 && (frame_id_eq (frame_unwind_id (get_current_frame ()),
3649 ecs
->event_thread
->step_frame_id
)
3650 || execution_direction
== EXEC_REVERSE
))
3652 CORE_ADDR real_stop_pc
;
3655 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
3657 if ((ecs
->event_thread
->step_over_calls
== STEP_OVER_NONE
)
3658 || ((ecs
->event_thread
->step_range_end
== 1)
3659 && in_prologue (ecs
->event_thread
->prev_pc
,
3660 ecs
->stop_func_start
)))
3662 /* I presume that step_over_calls is only 0 when we're
3663 supposed to be stepping at the assembly language level
3664 ("stepi"). Just stop. */
3665 /* Also, maybe we just did a "nexti" inside a prolog, so we
3666 thought it was a subroutine call but it was not. Stop as
3668 ecs
->event_thread
->stop_step
= 1;
3669 print_stop_reason (END_STEPPING_RANGE
, 0);
3670 stop_stepping (ecs
);
3674 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
3676 /* We're doing a "next".
3678 Normal (forward) execution: set a breakpoint at the
3679 callee's return address (the address at which the caller
3682 Reverse (backward) execution. set the step-resume
3683 breakpoint at the start of the function that we just
3684 stepped into (backwards), and continue to there. When we
3685 get there, we'll need to single-step back to the caller. */
3687 if (execution_direction
== EXEC_REVERSE
)
3689 struct symtab_and_line sr_sal
;
3691 if (ecs
->stop_func_start
== 0
3692 && in_solib_dynsym_resolve_code (stop_pc
))
3694 /* Stepped into runtime loader dynamic symbol
3695 resolution code. Since we're in reverse,
3696 we have already backed up through the runtime
3697 loader and the dynamic function. This is just
3698 the trampoline (jump table).
3700 Just keep stepping, we'll soon be home.
3705 /* Normal (staticly linked) function call return. */
3707 sr_sal
.pc
= ecs
->stop_func_start
;
3708 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3711 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3717 /* If we are in a function call trampoline (a stub between the
3718 calling routine and the real function), locate the real
3719 function. That's what tells us (a) whether we want to step
3720 into it at all, and (b) what prologue we want to run to the
3721 end of, if we do step into it. */
3722 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
3723 if (real_stop_pc
== 0)
3724 real_stop_pc
= gdbarch_skip_trampoline_code
3725 (current_gdbarch
, get_current_frame (), stop_pc
);
3726 if (real_stop_pc
!= 0)
3727 ecs
->stop_func_start
= real_stop_pc
;
3729 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
3731 struct symtab_and_line sr_sal
;
3733 sr_sal
.pc
= ecs
->stop_func_start
;
3735 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3740 /* If we have line number information for the function we are
3741 thinking of stepping into, step into it.
3743 If there are several symtabs at that PC (e.g. with include
3744 files), just want to know whether *any* of them have line
3745 numbers. find_pc_line handles this. */
3747 struct symtab_and_line tmp_sal
;
3749 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3750 if (tmp_sal
.line
!= 0)
3752 if (execution_direction
== EXEC_REVERSE
)
3753 handle_step_into_function_backward (ecs
);
3755 handle_step_into_function (ecs
);
3760 /* If we have no line number and the step-stop-if-no-debug is
3761 set, we stop the step so that the user has a chance to switch
3762 in assembly mode. */
3763 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3764 && step_stop_if_no_debug
)
3766 ecs
->event_thread
->stop_step
= 1;
3767 print_stop_reason (END_STEPPING_RANGE
, 0);
3768 stop_stepping (ecs
);
3772 if (execution_direction
== EXEC_REVERSE
)
3774 /* Set a breakpoint at callee's start address.
3775 From there we can step once and be back in the caller. */
3776 struct symtab_and_line sr_sal
;
3778 sr_sal
.pc
= ecs
->stop_func_start
;
3779 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3782 /* Set a breakpoint at callee's return address (the address
3783 at which the caller will resume). */
3784 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3790 /* If we're in the return path from a shared library trampoline,
3791 we want to proceed through the trampoline when stepping. */
3792 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
3793 stop_pc
, ecs
->stop_func_name
))
3795 /* Determine where this trampoline returns. */
3796 CORE_ADDR real_stop_pc
;
3797 real_stop_pc
= gdbarch_skip_trampoline_code
3798 (current_gdbarch
, get_current_frame (), stop_pc
);
3801 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3803 /* Only proceed through if we know where it's going. */
3806 /* And put the step-breakpoint there and go until there. */
3807 struct symtab_and_line sr_sal
;
3809 init_sal (&sr_sal
); /* initialize to zeroes */
3810 sr_sal
.pc
= real_stop_pc
;
3811 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3813 /* Do not specify what the fp should be when we stop since
3814 on some machines the prologue is where the new fp value
3816 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3818 /* Restart without fiddling with the step ranges or
3825 stop_pc_sal
= find_pc_line (stop_pc
, 0);
3827 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3828 the trampoline processing logic, however, there are some trampolines
3829 that have no names, so we should do trampoline handling first. */
3830 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3831 && ecs
->stop_func_name
== NULL
3832 && stop_pc_sal
.line
== 0)
3835 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3837 /* The inferior just stepped into, or returned to, an
3838 undebuggable function (where there is no debugging information
3839 and no line number corresponding to the address where the
3840 inferior stopped). Since we want to skip this kind of code,
3841 we keep going until the inferior returns from this
3842 function - unless the user has asked us not to (via
3843 set step-mode) or we no longer know how to get back
3844 to the call site. */
3845 if (step_stop_if_no_debug
3846 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3848 /* If we have no line number and the step-stop-if-no-debug
3849 is set, we stop the step so that the user has a chance to
3850 switch in assembly mode. */
3851 ecs
->event_thread
->stop_step
= 1;
3852 print_stop_reason (END_STEPPING_RANGE
, 0);
3853 stop_stepping (ecs
);
3858 /* Set a breakpoint at callee's return address (the address
3859 at which the caller will resume). */
3860 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3866 if (ecs
->event_thread
->step_range_end
== 1)
3868 /* It is stepi or nexti. We always want to stop stepping after
3871 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
3872 ecs
->event_thread
->stop_step
= 1;
3873 print_stop_reason (END_STEPPING_RANGE
, 0);
3874 stop_stepping (ecs
);
3878 if (stop_pc_sal
.line
== 0)
3880 /* We have no line number information. That means to stop
3881 stepping (does this always happen right after one instruction,
3882 when we do "s" in a function with no line numbers,
3883 or can this happen as a result of a return or longjmp?). */
3885 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
3886 ecs
->event_thread
->stop_step
= 1;
3887 print_stop_reason (END_STEPPING_RANGE
, 0);
3888 stop_stepping (ecs
);
3892 if ((stop_pc
== stop_pc_sal
.pc
)
3893 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
3894 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
3896 /* We are at the start of a different line. So stop. Note that
3897 we don't stop if we step into the middle of a different line.
3898 That is said to make things like for (;;) statements work
3901 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
3902 ecs
->event_thread
->stop_step
= 1;
3903 print_stop_reason (END_STEPPING_RANGE
, 0);
3904 stop_stepping (ecs
);
3908 /* We aren't done stepping.
3910 Optimize by setting the stepping range to the line.
3911 (We might not be in the original line, but if we entered a
3912 new line in mid-statement, we continue stepping. This makes
3913 things like for(;;) statements work better.) */
3915 ecs
->event_thread
->step_range_start
= stop_pc_sal
.pc
;
3916 ecs
->event_thread
->step_range_end
= stop_pc_sal
.end
;
3917 ecs
->event_thread
->step_frame_id
= get_frame_id (get_current_frame ());
3918 ecs
->event_thread
->current_line
= stop_pc_sal
.line
;
3919 ecs
->event_thread
->current_symtab
= stop_pc_sal
.symtab
;
3922 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
3926 /* Are we in the middle of stepping? */
3929 currently_stepping_thread (struct thread_info
*tp
)
3931 return (tp
->step_range_end
&& tp
->step_resume_breakpoint
== NULL
)
3932 || tp
->trap_expected
3933 || tp
->stepping_through_solib_after_catch
;
3937 currently_stepping_callback (struct thread_info
*tp
, void *data
)
3939 /* Return true if any thread *but* the one passed in "data" is
3940 in the middle of stepping. */
3941 return tp
!= data
&& currently_stepping_thread (tp
);
3945 currently_stepping (struct thread_info
*tp
)
3947 return currently_stepping_thread (tp
) || bpstat_should_step ();
3950 /* Inferior has stepped into a subroutine call with source code that
3951 we should not step over. Do step to the first line of code in
3955 handle_step_into_function (struct execution_control_state
*ecs
)
3958 struct symtab_and_line stop_func_sal
, sr_sal
;
3960 s
= find_pc_symtab (stop_pc
);
3961 if (s
&& s
->language
!= language_asm
)
3962 ecs
->stop_func_start
= gdbarch_skip_prologue (current_gdbarch
,
3963 ecs
->stop_func_start
);
3965 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3966 /* Use the step_resume_break to step until the end of the prologue,
3967 even if that involves jumps (as it seems to on the vax under
3969 /* If the prologue ends in the middle of a source line, continue to
3970 the end of that source line (if it is still within the function).
3971 Otherwise, just go to end of prologue. */
3972 if (stop_func_sal
.end
3973 && stop_func_sal
.pc
!= ecs
->stop_func_start
3974 && stop_func_sal
.end
< ecs
->stop_func_end
)
3975 ecs
->stop_func_start
= stop_func_sal
.end
;
3977 /* Architectures which require breakpoint adjustment might not be able
3978 to place a breakpoint at the computed address. If so, the test
3979 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3980 ecs->stop_func_start to an address at which a breakpoint may be
3981 legitimately placed.
3983 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3984 made, GDB will enter an infinite loop when stepping through
3985 optimized code consisting of VLIW instructions which contain
3986 subinstructions corresponding to different source lines. On
3987 FR-V, it's not permitted to place a breakpoint on any but the
3988 first subinstruction of a VLIW instruction. When a breakpoint is
3989 set, GDB will adjust the breakpoint address to the beginning of
3990 the VLIW instruction. Thus, we need to make the corresponding
3991 adjustment here when computing the stop address. */
3993 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3995 ecs
->stop_func_start
3996 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
3997 ecs
->stop_func_start
);
4000 if (ecs
->stop_func_start
== stop_pc
)
4002 /* We are already there: stop now. */
4003 ecs
->event_thread
->stop_step
= 1;
4004 print_stop_reason (END_STEPPING_RANGE
, 0);
4005 stop_stepping (ecs
);
4010 /* Put the step-breakpoint there and go until there. */
4011 init_sal (&sr_sal
); /* initialize to zeroes */
4012 sr_sal
.pc
= ecs
->stop_func_start
;
4013 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
4015 /* Do not specify what the fp should be when we stop since on
4016 some machines the prologue is where the new fp value is
4018 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
4020 /* And make sure stepping stops right away then. */
4021 ecs
->event_thread
->step_range_end
= ecs
->event_thread
->step_range_start
;
4026 /* Inferior has stepped backward into a subroutine call with source
4027 code that we should not step over. Do step to the beginning of the
4028 last line of code in it. */
4031 handle_step_into_function_backward (struct execution_control_state
*ecs
)
4034 struct symtab_and_line stop_func_sal
, sr_sal
;
4036 s
= find_pc_symtab (stop_pc
);
4037 if (s
&& s
->language
!= language_asm
)
4038 ecs
->stop_func_start
= gdbarch_skip_prologue (current_gdbarch
,
4039 ecs
->stop_func_start
);
4041 stop_func_sal
= find_pc_line (stop_pc
, 0);
4043 /* OK, we're just going to keep stepping here. */
4044 if (stop_func_sal
.pc
== stop_pc
)
4046 /* We're there already. Just stop stepping now. */
4047 ecs
->event_thread
->stop_step
= 1;
4048 print_stop_reason (END_STEPPING_RANGE
, 0);
4049 stop_stepping (ecs
);
4053 /* Else just reset the step range and keep going.
4054 No step-resume breakpoint, they don't work for
4055 epilogues, which can have multiple entry paths. */
4056 ecs
->event_thread
->step_range_start
= stop_func_sal
.pc
;
4057 ecs
->event_thread
->step_range_end
= stop_func_sal
.end
;
4063 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
4064 This is used to both functions and to skip over code. */
4067 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
4068 struct frame_id sr_id
)
4070 /* There should never be more than one step-resume or longjmp-resume
4071 breakpoint per thread, so we should never be setting a new
4072 step_resume_breakpoint when one is already active. */
4073 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
4076 fprintf_unfiltered (gdb_stdlog
,
4077 "infrun: inserting step-resume breakpoint at 0x%s\n",
4078 paddr_nz (sr_sal
.pc
));
4080 inferior_thread ()->step_resume_breakpoint
4081 = set_momentary_breakpoint (sr_sal
, sr_id
, bp_step_resume
);
4084 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
4085 to skip a potential signal handler.
4087 This is called with the interrupted function's frame. The signal
4088 handler, when it returns, will resume the interrupted function at
4092 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
4094 struct symtab_and_line sr_sal
;
4096 gdb_assert (return_frame
!= NULL
);
4097 init_sal (&sr_sal
); /* initialize to zeros */
4099 sr_sal
.pc
= gdbarch_addr_bits_remove
4100 (current_gdbarch
, get_frame_pc (return_frame
));
4101 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4103 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
4106 /* Similar to insert_step_resume_breakpoint_at_frame, except
4107 but a breakpoint at the previous frame's PC. This is used to
4108 skip a function after stepping into it (for "next" or if the called
4109 function has no debugging information).
4111 The current function has almost always been reached by single
4112 stepping a call or return instruction. NEXT_FRAME belongs to the
4113 current function, and the breakpoint will be set at the caller's
4116 This is a separate function rather than reusing
4117 insert_step_resume_breakpoint_at_frame in order to avoid
4118 get_prev_frame, which may stop prematurely (see the implementation
4119 of frame_unwind_id for an example). */
4122 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
4124 struct symtab_and_line sr_sal
;
4126 /* We shouldn't have gotten here if we don't know where the call site
4128 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
4130 init_sal (&sr_sal
); /* initialize to zeros */
4132 sr_sal
.pc
= gdbarch_addr_bits_remove
4133 (current_gdbarch
, frame_pc_unwind (next_frame
));
4134 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4136 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
4139 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
4140 new breakpoint at the target of a jmp_buf. The handling of
4141 longjmp-resume uses the same mechanisms used for handling
4142 "step-resume" breakpoints. */
4145 insert_longjmp_resume_breakpoint (CORE_ADDR pc
)
4147 /* There should never be more than one step-resume or longjmp-resume
4148 breakpoint per thread, so we should never be setting a new
4149 longjmp_resume_breakpoint when one is already active. */
4150 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
4153 fprintf_unfiltered (gdb_stdlog
,
4154 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
4157 inferior_thread ()->step_resume_breakpoint
=
4158 set_momentary_breakpoint_at_pc (pc
, bp_longjmp_resume
);
4162 stop_stepping (struct execution_control_state
*ecs
)
4165 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
4167 /* Let callers know we don't want to wait for the inferior anymore. */
4168 ecs
->wait_some_more
= 0;
4171 /* This function handles various cases where we need to continue
4172 waiting for the inferior. */
4173 /* (Used to be the keep_going: label in the old wait_for_inferior) */
4176 keep_going (struct execution_control_state
*ecs
)
4178 /* Save the pc before execution, to compare with pc after stop. */
4179 ecs
->event_thread
->prev_pc
4180 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4182 /* If we did not do break;, it means we should keep running the
4183 inferior and not return to debugger. */
4185 if (ecs
->event_thread
->trap_expected
4186 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
4188 /* We took a signal (which we are supposed to pass through to
4189 the inferior, else we'd not get here) and we haven't yet
4190 gotten our trap. Simply continue. */
4191 resume (currently_stepping (ecs
->event_thread
),
4192 ecs
->event_thread
->stop_signal
);
4196 /* Either the trap was not expected, but we are continuing
4197 anyway (the user asked that this signal be passed to the
4200 The signal was SIGTRAP, e.g. it was our signal, but we
4201 decided we should resume from it.
4203 We're going to run this baby now!
4205 Note that insert_breakpoints won't try to re-insert
4206 already inserted breakpoints. Therefore, we don't
4207 care if breakpoints were already inserted, or not. */
4209 if (ecs
->event_thread
->stepping_over_breakpoint
)
4211 if (! use_displaced_stepping (current_gdbarch
))
4212 /* Since we can't do a displaced step, we have to remove
4213 the breakpoint while we step it. To keep things
4214 simple, we remove them all. */
4215 remove_breakpoints ();
4219 struct gdb_exception e
;
4220 /* Stop stepping when inserting breakpoints
4222 TRY_CATCH (e
, RETURN_MASK_ERROR
)
4224 insert_breakpoints ();
4228 stop_stepping (ecs
);
4233 ecs
->event_thread
->trap_expected
= ecs
->event_thread
->stepping_over_breakpoint
;
4235 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
4236 specifies that such a signal should be delivered to the
4239 Typically, this would occure when a user is debugging a
4240 target monitor on a simulator: the target monitor sets a
4241 breakpoint; the simulator encounters this break-point and
4242 halts the simulation handing control to GDB; GDB, noteing
4243 that the break-point isn't valid, returns control back to the
4244 simulator; the simulator then delivers the hardware
4245 equivalent of a SIGNAL_TRAP to the program being debugged. */
4247 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
4248 && !signal_program
[ecs
->event_thread
->stop_signal
])
4249 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
4251 resume (currently_stepping (ecs
->event_thread
),
4252 ecs
->event_thread
->stop_signal
);
4255 prepare_to_wait (ecs
);
4258 /* This function normally comes after a resume, before
4259 handle_inferior_event exits. It takes care of any last bits of
4260 housekeeping, and sets the all-important wait_some_more flag. */
4263 prepare_to_wait (struct execution_control_state
*ecs
)
4266 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
4267 if (infwait_state
== infwait_normal_state
)
4269 overlay_cache_invalid
= 1;
4271 /* We have to invalidate the registers BEFORE calling
4272 target_wait because they can be loaded from the target while
4273 in target_wait. This makes remote debugging a bit more
4274 efficient for those targets that provide critical registers
4275 as part of their normal status mechanism. */
4277 registers_changed ();
4278 waiton_ptid
= pid_to_ptid (-1);
4280 /* This is the old end of the while loop. Let everybody know we
4281 want to wait for the inferior some more and get called again
4283 ecs
->wait_some_more
= 1;
4286 /* Print why the inferior has stopped. We always print something when
4287 the inferior exits, or receives a signal. The rest of the cases are
4288 dealt with later on in normal_stop() and print_it_typical(). Ideally
4289 there should be a call to this function from handle_inferior_event()
4290 each time stop_stepping() is called.*/
4292 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
4294 switch (stop_reason
)
4296 case END_STEPPING_RANGE
:
4297 /* We are done with a step/next/si/ni command. */
4298 /* For now print nothing. */
4299 /* Print a message only if not in the middle of doing a "step n"
4300 operation for n > 1 */
4301 if (!inferior_thread ()->step_multi
4302 || !inferior_thread ()->stop_step
)
4303 if (ui_out_is_mi_like_p (uiout
))
4306 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
4309 /* The inferior was terminated by a signal. */
4310 annotate_signalled ();
4311 if (ui_out_is_mi_like_p (uiout
))
4314 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
4315 ui_out_text (uiout
, "\nProgram terminated with signal ");
4316 annotate_signal_name ();
4317 ui_out_field_string (uiout
, "signal-name",
4318 target_signal_to_name (stop_info
));
4319 annotate_signal_name_end ();
4320 ui_out_text (uiout
, ", ");
4321 annotate_signal_string ();
4322 ui_out_field_string (uiout
, "signal-meaning",
4323 target_signal_to_string (stop_info
));
4324 annotate_signal_string_end ();
4325 ui_out_text (uiout
, ".\n");
4326 ui_out_text (uiout
, "The program no longer exists.\n");
4329 /* The inferior program is finished. */
4330 annotate_exited (stop_info
);
4333 if (ui_out_is_mi_like_p (uiout
))
4334 ui_out_field_string (uiout
, "reason",
4335 async_reason_lookup (EXEC_ASYNC_EXITED
));
4336 ui_out_text (uiout
, "\nProgram exited with code ");
4337 ui_out_field_fmt (uiout
, "exit-code", "0%o",
4338 (unsigned int) stop_info
);
4339 ui_out_text (uiout
, ".\n");
4343 if (ui_out_is_mi_like_p (uiout
))
4346 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
4347 ui_out_text (uiout
, "\nProgram exited normally.\n");
4349 /* Support the --return-child-result option. */
4350 return_child_result_value
= stop_info
;
4352 case SIGNAL_RECEIVED
:
4353 /* Signal received. The signal table tells us to print about
4357 if (stop_info
== TARGET_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
4359 struct thread_info
*t
= inferior_thread ();
4361 ui_out_text (uiout
, "\n[");
4362 ui_out_field_string (uiout
, "thread-name",
4363 target_pid_to_str (t
->ptid
));
4364 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
4365 ui_out_text (uiout
, " stopped");
4369 ui_out_text (uiout
, "\nProgram received signal ");
4370 annotate_signal_name ();
4371 if (ui_out_is_mi_like_p (uiout
))
4373 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
4374 ui_out_field_string (uiout
, "signal-name",
4375 target_signal_to_name (stop_info
));
4376 annotate_signal_name_end ();
4377 ui_out_text (uiout
, ", ");
4378 annotate_signal_string ();
4379 ui_out_field_string (uiout
, "signal-meaning",
4380 target_signal_to_string (stop_info
));
4381 annotate_signal_string_end ();
4383 ui_out_text (uiout
, ".\n");
4386 /* Reverse execution: target ran out of history info. */
4387 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
4390 internal_error (__FILE__
, __LINE__
,
4391 _("print_stop_reason: unrecognized enum value"));
4397 /* Here to return control to GDB when the inferior stops for real.
4398 Print appropriate messages, remove breakpoints, give terminal our modes.
4400 STOP_PRINT_FRAME nonzero means print the executing frame
4401 (pc, function, args, file, line number and line text).
4402 BREAKPOINTS_FAILED nonzero means stop was due to error
4403 attempting to insert breakpoints. */
4408 struct target_waitstatus last
;
4410 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
4412 get_last_target_status (&last_ptid
, &last
);
4414 /* If an exception is thrown from this point on, make sure to
4415 propagate GDB's knowledge of the executing state to the
4416 frontend/user running state. A QUIT is an easy exception to see
4417 here, so do this before any filtered output. */
4418 if (target_has_execution
)
4421 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
4422 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
4423 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4424 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
4427 /* In non-stop mode, we don't want GDB to switch threads behind the
4428 user's back, to avoid races where the user is typing a command to
4429 apply to thread x, but GDB switches to thread y before the user
4430 finishes entering the command. */
4432 /* As with the notification of thread events, we want to delay
4433 notifying the user that we've switched thread context until
4434 the inferior actually stops.
4436 There's no point in saying anything if the inferior has exited.
4437 Note that SIGNALLED here means "exited with a signal", not
4438 "received a signal". */
4440 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
4441 && target_has_execution
4442 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
4443 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4445 target_terminal_ours_for_output ();
4446 printf_filtered (_("[Switching to %s]\n"),
4447 target_pid_to_str (inferior_ptid
));
4448 annotate_thread_changed ();
4449 previous_inferior_ptid
= inferior_ptid
;
4452 if (!breakpoints_always_inserted_mode () && target_has_execution
)
4454 if (remove_breakpoints ())
4456 target_terminal_ours_for_output ();
4457 printf_filtered (_("\
4458 Cannot remove breakpoints because program is no longer writable.\n\
4459 Further execution is probably impossible.\n"));
4463 /* If an auto-display called a function and that got a signal,
4464 delete that auto-display to avoid an infinite recursion. */
4466 if (stopped_by_random_signal
)
4467 disable_current_display ();
4469 /* Don't print a message if in the middle of doing a "step n"
4470 operation for n > 1 */
4471 if (target_has_execution
4472 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
4473 && last
.kind
!= TARGET_WAITKIND_EXITED
4474 && inferior_thread ()->step_multi
4475 && inferior_thread ()->stop_step
)
4478 target_terminal_ours ();
4480 /* Set the current source location. This will also happen if we
4481 display the frame below, but the current SAL will be incorrect
4482 during a user hook-stop function. */
4483 if (has_stack_frames () && !stop_stack_dummy
)
4484 set_current_sal_from_frame (get_current_frame (), 1);
4486 /* Let the user/frontend see the threads as stopped. */
4487 do_cleanups (old_chain
);
4489 /* Look up the hook_stop and run it (CLI internally handles problem
4490 of stop_command's pre-hook not existing). */
4492 catch_errors (hook_stop_stub
, stop_command
,
4493 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
4495 if (!has_stack_frames ())
4498 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
4499 || last
.kind
== TARGET_WAITKIND_EXITED
)
4502 /* Select innermost stack frame - i.e., current frame is frame 0,
4503 and current location is based on that.
4504 Don't do this on return from a stack dummy routine,
4505 or if the program has exited. */
4507 if (!stop_stack_dummy
)
4509 select_frame (get_current_frame ());
4511 /* Print current location without a level number, if
4512 we have changed functions or hit a breakpoint.
4513 Print source line if we have one.
4514 bpstat_print() contains the logic deciding in detail
4515 what to print, based on the event(s) that just occurred. */
4517 /* If --batch-silent is enabled then there's no need to print the current
4518 source location, and to try risks causing an error message about
4519 missing source files. */
4520 if (stop_print_frame
&& !batch_silent
)
4524 int do_frame_printing
= 1;
4525 struct thread_info
*tp
= inferior_thread ();
4527 bpstat_ret
= bpstat_print (tp
->stop_bpstat
);
4531 /* If we had hit a shared library event breakpoint,
4532 bpstat_print would print out this message. If we hit
4533 an OS-level shared library event, do the same
4535 if (last
.kind
== TARGET_WAITKIND_LOADED
)
4537 printf_filtered (_("Stopped due to shared library event\n"));
4538 source_flag
= SRC_LINE
; /* something bogus */
4539 do_frame_printing
= 0;
4543 /* FIXME: cagney/2002-12-01: Given that a frame ID does
4544 (or should) carry around the function and does (or
4545 should) use that when doing a frame comparison. */
4547 && frame_id_eq (tp
->step_frame_id
,
4548 get_frame_id (get_current_frame ()))
4549 && step_start_function
== find_pc_function (stop_pc
))
4550 source_flag
= SRC_LINE
; /* finished step, just print source line */
4552 source_flag
= SRC_AND_LOC
; /* print location and source line */
4554 case PRINT_SRC_AND_LOC
:
4555 source_flag
= SRC_AND_LOC
; /* print location and source line */
4557 case PRINT_SRC_ONLY
:
4558 source_flag
= SRC_LINE
;
4561 source_flag
= SRC_LINE
; /* something bogus */
4562 do_frame_printing
= 0;
4565 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
4568 /* The behavior of this routine with respect to the source
4570 SRC_LINE: Print only source line
4571 LOCATION: Print only location
4572 SRC_AND_LOC: Print location and source line */
4573 if (do_frame_printing
)
4574 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
4576 /* Display the auto-display expressions. */
4581 /* Save the function value return registers, if we care.
4582 We might be about to restore their previous contents. */
4583 if (inferior_thread ()->proceed_to_finish
)
4585 /* This should not be necessary. */
4587 regcache_xfree (stop_registers
);
4589 /* NB: The copy goes through to the target picking up the value of
4590 all the registers. */
4591 stop_registers
= regcache_dup (get_current_regcache ());
4594 if (stop_stack_dummy
)
4596 /* Pop the empty frame that contains the stack dummy.
4597 This also restores inferior state prior to the call
4598 (struct inferior_thread_state). */
4599 struct frame_info
*frame
= get_current_frame ();
4600 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
4602 /* frame_pop() calls reinit_frame_cache as the last thing it does
4603 which means there's currently no selected frame. We don't need
4604 to re-establish a selected frame if the dummy call returns normally,
4605 that will be done by restore_inferior_status. However, we do have
4606 to handle the case where the dummy call is returning after being
4607 stopped (e.g. the dummy call previously hit a breakpoint). We
4608 can't know which case we have so just always re-establish a
4609 selected frame here. */
4610 select_frame (get_current_frame ());
4614 annotate_stopped ();
4616 /* Suppress the stop observer if we're in the middle of:
4618 - a step n (n > 1), as there still more steps to be done.
4620 - a "finish" command, as the observer will be called in
4621 finish_command_continuation, so it can include the inferior
4622 function's return value.
4624 - calling an inferior function, as we pretend we inferior didn't
4625 run at all. The return value of the call is handled by the
4626 expression evaluator, through call_function_by_hand. */
4628 if (!target_has_execution
4629 || last
.kind
== TARGET_WAITKIND_SIGNALLED
4630 || last
.kind
== TARGET_WAITKIND_EXITED
4631 || (!inferior_thread ()->step_multi
4632 && !(inferior_thread ()->stop_bpstat
4633 && inferior_thread ()->proceed_to_finish
)
4634 && !inferior_thread ()->in_infcall
))
4636 if (!ptid_equal (inferior_ptid
, null_ptid
))
4637 observer_notify_normal_stop (inferior_thread ()->stop_bpstat
,
4640 observer_notify_normal_stop (NULL
, stop_print_frame
);
4643 if (target_has_execution
)
4645 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
4646 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4647 /* Delete the breakpoint we stopped at, if it wants to be deleted.
4648 Delete any breakpoint that is to be deleted at the next stop. */
4649 breakpoint_auto_delete (inferior_thread ()->stop_bpstat
);
4654 hook_stop_stub (void *cmd
)
4656 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
4661 signal_stop_state (int signo
)
4663 return signal_stop
[signo
];
4667 signal_print_state (int signo
)
4669 return signal_print
[signo
];
4673 signal_pass_state (int signo
)
4675 return signal_program
[signo
];
4679 signal_stop_update (int signo
, int state
)
4681 int ret
= signal_stop
[signo
];
4682 signal_stop
[signo
] = state
;
4687 signal_print_update (int signo
, int state
)
4689 int ret
= signal_print
[signo
];
4690 signal_print
[signo
] = state
;
4695 signal_pass_update (int signo
, int state
)
4697 int ret
= signal_program
[signo
];
4698 signal_program
[signo
] = state
;
4703 sig_print_header (void)
4705 printf_filtered (_("\
4706 Signal Stop\tPrint\tPass to program\tDescription\n"));
4710 sig_print_info (enum target_signal oursig
)
4712 const char *name
= target_signal_to_name (oursig
);
4713 int name_padding
= 13 - strlen (name
);
4715 if (name_padding
<= 0)
4718 printf_filtered ("%s", name
);
4719 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
4720 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
4721 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
4722 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
4723 printf_filtered ("%s\n", target_signal_to_string (oursig
));
4726 /* Specify how various signals in the inferior should be handled. */
4729 handle_command (char *args
, int from_tty
)
4732 int digits
, wordlen
;
4733 int sigfirst
, signum
, siglast
;
4734 enum target_signal oursig
;
4737 unsigned char *sigs
;
4738 struct cleanup
*old_chain
;
4742 error_no_arg (_("signal to handle"));
4745 /* Allocate and zero an array of flags for which signals to handle. */
4747 nsigs
= (int) TARGET_SIGNAL_LAST
;
4748 sigs
= (unsigned char *) alloca (nsigs
);
4749 memset (sigs
, 0, nsigs
);
4751 /* Break the command line up into args. */
4753 argv
= gdb_buildargv (args
);
4754 old_chain
= make_cleanup_freeargv (argv
);
4756 /* Walk through the args, looking for signal oursigs, signal names, and
4757 actions. Signal numbers and signal names may be interspersed with
4758 actions, with the actions being performed for all signals cumulatively
4759 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4761 while (*argv
!= NULL
)
4763 wordlen
= strlen (*argv
);
4764 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
4768 sigfirst
= siglast
= -1;
4770 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
4772 /* Apply action to all signals except those used by the
4773 debugger. Silently skip those. */
4776 siglast
= nsigs
- 1;
4778 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
4780 SET_SIGS (nsigs
, sigs
, signal_stop
);
4781 SET_SIGS (nsigs
, sigs
, signal_print
);
4783 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
4785 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4787 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
4789 SET_SIGS (nsigs
, sigs
, signal_print
);
4791 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
4793 SET_SIGS (nsigs
, sigs
, signal_program
);
4795 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
4797 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4799 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
4801 SET_SIGS (nsigs
, sigs
, signal_program
);
4803 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
4805 UNSET_SIGS (nsigs
, sigs
, signal_print
);
4806 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4808 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
4810 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4812 else if (digits
> 0)
4814 /* It is numeric. The numeric signal refers to our own
4815 internal signal numbering from target.h, not to host/target
4816 signal number. This is a feature; users really should be
4817 using symbolic names anyway, and the common ones like
4818 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
4820 sigfirst
= siglast
= (int)
4821 target_signal_from_command (atoi (*argv
));
4822 if ((*argv
)[digits
] == '-')
4825 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
4827 if (sigfirst
> siglast
)
4829 /* Bet he didn't figure we'd think of this case... */
4837 oursig
= target_signal_from_name (*argv
);
4838 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
4840 sigfirst
= siglast
= (int) oursig
;
4844 /* Not a number and not a recognized flag word => complain. */
4845 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
4849 /* If any signal numbers or symbol names were found, set flags for
4850 which signals to apply actions to. */
4852 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
4854 switch ((enum target_signal
) signum
)
4856 case TARGET_SIGNAL_TRAP
:
4857 case TARGET_SIGNAL_INT
:
4858 if (!allsigs
&& !sigs
[signum
])
4860 if (query (_("%s is used by the debugger.\n\
4861 Are you sure you want to change it? "), target_signal_to_name ((enum target_signal
) signum
)))
4867 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4868 gdb_flush (gdb_stdout
);
4872 case TARGET_SIGNAL_0
:
4873 case TARGET_SIGNAL_DEFAULT
:
4874 case TARGET_SIGNAL_UNKNOWN
:
4875 /* Make sure that "all" doesn't print these. */
4886 for (signum
= 0; signum
< nsigs
; signum
++)
4889 target_notice_signals (inferior_ptid
);
4893 /* Show the results. */
4894 sig_print_header ();
4895 for (; signum
< nsigs
; signum
++)
4897 sig_print_info (signum
);
4903 do_cleanups (old_chain
);
4907 xdb_handle_command (char *args
, int from_tty
)
4910 struct cleanup
*old_chain
;
4913 error_no_arg (_("xdb command"));
4915 /* Break the command line up into args. */
4917 argv
= gdb_buildargv (args
);
4918 old_chain
= make_cleanup_freeargv (argv
);
4919 if (argv
[1] != (char *) NULL
)
4924 bufLen
= strlen (argv
[0]) + 20;
4925 argBuf
= (char *) xmalloc (bufLen
);
4929 enum target_signal oursig
;
4931 oursig
= target_signal_from_name (argv
[0]);
4932 memset (argBuf
, 0, bufLen
);
4933 if (strcmp (argv
[1], "Q") == 0)
4934 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4937 if (strcmp (argv
[1], "s") == 0)
4939 if (!signal_stop
[oursig
])
4940 sprintf (argBuf
, "%s %s", argv
[0], "stop");
4942 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
4944 else if (strcmp (argv
[1], "i") == 0)
4946 if (!signal_program
[oursig
])
4947 sprintf (argBuf
, "%s %s", argv
[0], "pass");
4949 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
4951 else if (strcmp (argv
[1], "r") == 0)
4953 if (!signal_print
[oursig
])
4954 sprintf (argBuf
, "%s %s", argv
[0], "print");
4956 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4962 handle_command (argBuf
, from_tty
);
4964 printf_filtered (_("Invalid signal handling flag.\n"));
4969 do_cleanups (old_chain
);
4972 /* Print current contents of the tables set by the handle command.
4973 It is possible we should just be printing signals actually used
4974 by the current target (but for things to work right when switching
4975 targets, all signals should be in the signal tables). */
4978 signals_info (char *signum_exp
, int from_tty
)
4980 enum target_signal oursig
;
4981 sig_print_header ();
4985 /* First see if this is a symbol name. */
4986 oursig
= target_signal_from_name (signum_exp
);
4987 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
4989 /* No, try numeric. */
4991 target_signal_from_command (parse_and_eval_long (signum_exp
));
4993 sig_print_info (oursig
);
4997 printf_filtered ("\n");
4998 /* These ugly casts brought to you by the native VAX compiler. */
4999 for (oursig
= TARGET_SIGNAL_FIRST
;
5000 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
5001 oursig
= (enum target_signal
) ((int) oursig
+ 1))
5005 if (oursig
!= TARGET_SIGNAL_UNKNOWN
5006 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
5007 sig_print_info (oursig
);
5010 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
5013 /* The $_siginfo convenience variable is a bit special. We don't know
5014 for sure the type of the value until we actually have a chance to
5015 fetch the data. The type can change depending on gdbarch, so it it
5016 also dependent on which thread you have selected.
5018 1. making $_siginfo be an internalvar that creates a new value on
5021 2. making the value of $_siginfo be an lval_computed value. */
5023 /* This function implements the lval_computed support for reading a
5027 siginfo_value_read (struct value
*v
)
5029 LONGEST transferred
;
5032 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
5034 value_contents_all_raw (v
),
5036 TYPE_LENGTH (value_type (v
)));
5038 if (transferred
!= TYPE_LENGTH (value_type (v
)))
5039 error (_("Unable to read siginfo"));
5042 /* This function implements the lval_computed support for writing a
5046 siginfo_value_write (struct value
*v
, struct value
*fromval
)
5048 LONGEST transferred
;
5050 transferred
= target_write (¤t_target
,
5051 TARGET_OBJECT_SIGNAL_INFO
,
5053 value_contents_all_raw (fromval
),
5055 TYPE_LENGTH (value_type (fromval
)));
5057 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
5058 error (_("Unable to write siginfo"));
5061 static struct lval_funcs siginfo_value_funcs
=
5067 /* Return a new value with the correct type for the siginfo object of
5068 the current thread. Return a void value if there's no object
5071 static struct value
*
5072 siginfo_make_value (struct internalvar
*var
)
5075 struct gdbarch
*gdbarch
;
5077 if (target_has_stack
5078 && !ptid_equal (inferior_ptid
, null_ptid
))
5080 gdbarch
= get_frame_arch (get_current_frame ());
5082 if (gdbarch_get_siginfo_type_p (gdbarch
))
5084 type
= gdbarch_get_siginfo_type (gdbarch
);
5086 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
5090 return allocate_value (builtin_type_void
);
5094 /* Inferior thread state.
5095 These are details related to the inferior itself, and don't include
5096 things like what frame the user had selected or what gdb was doing
5097 with the target at the time.
5098 For inferior function calls these are things we want to restore
5099 regardless of whether the function call successfully completes
5100 or the dummy frame has to be manually popped. */
5102 struct inferior_thread_state
5104 enum target_signal stop_signal
;
5106 struct regcache
*registers
;
5109 struct inferior_thread_state
*
5110 save_inferior_thread_state (void)
5112 struct inferior_thread_state
*inf_state
= XMALLOC (struct inferior_thread_state
);
5113 struct thread_info
*tp
= inferior_thread ();
5115 inf_state
->stop_signal
= tp
->stop_signal
;
5116 inf_state
->stop_pc
= stop_pc
;
5118 inf_state
->registers
= regcache_dup (get_current_regcache ());
5123 /* Restore inferior session state to INF_STATE. */
5126 restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5128 struct thread_info
*tp
= inferior_thread ();
5130 tp
->stop_signal
= inf_state
->stop_signal
;
5131 stop_pc
= inf_state
->stop_pc
;
5133 /* The inferior can be gone if the user types "print exit(0)"
5134 (and perhaps other times). */
5135 if (target_has_execution
)
5136 /* NB: The register write goes through to the target. */
5137 regcache_cpy (get_current_regcache (), inf_state
->registers
);
5138 regcache_xfree (inf_state
->registers
);
5143 do_restore_inferior_thread_state_cleanup (void *state
)
5145 restore_inferior_thread_state (state
);
5149 make_cleanup_restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5151 return make_cleanup (do_restore_inferior_thread_state_cleanup
, inf_state
);
5155 discard_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5157 regcache_xfree (inf_state
->registers
);
5162 get_inferior_thread_state_regcache (struct inferior_thread_state
*inf_state
)
5164 return inf_state
->registers
;
5167 /* Session related state for inferior function calls.
5168 These are the additional bits of state that need to be restored
5169 when an inferior function call successfully completes. */
5171 struct inferior_status
5175 int stop_stack_dummy
;
5176 int stopped_by_random_signal
;
5177 int stepping_over_breakpoint
;
5178 CORE_ADDR step_range_start
;
5179 CORE_ADDR step_range_end
;
5180 struct frame_id step_frame_id
;
5181 enum step_over_calls_kind step_over_calls
;
5182 CORE_ADDR step_resume_break_address
;
5183 int stop_after_trap
;
5186 /* ID if the selected frame when the inferior function call was made. */
5187 struct frame_id selected_frame_id
;
5189 int proceed_to_finish
;
5193 /* Save all of the information associated with the inferior<==>gdb
5196 struct inferior_status
*
5197 save_inferior_status (void)
5199 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
5200 struct thread_info
*tp
= inferior_thread ();
5201 struct inferior
*inf
= current_inferior ();
5203 inf_status
->stop_step
= tp
->stop_step
;
5204 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
5205 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
5206 inf_status
->stepping_over_breakpoint
= tp
->trap_expected
;
5207 inf_status
->step_range_start
= tp
->step_range_start
;
5208 inf_status
->step_range_end
= tp
->step_range_end
;
5209 inf_status
->step_frame_id
= tp
->step_frame_id
;
5210 inf_status
->step_over_calls
= tp
->step_over_calls
;
5211 inf_status
->stop_after_trap
= stop_after_trap
;
5212 inf_status
->stop_soon
= inf
->stop_soon
;
5213 /* Save original bpstat chain here; replace it with copy of chain.
5214 If caller's caller is walking the chain, they'll be happier if we
5215 hand them back the original chain when restore_inferior_status is
5217 inf_status
->stop_bpstat
= tp
->stop_bpstat
;
5218 tp
->stop_bpstat
= bpstat_copy (tp
->stop_bpstat
);
5219 inf_status
->proceed_to_finish
= tp
->proceed_to_finish
;
5220 inf_status
->in_infcall
= tp
->in_infcall
;
5222 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
5228 restore_selected_frame (void *args
)
5230 struct frame_id
*fid
= (struct frame_id
*) args
;
5231 struct frame_info
*frame
;
5233 frame
= frame_find_by_id (*fid
);
5235 /* If inf_status->selected_frame_id is NULL, there was no previously
5239 warning (_("Unable to restore previously selected frame."));
5243 select_frame (frame
);
5248 /* Restore inferior session state to INF_STATUS. */
5251 restore_inferior_status (struct inferior_status
*inf_status
)
5253 struct thread_info
*tp
= inferior_thread ();
5254 struct inferior
*inf
= current_inferior ();
5256 tp
->stop_step
= inf_status
->stop_step
;
5257 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
5258 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
5259 tp
->trap_expected
= inf_status
->stepping_over_breakpoint
;
5260 tp
->step_range_start
= inf_status
->step_range_start
;
5261 tp
->step_range_end
= inf_status
->step_range_end
;
5262 tp
->step_frame_id
= inf_status
->step_frame_id
;
5263 tp
->step_over_calls
= inf_status
->step_over_calls
;
5264 stop_after_trap
= inf_status
->stop_after_trap
;
5265 inf
->stop_soon
= inf_status
->stop_soon
;
5266 bpstat_clear (&tp
->stop_bpstat
);
5267 tp
->stop_bpstat
= inf_status
->stop_bpstat
;
5268 inf_status
->stop_bpstat
= NULL
;
5269 tp
->proceed_to_finish
= inf_status
->proceed_to_finish
;
5270 tp
->in_infcall
= inf_status
->in_infcall
;
5272 if (target_has_stack
)
5274 /* The point of catch_errors is that if the stack is clobbered,
5275 walking the stack might encounter a garbage pointer and
5276 error() trying to dereference it. */
5278 (restore_selected_frame
, &inf_status
->selected_frame_id
,
5279 "Unable to restore previously selected frame:\n",
5280 RETURN_MASK_ERROR
) == 0)
5281 /* Error in restoring the selected frame. Select the innermost
5283 select_frame (get_current_frame ());
5290 do_restore_inferior_status_cleanup (void *sts
)
5292 restore_inferior_status (sts
);
5296 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
5298 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
5302 discard_inferior_status (struct inferior_status
*inf_status
)
5304 /* See save_inferior_status for info on stop_bpstat. */
5305 bpstat_clear (&inf_status
->stop_bpstat
);
5310 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
5312 struct target_waitstatus last
;
5315 get_last_target_status (&last_ptid
, &last
);
5317 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
5320 if (!ptid_equal (last_ptid
, pid
))
5323 *child_pid
= last
.value
.related_pid
;
5328 inferior_has_vforked (ptid_t pid
, ptid_t
*child_pid
)
5330 struct target_waitstatus last
;
5333 get_last_target_status (&last_ptid
, &last
);
5335 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
5338 if (!ptid_equal (last_ptid
, pid
))
5341 *child_pid
= last
.value
.related_pid
;
5346 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
5348 struct target_waitstatus last
;
5351 get_last_target_status (&last_ptid
, &last
);
5353 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
5356 if (!ptid_equal (last_ptid
, pid
))
5359 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
5363 /* Oft used ptids */
5365 ptid_t minus_one_ptid
;
5367 /* Create a ptid given the necessary PID, LWP, and TID components. */
5370 ptid_build (int pid
, long lwp
, long tid
)
5380 /* Create a ptid from just a pid. */
5383 pid_to_ptid (int pid
)
5385 return ptid_build (pid
, 0, 0);
5388 /* Fetch the pid (process id) component from a ptid. */
5391 ptid_get_pid (ptid_t ptid
)
5396 /* Fetch the lwp (lightweight process) component from a ptid. */
5399 ptid_get_lwp (ptid_t ptid
)
5404 /* Fetch the tid (thread id) component from a ptid. */
5407 ptid_get_tid (ptid_t ptid
)
5412 /* ptid_equal() is used to test equality of two ptids. */
5415 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
5417 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
5418 && ptid1
.tid
== ptid2
.tid
);
5421 /* Returns true if PTID represents a process. */
5424 ptid_is_pid (ptid_t ptid
)
5426 if (ptid_equal (minus_one_ptid
, ptid
))
5428 if (ptid_equal (null_ptid
, ptid
))
5431 return (ptid_get_lwp (ptid
) == 0 && ptid_get_tid (ptid
) == 0);
5434 /* restore_inferior_ptid() will be used by the cleanup machinery
5435 to restore the inferior_ptid value saved in a call to
5436 save_inferior_ptid(). */
5439 restore_inferior_ptid (void *arg
)
5441 ptid_t
*saved_ptid_ptr
= arg
;
5442 inferior_ptid
= *saved_ptid_ptr
;
5446 /* Save the value of inferior_ptid so that it may be restored by a
5447 later call to do_cleanups(). Returns the struct cleanup pointer
5448 needed for later doing the cleanup. */
5451 save_inferior_ptid (void)
5453 ptid_t
*saved_ptid_ptr
;
5455 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
5456 *saved_ptid_ptr
= inferior_ptid
;
5457 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
5461 /* User interface for reverse debugging:
5462 Set exec-direction / show exec-direction commands
5463 (returns error unless target implements to_set_exec_direction method). */
5465 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
5466 static const char exec_forward
[] = "forward";
5467 static const char exec_reverse
[] = "reverse";
5468 static const char *exec_direction
= exec_forward
;
5469 static const char *exec_direction_names
[] = {
5476 set_exec_direction_func (char *args
, int from_tty
,
5477 struct cmd_list_element
*cmd
)
5479 if (target_can_execute_reverse
)
5481 if (!strcmp (exec_direction
, exec_forward
))
5482 execution_direction
= EXEC_FORWARD
;
5483 else if (!strcmp (exec_direction
, exec_reverse
))
5484 execution_direction
= EXEC_REVERSE
;
5489 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
5490 struct cmd_list_element
*cmd
, const char *value
)
5492 switch (execution_direction
) {
5494 fprintf_filtered (out
, _("Forward.\n"));
5497 fprintf_filtered (out
, _("Reverse.\n"));
5501 fprintf_filtered (out
,
5502 _("Forward (target `%s' does not support exec-direction).\n"),
5508 /* User interface for non-stop mode. */
5511 static int non_stop_1
= 0;
5514 set_non_stop (char *args
, int from_tty
,
5515 struct cmd_list_element
*c
)
5517 if (target_has_execution
)
5519 non_stop_1
= non_stop
;
5520 error (_("Cannot change this setting while the inferior is running."));
5523 non_stop
= non_stop_1
;
5527 show_non_stop (struct ui_file
*file
, int from_tty
,
5528 struct cmd_list_element
*c
, const char *value
)
5530 fprintf_filtered (file
,
5531 _("Controlling the inferior in non-stop mode is %s.\n"),
5537 _initialize_infrun (void)
5541 struct cmd_list_element
*c
;
5543 add_info ("signals", signals_info
, _("\
5544 What debugger does when program gets various signals.\n\
5545 Specify a signal as argument to print info on that signal only."));
5546 add_info_alias ("handle", "signals", 0);
5548 add_com ("handle", class_run
, handle_command
, _("\
5549 Specify how to handle a signal.\n\
5550 Args are signals and actions to apply to those signals.\n\
5551 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
5552 from 1-15 are allowed for compatibility with old versions of GDB.\n\
5553 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
5554 The special arg \"all\" is recognized to mean all signals except those\n\
5555 used by the debugger, typically SIGTRAP and SIGINT.\n\
5556 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
5557 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
5558 Stop means reenter debugger if this signal happens (implies print).\n\
5559 Print means print a message if this signal happens.\n\
5560 Pass means let program see this signal; otherwise program doesn't know.\n\
5561 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
5562 Pass and Stop may be combined."));
5565 add_com ("lz", class_info
, signals_info
, _("\
5566 What debugger does when program gets various signals.\n\
5567 Specify a signal as argument to print info on that signal only."));
5568 add_com ("z", class_run
, xdb_handle_command
, _("\
5569 Specify how to handle a signal.\n\
5570 Args are signals and actions to apply to those signals.\n\
5571 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
5572 from 1-15 are allowed for compatibility with old versions of GDB.\n\
5573 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
5574 The special arg \"all\" is recognized to mean all signals except those\n\
5575 used by the debugger, typically SIGTRAP and SIGINT.\n\
5576 Recognized actions include \"s\" (toggles between stop and nostop), \n\
5577 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
5578 nopass), \"Q\" (noprint)\n\
5579 Stop means reenter debugger if this signal happens (implies print).\n\
5580 Print means print a message if this signal happens.\n\
5581 Pass means let program see this signal; otherwise program doesn't know.\n\
5582 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
5583 Pass and Stop may be combined."));
5587 stop_command
= add_cmd ("stop", class_obscure
,
5588 not_just_help_class_command
, _("\
5589 There is no `stop' command, but you can set a hook on `stop'.\n\
5590 This allows you to set a list of commands to be run each time execution\n\
5591 of the program stops."), &cmdlist
);
5593 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
5594 Set inferior debugging."), _("\
5595 Show inferior debugging."), _("\
5596 When non-zero, inferior specific debugging is enabled."),
5599 &setdebuglist
, &showdebuglist
);
5601 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
5602 Set displaced stepping debugging."), _("\
5603 Show displaced stepping debugging."), _("\
5604 When non-zero, displaced stepping specific debugging is enabled."),
5606 show_debug_displaced
,
5607 &setdebuglist
, &showdebuglist
);
5609 add_setshow_boolean_cmd ("non-stop", no_class
,
5611 Set whether gdb controls the inferior in non-stop mode."), _("\
5612 Show whether gdb controls the inferior in non-stop mode."), _("\
5613 When debugging a multi-threaded program and this setting is\n\
5614 off (the default, also called all-stop mode), when one thread stops\n\
5615 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
5616 all other threads in the program while you interact with the thread of\n\
5617 interest. When you continue or step a thread, you can allow the other\n\
5618 threads to run, or have them remain stopped, but while you inspect any\n\
5619 thread's state, all threads stop.\n\
5621 In non-stop mode, when one thread stops, other threads can continue\n\
5622 to run freely. You'll be able to step each thread independently,\n\
5623 leave it stopped or free to run as needed."),
5629 numsigs
= (int) TARGET_SIGNAL_LAST
;
5630 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
5631 signal_print
= (unsigned char *)
5632 xmalloc (sizeof (signal_print
[0]) * numsigs
);
5633 signal_program
= (unsigned char *)
5634 xmalloc (sizeof (signal_program
[0]) * numsigs
);
5635 for (i
= 0; i
< numsigs
; i
++)
5638 signal_print
[i
] = 1;
5639 signal_program
[i
] = 1;
5642 /* Signals caused by debugger's own actions
5643 should not be given to the program afterwards. */
5644 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
5645 signal_program
[TARGET_SIGNAL_INT
] = 0;
5647 /* Signals that are not errors should not normally enter the debugger. */
5648 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
5649 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
5650 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
5651 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
5652 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
5653 signal_print
[TARGET_SIGNAL_PROF
] = 0;
5654 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
5655 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
5656 signal_stop
[TARGET_SIGNAL_IO
] = 0;
5657 signal_print
[TARGET_SIGNAL_IO
] = 0;
5658 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
5659 signal_print
[TARGET_SIGNAL_POLL
] = 0;
5660 signal_stop
[TARGET_SIGNAL_URG
] = 0;
5661 signal_print
[TARGET_SIGNAL_URG
] = 0;
5662 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
5663 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
5665 /* These signals are used internally by user-level thread
5666 implementations. (See signal(5) on Solaris.) Like the above
5667 signals, a healthy program receives and handles them as part of
5668 its normal operation. */
5669 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
5670 signal_print
[TARGET_SIGNAL_LWP
] = 0;
5671 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
5672 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
5673 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
5674 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
5676 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
5677 &stop_on_solib_events
, _("\
5678 Set stopping for shared library events."), _("\
5679 Show stopping for shared library events."), _("\
5680 If nonzero, gdb will give control to the user when the dynamic linker\n\
5681 notifies gdb of shared library events. The most common event of interest\n\
5682 to the user would be loading/unloading of a new library."),
5684 show_stop_on_solib_events
,
5685 &setlist
, &showlist
);
5687 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
5688 follow_fork_mode_kind_names
,
5689 &follow_fork_mode_string
, _("\
5690 Set debugger response to a program call of fork or vfork."), _("\
5691 Show debugger response to a program call of fork or vfork."), _("\
5692 A fork or vfork creates a new process. follow-fork-mode can be:\n\
5693 parent - the original process is debugged after a fork\n\
5694 child - the new process is debugged after a fork\n\
5695 The unfollowed process will continue to run.\n\
5696 By default, the debugger will follow the parent process."),
5698 show_follow_fork_mode_string
,
5699 &setlist
, &showlist
);
5701 add_setshow_enum_cmd ("scheduler-locking", class_run
,
5702 scheduler_enums
, &scheduler_mode
, _("\
5703 Set mode for locking scheduler during execution."), _("\
5704 Show mode for locking scheduler during execution."), _("\
5705 off == no locking (threads may preempt at any time)\n\
5706 on == full locking (no thread except the current thread may run)\n\
5707 step == scheduler locked during every single-step operation.\n\
5708 In this mode, no other thread may run during a step command.\n\
5709 Other threads may run while stepping over a function call ('next')."),
5710 set_schedlock_func
, /* traps on target vector */
5711 show_scheduler_mode
,
5712 &setlist
, &showlist
);
5714 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
5715 Set mode of the step operation."), _("\
5716 Show mode of the step operation."), _("\
5717 When set, doing a step over a function without debug line information\n\
5718 will stop at the first instruction of that function. Otherwise, the\n\
5719 function is skipped and the step command stops at a different source line."),
5721 show_step_stop_if_no_debug
,
5722 &setlist
, &showlist
);
5724 add_setshow_enum_cmd ("displaced-stepping", class_run
,
5725 can_use_displaced_stepping_enum
,
5726 &can_use_displaced_stepping
, _("\
5727 Set debugger's willingness to use displaced stepping."), _("\
5728 Show debugger's willingness to use displaced stepping."), _("\
5729 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
5730 supported by the target architecture. If off, gdb will not use displaced\n\
5731 stepping to step over breakpoints, even if such is supported by the target\n\
5732 architecture. If auto (which is the default), gdb will use displaced stepping\n\
5733 if the target architecture supports it and non-stop mode is active, but will not\n\
5734 use it in all-stop mode (see help set non-stop)."),
5736 show_can_use_displaced_stepping
,
5737 &setlist
, &showlist
);
5739 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
5740 &exec_direction
, _("Set direction of execution.\n\
5741 Options are 'forward' or 'reverse'."),
5742 _("Show direction of execution (forward/reverse)."),
5743 _("Tells gdb whether to execute forward or backward."),
5744 set_exec_direction_func
, show_exec_direction_func
,
5745 &setlist
, &showlist
);
5747 /* ptid initializations */
5748 null_ptid
= ptid_build (0, 0, 0);
5749 minus_one_ptid
= ptid_build (-1, 0, 0);
5750 inferior_ptid
= null_ptid
;
5751 target_last_wait_ptid
= minus_one_ptid
;
5752 displaced_step_ptid
= null_ptid
;
5754 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
5755 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
5756 observer_attach_thread_exit (infrun_thread_thread_exit
);
5758 /* Explicitly create without lookup, since that tries to create a
5759 value with a void typed value, and when we get here, gdbarch
5760 isn't initialized yet. At this point, we're quite sure there
5761 isn't another convenience variable of the same name. */
5762 create_internalvar_type_lazy ("_siginfo", siginfo_make_value
);