1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
6 2008, 2009 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
48 #include "gdb_assert.h"
49 #include "mi/mi-common.h"
50 #include "event-top.h"
53 /* Prototypes for local functions */
55 static void signals_info (char *, int);
57 static void handle_command (char *, int);
59 static void sig_print_info (enum target_signal
);
61 static void sig_print_header (void);
63 static void resume_cleanups (void *);
65 static int hook_stop_stub (void *);
67 static int restore_selected_frame (void *);
69 static void build_infrun (void);
71 static int follow_fork (void);
73 static void set_schedlock_func (char *args
, int from_tty
,
74 struct cmd_list_element
*c
);
76 static int currently_stepping (struct thread_info
*tp
);
78 static int currently_stepping_callback (struct thread_info
*tp
, void *data
);
80 static void xdb_handle_command (char *args
, int from_tty
);
82 static int prepare_to_proceed (int);
84 void _initialize_infrun (void);
86 /* When set, stop the 'step' command if we enter a function which has
87 no line number information. The normal behavior is that we step
88 over such function. */
89 int step_stop_if_no_debug
= 0;
91 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
92 struct cmd_list_element
*c
, const char *value
)
94 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
97 /* In asynchronous mode, but simulating synchronous execution. */
99 int sync_execution
= 0;
101 /* wait_for_inferior and normal_stop use this to notify the user
102 when the inferior stopped in a different thread than it had been
105 static ptid_t previous_inferior_ptid
;
107 int debug_displaced
= 0;
109 show_debug_displaced (struct ui_file
*file
, int from_tty
,
110 struct cmd_list_element
*c
, const char *value
)
112 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
115 static int debug_infrun
= 0;
117 show_debug_infrun (struct ui_file
*file
, int from_tty
,
118 struct cmd_list_element
*c
, const char *value
)
120 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
123 /* If the program uses ELF-style shared libraries, then calls to
124 functions in shared libraries go through stubs, which live in a
125 table called the PLT (Procedure Linkage Table). The first time the
126 function is called, the stub sends control to the dynamic linker,
127 which looks up the function's real address, patches the stub so
128 that future calls will go directly to the function, and then passes
129 control to the function.
131 If we are stepping at the source level, we don't want to see any of
132 this --- we just want to skip over the stub and the dynamic linker.
133 The simple approach is to single-step until control leaves the
136 However, on some systems (e.g., Red Hat's 5.2 distribution) the
137 dynamic linker calls functions in the shared C library, so you
138 can't tell from the PC alone whether the dynamic linker is still
139 running. In this case, we use a step-resume breakpoint to get us
140 past the dynamic linker, as if we were using "next" to step over a
143 in_solib_dynsym_resolve_code() says whether we're in the dynamic
144 linker code or not. Normally, this means we single-step. However,
145 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
146 address where we can place a step-resume breakpoint to get past the
147 linker's symbol resolution function.
149 in_solib_dynsym_resolve_code() can generally be implemented in a
150 pretty portable way, by comparing the PC against the address ranges
151 of the dynamic linker's sections.
153 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
154 it depends on internal details of the dynamic linker. It's usually
155 not too hard to figure out where to put a breakpoint, but it
156 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
157 sanity checking. If it can't figure things out, returning zero and
158 getting the (possibly confusing) stepping behavior is better than
159 signalling an error, which will obscure the change in the
162 /* This function returns TRUE if pc is the address of an instruction
163 that lies within the dynamic linker (such as the event hook, or the
166 This function must be used only when a dynamic linker event has
167 been caught, and the inferior is being stepped out of the hook, or
168 undefined results are guaranteed. */
170 #ifndef SOLIB_IN_DYNAMIC_LINKER
171 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
175 /* Convert the #defines into values. This is temporary until wfi control
176 flow is completely sorted out. */
178 #ifndef CANNOT_STEP_HW_WATCHPOINTS
179 #define CANNOT_STEP_HW_WATCHPOINTS 0
181 #undef CANNOT_STEP_HW_WATCHPOINTS
182 #define CANNOT_STEP_HW_WATCHPOINTS 1
185 /* Tables of how to react to signals; the user sets them. */
187 static unsigned char *signal_stop
;
188 static unsigned char *signal_print
;
189 static unsigned char *signal_program
;
191 #define SET_SIGS(nsigs,sigs,flags) \
193 int signum = (nsigs); \
194 while (signum-- > 0) \
195 if ((sigs)[signum]) \
196 (flags)[signum] = 1; \
199 #define UNSET_SIGS(nsigs,sigs,flags) \
201 int signum = (nsigs); \
202 while (signum-- > 0) \
203 if ((sigs)[signum]) \
204 (flags)[signum] = 0; \
207 /* Value to pass to target_resume() to cause all threads to resume */
209 #define RESUME_ALL (pid_to_ptid (-1))
211 /* Command list pointer for the "stop" placeholder. */
213 static struct cmd_list_element
*stop_command
;
215 /* Function inferior was in as of last step command. */
217 static struct symbol
*step_start_function
;
219 /* Nonzero if we want to give control to the user when we're notified
220 of shared library events by the dynamic linker. */
221 static int stop_on_solib_events
;
223 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
224 struct cmd_list_element
*c
, const char *value
)
226 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
230 /* Nonzero means expecting a trace trap
231 and should stop the inferior and return silently when it happens. */
235 /* Save register contents here when executing a "finish" command or are
236 about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set.
237 Thus this contains the return value from the called function (assuming
238 values are returned in a register). */
240 struct regcache
*stop_registers
;
242 /* Nonzero after stop if current stack frame should be printed. */
244 static int stop_print_frame
;
246 /* This is a cached copy of the pid/waitstatus of the last event
247 returned by target_wait()/deprecated_target_wait_hook(). This
248 information is returned by get_last_target_status(). */
249 static ptid_t target_last_wait_ptid
;
250 static struct target_waitstatus target_last_waitstatus
;
252 static void context_switch (ptid_t ptid
);
254 void init_thread_stepping_state (struct thread_info
*tss
);
256 void init_infwait_state (void);
258 /* This is used to remember when a fork, vfork or exec event
259 was caught by a catchpoint, and thus the event is to be
260 followed at the next resume of the inferior, and not
264 enum target_waitkind kind
;
274 static const char follow_fork_mode_child
[] = "child";
275 static const char follow_fork_mode_parent
[] = "parent";
277 static const char *follow_fork_mode_kind_names
[] = {
278 follow_fork_mode_child
,
279 follow_fork_mode_parent
,
283 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
285 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
286 struct cmd_list_element
*c
, const char *value
)
288 fprintf_filtered (file
, _("\
289 Debugger response to a program call of fork or vfork is \"%s\".\n"),
297 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
299 return target_follow_fork (follow_child
);
303 follow_inferior_reset_breakpoints (void)
305 struct thread_info
*tp
= inferior_thread ();
307 /* Was there a step_resume breakpoint? (There was if the user
308 did a "next" at the fork() call.) If so, explicitly reset its
311 step_resumes are a form of bp that are made to be per-thread.
312 Since we created the step_resume bp when the parent process
313 was being debugged, and now are switching to the child process,
314 from the breakpoint package's viewpoint, that's a switch of
315 "threads". We must update the bp's notion of which thread
316 it is for, or it'll be ignored when it triggers. */
318 if (tp
->step_resume_breakpoint
)
319 breakpoint_re_set_thread (tp
->step_resume_breakpoint
);
321 /* Reinsert all breakpoints in the child. The user may have set
322 breakpoints after catching the fork, in which case those
323 were never set in the child, but only in the parent. This makes
324 sure the inserted breakpoints match the breakpoint list. */
326 breakpoint_re_set ();
327 insert_breakpoints ();
330 /* EXECD_PATHNAME is assumed to be non-NULL. */
333 follow_exec (ptid_t pid
, char *execd_pathname
)
335 struct target_ops
*tgt
;
336 struct thread_info
*th
= inferior_thread ();
338 /* This is an exec event that we actually wish to pay attention to.
339 Refresh our symbol table to the newly exec'd program, remove any
342 If there are breakpoints, they aren't really inserted now,
343 since the exec() transformed our inferior into a fresh set
346 We want to preserve symbolic breakpoints on the list, since
347 we have hopes that they can be reset after the new a.out's
348 symbol table is read.
350 However, any "raw" breakpoints must be removed from the list
351 (e.g., the solib bp's), since their address is probably invalid
354 And, we DON'T want to call delete_breakpoints() here, since
355 that may write the bp's "shadow contents" (the instruction
356 value that was overwritten witha TRAP instruction). Since
357 we now have a new a.out, those shadow contents aren't valid. */
358 update_breakpoints_after_exec ();
360 /* If there was one, it's gone now. We cannot truly step-to-next
361 statement through an exec(). */
362 th
->step_resume_breakpoint
= NULL
;
363 th
->step_range_start
= 0;
364 th
->step_range_end
= 0;
366 /* What is this a.out's name? */
367 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
369 /* We've followed the inferior through an exec. Therefore, the
370 inferior has essentially been killed & reborn. */
372 gdb_flush (gdb_stdout
);
374 breakpoint_init_inferior (inf_execd
);
376 if (gdb_sysroot
&& *gdb_sysroot
)
378 char *name
= alloca (strlen (gdb_sysroot
)
379 + strlen (execd_pathname
)
381 strcpy (name
, gdb_sysroot
);
382 strcat (name
, execd_pathname
);
383 execd_pathname
= name
;
386 /* That a.out is now the one to use. */
387 exec_file_attach (execd_pathname
, 0);
389 /* Reset the shared library package. This ensures that we get a
390 shlib event when the child reaches "_start", at which point the
391 dld will have had a chance to initialize the child. */
392 /* Also, loading a symbol file below may trigger symbol lookups, and
393 we don't want those to be satisfied by the libraries of the
394 previous incarnation of this process. */
395 no_shared_libraries (NULL
, 0);
397 /* Load the main file's symbols. */
398 symbol_file_add_main (execd_pathname
, 0);
400 #ifdef SOLIB_CREATE_INFERIOR_HOOK
401 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
403 solib_create_inferior_hook ();
406 /* Reinsert all breakpoints. (Those which were symbolic have
407 been reset to the proper address in the new a.out, thanks
408 to symbol_file_command...) */
409 insert_breakpoints ();
411 /* The next resume of this inferior should bring it to the shlib
412 startup breakpoints. (If the user had also set bp's on
413 "main" from the old (parent) process, then they'll auto-
414 matically get reset there in the new process.) */
417 /* Non-zero if we just simulating a single-step. This is needed
418 because we cannot remove the breakpoints in the inferior process
419 until after the `wait' in `wait_for_inferior'. */
420 static int singlestep_breakpoints_inserted_p
= 0;
422 /* The thread we inserted single-step breakpoints for. */
423 static ptid_t singlestep_ptid
;
425 /* PC when we started this single-step. */
426 static CORE_ADDR singlestep_pc
;
428 /* If another thread hit the singlestep breakpoint, we save the original
429 thread here so that we can resume single-stepping it later. */
430 static ptid_t saved_singlestep_ptid
;
431 static int stepping_past_singlestep_breakpoint
;
433 /* If not equal to null_ptid, this means that after stepping over breakpoint
434 is finished, we need to switch to deferred_step_ptid, and step it.
436 The use case is when one thread has hit a breakpoint, and then the user
437 has switched to another thread and issued 'step'. We need to step over
438 breakpoint in the thread which hit the breakpoint, but then continue
439 stepping the thread user has selected. */
440 static ptid_t deferred_step_ptid
;
442 /* Displaced stepping. */
444 /* In non-stop debugging mode, we must take special care to manage
445 breakpoints properly; in particular, the traditional strategy for
446 stepping a thread past a breakpoint it has hit is unsuitable.
447 'Displaced stepping' is a tactic for stepping one thread past a
448 breakpoint it has hit while ensuring that other threads running
449 concurrently will hit the breakpoint as they should.
451 The traditional way to step a thread T off a breakpoint in a
452 multi-threaded program in all-stop mode is as follows:
454 a0) Initially, all threads are stopped, and breakpoints are not
456 a1) We single-step T, leaving breakpoints uninserted.
457 a2) We insert breakpoints, and resume all threads.
459 In non-stop debugging, however, this strategy is unsuitable: we
460 don't want to have to stop all threads in the system in order to
461 continue or step T past a breakpoint. Instead, we use displaced
464 n0) Initially, T is stopped, other threads are running, and
465 breakpoints are inserted.
466 n1) We copy the instruction "under" the breakpoint to a separate
467 location, outside the main code stream, making any adjustments
468 to the instruction, register, and memory state as directed by
470 n2) We single-step T over the instruction at its new location.
471 n3) We adjust the resulting register and memory state as directed
472 by T's architecture. This includes resetting T's PC to point
473 back into the main instruction stream.
476 This approach depends on the following gdbarch methods:
478 - gdbarch_max_insn_length and gdbarch_displaced_step_location
479 indicate where to copy the instruction, and how much space must
480 be reserved there. We use these in step n1.
482 - gdbarch_displaced_step_copy_insn copies a instruction to a new
483 address, and makes any necessary adjustments to the instruction,
484 register contents, and memory. We use this in step n1.
486 - gdbarch_displaced_step_fixup adjusts registers and memory after
487 we have successfuly single-stepped the instruction, to yield the
488 same effect the instruction would have had if we had executed it
489 at its original address. We use this in step n3.
491 - gdbarch_displaced_step_free_closure provides cleanup.
493 The gdbarch_displaced_step_copy_insn and
494 gdbarch_displaced_step_fixup functions must be written so that
495 copying an instruction with gdbarch_displaced_step_copy_insn,
496 single-stepping across the copied instruction, and then applying
497 gdbarch_displaced_insn_fixup should have the same effects on the
498 thread's memory and registers as stepping the instruction in place
499 would have. Exactly which responsibilities fall to the copy and
500 which fall to the fixup is up to the author of those functions.
502 See the comments in gdbarch.sh for details.
504 Note that displaced stepping and software single-step cannot
505 currently be used in combination, although with some care I think
506 they could be made to. Software single-step works by placing
507 breakpoints on all possible subsequent instructions; if the
508 displaced instruction is a PC-relative jump, those breakpoints
509 could fall in very strange places --- on pages that aren't
510 executable, or at addresses that are not proper instruction
511 boundaries. (We do generally let other threads run while we wait
512 to hit the software single-step breakpoint, and they might
513 encounter such a corrupted instruction.) One way to work around
514 this would be to have gdbarch_displaced_step_copy_insn fully
515 simulate the effect of PC-relative instructions (and return NULL)
516 on architectures that use software single-stepping.
518 In non-stop mode, we can have independent and simultaneous step
519 requests, so more than one thread may need to simultaneously step
520 over a breakpoint. The current implementation assumes there is
521 only one scratch space per process. In this case, we have to
522 serialize access to the scratch space. If thread A wants to step
523 over a breakpoint, but we are currently waiting for some other
524 thread to complete a displaced step, we leave thread A stopped and
525 place it in the displaced_step_request_queue. Whenever a displaced
526 step finishes, we pick the next thread in the queue and start a new
527 displaced step operation on it. See displaced_step_prepare and
528 displaced_step_fixup for details. */
530 /* If this is not null_ptid, this is the thread carrying out a
531 displaced single-step. This thread's state will require fixing up
532 once it has completed its step. */
533 static ptid_t displaced_step_ptid
;
535 struct displaced_step_request
538 struct displaced_step_request
*next
;
541 /* A queue of pending displaced stepping requests. */
542 struct displaced_step_request
*displaced_step_request_queue
;
544 /* The architecture the thread had when we stepped it. */
545 static struct gdbarch
*displaced_step_gdbarch
;
547 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
548 for post-step cleanup. */
549 static struct displaced_step_closure
*displaced_step_closure
;
551 /* The address of the original instruction, and the copy we made. */
552 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
554 /* Saved contents of copy area. */
555 static gdb_byte
*displaced_step_saved_copy
;
557 /* Enum strings for "set|show displaced-stepping". */
559 static const char can_use_displaced_stepping_auto
[] = "auto";
560 static const char can_use_displaced_stepping_on
[] = "on";
561 static const char can_use_displaced_stepping_off
[] = "off";
562 static const char *can_use_displaced_stepping_enum
[] =
564 can_use_displaced_stepping_auto
,
565 can_use_displaced_stepping_on
,
566 can_use_displaced_stepping_off
,
570 /* If ON, and the architecture supports it, GDB will use displaced
571 stepping to step over breakpoints. If OFF, or if the architecture
572 doesn't support it, GDB will instead use the traditional
573 hold-and-step approach. If AUTO (which is the default), GDB will
574 decide which technique to use to step over breakpoints depending on
575 which of all-stop or non-stop mode is active --- displaced stepping
576 in non-stop mode; hold-and-step in all-stop mode. */
578 static const char *can_use_displaced_stepping
=
579 can_use_displaced_stepping_auto
;
582 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
583 struct cmd_list_element
*c
,
586 if (can_use_displaced_stepping
== can_use_displaced_stepping_auto
)
587 fprintf_filtered (file
, _("\
588 Debugger's willingness to use displaced stepping to step over \
589 breakpoints is %s (currently %s).\n"),
590 value
, non_stop
? "on" : "off");
592 fprintf_filtered (file
, _("\
593 Debugger's willingness to use displaced stepping to step over \
594 breakpoints is %s.\n"), value
);
597 /* Return non-zero if displaced stepping can/should be used to step
601 use_displaced_stepping (struct gdbarch
*gdbarch
)
603 return (((can_use_displaced_stepping
== can_use_displaced_stepping_auto
605 || can_use_displaced_stepping
== can_use_displaced_stepping_on
)
606 && gdbarch_displaced_step_copy_insn_p (gdbarch
)
610 /* Clean out any stray displaced stepping state. */
612 displaced_step_clear (void)
614 /* Indicate that there is no cleanup pending. */
615 displaced_step_ptid
= null_ptid
;
617 if (displaced_step_closure
)
619 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
620 displaced_step_closure
);
621 displaced_step_closure
= NULL
;
626 cleanup_displaced_step_closure (void *ptr
)
628 struct displaced_step_closure
*closure
= ptr
;
630 gdbarch_displaced_step_free_closure (current_gdbarch
, closure
);
633 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
635 displaced_step_dump_bytes (struct ui_file
*file
,
641 for (i
= 0; i
< len
; i
++)
642 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
643 fputs_unfiltered ("\n", file
);
646 /* Prepare to single-step, using displaced stepping.
648 Note that we cannot use displaced stepping when we have a signal to
649 deliver. If we have a signal to deliver and an instruction to step
650 over, then after the step, there will be no indication from the
651 target whether the thread entered a signal handler or ignored the
652 signal and stepped over the instruction successfully --- both cases
653 result in a simple SIGTRAP. In the first case we mustn't do a
654 fixup, and in the second case we must --- but we can't tell which.
655 Comments in the code for 'random signals' in handle_inferior_event
656 explain how we handle this case instead.
658 Returns 1 if preparing was successful -- this thread is going to be
659 stepped now; or 0 if displaced stepping this thread got queued. */
661 displaced_step_prepare (ptid_t ptid
)
663 struct cleanup
*old_cleanups
, *ignore_cleanups
;
664 struct regcache
*regcache
= get_thread_regcache (ptid
);
665 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
666 CORE_ADDR original
, copy
;
668 struct displaced_step_closure
*closure
;
670 /* We should never reach this function if the architecture does not
671 support displaced stepping. */
672 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
674 /* For the first cut, we're displaced stepping one thread at a
677 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
679 /* Already waiting for a displaced step to finish. Defer this
680 request and place in queue. */
681 struct displaced_step_request
*req
, *new_req
;
684 fprintf_unfiltered (gdb_stdlog
,
685 "displaced: defering step of %s\n",
686 target_pid_to_str (ptid
));
688 new_req
= xmalloc (sizeof (*new_req
));
689 new_req
->ptid
= ptid
;
690 new_req
->next
= NULL
;
692 if (displaced_step_request_queue
)
694 for (req
= displaced_step_request_queue
;
701 displaced_step_request_queue
= new_req
;
708 fprintf_unfiltered (gdb_stdlog
,
709 "displaced: stepping %s now\n",
710 target_pid_to_str (ptid
));
713 displaced_step_clear ();
715 old_cleanups
= save_inferior_ptid ();
716 inferior_ptid
= ptid
;
718 original
= regcache_read_pc (regcache
);
720 copy
= gdbarch_displaced_step_location (gdbarch
);
721 len
= gdbarch_max_insn_length (gdbarch
);
723 /* Save the original contents of the copy area. */
724 displaced_step_saved_copy
= xmalloc (len
);
725 ignore_cleanups
= make_cleanup (free_current_contents
,
726 &displaced_step_saved_copy
);
727 read_memory (copy
, displaced_step_saved_copy
, len
);
730 fprintf_unfiltered (gdb_stdlog
, "displaced: saved 0x%s: ",
732 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
735 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
736 original
, copy
, regcache
);
738 /* We don't support the fully-simulated case at present. */
739 gdb_assert (closure
);
741 make_cleanup (cleanup_displaced_step_closure
, closure
);
743 /* Resume execution at the copy. */
744 regcache_write_pc (regcache
, copy
);
746 discard_cleanups (ignore_cleanups
);
748 do_cleanups (old_cleanups
);
751 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to 0x%s\n",
754 /* Save the information we need to fix things up if the step
756 displaced_step_ptid
= ptid
;
757 displaced_step_gdbarch
= gdbarch
;
758 displaced_step_closure
= closure
;
759 displaced_step_original
= original
;
760 displaced_step_copy
= copy
;
765 displaced_step_clear_cleanup (void *ignore
)
767 displaced_step_clear ();
771 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
773 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
774 inferior_ptid
= ptid
;
775 write_memory (memaddr
, myaddr
, len
);
776 do_cleanups (ptid_cleanup
);
780 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
782 struct cleanup
*old_cleanups
;
784 /* Was this event for the pid we displaced? */
785 if (ptid_equal (displaced_step_ptid
, null_ptid
)
786 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
789 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
791 /* Restore the contents of the copy area. */
793 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
794 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
795 displaced_step_saved_copy
, len
);
797 fprintf_unfiltered (gdb_stdlog
, "displaced: restored 0x%s\n",
798 paddr_nz (displaced_step_copy
));
801 /* Did the instruction complete successfully? */
802 if (signal
== TARGET_SIGNAL_TRAP
)
804 /* Fix up the resulting state. */
805 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
806 displaced_step_closure
,
807 displaced_step_original
,
809 get_thread_regcache (displaced_step_ptid
));
813 /* Since the instruction didn't complete, all we can do is
815 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
816 CORE_ADDR pc
= regcache_read_pc (regcache
);
817 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
818 regcache_write_pc (regcache
, pc
);
821 do_cleanups (old_cleanups
);
823 displaced_step_ptid
= null_ptid
;
825 /* Are there any pending displaced stepping requests? If so, run
827 while (displaced_step_request_queue
)
829 struct displaced_step_request
*head
;
833 head
= displaced_step_request_queue
;
835 displaced_step_request_queue
= head
->next
;
838 context_switch (ptid
);
840 actual_pc
= regcache_read_pc (get_thread_regcache (ptid
));
842 if (breakpoint_here_p (actual_pc
))
845 fprintf_unfiltered (gdb_stdlog
,
846 "displaced: stepping queued %s now\n",
847 target_pid_to_str (ptid
));
849 displaced_step_prepare (ptid
);
855 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
856 paddr_nz (actual_pc
));
857 read_memory (actual_pc
, buf
, sizeof (buf
));
858 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
861 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
863 /* Done, we're stepping a thread. */
869 struct thread_info
*tp
= inferior_thread ();
871 /* The breakpoint we were sitting under has since been
873 tp
->trap_expected
= 0;
875 /* Go back to what we were trying to do. */
876 step
= currently_stepping (tp
);
879 fprintf_unfiltered (gdb_stdlog
, "breakpoint is gone %s: step(%d)\n",
880 target_pid_to_str (tp
->ptid
), step
);
882 target_resume (ptid
, step
, TARGET_SIGNAL_0
);
883 tp
->stop_signal
= TARGET_SIGNAL_0
;
885 /* This request was discarded. See if there's any other
886 thread waiting for its turn. */
891 /* Update global variables holding ptids to hold NEW_PTID if they were
894 infrun_thread_ptid_changed (ptid_t old_ptid
, ptid_t new_ptid
)
896 struct displaced_step_request
*it
;
898 if (ptid_equal (inferior_ptid
, old_ptid
))
899 inferior_ptid
= new_ptid
;
901 if (ptid_equal (singlestep_ptid
, old_ptid
))
902 singlestep_ptid
= new_ptid
;
904 if (ptid_equal (displaced_step_ptid
, old_ptid
))
905 displaced_step_ptid
= new_ptid
;
907 if (ptid_equal (deferred_step_ptid
, old_ptid
))
908 deferred_step_ptid
= new_ptid
;
910 for (it
= displaced_step_request_queue
; it
; it
= it
->next
)
911 if (ptid_equal (it
->ptid
, old_ptid
))
918 /* Things to clean up if we QUIT out of resume (). */
920 resume_cleanups (void *ignore
)
925 static const char schedlock_off
[] = "off";
926 static const char schedlock_on
[] = "on";
927 static const char schedlock_step
[] = "step";
928 static const char *scheduler_enums
[] = {
934 static const char *scheduler_mode
= schedlock_off
;
936 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
937 struct cmd_list_element
*c
, const char *value
)
939 fprintf_filtered (file
, _("\
940 Mode for locking scheduler during execution is \"%s\".\n"),
945 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
947 if (!target_can_lock_scheduler
)
949 scheduler_mode
= schedlock_off
;
950 error (_("Target '%s' cannot support this command."), target_shortname
);
954 /* Try to setup for software single stepping over the specified location.
955 Return 1 if target_resume() should use hardware single step.
957 GDBARCH the current gdbarch.
958 PC the location to step over. */
961 maybe_software_singlestep (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
965 if (gdbarch_software_single_step_p (gdbarch
)
966 && gdbarch_software_single_step (gdbarch
, get_current_frame ()))
969 /* Do not pull these breakpoints until after a `wait' in
970 `wait_for_inferior' */
971 singlestep_breakpoints_inserted_p
= 1;
972 singlestep_ptid
= inferior_ptid
;
978 /* Resume the inferior, but allow a QUIT. This is useful if the user
979 wants to interrupt some lengthy single-stepping operation
980 (for child processes, the SIGINT goes to the inferior, and so
981 we get a SIGINT random_signal, but for remote debugging and perhaps
982 other targets, that's not true).
984 STEP nonzero if we should step (zero to continue instead).
985 SIG is the signal to give the inferior (zero for none). */
987 resume (int step
, enum target_signal sig
)
989 int should_resume
= 1;
990 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
992 /* Note that these must be reset if we follow a fork below. */
993 struct regcache
*regcache
= get_current_regcache ();
994 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
995 struct thread_info
*tp
= inferior_thread ();
996 CORE_ADDR pc
= regcache_read_pc (regcache
);
1001 fprintf_unfiltered (gdb_stdlog
,
1002 "infrun: resume (step=%d, signal=%d), "
1003 "trap_expected=%d\n",
1004 step
, sig
, tp
->trap_expected
);
1006 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
1007 over an instruction that causes a page fault without triggering
1008 a hardware watchpoint. The kernel properly notices that it shouldn't
1009 stop, because the hardware watchpoint is not triggered, but it forgets
1010 the step request and continues the program normally.
1011 Work around the problem by removing hardware watchpoints if a step is
1012 requested, GDB will check for a hardware watchpoint trigger after the
1014 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
1015 remove_hw_watchpoints ();
1018 /* Normally, by the time we reach `resume', the breakpoints are either
1019 removed or inserted, as appropriate. The exception is if we're sitting
1020 at a permanent breakpoint; we need to step over it, but permanent
1021 breakpoints can't be removed. So we have to test for it here. */
1022 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
1024 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
1025 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
1028 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1029 how to step past a permanent breakpoint on this architecture. Try using\n\
1030 a command like `return' or `jump' to continue execution."));
1033 /* If enabled, step over breakpoints by executing a copy of the
1034 instruction at a different address.
1036 We can't use displaced stepping when we have a signal to deliver;
1037 the comments for displaced_step_prepare explain why. The
1038 comments in the handle_inferior event for dealing with 'random
1039 signals' explain what we do instead. */
1040 if (use_displaced_stepping (gdbarch
)
1041 && tp
->trap_expected
1042 && sig
== TARGET_SIGNAL_0
)
1044 if (!displaced_step_prepare (inferior_ptid
))
1046 /* Got placed in displaced stepping queue. Will be resumed
1047 later when all the currently queued displaced stepping
1048 requests finish. The thread is not executing at this point,
1049 and the call to set_executing will be made later. But we
1050 need to call set_running here, since from frontend point of view,
1051 the thread is running. */
1052 set_running (inferior_ptid
, 1);
1053 discard_cleanups (old_cleanups
);
1058 /* Do we need to do it the hard way, w/temp breakpoints? */
1060 step
= maybe_software_singlestep (gdbarch
, pc
);
1062 /* If there were any forks/vforks/execs that were caught and are
1063 now to be followed, then do so. */
1064 switch (pending_follow
.kind
)
1066 case TARGET_WAITKIND_FORKED
:
1067 case TARGET_WAITKIND_VFORKED
:
1068 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
1072 /* Following a child fork will change our notion of current
1074 tp
= inferior_thread ();
1075 regcache
= get_current_regcache ();
1076 gdbarch
= get_regcache_arch (regcache
);
1077 pc
= regcache_read_pc (regcache
);
1084 /* Install inferior's terminal modes. */
1085 target_terminal_inferior ();
1091 resume_ptid
= RESUME_ALL
; /* Default */
1093 /* If STEP is set, it's a request to use hardware stepping
1094 facilities. But in that case, we should never
1095 use singlestep breakpoint. */
1096 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1098 if (singlestep_breakpoints_inserted_p
1099 && stepping_past_singlestep_breakpoint
)
1101 /* The situation here is as follows. In thread T1 we wanted to
1102 single-step. Lacking hardware single-stepping we've
1103 set breakpoint at the PC of the next instruction -- call it
1104 P. After resuming, we've hit that breakpoint in thread T2.
1105 Now we've removed original breakpoint, inserted breakpoint
1106 at P+1, and try to step to advance T2 past breakpoint.
1107 We need to step only T2, as if T1 is allowed to freely run,
1108 it can run past P, and if other threads are allowed to run,
1109 they can hit breakpoint at P+1, and nested hits of single-step
1110 breakpoints is not something we'd want -- that's complicated
1111 to support, and has no value. */
1112 resume_ptid
= inferior_ptid
;
1115 if ((step
|| singlestep_breakpoints_inserted_p
)
1116 && tp
->trap_expected
)
1118 /* We're allowing a thread to run past a breakpoint it has
1119 hit, by single-stepping the thread with the breakpoint
1120 removed. In which case, we need to single-step only this
1121 thread, and keep others stopped, as they can miss this
1122 breakpoint if allowed to run.
1124 The current code actually removes all breakpoints when
1125 doing this, not just the one being stepped over, so if we
1126 let other threads run, we can actually miss any
1127 breakpoint, not just the one at PC. */
1128 resume_ptid
= inferior_ptid
;
1133 /* With non-stop mode on, threads are always handled
1135 resume_ptid
= inferior_ptid
;
1137 else if ((scheduler_mode
== schedlock_on
)
1138 || (scheduler_mode
== schedlock_step
1139 && (step
|| singlestep_breakpoints_inserted_p
)))
1141 /* User-settable 'scheduler' mode requires solo thread resume. */
1142 resume_ptid
= inferior_ptid
;
1145 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1147 /* Most targets can step a breakpoint instruction, thus
1148 executing it normally. But if this one cannot, just
1149 continue and we will hit it anyway. */
1150 if (step
&& breakpoint_inserted_here_p (pc
))
1155 && use_displaced_stepping (gdbarch
)
1156 && tp
->trap_expected
)
1158 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1159 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1162 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
1163 paddr_nz (actual_pc
));
1164 read_memory (actual_pc
, buf
, sizeof (buf
));
1165 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1168 /* Avoid confusing the next resume, if the next stop/resume
1169 happens to apply to another thread. */
1170 tp
->stop_signal
= TARGET_SIGNAL_0
;
1172 target_resume (resume_ptid
, step
, sig
);
1175 discard_cleanups (old_cleanups
);
1180 /* Clear out all variables saying what to do when inferior is continued.
1181 First do this, then set the ones you want, then call `proceed'. */
1184 clear_proceed_status_thread (struct thread_info
*tp
)
1187 fprintf_unfiltered (gdb_stdlog
,
1188 "infrun: clear_proceed_status_thread (%s)\n",
1189 target_pid_to_str (tp
->ptid
));
1191 tp
->trap_expected
= 0;
1192 tp
->step_range_start
= 0;
1193 tp
->step_range_end
= 0;
1194 tp
->step_frame_id
= null_frame_id
;
1195 tp
->step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1196 tp
->stop_requested
= 0;
1200 tp
->proceed_to_finish
= 0;
1202 /* Discard any remaining commands or status from previous stop. */
1203 bpstat_clear (&tp
->stop_bpstat
);
1207 clear_proceed_status_callback (struct thread_info
*tp
, void *data
)
1209 if (is_exited (tp
->ptid
))
1212 clear_proceed_status_thread (tp
);
1217 clear_proceed_status (void)
1219 if (!ptid_equal (inferior_ptid
, null_ptid
))
1221 struct inferior
*inferior
;
1225 /* If in non-stop mode, only delete the per-thread status
1226 of the current thread. */
1227 clear_proceed_status_thread (inferior_thread ());
1231 /* In all-stop mode, delete the per-thread status of
1233 iterate_over_threads (clear_proceed_status_callback
, NULL
);
1236 inferior
= current_inferior ();
1237 inferior
->stop_soon
= NO_STOP_QUIETLY
;
1240 stop_after_trap
= 0;
1242 observer_notify_about_to_proceed ();
1246 regcache_xfree (stop_registers
);
1247 stop_registers
= NULL
;
1251 /* This should be suitable for any targets that support threads. */
1254 prepare_to_proceed (int step
)
1257 struct target_waitstatus wait_status
;
1259 /* Get the last target status returned by target_wait(). */
1260 get_last_target_status (&wait_ptid
, &wait_status
);
1262 /* Make sure we were stopped at a breakpoint. */
1263 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1264 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1269 /* Switched over from WAIT_PID. */
1270 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1271 && !ptid_equal (inferior_ptid
, wait_ptid
))
1273 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1275 if (breakpoint_here_p (regcache_read_pc (regcache
)))
1277 /* If stepping, remember current thread to switch back to. */
1279 deferred_step_ptid
= inferior_ptid
;
1281 /* Switch back to WAIT_PID thread. */
1282 switch_to_thread (wait_ptid
);
1284 /* We return 1 to indicate that there is a breakpoint here,
1285 so we need to step over it before continuing to avoid
1286 hitting it straight away. */
1294 /* Basic routine for continuing the program in various fashions.
1296 ADDR is the address to resume at, or -1 for resume where stopped.
1297 SIGGNAL is the signal to give it, or 0 for none,
1298 or -1 for act according to how it stopped.
1299 STEP is nonzero if should trap after one instruction.
1300 -1 means return after that and print nothing.
1301 You should probably set various step_... variables
1302 before calling here, if you are stepping.
1304 You should call clear_proceed_status before calling proceed. */
1307 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1309 struct regcache
*regcache
= get_current_regcache ();
1310 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1311 struct thread_info
*tp
;
1312 CORE_ADDR pc
= regcache_read_pc (regcache
);
1316 step_start_function
= find_pc_function (pc
);
1318 stop_after_trap
= 1;
1320 if (addr
== (CORE_ADDR
) -1)
1322 if (pc
== stop_pc
&& breakpoint_here_p (pc
)
1323 && execution_direction
!= EXEC_REVERSE
)
1324 /* There is a breakpoint at the address we will resume at,
1325 step one instruction before inserting breakpoints so that
1326 we do not stop right away (and report a second hit at this
1329 Note, we don't do this in reverse, because we won't
1330 actually be executing the breakpoint insn anyway.
1331 We'll be (un-)executing the previous instruction. */
1334 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1335 && gdbarch_single_step_through_delay (gdbarch
,
1336 get_current_frame ()))
1337 /* We stepped onto an instruction that needs to be stepped
1338 again before re-inserting the breakpoint, do so. */
1343 regcache_write_pc (regcache
, addr
);
1347 fprintf_unfiltered (gdb_stdlog
,
1348 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1349 paddr_nz (addr
), siggnal
, step
);
1352 /* In non-stop, each thread is handled individually. The context
1353 must already be set to the right thread here. */
1357 /* In a multi-threaded task we may select another thread and
1358 then continue or step.
1360 But if the old thread was stopped at a breakpoint, it will
1361 immediately cause another breakpoint stop without any
1362 execution (i.e. it will report a breakpoint hit incorrectly).
1363 So we must step over it first.
1365 prepare_to_proceed checks the current thread against the
1366 thread that reported the most recent event. If a step-over
1367 is required it returns TRUE and sets the current thread to
1369 if (prepare_to_proceed (step
))
1373 /* prepare_to_proceed may change the current thread. */
1374 tp
= inferior_thread ();
1378 tp
->trap_expected
= 1;
1379 /* If displaced stepping is enabled, we can step over the
1380 breakpoint without hitting it, so leave all breakpoints
1381 inserted. Otherwise we need to disable all breakpoints, step
1382 one instruction, and then re-add them when that step is
1384 if (!use_displaced_stepping (gdbarch
))
1385 remove_breakpoints ();
1388 /* We can insert breakpoints if we're not trying to step over one,
1389 or if we are stepping over one but we're using displaced stepping
1391 if (! tp
->trap_expected
|| use_displaced_stepping (gdbarch
))
1392 insert_breakpoints ();
1396 /* Pass the last stop signal to the thread we're resuming,
1397 irrespective of whether the current thread is the thread that
1398 got the last event or not. This was historically GDB's
1399 behaviour before keeping a stop_signal per thread. */
1401 struct thread_info
*last_thread
;
1403 struct target_waitstatus last_status
;
1405 get_last_target_status (&last_ptid
, &last_status
);
1406 if (!ptid_equal (inferior_ptid
, last_ptid
)
1407 && !ptid_equal (last_ptid
, null_ptid
)
1408 && !ptid_equal (last_ptid
, minus_one_ptid
))
1410 last_thread
= find_thread_pid (last_ptid
);
1413 tp
->stop_signal
= last_thread
->stop_signal
;
1414 last_thread
->stop_signal
= TARGET_SIGNAL_0
;
1419 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1420 tp
->stop_signal
= siggnal
;
1421 /* If this signal should not be seen by program,
1422 give it zero. Used for debugging signals. */
1423 else if (!signal_program
[tp
->stop_signal
])
1424 tp
->stop_signal
= TARGET_SIGNAL_0
;
1426 annotate_starting ();
1428 /* Make sure that output from GDB appears before output from the
1430 gdb_flush (gdb_stdout
);
1432 /* Refresh prev_pc value just prior to resuming. This used to be
1433 done in stop_stepping, however, setting prev_pc there did not handle
1434 scenarios such as inferior function calls or returning from
1435 a function via the return command. In those cases, the prev_pc
1436 value was not set properly for subsequent commands. The prev_pc value
1437 is used to initialize the starting line number in the ecs. With an
1438 invalid value, the gdb next command ends up stopping at the position
1439 represented by the next line table entry past our start position.
1440 On platforms that generate one line table entry per line, this
1441 is not a problem. However, on the ia64, the compiler generates
1442 extraneous line table entries that do not increase the line number.
1443 When we issue the gdb next command on the ia64 after an inferior call
1444 or a return command, we often end up a few instructions forward, still
1445 within the original line we started.
1447 An attempt was made to have init_execution_control_state () refresh
1448 the prev_pc value before calculating the line number. This approach
1449 did not work because on platforms that use ptrace, the pc register
1450 cannot be read unless the inferior is stopped. At that point, we
1451 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1452 call can fail. Setting the prev_pc value here ensures the value is
1453 updated correctly when the inferior is stopped. */
1454 tp
->prev_pc
= regcache_read_pc (get_current_regcache ());
1456 /* Fill in with reasonable starting values. */
1457 init_thread_stepping_state (tp
);
1459 /* Reset to normal state. */
1460 init_infwait_state ();
1462 /* Resume inferior. */
1463 resume (oneproc
|| step
|| bpstat_should_step (), tp
->stop_signal
);
1465 /* Wait for it to stop (if not standalone)
1466 and in any case decode why it stopped, and act accordingly. */
1467 /* Do this only if we are not using the event loop, or if the target
1468 does not support asynchronous execution. */
1469 if (!target_can_async_p ())
1471 wait_for_inferior (0);
1477 /* Start remote-debugging of a machine over a serial link. */
1480 start_remote (int from_tty
)
1482 struct inferior
*inferior
;
1483 init_wait_for_inferior ();
1485 inferior
= current_inferior ();
1486 inferior
->stop_soon
= STOP_QUIETLY_REMOTE
;
1488 /* Always go on waiting for the target, regardless of the mode. */
1489 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1490 indicate to wait_for_inferior that a target should timeout if
1491 nothing is returned (instead of just blocking). Because of this,
1492 targets expecting an immediate response need to, internally, set
1493 things up so that the target_wait() is forced to eventually
1495 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1496 differentiate to its caller what the state of the target is after
1497 the initial open has been performed. Here we're assuming that
1498 the target has stopped. It should be possible to eventually have
1499 target_open() return to the caller an indication that the target
1500 is currently running and GDB state should be set to the same as
1501 for an async run. */
1502 wait_for_inferior (0);
1504 /* Now that the inferior has stopped, do any bookkeeping like
1505 loading shared libraries. We want to do this before normal_stop,
1506 so that the displayed frame is up to date. */
1507 post_create_inferior (¤t_target
, from_tty
);
1512 /* Initialize static vars when a new inferior begins. */
1515 init_wait_for_inferior (void)
1517 /* These are meaningless until the first time through wait_for_inferior. */
1519 breakpoint_init_inferior (inf_starting
);
1521 /* The first resume is not following a fork/vfork/exec. */
1522 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1524 clear_proceed_status ();
1526 stepping_past_singlestep_breakpoint
= 0;
1527 deferred_step_ptid
= null_ptid
;
1529 target_last_wait_ptid
= minus_one_ptid
;
1531 previous_inferior_ptid
= null_ptid
;
1532 init_infwait_state ();
1534 displaced_step_clear ();
1538 /* This enum encodes possible reasons for doing a target_wait, so that
1539 wfi can call target_wait in one place. (Ultimately the call will be
1540 moved out of the infinite loop entirely.) */
1544 infwait_normal_state
,
1545 infwait_thread_hop_state
,
1546 infwait_step_watch_state
,
1547 infwait_nonstep_watch_state
1550 /* Why did the inferior stop? Used to print the appropriate messages
1551 to the interface from within handle_inferior_event(). */
1552 enum inferior_stop_reason
1554 /* Step, next, nexti, stepi finished. */
1556 /* Inferior terminated by signal. */
1558 /* Inferior exited. */
1560 /* Inferior received signal, and user asked to be notified. */
1562 /* Reverse execution -- target ran out of history info. */
1566 /* The PTID we'll do a target_wait on.*/
1569 /* Current inferior wait state. */
1570 enum infwait_states infwait_state
;
1572 /* Data to be passed around while handling an event. This data is
1573 discarded between events. */
1574 struct execution_control_state
1577 /* The thread that got the event, if this was a thread event; NULL
1579 struct thread_info
*event_thread
;
1581 struct target_waitstatus ws
;
1583 CORE_ADDR stop_func_start
;
1584 CORE_ADDR stop_func_end
;
1585 char *stop_func_name
;
1586 int new_thread_event
;
1590 void init_execution_control_state (struct execution_control_state
*ecs
);
1592 void handle_inferior_event (struct execution_control_state
*ecs
);
1594 static void handle_step_into_function (struct execution_control_state
*ecs
);
1595 static void handle_step_into_function_backward (struct execution_control_state
*ecs
);
1596 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1597 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1598 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
1599 struct frame_id sr_id
);
1600 static void insert_longjmp_resume_breakpoint (CORE_ADDR
);
1602 static void stop_stepping (struct execution_control_state
*ecs
);
1603 static void prepare_to_wait (struct execution_control_state
*ecs
);
1604 static void keep_going (struct execution_control_state
*ecs
);
1605 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1608 /* Callback for iterate over threads. If the thread is stopped, but
1609 the user/frontend doesn't know about that yet, go through
1610 normal_stop, as if the thread had just stopped now. ARG points at
1611 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
1612 ptid_is_pid(PTID) is true, applies to all threads of the process
1613 pointed at by PTID. Otherwise, apply only to the thread pointed by
1617 infrun_thread_stop_requested_callback (struct thread_info
*info
, void *arg
)
1619 ptid_t ptid
= * (ptid_t
*) arg
;
1621 if ((ptid_equal (info
->ptid
, ptid
)
1622 || ptid_equal (minus_one_ptid
, ptid
)
1623 || (ptid_is_pid (ptid
)
1624 && ptid_get_pid (ptid
) == ptid_get_pid (info
->ptid
)))
1625 && is_running (info
->ptid
)
1626 && !is_executing (info
->ptid
))
1628 struct cleanup
*old_chain
;
1629 struct execution_control_state ecss
;
1630 struct execution_control_state
*ecs
= &ecss
;
1632 memset (ecs
, 0, sizeof (*ecs
));
1634 old_chain
= make_cleanup_restore_current_thread ();
1636 switch_to_thread (info
->ptid
);
1638 /* Go through handle_inferior_event/normal_stop, so we always
1639 have consistent output as if the stop event had been
1641 ecs
->ptid
= info
->ptid
;
1642 ecs
->event_thread
= find_thread_pid (info
->ptid
);
1643 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1644 ecs
->ws
.value
.sig
= TARGET_SIGNAL_0
;
1646 handle_inferior_event (ecs
);
1648 if (!ecs
->wait_some_more
)
1650 struct thread_info
*tp
;
1654 /* Finish off the continuations. The continations
1655 themselves are responsible for realising the thread
1656 didn't finish what it was supposed to do. */
1657 tp
= inferior_thread ();
1658 do_all_intermediate_continuations_thread (tp
);
1659 do_all_continuations_thread (tp
);
1662 do_cleanups (old_chain
);
1668 /* This function is attached as a "thread_stop_requested" observer.
1669 Cleanup local state that assumed the PTID was to be resumed, and
1670 report the stop to the frontend. */
1673 infrun_thread_stop_requested (ptid_t ptid
)
1675 struct displaced_step_request
*it
, *next
, *prev
= NULL
;
1677 /* PTID was requested to stop. Remove it from the displaced
1678 stepping queue, so we don't try to resume it automatically. */
1679 for (it
= displaced_step_request_queue
; it
; it
= next
)
1683 if (ptid_equal (it
->ptid
, ptid
)
1684 || ptid_equal (minus_one_ptid
, ptid
)
1685 || (ptid_is_pid (ptid
)
1686 && ptid_get_pid (ptid
) == ptid_get_pid (it
->ptid
)))
1688 if (displaced_step_request_queue
== it
)
1689 displaced_step_request_queue
= it
->next
;
1691 prev
->next
= it
->next
;
1699 iterate_over_threads (infrun_thread_stop_requested_callback
, &ptid
);
1702 void nullify_last_target_wait_ptid (void);
1705 infrun_thread_thread_exit (struct thread_info
*tp
, int silent
)
1707 if (ptid_equal (target_last_wait_ptid
, tp
->ptid
))
1708 nullify_last_target_wait_ptid ();
1711 /* Callback for iterate_over_threads. */
1714 delete_step_resume_breakpoint_callback (struct thread_info
*info
, void *data
)
1716 if (is_exited (info
->ptid
))
1719 delete_step_resume_breakpoint (info
);
1723 /* In all-stop, delete the step resume breakpoint of any thread that
1724 had one. In non-stop, delete the step resume breakpoint of the
1725 thread that just stopped. */
1728 delete_step_thread_step_resume_breakpoint (void)
1730 if (!target_has_execution
1731 || ptid_equal (inferior_ptid
, null_ptid
))
1732 /* If the inferior has exited, we have already deleted the step
1733 resume breakpoints out of GDB's lists. */
1738 /* If in non-stop mode, only delete the step-resume or
1739 longjmp-resume breakpoint of the thread that just stopped
1741 struct thread_info
*tp
= inferior_thread ();
1742 delete_step_resume_breakpoint (tp
);
1745 /* In all-stop mode, delete all step-resume and longjmp-resume
1746 breakpoints of any thread that had them. */
1747 iterate_over_threads (delete_step_resume_breakpoint_callback
, NULL
);
1750 /* A cleanup wrapper. */
1753 delete_step_thread_step_resume_breakpoint_cleanup (void *arg
)
1755 delete_step_thread_step_resume_breakpoint ();
1758 /* Pretty print the results of target_wait, for debugging purposes. */
1761 print_target_wait_results (ptid_t waiton_ptid
, ptid_t result_ptid
,
1762 const struct target_waitstatus
*ws
)
1764 char *status_string
= target_waitstatus_to_string (ws
);
1765 struct ui_file
*tmp_stream
= mem_fileopen ();
1769 /* The text is split over several lines because it was getting too long.
1770 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
1771 output as a unit; we want only one timestamp printed if debug_timestamp
1774 fprintf_unfiltered (tmp_stream
,
1775 "infrun: target_wait (%d", PIDGET (waiton_ptid
));
1776 if (PIDGET (waiton_ptid
) != -1)
1777 fprintf_unfiltered (tmp_stream
,
1778 " [%s]", target_pid_to_str (waiton_ptid
));
1779 fprintf_unfiltered (tmp_stream
, ", status) =\n");
1780 fprintf_unfiltered (tmp_stream
,
1781 "infrun: %d [%s],\n",
1782 PIDGET (result_ptid
), target_pid_to_str (result_ptid
));
1783 fprintf_unfiltered (tmp_stream
,
1787 text
= ui_file_xstrdup (tmp_stream
, &len
);
1789 /* This uses %s in part to handle %'s in the text, but also to avoid
1790 a gcc error: the format attribute requires a string literal. */
1791 fprintf_unfiltered (gdb_stdlog
, "%s", text
);
1793 xfree (status_string
);
1795 ui_file_delete (tmp_stream
);
1798 /* Wait for control to return from inferior to debugger.
1800 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1801 as if they were SIGTRAP signals. This can be useful during
1802 the startup sequence on some targets such as HP/UX, where
1803 we receive an EXEC event instead of the expected SIGTRAP.
1805 If inferior gets a signal, we may decide to start it up again
1806 instead of returning. That is why there is a loop in this function.
1807 When this function actually returns it means the inferior
1808 should be left stopped and GDB should read more commands. */
1811 wait_for_inferior (int treat_exec_as_sigtrap
)
1813 struct cleanup
*old_cleanups
;
1814 struct execution_control_state ecss
;
1815 struct execution_control_state
*ecs
;
1819 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1820 treat_exec_as_sigtrap
);
1823 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup
, NULL
);
1826 memset (ecs
, 0, sizeof (*ecs
));
1828 overlay_cache_invalid
= 1;
1830 /* We'll update this if & when we switch to a new thread. */
1831 previous_inferior_ptid
= inferior_ptid
;
1833 /* We have to invalidate the registers BEFORE calling target_wait
1834 because they can be loaded from the target while in target_wait.
1835 This makes remote debugging a bit more efficient for those
1836 targets that provide critical registers as part of their normal
1837 status mechanism. */
1839 registers_changed ();
1843 struct cleanup
*old_chain
;
1845 if (deprecated_target_wait_hook
)
1846 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1848 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1851 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
1853 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1855 xfree (ecs
->ws
.value
.execd_pathname
);
1856 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1857 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
1860 /* If an error happens while handling the event, propagate GDB's
1861 knowledge of the executing state to the frontend/user running
1863 old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
1865 /* Now figure out what to do with the result of the result. */
1866 handle_inferior_event (ecs
);
1868 /* No error, don't finish the state yet. */
1869 discard_cleanups (old_chain
);
1871 if (!ecs
->wait_some_more
)
1875 do_cleanups (old_cleanups
);
1878 /* Asynchronous version of wait_for_inferior. It is called by the
1879 event loop whenever a change of state is detected on the file
1880 descriptor corresponding to the target. It can be called more than
1881 once to complete a single execution command. In such cases we need
1882 to keep the state in a global variable ECSS. If it is the last time
1883 that this function is called for a single execution command, then
1884 report to the user that the inferior has stopped, and do the
1885 necessary cleanups. */
1888 fetch_inferior_event (void *client_data
)
1890 struct execution_control_state ecss
;
1891 struct execution_control_state
*ecs
= &ecss
;
1892 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
1893 struct cleanup
*ts_old_chain
;
1894 int was_sync
= sync_execution
;
1896 memset (ecs
, 0, sizeof (*ecs
));
1898 overlay_cache_invalid
= 1;
1900 /* We can only rely on wait_for_more being correct before handling
1901 the event in all-stop, but previous_inferior_ptid isn't used in
1903 if (!ecs
->wait_some_more
)
1904 /* We'll update this if & when we switch to a new thread. */
1905 previous_inferior_ptid
= inferior_ptid
;
1908 /* In non-stop mode, the user/frontend should not notice a thread
1909 switch due to internal events. Make sure we reverse to the
1910 user selected thread and frame after handling the event and
1911 running any breakpoint commands. */
1912 make_cleanup_restore_current_thread ();
1914 /* We have to invalidate the registers BEFORE calling target_wait
1915 because they can be loaded from the target while in target_wait.
1916 This makes remote debugging a bit more efficient for those
1917 targets that provide critical registers as part of their normal
1918 status mechanism. */
1920 registers_changed ();
1922 if (deprecated_target_wait_hook
)
1924 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1926 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1929 print_target_wait_results (waiton_ptid
, ecs
->ptid
, &ecs
->ws
);
1932 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
1933 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1934 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
1935 /* In non-stop mode, each thread is handled individually. Switch
1936 early, so the global state is set correctly for this
1938 context_switch (ecs
->ptid
);
1940 /* If an error happens while handling the event, propagate GDB's
1941 knowledge of the executing state to the frontend/user running
1944 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
1946 ts_old_chain
= make_cleanup (finish_thread_state_cleanup
, &ecs
->ptid
);
1948 /* Now figure out what to do with the result of the result. */
1949 handle_inferior_event (ecs
);
1951 if (!ecs
->wait_some_more
)
1953 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
1955 delete_step_thread_step_resume_breakpoint ();
1957 /* We may not find an inferior if this was a process exit. */
1958 if (inf
== NULL
|| inf
->stop_soon
== NO_STOP_QUIETLY
)
1961 if (target_has_execution
1962 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1963 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
1964 && ecs
->event_thread
->step_multi
1965 && ecs
->event_thread
->stop_step
)
1966 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1968 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1971 /* No error, don't finish the thread states yet. */
1972 discard_cleanups (ts_old_chain
);
1974 /* Revert thread and frame. */
1975 do_cleanups (old_chain
);
1977 /* If the inferior was in sync execution mode, and now isn't,
1978 restore the prompt. */
1979 if (was_sync
&& !sync_execution
)
1980 display_gdb_prompt (0);
1983 /* Prepare an execution control state for looping through a
1984 wait_for_inferior-type loop. */
1987 init_execution_control_state (struct execution_control_state
*ecs
)
1989 ecs
->random_signal
= 0;
1992 /* Clear context switchable stepping state. */
1995 init_thread_stepping_state (struct thread_info
*tss
)
1997 struct symtab_and_line sal
;
1999 tss
->stepping_over_breakpoint
= 0;
2000 tss
->step_after_step_resume_breakpoint
= 0;
2001 tss
->stepping_through_solib_after_catch
= 0;
2002 tss
->stepping_through_solib_catchpoints
= NULL
;
2004 sal
= find_pc_line (tss
->prev_pc
, 0);
2005 tss
->current_line
= sal
.line
;
2006 tss
->current_symtab
= sal
.symtab
;
2009 /* Return the cached copy of the last pid/waitstatus returned by
2010 target_wait()/deprecated_target_wait_hook(). The data is actually
2011 cached by handle_inferior_event(), which gets called immediately
2012 after target_wait()/deprecated_target_wait_hook(). */
2015 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
2017 *ptidp
= target_last_wait_ptid
;
2018 *status
= target_last_waitstatus
;
2022 nullify_last_target_wait_ptid (void)
2024 target_last_wait_ptid
= minus_one_ptid
;
2027 /* Switch thread contexts. */
2030 context_switch (ptid_t ptid
)
2034 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
2035 target_pid_to_str (inferior_ptid
));
2036 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
2037 target_pid_to_str (ptid
));
2040 switch_to_thread (ptid
);
2044 adjust_pc_after_break (struct execution_control_state
*ecs
)
2046 struct regcache
*regcache
;
2047 struct gdbarch
*gdbarch
;
2048 CORE_ADDR breakpoint_pc
;
2050 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2051 we aren't, just return.
2053 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2054 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2055 implemented by software breakpoints should be handled through the normal
2058 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2059 different signals (SIGILL or SIGEMT for instance), but it is less
2060 clear where the PC is pointing afterwards. It may not match
2061 gdbarch_decr_pc_after_break. I don't know any specific target that
2062 generates these signals at breakpoints (the code has been in GDB since at
2063 least 1992) so I can not guess how to handle them here.
2065 In earlier versions of GDB, a target with
2066 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2067 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2068 target with both of these set in GDB history, and it seems unlikely to be
2069 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2071 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
2074 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
2077 /* In reverse execution, when a breakpoint is hit, the instruction
2078 under it has already been de-executed. The reported PC always
2079 points at the breakpoint address, so adjusting it further would
2080 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2083 B1 0x08000000 : INSN1
2084 B2 0x08000001 : INSN2
2086 PC -> 0x08000003 : INSN4
2088 Say you're stopped at 0x08000003 as above. Reverse continuing
2089 from that point should hit B2 as below. Reading the PC when the
2090 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2091 been de-executed already.
2093 B1 0x08000000 : INSN1
2094 B2 PC -> 0x08000001 : INSN2
2098 We can't apply the same logic as for forward execution, because
2099 we would wrongly adjust the PC to 0x08000000, since there's a
2100 breakpoint at PC - 1. We'd then report a hit on B1, although
2101 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2103 if (execution_direction
== EXEC_REVERSE
)
2106 /* If this target does not decrement the PC after breakpoints, then
2107 we have nothing to do. */
2108 regcache
= get_thread_regcache (ecs
->ptid
);
2109 gdbarch
= get_regcache_arch (regcache
);
2110 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
2113 /* Find the location where (if we've hit a breakpoint) the
2114 breakpoint would be. */
2115 breakpoint_pc
= regcache_read_pc (regcache
)
2116 - gdbarch_decr_pc_after_break (gdbarch
);
2118 /* Check whether there actually is a software breakpoint inserted at
2121 If in non-stop mode, a race condition is possible where we've
2122 removed a breakpoint, but stop events for that breakpoint were
2123 already queued and arrive later. To suppress those spurious
2124 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2125 and retire them after a number of stop events are reported. */
2126 if (software_breakpoint_inserted_here_p (breakpoint_pc
)
2127 || (non_stop
&& moribund_breakpoint_here_p (breakpoint_pc
)))
2129 struct cleanup
*old_cleanups
= NULL
;
2131 old_cleanups
= record_gdb_operation_disable_set ();
2133 /* When using hardware single-step, a SIGTRAP is reported for both
2134 a completed single-step and a software breakpoint. Need to
2135 differentiate between the two, as the latter needs adjusting
2136 but the former does not.
2138 The SIGTRAP can be due to a completed hardware single-step only if
2139 - we didn't insert software single-step breakpoints
2140 - the thread to be examined is still the current thread
2141 - this thread is currently being stepped
2143 If any of these events did not occur, we must have stopped due
2144 to hitting a software breakpoint, and have to back up to the
2147 As a special case, we could have hardware single-stepped a
2148 software breakpoint. In this case (prev_pc == breakpoint_pc),
2149 we also need to back up to the breakpoint address. */
2151 if (singlestep_breakpoints_inserted_p
2152 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
2153 || !currently_stepping (ecs
->event_thread
)
2154 || ecs
->event_thread
->prev_pc
== breakpoint_pc
)
2155 regcache_write_pc (regcache
, breakpoint_pc
);
2158 do_cleanups (old_cleanups
);
2163 init_infwait_state (void)
2165 waiton_ptid
= pid_to_ptid (-1);
2166 infwait_state
= infwait_normal_state
;
2170 error_is_running (void)
2173 Cannot execute this command while the selected thread is running."));
2177 ensure_not_running (void)
2179 if (is_running (inferior_ptid
))
2180 error_is_running ();
2183 /* Given an execution control state that has been freshly filled in
2184 by an event from the inferior, figure out what it means and take
2185 appropriate action. */
2188 handle_inferior_event (struct execution_control_state
*ecs
)
2190 int sw_single_step_trap_p
= 0;
2191 int stopped_by_watchpoint
;
2192 int stepped_after_stopped_by_watchpoint
= 0;
2193 struct symtab_and_line stop_pc_sal
;
2194 enum stop_kind stop_soon
;
2196 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2197 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2198 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
2200 struct inferior
*inf
= find_inferior_pid (ptid_get_pid (ecs
->ptid
));
2202 stop_soon
= inf
->stop_soon
;
2205 stop_soon
= NO_STOP_QUIETLY
;
2207 /* Cache the last pid/waitstatus. */
2208 target_last_wait_ptid
= ecs
->ptid
;
2209 target_last_waitstatus
= ecs
->ws
;
2211 /* Always clear state belonging to the previous time we stopped. */
2212 stop_stack_dummy
= 0;
2214 /* If it's a new process, add it to the thread database */
2216 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
2217 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
2218 && !in_thread_list (ecs
->ptid
));
2220 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
2221 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
2222 add_thread (ecs
->ptid
);
2224 ecs
->event_thread
= find_thread_pid (ecs
->ptid
);
2226 /* Dependent on valid ECS->EVENT_THREAD. */
2227 adjust_pc_after_break (ecs
);
2229 /* Dependent on the current PC value modified by adjust_pc_after_break. */
2230 reinit_frame_cache ();
2232 if (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
2234 breakpoint_retire_moribund ();
2236 /* Mark the non-executing threads accordingly. In all-stop, all
2237 threads of all processes are stopped when we get any event
2238 reported. In non-stop mode, only the event thread stops. If
2239 we're handling a process exit in non-stop mode, there's
2240 nothing to do, as threads of the dead process are gone, and
2241 threads of any other process were left running. */
2243 set_executing (minus_one_ptid
, 0);
2244 else if (ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
2245 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
)
2246 set_executing (inferior_ptid
, 0);
2249 switch (infwait_state
)
2251 case infwait_thread_hop_state
:
2253 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
2254 /* Cancel the waiton_ptid. */
2255 waiton_ptid
= pid_to_ptid (-1);
2258 case infwait_normal_state
:
2260 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
2263 case infwait_step_watch_state
:
2265 fprintf_unfiltered (gdb_stdlog
,
2266 "infrun: infwait_step_watch_state\n");
2268 stepped_after_stopped_by_watchpoint
= 1;
2271 case infwait_nonstep_watch_state
:
2273 fprintf_unfiltered (gdb_stdlog
,
2274 "infrun: infwait_nonstep_watch_state\n");
2275 insert_breakpoints ();
2277 /* FIXME-maybe: is this cleaner than setting a flag? Does it
2278 handle things like signals arriving and other things happening
2279 in combination correctly? */
2280 stepped_after_stopped_by_watchpoint
= 1;
2284 internal_error (__FILE__
, __LINE__
, _("bad switch"));
2286 infwait_state
= infwait_normal_state
;
2288 switch (ecs
->ws
.kind
)
2290 case TARGET_WAITKIND_LOADED
:
2292 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
2293 /* Ignore gracefully during startup of the inferior, as it might
2294 be the shell which has just loaded some objects, otherwise
2295 add the symbols for the newly loaded objects. Also ignore at
2296 the beginning of an attach or remote session; we will query
2297 the full list of libraries once the connection is
2299 if (stop_soon
== NO_STOP_QUIETLY
)
2301 /* Check for any newly added shared libraries if we're
2302 supposed to be adding them automatically. Switch
2303 terminal for any messages produced by
2304 breakpoint_re_set. */
2305 target_terminal_ours_for_output ();
2306 /* NOTE: cagney/2003-11-25: Make certain that the target
2307 stack's section table is kept up-to-date. Architectures,
2308 (e.g., PPC64), use the section table to perform
2309 operations such as address => section name and hence
2310 require the table to contain all sections (including
2311 those found in shared libraries). */
2312 /* NOTE: cagney/2003-11-25: Pass current_target and not
2313 exec_ops to SOLIB_ADD. This is because current GDB is
2314 only tooled to propagate section_table changes out from
2315 the "current_target" (see target_resize_to_sections), and
2316 not up from the exec stratum. This, of course, isn't
2317 right. "infrun.c" should only interact with the
2318 exec/process stratum, instead relying on the target stack
2319 to propagate relevant changes (stop, section table
2320 changed, ...) up to other layers. */
2322 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2324 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2326 target_terminal_inferior ();
2328 /* If requested, stop when the dynamic linker notifies
2329 gdb of events. This allows the user to get control
2330 and place breakpoints in initializer routines for
2331 dynamically loaded objects (among other things). */
2332 if (stop_on_solib_events
)
2334 stop_stepping (ecs
);
2338 /* NOTE drow/2007-05-11: This might be a good place to check
2339 for "catch load". */
2342 /* If we are skipping through a shell, or through shared library
2343 loading that we aren't interested in, resume the program. If
2344 we're running the program normally, also resume. But stop if
2345 we're attaching or setting up a remote connection. */
2346 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
2348 /* Loading of shared libraries might have changed breakpoint
2349 addresses. Make sure new breakpoints are inserted. */
2350 if (stop_soon
== NO_STOP_QUIETLY
2351 && !breakpoints_always_inserted_mode ())
2352 insert_breakpoints ();
2353 resume (0, TARGET_SIGNAL_0
);
2354 prepare_to_wait (ecs
);
2360 case TARGET_WAITKIND_SPURIOUS
:
2362 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
2363 resume (0, TARGET_SIGNAL_0
);
2364 prepare_to_wait (ecs
);
2367 case TARGET_WAITKIND_EXITED
:
2369 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
2370 inferior_ptid
= ecs
->ptid
;
2371 target_terminal_ours (); /* Must do this before mourn anyway */
2372 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
2374 /* Record the exit code in the convenience variable $_exitcode, so
2375 that the user can inspect this again later. */
2376 set_internalvar (lookup_internalvar ("_exitcode"),
2377 value_from_longest (builtin_type_int32
,
2378 (LONGEST
) ecs
->ws
.value
.integer
));
2379 gdb_flush (gdb_stdout
);
2380 target_mourn_inferior ();
2381 singlestep_breakpoints_inserted_p
= 0;
2382 stop_print_frame
= 0;
2383 stop_stepping (ecs
);
2386 case TARGET_WAITKIND_SIGNALLED
:
2388 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
2389 inferior_ptid
= ecs
->ptid
;
2390 stop_print_frame
= 0;
2391 target_terminal_ours (); /* Must do this before mourn anyway */
2393 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
2394 reach here unless the inferior is dead. However, for years
2395 target_kill() was called here, which hints that fatal signals aren't
2396 really fatal on some systems. If that's true, then some changes
2398 target_mourn_inferior ();
2400 print_stop_reason (SIGNAL_EXITED
, ecs
->ws
.value
.sig
);
2401 singlestep_breakpoints_inserted_p
= 0;
2402 stop_stepping (ecs
);
2405 /* The following are the only cases in which we keep going;
2406 the above cases end in a continue or goto. */
2407 case TARGET_WAITKIND_FORKED
:
2408 case TARGET_WAITKIND_VFORKED
:
2410 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
2411 pending_follow
.kind
= ecs
->ws
.kind
;
2413 pending_follow
.fork_event
.parent_pid
= ecs
->ptid
;
2414 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
2416 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2418 context_switch (ecs
->ptid
);
2419 reinit_frame_cache ();
2422 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2424 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2426 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2428 /* If no catchpoint triggered for this, then keep going. */
2429 if (ecs
->random_signal
)
2431 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2435 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2436 goto process_event_stop_test
;
2438 case TARGET_WAITKIND_EXECD
:
2440 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
2442 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2444 context_switch (ecs
->ptid
);
2445 reinit_frame_cache ();
2448 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2450 /* This causes the eventpoints and symbol table to be reset.
2451 Must do this now, before trying to determine whether to
2453 follow_exec (inferior_ptid
, ecs
->ws
.value
.execd_pathname
);
2455 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2456 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
2458 /* Note that this may be referenced from inside
2459 bpstat_stop_status above, through inferior_has_execd. */
2460 xfree (ecs
->ws
.value
.execd_pathname
);
2461 ecs
->ws
.value
.execd_pathname
= NULL
;
2463 /* If no catchpoint triggered for this, then keep going. */
2464 if (ecs
->random_signal
)
2466 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2470 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
2471 goto process_event_stop_test
;
2473 /* Be careful not to try to gather much state about a thread
2474 that's in a syscall. It's frequently a losing proposition. */
2475 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2477 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2478 resume (0, TARGET_SIGNAL_0
);
2479 prepare_to_wait (ecs
);
2482 /* Before examining the threads further, step this thread to
2483 get it entirely out of the syscall. (We get notice of the
2484 event when the thread is just on the verge of exiting a
2485 syscall. Stepping one instruction seems to get it back
2487 case TARGET_WAITKIND_SYSCALL_RETURN
:
2489 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2490 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2491 prepare_to_wait (ecs
);
2494 case TARGET_WAITKIND_STOPPED
:
2496 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
2497 ecs
->event_thread
->stop_signal
= ecs
->ws
.value
.sig
;
2500 case TARGET_WAITKIND_NO_HISTORY
:
2501 /* Reverse execution: target ran out of history info. */
2502 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2503 print_stop_reason (NO_HISTORY
, 0);
2504 stop_stepping (ecs
);
2507 /* We had an event in the inferior, but we are not interested
2508 in handling it at this level. The lower layers have already
2509 done what needs to be done, if anything.
2511 One of the possible circumstances for this is when the
2512 inferior produces output for the console. The inferior has
2513 not stopped, and we are ignoring the event. Another possible
2514 circumstance is any event which the lower level knows will be
2515 reported multiple times without an intervening resume. */
2516 case TARGET_WAITKIND_IGNORE
:
2518 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2519 prepare_to_wait (ecs
);
2523 if (ecs
->new_thread_event
)
2526 /* Non-stop assumes that the target handles adding new threads
2527 to the thread list. */
2528 internal_error (__FILE__
, __LINE__
, "\
2529 targets should add new threads to the thread list themselves in non-stop mode.");
2531 /* We may want to consider not doing a resume here in order to
2532 give the user a chance to play with the new thread. It might
2533 be good to make that a user-settable option. */
2535 /* At this point, all threads are stopped (happens automatically
2536 in either the OS or the native code). Therefore we need to
2537 continue all threads in order to make progress. */
2539 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
2540 prepare_to_wait (ecs
);
2544 if (ecs
->ws
.kind
== TARGET_WAITKIND_STOPPED
)
2546 /* Do we need to clean up the state of a thread that has
2547 completed a displaced single-step? (Doing so usually affects
2548 the PC, so do it here, before we set stop_pc.) */
2549 displaced_step_fixup (ecs
->ptid
, ecs
->event_thread
->stop_signal
);
2551 /* If we either finished a single-step or hit a breakpoint, but
2552 the user wanted this thread to be stopped, pretend we got a
2553 SIG0 (generic unsignaled stop). */
2555 if (ecs
->event_thread
->stop_requested
2556 && ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2557 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2560 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2564 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n",
2565 paddr_nz (stop_pc
));
2566 if (target_stopped_by_watchpoint ())
2569 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2571 if (target_stopped_data_address (¤t_target
, &addr
))
2572 fprintf_unfiltered (gdb_stdlog
,
2573 "infrun: stopped data address = 0x%s\n",
2576 fprintf_unfiltered (gdb_stdlog
,
2577 "infrun: (no data address available)\n");
2581 if (stepping_past_singlestep_breakpoint
)
2583 gdb_assert (singlestep_breakpoints_inserted_p
);
2584 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2585 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2587 stepping_past_singlestep_breakpoint
= 0;
2589 /* We've either finished single-stepping past the single-step
2590 breakpoint, or stopped for some other reason. It would be nice if
2591 we could tell, but we can't reliably. */
2592 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2595 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2596 /* Pull the single step breakpoints out of the target. */
2597 remove_single_step_breakpoints ();
2598 singlestep_breakpoints_inserted_p
= 0;
2600 ecs
->random_signal
= 0;
2602 context_switch (saved_singlestep_ptid
);
2603 if (deprecated_context_hook
)
2604 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2606 resume (1, TARGET_SIGNAL_0
);
2607 prepare_to_wait (ecs
);
2612 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2614 /* In non-stop mode, there's never a deferred_step_ptid set. */
2615 gdb_assert (!non_stop
);
2617 /* If we stopped for some other reason than single-stepping, ignore
2618 the fact that we were supposed to switch back. */
2619 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2622 fprintf_unfiltered (gdb_stdlog
,
2623 "infrun: handling deferred step\n");
2625 /* Pull the single step breakpoints out of the target. */
2626 if (singlestep_breakpoints_inserted_p
)
2628 remove_single_step_breakpoints ();
2629 singlestep_breakpoints_inserted_p
= 0;
2632 /* Note: We do not call context_switch at this point, as the
2633 context is already set up for stepping the original thread. */
2634 switch_to_thread (deferred_step_ptid
);
2635 deferred_step_ptid
= null_ptid
;
2636 /* Suppress spurious "Switching to ..." message. */
2637 previous_inferior_ptid
= inferior_ptid
;
2639 resume (1, TARGET_SIGNAL_0
);
2640 prepare_to_wait (ecs
);
2644 deferred_step_ptid
= null_ptid
;
2647 /* See if a thread hit a thread-specific breakpoint that was meant for
2648 another thread. If so, then step that thread past the breakpoint,
2651 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
2653 int thread_hop_needed
= 0;
2655 /* Check if a regular breakpoint has been hit before checking
2656 for a potential single step breakpoint. Otherwise, GDB will
2657 not see this breakpoint hit when stepping onto breakpoints. */
2658 if (regular_breakpoint_inserted_here_p (stop_pc
))
2660 ecs
->random_signal
= 0;
2661 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2662 thread_hop_needed
= 1;
2664 else if (singlestep_breakpoints_inserted_p
)
2666 /* We have not context switched yet, so this should be true
2667 no matter which thread hit the singlestep breakpoint. */
2668 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2670 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2672 target_pid_to_str (ecs
->ptid
));
2674 ecs
->random_signal
= 0;
2675 /* The call to in_thread_list is necessary because PTIDs sometimes
2676 change when we go from single-threaded to multi-threaded. If
2677 the singlestep_ptid is still in the list, assume that it is
2678 really different from ecs->ptid. */
2679 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2680 && in_thread_list (singlestep_ptid
))
2682 /* If the PC of the thread we were trying to single-step
2683 has changed, discard this event (which we were going
2684 to ignore anyway), and pretend we saw that thread
2685 trap. This prevents us continuously moving the
2686 single-step breakpoint forward, one instruction at a
2687 time. If the PC has changed, then the thread we were
2688 trying to single-step has trapped or been signalled,
2689 but the event has not been reported to GDB yet.
2691 There might be some cases where this loses signal
2692 information, if a signal has arrived at exactly the
2693 same time that the PC changed, but this is the best
2694 we can do with the information available. Perhaps we
2695 should arrange to report all events for all threads
2696 when they stop, or to re-poll the remote looking for
2697 this particular thread (i.e. temporarily enable
2700 CORE_ADDR new_singlestep_pc
2701 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
2703 if (new_singlestep_pc
!= singlestep_pc
)
2705 enum target_signal stop_signal
;
2708 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2709 " but expected thread advanced also\n");
2711 /* The current context still belongs to
2712 singlestep_ptid. Don't swap here, since that's
2713 the context we want to use. Just fudge our
2714 state and continue. */
2715 stop_signal
= ecs
->event_thread
->stop_signal
;
2716 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2717 ecs
->ptid
= singlestep_ptid
;
2718 ecs
->event_thread
= find_thread_pid (ecs
->ptid
);
2719 ecs
->event_thread
->stop_signal
= stop_signal
;
2720 stop_pc
= new_singlestep_pc
;
2725 fprintf_unfiltered (gdb_stdlog
,
2726 "infrun: unexpected thread\n");
2728 thread_hop_needed
= 1;
2729 stepping_past_singlestep_breakpoint
= 1;
2730 saved_singlestep_ptid
= singlestep_ptid
;
2735 if (thread_hop_needed
)
2737 int remove_status
= 0;
2740 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2742 /* Saw a breakpoint, but it was hit by the wrong thread.
2745 if (singlestep_breakpoints_inserted_p
)
2747 /* Pull the single step breakpoints out of the target. */
2748 remove_single_step_breakpoints ();
2749 singlestep_breakpoints_inserted_p
= 0;
2752 /* If the arch can displace step, don't remove the
2754 if (!use_displaced_stepping (current_gdbarch
))
2755 remove_status
= remove_breakpoints ();
2757 /* Did we fail to remove breakpoints? If so, try
2758 to set the PC past the bp. (There's at least
2759 one situation in which we can fail to remove
2760 the bp's: On HP-UX's that use ttrace, we can't
2761 change the address space of a vforking child
2762 process until the child exits (well, okay, not
2763 then either :-) or execs. */
2764 if (remove_status
!= 0)
2765 error (_("Cannot step over breakpoint hit in wrong thread"));
2768 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2769 context_switch (ecs
->ptid
);
2773 /* Only need to require the next event from this
2774 thread in all-stop mode. */
2775 waiton_ptid
= ecs
->ptid
;
2776 infwait_state
= infwait_thread_hop_state
;
2779 ecs
->event_thread
->stepping_over_breakpoint
= 1;
2781 registers_changed ();
2785 else if (singlestep_breakpoints_inserted_p
)
2787 sw_single_step_trap_p
= 1;
2788 ecs
->random_signal
= 0;
2792 ecs
->random_signal
= 1;
2794 /* See if something interesting happened to the non-current thread. If
2795 so, then switch to that thread. */
2796 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2799 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
2801 context_switch (ecs
->ptid
);
2803 if (deprecated_context_hook
)
2804 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2807 if (singlestep_breakpoints_inserted_p
)
2809 /* Pull the single step breakpoints out of the target. */
2810 remove_single_step_breakpoints ();
2811 singlestep_breakpoints_inserted_p
= 0;
2814 if (stepped_after_stopped_by_watchpoint
)
2815 stopped_by_watchpoint
= 0;
2817 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
2819 /* If necessary, step over this watchpoint. We'll be back to display
2821 if (stopped_by_watchpoint
2822 && (target_have_steppable_watchpoint
2823 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
2825 /* At this point, we are stopped at an instruction which has
2826 attempted to write to a piece of memory under control of
2827 a watchpoint. The instruction hasn't actually executed
2828 yet. If we were to evaluate the watchpoint expression
2829 now, we would get the old value, and therefore no change
2830 would seem to have occurred.
2832 In order to make watchpoints work `right', we really need
2833 to complete the memory write, and then evaluate the
2834 watchpoint expression. We do this by single-stepping the
2837 It may not be necessary to disable the watchpoint to stop over
2838 it. For example, the PA can (with some kernel cooperation)
2839 single step over a watchpoint without disabling the watchpoint.
2841 It is far more common to need to disable a watchpoint to step
2842 the inferior over it. If we have non-steppable watchpoints,
2843 we must disable the current watchpoint; it's simplest to
2844 disable all watchpoints and breakpoints. */
2847 if (!target_have_steppable_watchpoint
)
2848 remove_breakpoints ();
2850 hw_step
= maybe_software_singlestep (current_gdbarch
, stop_pc
);
2851 target_resume (ecs
->ptid
, hw_step
, TARGET_SIGNAL_0
);
2852 registers_changed ();
2853 waiton_ptid
= ecs
->ptid
;
2854 if (target_have_steppable_watchpoint
)
2855 infwait_state
= infwait_step_watch_state
;
2857 infwait_state
= infwait_nonstep_watch_state
;
2858 prepare_to_wait (ecs
);
2862 ecs
->stop_func_start
= 0;
2863 ecs
->stop_func_end
= 0;
2864 ecs
->stop_func_name
= 0;
2865 /* Don't care about return value; stop_func_start and stop_func_name
2866 will both be 0 if it doesn't work. */
2867 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2868 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2869 ecs
->stop_func_start
2870 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
2871 ecs
->event_thread
->stepping_over_breakpoint
= 0;
2872 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
2873 ecs
->event_thread
->stop_step
= 0;
2874 stop_print_frame
= 1;
2875 ecs
->random_signal
= 0;
2876 stopped_by_random_signal
= 0;
2878 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
2879 && ecs
->event_thread
->trap_expected
2880 && gdbarch_single_step_through_delay_p (current_gdbarch
)
2881 && currently_stepping (ecs
->event_thread
))
2883 /* We're trying to step off a breakpoint. Turns out that we're
2884 also on an instruction that needs to be stepped multiple
2885 times before it's been fully executing. E.g., architectures
2886 with a delay slot. It needs to be stepped twice, once for
2887 the instruction and once for the delay slot. */
2888 int step_through_delay
2889 = gdbarch_single_step_through_delay (current_gdbarch
,
2890 get_current_frame ());
2891 if (debug_infrun
&& step_through_delay
)
2892 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
2893 if (ecs
->event_thread
->step_range_end
== 0 && step_through_delay
)
2895 /* The user issued a continue when stopped at a breakpoint.
2896 Set up for another trap and get out of here. */
2897 ecs
->event_thread
->stepping_over_breakpoint
= 1;
2901 else if (step_through_delay
)
2903 /* The user issued a step when stopped at a breakpoint.
2904 Maybe we should stop, maybe we should not - the delay
2905 slot *might* correspond to a line of source. In any
2906 case, don't decide that here, just set
2907 ecs->stepping_over_breakpoint, making sure we
2908 single-step again before breakpoints are re-inserted. */
2909 ecs
->event_thread
->stepping_over_breakpoint
= 1;
2913 /* Look at the cause of the stop, and decide what to do.
2914 The alternatives are:
2915 1) stop_stepping and return; to really stop and return to the debugger,
2916 2) keep_going and return to start up again
2917 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
2918 3) set ecs->random_signal to 1, and the decision between 1 and 2
2919 will be made according to the signal handling tables. */
2921 /* First, distinguish signals caused by the debugger from signals
2922 that have to do with the program's own actions. Note that
2923 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2924 on the operating system version. Here we detect when a SIGILL or
2925 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2926 something similar for SIGSEGV, since a SIGSEGV will be generated
2927 when we're trying to execute a breakpoint instruction on a
2928 non-executable stack. This happens for call dummy breakpoints
2929 for architectures like SPARC that place call dummies on the
2932 If we're doing a displaced step past a breakpoint, then the
2933 breakpoint is always inserted at the original instruction;
2934 non-standard signals can't be explained by the breakpoint. */
2935 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
2936 || (! ecs
->event_thread
->trap_expected
2937 && breakpoint_inserted_here_p (stop_pc
)
2938 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_ILL
2939 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_SEGV
2940 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_EMT
))
2941 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2942 || stop_soon
== STOP_QUIETLY_REMOTE
)
2944 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2947 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
2948 stop_print_frame
= 0;
2949 stop_stepping (ecs
);
2953 /* This is originated from start_remote(), start_inferior() and
2954 shared libraries hook functions. */
2955 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
2958 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
2959 stop_stepping (ecs
);
2963 /* This originates from attach_command(). We need to overwrite
2964 the stop_signal here, because some kernels don't ignore a
2965 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2966 See more comments in inferior.h. On the other hand, if we
2967 get a non-SIGSTOP, report it to the user - assume the backend
2968 will handle the SIGSTOP if it should show up later.
2970 Also consider that the attach is complete when we see a
2971 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
2972 target extended-remote report it instead of a SIGSTOP
2973 (e.g. gdbserver). We already rely on SIGTRAP being our
2974 signal, so this is no exception.
2976 Also consider that the attach is complete when we see a
2977 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
2978 the target to stop all threads of the inferior, in case the
2979 low level attach operation doesn't stop them implicitly. If
2980 they weren't stopped implicitly, then the stub will report a
2981 TARGET_SIGNAL_0, meaning: stopped for no particular reason
2982 other than GDB's request. */
2983 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2984 && (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_STOP
2985 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
2986 || ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_0
))
2988 stop_stepping (ecs
);
2989 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
2993 /* See if there is a breakpoint at the current PC. */
2994 ecs
->event_thread
->stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2996 /* Following in case break condition called a
2998 stop_print_frame
= 1;
3000 /* NOTE: cagney/2003-03-29: These two checks for a random signal
3001 at one stage in the past included checks for an inferior
3002 function call's call dummy's return breakpoint. The original
3003 comment, that went with the test, read:
3005 ``End of a stack dummy. Some systems (e.g. Sony news) give
3006 another signal besides SIGTRAP, so check here as well as
3009 If someone ever tries to get call dummys on a
3010 non-executable stack to work (where the target would stop
3011 with something like a SIGSEGV), then those tests might need
3012 to be re-instated. Given, however, that the tests were only
3013 enabled when momentary breakpoints were not being used, I
3014 suspect that it won't be the case.
3016 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
3017 be necessary for call dummies on a non-executable stack on
3020 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
)
3022 = !(bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
)
3023 || ecs
->event_thread
->trap_expected
3024 || (ecs
->event_thread
->step_range_end
3025 && ecs
->event_thread
->step_resume_breakpoint
== NULL
));
3028 ecs
->random_signal
= !bpstat_explains_signal (ecs
->event_thread
->stop_bpstat
);
3029 if (!ecs
->random_signal
)
3030 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_TRAP
;
3034 /* When we reach this point, we've pretty much decided
3035 that the reason for stopping must've been a random
3036 (unexpected) signal. */
3039 ecs
->random_signal
= 1;
3041 process_event_stop_test
:
3042 /* For the program's own signals, act according to
3043 the signal handling tables. */
3045 if (ecs
->random_signal
)
3047 /* Signal not for debugging purposes. */
3051 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n",
3052 ecs
->event_thread
->stop_signal
);
3054 stopped_by_random_signal
= 1;
3056 if (signal_print
[ecs
->event_thread
->stop_signal
])
3059 target_terminal_ours_for_output ();
3060 print_stop_reason (SIGNAL_RECEIVED
, ecs
->event_thread
->stop_signal
);
3062 /* Always stop on signals if we're either just gaining control
3063 of the program, or the user explicitly requested this thread
3064 to remain stopped. */
3065 if (stop_soon
!= NO_STOP_QUIETLY
3066 || ecs
->event_thread
->stop_requested
3067 || signal_stop_state (ecs
->event_thread
->stop_signal
))
3069 stop_stepping (ecs
);
3072 /* If not going to stop, give terminal back
3073 if we took it away. */
3075 target_terminal_inferior ();
3077 /* Clear the signal if it should not be passed. */
3078 if (signal_program
[ecs
->event_thread
->stop_signal
] == 0)
3079 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
3081 if (ecs
->event_thread
->prev_pc
== stop_pc
3082 && ecs
->event_thread
->trap_expected
3083 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3085 /* We were just starting a new sequence, attempting to
3086 single-step off of a breakpoint and expecting a SIGTRAP.
3087 Instead this signal arrives. This signal will take us out
3088 of the stepping range so GDB needs to remember to, when
3089 the signal handler returns, resume stepping off that
3091 /* To simplify things, "continue" is forced to use the same
3092 code paths as single-step - set a breakpoint at the
3093 signal return address and then, once hit, step off that
3096 fprintf_unfiltered (gdb_stdlog
,
3097 "infrun: signal arrived while stepping over "
3100 insert_step_resume_breakpoint_at_frame (get_current_frame ());
3101 ecs
->event_thread
->step_after_step_resume_breakpoint
= 1;
3106 if (ecs
->event_thread
->step_range_end
!= 0
3107 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_0
3108 && (ecs
->event_thread
->step_range_start
<= stop_pc
3109 && stop_pc
< ecs
->event_thread
->step_range_end
)
3110 && frame_id_eq (get_frame_id (get_current_frame ()),
3111 ecs
->event_thread
->step_frame_id
)
3112 && ecs
->event_thread
->step_resume_breakpoint
== NULL
)
3114 /* The inferior is about to take a signal that will take it
3115 out of the single step range. Set a breakpoint at the
3116 current PC (which is presumably where the signal handler
3117 will eventually return) and then allow the inferior to
3120 Note that this is only needed for a signal delivered
3121 while in the single-step range. Nested signals aren't a
3122 problem as they eventually all return. */
3124 fprintf_unfiltered (gdb_stdlog
,
3125 "infrun: signal may take us out of "
3126 "single-step range\n");
3128 insert_step_resume_breakpoint_at_frame (get_current_frame ());
3133 /* Note: step_resume_breakpoint may be non-NULL. This occures
3134 when either there's a nested signal, or when there's a
3135 pending signal enabled just as the signal handler returns
3136 (leaving the inferior at the step-resume-breakpoint without
3137 actually executing it). Either way continue until the
3138 breakpoint is really hit. */
3143 /* Handle cases caused by hitting a breakpoint. */
3145 CORE_ADDR jmp_buf_pc
;
3146 struct bpstat_what what
;
3148 what
= bpstat_what (ecs
->event_thread
->stop_bpstat
);
3150 if (what
.call_dummy
)
3152 stop_stack_dummy
= 1;
3155 switch (what
.main_action
)
3157 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
3158 /* If we hit the breakpoint at longjmp while stepping, we
3159 install a momentary breakpoint at the target of the
3163 fprintf_unfiltered (gdb_stdlog
,
3164 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
3166 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3168 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
3169 || !gdbarch_get_longjmp_target (current_gdbarch
,
3170 get_current_frame (), &jmp_buf_pc
))
3173 fprintf_unfiltered (gdb_stdlog
, "\
3174 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
3179 /* We're going to replace the current step-resume breakpoint
3180 with a longjmp-resume breakpoint. */
3181 delete_step_resume_breakpoint (ecs
->event_thread
);
3183 /* Insert a breakpoint at resume address. */
3184 insert_longjmp_resume_breakpoint (jmp_buf_pc
);
3189 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
3191 fprintf_unfiltered (gdb_stdlog
,
3192 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
3194 gdb_assert (ecs
->event_thread
->step_resume_breakpoint
!= NULL
);
3195 delete_step_resume_breakpoint (ecs
->event_thread
);
3197 ecs
->event_thread
->stop_step
= 1;
3198 print_stop_reason (END_STEPPING_RANGE
, 0);
3199 stop_stepping (ecs
);
3202 case BPSTAT_WHAT_SINGLE
:
3204 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
3205 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3206 /* Still need to check other stuff, at least the case
3207 where we are stepping and step out of the right range. */
3210 case BPSTAT_WHAT_STOP_NOISY
:
3212 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
3213 stop_print_frame
= 1;
3215 /* We are about to nuke the step_resume_breakpointt via the
3216 cleanup chain, so no need to worry about it here. */
3218 stop_stepping (ecs
);
3221 case BPSTAT_WHAT_STOP_SILENT
:
3223 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
3224 stop_print_frame
= 0;
3226 /* We are about to nuke the step_resume_breakpoin via the
3227 cleanup chain, so no need to worry about it here. */
3229 stop_stepping (ecs
);
3232 case BPSTAT_WHAT_STEP_RESUME
:
3234 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
3236 delete_step_resume_breakpoint (ecs
->event_thread
);
3237 if (ecs
->event_thread
->step_after_step_resume_breakpoint
)
3239 /* Back when the step-resume breakpoint was inserted, we
3240 were trying to single-step off a breakpoint. Go back
3242 ecs
->event_thread
->step_after_step_resume_breakpoint
= 0;
3243 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3247 if (stop_pc
== ecs
->stop_func_start
3248 && execution_direction
== EXEC_REVERSE
)
3250 /* We are stepping over a function call in reverse, and
3251 just hit the step-resume breakpoint at the start
3252 address of the function. Go back to single-stepping,
3253 which should take us back to the function call. */
3254 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3260 case BPSTAT_WHAT_CHECK_SHLIBS
:
3263 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
3265 /* Check for any newly added shared libraries if we're
3266 supposed to be adding them automatically. Switch
3267 terminal for any messages produced by
3268 breakpoint_re_set. */
3269 target_terminal_ours_for_output ();
3270 /* NOTE: cagney/2003-11-25: Make certain that the target
3271 stack's section table is kept up-to-date. Architectures,
3272 (e.g., PPC64), use the section table to perform
3273 operations such as address => section name and hence
3274 require the table to contain all sections (including
3275 those found in shared libraries). */
3276 /* NOTE: cagney/2003-11-25: Pass current_target and not
3277 exec_ops to SOLIB_ADD. This is because current GDB is
3278 only tooled to propagate section_table changes out from
3279 the "current_target" (see target_resize_to_sections), and
3280 not up from the exec stratum. This, of course, isn't
3281 right. "infrun.c" should only interact with the
3282 exec/process stratum, instead relying on the target stack
3283 to propagate relevant changes (stop, section table
3284 changed, ...) up to other layers. */
3286 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
3288 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
3290 target_terminal_inferior ();
3292 /* If requested, stop when the dynamic linker notifies
3293 gdb of events. This allows the user to get control
3294 and place breakpoints in initializer routines for
3295 dynamically loaded objects (among other things). */
3296 if (stop_on_solib_events
|| stop_stack_dummy
)
3298 stop_stepping (ecs
);
3303 /* We want to step over this breakpoint, then keep going. */
3304 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3310 case BPSTAT_WHAT_LAST
:
3311 /* Not a real code, but listed here to shut up gcc -Wall. */
3313 case BPSTAT_WHAT_KEEP_CHECKING
:
3318 /* We come here if we hit a breakpoint but should not
3319 stop for it. Possibly we also were stepping
3320 and should stop for that. So fall through and
3321 test for stepping. But, if not stepping,
3324 /* In all-stop mode, if we're currently stepping but have stopped in
3325 some other thread, we need to switch back to the stepped thread. */
3328 struct thread_info
*tp
;
3329 tp
= iterate_over_threads (currently_stepping_callback
,
3333 /* However, if the current thread is blocked on some internal
3334 breakpoint, and we simply need to step over that breakpoint
3335 to get it going again, do that first. */
3336 if ((ecs
->event_thread
->trap_expected
3337 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
3338 || ecs
->event_thread
->stepping_over_breakpoint
)
3344 /* Otherwise, we no longer expect a trap in the current thread.
3345 Clear the trap_expected flag before switching back -- this is
3346 what keep_going would do as well, if we called it. */
3347 ecs
->event_thread
->trap_expected
= 0;
3350 fprintf_unfiltered (gdb_stdlog
,
3351 "infrun: switching back to stepped thread\n");
3353 ecs
->event_thread
= tp
;
3354 ecs
->ptid
= tp
->ptid
;
3355 context_switch (ecs
->ptid
);
3361 /* Are we stepping to get the inferior out of the dynamic linker's
3362 hook (and possibly the dld itself) after catching a shlib
3364 if (ecs
->event_thread
->stepping_through_solib_after_catch
)
3366 #if defined(SOLIB_ADD)
3367 /* Have we reached our destination? If not, keep going. */
3368 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
3371 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
3372 ecs
->event_thread
->stepping_over_breakpoint
= 1;
3378 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
3379 /* Else, stop and report the catchpoint(s) whose triggering
3380 caused us to begin stepping. */
3381 ecs
->event_thread
->stepping_through_solib_after_catch
= 0;
3382 bpstat_clear (&ecs
->event_thread
->stop_bpstat
);
3383 ecs
->event_thread
->stop_bpstat
3384 = bpstat_copy (ecs
->event_thread
->stepping_through_solib_catchpoints
);
3385 bpstat_clear (&ecs
->event_thread
->stepping_through_solib_catchpoints
);
3386 stop_print_frame
= 1;
3387 stop_stepping (ecs
);
3391 if (ecs
->event_thread
->step_resume_breakpoint
)
3394 fprintf_unfiltered (gdb_stdlog
,
3395 "infrun: step-resume breakpoint is inserted\n");
3397 /* Having a step-resume breakpoint overrides anything
3398 else having to do with stepping commands until
3399 that breakpoint is reached. */
3404 if (ecs
->event_thread
->step_range_end
== 0)
3407 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
3408 /* Likewise if we aren't even stepping. */
3413 /* If stepping through a line, keep going if still within it.
3415 Note that step_range_end is the address of the first instruction
3416 beyond the step range, and NOT the address of the last instruction
3418 if (stop_pc
>= ecs
->event_thread
->step_range_start
3419 && stop_pc
< ecs
->event_thread
->step_range_end
)
3422 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
3423 paddr_nz (ecs
->event_thread
->step_range_start
),
3424 paddr_nz (ecs
->event_thread
->step_range_end
));
3426 /* When stepping backward, stop at beginning of line range
3427 (unless it's the function entry point, in which case
3428 keep going back to the call point). */
3429 if (stop_pc
== ecs
->event_thread
->step_range_start
3430 && stop_pc
!= ecs
->stop_func_start
3431 && execution_direction
== EXEC_REVERSE
)
3433 ecs
->event_thread
->stop_step
= 1;
3434 print_stop_reason (END_STEPPING_RANGE
, 0);
3435 stop_stepping (ecs
);
3443 /* We stepped out of the stepping range. */
3445 /* If we are stepping at the source level and entered the runtime
3446 loader dynamic symbol resolution code, we keep on single stepping
3447 until we exit the run time loader code and reach the callee's
3449 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3450 && in_solib_dynsym_resolve_code (stop_pc
))
3452 CORE_ADDR pc_after_resolver
=
3453 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
3456 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
3458 if (pc_after_resolver
)
3460 /* Set up a step-resume breakpoint at the address
3461 indicated by SKIP_SOLIB_RESOLVER. */
3462 struct symtab_and_line sr_sal
;
3464 sr_sal
.pc
= pc_after_resolver
;
3466 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3473 if (ecs
->event_thread
->step_range_end
!= 1
3474 && (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3475 || ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
3476 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
3479 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
3480 /* The inferior, while doing a "step" or "next", has ended up in
3481 a signal trampoline (either by a signal being delivered or by
3482 the signal handler returning). Just single-step until the
3483 inferior leaves the trampoline (either by calling the handler
3489 /* Check for subroutine calls. The check for the current frame
3490 equalling the step ID is not necessary - the check of the
3491 previous frame's ID is sufficient - but it is a common case and
3492 cheaper than checking the previous frame's ID.
3494 NOTE: frame_id_eq will never report two invalid frame IDs as
3495 being equal, so to get into this block, both the current and
3496 previous frame must have valid frame IDs. */
3497 if (!frame_id_eq (get_frame_id (get_current_frame ()),
3498 ecs
->event_thread
->step_frame_id
)
3499 && (frame_id_eq (frame_unwind_id (get_current_frame ()),
3500 ecs
->event_thread
->step_frame_id
)
3501 || execution_direction
== EXEC_REVERSE
))
3503 CORE_ADDR real_stop_pc
;
3506 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
3508 if ((ecs
->event_thread
->step_over_calls
== STEP_OVER_NONE
)
3509 || ((ecs
->event_thread
->step_range_end
== 1)
3510 && in_prologue (ecs
->event_thread
->prev_pc
,
3511 ecs
->stop_func_start
)))
3513 /* I presume that step_over_calls is only 0 when we're
3514 supposed to be stepping at the assembly language level
3515 ("stepi"). Just stop. */
3516 /* Also, maybe we just did a "nexti" inside a prolog, so we
3517 thought it was a subroutine call but it was not. Stop as
3519 ecs
->event_thread
->stop_step
= 1;
3520 print_stop_reason (END_STEPPING_RANGE
, 0);
3521 stop_stepping (ecs
);
3525 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_ALL
)
3527 /* We're doing a "next".
3529 Normal (forward) execution: set a breakpoint at the
3530 callee's return address (the address at which the caller
3533 Reverse (backward) execution. set the step-resume
3534 breakpoint at the start of the function that we just
3535 stepped into (backwards), and continue to there. When we
3536 get there, we'll need to single-step back to the caller. */
3538 if (execution_direction
== EXEC_REVERSE
)
3540 struct symtab_and_line sr_sal
;
3542 if (ecs
->stop_func_start
== 0
3543 && in_solib_dynsym_resolve_code (stop_pc
))
3545 /* Stepped into runtime loader dynamic symbol
3546 resolution code. Since we're in reverse,
3547 we have already backed up through the runtime
3548 loader and the dynamic function. This is just
3549 the trampoline (jump table).
3551 Just keep stepping, we'll soon be home.
3556 /* Normal (staticly linked) function call return. */
3558 sr_sal
.pc
= ecs
->stop_func_start
;
3559 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3562 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3568 /* If we are in a function call trampoline (a stub between the
3569 calling routine and the real function), locate the real
3570 function. That's what tells us (a) whether we want to step
3571 into it at all, and (b) what prologue we want to run to the
3572 end of, if we do step into it. */
3573 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
3574 if (real_stop_pc
== 0)
3575 real_stop_pc
= gdbarch_skip_trampoline_code
3576 (current_gdbarch
, get_current_frame (), stop_pc
);
3577 if (real_stop_pc
!= 0)
3578 ecs
->stop_func_start
= real_stop_pc
;
3580 if (real_stop_pc
!= 0 && in_solib_dynsym_resolve_code (real_stop_pc
))
3582 struct symtab_and_line sr_sal
;
3584 sr_sal
.pc
= ecs
->stop_func_start
;
3586 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3591 /* If we have line number information for the function we are
3592 thinking of stepping into, step into it.
3594 If there are several symtabs at that PC (e.g. with include
3595 files), just want to know whether *any* of them have line
3596 numbers. find_pc_line handles this. */
3598 struct symtab_and_line tmp_sal
;
3600 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3601 if (tmp_sal
.line
!= 0)
3603 if (execution_direction
== EXEC_REVERSE
)
3604 handle_step_into_function_backward (ecs
);
3606 handle_step_into_function (ecs
);
3611 /* If we have no line number and the step-stop-if-no-debug is
3612 set, we stop the step so that the user has a chance to switch
3613 in assembly mode. */
3614 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3615 && step_stop_if_no_debug
)
3617 ecs
->event_thread
->stop_step
= 1;
3618 print_stop_reason (END_STEPPING_RANGE
, 0);
3619 stop_stepping (ecs
);
3623 if (execution_direction
== EXEC_REVERSE
)
3625 /* Set a breakpoint at callee's start address.
3626 From there we can step once and be back in the caller. */
3627 struct symtab_and_line sr_sal
;
3629 sr_sal
.pc
= ecs
->stop_func_start
;
3630 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3633 /* Set a breakpoint at callee's return address (the address
3634 at which the caller will resume). */
3635 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3641 /* If we're in the return path from a shared library trampoline,
3642 we want to proceed through the trampoline when stepping. */
3643 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
3644 stop_pc
, ecs
->stop_func_name
))
3646 /* Determine where this trampoline returns. */
3647 CORE_ADDR real_stop_pc
;
3648 real_stop_pc
= gdbarch_skip_trampoline_code
3649 (current_gdbarch
, get_current_frame (), stop_pc
);
3652 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3654 /* Only proceed through if we know where it's going. */
3657 /* And put the step-breakpoint there and go until there. */
3658 struct symtab_and_line sr_sal
;
3660 init_sal (&sr_sal
); /* initialize to zeroes */
3661 sr_sal
.pc
= real_stop_pc
;
3662 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3664 /* Do not specify what the fp should be when we stop since
3665 on some machines the prologue is where the new fp value
3667 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3669 /* Restart without fiddling with the step ranges or
3676 stop_pc_sal
= find_pc_line (stop_pc
, 0);
3678 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3679 the trampoline processing logic, however, there are some trampolines
3680 that have no names, so we should do trampoline handling first. */
3681 if (ecs
->event_thread
->step_over_calls
== STEP_OVER_UNDEBUGGABLE
3682 && ecs
->stop_func_name
== NULL
3683 && stop_pc_sal
.line
== 0)
3686 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3688 /* The inferior just stepped into, or returned to, an
3689 undebuggable function (where there is no debugging information
3690 and no line number corresponding to the address where the
3691 inferior stopped). Since we want to skip this kind of code,
3692 we keep going until the inferior returns from this
3693 function - unless the user has asked us not to (via
3694 set step-mode) or we no longer know how to get back
3695 to the call site. */
3696 if (step_stop_if_no_debug
3697 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3699 /* If we have no line number and the step-stop-if-no-debug
3700 is set, we stop the step so that the user has a chance to
3701 switch in assembly mode. */
3702 ecs
->event_thread
->stop_step
= 1;
3703 print_stop_reason (END_STEPPING_RANGE
, 0);
3704 stop_stepping (ecs
);
3709 /* Set a breakpoint at callee's return address (the address
3710 at which the caller will resume). */
3711 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3717 if (ecs
->event_thread
->step_range_end
== 1)
3719 /* It is stepi or nexti. We always want to stop stepping after
3722 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
3723 ecs
->event_thread
->stop_step
= 1;
3724 print_stop_reason (END_STEPPING_RANGE
, 0);
3725 stop_stepping (ecs
);
3729 if (stop_pc_sal
.line
== 0)
3731 /* We have no line number information. That means to stop
3732 stepping (does this always happen right after one instruction,
3733 when we do "s" in a function with no line numbers,
3734 or can this happen as a result of a return or longjmp?). */
3736 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
3737 ecs
->event_thread
->stop_step
= 1;
3738 print_stop_reason (END_STEPPING_RANGE
, 0);
3739 stop_stepping (ecs
);
3743 if ((stop_pc
== stop_pc_sal
.pc
)
3744 && (ecs
->event_thread
->current_line
!= stop_pc_sal
.line
3745 || ecs
->event_thread
->current_symtab
!= stop_pc_sal
.symtab
))
3747 /* We are at the start of a different line. So stop. Note that
3748 we don't stop if we step into the middle of a different line.
3749 That is said to make things like for (;;) statements work
3752 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
3753 ecs
->event_thread
->stop_step
= 1;
3754 print_stop_reason (END_STEPPING_RANGE
, 0);
3755 stop_stepping (ecs
);
3759 /* We aren't done stepping.
3761 Optimize by setting the stepping range to the line.
3762 (We might not be in the original line, but if we entered a
3763 new line in mid-statement, we continue stepping. This makes
3764 things like for(;;) statements work better.) */
3766 ecs
->event_thread
->step_range_start
= stop_pc_sal
.pc
;
3767 ecs
->event_thread
->step_range_end
= stop_pc_sal
.end
;
3768 ecs
->event_thread
->step_frame_id
= get_frame_id (get_current_frame ());
3769 ecs
->event_thread
->current_line
= stop_pc_sal
.line
;
3770 ecs
->event_thread
->current_symtab
= stop_pc_sal
.symtab
;
3773 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
3777 /* Are we in the middle of stepping? */
3780 currently_stepping_thread (struct thread_info
*tp
)
3782 return (tp
->step_range_end
&& tp
->step_resume_breakpoint
== NULL
)
3783 || tp
->trap_expected
3784 || tp
->stepping_through_solib_after_catch
;
3788 currently_stepping_callback (struct thread_info
*tp
, void *data
)
3790 /* Return true if any thread *but* the one passed in "data" is
3791 in the middle of stepping. */
3792 return tp
!= data
&& currently_stepping_thread (tp
);
3796 currently_stepping (struct thread_info
*tp
)
3798 return currently_stepping_thread (tp
) || bpstat_should_step ();
3801 /* Inferior has stepped into a subroutine call with source code that
3802 we should not step over. Do step to the first line of code in
3806 handle_step_into_function (struct execution_control_state
*ecs
)
3809 struct symtab_and_line stop_func_sal
, sr_sal
;
3811 s
= find_pc_symtab (stop_pc
);
3812 if (s
&& s
->language
!= language_asm
)
3813 ecs
->stop_func_start
= gdbarch_skip_prologue (current_gdbarch
,
3814 ecs
->stop_func_start
);
3816 stop_func_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3817 /* Use the step_resume_break to step until the end of the prologue,
3818 even if that involves jumps (as it seems to on the vax under
3820 /* If the prologue ends in the middle of a source line, continue to
3821 the end of that source line (if it is still within the function).
3822 Otherwise, just go to end of prologue. */
3823 if (stop_func_sal
.end
3824 && stop_func_sal
.pc
!= ecs
->stop_func_start
3825 && stop_func_sal
.end
< ecs
->stop_func_end
)
3826 ecs
->stop_func_start
= stop_func_sal
.end
;
3828 /* Architectures which require breakpoint adjustment might not be able
3829 to place a breakpoint at the computed address. If so, the test
3830 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3831 ecs->stop_func_start to an address at which a breakpoint may be
3832 legitimately placed.
3834 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3835 made, GDB will enter an infinite loop when stepping through
3836 optimized code consisting of VLIW instructions which contain
3837 subinstructions corresponding to different source lines. On
3838 FR-V, it's not permitted to place a breakpoint on any but the
3839 first subinstruction of a VLIW instruction. When a breakpoint is
3840 set, GDB will adjust the breakpoint address to the beginning of
3841 the VLIW instruction. Thus, we need to make the corresponding
3842 adjustment here when computing the stop address. */
3844 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3846 ecs
->stop_func_start
3847 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
3848 ecs
->stop_func_start
);
3851 if (ecs
->stop_func_start
== stop_pc
)
3853 /* We are already there: stop now. */
3854 ecs
->event_thread
->stop_step
= 1;
3855 print_stop_reason (END_STEPPING_RANGE
, 0);
3856 stop_stepping (ecs
);
3861 /* Put the step-breakpoint there and go until there. */
3862 init_sal (&sr_sal
); /* initialize to zeroes */
3863 sr_sal
.pc
= ecs
->stop_func_start
;
3864 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3866 /* Do not specify what the fp should be when we stop since on
3867 some machines the prologue is where the new fp value is
3869 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3871 /* And make sure stepping stops right away then. */
3872 ecs
->event_thread
->step_range_end
= ecs
->event_thread
->step_range_start
;
3877 /* Inferior has stepped backward into a subroutine call with source
3878 code that we should not step over. Do step to the beginning of the
3879 last line of code in it. */
3882 handle_step_into_function_backward (struct execution_control_state
*ecs
)
3885 struct symtab_and_line stop_func_sal
, sr_sal
;
3887 s
= find_pc_symtab (stop_pc
);
3888 if (s
&& s
->language
!= language_asm
)
3889 ecs
->stop_func_start
= gdbarch_skip_prologue (current_gdbarch
,
3890 ecs
->stop_func_start
);
3892 stop_func_sal
= find_pc_line (stop_pc
, 0);
3894 /* OK, we're just going to keep stepping here. */
3895 if (stop_func_sal
.pc
== stop_pc
)
3897 /* We're there already. Just stop stepping now. */
3898 ecs
->event_thread
->stop_step
= 1;
3899 print_stop_reason (END_STEPPING_RANGE
, 0);
3900 stop_stepping (ecs
);
3904 /* Else just reset the step range and keep going.
3905 No step-resume breakpoint, they don't work for
3906 epilogues, which can have multiple entry paths. */
3907 ecs
->event_thread
->step_range_start
= stop_func_sal
.pc
;
3908 ecs
->event_thread
->step_range_end
= stop_func_sal
.end
;
3914 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3915 This is used to both functions and to skip over code. */
3918 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
3919 struct frame_id sr_id
)
3921 /* There should never be more than one step-resume or longjmp-resume
3922 breakpoint per thread, so we should never be setting a new
3923 step_resume_breakpoint when one is already active. */
3924 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
3927 fprintf_unfiltered (gdb_stdlog
,
3928 "infrun: inserting step-resume breakpoint at 0x%s\n",
3929 paddr_nz (sr_sal
.pc
));
3931 inferior_thread ()->step_resume_breakpoint
3932 = set_momentary_breakpoint (sr_sal
, sr_id
, bp_step_resume
);
3935 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3936 to skip a potential signal handler.
3938 This is called with the interrupted function's frame. The signal
3939 handler, when it returns, will resume the interrupted function at
3943 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
3945 struct symtab_and_line sr_sal
;
3947 gdb_assert (return_frame
!= NULL
);
3948 init_sal (&sr_sal
); /* initialize to zeros */
3950 sr_sal
.pc
= gdbarch_addr_bits_remove
3951 (current_gdbarch
, get_frame_pc (return_frame
));
3952 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3954 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
3957 /* Similar to insert_step_resume_breakpoint_at_frame, except
3958 but a breakpoint at the previous frame's PC. This is used to
3959 skip a function after stepping into it (for "next" or if the called
3960 function has no debugging information).
3962 The current function has almost always been reached by single
3963 stepping a call or return instruction. NEXT_FRAME belongs to the
3964 current function, and the breakpoint will be set at the caller's
3967 This is a separate function rather than reusing
3968 insert_step_resume_breakpoint_at_frame in order to avoid
3969 get_prev_frame, which may stop prematurely (see the implementation
3970 of frame_unwind_id for an example). */
3973 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
3975 struct symtab_and_line sr_sal
;
3977 /* We shouldn't have gotten here if we don't know where the call site
3979 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
3981 init_sal (&sr_sal
); /* initialize to zeros */
3983 sr_sal
.pc
= gdbarch_addr_bits_remove
3984 (current_gdbarch
, frame_pc_unwind (next_frame
));
3985 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3987 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
3990 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
3991 new breakpoint at the target of a jmp_buf. The handling of
3992 longjmp-resume uses the same mechanisms used for handling
3993 "step-resume" breakpoints. */
3996 insert_longjmp_resume_breakpoint (CORE_ADDR pc
)
3998 /* There should never be more than one step-resume or longjmp-resume
3999 breakpoint per thread, so we should never be setting a new
4000 longjmp_resume_breakpoint when one is already active. */
4001 gdb_assert (inferior_thread ()->step_resume_breakpoint
== NULL
);
4004 fprintf_unfiltered (gdb_stdlog
,
4005 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
4008 inferior_thread ()->step_resume_breakpoint
=
4009 set_momentary_breakpoint_at_pc (pc
, bp_longjmp_resume
);
4013 stop_stepping (struct execution_control_state
*ecs
)
4016 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
4018 /* Let callers know we don't want to wait for the inferior anymore. */
4019 ecs
->wait_some_more
= 0;
4022 /* This function handles various cases where we need to continue
4023 waiting for the inferior. */
4024 /* (Used to be the keep_going: label in the old wait_for_inferior) */
4027 keep_going (struct execution_control_state
*ecs
)
4029 /* Save the pc before execution, to compare with pc after stop. */
4030 ecs
->event_thread
->prev_pc
4031 = regcache_read_pc (get_thread_regcache (ecs
->ptid
));
4033 /* If we did not do break;, it means we should keep running the
4034 inferior and not return to debugger. */
4036 if (ecs
->event_thread
->trap_expected
4037 && ecs
->event_thread
->stop_signal
!= TARGET_SIGNAL_TRAP
)
4039 /* We took a signal (which we are supposed to pass through to
4040 the inferior, else we'd not get here) and we haven't yet
4041 gotten our trap. Simply continue. */
4042 resume (currently_stepping (ecs
->event_thread
),
4043 ecs
->event_thread
->stop_signal
);
4047 /* Either the trap was not expected, but we are continuing
4048 anyway (the user asked that this signal be passed to the
4051 The signal was SIGTRAP, e.g. it was our signal, but we
4052 decided we should resume from it.
4054 We're going to run this baby now!
4056 Note that insert_breakpoints won't try to re-insert
4057 already inserted breakpoints. Therefore, we don't
4058 care if breakpoints were already inserted, or not. */
4060 if (ecs
->event_thread
->stepping_over_breakpoint
)
4062 if (! use_displaced_stepping (current_gdbarch
))
4063 /* Since we can't do a displaced step, we have to remove
4064 the breakpoint while we step it. To keep things
4065 simple, we remove them all. */
4066 remove_breakpoints ();
4070 struct gdb_exception e
;
4071 /* Stop stepping when inserting breakpoints
4073 TRY_CATCH (e
, RETURN_MASK_ERROR
)
4075 insert_breakpoints ();
4079 stop_stepping (ecs
);
4084 ecs
->event_thread
->trap_expected
= ecs
->event_thread
->stepping_over_breakpoint
;
4086 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
4087 specifies that such a signal should be delivered to the
4090 Typically, this would occure when a user is debugging a
4091 target monitor on a simulator: the target monitor sets a
4092 breakpoint; the simulator encounters this break-point and
4093 halts the simulation handing control to GDB; GDB, noteing
4094 that the break-point isn't valid, returns control back to the
4095 simulator; the simulator then delivers the hardware
4096 equivalent of a SIGNAL_TRAP to the program being debugged. */
4098 if (ecs
->event_thread
->stop_signal
== TARGET_SIGNAL_TRAP
4099 && !signal_program
[ecs
->event_thread
->stop_signal
])
4100 ecs
->event_thread
->stop_signal
= TARGET_SIGNAL_0
;
4102 resume (currently_stepping (ecs
->event_thread
),
4103 ecs
->event_thread
->stop_signal
);
4106 prepare_to_wait (ecs
);
4109 /* This function normally comes after a resume, before
4110 handle_inferior_event exits. It takes care of any last bits of
4111 housekeeping, and sets the all-important wait_some_more flag. */
4114 prepare_to_wait (struct execution_control_state
*ecs
)
4117 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
4118 if (infwait_state
== infwait_normal_state
)
4120 overlay_cache_invalid
= 1;
4122 /* We have to invalidate the registers BEFORE calling
4123 target_wait because they can be loaded from the target while
4124 in target_wait. This makes remote debugging a bit more
4125 efficient for those targets that provide critical registers
4126 as part of their normal status mechanism. */
4128 registers_changed ();
4129 waiton_ptid
= pid_to_ptid (-1);
4131 /* This is the old end of the while loop. Let everybody know we
4132 want to wait for the inferior some more and get called again
4134 ecs
->wait_some_more
= 1;
4137 /* Print why the inferior has stopped. We always print something when
4138 the inferior exits, or receives a signal. The rest of the cases are
4139 dealt with later on in normal_stop() and print_it_typical(). Ideally
4140 there should be a call to this function from handle_inferior_event()
4141 each time stop_stepping() is called.*/
4143 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
4145 switch (stop_reason
)
4147 case END_STEPPING_RANGE
:
4148 /* We are done with a step/next/si/ni command. */
4149 /* For now print nothing. */
4150 /* Print a message only if not in the middle of doing a "step n"
4151 operation for n > 1 */
4152 if (!inferior_thread ()->step_multi
4153 || !inferior_thread ()->stop_step
)
4154 if (ui_out_is_mi_like_p (uiout
))
4157 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
4160 /* The inferior was terminated by a signal. */
4161 annotate_signalled ();
4162 if (ui_out_is_mi_like_p (uiout
))
4165 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
4166 ui_out_text (uiout
, "\nProgram terminated with signal ");
4167 annotate_signal_name ();
4168 ui_out_field_string (uiout
, "signal-name",
4169 target_signal_to_name (stop_info
));
4170 annotate_signal_name_end ();
4171 ui_out_text (uiout
, ", ");
4172 annotate_signal_string ();
4173 ui_out_field_string (uiout
, "signal-meaning",
4174 target_signal_to_string (stop_info
));
4175 annotate_signal_string_end ();
4176 ui_out_text (uiout
, ".\n");
4177 ui_out_text (uiout
, "The program no longer exists.\n");
4180 /* The inferior program is finished. */
4181 annotate_exited (stop_info
);
4184 if (ui_out_is_mi_like_p (uiout
))
4185 ui_out_field_string (uiout
, "reason",
4186 async_reason_lookup (EXEC_ASYNC_EXITED
));
4187 ui_out_text (uiout
, "\nProgram exited with code ");
4188 ui_out_field_fmt (uiout
, "exit-code", "0%o",
4189 (unsigned int) stop_info
);
4190 ui_out_text (uiout
, ".\n");
4194 if (ui_out_is_mi_like_p (uiout
))
4197 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
4198 ui_out_text (uiout
, "\nProgram exited normally.\n");
4200 /* Support the --return-child-result option. */
4201 return_child_result_value
= stop_info
;
4203 case SIGNAL_RECEIVED
:
4204 /* Signal received. The signal table tells us to print about
4208 if (stop_info
== TARGET_SIGNAL_0
&& !ui_out_is_mi_like_p (uiout
))
4210 struct thread_info
*t
= inferior_thread ();
4212 ui_out_text (uiout
, "\n[");
4213 ui_out_field_string (uiout
, "thread-name",
4214 target_pid_to_str (t
->ptid
));
4215 ui_out_field_fmt (uiout
, "thread-id", "] #%d", t
->num
);
4216 ui_out_text (uiout
, " stopped");
4220 ui_out_text (uiout
, "\nProgram received signal ");
4221 annotate_signal_name ();
4222 if (ui_out_is_mi_like_p (uiout
))
4224 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
4225 ui_out_field_string (uiout
, "signal-name",
4226 target_signal_to_name (stop_info
));
4227 annotate_signal_name_end ();
4228 ui_out_text (uiout
, ", ");
4229 annotate_signal_string ();
4230 ui_out_field_string (uiout
, "signal-meaning",
4231 target_signal_to_string (stop_info
));
4232 annotate_signal_string_end ();
4234 ui_out_text (uiout
, ".\n");
4237 /* Reverse execution: target ran out of history info. */
4238 ui_out_text (uiout
, "\nNo more reverse-execution history.\n");
4241 internal_error (__FILE__
, __LINE__
,
4242 _("print_stop_reason: unrecognized enum value"));
4248 /* Here to return control to GDB when the inferior stops for real.
4249 Print appropriate messages, remove breakpoints, give terminal our modes.
4251 STOP_PRINT_FRAME nonzero means print the executing frame
4252 (pc, function, args, file, line number and line text).
4253 BREAKPOINTS_FAILED nonzero means stop was due to error
4254 attempting to insert breakpoints. */
4259 struct target_waitstatus last
;
4261 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
4263 get_last_target_status (&last_ptid
, &last
);
4265 /* If an exception is thrown from this point on, make sure to
4266 propagate GDB's knowledge of the executing state to the
4267 frontend/user running state. A QUIT is an easy exception to see
4268 here, so do this before any filtered output. */
4269 if (target_has_execution
)
4272 make_cleanup (finish_thread_state_cleanup
, &minus_one_ptid
);
4273 else if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
4274 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4275 make_cleanup (finish_thread_state_cleanup
, &inferior_ptid
);
4278 /* In non-stop mode, we don't want GDB to switch threads behind the
4279 user's back, to avoid races where the user is typing a command to
4280 apply to thread x, but GDB switches to thread y before the user
4281 finishes entering the command. */
4283 /* As with the notification of thread events, we want to delay
4284 notifying the user that we've switched thread context until
4285 the inferior actually stops.
4287 There's no point in saying anything if the inferior has exited.
4288 Note that SIGNALLED here means "exited with a signal", not
4289 "received a signal". */
4291 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
4292 && target_has_execution
4293 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
4294 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4296 target_terminal_ours_for_output ();
4297 printf_filtered (_("[Switching to %s]\n"),
4298 target_pid_to_str (inferior_ptid
));
4299 annotate_thread_changed ();
4300 previous_inferior_ptid
= inferior_ptid
;
4303 if (!breakpoints_always_inserted_mode () && target_has_execution
)
4305 if (remove_breakpoints ())
4307 target_terminal_ours_for_output ();
4308 printf_filtered (_("\
4309 Cannot remove breakpoints because program is no longer writable.\n\
4310 Further execution is probably impossible.\n"));
4314 /* If an auto-display called a function and that got a signal,
4315 delete that auto-display to avoid an infinite recursion. */
4317 if (stopped_by_random_signal
)
4318 disable_current_display ();
4320 /* Don't print a message if in the middle of doing a "step n"
4321 operation for n > 1 */
4322 if (target_has_execution
4323 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
4324 && last
.kind
!= TARGET_WAITKIND_EXITED
4325 && inferior_thread ()->step_multi
4326 && inferior_thread ()->stop_step
)
4329 target_terminal_ours ();
4331 /* Set the current source location. This will also happen if we
4332 display the frame below, but the current SAL will be incorrect
4333 during a user hook-stop function. */
4334 if (has_stack_frames () && !stop_stack_dummy
)
4335 set_current_sal_from_frame (get_current_frame (), 1);
4337 /* Let the user/frontend see the threads as stopped. */
4338 do_cleanups (old_chain
);
4340 /* Look up the hook_stop and run it (CLI internally handles problem
4341 of stop_command's pre-hook not existing). */
4343 catch_errors (hook_stop_stub
, stop_command
,
4344 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
4346 if (!has_stack_frames ())
4349 if (last
.kind
== TARGET_WAITKIND_SIGNALLED
4350 || last
.kind
== TARGET_WAITKIND_EXITED
)
4353 /* Select innermost stack frame - i.e., current frame is frame 0,
4354 and current location is based on that.
4355 Don't do this on return from a stack dummy routine,
4356 or if the program has exited. */
4358 if (!stop_stack_dummy
)
4360 select_frame (get_current_frame ());
4362 /* Print current location without a level number, if
4363 we have changed functions or hit a breakpoint.
4364 Print source line if we have one.
4365 bpstat_print() contains the logic deciding in detail
4366 what to print, based on the event(s) that just occurred. */
4368 /* If --batch-silent is enabled then there's no need to print the current
4369 source location, and to try risks causing an error message about
4370 missing source files. */
4371 if (stop_print_frame
&& !batch_silent
)
4375 int do_frame_printing
= 1;
4376 struct thread_info
*tp
= inferior_thread ();
4378 bpstat_ret
= bpstat_print (tp
->stop_bpstat
);
4382 /* If we had hit a shared library event breakpoint,
4383 bpstat_print would print out this message. If we hit
4384 an OS-level shared library event, do the same
4386 if (last
.kind
== TARGET_WAITKIND_LOADED
)
4388 printf_filtered (_("Stopped due to shared library event\n"));
4389 source_flag
= SRC_LINE
; /* something bogus */
4390 do_frame_printing
= 0;
4394 /* FIXME: cagney/2002-12-01: Given that a frame ID does
4395 (or should) carry around the function and does (or
4396 should) use that when doing a frame comparison. */
4398 && frame_id_eq (tp
->step_frame_id
,
4399 get_frame_id (get_current_frame ()))
4400 && step_start_function
== find_pc_function (stop_pc
))
4401 source_flag
= SRC_LINE
; /* finished step, just print source line */
4403 source_flag
= SRC_AND_LOC
; /* print location and source line */
4405 case PRINT_SRC_AND_LOC
:
4406 source_flag
= SRC_AND_LOC
; /* print location and source line */
4408 case PRINT_SRC_ONLY
:
4409 source_flag
= SRC_LINE
;
4412 source_flag
= SRC_LINE
; /* something bogus */
4413 do_frame_printing
= 0;
4416 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
4419 /* The behavior of this routine with respect to the source
4421 SRC_LINE: Print only source line
4422 LOCATION: Print only location
4423 SRC_AND_LOC: Print location and source line */
4424 if (do_frame_printing
)
4425 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
4427 /* Display the auto-display expressions. */
4432 /* Save the function value return registers, if we care.
4433 We might be about to restore their previous contents. */
4434 if (inferior_thread ()->proceed_to_finish
)
4436 /* This should not be necessary. */
4438 regcache_xfree (stop_registers
);
4440 /* NB: The copy goes through to the target picking up the value of
4441 all the registers. */
4442 stop_registers
= regcache_dup (get_current_regcache ());
4445 if (stop_stack_dummy
)
4447 /* Pop the empty frame that contains the stack dummy.
4448 This also restores inferior state prior to the call
4449 (struct inferior_thread_state). */
4450 struct frame_info
*frame
= get_current_frame ();
4451 gdb_assert (get_frame_type (frame
) == DUMMY_FRAME
);
4453 /* frame_pop() calls reinit_frame_cache as the last thing it does
4454 which means there's currently no selected frame. We don't need
4455 to re-establish a selected frame if the dummy call returns normally,
4456 that will be done by restore_inferior_status. However, we do have
4457 to handle the case where the dummy call is returning after being
4458 stopped (e.g. the dummy call previously hit a breakpoint). We
4459 can't know which case we have so just always re-establish a
4460 selected frame here. */
4461 select_frame (get_current_frame ());
4465 annotate_stopped ();
4467 /* Suppress the stop observer if we're in the middle of:
4469 - a step n (n > 1), as there still more steps to be done.
4471 - a "finish" command, as the observer will be called in
4472 finish_command_continuation, so it can include the inferior
4473 function's return value.
4475 - calling an inferior function, as we pretend we inferior didn't
4476 run at all. The return value of the call is handled by the
4477 expression evaluator, through call_function_by_hand. */
4479 if (!target_has_execution
4480 || last
.kind
== TARGET_WAITKIND_SIGNALLED
4481 || last
.kind
== TARGET_WAITKIND_EXITED
4482 || (!inferior_thread ()->step_multi
4483 && !(inferior_thread ()->stop_bpstat
4484 && inferior_thread ()->proceed_to_finish
)
4485 && !inferior_thread ()->in_infcall
))
4487 if (!ptid_equal (inferior_ptid
, null_ptid
))
4488 observer_notify_normal_stop (inferior_thread ()->stop_bpstat
,
4491 observer_notify_normal_stop (NULL
, stop_print_frame
);
4494 if (target_has_execution
)
4496 if (last
.kind
!= TARGET_WAITKIND_SIGNALLED
4497 && last
.kind
!= TARGET_WAITKIND_EXITED
)
4498 /* Delete the breakpoint we stopped at, if it wants to be deleted.
4499 Delete any breakpoint that is to be deleted at the next stop. */
4500 breakpoint_auto_delete (inferior_thread ()->stop_bpstat
);
4505 hook_stop_stub (void *cmd
)
4507 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
4512 signal_stop_state (int signo
)
4514 return signal_stop
[signo
];
4518 signal_print_state (int signo
)
4520 return signal_print
[signo
];
4524 signal_pass_state (int signo
)
4526 return signal_program
[signo
];
4530 signal_stop_update (int signo
, int state
)
4532 int ret
= signal_stop
[signo
];
4533 signal_stop
[signo
] = state
;
4538 signal_print_update (int signo
, int state
)
4540 int ret
= signal_print
[signo
];
4541 signal_print
[signo
] = state
;
4546 signal_pass_update (int signo
, int state
)
4548 int ret
= signal_program
[signo
];
4549 signal_program
[signo
] = state
;
4554 sig_print_header (void)
4556 printf_filtered (_("\
4557 Signal Stop\tPrint\tPass to program\tDescription\n"));
4561 sig_print_info (enum target_signal oursig
)
4563 const char *name
= target_signal_to_name (oursig
);
4564 int name_padding
= 13 - strlen (name
);
4566 if (name_padding
<= 0)
4569 printf_filtered ("%s", name
);
4570 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
4571 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
4572 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
4573 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
4574 printf_filtered ("%s\n", target_signal_to_string (oursig
));
4577 /* Specify how various signals in the inferior should be handled. */
4580 handle_command (char *args
, int from_tty
)
4583 int digits
, wordlen
;
4584 int sigfirst
, signum
, siglast
;
4585 enum target_signal oursig
;
4588 unsigned char *sigs
;
4589 struct cleanup
*old_chain
;
4593 error_no_arg (_("signal to handle"));
4596 /* Allocate and zero an array of flags for which signals to handle. */
4598 nsigs
= (int) TARGET_SIGNAL_LAST
;
4599 sigs
= (unsigned char *) alloca (nsigs
);
4600 memset (sigs
, 0, nsigs
);
4602 /* Break the command line up into args. */
4604 argv
= gdb_buildargv (args
);
4605 old_chain
= make_cleanup_freeargv (argv
);
4607 /* Walk through the args, looking for signal oursigs, signal names, and
4608 actions. Signal numbers and signal names may be interspersed with
4609 actions, with the actions being performed for all signals cumulatively
4610 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4612 while (*argv
!= NULL
)
4614 wordlen
= strlen (*argv
);
4615 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
4619 sigfirst
= siglast
= -1;
4621 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
4623 /* Apply action to all signals except those used by the
4624 debugger. Silently skip those. */
4627 siglast
= nsigs
- 1;
4629 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
4631 SET_SIGS (nsigs
, sigs
, signal_stop
);
4632 SET_SIGS (nsigs
, sigs
, signal_print
);
4634 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
4636 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4638 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
4640 SET_SIGS (nsigs
, sigs
, signal_print
);
4642 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
4644 SET_SIGS (nsigs
, sigs
, signal_program
);
4646 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
4648 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4650 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
4652 SET_SIGS (nsigs
, sigs
, signal_program
);
4654 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
4656 UNSET_SIGS (nsigs
, sigs
, signal_print
);
4657 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4659 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
4661 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4663 else if (digits
> 0)
4665 /* It is numeric. The numeric signal refers to our own
4666 internal signal numbering from target.h, not to host/target
4667 signal number. This is a feature; users really should be
4668 using symbolic names anyway, and the common ones like
4669 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
4671 sigfirst
= siglast
= (int)
4672 target_signal_from_command (atoi (*argv
));
4673 if ((*argv
)[digits
] == '-')
4676 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
4678 if (sigfirst
> siglast
)
4680 /* Bet he didn't figure we'd think of this case... */
4688 oursig
= target_signal_from_name (*argv
);
4689 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
4691 sigfirst
= siglast
= (int) oursig
;
4695 /* Not a number and not a recognized flag word => complain. */
4696 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
4700 /* If any signal numbers or symbol names were found, set flags for
4701 which signals to apply actions to. */
4703 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
4705 switch ((enum target_signal
) signum
)
4707 case TARGET_SIGNAL_TRAP
:
4708 case TARGET_SIGNAL_INT
:
4709 if (!allsigs
&& !sigs
[signum
])
4711 if (query (_("%s is used by the debugger.\n\
4712 Are you sure you want to change it? "), target_signal_to_name ((enum target_signal
) signum
)))
4718 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4719 gdb_flush (gdb_stdout
);
4723 case TARGET_SIGNAL_0
:
4724 case TARGET_SIGNAL_DEFAULT
:
4725 case TARGET_SIGNAL_UNKNOWN
:
4726 /* Make sure that "all" doesn't print these. */
4737 for (signum
= 0; signum
< nsigs
; signum
++)
4740 target_notice_signals (inferior_ptid
);
4744 /* Show the results. */
4745 sig_print_header ();
4746 for (; signum
< nsigs
; signum
++)
4748 sig_print_info (signum
);
4754 do_cleanups (old_chain
);
4758 xdb_handle_command (char *args
, int from_tty
)
4761 struct cleanup
*old_chain
;
4764 error_no_arg (_("xdb command"));
4766 /* Break the command line up into args. */
4768 argv
= gdb_buildargv (args
);
4769 old_chain
= make_cleanup_freeargv (argv
);
4770 if (argv
[1] != (char *) NULL
)
4775 bufLen
= strlen (argv
[0]) + 20;
4776 argBuf
= (char *) xmalloc (bufLen
);
4780 enum target_signal oursig
;
4782 oursig
= target_signal_from_name (argv
[0]);
4783 memset (argBuf
, 0, bufLen
);
4784 if (strcmp (argv
[1], "Q") == 0)
4785 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4788 if (strcmp (argv
[1], "s") == 0)
4790 if (!signal_stop
[oursig
])
4791 sprintf (argBuf
, "%s %s", argv
[0], "stop");
4793 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
4795 else if (strcmp (argv
[1], "i") == 0)
4797 if (!signal_program
[oursig
])
4798 sprintf (argBuf
, "%s %s", argv
[0], "pass");
4800 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
4802 else if (strcmp (argv
[1], "r") == 0)
4804 if (!signal_print
[oursig
])
4805 sprintf (argBuf
, "%s %s", argv
[0], "print");
4807 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4813 handle_command (argBuf
, from_tty
);
4815 printf_filtered (_("Invalid signal handling flag.\n"));
4820 do_cleanups (old_chain
);
4823 /* Print current contents of the tables set by the handle command.
4824 It is possible we should just be printing signals actually used
4825 by the current target (but for things to work right when switching
4826 targets, all signals should be in the signal tables). */
4829 signals_info (char *signum_exp
, int from_tty
)
4831 enum target_signal oursig
;
4832 sig_print_header ();
4836 /* First see if this is a symbol name. */
4837 oursig
= target_signal_from_name (signum_exp
);
4838 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
4840 /* No, try numeric. */
4842 target_signal_from_command (parse_and_eval_long (signum_exp
));
4844 sig_print_info (oursig
);
4848 printf_filtered ("\n");
4849 /* These ugly casts brought to you by the native VAX compiler. */
4850 for (oursig
= TARGET_SIGNAL_FIRST
;
4851 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
4852 oursig
= (enum target_signal
) ((int) oursig
+ 1))
4856 if (oursig
!= TARGET_SIGNAL_UNKNOWN
4857 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
4858 sig_print_info (oursig
);
4861 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4864 /* The $_siginfo convenience variable is a bit special. We don't know
4865 for sure the type of the value until we actually have a chance to
4866 fetch the data. The type can change depending on gdbarch, so it it
4867 also dependent on which thread you have selected.
4869 1. making $_siginfo be an internalvar that creates a new value on
4872 2. making the value of $_siginfo be an lval_computed value. */
4874 /* This function implements the lval_computed support for reading a
4878 siginfo_value_read (struct value
*v
)
4880 LONGEST transferred
;
4883 target_read (¤t_target
, TARGET_OBJECT_SIGNAL_INFO
,
4885 value_contents_all_raw (v
),
4887 TYPE_LENGTH (value_type (v
)));
4889 if (transferred
!= TYPE_LENGTH (value_type (v
)))
4890 error (_("Unable to read siginfo"));
4893 /* This function implements the lval_computed support for writing a
4897 siginfo_value_write (struct value
*v
, struct value
*fromval
)
4899 LONGEST transferred
;
4901 transferred
= target_write (¤t_target
,
4902 TARGET_OBJECT_SIGNAL_INFO
,
4904 value_contents_all_raw (fromval
),
4906 TYPE_LENGTH (value_type (fromval
)));
4908 if (transferred
!= TYPE_LENGTH (value_type (fromval
)))
4909 error (_("Unable to write siginfo"));
4912 static struct lval_funcs siginfo_value_funcs
=
4918 /* Return a new value with the correct type for the siginfo object of
4919 the current thread. Return a void value if there's no object
4922 static struct value
*
4923 siginfo_make_value (struct internalvar
*var
)
4926 struct gdbarch
*gdbarch
;
4928 if (target_has_stack
4929 && !ptid_equal (inferior_ptid
, null_ptid
))
4931 gdbarch
= get_frame_arch (get_current_frame ());
4933 if (gdbarch_get_siginfo_type_p (gdbarch
))
4935 type
= gdbarch_get_siginfo_type (gdbarch
);
4937 return allocate_computed_value (type
, &siginfo_value_funcs
, NULL
);
4941 return allocate_value (builtin_type_void
);
4945 /* Inferior thread state.
4946 These are details related to the inferior itself, and don't include
4947 things like what frame the user had selected or what gdb was doing
4948 with the target at the time.
4949 For inferior function calls these are things we want to restore
4950 regardless of whether the function call successfully completes
4951 or the dummy frame has to be manually popped. */
4953 struct inferior_thread_state
4955 enum target_signal stop_signal
;
4957 struct regcache
*registers
;
4960 struct inferior_thread_state
*
4961 save_inferior_thread_state (void)
4963 struct inferior_thread_state
*inf_state
= XMALLOC (struct inferior_thread_state
);
4964 struct thread_info
*tp
= inferior_thread ();
4966 inf_state
->stop_signal
= tp
->stop_signal
;
4967 inf_state
->stop_pc
= stop_pc
;
4969 inf_state
->registers
= regcache_dup (get_current_regcache ());
4974 /* Restore inferior session state to INF_STATE. */
4977 restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
4979 struct thread_info
*tp
= inferior_thread ();
4981 tp
->stop_signal
= inf_state
->stop_signal
;
4982 stop_pc
= inf_state
->stop_pc
;
4984 /* The inferior can be gone if the user types "print exit(0)"
4985 (and perhaps other times). */
4986 if (target_has_execution
)
4987 /* NB: The register write goes through to the target. */
4988 regcache_cpy (get_current_regcache (), inf_state
->registers
);
4989 regcache_xfree (inf_state
->registers
);
4994 do_restore_inferior_thread_state_cleanup (void *state
)
4996 restore_inferior_thread_state (state
);
5000 make_cleanup_restore_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5002 return make_cleanup (do_restore_inferior_thread_state_cleanup
, inf_state
);
5006 discard_inferior_thread_state (struct inferior_thread_state
*inf_state
)
5008 regcache_xfree (inf_state
->registers
);
5013 get_inferior_thread_state_regcache (struct inferior_thread_state
*inf_state
)
5015 return inf_state
->registers
;
5018 /* Session related state for inferior function calls.
5019 These are the additional bits of state that need to be restored
5020 when an inferior function call successfully completes. */
5022 struct inferior_status
5026 int stop_stack_dummy
;
5027 int stopped_by_random_signal
;
5028 int stepping_over_breakpoint
;
5029 CORE_ADDR step_range_start
;
5030 CORE_ADDR step_range_end
;
5031 struct frame_id step_frame_id
;
5032 enum step_over_calls_kind step_over_calls
;
5033 CORE_ADDR step_resume_break_address
;
5034 int stop_after_trap
;
5037 /* ID if the selected frame when the inferior function call was made. */
5038 struct frame_id selected_frame_id
;
5040 int proceed_to_finish
;
5044 /* Save all of the information associated with the inferior<==>gdb
5047 struct inferior_status
*
5048 save_inferior_status (void)
5050 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
5051 struct thread_info
*tp
= inferior_thread ();
5052 struct inferior
*inf
= current_inferior ();
5054 inf_status
->stop_step
= tp
->stop_step
;
5055 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
5056 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
5057 inf_status
->stepping_over_breakpoint
= tp
->trap_expected
;
5058 inf_status
->step_range_start
= tp
->step_range_start
;
5059 inf_status
->step_range_end
= tp
->step_range_end
;
5060 inf_status
->step_frame_id
= tp
->step_frame_id
;
5061 inf_status
->step_over_calls
= tp
->step_over_calls
;
5062 inf_status
->stop_after_trap
= stop_after_trap
;
5063 inf_status
->stop_soon
= inf
->stop_soon
;
5064 /* Save original bpstat chain here; replace it with copy of chain.
5065 If caller's caller is walking the chain, they'll be happier if we
5066 hand them back the original chain when restore_inferior_status is
5068 inf_status
->stop_bpstat
= tp
->stop_bpstat
;
5069 tp
->stop_bpstat
= bpstat_copy (tp
->stop_bpstat
);
5070 inf_status
->proceed_to_finish
= tp
->proceed_to_finish
;
5071 inf_status
->in_infcall
= tp
->in_infcall
;
5073 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
5079 restore_selected_frame (void *args
)
5081 struct frame_id
*fid
= (struct frame_id
*) args
;
5082 struct frame_info
*frame
;
5084 frame
= frame_find_by_id (*fid
);
5086 /* If inf_status->selected_frame_id is NULL, there was no previously
5090 warning (_("Unable to restore previously selected frame."));
5094 select_frame (frame
);
5099 /* Restore inferior session state to INF_STATUS. */
5102 restore_inferior_status (struct inferior_status
*inf_status
)
5104 struct thread_info
*tp
= inferior_thread ();
5105 struct inferior
*inf
= current_inferior ();
5107 tp
->stop_step
= inf_status
->stop_step
;
5108 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
5109 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
5110 tp
->trap_expected
= inf_status
->stepping_over_breakpoint
;
5111 tp
->step_range_start
= inf_status
->step_range_start
;
5112 tp
->step_range_end
= inf_status
->step_range_end
;
5113 tp
->step_frame_id
= inf_status
->step_frame_id
;
5114 tp
->step_over_calls
= inf_status
->step_over_calls
;
5115 stop_after_trap
= inf_status
->stop_after_trap
;
5116 inf
->stop_soon
= inf_status
->stop_soon
;
5117 bpstat_clear (&tp
->stop_bpstat
);
5118 tp
->stop_bpstat
= inf_status
->stop_bpstat
;
5119 inf_status
->stop_bpstat
= NULL
;
5120 tp
->proceed_to_finish
= inf_status
->proceed_to_finish
;
5121 tp
->in_infcall
= inf_status
->in_infcall
;
5123 if (target_has_stack
)
5125 /* The point of catch_errors is that if the stack is clobbered,
5126 walking the stack might encounter a garbage pointer and
5127 error() trying to dereference it. */
5129 (restore_selected_frame
, &inf_status
->selected_frame_id
,
5130 "Unable to restore previously selected frame:\n",
5131 RETURN_MASK_ERROR
) == 0)
5132 /* Error in restoring the selected frame. Select the innermost
5134 select_frame (get_current_frame ());
5141 do_restore_inferior_status_cleanup (void *sts
)
5143 restore_inferior_status (sts
);
5147 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
5149 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
5153 discard_inferior_status (struct inferior_status
*inf_status
)
5155 /* See save_inferior_status for info on stop_bpstat. */
5156 bpstat_clear (&inf_status
->stop_bpstat
);
5161 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
5163 struct target_waitstatus last
;
5166 get_last_target_status (&last_ptid
, &last
);
5168 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
5171 if (!ptid_equal (last_ptid
, pid
))
5174 *child_pid
= last
.value
.related_pid
;
5179 inferior_has_vforked (ptid_t pid
, ptid_t
*child_pid
)
5181 struct target_waitstatus last
;
5184 get_last_target_status (&last_ptid
, &last
);
5186 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
5189 if (!ptid_equal (last_ptid
, pid
))
5192 *child_pid
= last
.value
.related_pid
;
5197 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
5199 struct target_waitstatus last
;
5202 get_last_target_status (&last_ptid
, &last
);
5204 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
5207 if (!ptid_equal (last_ptid
, pid
))
5210 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
5214 /* Oft used ptids */
5216 ptid_t minus_one_ptid
;
5218 /* Create a ptid given the necessary PID, LWP, and TID components. */
5221 ptid_build (int pid
, long lwp
, long tid
)
5231 /* Create a ptid from just a pid. */
5234 pid_to_ptid (int pid
)
5236 return ptid_build (pid
, 0, 0);
5239 /* Fetch the pid (process id) component from a ptid. */
5242 ptid_get_pid (ptid_t ptid
)
5247 /* Fetch the lwp (lightweight process) component from a ptid. */
5250 ptid_get_lwp (ptid_t ptid
)
5255 /* Fetch the tid (thread id) component from a ptid. */
5258 ptid_get_tid (ptid_t ptid
)
5263 /* ptid_equal() is used to test equality of two ptids. */
5266 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
5268 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
5269 && ptid1
.tid
== ptid2
.tid
);
5272 /* Returns true if PTID represents a process. */
5275 ptid_is_pid (ptid_t ptid
)
5277 if (ptid_equal (minus_one_ptid
, ptid
))
5279 if (ptid_equal (null_ptid
, ptid
))
5282 return (ptid_get_lwp (ptid
) == 0 && ptid_get_tid (ptid
) == 0);
5285 /* restore_inferior_ptid() will be used by the cleanup machinery
5286 to restore the inferior_ptid value saved in a call to
5287 save_inferior_ptid(). */
5290 restore_inferior_ptid (void *arg
)
5292 ptid_t
*saved_ptid_ptr
= arg
;
5293 inferior_ptid
= *saved_ptid_ptr
;
5297 /* Save the value of inferior_ptid so that it may be restored by a
5298 later call to do_cleanups(). Returns the struct cleanup pointer
5299 needed for later doing the cleanup. */
5302 save_inferior_ptid (void)
5304 ptid_t
*saved_ptid_ptr
;
5306 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
5307 *saved_ptid_ptr
= inferior_ptid
;
5308 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
5312 /* User interface for reverse debugging:
5313 Set exec-direction / show exec-direction commands
5314 (returns error unless target implements to_set_exec_direction method). */
5316 enum exec_direction_kind execution_direction
= EXEC_FORWARD
;
5317 static const char exec_forward
[] = "forward";
5318 static const char exec_reverse
[] = "reverse";
5319 static const char *exec_direction
= exec_forward
;
5320 static const char *exec_direction_names
[] = {
5327 set_exec_direction_func (char *args
, int from_tty
,
5328 struct cmd_list_element
*cmd
)
5330 if (target_can_execute_reverse
)
5332 if (!strcmp (exec_direction
, exec_forward
))
5333 execution_direction
= EXEC_FORWARD
;
5334 else if (!strcmp (exec_direction
, exec_reverse
))
5335 execution_direction
= EXEC_REVERSE
;
5340 show_exec_direction_func (struct ui_file
*out
, int from_tty
,
5341 struct cmd_list_element
*cmd
, const char *value
)
5343 switch (execution_direction
) {
5345 fprintf_filtered (out
, _("Forward.\n"));
5348 fprintf_filtered (out
, _("Reverse.\n"));
5352 fprintf_filtered (out
,
5353 _("Forward (target `%s' does not support exec-direction).\n"),
5359 /* User interface for non-stop mode. */
5362 static int non_stop_1
= 0;
5365 set_non_stop (char *args
, int from_tty
,
5366 struct cmd_list_element
*c
)
5368 if (target_has_execution
)
5370 non_stop_1
= non_stop
;
5371 error (_("Cannot change this setting while the inferior is running."));
5374 non_stop
= non_stop_1
;
5378 show_non_stop (struct ui_file
*file
, int from_tty
,
5379 struct cmd_list_element
*c
, const char *value
)
5381 fprintf_filtered (file
,
5382 _("Controlling the inferior in non-stop mode is %s.\n"),
5388 _initialize_infrun (void)
5392 struct cmd_list_element
*c
;
5394 add_info ("signals", signals_info
, _("\
5395 What debugger does when program gets various signals.\n\
5396 Specify a signal as argument to print info on that signal only."));
5397 add_info_alias ("handle", "signals", 0);
5399 add_com ("handle", class_run
, handle_command
, _("\
5400 Specify how to handle a signal.\n\
5401 Args are signals and actions to apply to those signals.\n\
5402 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
5403 from 1-15 are allowed for compatibility with old versions of GDB.\n\
5404 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
5405 The special arg \"all\" is recognized to mean all signals except those\n\
5406 used by the debugger, typically SIGTRAP and SIGINT.\n\
5407 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
5408 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
5409 Stop means reenter debugger if this signal happens (implies print).\n\
5410 Print means print a message if this signal happens.\n\
5411 Pass means let program see this signal; otherwise program doesn't know.\n\
5412 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
5413 Pass and Stop may be combined."));
5416 add_com ("lz", class_info
, signals_info
, _("\
5417 What debugger does when program gets various signals.\n\
5418 Specify a signal as argument to print info on that signal only."));
5419 add_com ("z", class_run
, xdb_handle_command
, _("\
5420 Specify how to handle a signal.\n\
5421 Args are signals and actions to apply to those signals.\n\
5422 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
5423 from 1-15 are allowed for compatibility with old versions of GDB.\n\
5424 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
5425 The special arg \"all\" is recognized to mean all signals except those\n\
5426 used by the debugger, typically SIGTRAP and SIGINT.\n\
5427 Recognized actions include \"s\" (toggles between stop and nostop), \n\
5428 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
5429 nopass), \"Q\" (noprint)\n\
5430 Stop means reenter debugger if this signal happens (implies print).\n\
5431 Print means print a message if this signal happens.\n\
5432 Pass means let program see this signal; otherwise program doesn't know.\n\
5433 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
5434 Pass and Stop may be combined."));
5438 stop_command
= add_cmd ("stop", class_obscure
,
5439 not_just_help_class_command
, _("\
5440 There is no `stop' command, but you can set a hook on `stop'.\n\
5441 This allows you to set a list of commands to be run each time execution\n\
5442 of the program stops."), &cmdlist
);
5444 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
5445 Set inferior debugging."), _("\
5446 Show inferior debugging."), _("\
5447 When non-zero, inferior specific debugging is enabled."),
5450 &setdebuglist
, &showdebuglist
);
5452 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
5453 Set displaced stepping debugging."), _("\
5454 Show displaced stepping debugging."), _("\
5455 When non-zero, displaced stepping specific debugging is enabled."),
5457 show_debug_displaced
,
5458 &setdebuglist
, &showdebuglist
);
5460 add_setshow_boolean_cmd ("non-stop", no_class
,
5462 Set whether gdb controls the inferior in non-stop mode."), _("\
5463 Show whether gdb controls the inferior in non-stop mode."), _("\
5464 When debugging a multi-threaded program and this setting is\n\
5465 off (the default, also called all-stop mode), when one thread stops\n\
5466 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
5467 all other threads in the program while you interact with the thread of\n\
5468 interest. When you continue or step a thread, you can allow the other\n\
5469 threads to run, or have them remain stopped, but while you inspect any\n\
5470 thread's state, all threads stop.\n\
5472 In non-stop mode, when one thread stops, other threads can continue\n\
5473 to run freely. You'll be able to step each thread independently,\n\
5474 leave it stopped or free to run as needed."),
5480 numsigs
= (int) TARGET_SIGNAL_LAST
;
5481 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
5482 signal_print
= (unsigned char *)
5483 xmalloc (sizeof (signal_print
[0]) * numsigs
);
5484 signal_program
= (unsigned char *)
5485 xmalloc (sizeof (signal_program
[0]) * numsigs
);
5486 for (i
= 0; i
< numsigs
; i
++)
5489 signal_print
[i
] = 1;
5490 signal_program
[i
] = 1;
5493 /* Signals caused by debugger's own actions
5494 should not be given to the program afterwards. */
5495 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
5496 signal_program
[TARGET_SIGNAL_INT
] = 0;
5498 /* Signals that are not errors should not normally enter the debugger. */
5499 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
5500 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
5501 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
5502 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
5503 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
5504 signal_print
[TARGET_SIGNAL_PROF
] = 0;
5505 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
5506 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
5507 signal_stop
[TARGET_SIGNAL_IO
] = 0;
5508 signal_print
[TARGET_SIGNAL_IO
] = 0;
5509 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
5510 signal_print
[TARGET_SIGNAL_POLL
] = 0;
5511 signal_stop
[TARGET_SIGNAL_URG
] = 0;
5512 signal_print
[TARGET_SIGNAL_URG
] = 0;
5513 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
5514 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
5516 /* These signals are used internally by user-level thread
5517 implementations. (See signal(5) on Solaris.) Like the above
5518 signals, a healthy program receives and handles them as part of
5519 its normal operation. */
5520 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
5521 signal_print
[TARGET_SIGNAL_LWP
] = 0;
5522 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
5523 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
5524 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
5525 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
5527 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
5528 &stop_on_solib_events
, _("\
5529 Set stopping for shared library events."), _("\
5530 Show stopping for shared library events."), _("\
5531 If nonzero, gdb will give control to the user when the dynamic linker\n\
5532 notifies gdb of shared library events. The most common event of interest\n\
5533 to the user would be loading/unloading of a new library."),
5535 show_stop_on_solib_events
,
5536 &setlist
, &showlist
);
5538 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
5539 follow_fork_mode_kind_names
,
5540 &follow_fork_mode_string
, _("\
5541 Set debugger response to a program call of fork or vfork."), _("\
5542 Show debugger response to a program call of fork or vfork."), _("\
5543 A fork or vfork creates a new process. follow-fork-mode can be:\n\
5544 parent - the original process is debugged after a fork\n\
5545 child - the new process is debugged after a fork\n\
5546 The unfollowed process will continue to run.\n\
5547 By default, the debugger will follow the parent process."),
5549 show_follow_fork_mode_string
,
5550 &setlist
, &showlist
);
5552 add_setshow_enum_cmd ("scheduler-locking", class_run
,
5553 scheduler_enums
, &scheduler_mode
, _("\
5554 Set mode for locking scheduler during execution."), _("\
5555 Show mode for locking scheduler during execution."), _("\
5556 off == no locking (threads may preempt at any time)\n\
5557 on == full locking (no thread except the current thread may run)\n\
5558 step == scheduler locked during every single-step operation.\n\
5559 In this mode, no other thread may run during a step command.\n\
5560 Other threads may run while stepping over a function call ('next')."),
5561 set_schedlock_func
, /* traps on target vector */
5562 show_scheduler_mode
,
5563 &setlist
, &showlist
);
5565 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
5566 Set mode of the step operation."), _("\
5567 Show mode of the step operation."), _("\
5568 When set, doing a step over a function without debug line information\n\
5569 will stop at the first instruction of that function. Otherwise, the\n\
5570 function is skipped and the step command stops at a different source line."),
5572 show_step_stop_if_no_debug
,
5573 &setlist
, &showlist
);
5575 add_setshow_enum_cmd ("displaced-stepping", class_run
,
5576 can_use_displaced_stepping_enum
,
5577 &can_use_displaced_stepping
, _("\
5578 Set debugger's willingness to use displaced stepping."), _("\
5579 Show debugger's willingness to use displaced stepping."), _("\
5580 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
5581 supported by the target architecture. If off, gdb will not use displaced\n\
5582 stepping to step over breakpoints, even if such is supported by the target\n\
5583 architecture. If auto (which is the default), gdb will use displaced stepping\n\
5584 if the target architecture supports it and non-stop mode is active, but will not\n\
5585 use it in all-stop mode (see help set non-stop)."),
5587 show_can_use_displaced_stepping
,
5588 &setlist
, &showlist
);
5590 add_setshow_enum_cmd ("exec-direction", class_run
, exec_direction_names
,
5591 &exec_direction
, _("Set direction of execution.\n\
5592 Options are 'forward' or 'reverse'."),
5593 _("Show direction of execution (forward/reverse)."),
5594 _("Tells gdb whether to execute forward or backward."),
5595 set_exec_direction_func
, show_exec_direction_func
,
5596 &setlist
, &showlist
);
5598 /* ptid initializations */
5599 null_ptid
= ptid_build (0, 0, 0);
5600 minus_one_ptid
= ptid_build (-1, 0, 0);
5601 inferior_ptid
= null_ptid
;
5602 target_last_wait_ptid
= minus_one_ptid
;
5603 displaced_step_ptid
= null_ptid
;
5605 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed
);
5606 observer_attach_thread_stop_requested (infrun_thread_stop_requested
);
5607 observer_attach_thread_exit (infrun_thread_thread_exit
);
5609 /* Explicitly create without lookup, since that tries to create a
5610 value with a void typed value, and when we get here, gdbarch
5611 isn't initialized yet. At this point, we're quite sure there
5612 isn't another convenience variable of the same name. */
5613 create_internalvar_type_lazy ("_siginfo", siginfo_make_value
);