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 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"
49 #include "gdb_assert.h"
50 #include "mi/mi-common.h"
52 /* Prototypes for local functions */
54 static void signals_info (char *, int);
56 static void handle_command (char *, int);
58 static void sig_print_info (enum target_signal
);
60 static void sig_print_header (void);
62 static void resume_cleanups (void *);
64 static int hook_stop_stub (void *);
66 static int restore_selected_frame (void *);
68 static void build_infrun (void);
70 static int follow_fork (void);
72 static void set_schedlock_func (char *args
, int from_tty
,
73 struct cmd_list_element
*c
);
75 struct thread_stepping_state
;
77 static int currently_stepping (struct thread_stepping_state
*tss
);
79 static void xdb_handle_command (char *args
, int from_tty
);
81 static int prepare_to_proceed (int);
83 void _initialize_infrun (void);
85 /* When set, stop the 'step' command if we enter a function which has
86 no line number information. The normal behavior is that we step
87 over such function. */
88 int step_stop_if_no_debug
= 0;
90 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
91 struct cmd_list_element
*c
, const char *value
)
93 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
96 /* In asynchronous mode, but simulating synchronous execution. */
98 int sync_execution
= 0;
100 /* wait_for_inferior and normal_stop use this to notify the user
101 when the inferior stopped in a different thread than it had been
104 static ptid_t previous_inferior_ptid
;
106 int debug_displaced
= 0;
108 show_debug_displaced (struct ui_file
*file
, int from_tty
,
109 struct cmd_list_element
*c
, const char *value
)
111 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
114 static int debug_infrun
= 0;
116 show_debug_infrun (struct ui_file
*file
, int from_tty
,
117 struct cmd_list_element
*c
, const char *value
)
119 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
122 /* If the program uses ELF-style shared libraries, then calls to
123 functions in shared libraries go through stubs, which live in a
124 table called the PLT (Procedure Linkage Table). The first time the
125 function is called, the stub sends control to the dynamic linker,
126 which looks up the function's real address, patches the stub so
127 that future calls will go directly to the function, and then passes
128 control to the function.
130 If we are stepping at the source level, we don't want to see any of
131 this --- we just want to skip over the stub and the dynamic linker.
132 The simple approach is to single-step until control leaves the
135 However, on some systems (e.g., Red Hat's 5.2 distribution) the
136 dynamic linker calls functions in the shared C library, so you
137 can't tell from the PC alone whether the dynamic linker is still
138 running. In this case, we use a step-resume breakpoint to get us
139 past the dynamic linker, as if we were using "next" to step over a
142 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
143 linker code or not. Normally, this means we single-step. However,
144 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
145 address where we can place a step-resume breakpoint to get past the
146 linker's symbol resolution function.
148 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
149 pretty portable way, by comparing the PC against the address ranges
150 of the dynamic linker's sections.
152 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
153 it depends on internal details of the dynamic linker. It's usually
154 not too hard to figure out where to put a breakpoint, but it
155 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
156 sanity checking. If it can't figure things out, returning zero and
157 getting the (possibly confusing) stepping behavior is better than
158 signalling an error, which will obscure the change in the
161 /* This function returns TRUE if pc is the address of an instruction
162 that lies within the dynamic linker (such as the event hook, or the
165 This function must be used only when a dynamic linker event has
166 been caught, and the inferior is being stepped out of the hook, or
167 undefined results are guaranteed. */
169 #ifndef SOLIB_IN_DYNAMIC_LINKER
170 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
174 /* Convert the #defines into values. This is temporary until wfi control
175 flow is completely sorted out. */
177 #ifndef CANNOT_STEP_HW_WATCHPOINTS
178 #define CANNOT_STEP_HW_WATCHPOINTS 0
180 #undef CANNOT_STEP_HW_WATCHPOINTS
181 #define CANNOT_STEP_HW_WATCHPOINTS 1
184 /* Tables of how to react to signals; the user sets them. */
186 static unsigned char *signal_stop
;
187 static unsigned char *signal_print
;
188 static unsigned char *signal_program
;
190 #define SET_SIGS(nsigs,sigs,flags) \
192 int signum = (nsigs); \
193 while (signum-- > 0) \
194 if ((sigs)[signum]) \
195 (flags)[signum] = 1; \
198 #define UNSET_SIGS(nsigs,sigs,flags) \
200 int signum = (nsigs); \
201 while (signum-- > 0) \
202 if ((sigs)[signum]) \
203 (flags)[signum] = 0; \
206 /* Value to pass to target_resume() to cause all threads to resume */
208 #define RESUME_ALL (pid_to_ptid (-1))
210 /* Command list pointer for the "stop" placeholder. */
212 static struct cmd_list_element
*stop_command
;
214 /* Function inferior was in as of last step command. */
216 static struct symbol
*step_start_function
;
218 /* Nonzero if we are presently stepping over a breakpoint.
220 If we hit a breakpoint or watchpoint, and then continue,
221 we need to single step the current thread with breakpoints
222 disabled, to avoid hitting the same breakpoint or
223 watchpoint again. And we should step just a single
224 thread and keep other threads stopped, so that
225 other threads don't miss breakpoints while they are removed.
227 So, this variable simultaneously means that we need to single
228 step the current thread, keep other threads stopped, and that
229 breakpoints should be removed while we step.
231 This variable is set either:
232 - in proceed, when we resume inferior on user's explicit request
233 - in keep_going, if handle_inferior_event decides we need to
234 step over breakpoint.
236 The variable is cleared in clear_proceed_status, called every
237 time before we call proceed. The proceed calls wait_for_inferior,
238 which calls handle_inferior_event in a loop, and until
239 wait_for_inferior exits, this variable is changed only by keep_going. */
241 static int stepping_over_breakpoint
;
243 /* Nonzero if we want to give control to the user when we're notified
244 of shared library events by the dynamic linker. */
245 static int stop_on_solib_events
;
247 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
248 struct cmd_list_element
*c
, const char *value
)
250 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
254 /* Nonzero means expecting a trace trap
255 and should stop the inferior and return silently when it happens. */
259 /* Nonzero means expecting a trap and caller will handle it themselves.
260 It is used after attach, due to attaching to a process;
261 when running in the shell before the child program has been exec'd;
262 and when running some kinds of remote stuff (FIXME?). */
264 enum stop_kind stop_soon
;
266 /* Nonzero if proceed is being used for a "finish" command or a similar
267 situation when stop_registers should be saved. */
269 int proceed_to_finish
;
271 /* Save register contents here when about to pop a stack dummy frame,
272 if-and-only-if proceed_to_finish is set.
273 Thus this contains the return value from the called function (assuming
274 values are returned in a register). */
276 struct regcache
*stop_registers
;
278 /* Nonzero after stop if current stack frame should be printed. */
280 static int stop_print_frame
;
282 /* Step-resume or longjmp-resume breakpoint. */
283 static struct breakpoint
*step_resume_breakpoint
= NULL
;
285 /* This is a cached copy of the pid/waitstatus of the last event
286 returned by target_wait()/deprecated_target_wait_hook(). This
287 information is returned by get_last_target_status(). */
288 static ptid_t target_last_wait_ptid
;
289 static struct target_waitstatus target_last_waitstatus
;
291 /* Context-switchable data. */
292 struct thread_stepping_state
294 /* Should we step over breakpoint next time keep_going
296 int stepping_over_breakpoint
;
297 struct symtab_and_line sal
;
299 struct symtab
*current_symtab
;
300 int step_after_step_resume_breakpoint
;
301 int stepping_through_solib_after_catch
;
302 bpstat stepping_through_solib_catchpoints
;
305 struct thread_stepping_state gtss
;
306 struct thread_stepping_state
*tss
= >ss
;
308 static void context_switch (ptid_t ptid
);
310 void init_thread_stepping_state (struct thread_stepping_state
*tss
);
312 void init_infwait_state (void);
314 /* This is used to remember when a fork, vfork or exec event
315 was caught by a catchpoint, and thus the event is to be
316 followed at the next resume of the inferior, and not
320 enum target_waitkind kind
;
327 char *execd_pathname
;
331 static const char follow_fork_mode_child
[] = "child";
332 static const char follow_fork_mode_parent
[] = "parent";
334 static const char *follow_fork_mode_kind_names
[] = {
335 follow_fork_mode_child
,
336 follow_fork_mode_parent
,
340 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
342 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
343 struct cmd_list_element
*c
, const char *value
)
345 fprintf_filtered (file
, _("\
346 Debugger response to a program call of fork or vfork is \"%s\".\n"),
354 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
356 return target_follow_fork (follow_child
);
360 follow_inferior_reset_breakpoints (void)
362 /* Was there a step_resume breakpoint? (There was if the user
363 did a "next" at the fork() call.) If so, explicitly reset its
366 step_resumes are a form of bp that are made to be per-thread.
367 Since we created the step_resume bp when the parent process
368 was being debugged, and now are switching to the child process,
369 from the breakpoint package's viewpoint, that's a switch of
370 "threads". We must update the bp's notion of which thread
371 it is for, or it'll be ignored when it triggers. */
373 if (step_resume_breakpoint
)
374 breakpoint_re_set_thread (step_resume_breakpoint
);
376 /* Reinsert all breakpoints in the child. The user may have set
377 breakpoints after catching the fork, in which case those
378 were never set in the child, but only in the parent. This makes
379 sure the inserted breakpoints match the breakpoint list. */
381 breakpoint_re_set ();
382 insert_breakpoints ();
385 /* EXECD_PATHNAME is assumed to be non-NULL. */
388 follow_exec (ptid_t pid
, char *execd_pathname
)
390 ptid_t saved_pid
= pid
;
391 struct target_ops
*tgt
;
393 /* This is an exec event that we actually wish to pay attention to.
394 Refresh our symbol table to the newly exec'd program, remove any
397 If there are breakpoints, they aren't really inserted now,
398 since the exec() transformed our inferior into a fresh set
401 We want to preserve symbolic breakpoints on the list, since
402 we have hopes that they can be reset after the new a.out's
403 symbol table is read.
405 However, any "raw" breakpoints must be removed from the list
406 (e.g., the solib bp's), since their address is probably invalid
409 And, we DON'T want to call delete_breakpoints() here, since
410 that may write the bp's "shadow contents" (the instruction
411 value that was overwritten witha TRAP instruction). Since
412 we now have a new a.out, those shadow contents aren't valid. */
413 update_breakpoints_after_exec ();
415 /* If there was one, it's gone now. We cannot truly step-to-next
416 statement through an exec(). */
417 step_resume_breakpoint
= NULL
;
418 step_range_start
= 0;
421 /* What is this a.out's name? */
422 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
424 /* We've followed the inferior through an exec. Therefore, the
425 inferior has essentially been killed & reborn. */
427 gdb_flush (gdb_stdout
);
428 generic_mourn_inferior ();
429 /* Because mourn_inferior resets inferior_ptid. */
430 inferior_ptid
= saved_pid
;
432 if (gdb_sysroot
&& *gdb_sysroot
)
434 char *name
= alloca (strlen (gdb_sysroot
)
435 + strlen (execd_pathname
)
437 strcpy (name
, gdb_sysroot
);
438 strcat (name
, execd_pathname
);
439 execd_pathname
= name
;
442 /* That a.out is now the one to use. */
443 exec_file_attach (execd_pathname
, 0);
445 /* Reset the shared library package. This ensures that we get a
446 shlib event when the child reaches "_start", at which point the
447 dld will have had a chance to initialize the child. */
448 /* Also, loading a symbol file below may trigger symbol lookups, and
449 we don't want those to be satisfied by the libraries of the
450 previous incarnation of this process. */
451 no_shared_libraries (NULL
, 0);
453 /* Load the main file's symbols. */
454 symbol_file_add_main (execd_pathname
, 0);
456 #ifdef SOLIB_CREATE_INFERIOR_HOOK
457 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
459 solib_create_inferior_hook ();
462 /* Reinsert all breakpoints. (Those which were symbolic have
463 been reset to the proper address in the new a.out, thanks
464 to symbol_file_command...) */
465 insert_breakpoints ();
467 /* The next resume of this inferior should bring it to the shlib
468 startup breakpoints. (If the user had also set bp's on
469 "main" from the old (parent) process, then they'll auto-
470 matically get reset there in the new process.) */
473 /* Non-zero if we just simulating a single-step. This is needed
474 because we cannot remove the breakpoints in the inferior process
475 until after the `wait' in `wait_for_inferior'. */
476 static int singlestep_breakpoints_inserted_p
= 0;
478 /* The thread we inserted single-step breakpoints for. */
479 static ptid_t singlestep_ptid
;
481 /* PC when we started this single-step. */
482 static CORE_ADDR singlestep_pc
;
484 /* If another thread hit the singlestep breakpoint, we save the original
485 thread here so that we can resume single-stepping it later. */
486 static ptid_t saved_singlestep_ptid
;
487 static int stepping_past_singlestep_breakpoint
;
489 /* If not equal to null_ptid, this means that after stepping over breakpoint
490 is finished, we need to switch to deferred_step_ptid, and step it.
492 The use case is when one thread has hit a breakpoint, and then the user
493 has switched to another thread and issued 'step'. We need to step over
494 breakpoint in the thread which hit the breakpoint, but then continue
495 stepping the thread user has selected. */
496 static ptid_t deferred_step_ptid
;
498 /* Displaced stepping. */
500 /* In non-stop debugging mode, we must take special care to manage
501 breakpoints properly; in particular, the traditional strategy for
502 stepping a thread past a breakpoint it has hit is unsuitable.
503 'Displaced stepping' is a tactic for stepping one thread past a
504 breakpoint it has hit while ensuring that other threads running
505 concurrently will hit the breakpoint as they should.
507 The traditional way to step a thread T off a breakpoint in a
508 multi-threaded program in all-stop mode is as follows:
510 a0) Initially, all threads are stopped, and breakpoints are not
512 a1) We single-step T, leaving breakpoints uninserted.
513 a2) We insert breakpoints, and resume all threads.
515 In non-stop debugging, however, this strategy is unsuitable: we
516 don't want to have to stop all threads in the system in order to
517 continue or step T past a breakpoint. Instead, we use displaced
520 n0) Initially, T is stopped, other threads are running, and
521 breakpoints are inserted.
522 n1) We copy the instruction "under" the breakpoint to a separate
523 location, outside the main code stream, making any adjustments
524 to the instruction, register, and memory state as directed by
526 n2) We single-step T over the instruction at its new location.
527 n3) We adjust the resulting register and memory state as directed
528 by T's architecture. This includes resetting T's PC to point
529 back into the main instruction stream.
532 This approach depends on the following gdbarch methods:
534 - gdbarch_max_insn_length and gdbarch_displaced_step_location
535 indicate where to copy the instruction, and how much space must
536 be reserved there. We use these in step n1.
538 - gdbarch_displaced_step_copy_insn copies a instruction to a new
539 address, and makes any necessary adjustments to the instruction,
540 register contents, and memory. We use this in step n1.
542 - gdbarch_displaced_step_fixup adjusts registers and memory after
543 we have successfuly single-stepped the instruction, to yield the
544 same effect the instruction would have had if we had executed it
545 at its original address. We use this in step n3.
547 - gdbarch_displaced_step_free_closure provides cleanup.
549 The gdbarch_displaced_step_copy_insn and
550 gdbarch_displaced_step_fixup functions must be written so that
551 copying an instruction with gdbarch_displaced_step_copy_insn,
552 single-stepping across the copied instruction, and then applying
553 gdbarch_displaced_insn_fixup should have the same effects on the
554 thread's memory and registers as stepping the instruction in place
555 would have. Exactly which responsibilities fall to the copy and
556 which fall to the fixup is up to the author of those functions.
558 See the comments in gdbarch.sh for details.
560 Note that displaced stepping and software single-step cannot
561 currently be used in combination, although with some care I think
562 they could be made to. Software single-step works by placing
563 breakpoints on all possible subsequent instructions; if the
564 displaced instruction is a PC-relative jump, those breakpoints
565 could fall in very strange places --- on pages that aren't
566 executable, or at addresses that are not proper instruction
567 boundaries. (We do generally let other threads run while we wait
568 to hit the software single-step breakpoint, and they might
569 encounter such a corrupted instruction.) One way to work around
570 this would be to have gdbarch_displaced_step_copy_insn fully
571 simulate the effect of PC-relative instructions (and return NULL)
572 on architectures that use software single-stepping.
574 In non-stop mode, we can have independent and simultaneous step
575 requests, so more than one thread may need to simultaneously step
576 over a breakpoint. The current implementation assumes there is
577 only one scratch space per process. In this case, we have to
578 serialize access to the scratch space. If thread A wants to step
579 over a breakpoint, but we are currently waiting for some other
580 thread to complete a displaced step, we leave thread A stopped and
581 place it in the displaced_step_request_queue. Whenever a displaced
582 step finishes, we pick the next thread in the queue and start a new
583 displaced step operation on it. See displaced_step_prepare and
584 displaced_step_fixup for details. */
586 /* If this is not null_ptid, this is the thread carrying out a
587 displaced single-step. This thread's state will require fixing up
588 once it has completed its step. */
589 static ptid_t displaced_step_ptid
;
591 struct displaced_step_request
594 struct displaced_step_request
*next
;
597 /* A queue of pending displaced stepping requests. */
598 struct displaced_step_request
*displaced_step_request_queue
;
600 /* The architecture the thread had when we stepped it. */
601 static struct gdbarch
*displaced_step_gdbarch
;
603 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
604 for post-step cleanup. */
605 static struct displaced_step_closure
*displaced_step_closure
;
607 /* The address of the original instruction, and the copy we made. */
608 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
610 /* Saved contents of copy area. */
611 static gdb_byte
*displaced_step_saved_copy
;
613 /* When this is non-zero, we are allowed to use displaced stepping, if
614 the architecture supports it. When this is zero, we use
615 traditional the hold-and-step approach. */
616 int can_use_displaced_stepping
= 1;
618 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
619 struct cmd_list_element
*c
,
622 fprintf_filtered (file
, _("\
623 Debugger's willingness to use displaced stepping to step over "
624 "breakpoints is %s.\n"), value
);
627 /* Return non-zero if displaced stepping is enabled, and can be used
630 use_displaced_stepping (struct gdbarch
*gdbarch
)
632 return (can_use_displaced_stepping
633 && gdbarch_displaced_step_copy_insn_p (gdbarch
));
636 /* Clean out any stray displaced stepping state. */
638 displaced_step_clear (void)
640 /* Indicate that there is no cleanup pending. */
641 displaced_step_ptid
= null_ptid
;
643 if (displaced_step_closure
)
645 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
646 displaced_step_closure
);
647 displaced_step_closure
= NULL
;
652 cleanup_displaced_step_closure (void *ptr
)
654 struct displaced_step_closure
*closure
= ptr
;
656 gdbarch_displaced_step_free_closure (current_gdbarch
, closure
);
659 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
661 displaced_step_dump_bytes (struct ui_file
*file
,
667 for (i
= 0; i
< len
; i
++)
668 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
669 fputs_unfiltered ("\n", file
);
672 /* Prepare to single-step, using displaced stepping.
674 Note that we cannot use displaced stepping when we have a signal to
675 deliver. If we have a signal to deliver and an instruction to step
676 over, then after the step, there will be no indication from the
677 target whether the thread entered a signal handler or ignored the
678 signal and stepped over the instruction successfully --- both cases
679 result in a simple SIGTRAP. In the first case we mustn't do a
680 fixup, and in the second case we must --- but we can't tell which.
681 Comments in the code for 'random signals' in handle_inferior_event
682 explain how we handle this case instead.
684 Returns 1 if preparing was successful -- this thread is going to be
685 stepped now; or 0 if displaced stepping this thread got queued. */
687 displaced_step_prepare (ptid_t ptid
)
689 struct cleanup
*old_cleanups
;
690 struct regcache
*regcache
= get_thread_regcache (ptid
);
691 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
692 CORE_ADDR original
, copy
;
694 struct displaced_step_closure
*closure
;
696 /* We should never reach this function if the architecture does not
697 support displaced stepping. */
698 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
700 /* For the first cut, we're displaced stepping one thread at a
703 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
705 /* Already waiting for a displaced step to finish. Defer this
706 request and place in queue. */
707 struct displaced_step_request
*req
, *new_req
;
710 fprintf_unfiltered (gdb_stdlog
,
711 "displaced: defering step of %s\n",
712 target_pid_to_str (ptid
));
714 new_req
= xmalloc (sizeof (*new_req
));
715 new_req
->ptid
= ptid
;
716 new_req
->next
= NULL
;
718 if (displaced_step_request_queue
)
720 for (req
= displaced_step_request_queue
;
727 displaced_step_request_queue
= new_req
;
734 fprintf_unfiltered (gdb_stdlog
,
735 "displaced: stepping %s now\n",
736 target_pid_to_str (ptid
));
739 displaced_step_clear ();
741 original
= regcache_read_pc (regcache
);
743 copy
= gdbarch_displaced_step_location (gdbarch
);
744 len
= gdbarch_max_insn_length (gdbarch
);
746 /* Save the original contents of the copy area. */
747 displaced_step_saved_copy
= xmalloc (len
);
748 old_cleanups
= make_cleanup (free_current_contents
,
749 &displaced_step_saved_copy
);
750 read_memory (copy
, displaced_step_saved_copy
, len
);
753 fprintf_unfiltered (gdb_stdlog
, "displaced: saved 0x%s: ",
755 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
758 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
759 original
, copy
, regcache
);
761 /* We don't support the fully-simulated case at present. */
762 gdb_assert (closure
);
764 make_cleanup (cleanup_displaced_step_closure
, closure
);
766 /* Resume execution at the copy. */
767 regcache_write_pc (regcache
, copy
);
769 discard_cleanups (old_cleanups
);
772 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to 0x%s\n",
775 /* Save the information we need to fix things up if the step
777 displaced_step_ptid
= ptid
;
778 displaced_step_gdbarch
= gdbarch
;
779 displaced_step_closure
= closure
;
780 displaced_step_original
= original
;
781 displaced_step_copy
= copy
;
786 displaced_step_clear_cleanup (void *ignore
)
788 displaced_step_clear ();
792 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
794 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
795 inferior_ptid
= ptid
;
796 write_memory (memaddr
, myaddr
, len
);
797 do_cleanups (ptid_cleanup
);
801 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
803 struct cleanup
*old_cleanups
;
805 /* Was this event for the pid we displaced? */
806 if (ptid_equal (displaced_step_ptid
, null_ptid
)
807 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
810 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
812 /* Restore the contents of the copy area. */
814 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
815 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
816 displaced_step_saved_copy
, len
);
818 fprintf_unfiltered (gdb_stdlog
, "displaced: restored 0x%s\n",
819 paddr_nz (displaced_step_copy
));
822 /* Did the instruction complete successfully? */
823 if (signal
== TARGET_SIGNAL_TRAP
)
825 /* Fix up the resulting state. */
826 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
827 displaced_step_closure
,
828 displaced_step_original
,
830 get_thread_regcache (displaced_step_ptid
));
834 /* Since the instruction didn't complete, all we can do is
836 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
837 CORE_ADDR pc
= regcache_read_pc (regcache
);
838 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
839 regcache_write_pc (regcache
, pc
);
842 do_cleanups (old_cleanups
);
844 /* Are there any pending displaced stepping requests? If so, run
846 if (displaced_step_request_queue
)
848 struct displaced_step_request
*head
;
851 head
= displaced_step_request_queue
;
853 displaced_step_request_queue
= head
->next
;
857 fprintf_unfiltered (gdb_stdlog
,
858 "displaced: stepping queued %s now\n",
859 target_pid_to_str (ptid
));
862 displaced_step_ptid
= null_ptid
;
863 displaced_step_prepare (ptid
);
864 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
871 /* Things to clean up if we QUIT out of resume (). */
873 resume_cleanups (void *ignore
)
878 static const char schedlock_off
[] = "off";
879 static const char schedlock_on
[] = "on";
880 static const char schedlock_step
[] = "step";
881 static const char *scheduler_enums
[] = {
887 static const char *scheduler_mode
= schedlock_off
;
889 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
890 struct cmd_list_element
*c
, const char *value
)
892 fprintf_filtered (file
, _("\
893 Mode for locking scheduler during execution is \"%s\".\n"),
898 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
900 if (!target_can_lock_scheduler
)
902 scheduler_mode
= schedlock_off
;
903 error (_("Target '%s' cannot support this command."), target_shortname
);
908 /* Resume the inferior, but allow a QUIT. This is useful if the user
909 wants to interrupt some lengthy single-stepping operation
910 (for child processes, the SIGINT goes to the inferior, and so
911 we get a SIGINT random_signal, but for remote debugging and perhaps
912 other targets, that's not true).
914 STEP nonzero if we should step (zero to continue instead).
915 SIG is the signal to give the inferior (zero for none). */
917 resume (int step
, enum target_signal sig
)
919 int should_resume
= 1;
920 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
921 struct regcache
*regcache
= get_current_regcache ();
922 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
923 CORE_ADDR pc
= regcache_read_pc (regcache
);
927 fprintf_unfiltered (gdb_stdlog
,
928 "infrun: resume (step=%d, signal=%d), "
929 "stepping_over_breakpoint=%d\n",
930 step
, sig
, stepping_over_breakpoint
);
932 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
933 over an instruction that causes a page fault without triggering
934 a hardware watchpoint. The kernel properly notices that it shouldn't
935 stop, because the hardware watchpoint is not triggered, but it forgets
936 the step request and continues the program normally.
937 Work around the problem by removing hardware watchpoints if a step is
938 requested, GDB will check for a hardware watchpoint trigger after the
940 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
941 remove_hw_watchpoints ();
944 /* Normally, by the time we reach `resume', the breakpoints are either
945 removed or inserted, as appropriate. The exception is if we're sitting
946 at a permanent breakpoint; we need to step over it, but permanent
947 breakpoints can't be removed. So we have to test for it here. */
948 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
950 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
951 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
954 The program is stopped at a permanent breakpoint, but GDB does not know\n\
955 how to step past a permanent breakpoint on this architecture. Try using\n\
956 a command like `return' or `jump' to continue execution."));
959 /* If enabled, step over breakpoints by executing a copy of the
960 instruction at a different address.
962 We can't use displaced stepping when we have a signal to deliver;
963 the comments for displaced_step_prepare explain why. The
964 comments in the handle_inferior event for dealing with 'random
965 signals' explain what we do instead. */
966 if (use_displaced_stepping (gdbarch
)
967 && stepping_over_breakpoint
968 && sig
== TARGET_SIGNAL_0
)
970 if (!displaced_step_prepare (inferior_ptid
))
971 /* Got placed in displaced stepping queue. Will be resumed
972 later when all the currently queued displaced stepping
977 if (step
&& gdbarch_software_single_step_p (gdbarch
))
979 /* Do it the hard way, w/temp breakpoints */
980 if (gdbarch_software_single_step (gdbarch
, get_current_frame ()))
982 /* ...and don't ask hardware to do it. */
984 /* and do not pull these breakpoints until after a `wait' in
985 `wait_for_inferior' */
986 singlestep_breakpoints_inserted_p
= 1;
987 singlestep_ptid
= inferior_ptid
;
992 /* If there were any forks/vforks/execs that were caught and are
993 now to be followed, then do so. */
994 switch (pending_follow
.kind
)
996 case TARGET_WAITKIND_FORKED
:
997 case TARGET_WAITKIND_VFORKED
:
998 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
1003 case TARGET_WAITKIND_EXECD
:
1004 /* follow_exec is called as soon as the exec event is seen. */
1005 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
1012 /* Install inferior's terminal modes. */
1013 target_terminal_inferior ();
1019 resume_ptid
= RESUME_ALL
; /* Default */
1021 /* If STEP is set, it's a request to use hardware stepping
1022 facilities. But in that case, we should never
1023 use singlestep breakpoint. */
1024 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1026 if (singlestep_breakpoints_inserted_p
1027 && stepping_past_singlestep_breakpoint
)
1029 /* The situation here is as follows. In thread T1 we wanted to
1030 single-step. Lacking hardware single-stepping we've
1031 set breakpoint at the PC of the next instruction -- call it
1032 P. After resuming, we've hit that breakpoint in thread T2.
1033 Now we've removed original breakpoint, inserted breakpoint
1034 at P+1, and try to step to advance T2 past breakpoint.
1035 We need to step only T2, as if T1 is allowed to freely run,
1036 it can run past P, and if other threads are allowed to run,
1037 they can hit breakpoint at P+1, and nested hits of single-step
1038 breakpoints is not something we'd want -- that's complicated
1039 to support, and has no value. */
1040 resume_ptid
= inferior_ptid
;
1043 if ((step
|| singlestep_breakpoints_inserted_p
)
1044 && stepping_over_breakpoint
)
1046 /* We're allowing a thread to run past a breakpoint it has
1047 hit, by single-stepping the thread with the breakpoint
1048 removed. In which case, we need to single-step only this
1049 thread, and keep others stopped, as they can miss this
1050 breakpoint if allowed to run.
1052 The current code actually removes all breakpoints when
1053 doing this, not just the one being stepped over, so if we
1054 let other threads run, we can actually miss any
1055 breakpoint, not just the one at PC. */
1056 resume_ptid
= inferior_ptid
;
1061 /* With non-stop mode on, threads are always handled
1063 resume_ptid
= inferior_ptid
;
1065 else if ((scheduler_mode
== schedlock_on
)
1066 || (scheduler_mode
== schedlock_step
1067 && (step
|| singlestep_breakpoints_inserted_p
)))
1069 /* User-settable 'scheduler' mode requires solo thread resume. */
1070 resume_ptid
= inferior_ptid
;
1073 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1075 /* Most targets can step a breakpoint instruction, thus
1076 executing it normally. But if this one cannot, just
1077 continue and we will hit it anyway. */
1078 if (step
&& breakpoint_inserted_here_p (pc
))
1083 && use_displaced_stepping (gdbarch
)
1084 && stepping_over_breakpoint
)
1086 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1087 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1090 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
1091 paddr_nz (actual_pc
));
1092 read_memory (actual_pc
, buf
, sizeof (buf
));
1093 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1096 target_resume (resume_ptid
, step
, sig
);
1099 discard_cleanups (old_cleanups
);
1104 /* Clear out all variables saying what to do when inferior is continued.
1105 First do this, then set the ones you want, then call `proceed'. */
1108 clear_proceed_status (void)
1110 stepping_over_breakpoint
= 0;
1111 step_range_start
= 0;
1113 step_frame_id
= null_frame_id
;
1114 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1115 stop_after_trap
= 0;
1116 stop_soon
= NO_STOP_QUIETLY
;
1117 proceed_to_finish
= 0;
1118 breakpoint_proceeded
= 1; /* We're about to proceed... */
1122 regcache_xfree (stop_registers
);
1123 stop_registers
= NULL
;
1126 /* Discard any remaining commands or status from previous stop. */
1127 bpstat_clear (&stop_bpstat
);
1130 /* This should be suitable for any targets that support threads. */
1133 prepare_to_proceed (int step
)
1136 struct target_waitstatus wait_status
;
1138 /* Get the last target status returned by target_wait(). */
1139 get_last_target_status (&wait_ptid
, &wait_status
);
1141 /* Make sure we were stopped at a breakpoint. */
1142 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1143 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1148 /* Switched over from WAIT_PID. */
1149 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1150 && !ptid_equal (inferior_ptid
, wait_ptid
))
1152 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1154 if (breakpoint_here_p (regcache_read_pc (regcache
)))
1156 /* If stepping, remember current thread to switch back to. */
1158 deferred_step_ptid
= inferior_ptid
;
1160 /* Switch back to WAIT_PID thread. */
1161 switch_to_thread (wait_ptid
);
1163 /* We return 1 to indicate that there is a breakpoint here,
1164 so we need to step over it before continuing to avoid
1165 hitting it straight away. */
1173 /* Record the pc of the program the last time it stopped. This is
1174 just used internally by wait_for_inferior, but need to be preserved
1175 over calls to it and cleared when the inferior is started. */
1176 static CORE_ADDR prev_pc
;
1178 /* Basic routine for continuing the program in various fashions.
1180 ADDR is the address to resume at, or -1 for resume where stopped.
1181 SIGGNAL is the signal to give it, or 0 for none,
1182 or -1 for act according to how it stopped.
1183 STEP is nonzero if should trap after one instruction.
1184 -1 means return after that and print nothing.
1185 You should probably set various step_... variables
1186 before calling here, if you are stepping.
1188 You should call clear_proceed_status before calling proceed. */
1191 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1193 struct regcache
*regcache
= get_current_regcache ();
1194 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1195 CORE_ADDR pc
= regcache_read_pc (regcache
);
1199 step_start_function
= find_pc_function (pc
);
1201 stop_after_trap
= 1;
1203 if (addr
== (CORE_ADDR
) -1)
1205 if (pc
== stop_pc
&& breakpoint_here_p (pc
))
1206 /* There is a breakpoint at the address we will resume at,
1207 step one instruction before inserting breakpoints so that
1208 we do not stop right away (and report a second hit at this
1211 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1212 && gdbarch_single_step_through_delay (gdbarch
,
1213 get_current_frame ()))
1214 /* We stepped onto an instruction that needs to be stepped
1215 again before re-inserting the breakpoint, do so. */
1220 regcache_write_pc (regcache
, addr
);
1224 fprintf_unfiltered (gdb_stdlog
,
1225 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1226 paddr_nz (addr
), siggnal
, step
);
1229 /* In non-stop, each thread is handled individually. The context
1230 must already be set to the right thread here. */
1234 /* In a multi-threaded task we may select another thread and
1235 then continue or step.
1237 But if the old thread was stopped at a breakpoint, it will
1238 immediately cause another breakpoint stop without any
1239 execution (i.e. it will report a breakpoint hit incorrectly).
1240 So we must step over it first.
1242 prepare_to_proceed checks the current thread against the
1243 thread that reported the most recent event. If a step-over
1244 is required it returns TRUE and sets the current thread to
1246 if (prepare_to_proceed (step
))
1252 stepping_over_breakpoint
= 1;
1253 /* If displaced stepping is enabled, we can step over the
1254 breakpoint without hitting it, so leave all breakpoints
1255 inserted. Otherwise we need to disable all breakpoints, step
1256 one instruction, and then re-add them when that step is
1258 if (!use_displaced_stepping (gdbarch
))
1259 remove_breakpoints ();
1262 /* We can insert breakpoints if we're not trying to step over one,
1263 or if we are stepping over one but we're using displaced stepping
1265 if (! stepping_over_breakpoint
|| use_displaced_stepping (gdbarch
))
1266 insert_breakpoints ();
1268 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1269 stop_signal
= siggnal
;
1270 /* If this signal should not be seen by program,
1271 give it zero. Used for debugging signals. */
1272 else if (!signal_program
[stop_signal
])
1273 stop_signal
= TARGET_SIGNAL_0
;
1275 annotate_starting ();
1277 /* Make sure that output from GDB appears before output from the
1279 gdb_flush (gdb_stdout
);
1281 /* Refresh prev_pc value just prior to resuming. This used to be
1282 done in stop_stepping, however, setting prev_pc there did not handle
1283 scenarios such as inferior function calls or returning from
1284 a function via the return command. In those cases, the prev_pc
1285 value was not set properly for subsequent commands. The prev_pc value
1286 is used to initialize the starting line number in the ecs. With an
1287 invalid value, the gdb next command ends up stopping at the position
1288 represented by the next line table entry past our start position.
1289 On platforms that generate one line table entry per line, this
1290 is not a problem. However, on the ia64, the compiler generates
1291 extraneous line table entries that do not increase the line number.
1292 When we issue the gdb next command on the ia64 after an inferior call
1293 or a return command, we often end up a few instructions forward, still
1294 within the original line we started.
1296 An attempt was made to have init_execution_control_state () refresh
1297 the prev_pc value before calculating the line number. This approach
1298 did not work because on platforms that use ptrace, the pc register
1299 cannot be read unless the inferior is stopped. At that point, we
1300 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1301 call can fail. Setting the prev_pc value here ensures the value is
1302 updated correctly when the inferior is stopped. */
1303 prev_pc
= regcache_read_pc (get_current_regcache ());
1305 /* Fill in with reasonable starting values. */
1306 init_thread_stepping_state (tss
);
1308 /* We'll update this if & when we switch to a new thread. */
1309 previous_inferior_ptid
= inferior_ptid
;
1311 /* Reset to normal state. */
1312 init_infwait_state ();
1314 /* Resume inferior. */
1315 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1317 /* Wait for it to stop (if not standalone)
1318 and in any case decode why it stopped, and act accordingly. */
1319 /* Do this only if we are not using the event loop, or if the target
1320 does not support asynchronous execution. */
1321 if (!target_can_async_p ())
1323 wait_for_inferior (0);
1329 /* Start remote-debugging of a machine over a serial link. */
1332 start_remote (int from_tty
)
1334 init_wait_for_inferior ();
1335 stop_soon
= STOP_QUIETLY_REMOTE
;
1336 stepping_over_breakpoint
= 0;
1338 /* Always go on waiting for the target, regardless of the mode. */
1339 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1340 indicate to wait_for_inferior that a target should timeout if
1341 nothing is returned (instead of just blocking). Because of this,
1342 targets expecting an immediate response need to, internally, set
1343 things up so that the target_wait() is forced to eventually
1345 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1346 differentiate to its caller what the state of the target is after
1347 the initial open has been performed. Here we're assuming that
1348 the target has stopped. It should be possible to eventually have
1349 target_open() return to the caller an indication that the target
1350 is currently running and GDB state should be set to the same as
1351 for an async run. */
1352 wait_for_inferior (0);
1354 /* Now that the inferior has stopped, do any bookkeeping like
1355 loading shared libraries. We want to do this before normal_stop,
1356 so that the displayed frame is up to date. */
1357 post_create_inferior (¤t_target
, from_tty
);
1362 /* Initialize static vars when a new inferior begins. */
1365 init_wait_for_inferior (void)
1367 /* These are meaningless until the first time through wait_for_inferior. */
1370 breakpoint_init_inferior (inf_starting
);
1372 /* Don't confuse first call to proceed(). */
1373 stop_signal
= TARGET_SIGNAL_0
;
1375 /* The first resume is not following a fork/vfork/exec. */
1376 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1378 clear_proceed_status ();
1380 stepping_past_singlestep_breakpoint
= 0;
1381 deferred_step_ptid
= null_ptid
;
1383 target_last_wait_ptid
= minus_one_ptid
;
1385 init_thread_stepping_state (tss
);
1386 previous_inferior_ptid
= null_ptid
;
1387 init_infwait_state ();
1389 displaced_step_clear ();
1393 /* This enum encodes possible reasons for doing a target_wait, so that
1394 wfi can call target_wait in one place. (Ultimately the call will be
1395 moved out of the infinite loop entirely.) */
1399 infwait_normal_state
,
1400 infwait_thread_hop_state
,
1401 infwait_step_watch_state
,
1402 infwait_nonstep_watch_state
1405 /* Why did the inferior stop? Used to print the appropriate messages
1406 to the interface from within handle_inferior_event(). */
1407 enum inferior_stop_reason
1409 /* Step, next, nexti, stepi finished. */
1411 /* Inferior terminated by signal. */
1413 /* Inferior exited. */
1415 /* Inferior received signal, and user asked to be notified. */
1419 /* The PTID we'll do a target_wait on.*/
1422 /* Current inferior wait state. */
1423 enum infwait_states infwait_state
;
1425 /* Data to be passed around while handling an event. This data is
1426 discarded between events. */
1427 struct execution_control_state
1430 struct target_waitstatus ws
;
1432 CORE_ADDR stop_func_start
;
1433 CORE_ADDR stop_func_end
;
1434 char *stop_func_name
;
1435 int new_thread_event
;
1439 void init_execution_control_state (struct execution_control_state
*ecs
);
1441 void handle_inferior_event (struct execution_control_state
*ecs
);
1443 static void step_into_function (struct execution_control_state
*ecs
);
1444 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1445 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1446 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
1447 struct frame_id sr_id
);
1448 static void insert_longjmp_resume_breakpoint (CORE_ADDR
);
1450 static void stop_stepping (struct execution_control_state
*ecs
);
1451 static void prepare_to_wait (struct execution_control_state
*ecs
);
1452 static void keep_going (struct execution_control_state
*ecs
);
1453 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1456 /* Wait for control to return from inferior to debugger.
1458 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1459 as if they were SIGTRAP signals. This can be useful during
1460 the startup sequence on some targets such as HP/UX, where
1461 we receive an EXEC event instead of the expected SIGTRAP.
1463 If inferior gets a signal, we may decide to start it up again
1464 instead of returning. That is why there is a loop in this function.
1465 When this function actually returns it means the inferior
1466 should be left stopped and GDB should read more commands. */
1469 wait_for_inferior (int treat_exec_as_sigtrap
)
1471 struct cleanup
*old_cleanups
;
1472 struct execution_control_state ecss
;
1473 struct execution_control_state
*ecs
;
1477 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1478 treat_exec_as_sigtrap
);
1480 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1481 &step_resume_breakpoint
);
1484 memset (ecs
, 0, sizeof (*ecs
));
1486 overlay_cache_invalid
= 1;
1488 /* We have to invalidate the registers BEFORE calling target_wait
1489 because they can be loaded from the target while in target_wait.
1490 This makes remote debugging a bit more efficient for those
1491 targets that provide critical registers as part of their normal
1492 status mechanism. */
1494 registers_changed ();
1498 if (deprecated_target_wait_hook
)
1499 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1501 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1503 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1505 xfree (ecs
->ws
.value
.execd_pathname
);
1506 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1507 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
1510 /* Now figure out what to do with the result of the result. */
1511 handle_inferior_event (ecs
);
1513 if (!ecs
->wait_some_more
)
1516 do_cleanups (old_cleanups
);
1519 /* Asynchronous version of wait_for_inferior. It is called by the
1520 event loop whenever a change of state is detected on the file
1521 descriptor corresponding to the target. It can be called more than
1522 once to complete a single execution command. In such cases we need
1523 to keep the state in a global variable ECSS. If it is the last time
1524 that this function is called for a single execution command, then
1525 report to the user that the inferior has stopped, and do the
1526 necessary cleanups. */
1529 fetch_inferior_event (void *client_data
)
1531 struct execution_control_state ecss
;
1532 struct execution_control_state
*ecs
= &ecss
;
1534 memset (ecs
, 0, sizeof (*ecs
));
1536 overlay_cache_invalid
= 1;
1538 /* We have to invalidate the registers BEFORE calling target_wait
1539 because they can be loaded from the target while in target_wait.
1540 This makes remote debugging a bit more efficient for those
1541 targets that provide critical registers as part of their normal
1542 status mechanism. */
1544 registers_changed ();
1546 if (deprecated_target_wait_hook
)
1548 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1550 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1553 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
1554 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1555 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
1556 /* In non-stop mode, each thread is handled individually. Switch
1557 early, so the global state is set correctly for this
1559 context_switch (ecs
->ptid
);
1561 /* Now figure out what to do with the result of the result. */
1562 handle_inferior_event (ecs
);
1564 if (!ecs
->wait_some_more
)
1566 delete_step_resume_breakpoint (&step_resume_breakpoint
);
1569 if (step_multi
&& stop_step
)
1570 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1572 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1576 /* Prepare an execution control state for looping through a
1577 wait_for_inferior-type loop. */
1580 init_execution_control_state (struct execution_control_state
*ecs
)
1582 ecs
->random_signal
= 0;
1585 /* Clear context switchable stepping state. */
1588 init_thread_stepping_state (struct thread_stepping_state
*tss
)
1590 tss
->stepping_over_breakpoint
= 0;
1591 tss
->step_after_step_resume_breakpoint
= 0;
1592 tss
->stepping_through_solib_after_catch
= 0;
1593 tss
->stepping_through_solib_catchpoints
= NULL
;
1594 tss
->sal
= find_pc_line (prev_pc
, 0);
1595 tss
->current_line
= tss
->sal
.line
;
1596 tss
->current_symtab
= tss
->sal
.symtab
;
1599 /* Return the cached copy of the last pid/waitstatus returned by
1600 target_wait()/deprecated_target_wait_hook(). The data is actually
1601 cached by handle_inferior_event(), which gets called immediately
1602 after target_wait()/deprecated_target_wait_hook(). */
1605 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1607 *ptidp
= target_last_wait_ptid
;
1608 *status
= target_last_waitstatus
;
1612 nullify_last_target_wait_ptid (void)
1614 target_last_wait_ptid
= minus_one_ptid
;
1617 /* Switch thread contexts, maintaining "infrun state". */
1620 context_switch (ptid_t ptid
)
1622 /* Caution: it may happen that the new thread (or the old one!)
1623 is not in the thread list. In this case we must not attempt
1624 to "switch context", or we run the risk that our context may
1625 be lost. This may happen as a result of the target module
1626 mishandling thread creation. */
1630 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
1631 target_pid_to_str (inferior_ptid
));
1632 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
1633 target_pid_to_str (ptid
));
1636 if (in_thread_list (inferior_ptid
) && in_thread_list (ptid
))
1637 { /* Perform infrun state context switch: */
1638 /* Save infrun state for the old thread. */
1639 save_infrun_state (inferior_ptid
, prev_pc
,
1640 stepping_over_breakpoint
, step_resume_breakpoint
,
1642 step_range_end
, &step_frame_id
,
1643 tss
->stepping_over_breakpoint
,
1644 tss
->stepping_through_solib_after_catch
,
1645 tss
->stepping_through_solib_catchpoints
,
1646 tss
->current_line
, tss
->current_symtab
,
1647 cmd_continuation
, intermediate_continuation
,
1655 /* Load infrun state for the new thread. */
1656 load_infrun_state (ptid
, &prev_pc
,
1657 &stepping_over_breakpoint
, &step_resume_breakpoint
,
1659 &step_range_end
, &step_frame_id
,
1660 &tss
->stepping_over_breakpoint
,
1661 &tss
->stepping_through_solib_after_catch
,
1662 &tss
->stepping_through_solib_catchpoints
,
1663 &tss
->current_line
, &tss
->current_symtab
,
1664 &cmd_continuation
, &intermediate_continuation
,
1673 switch_to_thread (ptid
);
1676 /* Context switch to thread PTID. */
1678 context_switch_to (ptid_t ptid
)
1680 ptid_t current_ptid
= inferior_ptid
;
1682 /* Context switch to the new thread. */
1683 if (!ptid_equal (ptid
, inferior_ptid
))
1685 context_switch (ptid
);
1687 return current_ptid
;
1691 adjust_pc_after_break (struct execution_control_state
*ecs
)
1693 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
1694 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1695 CORE_ADDR breakpoint_pc
;
1697 /* If this target does not decrement the PC after breakpoints, then
1698 we have nothing to do. */
1699 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
1702 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1703 we aren't, just return.
1705 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1706 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1707 implemented by software breakpoints should be handled through the normal
1710 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1711 different signals (SIGILL or SIGEMT for instance), but it is less
1712 clear where the PC is pointing afterwards. It may not match
1713 gdbarch_decr_pc_after_break. I don't know any specific target that
1714 generates these signals at breakpoints (the code has been in GDB since at
1715 least 1992) so I can not guess how to handle them here.
1717 In earlier versions of GDB, a target with
1718 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1719 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1720 target with both of these set in GDB history, and it seems unlikely to be
1721 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1723 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
1726 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1729 /* Find the location where (if we've hit a breakpoint) the
1730 breakpoint would be. */
1731 breakpoint_pc
= regcache_read_pc (regcache
)
1732 - gdbarch_decr_pc_after_break (gdbarch
);
1734 /* Check whether there actually is a software breakpoint inserted
1735 at that location. */
1736 if (software_breakpoint_inserted_here_p (breakpoint_pc
))
1738 /* When using hardware single-step, a SIGTRAP is reported for both
1739 a completed single-step and a software breakpoint. Need to
1740 differentiate between the two, as the latter needs adjusting
1741 but the former does not.
1743 The SIGTRAP can be due to a completed hardware single-step only if
1744 - we didn't insert software single-step breakpoints
1745 - the thread to be examined is still the current thread
1746 - this thread is currently being stepped
1748 If any of these events did not occur, we must have stopped due
1749 to hitting a software breakpoint, and have to back up to the
1752 As a special case, we could have hardware single-stepped a
1753 software breakpoint. In this case (prev_pc == breakpoint_pc),
1754 we also need to back up to the breakpoint address. */
1756 if (singlestep_breakpoints_inserted_p
1757 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
1758 || !currently_stepping (tss
)
1759 || prev_pc
== breakpoint_pc
)
1760 regcache_write_pc (regcache
, breakpoint_pc
);
1765 init_infwait_state (void)
1767 waiton_ptid
= pid_to_ptid (-1);
1768 infwait_state
= infwait_normal_state
;
1772 error_is_running (void)
1775 Cannot execute this command while the selected thread is running."));
1779 ensure_not_running (void)
1781 if (is_running (inferior_ptid
))
1782 error_is_running ();
1785 /* Given an execution control state that has been freshly filled in
1786 by an event from the inferior, figure out what it means and take
1787 appropriate action. */
1790 handle_inferior_event (struct execution_control_state
*ecs
)
1792 int sw_single_step_trap_p
= 0;
1793 int stopped_by_watchpoint
;
1794 int stepped_after_stopped_by_watchpoint
= 0;
1796 breakpoint_retire_moribund ();
1798 /* Cache the last pid/waitstatus. */
1799 target_last_wait_ptid
= ecs
->ptid
;
1800 target_last_waitstatus
= ecs
->ws
;
1802 /* Always clear state belonging to the previous time we stopped. */
1803 stop_stack_dummy
= 0;
1805 adjust_pc_after_break (ecs
);
1807 switch (infwait_state
)
1809 case infwait_thread_hop_state
:
1811 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
1812 /* Cancel the waiton_ptid. */
1813 waiton_ptid
= pid_to_ptid (-1);
1816 case infwait_normal_state
:
1818 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
1821 case infwait_step_watch_state
:
1823 fprintf_unfiltered (gdb_stdlog
,
1824 "infrun: infwait_step_watch_state\n");
1826 stepped_after_stopped_by_watchpoint
= 1;
1829 case infwait_nonstep_watch_state
:
1831 fprintf_unfiltered (gdb_stdlog
,
1832 "infrun: infwait_nonstep_watch_state\n");
1833 insert_breakpoints ();
1835 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1836 handle things like signals arriving and other things happening
1837 in combination correctly? */
1838 stepped_after_stopped_by_watchpoint
= 1;
1842 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1844 infwait_state
= infwait_normal_state
;
1846 reinit_frame_cache ();
1848 /* If it's a new process, add it to the thread database */
1850 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1851 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
1852 && !in_thread_list (ecs
->ptid
));
1854 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1855 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1856 add_thread (ecs
->ptid
);
1858 if (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
1860 /* Mark the non-executing threads accordingly. */
1862 || ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
1863 || ecs
->ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
1864 set_executing (pid_to_ptid (-1), 0);
1866 set_executing (ecs
->ptid
, 0);
1869 switch (ecs
->ws
.kind
)
1871 case TARGET_WAITKIND_LOADED
:
1873 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
1874 /* Ignore gracefully during startup of the inferior, as it might
1875 be the shell which has just loaded some objects, otherwise
1876 add the symbols for the newly loaded objects. Also ignore at
1877 the beginning of an attach or remote session; we will query
1878 the full list of libraries once the connection is
1880 if (stop_soon
== NO_STOP_QUIETLY
)
1882 /* Check for any newly added shared libraries if we're
1883 supposed to be adding them automatically. Switch
1884 terminal for any messages produced by
1885 breakpoint_re_set. */
1886 target_terminal_ours_for_output ();
1887 /* NOTE: cagney/2003-11-25: Make certain that the target
1888 stack's section table is kept up-to-date. Architectures,
1889 (e.g., PPC64), use the section table to perform
1890 operations such as address => section name and hence
1891 require the table to contain all sections (including
1892 those found in shared libraries). */
1893 /* NOTE: cagney/2003-11-25: Pass current_target and not
1894 exec_ops to SOLIB_ADD. This is because current GDB is
1895 only tooled to propagate section_table changes out from
1896 the "current_target" (see target_resize_to_sections), and
1897 not up from the exec stratum. This, of course, isn't
1898 right. "infrun.c" should only interact with the
1899 exec/process stratum, instead relying on the target stack
1900 to propagate relevant changes (stop, section table
1901 changed, ...) up to other layers. */
1903 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
1905 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
1907 target_terminal_inferior ();
1909 /* If requested, stop when the dynamic linker notifies
1910 gdb of events. This allows the user to get control
1911 and place breakpoints in initializer routines for
1912 dynamically loaded objects (among other things). */
1913 if (stop_on_solib_events
)
1915 stop_stepping (ecs
);
1919 /* NOTE drow/2007-05-11: This might be a good place to check
1920 for "catch load". */
1923 /* If we are skipping through a shell, or through shared library
1924 loading that we aren't interested in, resume the program. If
1925 we're running the program normally, also resume. But stop if
1926 we're attaching or setting up a remote connection. */
1927 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
1929 /* Loading of shared libraries might have changed breakpoint
1930 addresses. Make sure new breakpoints are inserted. */
1931 if (stop_soon
== NO_STOP_QUIETLY
1932 && !breakpoints_always_inserted_mode ())
1933 insert_breakpoints ();
1934 resume (0, TARGET_SIGNAL_0
);
1935 prepare_to_wait (ecs
);
1941 case TARGET_WAITKIND_SPURIOUS
:
1943 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
1944 resume (0, TARGET_SIGNAL_0
);
1945 prepare_to_wait (ecs
);
1948 case TARGET_WAITKIND_EXITED
:
1950 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
1951 target_terminal_ours (); /* Must do this before mourn anyway */
1952 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1954 /* Record the exit code in the convenience variable $_exitcode, so
1955 that the user can inspect this again later. */
1956 set_internalvar (lookup_internalvar ("_exitcode"),
1957 value_from_longest (builtin_type_int
,
1958 (LONGEST
) ecs
->ws
.value
.integer
));
1959 gdb_flush (gdb_stdout
);
1960 target_mourn_inferior ();
1961 singlestep_breakpoints_inserted_p
= 0;
1962 stop_print_frame
= 0;
1963 stop_stepping (ecs
);
1966 case TARGET_WAITKIND_SIGNALLED
:
1968 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
1969 stop_print_frame
= 0;
1970 stop_signal
= ecs
->ws
.value
.sig
;
1971 target_terminal_ours (); /* Must do this before mourn anyway */
1973 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1974 reach here unless the inferior is dead. However, for years
1975 target_kill() was called here, which hints that fatal signals aren't
1976 really fatal on some systems. If that's true, then some changes
1978 target_mourn_inferior ();
1980 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1981 singlestep_breakpoints_inserted_p
= 0;
1982 stop_stepping (ecs
);
1985 /* The following are the only cases in which we keep going;
1986 the above cases end in a continue or goto. */
1987 case TARGET_WAITKIND_FORKED
:
1988 case TARGET_WAITKIND_VFORKED
:
1990 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
1991 stop_signal
= TARGET_SIGNAL_TRAP
;
1992 pending_follow
.kind
= ecs
->ws
.kind
;
1994 pending_follow
.fork_event
.parent_pid
= ecs
->ptid
;
1995 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1997 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1999 context_switch (ecs
->ptid
);
2000 reinit_frame_cache ();
2003 stop_pc
= read_pc ();
2005 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2007 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2009 /* If no catchpoint triggered for this, then keep going. */
2010 if (ecs
->random_signal
)
2012 stop_signal
= TARGET_SIGNAL_0
;
2016 goto process_event_stop_test
;
2018 case TARGET_WAITKIND_EXECD
:
2020 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
2021 stop_signal
= TARGET_SIGNAL_TRAP
;
2023 pending_follow
.execd_pathname
=
2024 savestring (ecs
->ws
.value
.execd_pathname
,
2025 strlen (ecs
->ws
.value
.execd_pathname
));
2027 /* This causes the eventpoints and symbol table to be reset. Must
2028 do this now, before trying to determine whether to stop. */
2029 follow_exec (inferior_ptid
, pending_follow
.execd_pathname
);
2030 xfree (pending_follow
.execd_pathname
);
2032 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2035 /* The breakpoints module may need to touch the inferior's
2036 memory. Switch to the (stopped) event ptid
2038 ptid_t saved_inferior_ptid
= inferior_ptid
;
2039 inferior_ptid
= ecs
->ptid
;
2041 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2043 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2044 inferior_ptid
= saved_inferior_ptid
;
2047 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2049 context_switch (ecs
->ptid
);
2050 reinit_frame_cache ();
2053 /* If no catchpoint triggered for this, then keep going. */
2054 if (ecs
->random_signal
)
2056 stop_signal
= TARGET_SIGNAL_0
;
2060 goto process_event_stop_test
;
2062 /* Be careful not to try to gather much state about a thread
2063 that's in a syscall. It's frequently a losing proposition. */
2064 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2066 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2067 resume (0, TARGET_SIGNAL_0
);
2068 prepare_to_wait (ecs
);
2071 /* Before examining the threads further, step this thread to
2072 get it entirely out of the syscall. (We get notice of the
2073 event when the thread is just on the verge of exiting a
2074 syscall. Stepping one instruction seems to get it back
2076 case TARGET_WAITKIND_SYSCALL_RETURN
:
2078 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2079 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2080 prepare_to_wait (ecs
);
2083 case TARGET_WAITKIND_STOPPED
:
2085 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
2086 stop_signal
= ecs
->ws
.value
.sig
;
2089 /* We had an event in the inferior, but we are not interested
2090 in handling it at this level. The lower layers have already
2091 done what needs to be done, if anything.
2093 One of the possible circumstances for this is when the
2094 inferior produces output for the console. The inferior has
2095 not stopped, and we are ignoring the event. Another possible
2096 circumstance is any event which the lower level knows will be
2097 reported multiple times without an intervening resume. */
2098 case TARGET_WAITKIND_IGNORE
:
2100 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2101 prepare_to_wait (ecs
);
2105 if (ecs
->new_thread_event
)
2108 /* Non-stop assumes that the target handles adding new threads
2109 to the thread list. */
2110 internal_error (__FILE__
, __LINE__
, "\
2111 targets should add new threads to the thread list themselves in non-stop mode.");
2113 /* We may want to consider not doing a resume here in order to
2114 give the user a chance to play with the new thread. It might
2115 be good to make that a user-settable option. */
2117 /* At this point, all threads are stopped (happens automatically
2118 in either the OS or the native code). Therefore we need to
2119 continue all threads in order to make progress. */
2121 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
2122 prepare_to_wait (ecs
);
2126 /* Do we need to clean up the state of a thread that has completed a
2127 displaced single-step? (Doing so usually affects the PC, so do
2128 it here, before we set stop_pc.) */
2129 displaced_step_fixup (ecs
->ptid
, stop_signal
);
2131 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2135 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n",
2136 paddr_nz (stop_pc
));
2137 if (STOPPED_BY_WATCHPOINT (&ecs
->ws
))
2140 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2142 if (target_stopped_data_address (¤t_target
, &addr
))
2143 fprintf_unfiltered (gdb_stdlog
,
2144 "infrun: stopped data address = 0x%s\n",
2147 fprintf_unfiltered (gdb_stdlog
,
2148 "infrun: (no data address available)\n");
2152 if (stepping_past_singlestep_breakpoint
)
2154 gdb_assert (singlestep_breakpoints_inserted_p
);
2155 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2156 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2158 stepping_past_singlestep_breakpoint
= 0;
2160 /* We've either finished single-stepping past the single-step
2161 breakpoint, or stopped for some other reason. It would be nice if
2162 we could tell, but we can't reliably. */
2163 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2166 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2167 /* Pull the single step breakpoints out of the target. */
2168 remove_single_step_breakpoints ();
2169 singlestep_breakpoints_inserted_p
= 0;
2171 ecs
->random_signal
= 0;
2173 context_switch (saved_singlestep_ptid
);
2174 if (deprecated_context_hook
)
2175 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2177 resume (1, TARGET_SIGNAL_0
);
2178 prepare_to_wait (ecs
);
2183 stepping_past_singlestep_breakpoint
= 0;
2185 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2187 /* In non-stop mode, there's never a deferred_step_ptid set. */
2188 gdb_assert (!non_stop
);
2190 /* If we stopped for some other reason than single-stepping, ignore
2191 the fact that we were supposed to switch back. */
2192 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2195 fprintf_unfiltered (gdb_stdlog
,
2196 "infrun: handling deferred step\n");
2198 /* Pull the single step breakpoints out of the target. */
2199 if (singlestep_breakpoints_inserted_p
)
2201 remove_single_step_breakpoints ();
2202 singlestep_breakpoints_inserted_p
= 0;
2205 /* Note: We do not call context_switch at this point, as the
2206 context is already set up for stepping the original thread. */
2207 switch_to_thread (deferred_step_ptid
);
2208 deferred_step_ptid
= null_ptid
;
2209 /* Suppress spurious "Switching to ..." message. */
2210 previous_inferior_ptid
= inferior_ptid
;
2212 resume (1, TARGET_SIGNAL_0
);
2213 prepare_to_wait (ecs
);
2217 deferred_step_ptid
= null_ptid
;
2220 /* See if a thread hit a thread-specific breakpoint that was meant for
2221 another thread. If so, then step that thread past the breakpoint,
2224 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2226 int thread_hop_needed
= 0;
2228 /* Check if a regular breakpoint has been hit before checking
2229 for a potential single step breakpoint. Otherwise, GDB will
2230 not see this breakpoint hit when stepping onto breakpoints. */
2231 if (regular_breakpoint_inserted_here_p (stop_pc
))
2233 ecs
->random_signal
= 0;
2234 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2235 thread_hop_needed
= 1;
2237 else if (singlestep_breakpoints_inserted_p
)
2239 /* We have not context switched yet, so this should be true
2240 no matter which thread hit the singlestep breakpoint. */
2241 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2243 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2245 target_pid_to_str (ecs
->ptid
));
2247 ecs
->random_signal
= 0;
2248 /* The call to in_thread_list is necessary because PTIDs sometimes
2249 change when we go from single-threaded to multi-threaded. If
2250 the singlestep_ptid is still in the list, assume that it is
2251 really different from ecs->ptid. */
2252 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2253 && in_thread_list (singlestep_ptid
))
2255 /* If the PC of the thread we were trying to single-step
2256 has changed, discard this event (which we were going
2257 to ignore anyway), and pretend we saw that thread
2258 trap. This prevents us continuously moving the
2259 single-step breakpoint forward, one instruction at a
2260 time. If the PC has changed, then the thread we were
2261 trying to single-step has trapped or been signalled,
2262 but the event has not been reported to GDB yet.
2264 There might be some cases where this loses signal
2265 information, if a signal has arrived at exactly the
2266 same time that the PC changed, but this is the best
2267 we can do with the information available. Perhaps we
2268 should arrange to report all events for all threads
2269 when they stop, or to re-poll the remote looking for
2270 this particular thread (i.e. temporarily enable
2273 CORE_ADDR new_singlestep_pc
2274 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
2276 if (new_singlestep_pc
!= singlestep_pc
)
2279 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2280 " but expected thread advanced also\n");
2282 /* The current context still belongs to
2283 singlestep_ptid. Don't swap here, since that's
2284 the context we want to use. Just fudge our
2285 state and continue. */
2286 ecs
->ptid
= singlestep_ptid
;
2287 stop_pc
= new_singlestep_pc
;
2292 fprintf_unfiltered (gdb_stdlog
,
2293 "infrun: unexpected thread\n");
2295 thread_hop_needed
= 1;
2296 stepping_past_singlestep_breakpoint
= 1;
2297 saved_singlestep_ptid
= singlestep_ptid
;
2302 if (thread_hop_needed
)
2304 int remove_status
= 0;
2307 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2309 /* Saw a breakpoint, but it was hit by the wrong thread.
2312 if (singlestep_breakpoints_inserted_p
)
2314 /* Pull the single step breakpoints out of the target. */
2315 remove_single_step_breakpoints ();
2316 singlestep_breakpoints_inserted_p
= 0;
2319 /* If the arch can displace step, don't remove the
2321 if (!use_displaced_stepping (current_gdbarch
))
2322 remove_status
= remove_breakpoints ();
2324 /* Did we fail to remove breakpoints? If so, try
2325 to set the PC past the bp. (There's at least
2326 one situation in which we can fail to remove
2327 the bp's: On HP-UX's that use ttrace, we can't
2328 change the address space of a vforking child
2329 process until the child exits (well, okay, not
2330 then either :-) or execs. */
2331 if (remove_status
!= 0)
2332 error (_("Cannot step over breakpoint hit in wrong thread"));
2335 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2336 context_switch (ecs
->ptid
);
2340 /* Only need to require the next event from this
2341 thread in all-stop mode. */
2342 waiton_ptid
= ecs
->ptid
;
2343 infwait_state
= infwait_thread_hop_state
;
2346 tss
->stepping_over_breakpoint
= 1;
2348 registers_changed ();
2352 else if (singlestep_breakpoints_inserted_p
)
2354 sw_single_step_trap_p
= 1;
2355 ecs
->random_signal
= 0;
2359 ecs
->random_signal
= 1;
2361 /* See if something interesting happened to the non-current thread. If
2362 so, then switch to that thread. */
2363 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2366 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
2368 context_switch (ecs
->ptid
);
2370 if (deprecated_context_hook
)
2371 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2374 if (singlestep_breakpoints_inserted_p
)
2376 /* Pull the single step breakpoints out of the target. */
2377 remove_single_step_breakpoints ();
2378 singlestep_breakpoints_inserted_p
= 0;
2381 if (stepped_after_stopped_by_watchpoint
)
2382 stopped_by_watchpoint
= 0;
2384 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
2386 /* If necessary, step over this watchpoint. We'll be back to display
2388 if (stopped_by_watchpoint
2389 && (HAVE_STEPPABLE_WATCHPOINT
2390 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
2392 /* At this point, we are stopped at an instruction which has
2393 attempted to write to a piece of memory under control of
2394 a watchpoint. The instruction hasn't actually executed
2395 yet. If we were to evaluate the watchpoint expression
2396 now, we would get the old value, and therefore no change
2397 would seem to have occurred.
2399 In order to make watchpoints work `right', we really need
2400 to complete the memory write, and then evaluate the
2401 watchpoint expression. We do this by single-stepping the
2404 It may not be necessary to disable the watchpoint to stop over
2405 it. For example, the PA can (with some kernel cooperation)
2406 single step over a watchpoint without disabling the watchpoint.
2408 It is far more common to need to disable a watchpoint to step
2409 the inferior over it. If we have non-steppable watchpoints,
2410 we must disable the current watchpoint; it's simplest to
2411 disable all watchpoints and breakpoints. */
2413 if (!HAVE_STEPPABLE_WATCHPOINT
)
2414 remove_breakpoints ();
2415 registers_changed ();
2416 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2417 waiton_ptid
= ecs
->ptid
;
2418 if (HAVE_STEPPABLE_WATCHPOINT
)
2419 infwait_state
= infwait_step_watch_state
;
2421 infwait_state
= infwait_nonstep_watch_state
;
2422 prepare_to_wait (ecs
);
2426 ecs
->stop_func_start
= 0;
2427 ecs
->stop_func_end
= 0;
2428 ecs
->stop_func_name
= 0;
2429 /* Don't care about return value; stop_func_start and stop_func_name
2430 will both be 0 if it doesn't work. */
2431 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2432 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2433 ecs
->stop_func_start
2434 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
2435 tss
->stepping_over_breakpoint
= 0;
2436 bpstat_clear (&stop_bpstat
);
2438 stop_print_frame
= 1;
2439 ecs
->random_signal
= 0;
2440 stopped_by_random_signal
= 0;
2442 if (stop_signal
== TARGET_SIGNAL_TRAP
2443 && stepping_over_breakpoint
2444 && gdbarch_single_step_through_delay_p (current_gdbarch
)
2445 && currently_stepping (tss
))
2447 /* We're trying to step off a breakpoint. Turns out that we're
2448 also on an instruction that needs to be stepped multiple
2449 times before it's been fully executing. E.g., architectures
2450 with a delay slot. It needs to be stepped twice, once for
2451 the instruction and once for the delay slot. */
2452 int step_through_delay
2453 = gdbarch_single_step_through_delay (current_gdbarch
,
2454 get_current_frame ());
2455 if (debug_infrun
&& step_through_delay
)
2456 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
2457 if (step_range_end
== 0 && step_through_delay
)
2459 /* The user issued a continue when stopped at a breakpoint.
2460 Set up for another trap and get out of here. */
2461 tss
->stepping_over_breakpoint
= 1;
2465 else if (step_through_delay
)
2467 /* The user issued a step when stopped at a breakpoint.
2468 Maybe we should stop, maybe we should not - the delay
2469 slot *might* correspond to a line of source. In any
2470 case, don't decide that here, just set
2471 ecs->stepping_over_breakpoint, making sure we
2472 single-step again before breakpoints are re-inserted. */
2473 tss
->stepping_over_breakpoint
= 1;
2477 /* Look at the cause of the stop, and decide what to do.
2478 The alternatives are:
2479 1) stop_stepping and return; to really stop and return to the debugger,
2480 2) keep_going and return to start up again
2481 (set tss->stepping_over_breakpoint to 1 to single step once)
2482 3) set ecs->random_signal to 1, and the decision between 1 and 2
2483 will be made according to the signal handling tables. */
2485 /* First, distinguish signals caused by the debugger from signals
2486 that have to do with the program's own actions. Note that
2487 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2488 on the operating system version. Here we detect when a SIGILL or
2489 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2490 something similar for SIGSEGV, since a SIGSEGV will be generated
2491 when we're trying to execute a breakpoint instruction on a
2492 non-executable stack. This happens for call dummy breakpoints
2493 for architectures like SPARC that place call dummies on the
2496 If we're doing a displaced step past a breakpoint, then the
2497 breakpoint is always inserted at the original instruction;
2498 non-standard signals can't be explained by the breakpoint. */
2499 if (stop_signal
== TARGET_SIGNAL_TRAP
2500 || (! stepping_over_breakpoint
2501 && breakpoint_inserted_here_p (stop_pc
)
2502 && (stop_signal
== TARGET_SIGNAL_ILL
2503 || stop_signal
== TARGET_SIGNAL_SEGV
2504 || stop_signal
== TARGET_SIGNAL_EMT
))
2505 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2506 || stop_soon
== STOP_QUIETLY_REMOTE
)
2508 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2511 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
2512 stop_print_frame
= 0;
2513 stop_stepping (ecs
);
2517 /* This is originated from start_remote(), start_inferior() and
2518 shared libraries hook functions. */
2519 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
2522 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
2523 stop_stepping (ecs
);
2527 /* This originates from attach_command(). We need to overwrite
2528 the stop_signal here, because some kernels don't ignore a
2529 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2530 See more comments in inferior.h. On the other hand, if we
2531 get a non-SIGSTOP, report it to the user - assume the backend
2532 will handle the SIGSTOP if it should show up later. */
2533 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2534 && stop_signal
== TARGET_SIGNAL_STOP
)
2536 stop_stepping (ecs
);
2537 stop_signal
= TARGET_SIGNAL_0
;
2541 /* See if there is a breakpoint at the current PC. */
2542 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2544 /* Following in case break condition called a
2546 stop_print_frame
= 1;
2548 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2549 at one stage in the past included checks for an inferior
2550 function call's call dummy's return breakpoint. The original
2551 comment, that went with the test, read:
2553 ``End of a stack dummy. Some systems (e.g. Sony news) give
2554 another signal besides SIGTRAP, so check here as well as
2557 If someone ever tries to get get call dummys on a
2558 non-executable stack to work (where the target would stop
2559 with something like a SIGSEGV), then those tests might need
2560 to be re-instated. Given, however, that the tests were only
2561 enabled when momentary breakpoints were not being used, I
2562 suspect that it won't be the case.
2564 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2565 be necessary for call dummies on a non-executable stack on
2568 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2570 = !(bpstat_explains_signal (stop_bpstat
)
2571 || stepping_over_breakpoint
2572 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2575 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2576 if (!ecs
->random_signal
)
2577 stop_signal
= TARGET_SIGNAL_TRAP
;
2581 /* When we reach this point, we've pretty much decided
2582 that the reason for stopping must've been a random
2583 (unexpected) signal. */
2586 ecs
->random_signal
= 1;
2588 process_event_stop_test
:
2589 /* For the program's own signals, act according to
2590 the signal handling tables. */
2592 if (ecs
->random_signal
)
2594 /* Signal not for debugging purposes. */
2598 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n", stop_signal
);
2600 stopped_by_random_signal
= 1;
2602 if (signal_print
[stop_signal
])
2605 target_terminal_ours_for_output ();
2606 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2608 if (signal_stop_state (stop_signal
))
2610 stop_stepping (ecs
);
2613 /* If not going to stop, give terminal back
2614 if we took it away. */
2616 target_terminal_inferior ();
2618 /* Clear the signal if it should not be passed. */
2619 if (signal_program
[stop_signal
] == 0)
2620 stop_signal
= TARGET_SIGNAL_0
;
2622 if (prev_pc
== read_pc ()
2623 && stepping_over_breakpoint
2624 && step_resume_breakpoint
== NULL
)
2626 /* We were just starting a new sequence, attempting to
2627 single-step off of a breakpoint and expecting a SIGTRAP.
2628 Instead this signal arrives. This signal will take us out
2629 of the stepping range so GDB needs to remember to, when
2630 the signal handler returns, resume stepping off that
2632 /* To simplify things, "continue" is forced to use the same
2633 code paths as single-step - set a breakpoint at the
2634 signal return address and then, once hit, step off that
2637 fprintf_unfiltered (gdb_stdlog
,
2638 "infrun: signal arrived while stepping over "
2641 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2642 tss
->step_after_step_resume_breakpoint
= 1;
2647 if (step_range_end
!= 0
2648 && stop_signal
!= TARGET_SIGNAL_0
2649 && stop_pc
>= step_range_start
&& stop_pc
< step_range_end
2650 && frame_id_eq (get_frame_id (get_current_frame ()),
2652 && step_resume_breakpoint
== NULL
)
2654 /* The inferior is about to take a signal that will take it
2655 out of the single step range. Set a breakpoint at the
2656 current PC (which is presumably where the signal handler
2657 will eventually return) and then allow the inferior to
2660 Note that this is only needed for a signal delivered
2661 while in the single-step range. Nested signals aren't a
2662 problem as they eventually all return. */
2664 fprintf_unfiltered (gdb_stdlog
,
2665 "infrun: signal may take us out of "
2666 "single-step range\n");
2668 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2673 /* Note: step_resume_breakpoint may be non-NULL. This occures
2674 when either there's a nested signal, or when there's a
2675 pending signal enabled just as the signal handler returns
2676 (leaving the inferior at the step-resume-breakpoint without
2677 actually executing it). Either way continue until the
2678 breakpoint is really hit. */
2683 /* Handle cases caused by hitting a breakpoint. */
2685 CORE_ADDR jmp_buf_pc
;
2686 struct bpstat_what what
;
2688 what
= bpstat_what (stop_bpstat
);
2690 if (what
.call_dummy
)
2692 stop_stack_dummy
= 1;
2695 switch (what
.main_action
)
2697 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2698 /* If we hit the breakpoint at longjmp while stepping, we
2699 install a momentary breakpoint at the target of the
2703 fprintf_unfiltered (gdb_stdlog
,
2704 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2706 tss
->stepping_over_breakpoint
= 1;
2708 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
2709 || !gdbarch_get_longjmp_target (current_gdbarch
,
2710 get_current_frame (), &jmp_buf_pc
))
2713 fprintf_unfiltered (gdb_stdlog
, "\
2714 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
2719 /* We're going to replace the current step-resume breakpoint
2720 with a longjmp-resume breakpoint. */
2721 if (step_resume_breakpoint
!= NULL
)
2722 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2724 /* Insert a breakpoint at resume address. */
2725 insert_longjmp_resume_breakpoint (jmp_buf_pc
);
2730 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2732 fprintf_unfiltered (gdb_stdlog
,
2733 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2735 gdb_assert (step_resume_breakpoint
!= NULL
);
2736 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2739 print_stop_reason (END_STEPPING_RANGE
, 0);
2740 stop_stepping (ecs
);
2743 case BPSTAT_WHAT_SINGLE
:
2745 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
2746 tss
->stepping_over_breakpoint
= 1;
2747 /* Still need to check other stuff, at least the case
2748 where we are stepping and step out of the right range. */
2751 case BPSTAT_WHAT_STOP_NOISY
:
2753 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2754 stop_print_frame
= 1;
2756 /* We are about to nuke the step_resume_breakpointt via the
2757 cleanup chain, so no need to worry about it here. */
2759 stop_stepping (ecs
);
2762 case BPSTAT_WHAT_STOP_SILENT
:
2764 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2765 stop_print_frame
= 0;
2767 /* We are about to nuke the step_resume_breakpoin via the
2768 cleanup chain, so no need to worry about it here. */
2770 stop_stepping (ecs
);
2773 case BPSTAT_WHAT_STEP_RESUME
:
2774 /* This proably demands a more elegant solution, but, yeah
2777 This function's use of the simple variable
2778 step_resume_breakpoint doesn't seem to accomodate
2779 simultaneously active step-resume bp's, although the
2780 breakpoint list certainly can.
2782 If we reach here and step_resume_breakpoint is already
2783 NULL, then apparently we have multiple active
2784 step-resume bp's. We'll just delete the breakpoint we
2785 stopped at, and carry on.
2787 Correction: what the code currently does is delete a
2788 step-resume bp, but it makes no effort to ensure that
2789 the one deleted is the one currently stopped at. MVS */
2792 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2794 if (step_resume_breakpoint
== NULL
)
2796 step_resume_breakpoint
=
2797 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2799 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2800 if (tss
->step_after_step_resume_breakpoint
)
2802 /* Back when the step-resume breakpoint was inserted, we
2803 were trying to single-step off a breakpoint. Go back
2805 tss
->step_after_step_resume_breakpoint
= 0;
2806 tss
->stepping_over_breakpoint
= 1;
2812 case BPSTAT_WHAT_CHECK_SHLIBS
:
2813 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2816 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2818 /* Check for any newly added shared libraries if we're
2819 supposed to be adding them automatically. Switch
2820 terminal for any messages produced by
2821 breakpoint_re_set. */
2822 target_terminal_ours_for_output ();
2823 /* NOTE: cagney/2003-11-25: Make certain that the target
2824 stack's section table is kept up-to-date. Architectures,
2825 (e.g., PPC64), use the section table to perform
2826 operations such as address => section name and hence
2827 require the table to contain all sections (including
2828 those found in shared libraries). */
2829 /* NOTE: cagney/2003-11-25: Pass current_target and not
2830 exec_ops to SOLIB_ADD. This is because current GDB is
2831 only tooled to propagate section_table changes out from
2832 the "current_target" (see target_resize_to_sections), and
2833 not up from the exec stratum. This, of course, isn't
2834 right. "infrun.c" should only interact with the
2835 exec/process stratum, instead relying on the target stack
2836 to propagate relevant changes (stop, section table
2837 changed, ...) up to other layers. */
2839 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2841 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2843 target_terminal_inferior ();
2845 /* If requested, stop when the dynamic linker notifies
2846 gdb of events. This allows the user to get control
2847 and place breakpoints in initializer routines for
2848 dynamically loaded objects (among other things). */
2849 if (stop_on_solib_events
|| stop_stack_dummy
)
2851 stop_stepping (ecs
);
2855 /* If we stopped due to an explicit catchpoint, then the
2856 (see above) call to SOLIB_ADD pulled in any symbols
2857 from a newly-loaded library, if appropriate.
2859 We do want the inferior to stop, but not where it is
2860 now, which is in the dynamic linker callback. Rather,
2861 we would like it stop in the user's program, just after
2862 the call that caused this catchpoint to trigger. That
2863 gives the user a more useful vantage from which to
2864 examine their program's state. */
2865 else if (what
.main_action
2866 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2868 /* ??rehrauer: If I could figure out how to get the
2869 right return PC from here, we could just set a temp
2870 breakpoint and resume. I'm not sure we can without
2871 cracking open the dld's shared libraries and sniffing
2872 their unwind tables and text/data ranges, and that's
2873 not a terribly portable notion.
2875 Until that time, we must step the inferior out of the
2876 dld callback, and also out of the dld itself (and any
2877 code or stubs in libdld.sl, such as "shl_load" and
2878 friends) until we reach non-dld code. At that point,
2879 we can stop stepping. */
2880 bpstat_get_triggered_catchpoints (stop_bpstat
,
2882 stepping_through_solib_catchpoints
);
2883 tss
->stepping_through_solib_after_catch
= 1;
2885 /* Be sure to lift all breakpoints, so the inferior does
2886 actually step past this point... */
2887 tss
->stepping_over_breakpoint
= 1;
2892 /* We want to step over this breakpoint, then keep going. */
2893 tss
->stepping_over_breakpoint
= 1;
2899 case BPSTAT_WHAT_LAST
:
2900 /* Not a real code, but listed here to shut up gcc -Wall. */
2902 case BPSTAT_WHAT_KEEP_CHECKING
:
2907 /* We come here if we hit a breakpoint but should not
2908 stop for it. Possibly we also were stepping
2909 and should stop for that. So fall through and
2910 test for stepping. But, if not stepping,
2913 /* Are we stepping to get the inferior out of the dynamic linker's
2914 hook (and possibly the dld itself) after catching a shlib
2916 if (tss
->stepping_through_solib_after_catch
)
2918 #if defined(SOLIB_ADD)
2919 /* Have we reached our destination? If not, keep going. */
2920 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2923 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
2924 tss
->stepping_over_breakpoint
= 1;
2930 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
2931 /* Else, stop and report the catchpoint(s) whose triggering
2932 caused us to begin stepping. */
2933 tss
->stepping_through_solib_after_catch
= 0;
2934 bpstat_clear (&stop_bpstat
);
2935 stop_bpstat
= bpstat_copy (tss
->stepping_through_solib_catchpoints
);
2936 bpstat_clear (&tss
->stepping_through_solib_catchpoints
);
2937 stop_print_frame
= 1;
2938 stop_stepping (ecs
);
2942 if (step_resume_breakpoint
)
2945 fprintf_unfiltered (gdb_stdlog
,
2946 "infrun: step-resume breakpoint is inserted\n");
2948 /* Having a step-resume breakpoint overrides anything
2949 else having to do with stepping commands until
2950 that breakpoint is reached. */
2955 if (step_range_end
== 0)
2958 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
2959 /* Likewise if we aren't even stepping. */
2964 /* If stepping through a line, keep going if still within it.
2966 Note that step_range_end is the address of the first instruction
2967 beyond the step range, and NOT the address of the last instruction
2969 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2972 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
2973 paddr_nz (step_range_start
),
2974 paddr_nz (step_range_end
));
2979 /* We stepped out of the stepping range. */
2981 /* If we are stepping at the source level and entered the runtime
2982 loader dynamic symbol resolution code, we keep on single stepping
2983 until we exit the run time loader code and reach the callee's
2985 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2986 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2987 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
)
2989 && in_solib_dynsym_resolve_code (stop_pc
)
2993 CORE_ADDR pc_after_resolver
=
2994 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
2997 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
2999 if (pc_after_resolver
)
3001 /* Set up a step-resume breakpoint at the address
3002 indicated by SKIP_SOLIB_RESOLVER. */
3003 struct symtab_and_line sr_sal
;
3005 sr_sal
.pc
= pc_after_resolver
;
3007 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3014 if (step_range_end
!= 1
3015 && (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3016 || step_over_calls
== STEP_OVER_ALL
)
3017 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
3020 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
3021 /* The inferior, while doing a "step" or "next", has ended up in
3022 a signal trampoline (either by a signal being delivered or by
3023 the signal handler returning). Just single-step until the
3024 inferior leaves the trampoline (either by calling the handler
3030 /* Check for subroutine calls. The check for the current frame
3031 equalling the step ID is not necessary - the check of the
3032 previous frame's ID is sufficient - but it is a common case and
3033 cheaper than checking the previous frame's ID.
3035 NOTE: frame_id_eq will never report two invalid frame IDs as
3036 being equal, so to get into this block, both the current and
3037 previous frame must have valid frame IDs. */
3038 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id
)
3039 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id
))
3041 CORE_ADDR real_stop_pc
;
3044 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
3046 if ((step_over_calls
== STEP_OVER_NONE
)
3047 || ((step_range_end
== 1)
3048 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
3050 /* I presume that step_over_calls is only 0 when we're
3051 supposed to be stepping at the assembly language level
3052 ("stepi"). Just stop. */
3053 /* Also, maybe we just did a "nexti" inside a prolog, so we
3054 thought it was a subroutine call but it was not. Stop as
3057 print_stop_reason (END_STEPPING_RANGE
, 0);
3058 stop_stepping (ecs
);
3062 if (step_over_calls
== STEP_OVER_ALL
)
3064 /* We're doing a "next", set a breakpoint at callee's return
3065 address (the address at which the caller will
3067 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3072 /* If we are in a function call trampoline (a stub between the
3073 calling routine and the real function), locate the real
3074 function. That's what tells us (a) whether we want to step
3075 into it at all, and (b) what prologue we want to run to the
3076 end of, if we do step into it. */
3077 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
3078 if (real_stop_pc
== 0)
3079 real_stop_pc
= gdbarch_skip_trampoline_code
3080 (current_gdbarch
, get_current_frame (), stop_pc
);
3081 if (real_stop_pc
!= 0)
3082 ecs
->stop_func_start
= real_stop_pc
;
3085 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
3086 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs
->stop_func_start
)
3088 in_solib_dynsym_resolve_code (ecs
->stop_func_start
)
3092 struct symtab_and_line sr_sal
;
3094 sr_sal
.pc
= ecs
->stop_func_start
;
3096 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3101 /* If we have line number information for the function we are
3102 thinking of stepping into, step into it.
3104 If there are several symtabs at that PC (e.g. with include
3105 files), just want to know whether *any* of them have line
3106 numbers. find_pc_line handles this. */
3108 struct symtab_and_line tmp_sal
;
3110 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3111 if (tmp_sal
.line
!= 0)
3113 step_into_function (ecs
);
3118 /* If we have no line number and the step-stop-if-no-debug is
3119 set, we stop the step so that the user has a chance to switch
3120 in assembly mode. */
3121 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
3124 print_stop_reason (END_STEPPING_RANGE
, 0);
3125 stop_stepping (ecs
);
3129 /* Set a breakpoint at callee's return address (the address at
3130 which the caller will resume). */
3131 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3136 /* If we're in the return path from a shared library trampoline,
3137 we want to proceed through the trampoline when stepping. */
3138 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
3139 stop_pc
, ecs
->stop_func_name
))
3141 /* Determine where this trampoline returns. */
3142 CORE_ADDR real_stop_pc
;
3143 real_stop_pc
= gdbarch_skip_trampoline_code
3144 (current_gdbarch
, get_current_frame (), stop_pc
);
3147 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3149 /* Only proceed through if we know where it's going. */
3152 /* And put the step-breakpoint there and go until there. */
3153 struct symtab_and_line sr_sal
;
3155 init_sal (&sr_sal
); /* initialize to zeroes */
3156 sr_sal
.pc
= real_stop_pc
;
3157 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3159 /* Do not specify what the fp should be when we stop since
3160 on some machines the prologue is where the new fp value
3162 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3164 /* Restart without fiddling with the step ranges or
3171 tss
->sal
= find_pc_line (stop_pc
, 0);
3173 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3174 the trampoline processing logic, however, there are some trampolines
3175 that have no names, so we should do trampoline handling first. */
3176 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3177 && ecs
->stop_func_name
== NULL
3178 && tss
->sal
.line
== 0)
3181 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3183 /* The inferior just stepped into, or returned to, an
3184 undebuggable function (where there is no debugging information
3185 and no line number corresponding to the address where the
3186 inferior stopped). Since we want to skip this kind of code,
3187 we keep going until the inferior returns from this
3188 function - unless the user has asked us not to (via
3189 set step-mode) or we no longer know how to get back
3190 to the call site. */
3191 if (step_stop_if_no_debug
3192 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3194 /* If we have no line number and the step-stop-if-no-debug
3195 is set, we stop the step so that the user has a chance to
3196 switch in assembly mode. */
3198 print_stop_reason (END_STEPPING_RANGE
, 0);
3199 stop_stepping (ecs
);
3204 /* Set a breakpoint at callee's return address (the address
3205 at which the caller will resume). */
3206 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3212 if (step_range_end
== 1)
3214 /* It is stepi or nexti. We always want to stop stepping after
3217 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
3219 print_stop_reason (END_STEPPING_RANGE
, 0);
3220 stop_stepping (ecs
);
3224 if (tss
->sal
.line
== 0)
3226 /* We have no line number information. That means to stop
3227 stepping (does this always happen right after one instruction,
3228 when we do "s" in a function with no line numbers,
3229 or can this happen as a result of a return or longjmp?). */
3231 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
3233 print_stop_reason (END_STEPPING_RANGE
, 0);
3234 stop_stepping (ecs
);
3238 if ((stop_pc
== tss
->sal
.pc
)
3239 && (tss
->current_line
!= tss
->sal
.line
3240 || tss
->current_symtab
!= tss
->sal
.symtab
))
3242 /* We are at the start of a different line. So stop. Note that
3243 we don't stop if we step into the middle of a different line.
3244 That is said to make things like for (;;) statements work
3247 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
3249 print_stop_reason (END_STEPPING_RANGE
, 0);
3250 stop_stepping (ecs
);
3254 /* We aren't done stepping.
3256 Optimize by setting the stepping range to the line.
3257 (We might not be in the original line, but if we entered a
3258 new line in mid-statement, we continue stepping. This makes
3259 things like for(;;) statements work better.) */
3261 step_range_start
= tss
->sal
.pc
;
3262 step_range_end
= tss
->sal
.end
;
3263 step_frame_id
= get_frame_id (get_current_frame ());
3264 tss
->current_line
= tss
->sal
.line
;
3265 tss
->current_symtab
= tss
->sal
.symtab
;
3267 /* In the case where we just stepped out of a function into the
3268 middle of a line of the caller, continue stepping, but
3269 step_frame_id must be modified to current frame */
3271 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
3272 generous. It will trigger on things like a step into a frameless
3273 stackless leaf function. I think the logic should instead look
3274 at the unwound frame ID has that should give a more robust
3275 indication of what happened. */
3276 if (step
- ID
== current
- ID
)
3277 still stepping in same function
;
3278 else if (step
- ID
== unwind (current
- ID
))
3279 stepped into a function
;
3281 stepped out of a function
;
3282 /* Of course this assumes that the frame ID unwind code is robust
3283 and we're willing to introduce frame unwind logic into this
3284 function. Fortunately, those days are nearly upon us. */
3287 struct frame_info
*frame
= get_current_frame ();
3288 struct frame_id current_frame
= get_frame_id (frame
);
3289 if (!(frame_id_inner (get_frame_arch (frame
), current_frame
,
3291 step_frame_id
= current_frame
;
3295 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
3299 /* Are we in the middle of stepping? */
3302 currently_stepping (struct thread_stepping_state
*tss
)
3304 return (((step_range_end
&& step_resume_breakpoint
== NULL
)
3305 || stepping_over_breakpoint
)
3306 || tss
->stepping_through_solib_after_catch
3307 || bpstat_should_step ());
3310 /* Subroutine call with source code we should not step over. Do step
3311 to the first line of code in it. */
3314 step_into_function (struct execution_control_state
*ecs
)
3317 struct symtab_and_line sr_sal
;
3319 s
= find_pc_symtab (stop_pc
);
3320 if (s
&& s
->language
!= language_asm
)
3321 ecs
->stop_func_start
= gdbarch_skip_prologue
3322 (current_gdbarch
, ecs
->stop_func_start
);
3324 tss
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3325 /* Use the step_resume_break to step until the end of the prologue,
3326 even if that involves jumps (as it seems to on the vax under
3328 /* If the prologue ends in the middle of a source line, continue to
3329 the end of that source line (if it is still within the function).
3330 Otherwise, just go to end of prologue. */
3332 && tss
->sal
.pc
!= ecs
->stop_func_start
3333 && tss
->sal
.end
< ecs
->stop_func_end
)
3334 ecs
->stop_func_start
= tss
->sal
.end
;
3336 /* Architectures which require breakpoint adjustment might not be able
3337 to place a breakpoint at the computed address. If so, the test
3338 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3339 ecs->stop_func_start to an address at which a breakpoint may be
3340 legitimately placed.
3342 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3343 made, GDB will enter an infinite loop when stepping through
3344 optimized code consisting of VLIW instructions which contain
3345 subinstructions corresponding to different source lines. On
3346 FR-V, it's not permitted to place a breakpoint on any but the
3347 first subinstruction of a VLIW instruction. When a breakpoint is
3348 set, GDB will adjust the breakpoint address to the beginning of
3349 the VLIW instruction. Thus, we need to make the corresponding
3350 adjustment here when computing the stop address. */
3352 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3354 ecs
->stop_func_start
3355 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
3356 ecs
->stop_func_start
);
3359 if (ecs
->stop_func_start
== stop_pc
)
3361 /* We are already there: stop now. */
3363 print_stop_reason (END_STEPPING_RANGE
, 0);
3364 stop_stepping (ecs
);
3369 /* Put the step-breakpoint there and go until there. */
3370 init_sal (&sr_sal
); /* initialize to zeroes */
3371 sr_sal
.pc
= ecs
->stop_func_start
;
3372 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3374 /* Do not specify what the fp should be when we stop since on
3375 some machines the prologue is where the new fp value is
3377 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3379 /* And make sure stepping stops right away then. */
3380 step_range_end
= step_range_start
;
3385 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3386 This is used to both functions and to skip over code. */
3389 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
3390 struct frame_id sr_id
)
3392 /* There should never be more than one step-resume or longjmp-resume
3393 breakpoint per thread, so we should never be setting a new
3394 step_resume_breakpoint when one is already active. */
3395 gdb_assert (step_resume_breakpoint
== NULL
);
3398 fprintf_unfiltered (gdb_stdlog
,
3399 "infrun: inserting step-resume breakpoint at 0x%s\n",
3400 paddr_nz (sr_sal
.pc
));
3402 step_resume_breakpoint
= set_momentary_breakpoint (sr_sal
, sr_id
,
3406 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3407 to skip a potential signal handler.
3409 This is called with the interrupted function's frame. The signal
3410 handler, when it returns, will resume the interrupted function at
3414 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
3416 struct symtab_and_line sr_sal
;
3418 gdb_assert (return_frame
!= NULL
);
3419 init_sal (&sr_sal
); /* initialize to zeros */
3421 sr_sal
.pc
= gdbarch_addr_bits_remove
3422 (current_gdbarch
, get_frame_pc (return_frame
));
3423 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3425 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
3428 /* Similar to insert_step_resume_breakpoint_at_frame, except
3429 but a breakpoint at the previous frame's PC. This is used to
3430 skip a function after stepping into it (for "next" or if the called
3431 function has no debugging information).
3433 The current function has almost always been reached by single
3434 stepping a call or return instruction. NEXT_FRAME belongs to the
3435 current function, and the breakpoint will be set at the caller's
3438 This is a separate function rather than reusing
3439 insert_step_resume_breakpoint_at_frame in order to avoid
3440 get_prev_frame, which may stop prematurely (see the implementation
3441 of frame_unwind_id for an example). */
3444 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
3446 struct symtab_and_line sr_sal
;
3448 /* We shouldn't have gotten here if we don't know where the call site
3450 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
3452 init_sal (&sr_sal
); /* initialize to zeros */
3454 sr_sal
.pc
= gdbarch_addr_bits_remove
3455 (current_gdbarch
, frame_pc_unwind (next_frame
));
3456 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3458 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
3461 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
3462 new breakpoint at the target of a jmp_buf. The handling of
3463 longjmp-resume uses the same mechanisms used for handling
3464 "step-resume" breakpoints. */
3467 insert_longjmp_resume_breakpoint (CORE_ADDR pc
)
3469 /* There should never be more than one step-resume or longjmp-resume
3470 breakpoint per thread, so we should never be setting a new
3471 longjmp_resume_breakpoint when one is already active. */
3472 gdb_assert (step_resume_breakpoint
== NULL
);
3475 fprintf_unfiltered (gdb_stdlog
,
3476 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
3479 step_resume_breakpoint
=
3480 set_momentary_breakpoint_at_pc (pc
, bp_longjmp_resume
);
3484 stop_stepping (struct execution_control_state
*ecs
)
3487 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
3489 /* Let callers know we don't want to wait for the inferior anymore. */
3490 ecs
->wait_some_more
= 0;
3493 /* This function handles various cases where we need to continue
3494 waiting for the inferior. */
3495 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3498 keep_going (struct execution_control_state
*ecs
)
3500 /* Save the pc before execution, to compare with pc after stop. */
3501 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3503 /* If we did not do break;, it means we should keep running the
3504 inferior and not return to debugger. */
3506 if (stepping_over_breakpoint
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3508 /* We took a signal (which we are supposed to pass through to
3509 the inferior, else we'd have done a break above) and we
3510 haven't yet gotten our trap. Simply continue. */
3511 resume (currently_stepping (tss
), stop_signal
);
3515 /* Either the trap was not expected, but we are continuing
3516 anyway (the user asked that this signal be passed to the
3519 The signal was SIGTRAP, e.g. it was our signal, but we
3520 decided we should resume from it.
3522 We're going to run this baby now!
3524 Note that insert_breakpoints won't try to re-insert
3525 already inserted breakpoints. Therefore, we don't
3526 care if breakpoints were already inserted, or not. */
3528 if (tss
->stepping_over_breakpoint
)
3530 if (! use_displaced_stepping (current_gdbarch
))
3531 /* Since we can't do a displaced step, we have to remove
3532 the breakpoint while we step it. To keep things
3533 simple, we remove them all. */
3534 remove_breakpoints ();
3538 struct gdb_exception e
;
3539 /* Stop stepping when inserting breakpoints
3541 TRY_CATCH (e
, RETURN_MASK_ERROR
)
3543 insert_breakpoints ();
3547 stop_stepping (ecs
);
3552 stepping_over_breakpoint
= tss
->stepping_over_breakpoint
;
3554 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3555 specifies that such a signal should be delivered to the
3558 Typically, this would occure when a user is debugging a
3559 target monitor on a simulator: the target monitor sets a
3560 breakpoint; the simulator encounters this break-point and
3561 halts the simulation handing control to GDB; GDB, noteing
3562 that the break-point isn't valid, returns control back to the
3563 simulator; the simulator then delivers the hardware
3564 equivalent of a SIGNAL_TRAP to the program being debugged. */
3566 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3567 stop_signal
= TARGET_SIGNAL_0
;
3570 resume (currently_stepping (tss
), stop_signal
);
3573 prepare_to_wait (ecs
);
3576 /* This function normally comes after a resume, before
3577 handle_inferior_event exits. It takes care of any last bits of
3578 housekeeping, and sets the all-important wait_some_more flag. */
3581 prepare_to_wait (struct execution_control_state
*ecs
)
3584 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
3585 if (infwait_state
== infwait_normal_state
)
3587 overlay_cache_invalid
= 1;
3589 /* We have to invalidate the registers BEFORE calling
3590 target_wait because they can be loaded from the target while
3591 in target_wait. This makes remote debugging a bit more
3592 efficient for those targets that provide critical registers
3593 as part of their normal status mechanism. */
3595 registers_changed ();
3596 waiton_ptid
= pid_to_ptid (-1);
3598 /* This is the old end of the while loop. Let everybody know we
3599 want to wait for the inferior some more and get called again
3601 ecs
->wait_some_more
= 1;
3604 /* Print why the inferior has stopped. We always print something when
3605 the inferior exits, or receives a signal. The rest of the cases are
3606 dealt with later on in normal_stop() and print_it_typical(). Ideally
3607 there should be a call to this function from handle_inferior_event()
3608 each time stop_stepping() is called.*/
3610 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3612 switch (stop_reason
)
3614 case END_STEPPING_RANGE
:
3615 /* We are done with a step/next/si/ni command. */
3616 /* For now print nothing. */
3617 /* Print a message only if not in the middle of doing a "step n"
3618 operation for n > 1 */
3619 if (!step_multi
|| !stop_step
)
3620 if (ui_out_is_mi_like_p (uiout
))
3623 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
3626 /* The inferior was terminated by a signal. */
3627 annotate_signalled ();
3628 if (ui_out_is_mi_like_p (uiout
))
3631 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
3632 ui_out_text (uiout
, "\nProgram terminated with signal ");
3633 annotate_signal_name ();
3634 ui_out_field_string (uiout
, "signal-name",
3635 target_signal_to_name (stop_info
));
3636 annotate_signal_name_end ();
3637 ui_out_text (uiout
, ", ");
3638 annotate_signal_string ();
3639 ui_out_field_string (uiout
, "signal-meaning",
3640 target_signal_to_string (stop_info
));
3641 annotate_signal_string_end ();
3642 ui_out_text (uiout
, ".\n");
3643 ui_out_text (uiout
, "The program no longer exists.\n");
3646 /* The inferior program is finished. */
3647 annotate_exited (stop_info
);
3650 if (ui_out_is_mi_like_p (uiout
))
3651 ui_out_field_string (uiout
, "reason",
3652 async_reason_lookup (EXEC_ASYNC_EXITED
));
3653 ui_out_text (uiout
, "\nProgram exited with code ");
3654 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3655 (unsigned int) stop_info
);
3656 ui_out_text (uiout
, ".\n");
3660 if (ui_out_is_mi_like_p (uiout
))
3663 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
3664 ui_out_text (uiout
, "\nProgram exited normally.\n");
3666 /* Support the --return-child-result option. */
3667 return_child_result_value
= stop_info
;
3669 case SIGNAL_RECEIVED
:
3670 /* Signal received. The signal table tells us to print about
3673 ui_out_text (uiout
, "\nProgram received signal ");
3674 annotate_signal_name ();
3675 if (ui_out_is_mi_like_p (uiout
))
3677 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
3678 ui_out_field_string (uiout
, "signal-name",
3679 target_signal_to_name (stop_info
));
3680 annotate_signal_name_end ();
3681 ui_out_text (uiout
, ", ");
3682 annotate_signal_string ();
3683 ui_out_field_string (uiout
, "signal-meaning",
3684 target_signal_to_string (stop_info
));
3685 annotate_signal_string_end ();
3686 ui_out_text (uiout
, ".\n");
3689 internal_error (__FILE__
, __LINE__
,
3690 _("print_stop_reason: unrecognized enum value"));
3696 /* Here to return control to GDB when the inferior stops for real.
3697 Print appropriate messages, remove breakpoints, give terminal our modes.
3699 STOP_PRINT_FRAME nonzero means print the executing frame
3700 (pc, function, args, file, line number and line text).
3701 BREAKPOINTS_FAILED nonzero means stop was due to error
3702 attempting to insert breakpoints. */
3707 struct target_waitstatus last
;
3710 get_last_target_status (&last_ptid
, &last
);
3712 /* As with the notification of thread events, we want to delay
3713 notifying the user that we've switched thread context until
3714 the inferior actually stops.
3716 There's no point in saying anything if the inferior has exited.
3717 Note that SIGNALLED here means "exited with a signal", not
3718 "received a signal". */
3719 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3720 && target_has_execution
3721 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3722 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3724 target_terminal_ours_for_output ();
3725 printf_filtered (_("[Switching to %s]\n"),
3726 target_pid_to_str (inferior_ptid
));
3727 annotate_thread_changed ();
3728 previous_inferior_ptid
= inferior_ptid
;
3731 /* NOTE drow/2004-01-17: Is this still necessary? */
3732 /* Make sure that the current_frame's pc is correct. This
3733 is a correction for setting up the frame info before doing
3734 gdbarch_decr_pc_after_break */
3735 if (target_has_execution
)
3736 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3737 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3738 frame code to check for this and sort out any resultant mess.
3739 gdbarch_decr_pc_after_break needs to just go away. */
3740 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3742 if (!breakpoints_always_inserted_mode () && target_has_execution
)
3744 if (remove_breakpoints ())
3746 target_terminal_ours_for_output ();
3747 printf_filtered (_("\
3748 Cannot remove breakpoints because program is no longer writable.\n\
3749 It might be running in another process.\n\
3750 Further execution is probably impossible.\n"));
3754 /* If an auto-display called a function and that got a signal,
3755 delete that auto-display to avoid an infinite recursion. */
3757 if (stopped_by_random_signal
)
3758 disable_current_display ();
3760 /* Don't print a message if in the middle of doing a "step n"
3761 operation for n > 1 */
3762 if (step_multi
&& stop_step
)
3765 target_terminal_ours ();
3767 /* Set the current source location. This will also happen if we
3768 display the frame below, but the current SAL will be incorrect
3769 during a user hook-stop function. */
3770 if (target_has_stack
&& !stop_stack_dummy
)
3771 set_current_sal_from_frame (get_current_frame (), 1);
3773 /* Look up the hook_stop and run it (CLI internally handles problem
3774 of stop_command's pre-hook not existing). */
3776 catch_errors (hook_stop_stub
, stop_command
,
3777 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3779 if (!target_has_stack
)
3785 /* Select innermost stack frame - i.e., current frame is frame 0,
3786 and current location is based on that.
3787 Don't do this on return from a stack dummy routine,
3788 or if the program has exited. */
3790 if (!stop_stack_dummy
)
3792 select_frame (get_current_frame ());
3794 /* Print current location without a level number, if
3795 we have changed functions or hit a breakpoint.
3796 Print source line if we have one.
3797 bpstat_print() contains the logic deciding in detail
3798 what to print, based on the event(s) that just occurred. */
3800 /* If --batch-silent is enabled then there's no need to print the current
3801 source location, and to try risks causing an error message about
3802 missing source files. */
3803 if (stop_print_frame
&& !batch_silent
)
3807 int do_frame_printing
= 1;
3809 bpstat_ret
= bpstat_print (stop_bpstat
);
3813 /* If we had hit a shared library event breakpoint,
3814 bpstat_print would print out this message. If we hit
3815 an OS-level shared library event, do the same
3817 if (last
.kind
== TARGET_WAITKIND_LOADED
)
3819 printf_filtered (_("Stopped due to shared library event\n"));
3820 source_flag
= SRC_LINE
; /* something bogus */
3821 do_frame_printing
= 0;
3825 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3826 (or should) carry around the function and does (or
3827 should) use that when doing a frame comparison. */
3829 && frame_id_eq (step_frame_id
,
3830 get_frame_id (get_current_frame ()))
3831 && step_start_function
== find_pc_function (stop_pc
))
3832 source_flag
= SRC_LINE
; /* finished step, just print source line */
3834 source_flag
= SRC_AND_LOC
; /* print location and source line */
3836 case PRINT_SRC_AND_LOC
:
3837 source_flag
= SRC_AND_LOC
; /* print location and source line */
3839 case PRINT_SRC_ONLY
:
3840 source_flag
= SRC_LINE
;
3843 source_flag
= SRC_LINE
; /* something bogus */
3844 do_frame_printing
= 0;
3847 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
3850 if (ui_out_is_mi_like_p (uiout
))
3851 ui_out_field_int (uiout
, "thread-id",
3852 pid_to_thread_id (inferior_ptid
));
3853 /* The behavior of this routine with respect to the source
3855 SRC_LINE: Print only source line
3856 LOCATION: Print only location
3857 SRC_AND_LOC: Print location and source line */
3858 if (do_frame_printing
)
3859 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
3861 /* Display the auto-display expressions. */
3866 /* Save the function value return registers, if we care.
3867 We might be about to restore their previous contents. */
3868 if (proceed_to_finish
)
3870 /* This should not be necessary. */
3872 regcache_xfree (stop_registers
);
3874 /* NB: The copy goes through to the target picking up the value of
3875 all the registers. */
3876 stop_registers
= regcache_dup (get_current_regcache ());
3879 if (stop_stack_dummy
)
3881 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3882 ends with a setting of the current frame, so we can use that
3884 frame_pop (get_current_frame ());
3885 /* Set stop_pc to what it was before we called the function.
3886 Can't rely on restore_inferior_status because that only gets
3887 called if we don't stop in the called function. */
3888 stop_pc
= read_pc ();
3889 select_frame (get_current_frame ());
3893 annotate_stopped ();
3894 if (!suppress_stop_observer
&& !step_multi
)
3895 observer_notify_normal_stop (stop_bpstat
);
3896 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3897 Delete any breakpoint that is to be deleted at the next stop. */
3898 breakpoint_auto_delete (stop_bpstat
);
3900 if (target_has_execution
3901 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3902 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3905 set_running (pid_to_ptid (-1), 0);
3907 set_running (inferior_ptid
, 0);
3912 hook_stop_stub (void *cmd
)
3914 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3919 signal_stop_state (int signo
)
3921 /* Always stop on signals if we're just gaining control of the
3923 return signal_stop
[signo
] || stop_soon
!= NO_STOP_QUIETLY
;
3927 signal_print_state (int signo
)
3929 return signal_print
[signo
];
3933 signal_pass_state (int signo
)
3935 return signal_program
[signo
];
3939 signal_stop_update (int signo
, int state
)
3941 int ret
= signal_stop
[signo
];
3942 signal_stop
[signo
] = state
;
3947 signal_print_update (int signo
, int state
)
3949 int ret
= signal_print
[signo
];
3950 signal_print
[signo
] = state
;
3955 signal_pass_update (int signo
, int state
)
3957 int ret
= signal_program
[signo
];
3958 signal_program
[signo
] = state
;
3963 sig_print_header (void)
3965 printf_filtered (_("\
3966 Signal Stop\tPrint\tPass to program\tDescription\n"));
3970 sig_print_info (enum target_signal oursig
)
3972 char *name
= target_signal_to_name (oursig
);
3973 int name_padding
= 13 - strlen (name
);
3975 if (name_padding
<= 0)
3978 printf_filtered ("%s", name
);
3979 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3980 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3981 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3982 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3983 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3986 /* Specify how various signals in the inferior should be handled. */
3989 handle_command (char *args
, int from_tty
)
3992 int digits
, wordlen
;
3993 int sigfirst
, signum
, siglast
;
3994 enum target_signal oursig
;
3997 unsigned char *sigs
;
3998 struct cleanup
*old_chain
;
4002 error_no_arg (_("signal to handle"));
4005 /* Allocate and zero an array of flags for which signals to handle. */
4007 nsigs
= (int) TARGET_SIGNAL_LAST
;
4008 sigs
= (unsigned char *) alloca (nsigs
);
4009 memset (sigs
, 0, nsigs
);
4011 /* Break the command line up into args. */
4013 argv
= buildargv (args
);
4018 old_chain
= make_cleanup_freeargv (argv
);
4020 /* Walk through the args, looking for signal oursigs, signal names, and
4021 actions. Signal numbers and signal names may be interspersed with
4022 actions, with the actions being performed for all signals cumulatively
4023 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4025 while (*argv
!= NULL
)
4027 wordlen
= strlen (*argv
);
4028 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
4032 sigfirst
= siglast
= -1;
4034 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
4036 /* Apply action to all signals except those used by the
4037 debugger. Silently skip those. */
4040 siglast
= nsigs
- 1;
4042 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
4044 SET_SIGS (nsigs
, sigs
, signal_stop
);
4045 SET_SIGS (nsigs
, sigs
, signal_print
);
4047 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
4049 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4051 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
4053 SET_SIGS (nsigs
, sigs
, signal_print
);
4055 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
4057 SET_SIGS (nsigs
, sigs
, signal_program
);
4059 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
4061 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4063 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
4065 SET_SIGS (nsigs
, sigs
, signal_program
);
4067 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
4069 UNSET_SIGS (nsigs
, sigs
, signal_print
);
4070 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4072 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
4074 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4076 else if (digits
> 0)
4078 /* It is numeric. The numeric signal refers to our own
4079 internal signal numbering from target.h, not to host/target
4080 signal number. This is a feature; users really should be
4081 using symbolic names anyway, and the common ones like
4082 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
4084 sigfirst
= siglast
= (int)
4085 target_signal_from_command (atoi (*argv
));
4086 if ((*argv
)[digits
] == '-')
4089 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
4091 if (sigfirst
> siglast
)
4093 /* Bet he didn't figure we'd think of this case... */
4101 oursig
= target_signal_from_name (*argv
);
4102 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
4104 sigfirst
= siglast
= (int) oursig
;
4108 /* Not a number and not a recognized flag word => complain. */
4109 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
4113 /* If any signal numbers or symbol names were found, set flags for
4114 which signals to apply actions to. */
4116 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
4118 switch ((enum target_signal
) signum
)
4120 case TARGET_SIGNAL_TRAP
:
4121 case TARGET_SIGNAL_INT
:
4122 if (!allsigs
&& !sigs
[signum
])
4124 if (query ("%s is used by the debugger.\n\
4125 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
4131 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4132 gdb_flush (gdb_stdout
);
4136 case TARGET_SIGNAL_0
:
4137 case TARGET_SIGNAL_DEFAULT
:
4138 case TARGET_SIGNAL_UNKNOWN
:
4139 /* Make sure that "all" doesn't print these. */
4150 target_notice_signals (inferior_ptid
);
4154 /* Show the results. */
4155 sig_print_header ();
4156 for (signum
= 0; signum
< nsigs
; signum
++)
4160 sig_print_info (signum
);
4165 do_cleanups (old_chain
);
4169 xdb_handle_command (char *args
, int from_tty
)
4172 struct cleanup
*old_chain
;
4174 /* Break the command line up into args. */
4176 argv
= buildargv (args
);
4181 old_chain
= make_cleanup_freeargv (argv
);
4182 if (argv
[1] != (char *) NULL
)
4187 bufLen
= strlen (argv
[0]) + 20;
4188 argBuf
= (char *) xmalloc (bufLen
);
4192 enum target_signal oursig
;
4194 oursig
= target_signal_from_name (argv
[0]);
4195 memset (argBuf
, 0, bufLen
);
4196 if (strcmp (argv
[1], "Q") == 0)
4197 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4200 if (strcmp (argv
[1], "s") == 0)
4202 if (!signal_stop
[oursig
])
4203 sprintf (argBuf
, "%s %s", argv
[0], "stop");
4205 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
4207 else if (strcmp (argv
[1], "i") == 0)
4209 if (!signal_program
[oursig
])
4210 sprintf (argBuf
, "%s %s", argv
[0], "pass");
4212 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
4214 else if (strcmp (argv
[1], "r") == 0)
4216 if (!signal_print
[oursig
])
4217 sprintf (argBuf
, "%s %s", argv
[0], "print");
4219 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4225 handle_command (argBuf
, from_tty
);
4227 printf_filtered (_("Invalid signal handling flag.\n"));
4232 do_cleanups (old_chain
);
4235 /* Print current contents of the tables set by the handle command.
4236 It is possible we should just be printing signals actually used
4237 by the current target (but for things to work right when switching
4238 targets, all signals should be in the signal tables). */
4241 signals_info (char *signum_exp
, int from_tty
)
4243 enum target_signal oursig
;
4244 sig_print_header ();
4248 /* First see if this is a symbol name. */
4249 oursig
= target_signal_from_name (signum_exp
);
4250 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
4252 /* No, try numeric. */
4254 target_signal_from_command (parse_and_eval_long (signum_exp
));
4256 sig_print_info (oursig
);
4260 printf_filtered ("\n");
4261 /* These ugly casts brought to you by the native VAX compiler. */
4262 for (oursig
= TARGET_SIGNAL_FIRST
;
4263 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
4264 oursig
= (enum target_signal
) ((int) oursig
+ 1))
4268 if (oursig
!= TARGET_SIGNAL_UNKNOWN
4269 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
4270 sig_print_info (oursig
);
4273 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4276 struct inferior_status
4278 enum target_signal stop_signal
;
4282 int stop_stack_dummy
;
4283 int stopped_by_random_signal
;
4284 int stepping_over_breakpoint
;
4285 CORE_ADDR step_range_start
;
4286 CORE_ADDR step_range_end
;
4287 struct frame_id step_frame_id
;
4288 enum step_over_calls_kind step_over_calls
;
4289 CORE_ADDR step_resume_break_address
;
4290 int stop_after_trap
;
4293 /* These are here because if call_function_by_hand has written some
4294 registers and then decides to call error(), we better not have changed
4296 struct regcache
*registers
;
4298 /* A frame unique identifier. */
4299 struct frame_id selected_frame_id
;
4301 int breakpoint_proceeded
;
4302 int restore_stack_info
;
4303 int proceed_to_finish
;
4307 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
4310 int size
= register_size (current_gdbarch
, regno
);
4311 void *buf
= alloca (size
);
4312 store_signed_integer (buf
, size
, val
);
4313 regcache_raw_write (inf_status
->registers
, regno
, buf
);
4316 /* Save all of the information associated with the inferior<==>gdb
4317 connection. INF_STATUS is a pointer to a "struct inferior_status"
4318 (defined in inferior.h). */
4320 struct inferior_status
*
4321 save_inferior_status (int restore_stack_info
)
4323 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
4325 inf_status
->stop_signal
= stop_signal
;
4326 inf_status
->stop_pc
= stop_pc
;
4327 inf_status
->stop_step
= stop_step
;
4328 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
4329 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
4330 inf_status
->stepping_over_breakpoint
= stepping_over_breakpoint
;
4331 inf_status
->step_range_start
= step_range_start
;
4332 inf_status
->step_range_end
= step_range_end
;
4333 inf_status
->step_frame_id
= step_frame_id
;
4334 inf_status
->step_over_calls
= step_over_calls
;
4335 inf_status
->stop_after_trap
= stop_after_trap
;
4336 inf_status
->stop_soon
= stop_soon
;
4337 /* Save original bpstat chain here; replace it with copy of chain.
4338 If caller's caller is walking the chain, they'll be happier if we
4339 hand them back the original chain when restore_inferior_status is
4341 inf_status
->stop_bpstat
= stop_bpstat
;
4342 stop_bpstat
= bpstat_copy (stop_bpstat
);
4343 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4344 inf_status
->restore_stack_info
= restore_stack_info
;
4345 inf_status
->proceed_to_finish
= proceed_to_finish
;
4347 inf_status
->registers
= regcache_dup (get_current_regcache ());
4349 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
4354 restore_selected_frame (void *args
)
4356 struct frame_id
*fid
= (struct frame_id
*) args
;
4357 struct frame_info
*frame
;
4359 frame
= frame_find_by_id (*fid
);
4361 /* If inf_status->selected_frame_id is NULL, there was no previously
4365 warning (_("Unable to restore previously selected frame."));
4369 select_frame (frame
);
4375 restore_inferior_status (struct inferior_status
*inf_status
)
4377 stop_signal
= inf_status
->stop_signal
;
4378 stop_pc
= inf_status
->stop_pc
;
4379 stop_step
= inf_status
->stop_step
;
4380 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4381 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4382 stepping_over_breakpoint
= inf_status
->stepping_over_breakpoint
;
4383 step_range_start
= inf_status
->step_range_start
;
4384 step_range_end
= inf_status
->step_range_end
;
4385 step_frame_id
= inf_status
->step_frame_id
;
4386 step_over_calls
= inf_status
->step_over_calls
;
4387 stop_after_trap
= inf_status
->stop_after_trap
;
4388 stop_soon
= inf_status
->stop_soon
;
4389 bpstat_clear (&stop_bpstat
);
4390 stop_bpstat
= inf_status
->stop_bpstat
;
4391 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4392 proceed_to_finish
= inf_status
->proceed_to_finish
;
4394 /* The inferior can be gone if the user types "print exit(0)"
4395 (and perhaps other times). */
4396 if (target_has_execution
)
4397 /* NB: The register write goes through to the target. */
4398 regcache_cpy (get_current_regcache (), inf_status
->registers
);
4399 regcache_xfree (inf_status
->registers
);
4401 /* FIXME: If we are being called after stopping in a function which
4402 is called from gdb, we should not be trying to restore the
4403 selected frame; it just prints a spurious error message (The
4404 message is useful, however, in detecting bugs in gdb (like if gdb
4405 clobbers the stack)). In fact, should we be restoring the
4406 inferior status at all in that case? . */
4408 if (target_has_stack
&& inf_status
->restore_stack_info
)
4410 /* The point of catch_errors is that if the stack is clobbered,
4411 walking the stack might encounter a garbage pointer and
4412 error() trying to dereference it. */
4414 (restore_selected_frame
, &inf_status
->selected_frame_id
,
4415 "Unable to restore previously selected frame:\n",
4416 RETURN_MASK_ERROR
) == 0)
4417 /* Error in restoring the selected frame. Select the innermost
4419 select_frame (get_current_frame ());
4427 do_restore_inferior_status_cleanup (void *sts
)
4429 restore_inferior_status (sts
);
4433 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4435 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4439 discard_inferior_status (struct inferior_status
*inf_status
)
4441 /* See save_inferior_status for info on stop_bpstat. */
4442 bpstat_clear (&inf_status
->stop_bpstat
);
4443 regcache_xfree (inf_status
->registers
);
4448 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
4450 struct target_waitstatus last
;
4453 get_last_target_status (&last_ptid
, &last
);
4455 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
4458 if (!ptid_equal (last_ptid
, pid
))
4461 *child_pid
= last
.value
.related_pid
;
4466 inferior_has_vforked (ptid_t pid
, ptid_t
*child_pid
)
4468 struct target_waitstatus last
;
4471 get_last_target_status (&last_ptid
, &last
);
4473 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
4476 if (!ptid_equal (last_ptid
, pid
))
4479 *child_pid
= last
.value
.related_pid
;
4484 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
4486 struct target_waitstatus last
;
4489 get_last_target_status (&last_ptid
, &last
);
4491 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
4494 if (!ptid_equal (last_ptid
, pid
))
4497 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
4501 /* Oft used ptids */
4503 ptid_t minus_one_ptid
;
4505 /* Create a ptid given the necessary PID, LWP, and TID components. */
4508 ptid_build (int pid
, long lwp
, long tid
)
4518 /* Create a ptid from just a pid. */
4521 pid_to_ptid (int pid
)
4523 return ptid_build (pid
, 0, 0);
4526 /* Fetch the pid (process id) component from a ptid. */
4529 ptid_get_pid (ptid_t ptid
)
4534 /* Fetch the lwp (lightweight process) component from a ptid. */
4537 ptid_get_lwp (ptid_t ptid
)
4542 /* Fetch the tid (thread id) component from a ptid. */
4545 ptid_get_tid (ptid_t ptid
)
4550 /* ptid_equal() is used to test equality of two ptids. */
4553 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4555 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4556 && ptid1
.tid
== ptid2
.tid
);
4559 /* restore_inferior_ptid() will be used by the cleanup machinery
4560 to restore the inferior_ptid value saved in a call to
4561 save_inferior_ptid(). */
4564 restore_inferior_ptid (void *arg
)
4566 ptid_t
*saved_ptid_ptr
= arg
;
4567 inferior_ptid
= *saved_ptid_ptr
;
4571 /* Save the value of inferior_ptid so that it may be restored by a
4572 later call to do_cleanups(). Returns the struct cleanup pointer
4573 needed for later doing the cleanup. */
4576 save_inferior_ptid (void)
4578 ptid_t
*saved_ptid_ptr
;
4580 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4581 *saved_ptid_ptr
= inferior_ptid
;
4582 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4587 static int non_stop_1
= 0;
4590 set_non_stop (char *args
, int from_tty
,
4591 struct cmd_list_element
*c
)
4593 if (target_has_execution
)
4595 non_stop_1
= non_stop
;
4596 error (_("Cannot change this setting while the inferior is running."));
4599 non_stop
= non_stop_1
;
4603 show_non_stop (struct ui_file
*file
, int from_tty
,
4604 struct cmd_list_element
*c
, const char *value
)
4606 fprintf_filtered (file
,
4607 _("Controlling the inferior in non-stop mode is %s.\n"),
4613 _initialize_infrun (void)
4617 struct cmd_list_element
*c
;
4619 add_info ("signals", signals_info
, _("\
4620 What debugger does when program gets various signals.\n\
4621 Specify a signal as argument to print info on that signal only."));
4622 add_info_alias ("handle", "signals", 0);
4624 add_com ("handle", class_run
, handle_command
, _("\
4625 Specify how to handle a signal.\n\
4626 Args are signals and actions to apply to those signals.\n\
4627 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4628 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4629 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4630 The special arg \"all\" is recognized to mean all signals except those\n\
4631 used by the debugger, typically SIGTRAP and SIGINT.\n\
4632 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4633 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4634 Stop means reenter debugger if this signal happens (implies print).\n\
4635 Print means print a message if this signal happens.\n\
4636 Pass means let program see this signal; otherwise program doesn't know.\n\
4637 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4638 Pass and Stop may be combined."));
4641 add_com ("lz", class_info
, signals_info
, _("\
4642 What debugger does when program gets various signals.\n\
4643 Specify a signal as argument to print info on that signal only."));
4644 add_com ("z", class_run
, xdb_handle_command
, _("\
4645 Specify how to handle a signal.\n\
4646 Args are signals and actions to apply to those signals.\n\
4647 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4648 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4649 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4650 The special arg \"all\" is recognized to mean all signals except those\n\
4651 used by the debugger, typically SIGTRAP and SIGINT.\n\
4652 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4653 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4654 nopass), \"Q\" (noprint)\n\
4655 Stop means reenter debugger if this signal happens (implies print).\n\
4656 Print means print a message if this signal happens.\n\
4657 Pass means let program see this signal; otherwise program doesn't know.\n\
4658 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4659 Pass and Stop may be combined."));
4663 stop_command
= add_cmd ("stop", class_obscure
,
4664 not_just_help_class_command
, _("\
4665 There is no `stop' command, but you can set a hook on `stop'.\n\
4666 This allows you to set a list of commands to be run each time execution\n\
4667 of the program stops."), &cmdlist
);
4669 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
4670 Set inferior debugging."), _("\
4671 Show inferior debugging."), _("\
4672 When non-zero, inferior specific debugging is enabled."),
4675 &setdebuglist
, &showdebuglist
);
4677 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
4678 Set displaced stepping debugging."), _("\
4679 Show displaced stepping debugging."), _("\
4680 When non-zero, displaced stepping specific debugging is enabled."),
4682 show_debug_displaced
,
4683 &setdebuglist
, &showdebuglist
);
4685 add_setshow_boolean_cmd ("non-stop", no_class
,
4687 Set whether gdb controls the inferior in non-stop mode."), _("\
4688 Show whether gdb controls the inferior in non-stop mode."), _("\
4689 When debugging a multi-threaded program and this setting is\n\
4690 off (the default, also called all-stop mode), when one thread stops\n\
4691 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
4692 all other threads in the program while you interact with the thread of\n\
4693 interest. When you continue or step a thread, you can allow the other\n\
4694 threads to run, or have them remain stopped, but while you inspect any\n\
4695 thread's state, all threads stop.\n\
4697 In non-stop mode, when one thread stops, other threads can continue\n\
4698 to run freely. You'll be able to step each thread independently,\n\
4699 leave it stopped or free to run as needed."),
4705 numsigs
= (int) TARGET_SIGNAL_LAST
;
4706 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4707 signal_print
= (unsigned char *)
4708 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4709 signal_program
= (unsigned char *)
4710 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4711 for (i
= 0; i
< numsigs
; i
++)
4714 signal_print
[i
] = 1;
4715 signal_program
[i
] = 1;
4718 /* Signals caused by debugger's own actions
4719 should not be given to the program afterwards. */
4720 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4721 signal_program
[TARGET_SIGNAL_INT
] = 0;
4723 /* Signals that are not errors should not normally enter the debugger. */
4724 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4725 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4726 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4727 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4728 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4729 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4730 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4731 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4732 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4733 signal_print
[TARGET_SIGNAL_IO
] = 0;
4734 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4735 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4736 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4737 signal_print
[TARGET_SIGNAL_URG
] = 0;
4738 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4739 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4741 /* These signals are used internally by user-level thread
4742 implementations. (See signal(5) on Solaris.) Like the above
4743 signals, a healthy program receives and handles them as part of
4744 its normal operation. */
4745 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4746 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4747 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4748 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4749 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4750 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4752 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
4753 &stop_on_solib_events
, _("\
4754 Set stopping for shared library events."), _("\
4755 Show stopping for shared library events."), _("\
4756 If nonzero, gdb will give control to the user when the dynamic linker\n\
4757 notifies gdb of shared library events. The most common event of interest\n\
4758 to the user would be loading/unloading of a new library."),
4760 show_stop_on_solib_events
,
4761 &setlist
, &showlist
);
4763 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
4764 follow_fork_mode_kind_names
,
4765 &follow_fork_mode_string
, _("\
4766 Set debugger response to a program call of fork or vfork."), _("\
4767 Show debugger response to a program call of fork or vfork."), _("\
4768 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4769 parent - the original process is debugged after a fork\n\
4770 child - the new process is debugged after a fork\n\
4771 The unfollowed process will continue to run.\n\
4772 By default, the debugger will follow the parent process."),
4774 show_follow_fork_mode_string
,
4775 &setlist
, &showlist
);
4777 add_setshow_enum_cmd ("scheduler-locking", class_run
,
4778 scheduler_enums
, &scheduler_mode
, _("\
4779 Set mode for locking scheduler during execution."), _("\
4780 Show mode for locking scheduler during execution."), _("\
4781 off == no locking (threads may preempt at any time)\n\
4782 on == full locking (no thread except the current thread may run)\n\
4783 step == scheduler locked during every single-step operation.\n\
4784 In this mode, no other thread may run during a step command.\n\
4785 Other threads may run while stepping over a function call ('next')."),
4786 set_schedlock_func
, /* traps on target vector */
4787 show_scheduler_mode
,
4788 &setlist
, &showlist
);
4790 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
4791 Set mode of the step operation."), _("\
4792 Show mode of the step operation."), _("\
4793 When set, doing a step over a function without debug line information\n\
4794 will stop at the first instruction of that function. Otherwise, the\n\
4795 function is skipped and the step command stops at a different source line."),
4797 show_step_stop_if_no_debug
,
4798 &setlist
, &showlist
);
4800 add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance
,
4801 &can_use_displaced_stepping
, _("\
4802 Set debugger's willingness to use displaced stepping."), _("\
4803 Show debugger's willingness to use displaced stepping."), _("\
4804 If zero, gdb will not use displaced stepping to step over\n\
4805 breakpoints, even if such is supported by the target."),
4807 show_can_use_displaced_stepping
,
4808 &maintenance_set_cmdlist
,
4809 &maintenance_show_cmdlist
);
4811 /* ptid initializations */
4812 null_ptid
= ptid_build (0, 0, 0);
4813 minus_one_ptid
= ptid_build (-1, 0, 0);
4814 inferior_ptid
= null_ptid
;
4815 target_last_wait_ptid
= minus_one_ptid
;
4816 displaced_step_ptid
= null_ptid
;