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"
52 #include "inline-frame.h"
54 /* Prototypes for local functions */
56 static void signals_info (char *, int);
58 static void handle_command (char *, int);
60 static void sig_print_info (enum target_signal
);
62 static void sig_print_header (void);
64 static void resume_cleanups (void *);
66 static int hook_stop_stub (void *);
68 static int restore_selected_frame (void *);
70 static void build_infrun (void);
72 static int follow_fork (void);
74 static void set_schedlock_func (char *args
, int from_tty
,
75 struct cmd_list_element
*c
);
77 static int currently_stepping (struct thread_info
*tp
);
79 static int currently_stepping_or_nexting_callback (struct thread_info
*tp
,
82 static void xdb_handle_command (char *args
, int from_tty
);
84 static int prepare_to_proceed (int);
86 void _initialize_infrun (void);
88 void nullify_last_target_wait_ptid (void);
90 /* When set, stop the 'step' command if we enter a function which has
91 no line number information. The normal behavior is that we step
92 over such function. */
93 int step_stop_if_no_debug
= 0;
95 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
96 struct cmd_list_element
*c
, const char *value
)
98 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
101 /* In asynchronous mode, but simulating synchronous execution. */
103 int sync_execution
= 0;
105 /* wait_for_inferior and normal_stop use this to notify the user
106 when the inferior stopped in a different thread than it had been
109 static ptid_t previous_inferior_ptid
;
111 int debug_displaced
= 0;
113 show_debug_displaced (struct ui_file
*file
, int from_tty
,
114 struct cmd_list_element
*c
, const char *value
)
116 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
119 static int debug_infrun
= 0;
121 show_debug_infrun (struct ui_file
*file
, int from_tty
,
122 struct cmd_list_element
*c
, const char *value
)
124 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
127 /* If the program uses ELF-style shared libraries, then calls to
128 functions in shared libraries go through stubs, which live in a
129 table called the PLT (Procedure Linkage Table). The first time the
130 function is called, the stub sends control to the dynamic linker,
131 which looks up the function's real address, patches the stub so
132 that future calls will go directly to the function, and then passes
133 control to the function.
135 If we are stepping at the source level, we don't want to see any of
136 this --- we just want to skip over the stub and the dynamic linker.
137 The simple approach is to single-step until control leaves the
140 However, on some systems (e.g., Red Hat's 5.2 distribution) the
141 dynamic linker calls functions in the shared C library, so you
142 can't tell from the PC alone whether the dynamic linker is still
143 running. In this case, we use a step-resume breakpoint to get us
144 past the dynamic linker, as if we were using "next" to step over a
147 in_solib_dynsym_resolve_code() says whether we're in the dynamic
148 linker code or not. Normally, this means we single-step. However,
149 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
150 address where we can place a step-resume breakpoint to get past the
151 linker's symbol resolution function.
153 in_solib_dynsym_resolve_code() can generally be implemented in a
154 pretty portable way, by comparing the PC against the address ranges
155 of the dynamic linker's sections.
157 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
158 it depends on internal details of the dynamic linker. It's usually
159 not too hard to figure out where to put a breakpoint, but it
160 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
161 sanity checking. If it can't figure things out, returning zero and
162 getting the (possibly confusing) stepping behavior is better than
163 signalling an error, which will obscure the change in the
166 /* This function returns TRUE if pc is the address of an instruction
167 that lies within the dynamic linker (such as the event hook, or the
170 This function must be used only when a dynamic linker event has
171 been caught, and the inferior is being stepped out of the hook, or
172 undefined results are guaranteed. */
174 #ifndef SOLIB_IN_DYNAMIC_LINKER
175 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
179 /* Convert the #defines into values. This is temporary until wfi control
180 flow is completely sorted out. */
182 #ifndef CANNOT_STEP_HW_WATCHPOINTS
183 #define CANNOT_STEP_HW_WATCHPOINTS 0
185 #undef CANNOT_STEP_HW_WATCHPOINTS
186 #define CANNOT_STEP_HW_WATCHPOINTS 1
189 /* Tables of how to react to signals; the user sets them. */
191 static unsigned char *signal_stop
;
192 static unsigned char *signal_print
;
193 static unsigned char *signal_program
;
195 #define SET_SIGS(nsigs,sigs,flags) \
197 int signum = (nsigs); \
198 while (signum-- > 0) \
199 if ((sigs)[signum]) \
200 (flags)[signum] = 1; \
203 #define UNSET_SIGS(nsigs,sigs,flags) \
205 int signum = (nsigs); \
206 while (signum-- > 0) \
207 if ((sigs)[signum]) \
208 (flags)[signum] = 0; \
211 /* Value to pass to target_resume() to cause all threads to resume */
213 #define RESUME_ALL minus_one_ptid
215 /* Command list pointer for the "stop" placeholder. */
217 static struct cmd_list_element
*stop_command
;
219 /* Function inferior was in as of last step command. */
221 static struct symbol
*step_start_function
;
223 /* Nonzero if we want to give control to the user when we're notified
224 of shared library events by the dynamic linker. */
225 static int stop_on_solib_events
;
227 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
228 struct cmd_list_element
*c
, const char *value
)
230 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
234 /* Nonzero means expecting a trace trap
235 and should stop the inferior and return silently when it happens. */
239 /* Save register contents here when executing a "finish" command or are
240 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
241 Thus this contains the return value from the called function (assuming
242 values are returned in a register). */
244 struct regcache
*stop_registers
;
246 /* Nonzero after stop if current stack frame should be printed. */
248 static int stop_print_frame
;
250 /* This is a cached copy of the pid/waitstatus of the last event
251 returned by target_wait()/deprecated_target_wait_hook(). This
252 information is returned by get_last_target_status(). */
253 static ptid_t target_last_wait_ptid
;
254 static struct target_waitstatus target_last_waitstatus
;
256 static void context_switch (ptid_t ptid
);
258 void init_thread_stepping_state (struct thread_info
*tss
);
260 void init_infwait_state (void);
262 static const char follow_fork_mode_child
[] = "child";
263 static const char follow_fork_mode_parent
[] = "parent";
265 static const char *follow_fork_mode_kind_names
[] = {
266 follow_fork_mode_child
,
267 follow_fork_mode_parent
,
271 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
273 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
274 struct cmd_list_element
*c
, const char *value
)
276 fprintf_filtered (file
, _("\
277 Debugger response to a program call of fork or vfork is \"%s\".\n"),
282 /* Tell the target to follow the fork we're stopped at. Returns true
283 if the inferior should be resumed; false, if the target for some
284 reason decided it's best not to resume. */
289 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
290 int should_resume
= 1;
291 struct thread_info
*tp
;
293 /* Copy user stepping state to the new inferior thread. FIXME: the
294 followed fork child thread should have a copy of most of the
295 parent thread structure's run control related fields, not just these.
296 Initialized to avoid "may be used uninitialized" warnings from gcc. */
297 struct breakpoint
*step_resume_breakpoint
= NULL
;
298 CORE_ADDR step_range_start
= 0;
299 CORE_ADDR step_range_end
= 0;
300 struct frame_id step_frame_id
= { 0 };
305 struct target_waitstatus wait_status
;
307 /* Get the last target status returned by target_wait(). */
308 get_last_target_status (&wait_ptid
, &wait_status
);
310 /* If not stopped at a fork event, then there's nothing else to
312 if (wait_status
.kind
!= TARGET_WAITKIND_FORKED
313 && wait_status
.kind
!= TARGET_WAITKIND_VFORKED
)
316 /* Check if we switched over from WAIT_PTID, since the event was
318 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
319 && !ptid_equal (inferior_ptid
, wait_ptid
))
321 /* We did. Switch back to WAIT_PTID thread, to tell the
322 target to follow it (in either direction). We'll
323 afterwards refuse to resume, and inform the user what
325 switch_to_thread (wait_ptid
);
330 tp
= inferior_thread ();
332 /* If there were any forks/vforks that were caught and are now to be
333 followed, then do so now. */
334 switch (tp
->pending_follow
.kind
)
336 case TARGET_WAITKIND_FORKED
:
337 case TARGET_WAITKIND_VFORKED
:
339 ptid_t parent
, child
;
341 /* If the user did a next/step, etc, over a fork call,
342 preserve the stepping state in the fork child. */
343 if (follow_child
&& should_resume
)
345 step_resume_breakpoint
346 = clone_momentary_breakpoint (tp
->step_resume_breakpoint
);
347 step_range_start
= tp
->step_range_start
;
348 step_range_end
= tp
->step_range_end
;
349 step_frame_id
= tp
->step_frame_id
;
351 /* For now, delete the parent's sr breakpoint, otherwise,
352 parent/child sr breakpoints are considered duplicates,
353 and the child version will not be installed. Remove
354 this when the breakpoints module becomes aware of
355 inferiors and address spaces. */
356 delete_step_resume_breakpoint (tp
);
357 tp
->step_range_start
= 0;
358 tp
->step_range_end
= 0;
359 tp
->step_frame_id
= null_frame_id
;
362 parent
= inferior_ptid
;
363 child
= tp
->pending_follow
.value
.related_pid
;
365 /* Tell the target to do whatever is necessary to follow
366 either parent or child. */
367 if (target_follow_fork (follow_child
))
369 /* Target refused to follow, or there's some other reason
370 we shouldn't resume. */
375 /* This pending follow fork event is now handled, one way
376 or another. The previous selected thread may be gone
377 from the lists by now, but if it is still around, need
378 to clear the pending follow request. */
379 tp
= find_thread_ptid (parent
);
381 tp
->pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
383 /* This makes sure we don't try to apply the "Switched
384 over from WAIT_PID" logic above. */
385 nullify_last_target_wait_ptid ();
387 /* If we followed the child, switch to it... */
390 switch_to_thread (child
);
392 /* ... and preserve the stepping state, in case the
393 user was stepping over the fork call. */
396 tp
= inferior_thread ();
397 tp
->step_resume_breakpoint
= step_resume_breakpoint
;
398 tp
->step_range_start
= step_range_start
;
399 tp
->step_range_end
= step_range_end
;
400 tp
->step_frame_id
= step_frame_id
;
404 /* If we get here, it was because we're trying to
405 resume from a fork catchpoint, but, the user
406 has switched threads away from the thread that
407 forked. In that case, the resume command
408 issued is most likely not applicable to the
409 child, so just warn, and refuse to resume. */
411 Not resuming: switched threads before following fork child.\n"));
414 /* Reset breakpoints in the child as appropriate. */
415 follow_inferior_reset_breakpoints ();
418 switch_to_thread (parent
);
422 case TARGET_WAITKIND_SPURIOUS
:
423 /* Nothing to follow. */
426 internal_error (__FILE__
, __LINE__
,
427 "Unexpected pending_follow.kind %d\n",
428 tp
->pending_follow
.kind
);
432 return should_resume
;
436 follow_inferior_reset_breakpoints (void)
438 struct thread_info
*tp
= inferior_thread ();
440 /* Was there a step_resume breakpoint? (There was if the user
441 did a "next" at the fork() call.) If so, explicitly reset its
444 step_resumes are a form of bp that are made to be per-thread.
445 Since we created the step_resume bp when the parent process
446 was being debugged, and now are switching to the child process,
447 from the breakpoint package's viewpoint, that's a switch of
448 "threads". We must update the bp's notion of which thread
449 it is for, or it'll be ignored when it triggers. */
451 if (tp
->step_resume_breakpoint
)
452 breakpoint_re_set_thread (tp
->step_resume_breakpoint
);
454 /* Reinsert all breakpoints in the child. The user may have set
455 breakpoints after catching the fork, in which case those
456 were never set in the child, but only in the parent. This makes
457 sure the inserted breakpoints match the breakpoint list. */
459 breakpoint_re_set ();
460 insert_breakpoints ();
463 /* EXECD_PATHNAME is assumed to be non-NULL. */
466 follow_exec (ptid_t pid
, char *execd_pathname
)
468 struct target_ops
*tgt
;
469 struct thread_info
*th
= inferior_thread ();
471 /* This is an exec event that we actually wish to pay attention to.
472 Refresh our symbol table to the newly exec'd program, remove any
475 If there are breakpoints, they aren't really inserted now,
476 since the exec() transformed our inferior into a fresh set
479 We want to preserve symbolic breakpoints on the list, since
480 we have hopes that they can be reset after the new a.out's
481 symbol table is read.
483 However, any "raw" breakpoints must be removed from the list
484 (e.g., the solib bp's), since their address is probably invalid
487 And, we DON'T want to call delete_breakpoints() here, since
488 that may write the bp's "shadow contents" (the instruction
489 value that was overwritten witha TRAP instruction). Since
490 we now have a new a.out, those shadow contents aren't valid. */
491 update_breakpoints_after_exec ();
493 /* If there was one, it's gone now. We cannot truly step-to-next
494 statement through an exec(). */
495 th
->step_resume_breakpoint
= NULL
;
496 th
->step_range_start
= 0;
497 th
->step_range_end
= 0;
499 /* The target reports the exec event to the main thread, even if
500 some other thread does the exec, and even if the main thread was
501 already stopped --- if debugging in non-stop mode, it's possible
502 the user had the main thread held stopped in the previous image
503 --- release it now. This is the same behavior as step-over-exec
504 with scheduler-locking on in all-stop mode. */
505 th
->stop_requested
= 0;
507 /* What is this a.out's name? */
508 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
510 /* We've followed the inferior through an exec. Therefore, the
511 inferior has essentially been killed & reborn. */
513 gdb_flush (gdb_stdout
);
515 breakpoint_init_inferior (inf_execd
);
517 if (gdb_sysroot
&& *gdb_sysroot
)
519 char *name
= alloca (strlen (gdb_sysroot
)
520 + strlen (execd_pathname
)
522 strcpy (name
, gdb_sysroot
);
523 strcat (name
, execd_pathname
);
524 execd_pathname
= name
;
527 /* That a.out is now the one to use. */
528 exec_file_attach (execd_pathname
, 0);
530 /* Reset the shared library package. This ensures that we get a
531 shlib event when the child reaches "_start", at which point the
532 dld will have had a chance to initialize the child. */
533 /* Also, loading a symbol file below may trigger symbol lookups, and
534 we don't want those to be satisfied by the libraries of the
535 previous incarnation of this process. */
536 no_shared_libraries (NULL
, 0);
538 /* Load the main file's symbols. */
539 symbol_file_add_main (execd_pathname
, 0);
541 #ifdef SOLIB_CREATE_INFERIOR_HOOK
542 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
544 solib_create_inferior_hook ();
547 /* Reinsert all breakpoints. (Those which were symbolic have
548 been reset to the proper address in the new a.out, thanks
549 to symbol_file_command...) */
550 insert_breakpoints ();
552 /* The next resume of this inferior should bring it to the shlib
553 startup breakpoints. (If the user had also set bp's on
554 "main" from the old (parent) process, then they'll auto-
555 matically get reset there in the new process.) */
558 /* Non-zero if we just simulating a single-step. This is needed
559 because we cannot remove the breakpoints in the inferior process
560 until after the `wait' in `wait_for_inferior'. */
561 static int singlestep_breakpoints_inserted_p
= 0;
563 /* The thread we inserted single-step breakpoints for. */
564 static ptid_t singlestep_ptid
;
566 /* PC when we started this single-step. */
567 static CORE_ADDR singlestep_pc
;
569 /* If another thread hit the singlestep breakpoint, we save the original
570 thread here so that we can resume single-stepping it later. */
571 static ptid_t saved_singlestep_ptid
;
572 static int stepping_past_singlestep_breakpoint
;
574 /* If not equal to null_ptid, this means that after stepping over breakpoint
575 is finished, we need to switch to deferred_step_ptid, and step it.
577 The use case is when one thread has hit a breakpoint, and then the user
578 has switched to another thread and issued 'step'. We need to step over
579 breakpoint in the thread which hit the breakpoint, but then continue
580 stepping the thread user has selected. */
581 static ptid_t deferred_step_ptid
;
583 /* Displaced stepping. */
585 /* In non-stop debugging mode, we must take special care to manage
586 breakpoints properly; in particular, the traditional strategy for
587 stepping a thread past a breakpoint it has hit is unsuitable.
588 'Displaced stepping' is a tactic for stepping one thread past a
589 breakpoint it has hit while ensuring that other threads running
590 concurrently will hit the breakpoint as they should.
592 The traditional way to step a thread T off a breakpoint in a
593 multi-threaded program in all-stop mode is as follows:
595 a0) Initially, all threads are stopped, and breakpoints are not
597 a1) We single-step T, leaving breakpoints uninserted.
598 a2) We insert breakpoints, and resume all threads.
600 In non-stop debugging, however, this strategy is unsuitable: we
601 don't want to have to stop all threads in the system in order to
602 continue or step T past a breakpoint. Instead, we use displaced
605 n0) Initially, T is stopped, other threads are running, and
606 breakpoints are inserted.
607 n1) We copy the instruction "under" the breakpoint to a separate
608 location, outside the main code stream, making any adjustments
609 to the instruction, register, and memory state as directed by
611 n2) We single-step T over the instruction at its new location.
612 n3) We adjust the resulting register and memory state as directed
613 by T's architecture. This includes resetting T's PC to point
614 back into the main instruction stream.
617 This approach depends on the following gdbarch methods:
619 - gdbarch_max_insn_length and gdbarch_displaced_step_location
620 indicate where to copy the instruction, and how much space must
621 be reserved there. We use these in step n1.
623 - gdbarch_displaced_step_copy_insn copies a instruction to a new
624 address, and makes any necessary adjustments to the instruction,
625 register contents, and memory. We use this in step n1.
627 - gdbarch_displaced_step_fixup adjusts registers and memory after
628 we have successfuly single-stepped the instruction, to yield the
629 same effect the instruction would have had if we had executed it
630 at its original address. We use this in step n3.
632 - gdbarch_displaced_step_free_closure provides cleanup.
634 The gdbarch_displaced_step_copy_insn and
635 gdbarch_displaced_step_fixup functions must be written so that
636 copying an instruction with gdbarch_displaced_step_copy_insn,
637 single-stepping across the copied instruction, and then applying
638 gdbarch_displaced_insn_fixup should have the same effects on the
639 thread's memory and registers as stepping the instruction in place
640 would have. Exactly which responsibilities fall to the copy and
641 which fall to the fixup is up to the author of those functions.
643 See the comments in gdbarch.sh for details.
645 Note that displaced stepping and software single-step cannot
646 currently be used in combination, although with some care I think
647 they could be made to. Software single-step works by placing
648 breakpoints on all possible subsequent instructions; if the
649 displaced instruction is a PC-relative jump, those breakpoints
650 could fall in very strange places --- on pages that aren't
651 executable, or at addresses that are not proper instruction
652 boundaries. (We do generally let other threads run while we wait
653 to hit the software single-step breakpoint, and they might
654 encounter such a corrupted instruction.) One way to work around
655 this would be to have gdbarch_displaced_step_copy_insn fully
656 simulate the effect of PC-relative instructions (and return NULL)
657 on architectures that use software single-stepping.
659 In non-stop mode, we can have independent and simultaneous step
660 requests, so more than one thread may need to simultaneously step
661 over a breakpoint. The current implementation assumes there is
662 only one scratch space per process. In this case, we have to
663 serialize access to the scratch space. If thread A wants to step
664 over a breakpoint, but we are currently waiting for some other
665 thread to complete a displaced step, we leave thread A stopped and
666 place it in the displaced_step_request_queue. Whenever a displaced
667 step finishes, we pick the next thread in the queue and start a new
668 displaced step operation on it. See displaced_step_prepare and
669 displaced_step_fixup for details. */
671 /* If this is not null_ptid, this is the thread carrying out a
672 displaced single-step. This thread's state will require fixing up
673 once it has completed its step. */
674 static ptid_t displaced_step_ptid
;
676 struct displaced_step_request
679 struct displaced_step_request
*next
;
682 /* A queue of pending displaced stepping requests. */
683 struct displaced_step_request
*displaced_step_request_queue
;
685 /* The architecture the thread had when we stepped it. */
686 static struct gdbarch
*displaced_step_gdbarch
;
688 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
689 for post-step cleanup. */
690 static struct displaced_step_closure
*displaced_step_closure
;
692 /* The address of the original instruction, and the copy we made. */
693 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
695 /* Saved contents of copy area. */
696 static gdb_byte
*displaced_step_saved_copy
;
698 /* Enum strings for "set|show displaced-stepping". */
700 static const char can_use_displaced_stepping_auto
[] = "auto";
701 static const char can_use_displaced_stepping_on
[] = "on";
702 static const char can_use_displaced_stepping_off
[] = "off";
703 static const char *can_use_displaced_stepping_enum
[] =
705 can_use_displaced_stepping_auto
,
706 can_use_displaced_stepping_on
,
707 can_use_displaced_stepping_off
,
711 /* If ON, and the architecture supports it, GDB will use displaced
712 stepping to step over breakpoints. If OFF, or if the architecture
713 doesn't support it, GDB will instead use the traditional
714 hold-and-step approach. If AUTO (which is the default), GDB will
715 decide which technique to use to step over breakpoints depending on
716 which of all-stop or non-stop mode is active --- displaced stepping
717 in non-stop mode; hold-and-step in all-stop mode. */
719 static const char *can_use_displaced_stepping
=
720 can_use_displaced_stepping_auto
;
723 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
724 struct cmd_list_element
*c
,
727 if (can_use_displaced_stepping
== can_use_displaced_stepping_auto
)
728 fprintf_filtered (file
, _("\
729 Debugger's willingness to use displaced stepping to step over \
730 breakpoints is %s (currently %s).\n"),
731 value
, non_stop
? "on" : "off");
733 fprintf_filtered (file
, _("\
734 Debugger's willingness to use displaced stepping to step over \
735 breakpoints is %s.\n"), value
);
738 /* Return non-zero if displaced stepping can/should be used to step
742 use_displaced_stepping (struct gdbarch
*gdbarch
)
744 return (((can_use_displaced_stepping
== can_use_displaced_stepping_auto
746 || can_use_displaced_stepping
== can_use_displaced_stepping_on
)
747 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
751 /* Clean out any stray displaced stepping state. */
753 displaced_step_clear (void)
755 /* Indicate that there is no cleanup pending. */
756 displaced_step_ptid
= null_ptid
;
758 if (displaced_step_closure
)
760 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
761 displaced_step_closure
);
762 displaced_step_closure
= NULL
;
767 displaced_step_clear_cleanup (void *ignore
)
769 displaced_step_clear ();
772 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
774 displaced_step_dump_bytes (struct ui_file
*file
,
780 for (i
= 0; i
< len
; i
++)
781 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
782 fputs_unfiltered ("\n", file
);
785 /* Prepare to single-step, using displaced stepping.
787 Note that we cannot use displaced stepping when we have a signal to
788 deliver. If we have a signal to deliver and an instruction to step
789 over, then after the step, there will be no indication from the
790 target whether the thread entered a signal handler or ignored the
791 signal and stepped over the instruction successfully --- both cases
792 result in a simple SIGTRAP. In the first case we mustn't do a
793 fixup, and in the second case we must --- but we can't tell which.
794 Comments in the code for 'random signals' in handle_inferior_event
795 explain how we handle this case instead.
797 Returns 1 if preparing was successful -- this thread is going to be
798 stepped now; or 0 if displaced stepping this thread got queued. */
800 displaced_step_prepare (ptid_t ptid
)
802 struct cleanup
*old_cleanups
, *ignore_cleanups
;
803 struct regcache
*regcache
= get_thread_regcache (ptid
);
804 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
805 CORE_ADDR original
, copy
;
807 struct displaced_step_closure
*closure
;
809 /* We should never reach this function if the architecture does not
810 support displaced stepping. */
811 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
813 /* For the first cut, we're displaced stepping one thread at a
816 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
818 /* Already waiting for a displaced step to finish. Defer this
819 request and place in queue. */
820 struct displaced_step_request
*req
, *new_req
;
823 fprintf_unfiltered (gdb_stdlog
,
824 "displaced: defering step of %s\n",
825 target_pid_to_str (ptid
));
827 new_req
= xmalloc (sizeof (*new_req
));
828 new_req
->ptid
= ptid
;
829 new_req
->next
= NULL
;
831 if (displaced_step_request_queue
)
833 for (req
= displaced_step_request_queue
;
840 displaced_step_request_queue
= new_req
;
847 fprintf_unfiltered (gdb_stdlog
,
848 "displaced: stepping %s now\n",
849 target_pid_to_str (ptid
));
852 displaced_step_clear ();
854 old_cleanups
= save_inferior_ptid ();
855 inferior_ptid
= ptid
;
857 original
= regcache_read_pc (regcache
);
859 copy
= gdbarch_displaced_step_location (gdbarch
);
860 len
= gdbarch_max_insn_length (gdbarch
);
862 /* Save the original contents of the copy area. */
863 displaced_step_saved_copy
= xmalloc (len
);
864 ignore_cleanups
= make_cleanup (free_current_contents
,
865 &displaced_step_saved_copy
);
866 read_memory (copy
, displaced_step_saved_copy
, len
);
869 fprintf_unfiltered (gdb_stdlog
, "displaced: saved %s: ",
870 paddress (gdbarch
, copy
));
871 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
874 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
875 original
, copy
, regcache
);
877 /* We don't support the fully-simulated case at present. */
878 gdb_assert (closure
);
880 /* Save the information we need to fix things up if the step
882 displaced_step_ptid
= ptid
;
883 displaced_step_gdbarch
= gdbarch
;
884 displaced_step_closure
= closure
;
885 displaced_step_original
= original
;
886 displaced_step_copy
= copy
;
888 make_cleanup (displaced_step_clear_cleanup
, 0);
890 /* Resume execution at the copy. */
891 regcache_write_pc (regcache
, copy
);
893 discard_cleanups (ignore_cleanups
);
895 do_cleanups (old_cleanups
);
898 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to %s\n",
899 paddress (gdbarch
, copy
));
905 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
907 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
908 inferior_ptid
= ptid
;
909 write_memory (memaddr
, myaddr
, len
);
910 do_cleanups (ptid_cleanup
);
914 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
916 struct cleanup
*old_cleanups
;
918 /* Was this event for the pid we displaced? */
919 if (ptid_equal (displaced_step_ptid
, null_ptid
)
920 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
923 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
925 /* Restore the contents of the copy area. */
927 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
928 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
929 displaced_step_saved_copy
, len
);
931 fprintf_unfiltered (gdb_stdlog
, "displaced: restored %s\n",
932 paddress (displaced_step_gdbarch
,
933 displaced_step_copy
));
936 /* Did the instruction complete successfully? */
937 if (signal
== TARGET_SIGNAL_TRAP
)
939 /* Fix up the resulting state. */
940 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
941 displaced_step_closure
,
942 displaced_step_original
,
944 get_thread_regcache (displaced_step_ptid
));
948 /* Since the instruction didn't complete, all we can do is
950 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
951 CORE_ADDR pc
= regcache_read_pc (regcache
);
952 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
953 regcache_write_pc (regcache
, pc
);
956 do_cleanups (old_cleanups
);
958 displaced_step_ptid
= null_ptid
;
960 /* Are there any pending displaced stepping requests? If so, run
962 while (displaced_step_request_queue
)
964 struct displaced_step_request
*head
;
966 struct regcache
*regcache
;
969 head
= displaced_step_request_queue
;
971 displaced_step_request_queue
= head
->next
;
974 context_switch (ptid
);
976 regcache
= get_thread_regcache (ptid
);
977 actual_pc
= regcache_read_pc (regcache
);
979 if (breakpoint_here_p (actual_pc
))
982 fprintf_unfiltered (gdb_stdlog
,
983 "displaced: stepping queued %s now\n",
984 target_pid_to_str (ptid
));
986 displaced_step_prepare (ptid
);
990 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
993 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
994 paddress (gdbarch
, actual_pc
));
995 read_memory (actual_pc
, buf
, sizeof (buf
));
996 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
999 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
1001 /* Done, we're stepping a thread. */
1007 struct thread_info
*tp
= inferior_thread ();
1009 /* The breakpoint we were sitting under has since been
1011 tp
->trap_expected
= 0;
1013 /* Go back to what we were trying to do. */
1014 step
= currently_stepping (tp
);
1016 if (debug_displaced
)
1017 fprintf_unfiltered (gdb_stdlog
, "breakpoint is gone %s: step(%d)\n",
1018 target_pid_to_str (tp
->ptid
), step
);
1020 target_resume (ptid
, step
, TARGET_SIGNAL_0
);
1021 tp
->stop_signal
= TARGET_SIGNAL_0
;
1023 /* This request was discarded. See if there's any other
1024 thread waiting for its turn. */
1029 /* Update global variables holding ptids to hold NEW_PTID if they were
1030 holding OLD_PTID. */
1032 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
1034 struct displaced_step_request
*it
;
1036 if (ptid_equal (inferior_ptid
, old_ptid
))
1037 inferior_ptid
= new_ptid
;
1039 if (ptid_equal (singlestep_ptid
, old_ptid
))
1040 singlestep_ptid
= new_ptid
;
1042 if (ptid_equal (displaced_step_ptid
, old_ptid
))
1043 displaced_step_ptid
= new_ptid
;
1045 if (ptid_equal (deferred_step_ptid
, old_ptid
))
1046 deferred_step_ptid
= new_ptid
;
1048 for (it
= displaced_step_request_queue
; it
; it
= it
->next
)
1049 if (ptid_equal (it
->ptid
, old_ptid
))
1050 it
->ptid
= new_ptid
;
1056 /* Things to clean up if we QUIT out of resume (). */
1058 resume_cleanups (void *ignore
)
1063 static const char schedlock_off
[] = "off";
1064 static const char schedlock_on
[] = "on";
1065 static const char schedlock_step
[] = "step";
1066 static const char *scheduler_enums
[] = {
1072 static const char *scheduler_mode
= schedlock_off
;
1074 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
1075 struct cmd_list_element
*c
, const char *value
)
1077 fprintf_filtered (file
, _("\
1078 Mode for locking scheduler during execution is \"%s\".\n"),
1083 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
1085 if (!target_can_lock_scheduler
)
1087 scheduler_mode
= schedlock_off
;
1088 error (_("Target '%s' cannot support this command."), target_shortname
);
1092 /* True if execution commands resume all threads of all processes by
1093 default; otherwise, resume only threads of the current inferior
1095 int sched_multi
= 0;
1097 /* Try to setup for software single stepping over the specified location.
1098 Return 1 if target_resume() should use hardware single step.
1100 GDBARCH the current gdbarch.
1101 PC the location to step over. */
1104 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
1108 if (gdbarch_software_single_step_p (gdbarch
)
1109 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
1112 /* Do not pull these breakpoints until after a `wait' in
1113 `wait_for_inferior' */
1114 singlestep_breakpoints_inserted_p
= 1;
1115 singlestep_ptid
= inferior_ptid
;
1121 /* Resume the inferior, but allow a QUIT. This is useful if the user
1122 wants to interrupt some lengthy single-stepping operation
1123 (for child processes, the SIGINT goes to the inferior, and so
1124 we get a SIGINT random_signal, but for remote debugging and perhaps
1125 other targets, that's not true).
1127 STEP nonzero if we should step (zero to continue instead).
1128 SIG is the signal to give the inferior (zero for none). */
1130 resume (int step
, enum target_signal sig
)
1132 int should_resume
= 1;
1133 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
1134 struct regcache
*regcache
= get_current_regcache ();
1135 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1136 struct thread_info
*tp
= inferior_thread ();
1137 CORE_ADDR pc
= regcache_read_pc (regcache
);
1142 fprintf_unfiltered (gdb_stdlog
,
1143 "infrun: resume (step=%d, signal=%d), "
1144 "trap_expected=%d\n",
1145 step
, sig
, tp
->trap_expected
);
1147 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
1148 over an instruction that causes a page fault without triggering
1149 a hardware watchpoint. The kernel properly notices that it shouldn't
1150 stop, because the hardware watchpoint is not triggered, but it forgets
1151 the step request and continues the program normally.
1152 Work around the problem by removing hardware watchpoints if a step is
1153 requested, GDB will check for a hardware watchpoint trigger after the
1155 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
1156 remove_hw_watchpoints ();
1159 /* Normally, by the time we reach `resume', the breakpoints are either
1160 removed or inserted, as appropriate. The exception is if we're sitting
1161 at a permanent breakpoint; we need to step over it, but permanent
1162 breakpoints can't be removed. So we have to test for it here. */
1163 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
1165 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1166 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1169 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1170 how to step past a permanent breakpoint on this architecture. Try using\n\
1171 a command like `return' or `jump' to continue execution."));
1174 /* If enabled, step over breakpoints by executing a copy of the
1175 instruction at a different address.
1177 We can't use displaced stepping when we have a signal to deliver;
1178 the comments for displaced_step_prepare explain why. The
1179 comments in the handle_inferior event for dealing with 'random
1180 signals' explain what we do instead. */
1181 if (use_displaced_stepping (gdbarch
)
1182 && tp
->trap_expected
1183 && sig
== TARGET_SIGNAL_0
)
1185 if (!displaced_step_prepare (inferior_ptid
))
1187 /* Got placed in displaced stepping queue. Will be resumed
1188 later when all the currently queued displaced stepping
1189 requests finish. The thread is not executing at this point,
1190 and the call to set_executing will be made later. But we
1191 need to call set_running here, since from frontend point of view,
1192 the thread is running. */
1193 set_running (inferior_ptid
, 1);
1194 discard_cleanups (old_cleanups
);
1199 /* Do we need to do it the hard way, w/temp breakpoints? */
1201 step
= maybe_software_singlestep (gdbarch
, pc
);
1207 /* If STEP is set, it's a request to use hardware stepping
1208 facilities. But in that case, we should never
1209 use singlestep breakpoint. */
1210 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1212 /* Decide the set of threads to ask the target to resume. Start
1213 by assuming everything will be resumed, than narrow the set
1214 by applying increasingly restricting conditions. */
1216 /* By default, resume all threads of all processes. */
1217 resume_ptid
= RESUME_ALL
;
1219 /* Maybe resume only all threads of the current process. */
1220 if (!sched_multi
&& target_supports_multi_process ())
1222 resume_ptid
= pid_to_ptid (ptid_get_pid (inferior_ptid
));
1225 /* Maybe resume a single thread after all. */
1226 if (singlestep_breakpoints_inserted_p
1227 && stepping_past_singlestep_breakpoint
)
1229 /* The situation here is as follows. In thread T1 we wanted to
1230 single-step. Lacking hardware single-stepping we've
1231 set breakpoint at the PC of the next instruction -- call it
1232 P. After resuming, we've hit that breakpoint in thread T2.
1233 Now we've removed original breakpoint, inserted breakpoint
1234 at P+1, and try to step to advance T2 past breakpoint.
1235 We need to step only T2, as if T1 is allowed to freely run,
1236 it can run past P, and if other threads are allowed to run,
1237 they can hit breakpoint at P+1, and nested hits of single-step
1238 breakpoints is not something we'd want -- that's complicated
1239 to support, and has no value. */
1240 resume_ptid
= inferior_ptid
;
1242 else if ((step
|| singlestep_breakpoints_inserted_p
)
1243 && tp
->trap_expected
)
1245 /* We're allowing a thread to run past a breakpoint it has
1246 hit, by single-stepping the thread with the breakpoint
1247 removed. In which case, we need to single-step only this
1248 thread, and keep others stopped, as they can miss this
1249 breakpoint if allowed to run.
1251 The current code actually removes all breakpoints when
1252 doing this, not just the one being stepped over, so if we
1253 let other threads run, we can actually miss any
1254 breakpoint, not just the one at PC. */
1255 resume_ptid
= inferior_ptid
;
1259 /* With non-stop mode on, threads are always handled
1261 resume_ptid
= inferior_ptid
;
1263 else if ((scheduler_mode
== schedlock_on
)
1264 || (scheduler_mode
== schedlock_step
1265 && (step
|| singlestep_breakpoints_inserted_p
)))
1267 /* User-settable 'scheduler' mode requires solo thread resume. */
1268 resume_ptid
= inferior_ptid
;
1271 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1273 /* Most targets can step a breakpoint instruction, thus
1274 executing it normally. But if this one cannot, just
1275 continue and we will hit it anyway. */
1276 if (step
&& breakpoint_inserted_here_p (pc
))
1281 && use_displaced_stepping (gdbarch
)
1282 && tp
->trap_expected
)
1284 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1285 struct gdbarch
*resume_gdbarch
= get_regcache_arch (resume_regcache
);
1286 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1289 fprintf_unfiltered (gdb_stdlog
, "displaced: run %s: ",
1290 paddress (resume_gdbarch
, actual_pc
));
1291 read_memory (actual_pc
, buf
, sizeof (buf
));
1292 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1295 /* Install inferior's terminal modes. */
1296 target_terminal_inferior ();
1298 /* Avoid confusing the next resume, if the next stop/resume
1299 happens to apply to another thread. */
1300 tp
->stop_signal
= TARGET_SIGNAL_0
;
1302 target_resume (resume_ptid
, step
, sig
);
1305 discard_cleanups (old_cleanups
);
1310 /* Clear out all variables saying what to do when inferior is continued.
1311 First do this, then set the ones you want, then call `proceed'. */
1314 clear_proceed_status_thread (struct thread_info
*tp
)
1317 fprintf_unfiltered (gdb_stdlog
,
1318 "infrun: clear_proceed_status_thread (%s)\n",
1319 target_pid_to_str (tp
->ptid
));
1321 tp
->trap_expected
= 0;
1322 tp
->step_range_start
= 0;
1323 tp
->step_range_end
= 0;
1324 tp
->step_frame_id
= null_frame_id
;
1325 tp
->step_stack_frame_id
= null_frame_id
;
1326 tp
->step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1327 tp
->stop_requested
= 0;
1331 tp
->proceed_to_finish
= 0;
1333 /* Discard any remaining commands or status from previous stop. */
1334 bpstat_clear (&tp
->stop_bpstat
);
1338 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
1340 if (is_exited (tp
->ptid
))
1343 clear_proceed_status_thread (tp
);
1348 clear_proceed_status (void)
1350 if (!ptid_equal (inferior_ptid
, null_ptid
))
1352 struct inferior
*inferior
;
1356 /* If in non-stop mode, only delete the per-thread status
1357 of the current thread. */
1358 clear_proceed_status_thread (inferior_thread ());
1362 /* In all-stop mode, delete the per-thread status of
1364 iterate_over_threads (clear_proceed_status_callback
, NULL
);
1367 inferior
= current_inferior ();
1368 inferior
->stop_soon
= NO_STOP_QUIETLY
;
1371 stop_after_trap
= 0;
1373 observer_notify_about_to_proceed ();
1377 regcache_xfree (stop_registers
);
1378 stop_registers
= NULL
;
1382 /* Check the current thread against the thread that reported the most recent
1383 event. If a step-over is required return TRUE and set the current thread
1384 to the old thread. Otherwise return FALSE.
1386 This should be suitable for any targets that support threads. */
1389 prepare_to_proceed (int step
)
1392 struct target_waitstatus wait_status
;
1393 int schedlock_enabled
;
1395 /* With non-stop mode on, threads are always handled individually. */
1396 gdb_assert (! non_stop
);
1398 /* Get the last target status returned by target_wait(). */
1399 get_last_target_status (&wait_ptid
, &wait_status
);
1401 /* Make sure we were stopped at a breakpoint. */
1402 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1403 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1408 schedlock_enabled
= (scheduler_mode
== schedlock_on
1409 || (scheduler_mode
== schedlock_step
1412 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1413 if (schedlock_enabled
)
1416 /* Don't switch over if we're about to resume some other process
1417 other than WAIT_PTID's, and schedule-multiple is off. */
1419 && ptid_get_pid (wait_ptid
) != ptid_get_pid (inferior_ptid
))
1422 /* Switched over from WAIT_PID. */
1423 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1424 && !ptid_equal (inferior_ptid
, wait_ptid
))
1426 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1428 if (breakpoint_here_p (regcache_read_pc (regcache
)))
1430 /* If stepping, remember current thread to switch back to. */
1432 deferred_step_ptid
= inferior_ptid
;
1434 /* Switch back to WAIT_PID thread. */
1435 switch_to_thread (wait_ptid
);
1437 /* We return 1 to indicate that there is a breakpoint here,
1438 so we need to step over it before continuing to avoid
1439 hitting it straight away. */
1447 /* Basic routine for continuing the program in various fashions.
1449 ADDR is the address to resume at, or -1 for resume where stopped.
1450 SIGGNAL is the signal to give it, or 0 for none,
1451 or -1 for act according to how it stopped.
1452 STEP is nonzero if should trap after one instruction.
1453 -1 means return after that and print nothing.
1454 You should probably set various step_... variables
1455 before calling here, if you are stepping.
1457 You should call clear_proceed_status before calling proceed. */
1460 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1462 struct regcache
*regcache
;
1463 struct gdbarch
*gdbarch
;
1464 struct thread_info
*tp
;
1468 /* If we're stopped at a fork/vfork, follow the branch set by the
1469 "set follow-fork-mode" command; otherwise, we'll just proceed
1470 resuming the current thread. */
1471 if (!follow_fork ())
1473 /* The target for some reason decided not to resume. */
1478 regcache
= get_current_regcache ();
1479 gdbarch
= get_regcache_arch (regcache
);
1480 pc
= regcache_read_pc (regcache
);
1483 step_start_function
= find_pc_function (pc
);
1485 stop_after_trap
= 1;
1487 if (addr
== (CORE_ADDR
) -1)
1489 if (pc
== stop_pc
&& breakpoint_here_p (pc
)
1490 && execution_direction
!= EXEC_REVERSE
)
1491 /* There is a breakpoint at the address we will resume at,
1492 step one instruction before inserting breakpoints so that
1493 we do not stop right away (and report a second hit at this
1496 Note, we don't do this in reverse, because we won't
1497 actually be executing the breakpoint insn anyway.
1498 We'll be (un-)executing the previous instruction. */
1501 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1502 && gdbarch_single_step_through_delay (gdbarch
,
1503 get_current_frame ()))
1504 /* We stepped onto an instruction that needs to be stepped
1505 again before re-inserting the breakpoint, do so. */
1510 regcache_write_pc (regcache
, addr
);
1514 fprintf_unfiltered (gdb_stdlog
,
1515 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
1516 paddress (gdbarch
, addr
), siggnal
, step
);
1519 /* In non-stop, each thread is handled individually. The context
1520 must already be set to the right thread here. */
1524 /* In a multi-threaded task we may select another thread and
1525 then continue or step.
1527 But if the old thread was stopped at a breakpoint, it will
1528 immediately cause another breakpoint stop without any
1529 execution (i.e. it will report a breakpoint hit incorrectly).
1530 So we must step over it first.
1532 prepare_to_proceed checks the current thread against the
1533 thread that reported the most recent event. If a step-over
1534 is required it returns TRUE and sets the current thread to
1536 if (prepare_to_proceed (step
))
1540 /* prepare_to_proceed may change the current thread. */
1541 tp
= inferior_thread ();
1545 tp
->trap_expected
= 1;
1546 /* If displaced stepping is enabled, we can step over the
1547 breakpoint without hitting it, so leave all breakpoints
1548 inserted. Otherwise we need to disable all breakpoints, step
1549 one instruction, and then re-add them when that step is
1551 if (!use_displaced_stepping (gdbarch
))
1552 remove_breakpoints ();
1555 /* We can insert breakpoints if we're not trying to step over one,
1556 or if we are stepping over one but we're using displaced stepping
1558 if (! tp
->trap_expected
|| use_displaced_stepping (gdbarch
))
1559 insert_breakpoints ();
1563 /* Pass the last stop signal to the thread we're resuming,
1564 irrespective of whether the current thread is the thread that
1565 got the last event or not. This was historically GDB's
1566 behaviour before keeping a stop_signal per thread. */
1568 struct thread_info
*last_thread
;
1570 struct target_waitstatus last_status
;
1572 get_last_target_status (&last_ptid
, &last_status
);
1573 if (!ptid_equal (inferior_ptid
, last_ptid
)
1574 && !ptid_equal (last_ptid
, null_ptid
)
1575 && !ptid_equal (last_ptid
, minus_one_ptid
))
1577 last_thread
= find_thread_ptid (last_ptid
);
1580 tp
->stop_signal
= last_thread
->stop_signal
;
1581 last_thread
->stop_signal
= TARGET_SIGNAL_0
;
1586 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1587 tp
->stop_signal
= siggnal
;
1588 /* If this signal should not be seen by program,
1589 give it zero. Used for debugging signals. */
1590 else if (!signal_program
[tp
->stop_signal
])
1591 tp
->stop_signal
= TARGET_SIGNAL_0
;
1593 annotate_starting ();
1595 /* Make sure that output from GDB appears before output from the
1597 gdb_flush (gdb_stdout
);
1599 /* Refresh prev_pc value just prior to resuming. This used to be
1600 done in stop_stepping, however, setting prev_pc there did not handle
1601 scenarios such as inferior function calls or returning from
1602 a function via the return command. In those cases, the prev_pc
1603 value was not set properly for subsequent commands. The prev_pc value
1604 is used to initialize the starting line number in the ecs. With an
1605 invalid value, the gdb next command ends up stopping at the position
1606 represented by the next line table entry past our start position.
1607 On platforms that generate one line table entry per line, this
1608 is not a problem. However, on the ia64, the compiler generates
1609 extraneous line table entries that do not increase the line number.
1610 When we issue the gdb next command on the ia64 after an inferior call
1611 or a return command, we often end up a few instructions forward, still
1612 within the original line we started.
1614 An attempt was made to have init_execution_control_state () refresh
1615 the prev_pc value before calculating the line number. This approach
1616 did not work because on platforms that use ptrace, the pc register
1617 cannot be read unless the inferior is stopped. At that point, we
1618 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1619 call can fail. Setting the prev_pc value here ensures the value is
1620 updated correctly when the inferior is stopped. */
1621 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
1623 /* Fill in with reasonable starting values. */
1624 init_thread_stepping_state (tp
);
1626 /* Reset to normal state. */
1627 init_infwait_state ();
1629 /* Resume inferior. */
1630 resume (oneproc
|| step
|| bpstat_should_step (), tp
->stop_signal
);
1632 /* Wait for it to stop (if not standalone)
1633 and in any case decode why it stopped, and act accordingly. */
1634 /* Do this only if we are not using the event loop, or if the target
1635 does not support asynchronous execution. */
1636 if (!target_can_async_p ())
1638 wait_for_inferior (0);
1644 /* Start remote-debugging of a machine over a serial link. */
1647 start_remote (int from_tty
)
1649 struct inferior
*inferior
;
1650 init_wait_for_inferior ();
1652 inferior
= current_inferior ();
1653 inferior
->stop_soon
= STOP_QUIETLY_REMOTE
;
1655 /* Always go on waiting for the target, regardless of the mode. */
1656 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1657 indicate to wait_for_inferior that a target should timeout if
1658 nothing is returned (instead of just blocking). Because of this,
1659 targets expecting an immediate response need to, internally, set
1660 things up so that the target_wait() is forced to eventually
1662 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1663 differentiate to its caller what the state of the target is after
1664 the initial open has been performed. Here we're assuming that
1665 the target has stopped. It should be possible to eventually have
1666 target_open() return to the caller an indication that the target
1667 is currently running and GDB state should be set to the same as
1668 for an async run. */
1669 wait_for_inferior (0);
1671 /* Now that the inferior has stopped, do any bookkeeping like
1672 loading shared libraries. We want to do this before normal_stop,
1673 so that the displayed frame is up to date. */
1674 post_create_inferior (¤t_target
, from_tty
);
1679 /* Initialize static vars when a new inferior begins. */
1682 init_wait_for_inferior (void)
1684 /* These are meaningless until the first time through wait_for_inferior. */
1686 breakpoint_init_inferior (inf_starting
);
1688 clear_proceed_status ();
1690 stepping_past_singlestep_breakpoint
= 0;
1691 deferred_step_ptid
= null_ptid
;
1693 target_last_wait_ptid
= minus_one_ptid
;
1695 previous_inferior_ptid
= null_ptid
;
1696 init_infwait_state ();
1698 displaced_step_clear ();
1700 /* Discard any skipped inlined frames. */
1701 clear_inline_frame_state (minus_one_ptid
);
1705 /* This enum encodes possible reasons for doing a target_wait, so that
1706 wfi can call target_wait in one place. (Ultimately the call will be
1707 moved out of the infinite loop entirely.) */
1711 infwait_normal_state
,
1712 infwait_thread_hop_state
,
1713 infwait_step_watch_state
,
1714 infwait_nonstep_watch_state
1717 /* Why did the inferior stop? Used to print the appropriate messages
1718 to the interface from within handle_inferior_event(). */
1719 enum inferior_stop_reason
1721 /* Step, next, nexti, stepi finished. */
1723 /* Inferior terminated by signal. */
1725 /* Inferior exited. */
1727 /* Inferior received signal, and user asked to be notified. */
1729 /* Reverse execution -- target ran out of history info. */
1733 /* The PTID we'll do a target_wait on.*/
1736 /* Current inferior wait state. */
1737 enum infwait_states infwait_state
;
1739 /* Data to be passed around while handling an event. This data is
1740 discarded between events. */
1741 struct execution_control_state
1744 /* The thread that got the event, if this was a thread event; NULL
1746 struct thread_info
*event_thread
;
1748 struct target_waitstatus ws
;
1750 CORE_ADDR stop_func_start
;
1751 CORE_ADDR stop_func_end
;
1752 char *stop_func_name
;
1753 int new_thread_event
;
1757 static void init_execution_control_state (struct execution_control_state
*ecs
);
1759 static void handle_inferior_event (struct execution_control_state
*ecs
);
1761 static void handle_step_into_function (struct gdbarch
*gdbarch
,
1762 struct execution_control_state
*ecs
);
1763 static void handle_step_into_function_backward (struct gdbarch
*gdbarch
,
1764 struct execution_control_state
*ecs
);
1765 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1766 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1767 static void insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
1768 struct symtab_and_line sr_sal
,
1769 struct frame_id sr_id
);
1770 static void insert_longjmp_resume_breakpoint (struct gdbarch
*, CORE_ADDR
);
1772 static void stop_stepping (struct execution_control_state
*ecs
);
1773 static void prepare_to_wait (struct execution_control_state
*ecs
);
1774 static void keep_going (struct execution_control_state
*ecs
);
1775 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1778 /* Callback for iterate over threads. If the thread is stopped, but
1779 the user/frontend doesn't know about that yet, go through
1780 normal_stop, as if the thread had just stopped now. ARG points at
1781 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
1782 ptid_is_pid(PTID) is true, applies to all threads of the process
1783 pointed at by PTID. Otherwise, apply only to the thread pointed by
1787 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
1789 ptid_t ptid
= * (ptid_t
*) arg
;
1791 if ((ptid_equal (info
->ptid
, ptid
)
1792 || ptid_equal (minus_one_ptid
, ptid
)
1793 || (ptid_is_pid (ptid
)
1794 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
1795 && is_running (info
->ptid
)
1796 && !is_executing (info
->ptid
))
1798 struct cleanup
*old_chain
;
1799 struct execution_control_state ecss
;
1800 struct execution_control_state
*ecs
= &ecss
;
1802 memset (ecs
, 0, sizeof (*ecs
));
1804 old_chain
= make_cleanup_restore_current_thread ();
1806 switch_to_thread (info
->ptid
);
1808 /* Go through handle_inferior_event/normal_stop, so we always
1809 have consistent output as if the stop event had been
1811 ecs
->ptid
= info
->ptid
;
1812 ecs
->event_thread
= find_thread_ptid (info
->ptid
);
1813 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1814 ecs
->ws
.value
.sig
= TARGET_SIGNAL_0
;
1816 handle_inferior_event (ecs
);
1818 if (!ecs
->wait_some_more
)
1820 struct thread_info
*tp
;
1824 /* Finish off the continuations. The continations
1825 themselves are responsible for realising the thread
1826 didn't finish what it was supposed to do. */
1827 tp
= inferior_thread ();
1828 do_all_intermediate_continuations_thread (tp
);
1829 do_all_continuations_thread (tp
);
1832 do_cleanups (old_chain
);
1838 /* This function is attached as a "thread_stop_requested" observer.
1839 Cleanup local state that assumed the PTID was to be resumed, and
1840 report the stop to the frontend. */
1843 infrun_thread_stop_requested (ptid_t ptid
)
1845 struct displaced_step_request
*it
, *next
, *prev
= NULL
;
1847 /* PTID was requested to stop. Remove it from the displaced
1848 stepping queue, so we don't try to resume it automatically. */
1849 for (it
= displaced_step_request_queue
; it
; it
= next
)
1853 if (ptid_equal (it
->ptid
, ptid
)
1854 || ptid_equal (minus_one_ptid
, ptid
)
1855 || (ptid_is_pid (ptid
)
1856 && ptid_get_pid (ptid
) == ptid_get_pid (it
->ptid
)))
1858 if (displaced_step_request_queue
== it
)
1859 displaced_step_request_queue
= it
->next
;
1861 prev
->next
= it
->next
;
1869 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
1873 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
1875 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
1876 nullify_last_target_wait_ptid ();
1879 /* Callback for iterate_over_threads. */
1882 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
1884 if (is_exited (info
->ptid
))
1887 delete_step_resume_breakpoint (info
);
1891 /* In all-stop, delete the step resume breakpoint of any thread that
1892 had one. In non-stop, delete the step resume breakpoint of the
1893 thread that just stopped. */
1896 delete_step_thread_step_resume_breakpoint (void)
1898 if (!target_has_execution
1899 || ptid_equal (inferior_ptid
, null_ptid
))
1900 /* If the inferior has exited, we have already deleted the step
1901 resume breakpoints out of GDB's lists. */
1906 /* If in non-stop mode, only delete the step-resume or
1907 longjmp-resume breakpoint of the thread that just stopped
1909 struct thread_info
*tp
= inferior_thread ();
1910 delete_step_resume_breakpoint (tp
);
1913 /* In all-stop mode, delete all step-resume and longjmp-resume
1914 breakpoints of any thread that had them. */
1915 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
1918 /* A cleanup wrapper. */
1921 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
1923 delete_step_thread_step_resume_breakpoint ();
1926 /* Pretty print the results of target_wait, for debugging purposes. */
1929 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
1930 const struct target_waitstatus
*ws
)
1932 char *status_string
= target_waitstatus_to_string (ws
);
1933 struct ui_file
*tmp_stream
= mem_fileopen ();
1937 /* The text is split over several lines because it was getting too long.
1938 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
1939 output as a unit; we want only one timestamp printed if debug_timestamp
1942 fprintf_unfiltered (tmp_stream
,
1943 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
1944 if (PIDGET (waiton_ptid
) != -1)
1945 fprintf_unfiltered (tmp_stream
,
1946 " [%s]", target_pid_to_str (waiton_ptid
));
1947 fprintf_unfiltered (tmp_stream
, ", status) =\n");
1948 fprintf_unfiltered (tmp_stream
,
1949 "infrun: %d [%s],\n",
1950 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
1951 fprintf_unfiltered (tmp_stream
,
1955 text
= ui_file_xstrdup (tmp_stream
, &len
);
1957 /* This uses %s in part to handle %'s in the text, but also to avoid
1958 a gcc error: the format attribute requires a string literal. */
1959 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
1961 xfree (status_string
);
1963 ui_file_delete (tmp_stream
);
1966 /* Wait for control to return from inferior to debugger.
1968 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1969 as if they were SIGTRAP signals. This can be useful during
1970 the startup sequence on some targets such as HP/UX, where
1971 we receive an EXEC event instead of the expected SIGTRAP.
1973 If inferior gets a signal, we may decide to start it up again
1974 instead of returning. That is why there is a loop in this function.
1975 When this function actually returns it means the inferior
1976 should be left stopped and GDB should read more commands. */
1979 wait_for_inferior (int treat_exec_as_sigtrap
)
1981 struct cleanup
*old_cleanups
;
1982 struct execution_control_state ecss
;
1983 struct execution_control_state
*ecs
;
1987 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1988 treat_exec_as_sigtrap
);
1991 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
1994 memset (ecs
, 0, sizeof (*ecs
));
1996 /* We'll update this if & when we switch to a new thread. */
1997 previous_inferior_ptid
= inferior_ptid
;
2001 struct cleanup
*old_chain
;
2003 /* We have to invalidate the registers BEFORE calling target_wait
2004 because they can be loaded from the target while in target_wait.
2005 This makes remote debugging a bit more efficient for those
2006 targets that provide critical registers as part of their normal
2007 status mechanism. */
2009 overlay_cache_invalid
= 1;
2010 registers_changed ();
2012 if (deprecated_target_wait_hook
)
2013 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, 0);
2015 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, 0);
2018 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2020 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
2022 xfree (ecs
->ws
.value
.execd_pathname
);
2023 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
2024 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
2027 /* If an error happens while handling the event, propagate GDB's
2028 knowledge of the executing state to the frontend/user running
2030 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2032 /* Now figure out what to do with the result of the result. */
2033 handle_inferior_event (ecs
);
2035 /* No error, don't finish the state yet. */
2036 discard_cleanups (old_chain
);
2038 if (!ecs
->wait_some_more
)
2042 do_cleanups (old_cleanups
);
2045 /* Asynchronous version of wait_for_inferior. It is called by the
2046 event loop whenever a change of state is detected on the file
2047 descriptor corresponding to the target. It can be called more than
2048 once to complete a single execution command. In such cases we need
2049 to keep the state in a global variable ECSS. If it is the last time
2050 that this function is called for a single execution command, then
2051 report to the user that the inferior has stopped, and do the
2052 necessary cleanups. */
2055 fetch_inferior_event (void *client_data
)
2057 struct execution_control_state ecss
;
2058 struct execution_control_state
*ecs
= &ecss
;
2059 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
2060 struct cleanup
*ts_old_chain
;
2061 int was_sync
= sync_execution
;
2063 memset (ecs
, 0, sizeof (*ecs
));
2065 /* We'll update this if & when we switch to a new thread. */
2066 previous_inferior_ptid
= inferior_ptid
;
2069 /* In non-stop mode, the user/frontend should not notice a thread
2070 switch due to internal events. Make sure we reverse to the
2071 user selected thread and frame after handling the event and
2072 running any breakpoint commands. */
2073 make_cleanup_restore_current_thread ();
2075 /* We have to invalidate the registers BEFORE calling target_wait
2076 because they can be loaded from the target while in target_wait.
2077 This makes remote debugging a bit more efficient for those
2078 targets that provide critical registers as part of their normal
2079 status mechanism. */
2081 overlay_cache_invalid
= 1;
2082 registers_changed ();
2084 if (deprecated_target_wait_hook
)
2086 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2088 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
, TARGET_WNOHANG
);
2091 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
2094 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
2095 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2096 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
2097 /* In non-stop mode, each thread is handled individually. Switch
2098 early, so the global state is set correctly for this
2100 context_switch (ecs
->ptid
);
2102 /* If an error happens while handling the event, propagate GDB's
2103 knowledge of the executing state to the frontend/user running
2106 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
2108 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
2110 /* Now figure out what to do with the result of the result. */
2111 handle_inferior_event (ecs
);
2113 if (!ecs
->wait_some_more
)
2115 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2117 delete_step_thread_step_resume_breakpoint ();
2119 /* We may not find an inferior if this was a process exit. */
2120 if (inf
== NULL
|| inf
->stop_soon
== NO_STOP_QUIETLY
)
2123 if (target_has_execution
2124 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2125 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2126 && ecs
->event_thread
->step_multi
2127 && ecs
->event_thread
->stop_step
)
2128 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
2130 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
2133 /* No error, don't finish the thread states yet. */
2134 discard_cleanups (ts_old_chain
);
2136 /* Revert thread and frame. */
2137 do_cleanups (old_chain
);
2139 /* If the inferior was in sync execution mode, and now isn't,
2140 restore the prompt. */
2141 if (was_sync
&& !sync_execution
)
2142 display_gdb_prompt (0);
2145 /* Record the frame and location we're currently stepping through. */
2147 set_step_info (struct frame_info
*frame
, struct symtab_and_line sal
)
2149 struct thread_info
*tp
= inferior_thread ();
2151 tp
->step_frame_id
= get_frame_id (frame
);
2152 tp
->step_stack_frame_id
= get_stack_frame_id (frame
);
2154 tp
->current_symtab
= sal
.symtab
;
2155 tp
->current_line
= sal
.line
;
2158 /* Prepare an execution control state for looping through a
2159 wait_for_inferior-type loop. */
2162 init_execution_control_state (struct execution_control_state
*ecs
)
2164 ecs
->random_signal
= 0;
2167 /* Clear context switchable stepping state. */
2170 init_thread_stepping_state (struct thread_info
*tss
)
2172 tss
->stepping_over_breakpoint
= 0;
2173 tss
->step_after_step_resume_breakpoint
= 0;
2174 tss
->stepping_through_solib_after_catch
= 0;
2175 tss
->stepping_through_solib_catchpoints
= NULL
;
2178 /* Return the cached copy of the last pid/waitstatus returned by
2179 target_wait()/deprecated_target_wait_hook(). The data is actually
2180 cached by handle_inferior_event(), which gets called immediately
2181 after target_wait()/deprecated_target_wait_hook(). */
2184 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2186 *ptidp
= target_last_wait_ptid
;
2187 *status
= target_last_waitstatus
;
2191 nullify_last_target_wait_ptid (void)
2193 target_last_wait_ptid
= minus_one_ptid
;
2196 /* Switch thread contexts. */
2199 context_switch (ptid_t ptid
)
2203 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2204 target_pid_to_str (inferior_ptid
));
2205 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2206 target_pid_to_str (ptid
));
2209 switch_to_thread (ptid
);
2213 adjust_pc_after_break (struct execution_control_state
*ecs
)
2215 struct regcache
*regcache
;
2216 struct gdbarch
*gdbarch
;
2217 CORE_ADDR breakpoint_pc
;
2219 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2220 we aren't, just return.
2222 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2223 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2224 implemented by software breakpoints should be handled through the normal
2227 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2228 different signals (SIGILL or SIGEMT for instance), but it is less
2229 clear where the PC is pointing afterwards. It may not match
2230 gdbarch_decr_pc_after_break. I don't know any specific target that
2231 generates these signals at breakpoints (the code has been in GDB since at
2232 least 1992) so I can not guess how to handle them here.
2234 In earlier versions of GDB, a target with
2235 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2236 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2237 target with both of these set in GDB history, and it seems unlikely to be
2238 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2240 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2243 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
2246 /* In reverse execution, when a breakpoint is hit, the instruction
2247 under it has already been de-executed. The reported PC always
2248 points at the breakpoint address, so adjusting it further would
2249 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2252 B1 0x08000000 : INSN1
2253 B2 0x08000001 : INSN2
2255 PC -> 0x08000003 : INSN4
2257 Say you're stopped at 0x08000003 as above. Reverse continuing
2258 from that point should hit B2 as below. Reading the PC when the
2259 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2260 been de-executed already.
2262 B1 0x08000000 : INSN1
2263 B2 PC -> 0x08000001 : INSN2
2267 We can't apply the same logic as for forward execution, because
2268 we would wrongly adjust the PC to 0x08000000, since there's a
2269 breakpoint at PC - 1. We'd then report a hit on B1, although
2270 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2272 if (execution_direction
== EXEC_REVERSE
)
2275 /* If this target does not decrement the PC after breakpoints, then
2276 we have nothing to do. */
2277 regcache
= get_thread_regcache (ecs
->ptid
);
2278 gdbarch
= get_regcache_arch (regcache
);
2279 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2282 /* Find the location where (if we've hit a breakpoint) the
2283 breakpoint would be. */
2284 breakpoint_pc
= regcache_read_pc (regcache
)
2285 - gdbarch_decr_pc_after_break (gdbarch
);
2287 /* Check whether there actually is a software breakpoint inserted at
2290 If in non-stop mode, a race condition is possible where we've
2291 removed a breakpoint, but stop events for that breakpoint were
2292 already queued and arrive later. To suppress those spurious
2293 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2294 and retire them after a number of stop events are reported. */
2295 if (software_breakpoint_inserted_here_p (breakpoint_pc
)
2296 || (non_stop
&& moribund_breakpoint_here_p (breakpoint_pc
)))
2298 struct cleanup
*old_cleanups
= NULL
;
2300 old_cleanups
= record_gdb_operation_disable_set ();
2302 /* When using hardware single-step, a SIGTRAP is reported for both
2303 a completed single-step and a software breakpoint. Need to
2304 differentiate between the two, as the latter needs adjusting
2305 but the former does not.
2307 The SIGTRAP can be due to a completed hardware single-step only if
2308 - we didn't insert software single-step breakpoints
2309 - the thread to be examined is still the current thread
2310 - this thread is currently being stepped
2312 If any of these events did not occur, we must have stopped due
2313 to hitting a software breakpoint, and have to back up to the
2316 As a special case, we could have hardware single-stepped a
2317 software breakpoint. In this case (prev_pc == breakpoint_pc),
2318 we also need to back up to the breakpoint address. */
2320 if (singlestep_breakpoints_inserted_p
2321 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
2322 || !currently_stepping (ecs
->event_thread
)
2323 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
2324 regcache_write_pc (regcache
, breakpoint_pc
);
2327 do_cleanups (old_cleanups
);
2332 init_infwait_state (void)
2334 waiton_ptid
= pid_to_ptid (-1);
2335 infwait_state
= infwait_normal_state
;
2339 error_is_running (void)
2342 Cannot execute this command while the selected thread is running."));
2346 ensure_not_running (void)
2348 if (is_running (inferior_ptid
))
2349 error_is_running ();
2353 stepped_in_from (struct frame_info
*frame
, struct frame_id step_frame_id
)
2355 for (frame
= get_prev_frame (frame
);
2357 frame
= get_prev_frame (frame
))
2359 if (frame_id_eq (get_frame_id (frame
), step_frame_id
))
2361 if (get_frame_type (frame
) != INLINE_FRAME
)
2368 /* Given an execution control state that has been freshly filled in
2369 by an event from the inferior, figure out what it means and take
2370 appropriate action. */
2373 handle_inferior_event (struct execution_control_state
*ecs
)
2375 struct frame_info
*frame
;
2376 struct gdbarch
*gdbarch
;
2377 int sw_single_step_trap_p
= 0;
2378 int stopped_by_watchpoint
;
2379 int stepped_after_stopped_by_watchpoint
= 0;
2380 struct symtab_and_line stop_pc_sal
;
2381 enum stop_kind stop_soon
;
2383 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2384 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2385 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
2387 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2389 stop_soon
= inf
->stop_soon
;
2392 stop_soon
= NO_STOP_QUIETLY
;
2394 /* Cache the last pid/waitstatus. */
2395 target_last_wait_ptid
= ecs
->ptid
;
2396 target_last_waitstatus
= ecs
->ws
;
2398 /* Always clear state belonging to the previous time we stopped. */
2399 stop_stack_dummy
= 0;
2401 /* If it's a new process, add it to the thread database */
2403 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
2404 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
2405 && !in_thread_list (ecs
->ptid
));
2407 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2408 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
2409 add_thread (ecs
->ptid
);
2411 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
2413 /* Dependent on valid ECS->EVENT_THREAD. */
2414 adjust_pc_after_break (ecs
);
2416 /* Dependent on the current PC value modified by adjust_pc_after_break. */
2417 reinit_frame_cache ();
2419 if (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
2421 breakpoint_retire_moribund ();
2423 /* Mark the non-executing threads accordingly. In all-stop, all
2424 threads of all processes are stopped when we get any event
2425 reported. In non-stop mode, only the event thread stops. If
2426 we're handling a process exit in non-stop mode, there's
2427 nothing to do, as threads of the dead process are gone, and
2428 threads of any other process were left running. */
2430 set_executing (minus_one_ptid
, 0);
2431 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2432 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
2433 set_executing (inferior_ptid
, 0);
2436 switch (infwait_state
)
2438 case infwait_thread_hop_state
:
2440 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
2443 case infwait_normal_state
:
2445 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
2448 case infwait_step_watch_state
:
2450 fprintf_unfiltered (gdb_stdlog
,
2451 "infrun: infwait_step_watch_state\n");
2453 stepped_after_stopped_by_watchpoint
= 1;
2456 case infwait_nonstep_watch_state
:
2458 fprintf_unfiltered (gdb_stdlog
,
2459 "infrun: infwait_nonstep_watch_state\n");
2460 insert_breakpoints ();
2462 /* FIXME-maybe: is this cleaner than setting a flag? Does it
2463 handle things like signals arriving and other things happening
2464 in combination correctly? */
2465 stepped_after_stopped_by_watchpoint
= 1;
2469 internal_error (__FILE__
, __LINE__
, _("bad switch"));
2472 infwait_state
= infwait_normal_state
;
2473 waiton_ptid
= pid_to_ptid (-1);
2475 switch (ecs
->ws
.kind
)
2477 case TARGET_WAITKIND_LOADED
:
2479 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
2480 /* Ignore gracefully during startup of the inferior, as it might
2481 be the shell which has just loaded some objects, otherwise
2482 add the symbols for the newly loaded objects. Also ignore at
2483 the beginning of an attach or remote session; we will query
2484 the full list of libraries once the connection is
2486 if (stop_soon
== NO_STOP_QUIETLY
)
2488 /* Check for any newly added shared libraries if we're
2489 supposed to be adding them automatically. Switch
2490 terminal for any messages produced by
2491 breakpoint_re_set. */
2492 target_terminal_ours_for_output ();
2493 /* NOTE: cagney/2003-11-25: Make certain that the target
2494 stack's section table is kept up-to-date. Architectures,
2495 (e.g., PPC64), use the section table to perform
2496 operations such as address => section name and hence
2497 require the table to contain all sections (including
2498 those found in shared libraries). */
2500 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2502 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2504 target_terminal_inferior ();
2506 /* If requested, stop when the dynamic linker notifies
2507 gdb of events. This allows the user to get control
2508 and place breakpoints in initializer routines for
2509 dynamically loaded objects (among other things). */
2510 if (stop_on_solib_events
)
2512 stop_stepping (ecs
);
2516 /* NOTE drow/2007-05-11: This might be a good place to check
2517 for "catch load". */
2520 /* If we are skipping through a shell, or through shared library
2521 loading that we aren't interested in, resume the program. If
2522 we're running the program normally, also resume. But stop if
2523 we're attaching or setting up a remote connection. */
2524 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
2526 /* Loading of shared libraries might have changed breakpoint
2527 addresses. Make sure new breakpoints are inserted. */
2528 if (stop_soon
== NO_STOP_QUIETLY
2529 && !breakpoints_always_inserted_mode ())
2530 insert_breakpoints ();
2531 resume (0, TARGET_SIGNAL_0
);
2532 prepare_to_wait (ecs
);
2538 case TARGET_WAITKIND_SPURIOUS
:
2540 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
2541 resume (0, TARGET_SIGNAL_0
);
2542 prepare_to_wait (ecs
);
2545 case TARGET_WAITKIND_EXITED
:
2547 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
2548 inferior_ptid
= ecs
->ptid
;
2549 target_terminal_ours (); /* Must do this before mourn anyway */
2550 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
2552 /* Record the exit code in the convenience variable $_exitcode, so
2553 that the user can inspect this again later. */
2554 set_internalvar_integer (lookup_internalvar ("_exitcode"),
2555 (LONGEST
) ecs
->ws
.value
.integer
);
2556 gdb_flush (gdb_stdout
);
2557 target_mourn_inferior ();
2558 singlestep_breakpoints_inserted_p
= 0;
2559 stop_print_frame
= 0;
2560 stop_stepping (ecs
);
2563 case TARGET_WAITKIND_SIGNALLED
:
2565 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2566 inferior_ptid
= ecs
->ptid
;
2567 stop_print_frame
= 0;
2568 target_terminal_ours (); /* Must do this before mourn anyway */
2570 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
2571 reach here unless the inferior is dead. However, for years
2572 target_kill() was called here, which hints that fatal signals aren't
2573 really fatal on some systems. If that's true, then some changes
2575 target_mourn_inferior ();
2577 print_stop_reason (SIGNAL_EXITED
, ecs
->ws
.value
.sig
);
2578 singlestep_breakpoints_inserted_p
= 0;
2579 stop_stepping (ecs
);
2582 /* The following are the only cases in which we keep going;
2583 the above cases end in a continue or goto. */
2584 case TARGET_WAITKIND_FORKED
:
2585 case TARGET_WAITKIND_VFORKED
:
2587 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
2589 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2591 context_switch (ecs
->ptid
);
2592 reinit_frame_cache ();
2595 /* Immediately detach breakpoints from the child before there's
2596 any chance of letting the user delete breakpoints from the
2597 breakpoint lists. If we don't do this early, it's easy to
2598 leave left over traps in the child, vis: "break foo; catch
2599 fork; c; <fork>; del; c; <child calls foo>". We only follow
2600 the fork on the last `continue', and by that time the
2601 breakpoint at "foo" is long gone from the breakpoint table.
2602 If we vforked, then we don't need to unpatch here, since both
2603 parent and child are sharing the same memory pages; we'll
2604 need to unpatch at follow/detach time instead to be certain
2605 that new breakpoints added between catchpoint hit time and
2606 vfork follow are detached. */
2607 if (ecs
->ws
.kind
!= TARGET_WAITKIND_VFORKED
)
2609 int child_pid
= ptid_get_pid (ecs
->ws
.value
.related_pid
);
2611 /* This won't actually modify the breakpoint list, but will
2612 physically remove the breakpoints from the child. */
2613 detach_breakpoints (child_pid
);
2616 /* In case the event is caught by a catchpoint, remember that
2617 the event is to be followed at the next resume of the thread,
2618 and not immediately. */
2619 ecs
->event_thread
->pending_follow
= ecs
->ws
;
2621 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2623 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2625 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2627 /* If no catchpoint triggered for this, then keep going. */
2628 if (ecs
->random_signal
)
2632 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2634 should_resume
= follow_fork ();
2636 ecs
->event_thread
= inferior_thread ();
2637 ecs
->ptid
= inferior_ptid
;
2642 stop_stepping (ecs
);
2645 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2646 goto process_event_stop_test
;
2648 case TARGET_WAITKIND_EXECD
:
2650 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
2652 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2654 context_switch (ecs
->ptid
);
2655 reinit_frame_cache ();
2658 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2660 /* This causes the eventpoints and symbol table to be reset.
2661 Must do this now, before trying to determine whether to
2663 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
2665 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2666 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2668 /* Note that this may be referenced from inside
2669 bpstat_stop_status above, through inferior_has_execd. */
2670 xfree (ecs
->ws
.value
.execd_pathname
);
2671 ecs
->ws
.value
.execd_pathname
= NULL
;
2673 /* If no catchpoint triggered for this, then keep going. */
2674 if (ecs
->random_signal
)
2676 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2680 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2681 goto process_event_stop_test
;
2683 /* Be careful not to try to gather much state about a thread
2684 that's in a syscall. It's frequently a losing proposition. */
2685 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2687 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2688 resume (0, TARGET_SIGNAL_0
);
2689 prepare_to_wait (ecs
);
2692 /* Before examining the threads further, step this thread to
2693 get it entirely out of the syscall. (We get notice of the
2694 event when the thread is just on the verge of exiting a
2695 syscall. Stepping one instruction seems to get it back
2697 case TARGET_WAITKIND_SYSCALL_RETURN
:
2699 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2700 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2701 prepare_to_wait (ecs
);
2704 case TARGET_WAITKIND_STOPPED
:
2706 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
2707 ecs
->event_thread
->stop_signal
= ecs
->ws
.value
.sig
;
2710 case TARGET_WAITKIND_NO_HISTORY
:
2711 /* Reverse execution: target ran out of history info. */
2712 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2713 print_stop_reason (NO_HISTORY
, 0);
2714 stop_stepping (ecs
);
2717 /* We had an event in the inferior, but we are not interested
2718 in handling it at this level. The lower layers have already
2719 done what needs to be done, if anything.
2721 One of the possible circumstances for this is when the
2722 inferior produces output for the console. The inferior has
2723 not stopped, and we are ignoring the event. Another possible
2724 circumstance is any event which the lower level knows will be
2725 reported multiple times without an intervening resume. */
2726 case TARGET_WAITKIND_IGNORE
:
2728 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2729 prepare_to_wait (ecs
);
2733 if (ecs
->new_thread_event
)
2736 /* Non-stop assumes that the target handles adding new threads
2737 to the thread list. */
2738 internal_error (__FILE__
, __LINE__
, "\
2739 targets should add new threads to the thread list themselves in non-stop mode.");
2741 /* We may want to consider not doing a resume here in order to
2742 give the user a chance to play with the new thread. It might
2743 be good to make that a user-settable option. */
2745 /* At this point, all threads are stopped (happens automatically
2746 in either the OS or the native code). Therefore we need to
2747 continue all threads in order to make progress. */
2749 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2750 context_switch (ecs
->ptid
);
2751 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
2752 prepare_to_wait (ecs
);
2756 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
2758 /* Do we need to clean up the state of a thread that has
2759 completed a displaced single-step? (Doing so usually affects
2760 the PC, so do it here, before we set stop_pc.) */
2761 displaced_step_fixup (ecs
->ptid
, ecs
->event_thread
->stop_signal
);
2763 /* If we either finished a single-step or hit a breakpoint, but
2764 the user wanted this thread to be stopped, pretend we got a
2765 SIG0 (generic unsignaled stop). */
2767 if (ecs
->event_thread
->stop_requested
2768 && ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2769 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2772 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2776 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
2777 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
2779 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = %s\n",
2780 paddress (gdbarch
, stop_pc
));
2781 if (target_stopped_by_watchpoint ())
2784 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2786 if (target_stopped_data_address (¤t_target
, &addr
))
2787 fprintf_unfiltered (gdb_stdlog
,
2788 "infrun: stopped data address = %s\n",
2789 paddress (gdbarch
, addr
));
2791 fprintf_unfiltered (gdb_stdlog
,
2792 "infrun: (no data address available)\n");
2796 if (stepping_past_singlestep_breakpoint
)
2798 gdb_assert (singlestep_breakpoints_inserted_p
);
2799 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2800 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2802 stepping_past_singlestep_breakpoint
= 0;
2804 /* We've either finished single-stepping past the single-step
2805 breakpoint, or stopped for some other reason. It would be nice if
2806 we could tell, but we can't reliably. */
2807 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2810 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2811 /* Pull the single step breakpoints out of the target. */
2812 remove_single_step_breakpoints ();
2813 singlestep_breakpoints_inserted_p
= 0;
2815 ecs
->random_signal
= 0;
2817 context_switch (saved_singlestep_ptid
);
2818 if (deprecated_context_hook
)
2819 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2821 resume (1, TARGET_SIGNAL_0
);
2822 prepare_to_wait (ecs
);
2827 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2829 /* In non-stop mode, there's never a deferred_step_ptid set. */
2830 gdb_assert (!non_stop
);
2832 /* If we stopped for some other reason than single-stepping, ignore
2833 the fact that we were supposed to switch back. */
2834 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2837 fprintf_unfiltered (gdb_stdlog
,
2838 "infrun: handling deferred step\n");
2840 /* Pull the single step breakpoints out of the target. */
2841 if (singlestep_breakpoints_inserted_p
)
2843 remove_single_step_breakpoints ();
2844 singlestep_breakpoints_inserted_p
= 0;
2847 /* Note: We do not call context_switch at this point, as the
2848 context is already set up for stepping the original thread. */
2849 switch_to_thread (deferred_step_ptid
);
2850 deferred_step_ptid
= null_ptid
;
2851 /* Suppress spurious "Switching to ..." message. */
2852 previous_inferior_ptid
= inferior_ptid
;
2854 resume (1, TARGET_SIGNAL_0
);
2855 prepare_to_wait (ecs
);
2859 deferred_step_ptid
= null_ptid
;
2862 /* See if a thread hit a thread-specific breakpoint that was meant for
2863 another thread. If so, then step that thread past the breakpoint,
2866 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2868 int thread_hop_needed
= 0;
2870 /* Check if a regular breakpoint has been hit before checking
2871 for a potential single step breakpoint. Otherwise, GDB will
2872 not see this breakpoint hit when stepping onto breakpoints. */
2873 if (regular_breakpoint_inserted_here_p (stop_pc
))
2875 ecs
->random_signal
= 0;
2876 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2877 thread_hop_needed
= 1;
2879 else if (singlestep_breakpoints_inserted_p
)
2881 /* We have not context switched yet, so this should be true
2882 no matter which thread hit the singlestep breakpoint. */
2883 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2885 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2887 target_pid_to_str (ecs
->ptid
));
2889 ecs
->random_signal
= 0;
2890 /* The call to in_thread_list is necessary because PTIDs sometimes
2891 change when we go from single-threaded to multi-threaded. If
2892 the singlestep_ptid is still in the list, assume that it is
2893 really different from ecs->ptid. */
2894 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2895 && in_thread_list (singlestep_ptid
))
2897 /* If the PC of the thread we were trying to single-step
2898 has changed, discard this event (which we were going
2899 to ignore anyway), and pretend we saw that thread
2900 trap. This prevents us continuously moving the
2901 single-step breakpoint forward, one instruction at a
2902 time. If the PC has changed, then the thread we were
2903 trying to single-step has trapped or been signalled,
2904 but the event has not been reported to GDB yet.
2906 There might be some cases where this loses signal
2907 information, if a signal has arrived at exactly the
2908 same time that the PC changed, but this is the best
2909 we can do with the information available. Perhaps we
2910 should arrange to report all events for all threads
2911 when they stop, or to re-poll the remote looking for
2912 this particular thread (i.e. temporarily enable
2915 CORE_ADDR new_singlestep_pc
2916 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
2918 if (new_singlestep_pc
!= singlestep_pc
)
2920 enum target_signal stop_signal
;
2923 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2924 " but expected thread advanced also\n");
2926 /* The current context still belongs to
2927 singlestep_ptid. Don't swap here, since that's
2928 the context we want to use. Just fudge our
2929 state and continue. */
2930 stop_signal
= ecs
->event_thread
->stop_signal
;
2931 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2932 ecs
->ptid
= singlestep_ptid
;
2933 ecs
->event_thread
= find_thread_ptid (ecs
->ptid
);
2934 ecs
->event_thread
->stop_signal
= stop_signal
;
2935 stop_pc
= new_singlestep_pc
;
2940 fprintf_unfiltered (gdb_stdlog
,
2941 "infrun: unexpected thread\n");
2943 thread_hop_needed
= 1;
2944 stepping_past_singlestep_breakpoint
= 1;
2945 saved_singlestep_ptid
= singlestep_ptid
;
2950 if (thread_hop_needed
)
2952 struct regcache
*thread_regcache
;
2953 int remove_status
= 0;
2956 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2958 /* Switch context before touching inferior memory, the
2959 previous thread may have exited. */
2960 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2961 context_switch (ecs
->ptid
);
2963 /* Saw a breakpoint, but it was hit by the wrong thread.
2966 if (singlestep_breakpoints_inserted_p
)
2968 /* Pull the single step breakpoints out of the target. */
2969 remove_single_step_breakpoints ();
2970 singlestep_breakpoints_inserted_p
= 0;
2973 /* If the arch can displace step, don't remove the
2975 thread_regcache
= get_thread_regcache (ecs
->ptid
);
2976 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
2977 remove_status
= remove_breakpoints ();
2979 /* Did we fail to remove breakpoints? If so, try
2980 to set the PC past the bp. (There's at least
2981 one situation in which we can fail to remove
2982 the bp's: On HP-UX's that use ttrace, we can't
2983 change the address space of a vforking child
2984 process until the child exits (well, okay, not
2985 then either :-) or execs. */
2986 if (remove_status
!= 0)
2987 error (_("Cannot step over breakpoint hit in wrong thread"));
2992 /* Only need to require the next event from this
2993 thread in all-stop mode. */
2994 waiton_ptid
= ecs
->ptid
;
2995 infwait_state
= infwait_thread_hop_state
;
2998 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3003 else if (singlestep_breakpoints_inserted_p
)
3005 sw_single_step_trap_p
= 1;
3006 ecs
->random_signal
= 0;
3010 ecs
->random_signal
= 1;
3012 /* See if something interesting happened to the non-current thread. If
3013 so, then switch to that thread. */
3014 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
3017 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
3019 context_switch (ecs
->ptid
);
3021 if (deprecated_context_hook
)
3022 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
3025 /* At this point, get hold of the now-current thread's frame. */
3026 frame
= get_current_frame ();
3027 gdbarch
= get_frame_arch (frame
);
3029 if (singlestep_breakpoints_inserted_p
)
3031 /* Pull the single step breakpoints out of the target. */
3032 remove_single_step_breakpoints ();
3033 singlestep_breakpoints_inserted_p
= 0;
3036 if (stepped_after_stopped_by_watchpoint
)
3037 stopped_by_watchpoint
= 0;
3039 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
3041 /* If necessary, step over this watchpoint. We'll be back to display
3043 if (stopped_by_watchpoint
3044 && (target_have_steppable_watchpoint
3045 || gdbarch_have_nonsteppable_watchpoint (gdbarch
)))
3047 /* At this point, we are stopped at an instruction which has
3048 attempted to write to a piece of memory under control of
3049 a watchpoint. The instruction hasn't actually executed
3050 yet. If we were to evaluate the watchpoint expression
3051 now, we would get the old value, and therefore no change
3052 would seem to have occurred.
3054 In order to make watchpoints work `right', we really need
3055 to complete the memory write, and then evaluate the
3056 watchpoint expression. We do this by single-stepping the
3059 It may not be necessary to disable the watchpoint to stop over
3060 it. For example, the PA can (with some kernel cooperation)
3061 single step over a watchpoint without disabling the watchpoint.
3063 It is far more common to need to disable a watchpoint to step
3064 the inferior over it. If we have non-steppable watchpoints,
3065 we must disable the current watchpoint; it's simplest to
3066 disable all watchpoints and breakpoints. */
3069 if (!target_have_steppable_watchpoint
)
3070 remove_breakpoints ();
3072 hw_step
= maybe_software_singlestep (gdbarch
, stop_pc
);
3073 target_resume (ecs
->ptid
, hw_step
, TARGET_SIGNAL_0
);
3074 waiton_ptid
= ecs
->ptid
;
3075 if (target_have_steppable_watchpoint
)
3076 infwait_state
= infwait_step_watch_state
;
3078 infwait_state
= infwait_nonstep_watch_state
;
3079 prepare_to_wait (ecs
);
3083 ecs
->stop_func_start
= 0;
3084 ecs
->stop_func_end
= 0;
3085 ecs
->stop_func_name
= 0;
3086 /* Don't care about return value; stop_func_start and stop_func_name
3087 will both be 0 if it doesn't work. */
3088 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
3089 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
3090 ecs
->stop_func_start
3091 += gdbarch_deprecated_function_start_offset (gdbarch
);
3092 ecs
->event_thread
->stepping_over_breakpoint
= 0;
3093 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
3094 ecs
->event_thread
->stop_step
= 0;
3095 stop_print_frame
= 1;
3096 ecs
->random_signal
= 0;
3097 stopped_by_random_signal
= 0;
3099 /* Hide inlined functions starting here, unless we just performed stepi or
3100 nexti. After stepi and nexti, always show the innermost frame (not any
3101 inline function call sites). */
3102 if (ecs
->event_thread
->step_range_end
!= 1)
3103 skip_inline_frames (ecs
->ptid
);
3105 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3106 && ecs
->event_thread
->trap_expected
3107 && gdbarch_single_step_through_delay_p (gdbarch
)
3108 && currently_stepping (ecs
->event_thread
))
3110 /* We're trying to step off a breakpoint. Turns out that we're
3111 also on an instruction that needs to be stepped multiple
3112 times before it's been fully executing. E.g., architectures
3113 with a delay slot. It needs to be stepped twice, once for
3114 the instruction and once for the delay slot. */
3115 int step_through_delay
3116 = gdbarch_single_step_through_delay (gdbarch
, frame
);
3117 if (debug_infrun
&& step_through_delay
)
3118 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
3119 if (ecs
->event_thread
->step_range_end
== 0 && step_through_delay
)
3121 /* The user issued a continue when stopped at a breakpoint.
3122 Set up for another trap and get out of here. */
3123 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3127 else if (step_through_delay
)
3129 /* The user issued a step when stopped at a breakpoint.
3130 Maybe we should stop, maybe we should not - the delay
3131 slot *might* correspond to a line of source. In any
3132 case, don't decide that here, just set
3133 ecs->stepping_over_breakpoint, making sure we
3134 single-step again before breakpoints are re-inserted. */
3135 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3139 /* Look at the cause of the stop, and decide what to do.
3140 The alternatives are:
3141 1) stop_stepping and return; to really stop and return to the debugger,
3142 2) keep_going and return to start up again
3143 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3144 3) set ecs->random_signal to 1, and the decision between 1 and 2
3145 will be made according to the signal handling tables. */
3147 /* First, distinguish signals caused by the debugger from signals
3148 that have to do with the program's own actions. Note that
3149 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3150 on the operating system version. Here we detect when a SIGILL or
3151 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3152 something similar for SIGSEGV, since a SIGSEGV will be generated
3153 when we're trying to execute a breakpoint instruction on a
3154 non-executable stack. This happens for call dummy breakpoints
3155 for architectures like SPARC that place call dummies on the
3158 If we're doing a displaced step past a breakpoint, then the
3159 breakpoint is always inserted at the original instruction;
3160 non-standard signals can't be explained by the breakpoint. */
3161 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3162 || (! ecs
->event_thread
->trap_expected
3163 && breakpoint_inserted_here_p (stop_pc
)
3164 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_ILL
3165 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_SEGV
3166 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_EMT
))
3167 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3168 || stop_soon
== STOP_QUIETLY_REMOTE
)
3170 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
3173 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
3174 stop_print_frame
= 0;
3175 stop_stepping (ecs
);
3179 /* This is originated from start_remote(), start_inferior() and
3180 shared libraries hook functions. */
3181 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
3184 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
3185 stop_stepping (ecs
);
3189 /* This originates from attach_command(). We need to overwrite
3190 the stop_signal here, because some kernels don't ignore a
3191 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
3192 See more comments in inferior.h. On the other hand, if we
3193 get a non-SIGSTOP, report it to the user - assume the backend
3194 will handle the SIGSTOP if it should show up later.
3196 Also consider that the attach is complete when we see a
3197 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
3198 target extended-remote report it instead of a SIGSTOP
3199 (e.g. gdbserver). We already rely on SIGTRAP being our
3200 signal, so this is no exception.
3202 Also consider that the attach is complete when we see a
3203 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
3204 the target to stop all threads of the inferior, in case the
3205 low level attach operation doesn't stop them implicitly. If
3206 they weren't stopped implicitly, then the stub will report a
3207 TARGET_SIGNAL_0, meaning: stopped for no particular reason
3208 other than GDB's request. */
3209 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
3210 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_STOP
3211 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
3212 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_0
))
3214 stop_stepping (ecs
);
3215 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3219 /* See if there is a breakpoint at the current PC. */
3220 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
3222 /* Following in case break condition called a
3224 stop_print_frame
= 1;
3226 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3227 at one stage in the past included checks for an inferior
3228 function call's call dummy's return breakpoint. The original
3229 comment, that went with the test, read:
3231 ``End of a stack dummy. Some systems (e.g. Sony news) give
3232 another signal besides SIGTRAP, so check here as well as
3235 If someone ever tries to get call dummys on a
3236 non-executable stack to work (where the target would stop
3237 with something like a SIGSEGV), then those tests might need
3238 to be re-instated. Given, however, that the tests were only
3239 enabled when momentary breakpoints were not being used, I
3240 suspect that it won't be the case.
3242 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3243 be necessary for call dummies on a non-executable stack on
3246 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3248 = !(bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
)
3249 || ecs
->event_thread
->trap_expected
3250 || (ecs
->event_thread
->step_range_end
3251 && ecs
->event_thread
->step_resume_breakpoint
== NULL
));
3254 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
3255 if (!ecs
->random_signal
)
3256 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3260 /* When we reach this point, we've pretty much decided
3261 that the reason for stopping must've been a random
3262 (unexpected) signal. */
3265 ecs
->random_signal
= 1;
3267 process_event_stop_test
:
3269 /* Re-fetch current thread's frame in case we did a
3270 "goto process_event_stop_test" above. */
3271 frame
= get_current_frame ();
3272 gdbarch
= get_frame_arch (frame
);
3274 /* For the program's own signals, act according to
3275 the signal handling tables. */
3277 if (ecs
->random_signal
)
3279 /* Signal not for debugging purposes. */
3283 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
3284 ecs
->event_thread
->stop_signal
);
3286 stopped_by_random_signal
= 1;
3288 if (signal_print
[ecs
->event_thread
->stop_signal
])
3291 target_terminal_ours_for_output ();
3292 print_stop_reason (SIGNAL_RECEIVED
, ecs
->event_thread
->stop_signal
);
3294 /* Always stop on signals if we're either just gaining control
3295 of the program, or the user explicitly requested this thread
3296 to remain stopped. */
3297 if (stop_soon
!= NO_STOP_QUIETLY
3298 || ecs
->event_thread
->stop_requested
3299 || signal_stop_state (ecs
->event_thread
->stop_signal
))
3301 stop_stepping (ecs
);
3304 /* If not going to stop, give terminal back
3305 if we took it away. */
3307 target_terminal_inferior ();
3309 /* Clear the signal if it should not be passed. */
3310 if (signal_program
[ecs
->event_thread
->stop_signal
] == 0)
3311 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3313 if (ecs
->event_thread
->prev_pc
== stop_pc
3314 && ecs
->event_thread
->trap_expected
3315 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3317 /* We were just starting a new sequence, attempting to
3318 single-step off of a breakpoint and expecting a SIGTRAP.
3319 Instead this signal arrives. This signal will take us out
3320 of the stepping range so GDB needs to remember to, when
3321 the signal handler returns, resume stepping off that
3323 /* To simplify things, "continue" is forced to use the same
3324 code paths as single-step - set a breakpoint at the
3325 signal return address and then, once hit, step off that
3328 fprintf_unfiltered (gdb_stdlog
,
3329 "infrun: signal arrived while stepping over "
3332 insert_step_resume_breakpoint_at_frame (frame
);
3333 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
3338 if (ecs
->event_thread
->step_range_end
!= 0
3339 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_0
3340 && (ecs
->event_thread
->step_range_start
<= stop_pc
3341 && stop_pc
< ecs
->event_thread
->step_range_end
)
3342 && frame_id_eq (get_stack_frame_id (frame
),
3343 ecs
->event_thread
->step_stack_frame_id
)
3344 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3346 /* The inferior is about to take a signal that will take it
3347 out of the single step range. Set a breakpoint at the
3348 current PC (which is presumably where the signal handler
3349 will eventually return) and then allow the inferior to
3352 Note that this is only needed for a signal delivered
3353 while in the single-step range. Nested signals aren't a
3354 problem as they eventually all return. */
3356 fprintf_unfiltered (gdb_stdlog
,
3357 "infrun: signal may take us out of "
3358 "single-step range\n");
3360 insert_step_resume_breakpoint_at_frame (frame
);
3365 /* Note: step_resume_breakpoint may be non-NULL. This occures
3366 when either there's a nested signal, or when there's a
3367 pending signal enabled just as the signal handler returns
3368 (leaving the inferior at the step-resume-breakpoint without
3369 actually executing it). Either way continue until the
3370 breakpoint is really hit. */
3375 /* Handle cases caused by hitting a breakpoint. */
3377 CORE_ADDR jmp_buf_pc
;
3378 struct bpstat_what what
;
3380 what
= bpstat_what (ecs
->event_thread
->stop_bpstat
);
3382 if (what
.call_dummy
)
3384 stop_stack_dummy
= 1;
3387 switch (what
.main_action
)
3389 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
3390 /* If we hit the breakpoint at longjmp while stepping, we
3391 install a momentary breakpoint at the target of the
3395 fprintf_unfiltered (gdb_stdlog
,
3396 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
3398 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3400 if (!gdbarch_get_longjmp_target_p (gdbarch
)
3401 || !gdbarch_get_longjmp_target (gdbarch
, frame
, &jmp_buf_pc
))
3404 fprintf_unfiltered (gdb_stdlog
, "\
3405 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
3410 /* We're going to replace the current step-resume breakpoint
3411 with a longjmp-resume breakpoint. */
3412 delete_step_resume_breakpoint (ecs
->event_thread
);
3414 /* Insert a breakpoint at resume address. */
3415 insert_longjmp_resume_breakpoint (gdbarch
, jmp_buf_pc
);
3420 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
3422 fprintf_unfiltered (gdb_stdlog
,
3423 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
3425 gdb_assert (ecs
->event_thread
->step_resume_breakpoint
!= NULL
);
3426 delete_step_resume_breakpoint (ecs
->event_thread
);
3428 ecs
->event_thread
->stop_step
= 1;
3429 print_stop_reason (END_STEPPING_RANGE
, 0);
3430 stop_stepping (ecs
);
3433 case BPSTAT_WHAT_SINGLE
:
3435 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
3436 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3437 /* Still need to check other stuff, at least the case
3438 where we are stepping and step out of the right range. */
3441 case BPSTAT_WHAT_STOP_NOISY
:
3443 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
3444 stop_print_frame
= 1;
3446 /* We are about to nuke the step_resume_breakpointt via the
3447 cleanup chain, so no need to worry about it here. */
3449 stop_stepping (ecs
);
3452 case BPSTAT_WHAT_STOP_SILENT
:
3454 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
3455 stop_print_frame
= 0;
3457 /* We are about to nuke the step_resume_breakpoin via the
3458 cleanup chain, so no need to worry about it here. */
3460 stop_stepping (ecs
);
3463 case BPSTAT_WHAT_STEP_RESUME
:
3465 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
3467 delete_step_resume_breakpoint (ecs
->event_thread
);
3468 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
3470 /* Back when the step-resume breakpoint was inserted, we
3471 were trying to single-step off a breakpoint. Go back
3473 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
3474 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3478 if (stop_pc
== ecs
->stop_func_start
3479 && execution_direction
== EXEC_REVERSE
)
3481 /* We are stepping over a function call in reverse, and
3482 just hit the step-resume breakpoint at the start
3483 address of the function. Go back to single-stepping,
3484 which should take us back to the function call. */
3485 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3491 case BPSTAT_WHAT_CHECK_SHLIBS
:
3494 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
3496 /* Check for any newly added shared libraries if we're
3497 supposed to be adding them automatically. Switch
3498 terminal for any messages produced by
3499 breakpoint_re_set. */
3500 target_terminal_ours_for_output ();
3501 /* NOTE: cagney/2003-11-25: Make certain that the target
3502 stack's section table is kept up-to-date. Architectures,
3503 (e.g., PPC64), use the section table to perform
3504 operations such as address => section name and hence
3505 require the table to contain all sections (including
3506 those found in shared libraries). */
3508 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
3510 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
3512 target_terminal_inferior ();
3514 /* If requested, stop when the dynamic linker notifies
3515 gdb of events. This allows the user to get control
3516 and place breakpoints in initializer routines for
3517 dynamically loaded objects (among other things). */
3518 if (stop_on_solib_events
|| stop_stack_dummy
)
3520 stop_stepping (ecs
);
3525 /* We want to step over this breakpoint, then keep going. */
3526 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3532 case BPSTAT_WHAT_LAST
:
3533 /* Not a real code, but listed here to shut up gcc -Wall. */
3535 case BPSTAT_WHAT_KEEP_CHECKING
:
3540 /* We come here if we hit a breakpoint but should not
3541 stop for it. Possibly we also were stepping
3542 and should stop for that. So fall through and
3543 test for stepping. But, if not stepping,
3546 /* In all-stop mode, if we're currently stepping but have stopped in
3547 some other thread, we need to switch back to the stepped thread. */
3550 struct thread_info
*tp
;
3551 tp
= iterate_over_threads (currently_stepping_or_nexting_callback
,
3555 /* However, if the current thread is blocked on some internal
3556 breakpoint, and we simply need to step over that breakpoint
3557 to get it going again, do that first. */
3558 if ((ecs
->event_thread
->trap_expected
3559 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
3560 || ecs
->event_thread
->stepping_over_breakpoint
)
3566 /* If the stepping thread exited, then don't try to switch
3567 back and resume it, which could fail in several different
3568 ways depending on the target. Instead, just keep going.
3570 We can find a stepping dead thread in the thread list in
3573 - The target supports thread exit events, and when the
3574 target tries to delete the thread from the thread list,
3575 inferior_ptid pointed at the exiting thread. In such
3576 case, calling delete_thread does not really remove the
3577 thread from the list; instead, the thread is left listed,
3578 with 'exited' state.
3580 - The target's debug interface does not support thread
3581 exit events, and so we have no idea whatsoever if the
3582 previously stepping thread is still alive. For that
3583 reason, we need to synchronously query the target
3585 if (is_exited (tp
->ptid
)
3586 || !target_thread_alive (tp
->ptid
))
3589 fprintf_unfiltered (gdb_stdlog
, "\
3590 infrun: not switching back to stepped thread, it has vanished\n");
3592 delete_thread (tp
->ptid
);
3597 /* Otherwise, we no longer expect a trap in the current thread.
3598 Clear the trap_expected flag before switching back -- this is
3599 what keep_going would do as well, if we called it. */
3600 ecs
->event_thread
->trap_expected
= 0;
3603 fprintf_unfiltered (gdb_stdlog
,
3604 "infrun: switching back to stepped thread\n");
3606 ecs
->event_thread
= tp
;
3607 ecs
->ptid
= tp
->ptid
;
3608 context_switch (ecs
->ptid
);
3614 /* Are we stepping to get the inferior out of the dynamic linker's
3615 hook (and possibly the dld itself) after catching a shlib
3617 if (ecs
->event_thread
->stepping_through_solib_after_catch
)
3619 #if defined(SOLIB_ADD)
3620 /* Have we reached our destination? If not, keep going. */
3621 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
3624 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
3625 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3631 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
3632 /* Else, stop and report the catchpoint(s) whose triggering
3633 caused us to begin stepping. */
3634 ecs
->event_thread
->stepping_through_solib_after_catch
= 0;
3635 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
3636 ecs
->event_thread
->stop_bpstat
3637 = bpstat_copy (ecs
->event_thread
->stepping_through_solib_catchpoints
);
3638 bpstat_clear (&ecs
->event_thread
->stepping_through_solib_catchpoints
);
3639 stop_print_frame
= 1;
3640 stop_stepping (ecs
);
3644 if (ecs
->event_thread
->step_resume_breakpoint
)
3647 fprintf_unfiltered (gdb_stdlog
,
3648 "infrun: step-resume breakpoint is inserted\n");
3650 /* Having a step-resume breakpoint overrides anything
3651 else having to do with stepping commands until
3652 that breakpoint is reached. */
3657 if (ecs
->event_thread
->step_range_end
== 0)
3660 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
3661 /* Likewise if we aren't even stepping. */
3666 /* If stepping through a line, keep going if still within it.
3668 Note that step_range_end is the address of the first instruction
3669 beyond the step range, and NOT the address of the last instruction
3672 Note also that during reverse execution, we may be stepping
3673 through a function epilogue and therefore must detect when
3674 the current-frame changes in the middle of a line. */
3676 if (stop_pc
>= ecs
->event_thread
->step_range_start
3677 && stop_pc
< ecs
->event_thread
->step_range_end
3678 && (execution_direction
!= EXEC_REVERSE
3679 || frame_id_eq (get_frame_id (frame
),
3680 ecs
->event_thread
->step_frame_id
)))
3684 (gdb_stdlog
, "infrun: stepping inside range [%s-%s]\n",
3685 paddress (gdbarch
, ecs
->event_thread
->step_range_start
),
3686 paddress (gdbarch
, ecs
->event_thread
->step_range_end
));
3688 /* When stepping backward, stop at beginning of line range
3689 (unless it's the function entry point, in which case
3690 keep going back to the call point). */
3691 if (stop_pc
== ecs
->event_thread
->step_range_start
3692 && stop_pc
!= ecs
->stop_func_start
3693 && execution_direction
== EXEC_REVERSE
)
3695 ecs
->event_thread
->stop_step
= 1;
3696 print_stop_reason (END_STEPPING_RANGE
, 0);
3697 stop_stepping (ecs
);
3705 /* We stepped out of the stepping range. */
3707 /* If we are stepping at the source level and entered the runtime
3708 loader dynamic symbol resolution code...
3710 EXEC_FORWARD: we keep on single stepping until we exit the run
3711 time loader code and reach the callee's address.
3713 EXEC_REVERSE: we've already executed the callee (backward), and
3714 the runtime loader code is handled just like any other
3715 undebuggable function call. Now we need only keep stepping
3716 backward through the trampoline code, and that's handled further
3717 down, so there is nothing for us to do here. */
3719 if (execution_direction
!= EXEC_REVERSE
3720 && ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3721 && in_solib_dynsym_resolve_code (stop_pc
))
3723 CORE_ADDR pc_after_resolver
=
3724 gdbarch_skip_solib_resolver (gdbarch
, stop_pc
);
3727 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
3729 if (pc_after_resolver
)
3731 /* Set up a step-resume breakpoint at the address
3732 indicated by SKIP_SOLIB_RESOLVER. */
3733 struct symtab_and_line sr_sal
;
3735 sr_sal
.pc
= pc_after_resolver
;
3737 insert_step_resume_breakpoint_at_sal (gdbarch
,
3738 sr_sal
, null_frame_id
);
3745 if (ecs
->event_thread
->step_range_end
!= 1
3746 && (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3747 || ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
3748 && get_frame_type (frame
) == SIGTRAMP_FRAME
)
3751 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
3752 /* The inferior, while doing a "step" or "next", has ended up in
3753 a signal trampoline (either by a signal being delivered or by
3754 the signal handler returning). Just single-step until the
3755 inferior leaves the trampoline (either by calling the handler
3761 /* Check for subroutine calls. The check for the current frame
3762 equalling the step ID is not necessary - the check of the
3763 previous frame's ID is sufficient - but it is a common case and
3764 cheaper than checking the previous frame's ID.
3766 NOTE: frame_id_eq will never report two invalid frame IDs as
3767 being equal, so to get into this block, both the current and
3768 previous frame must have valid frame IDs. */
3769 if (!frame_id_eq (get_stack_frame_id (frame
),
3770 ecs
->event_thread
->step_stack_frame_id
)
3771 && frame_id_eq (frame_unwind_caller_id (frame
),
3772 ecs
->event_thread
->step_stack_frame_id
))
3774 CORE_ADDR real_stop_pc
;
3777 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
3779 if ((ecs
->event_thread
->step_over_calls
== STEP_OVER_NONE
)
3780 || ((ecs
->event_thread
->step_range_end
== 1)
3781 && in_prologue (gdbarch
, ecs
->event_thread
->prev_pc
,
3782 ecs
->stop_func_start
)))
3784 /* I presume that step_over_calls is only 0 when we're
3785 supposed to be stepping at the assembly language level
3786 ("stepi"). Just stop. */
3787 /* Also, maybe we just did a "nexti" inside a prolog, so we
3788 thought it was a subroutine call but it was not. Stop as
3790 /* And this works the same backward as frontward. MVS */
3791 ecs
->event_thread
->stop_step
= 1;
3792 print_stop_reason (END_STEPPING_RANGE
, 0);
3793 stop_stepping (ecs
);
3797 /* Reverse stepping through solib trampolines. */
3799 if (execution_direction
== EXEC_REVERSE
3800 && ecs
->event_thread
->step_over_calls
!= STEP_OVER_NONE
3801 && (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
3802 || (ecs
->stop_func_start
== 0
3803 && in_solib_dynsym_resolve_code (stop_pc
))))
3805 /* Any solib trampoline code can be handled in reverse
3806 by simply continuing to single-step. We have already
3807 executed the solib function (backwards), and a few
3808 steps will take us back through the trampoline to the
3814 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
3816 /* We're doing a "next".
3818 Normal (forward) execution: set a breakpoint at the
3819 callee's return address (the address at which the caller
3822 Reverse (backward) execution. set the step-resume
3823 breakpoint at the start of the function that we just
3824 stepped into (backwards), and continue to there. When we
3825 get there, we'll need to single-step back to the caller. */
3827 if (execution_direction
== EXEC_REVERSE
)
3829 struct symtab_and_line sr_sal
;
3831 /* Normal function call return (static or dynamic). */
3833 sr_sal
.pc
= ecs
->stop_func_start
;
3834 insert_step_resume_breakpoint_at_sal (gdbarch
,
3835 sr_sal
, null_frame_id
);
3838 insert_step_resume_breakpoint_at_caller (frame
);
3844 /* If we are in a function call trampoline (a stub between the
3845 calling routine and the real function), locate the real
3846 function. That's what tells us (a) whether we want to step
3847 into it at all, and (b) what prologue we want to run to the
3848 end of, if we do step into it. */
3849 real_stop_pc
= skip_language_trampoline (frame
, stop_pc
);
3850 if (real_stop_pc
== 0)
3851 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
3852 if (real_stop_pc
!= 0)
3853 ecs
->stop_func_start
= real_stop_pc
;
3855 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
3857 struct symtab_and_line sr_sal
;
3859 sr_sal
.pc
= ecs
->stop_func_start
;
3861 insert_step_resume_breakpoint_at_sal (gdbarch
,
3862 sr_sal
, null_frame_id
);
3867 /* If we have line number information for the function we are
3868 thinking of stepping into, step into it.
3870 If there are several symtabs at that PC (e.g. with include
3871 files), just want to know whether *any* of them have line
3872 numbers. find_pc_line handles this. */
3874 struct symtab_and_line tmp_sal
;
3876 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3877 if (tmp_sal
.line
!= 0)
3879 if (execution_direction
== EXEC_REVERSE
)
3880 handle_step_into_function_backward (gdbarch
, ecs
);
3882 handle_step_into_function (gdbarch
, ecs
);
3887 /* If we have no line number and the step-stop-if-no-debug is
3888 set, we stop the step so that the user has a chance to switch
3889 in assembly mode. */
3890 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3891 && step_stop_if_no_debug
)
3893 ecs
->event_thread
->stop_step
= 1;
3894 print_stop_reason (END_STEPPING_RANGE
, 0);
3895 stop_stepping (ecs
);
3899 if (execution_direction
== EXEC_REVERSE
)
3901 /* Set a breakpoint at callee's start address.
3902 From there we can step once and be back in the caller. */
3903 struct symtab_and_line sr_sal
;
3905 sr_sal
.pc
= ecs
->stop_func_start
;
3906 insert_step_resume_breakpoint_at_sal (gdbarch
,
3907 sr_sal
, null_frame_id
);
3910 /* Set a breakpoint at callee's return address (the address
3911 at which the caller will resume). */
3912 insert_step_resume_breakpoint_at_caller (frame
);
3918 /* Reverse stepping through solib trampolines. */
3920 if (execution_direction
== EXEC_REVERSE
3921 && ecs
->event_thread
->step_over_calls
!= STEP_OVER_NONE
)
3923 if (gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
)
3924 || (ecs
->stop_func_start
== 0
3925 && in_solib_dynsym_resolve_code (stop_pc
)))
3927 /* Any solib trampoline code can be handled in reverse
3928 by simply continuing to single-step. We have already
3929 executed the solib function (backwards), and a few
3930 steps will take us back through the trampoline to the
3935 else if (in_solib_dynsym_resolve_code (stop_pc
))
3937 /* Stepped backward into the solib dynsym resolver.
3938 Set a breakpoint at its start and continue, then
3939 one more step will take us out. */
3940 struct symtab_and_line sr_sal
;
3942 sr_sal
.pc
= ecs
->stop_func_start
;
3943 insert_step_resume_breakpoint_at_sal (gdbarch
,
3944 sr_sal
, null_frame_id
);
3950 /* If we're in the return path from a shared library trampoline,
3951 we want to proceed through the trampoline when stepping. */
3952 if (gdbarch_in_solib_return_trampoline (gdbarch
,
3953 stop_pc
, ecs
->stop_func_name
))
3955 /* Determine where this trampoline returns. */
3956 CORE_ADDR real_stop_pc
;
3957 real_stop_pc
= gdbarch_skip_trampoline_code (gdbarch
, frame
, stop_pc
);
3960 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3962 /* Only proceed through if we know where it's going. */
3965 /* And put the step-breakpoint there and go until there. */
3966 struct symtab_and_line sr_sal
;
3968 init_sal (&sr_sal
); /* initialize to zeroes */
3969 sr_sal
.pc
= real_stop_pc
;
3970 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3972 /* Do not specify what the fp should be when we stop since
3973 on some machines the prologue is where the new fp value
3975 insert_step_resume_breakpoint_at_sal (gdbarch
,
3976 sr_sal
, null_frame_id
);
3978 /* Restart without fiddling with the step ranges or
3985 stop_pc_sal
= find_pc_line (stop_pc
, 0);
3987 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3988 the trampoline processing logic, however, there are some trampolines
3989 that have no names, so we should do trampoline handling first. */
3990 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3991 && ecs
->stop_func_name
== NULL
3992 && stop_pc_sal
.line
== 0)
3995 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3997 /* The inferior just stepped into, or returned to, an
3998 undebuggable function (where there is no debugging information
3999 and no line number corresponding to the address where the
4000 inferior stopped). Since we want to skip this kind of code,
4001 we keep going until the inferior returns from this
4002 function - unless the user has asked us not to (via
4003 set step-mode) or we no longer know how to get back
4004 to the call site. */
4005 if (step_stop_if_no_debug
4006 || !frame_id_p (frame_unwind_caller_id (frame
)))
4008 /* If we have no line number and the step-stop-if-no-debug
4009 is set, we stop the step so that the user has a chance to
4010 switch in assembly mode. */
4011 ecs
->event_thread
->stop_step
= 1;
4012 print_stop_reason (END_STEPPING_RANGE
, 0);
4013 stop_stepping (ecs
);
4018 /* Set a breakpoint at callee's return address (the address
4019 at which the caller will resume). */
4020 insert_step_resume_breakpoint_at_caller (frame
);
4026 if (ecs
->event_thread
->step_range_end
== 1)
4028 /* It is stepi or nexti. We always want to stop stepping after
4031 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
4032 ecs
->event_thread
->stop_step
= 1;
4033 print_stop_reason (END_STEPPING_RANGE
, 0);
4034 stop_stepping (ecs
);
4038 if (stop_pc_sal
.line
== 0)
4040 /* We have no line number information. That means to stop
4041 stepping (does this always happen right after one instruction,
4042 when we do "s" in a function with no line numbers,
4043 or can this happen as a result of a return or longjmp?). */
4045 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
4046 ecs
->event_thread
->stop_step
= 1;
4047 print_stop_reason (END_STEPPING_RANGE
, 0);
4048 stop_stepping (ecs
);
4052 /* Look for "calls" to inlined functions, part one. If the inline
4053 frame machinery detected some skipped call sites, we have entered
4054 a new inline function. */
4056 if (frame_id_eq (get_frame_id (get_current_frame ()),
4057 ecs
->event_thread
->step_frame_id
)
4058 && inline_skipped_frames (ecs
->ptid
))
4060 struct symtab_and_line call_sal
;
4063 fprintf_unfiltered (gdb_stdlog
,
4064 "infrun: stepped into inlined function\n");
4066 find_frame_sal (get_current_frame (), &call_sal
);
4068 if (ecs
->event_thread
->step_over_calls
!= STEP_OVER_ALL
)
4070 /* For "step", we're going to stop. But if the call site
4071 for this inlined function is on the same source line as
4072 we were previously stepping, go down into the function
4073 first. Otherwise stop at the call site. */
4075 if (call_sal
.line
== ecs
->event_thread
->current_line
4076 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
4077 step_into_inline_frame (ecs
->ptid
);
4079 ecs
->event_thread
->stop_step
= 1;
4080 print_stop_reason (END_STEPPING_RANGE
, 0);
4081 stop_stepping (ecs
);
4086 /* For "next", we should stop at the call site if it is on a
4087 different source line. Otherwise continue through the
4088 inlined function. */
4089 if (call_sal
.line
== ecs
->event_thread
->current_line
4090 && call_sal
.symtab
== ecs
->event_thread
->current_symtab
)
4094 ecs
->event_thread
->stop_step
= 1;
4095 print_stop_reason (END_STEPPING_RANGE
, 0);
4096 stop_stepping (ecs
);
4102 /* Look for "calls" to inlined functions, part two. If we are still
4103 in the same real function we were stepping through, but we have
4104 to go further up to find the exact frame ID, we are stepping
4105 through a more inlined call beyond its call site. */
4107 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
4108 && !frame_id_eq (get_frame_id (get_current_frame ()),
4109 ecs
->event_thread
->step_frame_id
)
4110 && stepped_in_from (get_current_frame (),
4111 ecs
->event_thread
->step_frame_id
))
4114 fprintf_unfiltered (gdb_stdlog
,
4115 "infrun: stepping through inlined function\n");
4117 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
4121 ecs
->event_thread
->stop_step
= 1;
4122 print_stop_reason (END_STEPPING_RANGE
, 0);
4123 stop_stepping (ecs
);
4128 if ((stop_pc
== stop_pc_sal
.pc
)
4129 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
4130 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
4132 /* We are at the start of a different line. So stop. Note that
4133 we don't stop if we step into the middle of a different line.
4134 That is said to make things like for (;;) statements work
4137 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
4138 ecs
->event_thread
->stop_step
= 1;
4139 print_stop_reason (END_STEPPING_RANGE
, 0);
4140 stop_stepping (ecs
);
4144 /* We aren't done stepping.
4146 Optimize by setting the stepping range to the line.
4147 (We might not be in the original line, but if we entered a
4148 new line in mid-statement, we continue stepping. This makes
4149 things like for(;;) statements work better.) */
4151 ecs
->event_thread
->step_range_start
= stop_pc_sal
.pc
;
4152 ecs
->event_thread
->step_range_end
= stop_pc_sal
.end
;
4153 set_step_info (frame
, stop_pc_sal
);
4156 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
4160 /* Is thread TP in the middle of single-stepping? */
4163 currently_stepping (struct thread_info
*tp
)
4165 return ((tp
->step_range_end
&& tp
->step_resume_breakpoint
== NULL
)
4166 || tp
->trap_expected
4167 || tp
->stepping_through_solib_after_catch
4168 || bpstat_should_step ());
4171 /* Returns true if any thread *but* the one passed in "data" is in the
4172 middle of stepping or of handling a "next". */
4175 currently_stepping_or_nexting_callback (struct thread_info
*tp
, void *data
)
4180 return (tp
->step_range_end
4181 || tp
->trap_expected
4182 || tp
->stepping_through_solib_after_catch
);
4185 /* Inferior has stepped into a subroutine call with source code that
4186 we should not step over. Do step to the first line of code in
4190 handle_step_into_function (struct gdbarch
*gdbarch
,
4191 struct execution_control_state
*ecs
)
4194 struct symtab_and_line stop_func_sal
, sr_sal
;
4196 s
= find_pc_symtab (stop_pc
);
4197 if (s
&& s
->language
!= language_asm
)
4198 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
4199 ecs
->stop_func_start
);
4201 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
4202 /* Use the step_resume_break to step until the end of the prologue,
4203 even if that involves jumps (as it seems to on the vax under
4205 /* If the prologue ends in the middle of a source line, continue to
4206 the end of that source line (if it is still within the function).
4207 Otherwise, just go to end of prologue. */
4208 if (stop_func_sal
.end
4209 && stop_func_sal
.pc
!= ecs
->stop_func_start
4210 && stop_func_sal
.end
< ecs
->stop_func_end
)
4211 ecs
->stop_func_start
= stop_func_sal
.end
;
4213 /* Architectures which require breakpoint adjustment might not be able
4214 to place a breakpoint at the computed address. If so, the test
4215 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
4216 ecs->stop_func_start to an address at which a breakpoint may be
4217 legitimately placed.
4219 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
4220 made, GDB will enter an infinite loop when stepping through
4221 optimized code consisting of VLIW instructions which contain
4222 subinstructions corresponding to different source lines. On
4223 FR-V, it's not permitted to place a breakpoint on any but the
4224 first subinstruction of a VLIW instruction. When a breakpoint is
4225 set, GDB will adjust the breakpoint address to the beginning of
4226 the VLIW instruction. Thus, we need to make the corresponding
4227 adjustment here when computing the stop address. */
4229 if (gdbarch_adjust_breakpoint_address_p (gdbarch
))
4231 ecs
->stop_func_start
4232 = gdbarch_adjust_breakpoint_address (gdbarch
,
4233 ecs
->stop_func_start
);
4236 if (ecs
->stop_func_start
== stop_pc
)
4238 /* We are already there: stop now. */
4239 ecs
->event_thread
->stop_step
= 1;
4240 print_stop_reason (END_STEPPING_RANGE
, 0);
4241 stop_stepping (ecs
);
4246 /* Put the step-breakpoint there and go until there. */
4247 init_sal (&sr_sal
); /* initialize to zeroes */
4248 sr_sal
.pc
= ecs
->stop_func_start
;
4249 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
4251 /* Do not specify what the fp should be when we stop since on
4252 some machines the prologue is where the new fp value is
4254 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
, null_frame_id
);
4256 /* And make sure stepping stops right away then. */
4257 ecs
->event_thread
->step_range_end
= ecs
->event_thread
->step_range_start
;
4262 /* Inferior has stepped backward into a subroutine call with source
4263 code that we should not step over. Do step to the beginning of the
4264 last line of code in it. */
4267 handle_step_into_function_backward (struct gdbarch
*gdbarch
,
4268 struct execution_control_state
*ecs
)
4271 struct symtab_and_line stop_func_sal
, sr_sal
;
4273 s
= find_pc_symtab (stop_pc
);
4274 if (s
&& s
->language
!= language_asm
)
4275 ecs
->stop_func_start
= gdbarch_skip_prologue (gdbarch
,
4276 ecs
->stop_func_start
);
4278 stop_func_sal
= find_pc_line (stop_pc
, 0);
4280 /* OK, we're just going to keep stepping here. */
4281 if (stop_func_sal
.pc
== stop_pc
)
4283 /* We're there already. Just stop stepping now. */
4284 ecs
->event_thread
->stop_step
= 1;
4285 print_stop_reason (END_STEPPING_RANGE
, 0);
4286 stop_stepping (ecs
);
4290 /* Else just reset the step range and keep going.
4291 No step-resume breakpoint, they don't work for
4292 epilogues, which can have multiple entry paths. */
4293 ecs
->event_thread
->step_range_start
= stop_func_sal
.pc
;
4294 ecs
->event_thread
->step_range_end
= stop_func_sal
.end
;
4300 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
4301 This is used to both functions and to skip over code. */
4304 insert_step_resume_breakpoint_at_sal (struct gdbarch
*gdbarch
,
4305 struct symtab_and_line sr_sal
,
4306 struct frame_id sr_id
)
4308 /* There should never be more than one step-resume or longjmp-resume
4309 breakpoint per thread, so we should never be setting a new
4310 step_resume_breakpoint when one is already active. */
4311 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
4314 fprintf_unfiltered (gdb_stdlog
,
4315 "infrun: inserting step-resume breakpoint at %s\n",
4316 paddress (gdbarch
, sr_sal
.pc
));
4318 inferior_thread ()->step_resume_breakpoint
4319 = set_momentary_breakpoint (gdbarch
, sr_sal
, sr_id
, bp_step_resume
);
4322 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
4323 to skip a potential signal handler.
4325 This is called with the interrupted function's frame. The signal
4326 handler, when it returns, will resume the interrupted function at
4330 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
4332 struct symtab_and_line sr_sal
;
4333 struct gdbarch
*gdbarch
;
4335 gdb_assert (return_frame
!= NULL
);
4336 init_sal (&sr_sal
); /* initialize to zeros */
4338 gdbarch
= get_frame_arch (return_frame
);
4339 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
, get_frame_pc (return_frame
));
4340 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4342 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
4343 get_stack_frame_id (return_frame
));
4346 /* Similar to insert_step_resume_breakpoint_at_frame, except
4347 but a breakpoint at the previous frame's PC. This is used to
4348 skip a function after stepping into it (for "next" or if the called
4349 function has no debugging information).
4351 The current function has almost always been reached by single
4352 stepping a call or return instruction. NEXT_FRAME belongs to the
4353 current function, and the breakpoint will be set at the caller's
4356 This is a separate function rather than reusing
4357 insert_step_resume_breakpoint_at_frame in order to avoid
4358 get_prev_frame, which may stop prematurely (see the implementation
4359 of frame_unwind_caller_id for an example). */
4362 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
4364 struct symtab_and_line sr_sal
;
4365 struct gdbarch
*gdbarch
;
4367 /* We shouldn't have gotten here if we don't know where the call site
4369 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame
)));
4371 init_sal (&sr_sal
); /* initialize to zeros */
4373 gdbarch
= frame_unwind_caller_arch (next_frame
);
4374 sr_sal
.pc
= gdbarch_addr_bits_remove (gdbarch
,
4375 frame_unwind_caller_pc (next_frame
));
4376 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
4378 insert_step_resume_breakpoint_at_sal (gdbarch
, sr_sal
,
4379 frame_unwind_caller_id (next_frame
));
4382 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
4383 new breakpoint at the target of a jmp_buf. The handling of
4384 longjmp-resume uses the same mechanisms used for handling
4385 "step-resume" breakpoints. */
4388 insert_longjmp_resume_breakpoint (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
4390 /* There should never be more than one step-resume or longjmp-resume
4391 breakpoint per thread, so we should never be setting a new
4392 longjmp_resume_breakpoint when one is already active. */
4393 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
4396 fprintf_unfiltered (gdb_stdlog
,
4397 "infrun: inserting longjmp-resume breakpoint at %s\n",
4398 paddress (gdbarch
, pc
));
4400 inferior_thread ()->step_resume_breakpoint
=
4401 set_momentary_breakpoint_at_pc (gdbarch
, pc
, bp_longjmp_resume
);
4405 stop_stepping (struct execution_control_state
*ecs
)
4408 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
4410 /* Let callers know we don't want to wait for the inferior anymore. */
4411 ecs
->wait_some_more
= 0;
4414 /* This function handles various cases where we need to continue
4415 waiting for the inferior. */
4416 /* (Used to be the keep_going: label in the old wait_for_inferior) */
4419 keep_going (struct execution_control_state
*ecs
)
4421 /* Save the pc before execution, to compare with pc after stop. */
4422 ecs
->event_thread
->prev_pc
4423 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4425 /* If we did not do break;, it means we should keep running the
4426 inferior and not return to debugger. */
4428 if (ecs
->event_thread
->trap_expected
4429 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
4431 /* We took a signal (which we are supposed to pass through to
4432 the inferior, else we'd not get here) and we haven't yet
4433 gotten our trap. Simply continue. */
4434 resume (currently_stepping (ecs
->event_thread
),
4435 ecs
->event_thread
->stop_signal
);
4439 /* Either the trap was not expected, but we are continuing
4440 anyway (the user asked that this signal be passed to the
4443 The signal was SIGTRAP, e.g. it was our signal, but we
4444 decided we should resume from it.
4446 We're going to run this baby now!
4448 Note that insert_breakpoints won't try to re-insert
4449 already inserted breakpoints. Therefore, we don't
4450 care if breakpoints were already inserted, or not. */
4452 if (ecs
->event_thread
->stepping_over_breakpoint
)
4454 struct regcache
*thread_regcache
= get_thread_regcache (ecs
->ptid
);
4455 if (!use_displaced_stepping (get_regcache_arch (thread_regcache
)))
4456 /* Since we can't do a displaced step, we have to remove
4457 the breakpoint while we step it. To keep things
4458 simple, we remove them all. */
4459 remove_breakpoints ();
4463 struct gdb_exception e
;
4464 /* Stop stepping when inserting breakpoints
4466 TRY_CATCH (e
, RETURN_MASK_ERROR
)
4468 insert_breakpoints ();
4472 stop_stepping (ecs
);
4477 ecs
->event_thread
->trap_expected
= ecs
->event_thread
->stepping_over_breakpoint
;
4479 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
4480 specifies that such a signal should be delivered to the
4483 Typically, this would occure when a user is debugging a
4484 target monitor on a simulator: the target monitor sets a
4485 breakpoint; the simulator encounters this break-point and
4486 halts the simulation handing control to GDB; GDB, noteing
4487 that the break-point isn't valid, returns control back to the
4488 simulator; the simulator then delivers the hardware
4489 equivalent of a SIGNAL_TRAP to the program being debugged. */
4491 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
4492 && !signal_program
[ecs
->event_thread
->stop_signal
])
4493 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
4495 resume (currently_stepping (ecs
->event_thread
),
4496 ecs
->event_thread
->stop_signal
);
4499 prepare_to_wait (ecs
);
4502 /* This function normally comes after a resume, before
4503 handle_inferior_event exits. It takes care of any last bits of
4504 housekeeping, and sets the all-important wait_some_more flag. */
4507 prepare_to_wait (struct execution_control_state
*ecs
)
4510 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
4512 /* This is the old end of the while loop. Let everybody know we
4513 want to wait for the inferior some more and get called again
4515 ecs
->wait_some_more
= 1;
4518 /* Print why the inferior has stopped. We always print something when
4519 the inferior exits, or receives a signal. The rest of the cases are
4520 dealt with later on in normal_stop() and print_it_typical(). Ideally
4521 there should be a call to this function from handle_inferior_event()
4522 each time stop_stepping() is called.*/
4524 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
4526 switch (stop_reason
)
4528 case END_STEPPING_RANGE
:
4529 /* We are done with a step/next/si/ni command. */
4530 /* For now print nothing. */
4531 /* Print a message only if not in the middle of doing a "step n"
4532 operation for n > 1 */
4533 if (!inferior_thread ()->step_multi
4534 || !inferior_thread ()->stop_step
)
4535 if (ui_out_is_mi_like_p (uiout
))
4538 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
4541 /* The inferior was terminated by a signal. */
4542 annotate_signalled ();
4543 if (ui_out_is_mi_like_p (uiout
))
4546 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
4547 ui_out_text (uiout
, "\nProgram terminated with signal ");
4548 annotate_signal_name ();
4549 ui_out_field_string (uiout
, "signal-name",
4550 target_signal_to_name (stop_info
));
4551 annotate_signal_name_end ();
4552 ui_out_text (uiout
, ", ");
4553 annotate_signal_string ();
4554 ui_out_field_string (uiout
, "signal-meaning",
4555 target_signal_to_string (stop_info
));
4556 annotate_signal_string_end ();
4557 ui_out_text (uiout
, ".\n");
4558 ui_out_text (uiout
, "The program no longer exists.\n");
4561 /* The inferior program is finished. */
4562 annotate_exited (stop_info
);
4565 if (ui_out_is_mi_like_p (uiout
))
4566 ui_out_field_string (uiout
, "reason",
4567 async_reason_lookup (EXEC_ASYNC_EXITED
));
4568 ui_out_text (uiout
, "\nProgram exited with code ");
4569 ui_out_field_fmt (uiout
, "exit-code", "0%o",
4570 (unsigned int) stop_info
);
4571 ui_out_text (uiout
, ".\n");
4575 if (ui_out_is_mi_like_p (uiout
))
4578 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
4579 ui_out_text (uiout
, "\nProgram exited normally.\n");
4581 /* Support the --return-child-result option. */
4582 return_child_result_value
= stop_info
;
4584 case SIGNAL_RECEIVED
:
4585 /* Signal received. The signal table tells us to print about
4589 if (stop_info
== TARGET_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
4591 struct thread_info
*t
= inferior_thread ();
4593 ui_out_text (uiout
, "\n[");
4594 ui_out_field_string (uiout
, "thread-name",
4595 target_pid_to_str (t
->ptid
));
4596 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
4597 ui_out_text (uiout
, " stopped");
4601 ui_out_text (uiout
, "\nProgram received signal ");
4602 annotate_signal_name ();
4603 if (ui_out_is_mi_like_p (uiout
))
4605 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
4606 ui_out_field_string (uiout
, "signal-name",
4607 target_signal_to_name (stop_info
));
4608 annotate_signal_name_end ();
4609 ui_out_text (uiout
, ", ");
4610 annotate_signal_string ();
4611 ui_out_field_string (uiout
, "signal-meaning",
4612 target_signal_to_string (stop_info
));
4613 annotate_signal_string_end ();
4615 ui_out_text (uiout
, ".\n");
4618 /* Reverse execution: target ran out of history info. */
4619 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
4622 internal_error (__FILE__
, __LINE__
,
4623 _("print_stop_reason: unrecognized enum value"));
4629 /* Here to return control to GDB when the inferior stops for real.
4630 Print appropriate messages, remove breakpoints, give terminal our modes.
4632 STOP_PRINT_FRAME nonzero means print the executing frame
4633 (pc, function, args, file, line number and line text).
4634 BREAKPOINTS_FAILED nonzero means stop was due to error
4635 attempting to insert breakpoints. */
4640 struct target_waitstatus last
;
4642 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
4644 get_last_target_status (&last_ptid
, &last
);
4646 /* If an exception is thrown from this point on, make sure to
4647 propagate GDB's knowledge of the executing state to the
4648 frontend/user running state. A QUIT is an easy exception to see
4649 here, so do this before any filtered output. */
4651 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
4652 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
4653 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4654 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
4656 /* In non-stop mode, we don't want GDB to switch threads behind the
4657 user's back, to avoid races where the user is typing a command to
4658 apply to thread x, but GDB switches to thread y before the user
4659 finishes entering the command. */
4661 /* As with the notification of thread events, we want to delay
4662 notifying the user that we've switched thread context until
4663 the inferior actually stops.
4665 There's no point in saying anything if the inferior has exited.
4666 Note that SIGNALLED here means "exited with a signal", not
4667 "received a signal". */
4669 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
4670 && target_has_execution
4671 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
4672 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4674 target_terminal_ours_for_output ();
4675 printf_filtered (_("[Switching to %s]\n"),
4676 target_pid_to_str (inferior_ptid
));
4677 annotate_thread_changed ();
4678 previous_inferior_ptid
= inferior_ptid
;
4681 if (!breakpoints_always_inserted_mode () && target_has_execution
)
4683 if (remove_breakpoints ())
4685 target_terminal_ours_for_output ();
4686 printf_filtered (_("\
4687 Cannot remove breakpoints because program is no longer writable.\n\
4688 Further execution is probably impossible.\n"));
4692 /* If an auto-display called a function and that got a signal,
4693 delete that auto-display to avoid an infinite recursion. */
4695 if (stopped_by_random_signal
)
4696 disable_current_display ();
4698 /* Don't print a message if in the middle of doing a "step n"
4699 operation for n > 1 */
4700 if (target_has_execution
4701 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
4702 && last
.kind
!= TARGET_WAITKIND_EXITED
4703 && inferior_thread ()->step_multi
4704 && inferior_thread ()->stop_step
)
4707 target_terminal_ours ();
4709 /* Set the current source location. This will also happen if we
4710 display the frame below, but the current SAL will be incorrect
4711 during a user hook-stop function. */
4712 if (has_stack_frames () && !stop_stack_dummy
)
4713 set_current_sal_from_frame (get_current_frame (), 1);
4715 /* Let the user/frontend see the threads as stopped. */
4716 do_cleanups (old_chain
);
4718 /* Look up the hook_stop and run it (CLI internally handles problem
4719 of stop_command's pre-hook not existing). */
4721 catch_errors (hook_stop_stub
, stop_command
,
4722 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
4724 if (!has_stack_frames ())
4727 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
4728 || last
.kind
== TARGET_WAITKIND_EXITED
)
4731 /* Select innermost stack frame - i.e., current frame is frame 0,
4732 and current location is based on that.
4733 Don't do this on return from a stack dummy routine,
4734 or if the program has exited. */
4736 if (!stop_stack_dummy
)
4738 select_frame (get_current_frame ());
4740 /* Print current location without a level number, if
4741 we have changed functions or hit a breakpoint.
4742 Print source line if we have one.
4743 bpstat_print() contains the logic deciding in detail
4744 what to print, based on the event(s) that just occurred. */
4746 /* If --batch-silent is enabled then there's no need to print the current
4747 source location, and to try risks causing an error message about
4748 missing source files. */
4749 if (stop_print_frame
&& !batch_silent
)
4753 int do_frame_printing
= 1;
4754 struct thread_info
*tp
= inferior_thread ();
4756 bpstat_ret
= bpstat_print (tp
->stop_bpstat
);
4760 /* If we had hit a shared library event breakpoint,
4761 bpstat_print would print out this message. If we hit
4762 an OS-level shared library event, do the same
4764 if (last
.kind
== TARGET_WAITKIND_LOADED
)
4766 printf_filtered (_("Stopped due to shared library event\n"));
4767 source_flag
= SRC_LINE
; /* something bogus */
4768 do_frame_printing
= 0;
4772 /* FIXME: cagney/2002-12-01: Given that a frame ID does
4773 (or should) carry around the function and does (or
4774 should) use that when doing a frame comparison. */
4776 && frame_id_eq (tp
->step_frame_id
,
4777 get_frame_id (get_current_frame ()))
4778 && step_start_function
== find_pc_function (stop_pc
))
4779 source_flag
= SRC_LINE
; /* finished step, just print source line */
4781 source_flag
= SRC_AND_LOC
; /* print location and source line */
4783 case PRINT_SRC_AND_LOC
:
4784 source_flag
= SRC_AND_LOC
; /* print location and source line */
4786 case PRINT_SRC_ONLY
:
4787 source_flag
= SRC_LINE
;
4790 source_flag
= SRC_LINE
; /* something bogus */
4791 do_frame_printing
= 0;
4794 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
4797 /* The behavior of this routine with respect to the source
4799 SRC_LINE: Print only source line
4800 LOCATION: Print only location
4801 SRC_AND_LOC: Print location and source line */
4802 if (do_frame_printing
)
4803 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
4805 /* Display the auto-display expressions. */
4810 /* Save the function value return registers, if we care.
4811 We might be about to restore their previous contents. */
4812 if (inferior_thread ()->proceed_to_finish
)
4814 /* This should not be necessary. */
4816 regcache_xfree (stop_registers
);
4818 /* NB: The copy goes through to the target picking up the value of
4819 all the registers. */
4820 stop_registers
= regcache_dup (get_current_regcache ());
4823 if (stop_stack_dummy
)
4825 /* Pop the empty frame that contains the stack dummy.
4826 This also restores inferior state prior to the call
4827 (struct inferior_thread_state). */
4828 struct frame_info
*frame
= get_current_frame ();
4829 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
4831 /* frame_pop() calls reinit_frame_cache as the last thing it does
4832 which means there's currently no selected frame. We don't need
4833 to re-establish a selected frame if the dummy call returns normally,
4834 that will be done by restore_inferior_status. However, we do have
4835 to handle the case where the dummy call is returning after being
4836 stopped (e.g. the dummy call previously hit a breakpoint). We
4837 can't know which case we have so just always re-establish a
4838 selected frame here. */
4839 select_frame (get_current_frame ());
4843 annotate_stopped ();
4845 /* Suppress the stop observer if we're in the middle of:
4847 - a step n (n > 1), as there still more steps to be done.
4849 - a "finish" command, as the observer will be called in
4850 finish_command_continuation, so it can include the inferior
4851 function's return value.
4853 - calling an inferior function, as we pretend we inferior didn't
4854 run at all. The return value of the call is handled by the
4855 expression evaluator, through call_function_by_hand. */
4857 if (!target_has_execution
4858 || last
.kind
== TARGET_WAITKIND_SIGNALLED
4859 || last
.kind
== TARGET_WAITKIND_EXITED
4860 || (!inferior_thread ()->step_multi
4861 && !(inferior_thread ()->stop_bpstat
4862 && inferior_thread ()->proceed_to_finish
)
4863 && !inferior_thread ()->in_infcall
))
4865 if (!ptid_equal (inferior_ptid
, null_ptid
))
4866 observer_notify_normal_stop (inferior_thread ()->stop_bpstat
,
4869 observer_notify_normal_stop (NULL
, stop_print_frame
);
4872 if (target_has_execution
)
4874 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
4875 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4876 /* Delete the breakpoint we stopped at, if it wants to be deleted.
4877 Delete any breakpoint that is to be deleted at the next stop. */
4878 breakpoint_auto_delete (inferior_thread ()->stop_bpstat
);
4883 hook_stop_stub (void *cmd
)
4885 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
4890 signal_stop_state (int signo
)
4892 return signal_stop
[signo
];
4896 signal_print_state (int signo
)
4898 return signal_print
[signo
];
4902 signal_pass_state (int signo
)
4904 return signal_program
[signo
];
4908 signal_stop_update (int signo
, int state
)
4910 int ret
= signal_stop
[signo
];
4911 signal_stop
[signo
] = state
;
4916 signal_print_update (int signo
, int state
)
4918 int ret
= signal_print
[signo
];
4919 signal_print
[signo
] = state
;
4924 signal_pass_update (int signo
, int state
)
4926 int ret
= signal_program
[signo
];
4927 signal_program
[signo
] = state
;
4932 sig_print_header (void)
4934 printf_filtered (_("\
4935 Signal Stop\tPrint\tPass to program\tDescription\n"));
4939 sig_print_info (enum target_signal oursig
)
4941 const char *name
= target_signal_to_name (oursig
);
4942 int name_padding
= 13 - strlen (name
);
4944 if (name_padding
<= 0)
4947 printf_filtered ("%s", name
);
4948 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
4949 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
4950 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
4951 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
4952 printf_filtered ("%s\n", target_signal_to_string (oursig
));
4955 /* Specify how various signals in the inferior should be handled. */
4958 handle_command (char *args
, int from_tty
)
4961 int digits
, wordlen
;
4962 int sigfirst
, signum
, siglast
;
4963 enum target_signal oursig
;
4966 unsigned char *sigs
;
4967 struct cleanup
*old_chain
;
4971 error_no_arg (_("signal to handle"));
4974 /* Allocate and zero an array of flags for which signals to handle. */
4976 nsigs
= (int) TARGET_SIGNAL_LAST
;
4977 sigs
= (unsigned char *) alloca (nsigs
);
4978 memset (sigs
, 0, nsigs
);
4980 /* Break the command line up into args. */
4982 argv
= gdb_buildargv (args
);
4983 old_chain
= make_cleanup_freeargv (argv
);
4985 /* Walk through the args, looking for signal oursigs, signal names, and
4986 actions. Signal numbers and signal names may be interspersed with
4987 actions, with the actions being performed for all signals cumulatively
4988 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4990 while (*argv
!= NULL
)
4992 wordlen
= strlen (*argv
);
4993 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
4997 sigfirst
= siglast
= -1;
4999 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
5001 /* Apply action to all signals except those used by the
5002 debugger. Silently skip those. */
5005 siglast
= nsigs
- 1;
5007 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
5009 SET_SIGS (nsigs
, sigs
, signal_stop
);
5010 SET_SIGS (nsigs
, sigs
, signal_print
);
5012 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
5014 UNSET_SIGS (nsigs
, sigs
, signal_program
);
5016 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
5018 SET_SIGS (nsigs
, sigs
, signal_print
);
5020 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
5022 SET_SIGS (nsigs
, sigs
, signal_program
);
5024 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
5026 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
5028 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
5030 SET_SIGS (nsigs
, sigs
, signal_program
);
5032 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
5034 UNSET_SIGS (nsigs
, sigs
, signal_print
);
5035 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
5037 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
5039 UNSET_SIGS (nsigs
, sigs
, signal_program
);
5041 else if (digits
> 0)
5043 /* It is numeric. The numeric signal refers to our own
5044 internal signal numbering from target.h, not to host/target
5045 signal number. This is a feature; users really should be
5046 using symbolic names anyway, and the common ones like
5047 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
5049 sigfirst
= siglast
= (int)
5050 target_signal_from_command (atoi (*argv
));
5051 if ((*argv
)[digits
] == '-')
5054 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
5056 if (sigfirst
> siglast
)
5058 /* Bet he didn't figure we'd think of this case... */
5066 oursig
= target_signal_from_name (*argv
);
5067 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
5069 sigfirst
= siglast
= (int) oursig
;
5073 /* Not a number and not a recognized flag word => complain. */
5074 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
5078 /* If any signal numbers or symbol names were found, set flags for
5079 which signals to apply actions to. */
5081 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
5083 switch ((enum target_signal
) signum
)
5085 case TARGET_SIGNAL_TRAP
:
5086 case TARGET_SIGNAL_INT
:
5087 if (!allsigs
&& !sigs
[signum
])
5089 if (query (_("%s is used by the debugger.\n\
5090 Are you sure you want to change it? "), target_signal_to_name ((enum target_signal
) signum
)))
5096 printf_unfiltered (_("Not confirmed, unchanged.\n"));
5097 gdb_flush (gdb_stdout
);
5101 case TARGET_SIGNAL_0
:
5102 case TARGET_SIGNAL_DEFAULT
:
5103 case TARGET_SIGNAL_UNKNOWN
:
5104 /* Make sure that "all" doesn't print these. */
5115 for (signum
= 0; signum
< nsigs
; signum
++)
5118 target_notice_signals (inferior_ptid
);
5122 /* Show the results. */
5123 sig_print_header ();
5124 for (; signum
< nsigs
; signum
++)
5126 sig_print_info (signum
);
5132 do_cleanups (old_chain
);
5136 xdb_handle_command (char *args
, int from_tty
)
5139 struct cleanup
*old_chain
;
5142 error_no_arg (_("xdb command"));
5144 /* Break the command line up into args. */
5146 argv
= gdb_buildargv (args
);
5147 old_chain
= make_cleanup_freeargv (argv
);
5148 if (argv
[1] != (char *) NULL
)
5153 bufLen
= strlen (argv
[0]) + 20;
5154 argBuf
= (char *) xmalloc (bufLen
);
5158 enum target_signal oursig
;
5160 oursig
= target_signal_from_name (argv
[0]);
5161 memset (argBuf
, 0, bufLen
);
5162 if (strcmp (argv
[1], "Q") == 0)
5163 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
5166 if (strcmp (argv
[1], "s") == 0)
5168 if (!signal_stop
[oursig
])
5169 sprintf (argBuf
, "%s %s", argv
[0], "stop");
5171 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
5173 else if (strcmp (argv
[1], "i") == 0)
5175 if (!signal_program
[oursig
])
5176 sprintf (argBuf
, "%s %s", argv
[0], "pass");
5178 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
5180 else if (strcmp (argv
[1], "r") == 0)
5182 if (!signal_print
[oursig
])
5183 sprintf (argBuf
, "%s %s", argv
[0], "print");
5185 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
5191 handle_command (argBuf
, from_tty
);
5193 printf_filtered (_("Invalid signal handling flag.\n"));
5198 do_cleanups (old_chain
);
5201 /* Print current contents of the tables set by the handle command.
5202 It is possible we should just be printing signals actually used
5203 by the current target (but for things to work right when switching
5204 targets, all signals should be in the signal tables). */
5207 signals_info (char *signum_exp
, int from_tty
)
5209 enum target_signal oursig
;
5210 sig_print_header ();
5214 /* First see if this is a symbol name. */
5215 oursig
= target_signal_from_name (signum_exp
);
5216 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
5218 /* No, try numeric. */
5220 target_signal_from_command (parse_and_eval_long (signum_exp
));
5222 sig_print_info (oursig
);
5226 printf_filtered ("\n");
5227 /* These ugly casts brought to you by the native VAX compiler. */
5228 for (oursig
= TARGET_SIGNAL_FIRST
;
5229 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
5230 oursig
= (enum target_signal
) ((int) oursig
+ 1))
5234 if (oursig
!= TARGET_SIGNAL_UNKNOWN
5235 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
5236 sig_print_info (oursig
);
5239 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
5242 /* The $_siginfo convenience variable is a bit special. We don't know
5243 for sure the type of the value until we actually have a chance to
5244 fetch the data. The type can change depending on gdbarch, so it it
5245 also dependent on which thread you have selected.
5247 1. making $_siginfo be an internalvar that creates a new value on
5250 2. making the value of $_siginfo be an lval_computed value. */
5252 /* This function implements the lval_computed support for reading a
5256 siginfo_value_read (struct value
*v
)
5258 LONGEST transferred
;
5261 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
5263 value_contents_all_raw (v
),
5265 TYPE_LENGTH (value_type (v
)));
5267 if (transferred
!= TYPE_LENGTH (value_type (v
)))
5268 error (_("Unable to read siginfo"));
5271 /* This function implements the lval_computed support for writing a
5275 siginfo_value_write (struct value
*v
, struct value
*fromval
)
5277 LONGEST transferred
;
5279 transferred
= target_write (¤t_target
,
5280 TARGET_OBJECT_SIGNAL_INFO
,
5282 value_contents_all_raw (fromval
),
5284 TYPE_LENGTH (value_type (fromval
)));
5286 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
5287 error (_("Unable to write siginfo"));
5290 static struct lval_funcs siginfo_value_funcs
=
5296 /* Return a new value with the correct type for the siginfo object of
5297 the current thread using architecture GDBARCH. Return a void value
5298 if there's no object available. */
5300 static struct value
*
5301 siginfo_make_value (struct gdbarch
*gdbarch
, struct internalvar
*var
)
5303 if (target_has_stack
5304 && !ptid_equal (inferior_ptid
, null_ptid
)
5305 && gdbarch_get_siginfo_type_p (gdbarch
))
5307 struct type
*type
= gdbarch_get_siginfo_type (gdbarch
);
5308 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
5311 return allocate_value (builtin_type (gdbarch
)->builtin_void
);
5315 /* Inferior thread state.
5316 These are details related to the inferior itself, and don't include
5317 things like what frame the user had selected or what gdb was doing
5318 with the target at the time.
5319 For inferior function calls these are things we want to restore
5320 regardless of whether the function call successfully completes
5321 or the dummy frame has to be manually popped. */
5323 struct inferior_thread_state
5325 enum target_signal stop_signal
;
5327 struct regcache
*registers
;
5330 struct inferior_thread_state
*
5331 save_inferior_thread_state (void)
5333 struct inferior_thread_state
*inf_state
= XMALLOC (struct inferior_thread_state
);
5334 struct thread_info
*tp
= inferior_thread ();
5336 inf_state
->stop_signal
= tp
->stop_signal
;
5337 inf_state
->stop_pc
= stop_pc
;
5339 inf_state
->registers
= regcache_dup (get_current_regcache ());
5344 /* Restore inferior session state to INF_STATE. */
5347 restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5349 struct thread_info
*tp
= inferior_thread ();
5351 tp
->stop_signal
= inf_state
->stop_signal
;
5352 stop_pc
= inf_state
->stop_pc
;
5354 /* The inferior can be gone if the user types "print exit(0)"
5355 (and perhaps other times). */
5356 if (target_has_execution
)
5357 /* NB: The register write goes through to the target. */
5358 regcache_cpy (get_current_regcache (), inf_state
->registers
);
5359 regcache_xfree (inf_state
->registers
);
5364 do_restore_inferior_thread_state_cleanup (void *state
)
5366 restore_inferior_thread_state (state
);
5370 make_cleanup_restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5372 return make_cleanup (do_restore_inferior_thread_state_cleanup
, inf_state
);
5376 discard_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5378 regcache_xfree (inf_state
->registers
);
5383 get_inferior_thread_state_regcache (struct inferior_thread_state
*inf_state
)
5385 return inf_state
->registers
;
5388 /* Session related state for inferior function calls.
5389 These are the additional bits of state that need to be restored
5390 when an inferior function call successfully completes. */
5392 struct inferior_status
5396 int stop_stack_dummy
;
5397 int stopped_by_random_signal
;
5398 int stepping_over_breakpoint
;
5399 CORE_ADDR step_range_start
;
5400 CORE_ADDR step_range_end
;
5401 struct frame_id step_frame_id
;
5402 struct frame_id step_stack_frame_id
;
5403 enum step_over_calls_kind step_over_calls
;
5404 CORE_ADDR step_resume_break_address
;
5405 int stop_after_trap
;
5408 /* ID if the selected frame when the inferior function call was made. */
5409 struct frame_id selected_frame_id
;
5411 int proceed_to_finish
;
5415 /* Save all of the information associated with the inferior<==>gdb
5418 struct inferior_status
*
5419 save_inferior_status (void)
5421 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
5422 struct thread_info
*tp
= inferior_thread ();
5423 struct inferior
*inf
= current_inferior ();
5425 inf_status
->stop_step
= tp
->stop_step
;
5426 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
5427 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
5428 inf_status
->stepping_over_breakpoint
= tp
->trap_expected
;
5429 inf_status
->step_range_start
= tp
->step_range_start
;
5430 inf_status
->step_range_end
= tp
->step_range_end
;
5431 inf_status
->step_frame_id
= tp
->step_frame_id
;
5432 inf_status
->step_stack_frame_id
= tp
->step_stack_frame_id
;
5433 inf_status
->step_over_calls
= tp
->step_over_calls
;
5434 inf_status
->stop_after_trap
= stop_after_trap
;
5435 inf_status
->stop_soon
= inf
->stop_soon
;
5436 /* Save original bpstat chain here; replace it with copy of chain.
5437 If caller's caller is walking the chain, they'll be happier if we
5438 hand them back the original chain when restore_inferior_status is
5440 inf_status
->stop_bpstat
= tp
->stop_bpstat
;
5441 tp
->stop_bpstat
= bpstat_copy (tp
->stop_bpstat
);
5442 inf_status
->proceed_to_finish
= tp
->proceed_to_finish
;
5443 inf_status
->in_infcall
= tp
->in_infcall
;
5445 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
5451 restore_selected_frame (void *args
)
5453 struct frame_id
*fid
= (struct frame_id
*) args
;
5454 struct frame_info
*frame
;
5456 frame
= frame_find_by_id (*fid
);
5458 /* If inf_status->selected_frame_id is NULL, there was no previously
5462 warning (_("Unable to restore previously selected frame."));
5466 select_frame (frame
);
5471 /* Restore inferior session state to INF_STATUS. */
5474 restore_inferior_status (struct inferior_status
*inf_status
)
5476 struct thread_info
*tp
= inferior_thread ();
5477 struct inferior
*inf
= current_inferior ();
5479 tp
->stop_step
= inf_status
->stop_step
;
5480 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
5481 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
5482 tp
->trap_expected
= inf_status
->stepping_over_breakpoint
;
5483 tp
->step_range_start
= inf_status
->step_range_start
;
5484 tp
->step_range_end
= inf_status
->step_range_end
;
5485 tp
->step_frame_id
= inf_status
->step_frame_id
;
5486 tp
->step_stack_frame_id
= inf_status
->step_stack_frame_id
;
5487 tp
->step_over_calls
= inf_status
->step_over_calls
;
5488 stop_after_trap
= inf_status
->stop_after_trap
;
5489 inf
->stop_soon
= inf_status
->stop_soon
;
5490 bpstat_clear (&tp
->stop_bpstat
);
5491 tp
->stop_bpstat
= inf_status
->stop_bpstat
;
5492 inf_status
->stop_bpstat
= NULL
;
5493 tp
->proceed_to_finish
= inf_status
->proceed_to_finish
;
5494 tp
->in_infcall
= inf_status
->in_infcall
;
5496 if (target_has_stack
)
5498 /* The point of catch_errors is that if the stack is clobbered,
5499 walking the stack might encounter a garbage pointer and
5500 error() trying to dereference it. */
5502 (restore_selected_frame
, &inf_status
->selected_frame_id
,
5503 "Unable to restore previously selected frame:\n",
5504 RETURN_MASK_ERROR
) == 0)
5505 /* Error in restoring the selected frame. Select the innermost
5507 select_frame (get_current_frame ());
5514 do_restore_inferior_status_cleanup (void *sts
)
5516 restore_inferior_status (sts
);
5520 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
5522 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
5526 discard_inferior_status (struct inferior_status
*inf_status
)
5528 /* See save_inferior_status for info on stop_bpstat. */
5529 bpstat_clear (&inf_status
->stop_bpstat
);
5534 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
5536 struct target_waitstatus last
;
5539 get_last_target_status (&last_ptid
, &last
);
5541 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
5544 if (!ptid_equal (last_ptid
, pid
))
5547 *child_pid
= last
.value
.related_pid
;
5552 inferior_has_vforked (ptid_t pid
, ptid_t
*child_pid
)
5554 struct target_waitstatus last
;
5557 get_last_target_status (&last_ptid
, &last
);
5559 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
5562 if (!ptid_equal (last_ptid
, pid
))
5565 *child_pid
= last
.value
.related_pid
;
5570 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
5572 struct target_waitstatus last
;
5575 get_last_target_status (&last_ptid
, &last
);
5577 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
5580 if (!ptid_equal (last_ptid
, pid
))
5583 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
5587 /* Oft used ptids */
5589 ptid_t minus_one_ptid
;
5591 /* Create a ptid given the necessary PID, LWP, and TID components. */
5594 ptid_build (int pid
, long lwp
, long tid
)
5604 /* Create a ptid from just a pid. */
5607 pid_to_ptid (int pid
)
5609 return ptid_build (pid
, 0, 0);
5612 /* Fetch the pid (process id) component from a ptid. */
5615 ptid_get_pid (ptid_t ptid
)
5620 /* Fetch the lwp (lightweight process) component from a ptid. */
5623 ptid_get_lwp (ptid_t ptid
)
5628 /* Fetch the tid (thread id) component from a ptid. */
5631 ptid_get_tid (ptid_t ptid
)
5636 /* ptid_equal() is used to test equality of two ptids. */
5639 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
5641 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
5642 && ptid1
.tid
== ptid2
.tid
);
5645 /* Returns true if PTID represents a process. */
5648 ptid_is_pid (ptid_t ptid
)
5650 if (ptid_equal (minus_one_ptid
, ptid
))
5652 if (ptid_equal (null_ptid
, ptid
))
5655 return (ptid_get_lwp (ptid
) == 0 && ptid_get_tid (ptid
) == 0);
5658 /* restore_inferior_ptid() will be used by the cleanup machinery
5659 to restore the inferior_ptid value saved in a call to
5660 save_inferior_ptid(). */
5663 restore_inferior_ptid (void *arg
)
5665 ptid_t
*saved_ptid_ptr
= arg
;
5666 inferior_ptid
= *saved_ptid_ptr
;
5670 /* Save the value of inferior_ptid so that it may be restored by a
5671 later call to do_cleanups(). Returns the struct cleanup pointer
5672 needed for later doing the cleanup. */
5675 save_inferior_ptid (void)
5677 ptid_t
*saved_ptid_ptr
;
5679 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
5680 *saved_ptid_ptr
= inferior_ptid
;
5681 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
5685 /* User interface for reverse debugging:
5686 Set exec-direction / show exec-direction commands
5687 (returns error unless target implements to_set_exec_direction method). */
5689 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
5690 static const char exec_forward
[] = "forward";
5691 static const char exec_reverse
[] = "reverse";
5692 static const char *exec_direction
= exec_forward
;
5693 static const char *exec_direction_names
[] = {
5700 set_exec_direction_func (char *args
, int from_tty
,
5701 struct cmd_list_element
*cmd
)
5703 if (target_can_execute_reverse
)
5705 if (!strcmp (exec_direction
, exec_forward
))
5706 execution_direction
= EXEC_FORWARD
;
5707 else if (!strcmp (exec_direction
, exec_reverse
))
5708 execution_direction
= EXEC_REVERSE
;
5713 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
5714 struct cmd_list_element
*cmd
, const char *value
)
5716 switch (execution_direction
) {
5718 fprintf_filtered (out
, _("Forward.\n"));
5721 fprintf_filtered (out
, _("Reverse.\n"));
5725 fprintf_filtered (out
,
5726 _("Forward (target `%s' does not support exec-direction).\n"),
5732 /* User interface for non-stop mode. */
5735 static int non_stop_1
= 0;
5738 set_non_stop (char *args
, int from_tty
,
5739 struct cmd_list_element
*c
)
5741 if (target_has_execution
)
5743 non_stop_1
= non_stop
;
5744 error (_("Cannot change this setting while the inferior is running."));
5747 non_stop
= non_stop_1
;
5751 show_non_stop (struct ui_file
*file
, int from_tty
,
5752 struct cmd_list_element
*c
, const char *value
)
5754 fprintf_filtered (file
,
5755 _("Controlling the inferior in non-stop mode is %s.\n"),
5760 show_schedule_multiple (struct ui_file
*file
, int from_tty
,
5761 struct cmd_list_element
*c
, const char *value
)
5763 fprintf_filtered (file
, _("\
5764 Resuming the execution of threads of all processes is %s.\n"), value
);
5768 _initialize_infrun (void)
5772 struct cmd_list_element
*c
;
5774 add_info ("signals", signals_info
, _("\
5775 What debugger does when program gets various signals.\n\
5776 Specify a signal as argument to print info on that signal only."));
5777 add_info_alias ("handle", "signals", 0);
5779 add_com ("handle", class_run
, handle_command
, _("\
5780 Specify how to handle a signal.\n\
5781 Args are signals and actions to apply to those signals.\n\
5782 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
5783 from 1-15 are allowed for compatibility with old versions of GDB.\n\
5784 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
5785 The special arg \"all\" is recognized to mean all signals except those\n\
5786 used by the debugger, typically SIGTRAP and SIGINT.\n\
5787 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
5788 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
5789 Stop means reenter debugger if this signal happens (implies print).\n\
5790 Print means print a message if this signal happens.\n\
5791 Pass means let program see this signal; otherwise program doesn't know.\n\
5792 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
5793 Pass and Stop may be combined."));
5796 add_com ("lz", class_info
, signals_info
, _("\
5797 What debugger does when program gets various signals.\n\
5798 Specify a signal as argument to print info on that signal only."));
5799 add_com ("z", class_run
, xdb_handle_command
, _("\
5800 Specify how to handle a signal.\n\
5801 Args are signals and actions to apply to those signals.\n\
5802 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
5803 from 1-15 are allowed for compatibility with old versions of GDB.\n\
5804 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
5805 The special arg \"all\" is recognized to mean all signals except those\n\
5806 used by the debugger, typically SIGTRAP and SIGINT.\n\
5807 Recognized actions include \"s\" (toggles between stop and nostop), \n\
5808 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
5809 nopass), \"Q\" (noprint)\n\
5810 Stop means reenter debugger if this signal happens (implies print).\n\
5811 Print means print a message if this signal happens.\n\
5812 Pass means let program see this signal; otherwise program doesn't know.\n\
5813 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
5814 Pass and Stop may be combined."));
5818 stop_command
= add_cmd ("stop", class_obscure
,
5819 not_just_help_class_command
, _("\
5820 There is no `stop' command, but you can set a hook on `stop'.\n\
5821 This allows you to set a list of commands to be run each time execution\n\
5822 of the program stops."), &cmdlist
);
5824 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
5825 Set inferior debugging."), _("\
5826 Show inferior debugging."), _("\
5827 When non-zero, inferior specific debugging is enabled."),
5830 &setdebuglist
, &showdebuglist
);
5832 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
5833 Set displaced stepping debugging."), _("\
5834 Show displaced stepping debugging."), _("\
5835 When non-zero, displaced stepping specific debugging is enabled."),
5837 show_debug_displaced
,
5838 &setdebuglist
, &showdebuglist
);
5840 add_setshow_boolean_cmd ("non-stop", no_class
,
5842 Set whether gdb controls the inferior in non-stop mode."), _("\
5843 Show whether gdb controls the inferior in non-stop mode."), _("\
5844 When debugging a multi-threaded program and this setting is\n\
5845 off (the default, also called all-stop mode), when one thread stops\n\
5846 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
5847 all other threads in the program while you interact with the thread of\n\
5848 interest. When you continue or step a thread, you can allow the other\n\
5849 threads to run, or have them remain stopped, but while you inspect any\n\
5850 thread's state, all threads stop.\n\
5852 In non-stop mode, when one thread stops, other threads can continue\n\
5853 to run freely. You'll be able to step each thread independently,\n\
5854 leave it stopped or free to run as needed."),
5860 numsigs
= (int) TARGET_SIGNAL_LAST
;
5861 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
5862 signal_print
= (unsigned char *)
5863 xmalloc (sizeof (signal_print
[0]) * numsigs
);
5864 signal_program
= (unsigned char *)
5865 xmalloc (sizeof (signal_program
[0]) * numsigs
);
5866 for (i
= 0; i
< numsigs
; i
++)
5869 signal_print
[i
] = 1;
5870 signal_program
[i
] = 1;
5873 /* Signals caused by debugger's own actions
5874 should not be given to the program afterwards. */
5875 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
5876 signal_program
[TARGET_SIGNAL_INT
] = 0;
5878 /* Signals that are not errors should not normally enter the debugger. */
5879 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
5880 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
5881 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
5882 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
5883 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
5884 signal_print
[TARGET_SIGNAL_PROF
] = 0;
5885 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
5886 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
5887 signal_stop
[TARGET_SIGNAL_IO
] = 0;
5888 signal_print
[TARGET_SIGNAL_IO
] = 0;
5889 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
5890 signal_print
[TARGET_SIGNAL_POLL
] = 0;
5891 signal_stop
[TARGET_SIGNAL_URG
] = 0;
5892 signal_print
[TARGET_SIGNAL_URG
] = 0;
5893 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
5894 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
5896 /* These signals are used internally by user-level thread
5897 implementations. (See signal(5) on Solaris.) Like the above
5898 signals, a healthy program receives and handles them as part of
5899 its normal operation. */
5900 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
5901 signal_print
[TARGET_SIGNAL_LWP
] = 0;
5902 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
5903 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
5904 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
5905 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
5907 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
5908 &stop_on_solib_events
, _("\
5909 Set stopping for shared library events."), _("\
5910 Show stopping for shared library events."), _("\
5911 If nonzero, gdb will give control to the user when the dynamic linker\n\
5912 notifies gdb of shared library events. The most common event of interest\n\
5913 to the user would be loading/unloading of a new library."),
5915 show_stop_on_solib_events
,
5916 &setlist
, &showlist
);
5918 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
5919 follow_fork_mode_kind_names
,
5920 &follow_fork_mode_string
, _("\
5921 Set debugger response to a program call of fork or vfork."), _("\
5922 Show debugger response to a program call of fork or vfork."), _("\
5923 A fork or vfork creates a new process. follow-fork-mode can be:\n\
5924 parent - the original process is debugged after a fork\n\
5925 child - the new process is debugged after a fork\n\
5926 The unfollowed process will continue to run.\n\
5927 By default, the debugger will follow the parent process."),
5929 show_follow_fork_mode_string
,
5930 &setlist
, &showlist
);
5932 add_setshow_enum_cmd ("scheduler-locking", class_run
,
5933 scheduler_enums
, &scheduler_mode
, _("\
5934 Set mode for locking scheduler during execution."), _("\
5935 Show mode for locking scheduler during execution."), _("\
5936 off == no locking (threads may preempt at any time)\n\
5937 on == full locking (no thread except the current thread may run)\n\
5938 step == scheduler locked during every single-step operation.\n\
5939 In this mode, no other thread may run during a step command.\n\
5940 Other threads may run while stepping over a function call ('next')."),
5941 set_schedlock_func
, /* traps on target vector */
5942 show_scheduler_mode
,
5943 &setlist
, &showlist
);
5945 add_setshow_boolean_cmd ("schedule-multiple", class_run
, &sched_multi
, _("\
5946 Set mode for resuming threads of all processes."), _("\
5947 Show mode for resuming threads of all processes."), _("\
5948 When on, execution commands (such as 'continue' or 'next') resume all\n\
5949 threads of all processes. When off (which is the default), execution\n\
5950 commands only resume the threads of the current process. The set of\n\
5951 threads that are resumed is further refined by the scheduler-locking\n\
5952 mode (see help set scheduler-locking)."),
5954 show_schedule_multiple
,
5955 &setlist
, &showlist
);
5957 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
5958 Set mode of the step operation."), _("\
5959 Show mode of the step operation."), _("\
5960 When set, doing a step over a function without debug line information\n\
5961 will stop at the first instruction of that function. Otherwise, the\n\
5962 function is skipped and the step command stops at a different source line."),
5964 show_step_stop_if_no_debug
,
5965 &setlist
, &showlist
);
5967 add_setshow_enum_cmd ("displaced-stepping", class_run
,
5968 can_use_displaced_stepping_enum
,
5969 &can_use_displaced_stepping
, _("\
5970 Set debugger's willingness to use displaced stepping."), _("\
5971 Show debugger's willingness to use displaced stepping."), _("\
5972 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
5973 supported by the target architecture. If off, gdb will not use displaced\n\
5974 stepping to step over breakpoints, even if such is supported by the target\n\
5975 architecture. If auto (which is the default), gdb will use displaced stepping\n\
5976 if the target architecture supports it and non-stop mode is active, but will not\n\
5977 use it in all-stop mode (see help set non-stop)."),
5979 show_can_use_displaced_stepping
,
5980 &setlist
, &showlist
);
5982 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
5983 &exec_direction
, _("Set direction of execution.\n\
5984 Options are 'forward' or 'reverse'."),
5985 _("Show direction of execution (forward/reverse)."),
5986 _("Tells gdb whether to execute forward or backward."),
5987 set_exec_direction_func
, show_exec_direction_func
,
5988 &setlist
, &showlist
);
5990 /* ptid initializations */
5991 null_ptid
= ptid_build (0, 0, 0);
5992 minus_one_ptid
= ptid_build (-1, 0, 0);
5993 inferior_ptid
= null_ptid
;
5994 target_last_wait_ptid
= minus_one_ptid
;
5995 displaced_step_ptid
= null_ptid
;
5997 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
5998 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
5999 observer_attach_thread_exit (infrun_thread_thread_exit
);
6001 /* Explicitly create without lookup, since that tries to create a
6002 value with a void typed value, and when we get here, gdbarch
6003 isn't initialized yet. At this point, we're quite sure there
6004 isn't another convenience variable of the same name. */
6005 create_internalvar_type_lazy ("_siginfo", siginfo_make_value
);