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"
51 #include "event-top.h"
53 /* Prototypes for local functions */
55 static void signals_info (char *, int);
57 static void handle_command (char *, int);
59 static void sig_print_info (enum target_signal
);
61 static void sig_print_header (void);
63 static void resume_cleanups (void *);
65 static int hook_stop_stub (void *);
67 static int restore_selected_frame (void *);
69 static void build_infrun (void);
71 static int follow_fork (void);
73 static void set_schedlock_func (char *args
, int from_tty
,
74 struct cmd_list_element
*c
);
76 struct thread_stepping_state
;
78 static int currently_stepping (struct thread_stepping_state
*tss
);
80 static void xdb_handle_command (char *args
, int from_tty
);
82 static int prepare_to_proceed (int);
84 void _initialize_infrun (void);
86 /* When set, stop the 'step' command if we enter a function which has
87 no line number information. The normal behavior is that we step
88 over such function. */
89 int step_stop_if_no_debug
= 0;
91 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
92 struct cmd_list_element
*c
, const char *value
)
94 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
97 /* In asynchronous mode, but simulating synchronous execution. */
99 int sync_execution
= 0;
101 /* wait_for_inferior and normal_stop use this to notify the user
102 when the inferior stopped in a different thread than it had been
105 static ptid_t previous_inferior_ptid
;
107 int debug_displaced
= 0;
109 show_debug_displaced (struct ui_file
*file
, int from_tty
,
110 struct cmd_list_element
*c
, const char *value
)
112 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
115 static int debug_infrun
= 0;
117 show_debug_infrun (struct ui_file
*file
, int from_tty
,
118 struct cmd_list_element
*c
, const char *value
)
120 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
123 /* If the program uses ELF-style shared libraries, then calls to
124 functions in shared libraries go through stubs, which live in a
125 table called the PLT (Procedure Linkage Table). The first time the
126 function is called, the stub sends control to the dynamic linker,
127 which looks up the function's real address, patches the stub so
128 that future calls will go directly to the function, and then passes
129 control to the function.
131 If we are stepping at the source level, we don't want to see any of
132 this --- we just want to skip over the stub and the dynamic linker.
133 The simple approach is to single-step until control leaves the
136 However, on some systems (e.g., Red Hat's 5.2 distribution) the
137 dynamic linker calls functions in the shared C library, so you
138 can't tell from the PC alone whether the dynamic linker is still
139 running. In this case, we use a step-resume breakpoint to get us
140 past the dynamic linker, as if we were using "next" to step over a
143 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
144 linker code or not. Normally, this means we single-step. However,
145 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
146 address where we can place a step-resume breakpoint to get past the
147 linker's symbol resolution function.
149 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
150 pretty portable way, by comparing the PC against the address ranges
151 of the dynamic linker's sections.
153 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
154 it depends on internal details of the dynamic linker. It's usually
155 not too hard to figure out where to put a breakpoint, but it
156 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
157 sanity checking. If it can't figure things out, returning zero and
158 getting the (possibly confusing) stepping behavior is better than
159 signalling an error, which will obscure the change in the
162 /* This function returns TRUE if pc is the address of an instruction
163 that lies within the dynamic linker (such as the event hook, or the
166 This function must be used only when a dynamic linker event has
167 been caught, and the inferior is being stepped out of the hook, or
168 undefined results are guaranteed. */
170 #ifndef SOLIB_IN_DYNAMIC_LINKER
171 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
175 /* Convert the #defines into values. This is temporary until wfi control
176 flow is completely sorted out. */
178 #ifndef CANNOT_STEP_HW_WATCHPOINTS
179 #define CANNOT_STEP_HW_WATCHPOINTS 0
181 #undef CANNOT_STEP_HW_WATCHPOINTS
182 #define CANNOT_STEP_HW_WATCHPOINTS 1
185 /* Tables of how to react to signals; the user sets them. */
187 static unsigned char *signal_stop
;
188 static unsigned char *signal_print
;
189 static unsigned char *signal_program
;
191 #define SET_SIGS(nsigs,sigs,flags) \
193 int signum = (nsigs); \
194 while (signum-- > 0) \
195 if ((sigs)[signum]) \
196 (flags)[signum] = 1; \
199 #define UNSET_SIGS(nsigs,sigs,flags) \
201 int signum = (nsigs); \
202 while (signum-- > 0) \
203 if ((sigs)[signum]) \
204 (flags)[signum] = 0; \
207 /* Value to pass to target_resume() to cause all threads to resume */
209 #define RESUME_ALL (pid_to_ptid (-1))
211 /* Command list pointer for the "stop" placeholder. */
213 static struct cmd_list_element
*stop_command
;
215 /* Function inferior was in as of last step command. */
217 static struct symbol
*step_start_function
;
219 /* Nonzero if we are presently stepping over a breakpoint.
221 If we hit a breakpoint or watchpoint, and then continue,
222 we need to single step the current thread with breakpoints
223 disabled, to avoid hitting the same breakpoint or
224 watchpoint again. And we should step just a single
225 thread and keep other threads stopped, so that
226 other threads don't miss breakpoints while they are removed.
228 So, this variable simultaneously means that we need to single
229 step the current thread, keep other threads stopped, and that
230 breakpoints should be removed while we step.
232 This variable is set either:
233 - in proceed, when we resume inferior on user's explicit request
234 - in keep_going, if handle_inferior_event decides we need to
235 step over breakpoint.
237 The variable is cleared in clear_proceed_status, called every
238 time before we call proceed. The proceed calls wait_for_inferior,
239 which calls handle_inferior_event in a loop, and until
240 wait_for_inferior exits, this variable is changed only by keep_going. */
242 static int stepping_over_breakpoint
;
244 /* Nonzero if we want to give control to the user when we're notified
245 of shared library events by the dynamic linker. */
246 static int stop_on_solib_events
;
248 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
249 struct cmd_list_element
*c
, const char *value
)
251 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
255 /* Nonzero means expecting a trace trap
256 and should stop the inferior and return silently when it happens. */
260 /* Nonzero means expecting a trap and caller will handle it themselves.
261 It is used after attach, due to attaching to a process;
262 when running in the shell before the child program has been exec'd;
263 and when running some kinds of remote stuff (FIXME?). */
265 enum stop_kind stop_soon
;
267 /* Nonzero if proceed is being used for a "finish" command or a similar
268 situation when stop_registers should be saved. */
270 int proceed_to_finish
;
272 /* Save register contents here when about to pop a stack dummy frame,
273 if-and-only-if proceed_to_finish is set.
274 Thus this contains the return value from the called function (assuming
275 values are returned in a register). */
277 struct regcache
*stop_registers
;
279 /* Nonzero after stop if current stack frame should be printed. */
281 static int stop_print_frame
;
283 /* Step-resume or longjmp-resume breakpoint. */
284 static struct breakpoint
*step_resume_breakpoint
= NULL
;
286 /* This is a cached copy of the pid/waitstatus of the last event
287 returned by target_wait()/deprecated_target_wait_hook(). This
288 information is returned by get_last_target_status(). */
289 static ptid_t target_last_wait_ptid
;
290 static struct target_waitstatus target_last_waitstatus
;
292 /* Context-switchable data. */
293 struct thread_stepping_state
295 /* Should we step over breakpoint next time keep_going
297 int stepping_over_breakpoint
;
298 struct symtab_and_line sal
;
300 struct symtab
*current_symtab
;
301 int step_after_step_resume_breakpoint
;
302 int stepping_through_solib_after_catch
;
303 bpstat stepping_through_solib_catchpoints
;
306 struct thread_stepping_state gtss
;
307 struct thread_stepping_state
*tss
= >ss
;
309 static void context_switch (ptid_t ptid
);
311 void init_thread_stepping_state (struct thread_stepping_state
*tss
);
313 void init_infwait_state (void);
315 /* This is used to remember when a fork, vfork or exec event
316 was caught by a catchpoint, and thus the event is to be
317 followed at the next resume of the inferior, and not
321 enum target_waitkind kind
;
328 char *execd_pathname
;
332 static const char follow_fork_mode_child
[] = "child";
333 static const char follow_fork_mode_parent
[] = "parent";
335 static const char *follow_fork_mode_kind_names
[] = {
336 follow_fork_mode_child
,
337 follow_fork_mode_parent
,
341 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
343 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
344 struct cmd_list_element
*c
, const char *value
)
346 fprintf_filtered (file
, _("\
347 Debugger response to a program call of fork or vfork is \"%s\".\n"),
355 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
357 return target_follow_fork (follow_child
);
361 follow_inferior_reset_breakpoints (void)
363 /* Was there a step_resume breakpoint? (There was if the user
364 did a "next" at the fork() call.) If so, explicitly reset its
367 step_resumes are a form of bp that are made to be per-thread.
368 Since we created the step_resume bp when the parent process
369 was being debugged, and now are switching to the child process,
370 from the breakpoint package's viewpoint, that's a switch of
371 "threads". We must update the bp's notion of which thread
372 it is for, or it'll be ignored when it triggers. */
374 if (step_resume_breakpoint
)
375 breakpoint_re_set_thread (step_resume_breakpoint
);
377 /* Reinsert all breakpoints in the child. The user may have set
378 breakpoints after catching the fork, in which case those
379 were never set in the child, but only in the parent. This makes
380 sure the inserted breakpoints match the breakpoint list. */
382 breakpoint_re_set ();
383 insert_breakpoints ();
386 /* EXECD_PATHNAME is assumed to be non-NULL. */
389 follow_exec (ptid_t pid
, char *execd_pathname
)
391 ptid_t saved_pid
= pid
;
392 struct target_ops
*tgt
;
394 /* This is an exec event that we actually wish to pay attention to.
395 Refresh our symbol table to the newly exec'd program, remove any
398 If there are breakpoints, they aren't really inserted now,
399 since the exec() transformed our inferior into a fresh set
402 We want to preserve symbolic breakpoints on the list, since
403 we have hopes that they can be reset after the new a.out's
404 symbol table is read.
406 However, any "raw" breakpoints must be removed from the list
407 (e.g., the solib bp's), since their address is probably invalid
410 And, we DON'T want to call delete_breakpoints() here, since
411 that may write the bp's "shadow contents" (the instruction
412 value that was overwritten witha TRAP instruction). Since
413 we now have a new a.out, those shadow contents aren't valid. */
414 update_breakpoints_after_exec ();
416 /* If there was one, it's gone now. We cannot truly step-to-next
417 statement through an exec(). */
418 step_resume_breakpoint
= NULL
;
419 step_range_start
= 0;
422 /* What is this a.out's name? */
423 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
425 /* We've followed the inferior through an exec. Therefore, the
426 inferior has essentially been killed & reborn. */
428 gdb_flush (gdb_stdout
);
429 generic_mourn_inferior ();
430 /* Because mourn_inferior resets inferior_ptid. */
431 inferior_ptid
= saved_pid
;
433 if (gdb_sysroot
&& *gdb_sysroot
)
435 char *name
= alloca (strlen (gdb_sysroot
)
436 + strlen (execd_pathname
)
438 strcpy (name
, gdb_sysroot
);
439 strcat (name
, execd_pathname
);
440 execd_pathname
= name
;
443 /* That a.out is now the one to use. */
444 exec_file_attach (execd_pathname
, 0);
446 /* Reset the shared library package. This ensures that we get a
447 shlib event when the child reaches "_start", at which point the
448 dld will have had a chance to initialize the child. */
449 /* Also, loading a symbol file below may trigger symbol lookups, and
450 we don't want those to be satisfied by the libraries of the
451 previous incarnation of this process. */
452 no_shared_libraries (NULL
, 0);
454 /* Load the main file's symbols. */
455 symbol_file_add_main (execd_pathname
, 0);
457 #ifdef SOLIB_CREATE_INFERIOR_HOOK
458 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
460 solib_create_inferior_hook ();
463 /* Reinsert all breakpoints. (Those which were symbolic have
464 been reset to the proper address in the new a.out, thanks
465 to symbol_file_command...) */
466 insert_breakpoints ();
468 /* The next resume of this inferior should bring it to the shlib
469 startup breakpoints. (If the user had also set bp's on
470 "main" from the old (parent) process, then they'll auto-
471 matically get reset there in the new process.) */
474 /* Non-zero if we just simulating a single-step. This is needed
475 because we cannot remove the breakpoints in the inferior process
476 until after the `wait' in `wait_for_inferior'. */
477 static int singlestep_breakpoints_inserted_p
= 0;
479 /* The thread we inserted single-step breakpoints for. */
480 static ptid_t singlestep_ptid
;
482 /* PC when we started this single-step. */
483 static CORE_ADDR singlestep_pc
;
485 /* If another thread hit the singlestep breakpoint, we save the original
486 thread here so that we can resume single-stepping it later. */
487 static ptid_t saved_singlestep_ptid
;
488 static int stepping_past_singlestep_breakpoint
;
490 /* If not equal to null_ptid, this means that after stepping over breakpoint
491 is finished, we need to switch to deferred_step_ptid, and step it.
493 The use case is when one thread has hit a breakpoint, and then the user
494 has switched to another thread and issued 'step'. We need to step over
495 breakpoint in the thread which hit the breakpoint, but then continue
496 stepping the thread user has selected. */
497 static ptid_t deferred_step_ptid
;
499 /* Displaced stepping. */
501 /* In non-stop debugging mode, we must take special care to manage
502 breakpoints properly; in particular, the traditional strategy for
503 stepping a thread past a breakpoint it has hit is unsuitable.
504 'Displaced stepping' is a tactic for stepping one thread past a
505 breakpoint it has hit while ensuring that other threads running
506 concurrently will hit the breakpoint as they should.
508 The traditional way to step a thread T off a breakpoint in a
509 multi-threaded program in all-stop mode is as follows:
511 a0) Initially, all threads are stopped, and breakpoints are not
513 a1) We single-step T, leaving breakpoints uninserted.
514 a2) We insert breakpoints, and resume all threads.
516 In non-stop debugging, however, this strategy is unsuitable: we
517 don't want to have to stop all threads in the system in order to
518 continue or step T past a breakpoint. Instead, we use displaced
521 n0) Initially, T is stopped, other threads are running, and
522 breakpoints are inserted.
523 n1) We copy the instruction "under" the breakpoint to a separate
524 location, outside the main code stream, making any adjustments
525 to the instruction, register, and memory state as directed by
527 n2) We single-step T over the instruction at its new location.
528 n3) We adjust the resulting register and memory state as directed
529 by T's architecture. This includes resetting T's PC to point
530 back into the main instruction stream.
533 This approach depends on the following gdbarch methods:
535 - gdbarch_max_insn_length and gdbarch_displaced_step_location
536 indicate where to copy the instruction, and how much space must
537 be reserved there. We use these in step n1.
539 - gdbarch_displaced_step_copy_insn copies a instruction to a new
540 address, and makes any necessary adjustments to the instruction,
541 register contents, and memory. We use this in step n1.
543 - gdbarch_displaced_step_fixup adjusts registers and memory after
544 we have successfuly single-stepped the instruction, to yield the
545 same effect the instruction would have had if we had executed it
546 at its original address. We use this in step n3.
548 - gdbarch_displaced_step_free_closure provides cleanup.
550 The gdbarch_displaced_step_copy_insn and
551 gdbarch_displaced_step_fixup functions must be written so that
552 copying an instruction with gdbarch_displaced_step_copy_insn,
553 single-stepping across the copied instruction, and then applying
554 gdbarch_displaced_insn_fixup should have the same effects on the
555 thread's memory and registers as stepping the instruction in place
556 would have. Exactly which responsibilities fall to the copy and
557 which fall to the fixup is up to the author of those functions.
559 See the comments in gdbarch.sh for details.
561 Note that displaced stepping and software single-step cannot
562 currently be used in combination, although with some care I think
563 they could be made to. Software single-step works by placing
564 breakpoints on all possible subsequent instructions; if the
565 displaced instruction is a PC-relative jump, those breakpoints
566 could fall in very strange places --- on pages that aren't
567 executable, or at addresses that are not proper instruction
568 boundaries. (We do generally let other threads run while we wait
569 to hit the software single-step breakpoint, and they might
570 encounter such a corrupted instruction.) One way to work around
571 this would be to have gdbarch_displaced_step_copy_insn fully
572 simulate the effect of PC-relative instructions (and return NULL)
573 on architectures that use software single-stepping.
575 In non-stop mode, we can have independent and simultaneous step
576 requests, so more than one thread may need to simultaneously step
577 over a breakpoint. The current implementation assumes there is
578 only one scratch space per process. In this case, we have to
579 serialize access to the scratch space. If thread A wants to step
580 over a breakpoint, but we are currently waiting for some other
581 thread to complete a displaced step, we leave thread A stopped and
582 place it in the displaced_step_request_queue. Whenever a displaced
583 step finishes, we pick the next thread in the queue and start a new
584 displaced step operation on it. See displaced_step_prepare and
585 displaced_step_fixup for details. */
587 /* If this is not null_ptid, this is the thread carrying out a
588 displaced single-step. This thread's state will require fixing up
589 once it has completed its step. */
590 static ptid_t displaced_step_ptid
;
592 struct displaced_step_request
595 struct displaced_step_request
*next
;
598 /* A queue of pending displaced stepping requests. */
599 struct displaced_step_request
*displaced_step_request_queue
;
601 /* The architecture the thread had when we stepped it. */
602 static struct gdbarch
*displaced_step_gdbarch
;
604 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
605 for post-step cleanup. */
606 static struct displaced_step_closure
*displaced_step_closure
;
608 /* The address of the original instruction, and the copy we made. */
609 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
611 /* Saved contents of copy area. */
612 static gdb_byte
*displaced_step_saved_copy
;
614 /* When this is non-zero, we are allowed to use displaced stepping, if
615 the architecture supports it. When this is zero, we use
616 traditional the hold-and-step approach. */
617 int can_use_displaced_stepping
= 1;
619 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
620 struct cmd_list_element
*c
,
623 fprintf_filtered (file
, _("\
624 Debugger's willingness to use displaced stepping to step over "
625 "breakpoints is %s.\n"), value
);
628 /* Return non-zero if displaced stepping is enabled, and can be used
631 use_displaced_stepping (struct gdbarch
*gdbarch
)
633 return (can_use_displaced_stepping
634 && gdbarch_displaced_step_copy_insn_p (gdbarch
));
637 /* Clean out any stray displaced stepping state. */
639 displaced_step_clear (void)
641 /* Indicate that there is no cleanup pending. */
642 displaced_step_ptid
= null_ptid
;
644 if (displaced_step_closure
)
646 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
647 displaced_step_closure
);
648 displaced_step_closure
= NULL
;
653 cleanup_displaced_step_closure (void *ptr
)
655 struct displaced_step_closure
*closure
= ptr
;
657 gdbarch_displaced_step_free_closure (current_gdbarch
, closure
);
660 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
662 displaced_step_dump_bytes (struct ui_file
*file
,
668 for (i
= 0; i
< len
; i
++)
669 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
670 fputs_unfiltered ("\n", file
);
673 /* Prepare to single-step, using displaced stepping.
675 Note that we cannot use displaced stepping when we have a signal to
676 deliver. If we have a signal to deliver and an instruction to step
677 over, then after the step, there will be no indication from the
678 target whether the thread entered a signal handler or ignored the
679 signal and stepped over the instruction successfully --- both cases
680 result in a simple SIGTRAP. In the first case we mustn't do a
681 fixup, and in the second case we must --- but we can't tell which.
682 Comments in the code for 'random signals' in handle_inferior_event
683 explain how we handle this case instead.
685 Returns 1 if preparing was successful -- this thread is going to be
686 stepped now; or 0 if displaced stepping this thread got queued. */
688 displaced_step_prepare (ptid_t ptid
)
690 struct cleanup
*old_cleanups
;
691 struct regcache
*regcache
= get_thread_regcache (ptid
);
692 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
693 CORE_ADDR original
, copy
;
695 struct displaced_step_closure
*closure
;
697 /* We should never reach this function if the architecture does not
698 support displaced stepping. */
699 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
701 /* For the first cut, we're displaced stepping one thread at a
704 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
706 /* Already waiting for a displaced step to finish. Defer this
707 request and place in queue. */
708 struct displaced_step_request
*req
, *new_req
;
711 fprintf_unfiltered (gdb_stdlog
,
712 "displaced: defering step of %s\n",
713 target_pid_to_str (ptid
));
715 new_req
= xmalloc (sizeof (*new_req
));
716 new_req
->ptid
= ptid
;
717 new_req
->next
= NULL
;
719 if (displaced_step_request_queue
)
721 for (req
= displaced_step_request_queue
;
728 displaced_step_request_queue
= new_req
;
735 fprintf_unfiltered (gdb_stdlog
,
736 "displaced: stepping %s now\n",
737 target_pid_to_str (ptid
));
740 displaced_step_clear ();
742 original
= regcache_read_pc (regcache
);
744 copy
= gdbarch_displaced_step_location (gdbarch
);
745 len
= gdbarch_max_insn_length (gdbarch
);
747 /* Save the original contents of the copy area. */
748 displaced_step_saved_copy
= xmalloc (len
);
749 old_cleanups
= make_cleanup (free_current_contents
,
750 &displaced_step_saved_copy
);
751 read_memory (copy
, displaced_step_saved_copy
, len
);
754 fprintf_unfiltered (gdb_stdlog
, "displaced: saved 0x%s: ",
756 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
759 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
760 original
, copy
, regcache
);
762 /* We don't support the fully-simulated case at present. */
763 gdb_assert (closure
);
765 make_cleanup (cleanup_displaced_step_closure
, closure
);
767 /* Resume execution at the copy. */
768 regcache_write_pc (regcache
, copy
);
770 discard_cleanups (old_cleanups
);
773 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to 0x%s\n",
776 /* Save the information we need to fix things up if the step
778 displaced_step_ptid
= ptid
;
779 displaced_step_gdbarch
= gdbarch
;
780 displaced_step_closure
= closure
;
781 displaced_step_original
= original
;
782 displaced_step_copy
= copy
;
787 displaced_step_clear_cleanup (void *ignore
)
789 displaced_step_clear ();
793 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
795 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
796 inferior_ptid
= ptid
;
797 write_memory (memaddr
, myaddr
, len
);
798 do_cleanups (ptid_cleanup
);
802 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
804 struct cleanup
*old_cleanups
;
806 /* Was this event for the pid we displaced? */
807 if (ptid_equal (displaced_step_ptid
, null_ptid
)
808 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
811 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
813 /* Restore the contents of the copy area. */
815 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
816 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
817 displaced_step_saved_copy
, len
);
819 fprintf_unfiltered (gdb_stdlog
, "displaced: restored 0x%s\n",
820 paddr_nz (displaced_step_copy
));
823 /* Did the instruction complete successfully? */
824 if (signal
== TARGET_SIGNAL_TRAP
)
826 /* Fix up the resulting state. */
827 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
828 displaced_step_closure
,
829 displaced_step_original
,
831 get_thread_regcache (displaced_step_ptid
));
835 /* Since the instruction didn't complete, all we can do is
837 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
838 CORE_ADDR pc
= regcache_read_pc (regcache
);
839 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
840 regcache_write_pc (regcache
, pc
);
843 do_cleanups (old_cleanups
);
845 /* Are there any pending displaced stepping requests? If so, run
847 if (displaced_step_request_queue
)
849 struct displaced_step_request
*head
;
852 head
= displaced_step_request_queue
;
854 displaced_step_request_queue
= head
->next
;
858 fprintf_unfiltered (gdb_stdlog
,
859 "displaced: stepping queued %s now\n",
860 target_pid_to_str (ptid
));
863 displaced_step_ptid
= null_ptid
;
864 displaced_step_prepare (ptid
);
865 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
872 /* Things to clean up if we QUIT out of resume (). */
874 resume_cleanups (void *ignore
)
879 static const char schedlock_off
[] = "off";
880 static const char schedlock_on
[] = "on";
881 static const char schedlock_step
[] = "step";
882 static const char *scheduler_enums
[] = {
888 static const char *scheduler_mode
= schedlock_off
;
890 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
891 struct cmd_list_element
*c
, const char *value
)
893 fprintf_filtered (file
, _("\
894 Mode for locking scheduler during execution is \"%s\".\n"),
899 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
901 if (!target_can_lock_scheduler
)
903 scheduler_mode
= schedlock_off
;
904 error (_("Target '%s' cannot support this command."), target_shortname
);
909 /* Resume the inferior, but allow a QUIT. This is useful if the user
910 wants to interrupt some lengthy single-stepping operation
911 (for child processes, the SIGINT goes to the inferior, and so
912 we get a SIGINT random_signal, but for remote debugging and perhaps
913 other targets, that's not true).
915 STEP nonzero if we should step (zero to continue instead).
916 SIG is the signal to give the inferior (zero for none). */
918 resume (int step
, enum target_signal sig
)
920 int should_resume
= 1;
921 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
922 struct regcache
*regcache
= get_current_regcache ();
923 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
924 CORE_ADDR pc
= regcache_read_pc (regcache
);
928 fprintf_unfiltered (gdb_stdlog
,
929 "infrun: resume (step=%d, signal=%d), "
930 "stepping_over_breakpoint=%d\n",
931 step
, sig
, stepping_over_breakpoint
);
933 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
934 over an instruction that causes a page fault without triggering
935 a hardware watchpoint. The kernel properly notices that it shouldn't
936 stop, because the hardware watchpoint is not triggered, but it forgets
937 the step request and continues the program normally.
938 Work around the problem by removing hardware watchpoints if a step is
939 requested, GDB will check for a hardware watchpoint trigger after the
941 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
942 remove_hw_watchpoints ();
945 /* Normally, by the time we reach `resume', the breakpoints are either
946 removed or inserted, as appropriate. The exception is if we're sitting
947 at a permanent breakpoint; we need to step over it, but permanent
948 breakpoints can't be removed. So we have to test for it here. */
949 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
951 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
952 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
955 The program is stopped at a permanent breakpoint, but GDB does not know\n\
956 how to step past a permanent breakpoint on this architecture. Try using\n\
957 a command like `return' or `jump' to continue execution."));
960 /* If enabled, step over breakpoints by executing a copy of the
961 instruction at a different address.
963 We can't use displaced stepping when we have a signal to deliver;
964 the comments for displaced_step_prepare explain why. The
965 comments in the handle_inferior event for dealing with 'random
966 signals' explain what we do instead. */
967 if (use_displaced_stepping (gdbarch
)
968 && stepping_over_breakpoint
969 && sig
== TARGET_SIGNAL_0
)
971 if (!displaced_step_prepare (inferior_ptid
))
972 /* Got placed in displaced stepping queue. Will be resumed
973 later when all the currently queued displaced stepping
978 if (step
&& gdbarch_software_single_step_p (gdbarch
))
980 /* Do it the hard way, w/temp breakpoints */
981 if (gdbarch_software_single_step (gdbarch
, get_current_frame ()))
983 /* ...and don't ask hardware to do it. */
985 /* and do not pull these breakpoints until after a `wait' in
986 `wait_for_inferior' */
987 singlestep_breakpoints_inserted_p
= 1;
988 singlestep_ptid
= inferior_ptid
;
993 /* If there were any forks/vforks/execs that were caught and are
994 now to be followed, then do so. */
995 switch (pending_follow
.kind
)
997 case TARGET_WAITKIND_FORKED
:
998 case TARGET_WAITKIND_VFORKED
:
999 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
1004 case TARGET_WAITKIND_EXECD
:
1005 /* follow_exec is called as soon as the exec event is seen. */
1006 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
1013 /* Install inferior's terminal modes. */
1014 target_terminal_inferior ();
1020 resume_ptid
= RESUME_ALL
; /* Default */
1022 /* If STEP is set, it's a request to use hardware stepping
1023 facilities. But in that case, we should never
1024 use singlestep breakpoint. */
1025 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
1027 if (singlestep_breakpoints_inserted_p
1028 && stepping_past_singlestep_breakpoint
)
1030 /* The situation here is as follows. In thread T1 we wanted to
1031 single-step. Lacking hardware single-stepping we've
1032 set breakpoint at the PC of the next instruction -- call it
1033 P. After resuming, we've hit that breakpoint in thread T2.
1034 Now we've removed original breakpoint, inserted breakpoint
1035 at P+1, and try to step to advance T2 past breakpoint.
1036 We need to step only T2, as if T1 is allowed to freely run,
1037 it can run past P, and if other threads are allowed to run,
1038 they can hit breakpoint at P+1, and nested hits of single-step
1039 breakpoints is not something we'd want -- that's complicated
1040 to support, and has no value. */
1041 resume_ptid
= inferior_ptid
;
1044 if ((step
|| singlestep_breakpoints_inserted_p
)
1045 && stepping_over_breakpoint
)
1047 /* We're allowing a thread to run past a breakpoint it has
1048 hit, by single-stepping the thread with the breakpoint
1049 removed. In which case, we need to single-step only this
1050 thread, and keep others stopped, as they can miss this
1051 breakpoint if allowed to run.
1053 The current code actually removes all breakpoints when
1054 doing this, not just the one being stepped over, so if we
1055 let other threads run, we can actually miss any
1056 breakpoint, not just the one at PC. */
1057 resume_ptid
= inferior_ptid
;
1062 /* With non-stop mode on, threads are always handled
1064 resume_ptid
= inferior_ptid
;
1066 else if ((scheduler_mode
== schedlock_on
)
1067 || (scheduler_mode
== schedlock_step
1068 && (step
|| singlestep_breakpoints_inserted_p
)))
1070 /* User-settable 'scheduler' mode requires solo thread resume. */
1071 resume_ptid
= inferior_ptid
;
1074 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1076 /* Most targets can step a breakpoint instruction, thus
1077 executing it normally. But if this one cannot, just
1078 continue and we will hit it anyway. */
1079 if (step
&& breakpoint_inserted_here_p (pc
))
1084 && use_displaced_stepping (gdbarch
)
1085 && stepping_over_breakpoint
)
1087 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1088 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1091 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
1092 paddr_nz (actual_pc
));
1093 read_memory (actual_pc
, buf
, sizeof (buf
));
1094 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1097 target_resume (resume_ptid
, step
, sig
);
1100 discard_cleanups (old_cleanups
);
1105 /* Clear out all variables saying what to do when inferior is continued.
1106 First do this, then set the ones you want, then call `proceed'. */
1109 clear_proceed_status (void)
1111 stepping_over_breakpoint
= 0;
1112 step_range_start
= 0;
1114 step_frame_id
= null_frame_id
;
1115 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1116 stop_after_trap
= 0;
1117 stop_soon
= NO_STOP_QUIETLY
;
1118 proceed_to_finish
= 0;
1119 breakpoint_proceeded
= 1; /* We're about to proceed... */
1123 regcache_xfree (stop_registers
);
1124 stop_registers
= NULL
;
1127 /* Discard any remaining commands or status from previous stop. */
1128 bpstat_clear (&stop_bpstat
);
1131 /* This should be suitable for any targets that support threads. */
1134 prepare_to_proceed (int step
)
1137 struct target_waitstatus wait_status
;
1139 /* Get the last target status returned by target_wait(). */
1140 get_last_target_status (&wait_ptid
, &wait_status
);
1142 /* Make sure we were stopped at a breakpoint. */
1143 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1144 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1149 /* Switched over from WAIT_PID. */
1150 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1151 && !ptid_equal (inferior_ptid
, wait_ptid
))
1153 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1155 if (breakpoint_here_p (regcache_read_pc (regcache
)))
1157 /* If stepping, remember current thread to switch back to. */
1159 deferred_step_ptid
= inferior_ptid
;
1161 /* Switch back to WAIT_PID thread. */
1162 switch_to_thread (wait_ptid
);
1164 /* We return 1 to indicate that there is a breakpoint here,
1165 so we need to step over it before continuing to avoid
1166 hitting it straight away. */
1174 /* Record the pc of the program the last time it stopped. This is
1175 just used internally by wait_for_inferior, but need to be preserved
1176 over calls to it and cleared when the inferior is started. */
1177 static CORE_ADDR prev_pc
;
1179 /* Basic routine for continuing the program in various fashions.
1181 ADDR is the address to resume at, or -1 for resume where stopped.
1182 SIGGNAL is the signal to give it, or 0 for none,
1183 or -1 for act according to how it stopped.
1184 STEP is nonzero if should trap after one instruction.
1185 -1 means return after that and print nothing.
1186 You should probably set various step_... variables
1187 before calling here, if you are stepping.
1189 You should call clear_proceed_status before calling proceed. */
1192 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1194 struct regcache
*regcache
= get_current_regcache ();
1195 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1196 CORE_ADDR pc
= regcache_read_pc (regcache
);
1200 step_start_function
= find_pc_function (pc
);
1202 stop_after_trap
= 1;
1204 if (addr
== (CORE_ADDR
) -1)
1206 if (pc
== stop_pc
&& breakpoint_here_p (pc
))
1207 /* There is a breakpoint at the address we will resume at,
1208 step one instruction before inserting breakpoints so that
1209 we do not stop right away (and report a second hit at this
1212 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1213 && gdbarch_single_step_through_delay (gdbarch
,
1214 get_current_frame ()))
1215 /* We stepped onto an instruction that needs to be stepped
1216 again before re-inserting the breakpoint, do so. */
1221 regcache_write_pc (regcache
, addr
);
1225 fprintf_unfiltered (gdb_stdlog
,
1226 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1227 paddr_nz (addr
), siggnal
, step
);
1230 /* In non-stop, each thread is handled individually. The context
1231 must already be set to the right thread here. */
1235 /* In a multi-threaded task we may select another thread and
1236 then continue or step.
1238 But if the old thread was stopped at a breakpoint, it will
1239 immediately cause another breakpoint stop without any
1240 execution (i.e. it will report a breakpoint hit incorrectly).
1241 So we must step over it first.
1243 prepare_to_proceed checks the current thread against the
1244 thread that reported the most recent event. If a step-over
1245 is required it returns TRUE and sets the current thread to
1247 if (prepare_to_proceed (step
))
1253 stepping_over_breakpoint
= 1;
1254 /* If displaced stepping is enabled, we can step over the
1255 breakpoint without hitting it, so leave all breakpoints
1256 inserted. Otherwise we need to disable all breakpoints, step
1257 one instruction, and then re-add them when that step is
1259 if (!use_displaced_stepping (gdbarch
))
1260 remove_breakpoints ();
1263 /* We can insert breakpoints if we're not trying to step over one,
1264 or if we are stepping over one but we're using displaced stepping
1266 if (! stepping_over_breakpoint
|| use_displaced_stepping (gdbarch
))
1267 insert_breakpoints ();
1269 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1270 stop_signal
= siggnal
;
1271 /* If this signal should not be seen by program,
1272 give it zero. Used for debugging signals. */
1273 else if (!signal_program
[stop_signal
])
1274 stop_signal
= TARGET_SIGNAL_0
;
1276 annotate_starting ();
1278 /* Make sure that output from GDB appears before output from the
1280 gdb_flush (gdb_stdout
);
1282 /* Refresh prev_pc value just prior to resuming. This used to be
1283 done in stop_stepping, however, setting prev_pc there did not handle
1284 scenarios such as inferior function calls or returning from
1285 a function via the return command. In those cases, the prev_pc
1286 value was not set properly for subsequent commands. The prev_pc value
1287 is used to initialize the starting line number in the ecs. With an
1288 invalid value, the gdb next command ends up stopping at the position
1289 represented by the next line table entry past our start position.
1290 On platforms that generate one line table entry per line, this
1291 is not a problem. However, on the ia64, the compiler generates
1292 extraneous line table entries that do not increase the line number.
1293 When we issue the gdb next command on the ia64 after an inferior call
1294 or a return command, we often end up a few instructions forward, still
1295 within the original line we started.
1297 An attempt was made to have init_execution_control_state () refresh
1298 the prev_pc value before calculating the line number. This approach
1299 did not work because on platforms that use ptrace, the pc register
1300 cannot be read unless the inferior is stopped. At that point, we
1301 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1302 call can fail. Setting the prev_pc value here ensures the value is
1303 updated correctly when the inferior is stopped. */
1304 prev_pc
= regcache_read_pc (get_current_regcache ());
1306 /* Fill in with reasonable starting values. */
1307 init_thread_stepping_state (tss
);
1309 /* We'll update this if & when we switch to a new thread. */
1310 previous_inferior_ptid
= inferior_ptid
;
1312 /* Reset to normal state. */
1313 init_infwait_state ();
1315 /* Resume inferior. */
1316 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1318 /* Wait for it to stop (if not standalone)
1319 and in any case decode why it stopped, and act accordingly. */
1320 /* Do this only if we are not using the event loop, or if the target
1321 does not support asynchronous execution. */
1322 if (!target_can_async_p ())
1324 wait_for_inferior (0);
1330 /* Start remote-debugging of a machine over a serial link. */
1333 start_remote (int from_tty
)
1335 init_wait_for_inferior ();
1336 stop_soon
= STOP_QUIETLY_REMOTE
;
1337 stepping_over_breakpoint
= 0;
1339 /* Always go on waiting for the target, regardless of the mode. */
1340 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1341 indicate to wait_for_inferior that a target should timeout if
1342 nothing is returned (instead of just blocking). Because of this,
1343 targets expecting an immediate response need to, internally, set
1344 things up so that the target_wait() is forced to eventually
1346 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1347 differentiate to its caller what the state of the target is after
1348 the initial open has been performed. Here we're assuming that
1349 the target has stopped. It should be possible to eventually have
1350 target_open() return to the caller an indication that the target
1351 is currently running and GDB state should be set to the same as
1352 for an async run. */
1353 wait_for_inferior (0);
1355 /* Now that the inferior has stopped, do any bookkeeping like
1356 loading shared libraries. We want to do this before normal_stop,
1357 so that the displayed frame is up to date. */
1358 post_create_inferior (¤t_target
, from_tty
);
1363 /* Initialize static vars when a new inferior begins. */
1366 init_wait_for_inferior (void)
1368 /* These are meaningless until the first time through wait_for_inferior. */
1371 breakpoint_init_inferior (inf_starting
);
1373 /* Don't confuse first call to proceed(). */
1374 stop_signal
= TARGET_SIGNAL_0
;
1376 /* The first resume is not following a fork/vfork/exec. */
1377 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1379 clear_proceed_status ();
1381 stepping_past_singlestep_breakpoint
= 0;
1382 deferred_step_ptid
= null_ptid
;
1384 target_last_wait_ptid
= minus_one_ptid
;
1386 init_thread_stepping_state (tss
);
1387 previous_inferior_ptid
= null_ptid
;
1388 init_infwait_state ();
1390 displaced_step_clear ();
1394 /* This enum encodes possible reasons for doing a target_wait, so that
1395 wfi can call target_wait in one place. (Ultimately the call will be
1396 moved out of the infinite loop entirely.) */
1400 infwait_normal_state
,
1401 infwait_thread_hop_state
,
1402 infwait_step_watch_state
,
1403 infwait_nonstep_watch_state
1406 /* Why did the inferior stop? Used to print the appropriate messages
1407 to the interface from within handle_inferior_event(). */
1408 enum inferior_stop_reason
1410 /* Step, next, nexti, stepi finished. */
1412 /* Inferior terminated by signal. */
1414 /* Inferior exited. */
1416 /* Inferior received signal, and user asked to be notified. */
1420 /* The PTID we'll do a target_wait on.*/
1423 /* Current inferior wait state. */
1424 enum infwait_states infwait_state
;
1426 /* Data to be passed around while handling an event. This data is
1427 discarded between events. */
1428 struct execution_control_state
1431 struct target_waitstatus ws
;
1433 CORE_ADDR stop_func_start
;
1434 CORE_ADDR stop_func_end
;
1435 char *stop_func_name
;
1436 int new_thread_event
;
1440 void init_execution_control_state (struct execution_control_state
*ecs
);
1442 void handle_inferior_event (struct execution_control_state
*ecs
);
1444 static void step_into_function (struct execution_control_state
*ecs
);
1445 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1446 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1447 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
1448 struct frame_id sr_id
);
1449 static void insert_longjmp_resume_breakpoint (CORE_ADDR
);
1451 static void stop_stepping (struct execution_control_state
*ecs
);
1452 static void prepare_to_wait (struct execution_control_state
*ecs
);
1453 static void keep_going (struct execution_control_state
*ecs
);
1454 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1457 /* Wait for control to return from inferior to debugger.
1459 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1460 as if they were SIGTRAP signals. This can be useful during
1461 the startup sequence on some targets such as HP/UX, where
1462 we receive an EXEC event instead of the expected SIGTRAP.
1464 If inferior gets a signal, we may decide to start it up again
1465 instead of returning. That is why there is a loop in this function.
1466 When this function actually returns it means the inferior
1467 should be left stopped and GDB should read more commands. */
1470 wait_for_inferior (int treat_exec_as_sigtrap
)
1472 struct cleanup
*old_cleanups
;
1473 struct execution_control_state ecss
;
1474 struct execution_control_state
*ecs
;
1478 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1479 treat_exec_as_sigtrap
);
1481 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1482 &step_resume_breakpoint
);
1485 memset (ecs
, 0, sizeof (*ecs
));
1487 overlay_cache_invalid
= 1;
1489 /* We have to invalidate the registers BEFORE calling target_wait
1490 because they can be loaded from the target while in target_wait.
1491 This makes remote debugging a bit more efficient for those
1492 targets that provide critical registers as part of their normal
1493 status mechanism. */
1495 registers_changed ();
1499 if (deprecated_target_wait_hook
)
1500 ecs
->ptid
= deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1502 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1504 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1506 xfree (ecs
->ws
.value
.execd_pathname
);
1507 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1508 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
1511 /* Now figure out what to do with the result of the result. */
1512 handle_inferior_event (ecs
);
1514 if (!ecs
->wait_some_more
)
1517 do_cleanups (old_cleanups
);
1520 /* Asynchronous version of wait_for_inferior. It is called by the
1521 event loop whenever a change of state is detected on the file
1522 descriptor corresponding to the target. It can be called more than
1523 once to complete a single execution command. In such cases we need
1524 to keep the state in a global variable ECSS. If it is the last time
1525 that this function is called for a single execution command, then
1526 report to the user that the inferior has stopped, and do the
1527 necessary cleanups. */
1530 fetch_inferior_event (void *client_data
)
1532 struct execution_control_state ecss
;
1533 struct execution_control_state
*ecs
= &ecss
;
1534 struct cleanup
*old_chain
= make_cleanup (null_cleanup
, NULL
);
1535 int was_sync
= sync_execution
;
1537 memset (ecs
, 0, sizeof (*ecs
));
1539 overlay_cache_invalid
= 1;
1542 /* In non-stop mode, the user/frontend should not notice a thread
1543 switch due to internal events. Make sure we reverse to the
1544 user selected thread and frame after handling the event and
1545 running any breakpoint commands. */
1546 make_cleanup_restore_current_thread ();
1548 /* We have to invalidate the registers BEFORE calling target_wait
1549 because they can be loaded from the target while in target_wait.
1550 This makes remote debugging a bit more efficient for those
1551 targets that provide critical registers as part of their normal
1552 status mechanism. */
1554 registers_changed ();
1556 if (deprecated_target_wait_hook
)
1558 deprecated_target_wait_hook (waiton_ptid
, &ecs
->ws
);
1560 ecs
->ptid
= target_wait (waiton_ptid
, &ecs
->ws
);
1563 && ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
1564 && ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1565 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
)
1566 /* In non-stop mode, each thread is handled individually. Switch
1567 early, so the global state is set correctly for this
1569 context_switch (ecs
->ptid
);
1571 /* Now figure out what to do with the result of the result. */
1572 handle_inferior_event (ecs
);
1574 if (!ecs
->wait_some_more
)
1576 delete_step_resume_breakpoint (&step_resume_breakpoint
);
1579 if (step_multi
&& stop_step
)
1580 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1582 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1585 /* Revert thread and frame. */
1586 do_cleanups (old_chain
);
1588 /* If the inferior was in sync execution mode, and now isn't,
1589 restore the prompt. */
1590 if (was_sync
&& !sync_execution
)
1591 display_gdb_prompt (0);
1594 /* Prepare an execution control state for looping through a
1595 wait_for_inferior-type loop. */
1598 init_execution_control_state (struct execution_control_state
*ecs
)
1600 ecs
->random_signal
= 0;
1603 /* Clear context switchable stepping state. */
1606 init_thread_stepping_state (struct thread_stepping_state
*tss
)
1608 tss
->stepping_over_breakpoint
= 0;
1609 tss
->step_after_step_resume_breakpoint
= 0;
1610 tss
->stepping_through_solib_after_catch
= 0;
1611 tss
->stepping_through_solib_catchpoints
= NULL
;
1612 tss
->sal
= find_pc_line (prev_pc
, 0);
1613 tss
->current_line
= tss
->sal
.line
;
1614 tss
->current_symtab
= tss
->sal
.symtab
;
1617 /* Return the cached copy of the last pid/waitstatus returned by
1618 target_wait()/deprecated_target_wait_hook(). The data is actually
1619 cached by handle_inferior_event(), which gets called immediately
1620 after target_wait()/deprecated_target_wait_hook(). */
1623 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1625 *ptidp
= target_last_wait_ptid
;
1626 *status
= target_last_waitstatus
;
1630 nullify_last_target_wait_ptid (void)
1632 target_last_wait_ptid
= minus_one_ptid
;
1635 /* Switch thread contexts, maintaining "infrun state". */
1638 context_switch (ptid_t ptid
)
1640 /* Caution: it may happen that the new thread (or the old one!)
1641 is not in the thread list. In this case we must not attempt
1642 to "switch context", or we run the risk that our context may
1643 be lost. This may happen as a result of the target module
1644 mishandling thread creation. */
1648 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
1649 target_pid_to_str (inferior_ptid
));
1650 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
1651 target_pid_to_str (ptid
));
1654 if (in_thread_list (inferior_ptid
) && in_thread_list (ptid
))
1655 { /* Perform infrun state context switch: */
1656 /* Save infrun state for the old thread. */
1657 save_infrun_state (inferior_ptid
, prev_pc
,
1658 stepping_over_breakpoint
, step_resume_breakpoint
,
1660 step_range_end
, &step_frame_id
,
1661 tss
->stepping_over_breakpoint
,
1662 tss
->stepping_through_solib_after_catch
,
1663 tss
->stepping_through_solib_catchpoints
,
1664 tss
->current_line
, tss
->current_symtab
,
1665 cmd_continuation
, intermediate_continuation
,
1673 /* Load infrun state for the new thread. */
1674 load_infrun_state (ptid
, &prev_pc
,
1675 &stepping_over_breakpoint
, &step_resume_breakpoint
,
1677 &step_range_end
, &step_frame_id
,
1678 &tss
->stepping_over_breakpoint
,
1679 &tss
->stepping_through_solib_after_catch
,
1680 &tss
->stepping_through_solib_catchpoints
,
1681 &tss
->current_line
, &tss
->current_symtab
,
1682 &cmd_continuation
, &intermediate_continuation
,
1691 switch_to_thread (ptid
);
1694 /* Context switch to thread PTID. */
1696 context_switch_to (ptid_t ptid
)
1698 ptid_t current_ptid
= inferior_ptid
;
1700 /* Context switch to the new thread. */
1701 if (!ptid_equal (ptid
, inferior_ptid
))
1703 context_switch (ptid
);
1705 return current_ptid
;
1709 adjust_pc_after_break (struct execution_control_state
*ecs
)
1711 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
1712 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1713 CORE_ADDR breakpoint_pc
;
1715 /* If this target does not decrement the PC after breakpoints, then
1716 we have nothing to do. */
1717 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
1720 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1721 we aren't, just return.
1723 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1724 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1725 implemented by software breakpoints should be handled through the normal
1728 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1729 different signals (SIGILL or SIGEMT for instance), but it is less
1730 clear where the PC is pointing afterwards. It may not match
1731 gdbarch_decr_pc_after_break. I don't know any specific target that
1732 generates these signals at breakpoints (the code has been in GDB since at
1733 least 1992) so I can not guess how to handle them here.
1735 In earlier versions of GDB, a target with
1736 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1737 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1738 target with both of these set in GDB history, and it seems unlikely to be
1739 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1741 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
1744 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1747 /* Find the location where (if we've hit a breakpoint) the
1748 breakpoint would be. */
1749 breakpoint_pc
= regcache_read_pc (regcache
)
1750 - gdbarch_decr_pc_after_break (gdbarch
);
1752 /* Check whether there actually is a software breakpoint inserted
1753 at that location. */
1754 if (software_breakpoint_inserted_here_p (breakpoint_pc
))
1756 /* When using hardware single-step, a SIGTRAP is reported for both
1757 a completed single-step and a software breakpoint. Need to
1758 differentiate between the two, as the latter needs adjusting
1759 but the former does not.
1761 The SIGTRAP can be due to a completed hardware single-step only if
1762 - we didn't insert software single-step breakpoints
1763 - the thread to be examined is still the current thread
1764 - this thread is currently being stepped
1766 If any of these events did not occur, we must have stopped due
1767 to hitting a software breakpoint, and have to back up to the
1770 As a special case, we could have hardware single-stepped a
1771 software breakpoint. In this case (prev_pc == breakpoint_pc),
1772 we also need to back up to the breakpoint address. */
1774 if (singlestep_breakpoints_inserted_p
1775 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
1776 || !currently_stepping (tss
)
1777 || prev_pc
== breakpoint_pc
)
1778 regcache_write_pc (regcache
, breakpoint_pc
);
1783 init_infwait_state (void)
1785 waiton_ptid
= pid_to_ptid (-1);
1786 infwait_state
= infwait_normal_state
;
1790 error_is_running (void)
1793 Cannot execute this command while the selected thread is running."));
1797 ensure_not_running (void)
1799 if (is_running (inferior_ptid
))
1800 error_is_running ();
1803 /* Given an execution control state that has been freshly filled in
1804 by an event from the inferior, figure out what it means and take
1805 appropriate action. */
1808 handle_inferior_event (struct execution_control_state
*ecs
)
1810 int sw_single_step_trap_p
= 0;
1811 int stopped_by_watchpoint
;
1812 int stepped_after_stopped_by_watchpoint
= 0;
1814 breakpoint_retire_moribund ();
1816 /* Cache the last pid/waitstatus. */
1817 target_last_wait_ptid
= ecs
->ptid
;
1818 target_last_waitstatus
= ecs
->ws
;
1820 /* Always clear state belonging to the previous time we stopped. */
1821 stop_stack_dummy
= 0;
1823 adjust_pc_after_break (ecs
);
1825 switch (infwait_state
)
1827 case infwait_thread_hop_state
:
1829 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
1830 /* Cancel the waiton_ptid. */
1831 waiton_ptid
= pid_to_ptid (-1);
1834 case infwait_normal_state
:
1836 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
1839 case infwait_step_watch_state
:
1841 fprintf_unfiltered (gdb_stdlog
,
1842 "infrun: infwait_step_watch_state\n");
1844 stepped_after_stopped_by_watchpoint
= 1;
1847 case infwait_nonstep_watch_state
:
1849 fprintf_unfiltered (gdb_stdlog
,
1850 "infrun: infwait_nonstep_watch_state\n");
1851 insert_breakpoints ();
1853 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1854 handle things like signals arriving and other things happening
1855 in combination correctly? */
1856 stepped_after_stopped_by_watchpoint
= 1;
1860 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1862 infwait_state
= infwait_normal_state
;
1864 reinit_frame_cache ();
1866 /* If it's a new process, add it to the thread database */
1868 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1869 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
1870 && !in_thread_list (ecs
->ptid
));
1872 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1873 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1874 add_thread (ecs
->ptid
);
1876 if (ecs
->ws
.kind
!= TARGET_WAITKIND_IGNORE
)
1878 /* Mark the non-executing threads accordingly. */
1880 || ecs
->ws
.kind
== TARGET_WAITKIND_EXITED
1881 || ecs
->ws
.kind
== TARGET_WAITKIND_SIGNALLED
)
1882 set_executing (pid_to_ptid (-1), 0);
1884 set_executing (ecs
->ptid
, 0);
1887 switch (ecs
->ws
.kind
)
1889 case TARGET_WAITKIND_LOADED
:
1891 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
1892 /* Ignore gracefully during startup of the inferior, as it might
1893 be the shell which has just loaded some objects, otherwise
1894 add the symbols for the newly loaded objects. Also ignore at
1895 the beginning of an attach or remote session; we will query
1896 the full list of libraries once the connection is
1898 if (stop_soon
== NO_STOP_QUIETLY
)
1900 /* Check for any newly added shared libraries if we're
1901 supposed to be adding them automatically. Switch
1902 terminal for any messages produced by
1903 breakpoint_re_set. */
1904 target_terminal_ours_for_output ();
1905 /* NOTE: cagney/2003-11-25: Make certain that the target
1906 stack's section table is kept up-to-date. Architectures,
1907 (e.g., PPC64), use the section table to perform
1908 operations such as address => section name and hence
1909 require the table to contain all sections (including
1910 those found in shared libraries). */
1911 /* NOTE: cagney/2003-11-25: Pass current_target and not
1912 exec_ops to SOLIB_ADD. This is because current GDB is
1913 only tooled to propagate section_table changes out from
1914 the "current_target" (see target_resize_to_sections), and
1915 not up from the exec stratum. This, of course, isn't
1916 right. "infrun.c" should only interact with the
1917 exec/process stratum, instead relying on the target stack
1918 to propagate relevant changes (stop, section table
1919 changed, ...) up to other layers. */
1921 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
1923 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
1925 target_terminal_inferior ();
1927 /* If requested, stop when the dynamic linker notifies
1928 gdb of events. This allows the user to get control
1929 and place breakpoints in initializer routines for
1930 dynamically loaded objects (among other things). */
1931 if (stop_on_solib_events
)
1933 stop_stepping (ecs
);
1937 /* NOTE drow/2007-05-11: This might be a good place to check
1938 for "catch load". */
1941 /* If we are skipping through a shell, or through shared library
1942 loading that we aren't interested in, resume the program. If
1943 we're running the program normally, also resume. But stop if
1944 we're attaching or setting up a remote connection. */
1945 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
1947 /* Loading of shared libraries might have changed breakpoint
1948 addresses. Make sure new breakpoints are inserted. */
1949 if (stop_soon
== NO_STOP_QUIETLY
1950 && !breakpoints_always_inserted_mode ())
1951 insert_breakpoints ();
1952 resume (0, TARGET_SIGNAL_0
);
1953 prepare_to_wait (ecs
);
1959 case TARGET_WAITKIND_SPURIOUS
:
1961 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
1962 resume (0, TARGET_SIGNAL_0
);
1963 prepare_to_wait (ecs
);
1966 case TARGET_WAITKIND_EXITED
:
1968 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
1969 target_terminal_ours (); /* Must do this before mourn anyway */
1970 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1972 /* Record the exit code in the convenience variable $_exitcode, so
1973 that the user can inspect this again later. */
1974 set_internalvar (lookup_internalvar ("_exitcode"),
1975 value_from_longest (builtin_type_int
,
1976 (LONGEST
) ecs
->ws
.value
.integer
));
1977 gdb_flush (gdb_stdout
);
1978 target_mourn_inferior ();
1979 singlestep_breakpoints_inserted_p
= 0;
1980 stop_print_frame
= 0;
1981 stop_stepping (ecs
);
1984 case TARGET_WAITKIND_SIGNALLED
:
1986 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
1987 stop_print_frame
= 0;
1988 stop_signal
= ecs
->ws
.value
.sig
;
1989 target_terminal_ours (); /* Must do this before mourn anyway */
1991 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1992 reach here unless the inferior is dead. However, for years
1993 target_kill() was called here, which hints that fatal signals aren't
1994 really fatal on some systems. If that's true, then some changes
1996 target_mourn_inferior ();
1998 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1999 singlestep_breakpoints_inserted_p
= 0;
2000 stop_stepping (ecs
);
2003 /* The following are the only cases in which we keep going;
2004 the above cases end in a continue or goto. */
2005 case TARGET_WAITKIND_FORKED
:
2006 case TARGET_WAITKIND_VFORKED
:
2008 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
2009 stop_signal
= TARGET_SIGNAL_TRAP
;
2010 pending_follow
.kind
= ecs
->ws
.kind
;
2012 pending_follow
.fork_event
.parent_pid
= ecs
->ptid
;
2013 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
2015 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2017 context_switch (ecs
->ptid
);
2018 reinit_frame_cache ();
2021 stop_pc
= read_pc ();
2023 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2025 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2027 /* If no catchpoint triggered for this, then keep going. */
2028 if (ecs
->random_signal
)
2030 stop_signal
= TARGET_SIGNAL_0
;
2034 goto process_event_stop_test
;
2036 case TARGET_WAITKIND_EXECD
:
2038 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
2039 stop_signal
= TARGET_SIGNAL_TRAP
;
2041 pending_follow
.execd_pathname
=
2042 savestring (ecs
->ws
.value
.execd_pathname
,
2043 strlen (ecs
->ws
.value
.execd_pathname
));
2045 /* This causes the eventpoints and symbol table to be reset. Must
2046 do this now, before trying to determine whether to stop. */
2047 follow_exec (inferior_ptid
, pending_follow
.execd_pathname
);
2048 xfree (pending_follow
.execd_pathname
);
2050 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2053 /* The breakpoints module may need to touch the inferior's
2054 memory. Switch to the (stopped) event ptid
2056 ptid_t saved_inferior_ptid
= inferior_ptid
;
2057 inferior_ptid
= ecs
->ptid
;
2059 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2061 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2062 inferior_ptid
= saved_inferior_ptid
;
2065 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2067 context_switch (ecs
->ptid
);
2068 reinit_frame_cache ();
2071 /* If no catchpoint triggered for this, then keep going. */
2072 if (ecs
->random_signal
)
2074 stop_signal
= TARGET_SIGNAL_0
;
2078 goto process_event_stop_test
;
2080 /* Be careful not to try to gather much state about a thread
2081 that's in a syscall. It's frequently a losing proposition. */
2082 case TARGET_WAITKIND_SYSCALL_ENTRY
:
2084 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
2085 resume (0, TARGET_SIGNAL_0
);
2086 prepare_to_wait (ecs
);
2089 /* Before examining the threads further, step this thread to
2090 get it entirely out of the syscall. (We get notice of the
2091 event when the thread is just on the verge of exiting a
2092 syscall. Stepping one instruction seems to get it back
2094 case TARGET_WAITKIND_SYSCALL_RETURN
:
2096 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
2097 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
2098 prepare_to_wait (ecs
);
2101 case TARGET_WAITKIND_STOPPED
:
2103 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
2104 stop_signal
= ecs
->ws
.value
.sig
;
2107 /* We had an event in the inferior, but we are not interested
2108 in handling it at this level. The lower layers have already
2109 done what needs to be done, if anything.
2111 One of the possible circumstances for this is when the
2112 inferior produces output for the console. The inferior has
2113 not stopped, and we are ignoring the event. Another possible
2114 circumstance is any event which the lower level knows will be
2115 reported multiple times without an intervening resume. */
2116 case TARGET_WAITKIND_IGNORE
:
2118 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
2119 prepare_to_wait (ecs
);
2123 if (ecs
->new_thread_event
)
2126 /* Non-stop assumes that the target handles adding new threads
2127 to the thread list. */
2128 internal_error (__FILE__
, __LINE__
, "\
2129 targets should add new threads to the thread list themselves in non-stop mode.");
2131 /* We may want to consider not doing a resume here in order to
2132 give the user a chance to play with the new thread. It might
2133 be good to make that a user-settable option. */
2135 /* At this point, all threads are stopped (happens automatically
2136 in either the OS or the native code). Therefore we need to
2137 continue all threads in order to make progress. */
2139 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
2140 prepare_to_wait (ecs
);
2144 /* Do we need to clean up the state of a thread that has completed a
2145 displaced single-step? (Doing so usually affects the PC, so do
2146 it here, before we set stop_pc.) */
2147 displaced_step_fixup (ecs
->ptid
, stop_signal
);
2149 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2153 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n",
2154 paddr_nz (stop_pc
));
2155 if (STOPPED_BY_WATCHPOINT (&ecs
->ws
))
2158 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2160 if (target_stopped_data_address (¤t_target
, &addr
))
2161 fprintf_unfiltered (gdb_stdlog
,
2162 "infrun: stopped data address = 0x%s\n",
2165 fprintf_unfiltered (gdb_stdlog
,
2166 "infrun: (no data address available)\n");
2170 if (stepping_past_singlestep_breakpoint
)
2172 gdb_assert (singlestep_breakpoints_inserted_p
);
2173 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2174 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2176 stepping_past_singlestep_breakpoint
= 0;
2178 /* We've either finished single-stepping past the single-step
2179 breakpoint, or stopped for some other reason. It would be nice if
2180 we could tell, but we can't reliably. */
2181 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2184 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2185 /* Pull the single step breakpoints out of the target. */
2186 remove_single_step_breakpoints ();
2187 singlestep_breakpoints_inserted_p
= 0;
2189 ecs
->random_signal
= 0;
2191 context_switch (saved_singlestep_ptid
);
2192 if (deprecated_context_hook
)
2193 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2195 resume (1, TARGET_SIGNAL_0
);
2196 prepare_to_wait (ecs
);
2201 stepping_past_singlestep_breakpoint
= 0;
2203 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2205 /* In non-stop mode, there's never a deferred_step_ptid set. */
2206 gdb_assert (!non_stop
);
2208 /* If we stopped for some other reason than single-stepping, ignore
2209 the fact that we were supposed to switch back. */
2210 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2213 fprintf_unfiltered (gdb_stdlog
,
2214 "infrun: handling deferred step\n");
2216 /* Pull the single step breakpoints out of the target. */
2217 if (singlestep_breakpoints_inserted_p
)
2219 remove_single_step_breakpoints ();
2220 singlestep_breakpoints_inserted_p
= 0;
2223 /* Note: We do not call context_switch at this point, as the
2224 context is already set up for stepping the original thread. */
2225 switch_to_thread (deferred_step_ptid
);
2226 deferred_step_ptid
= null_ptid
;
2227 /* Suppress spurious "Switching to ..." message. */
2228 previous_inferior_ptid
= inferior_ptid
;
2230 resume (1, TARGET_SIGNAL_0
);
2231 prepare_to_wait (ecs
);
2235 deferred_step_ptid
= null_ptid
;
2238 /* See if a thread hit a thread-specific breakpoint that was meant for
2239 another thread. If so, then step that thread past the breakpoint,
2242 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2244 int thread_hop_needed
= 0;
2246 /* Check if a regular breakpoint has been hit before checking
2247 for a potential single step breakpoint. Otherwise, GDB will
2248 not see this breakpoint hit when stepping onto breakpoints. */
2249 if (regular_breakpoint_inserted_here_p (stop_pc
))
2251 ecs
->random_signal
= 0;
2252 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2253 thread_hop_needed
= 1;
2255 else if (singlestep_breakpoints_inserted_p
)
2257 /* We have not context switched yet, so this should be true
2258 no matter which thread hit the singlestep breakpoint. */
2259 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2261 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2263 target_pid_to_str (ecs
->ptid
));
2265 ecs
->random_signal
= 0;
2266 /* The call to in_thread_list is necessary because PTIDs sometimes
2267 change when we go from single-threaded to multi-threaded. If
2268 the singlestep_ptid is still in the list, assume that it is
2269 really different from ecs->ptid. */
2270 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2271 && in_thread_list (singlestep_ptid
))
2273 /* If the PC of the thread we were trying to single-step
2274 has changed, discard this event (which we were going
2275 to ignore anyway), and pretend we saw that thread
2276 trap. This prevents us continuously moving the
2277 single-step breakpoint forward, one instruction at a
2278 time. If the PC has changed, then the thread we were
2279 trying to single-step has trapped or been signalled,
2280 but the event has not been reported to GDB yet.
2282 There might be some cases where this loses signal
2283 information, if a signal has arrived at exactly the
2284 same time that the PC changed, but this is the best
2285 we can do with the information available. Perhaps we
2286 should arrange to report all events for all threads
2287 when they stop, or to re-poll the remote looking for
2288 this particular thread (i.e. temporarily enable
2291 CORE_ADDR new_singlestep_pc
2292 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
2294 if (new_singlestep_pc
!= singlestep_pc
)
2297 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2298 " but expected thread advanced also\n");
2300 /* The current context still belongs to
2301 singlestep_ptid. Don't swap here, since that's
2302 the context we want to use. Just fudge our
2303 state and continue. */
2304 ecs
->ptid
= singlestep_ptid
;
2305 stop_pc
= new_singlestep_pc
;
2310 fprintf_unfiltered (gdb_stdlog
,
2311 "infrun: unexpected thread\n");
2313 thread_hop_needed
= 1;
2314 stepping_past_singlestep_breakpoint
= 1;
2315 saved_singlestep_ptid
= singlestep_ptid
;
2320 if (thread_hop_needed
)
2322 int remove_status
= 0;
2325 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2327 /* Saw a breakpoint, but it was hit by the wrong thread.
2330 if (singlestep_breakpoints_inserted_p
)
2332 /* Pull the single step breakpoints out of the target. */
2333 remove_single_step_breakpoints ();
2334 singlestep_breakpoints_inserted_p
= 0;
2337 /* If the arch can displace step, don't remove the
2339 if (!use_displaced_stepping (current_gdbarch
))
2340 remove_status
= remove_breakpoints ();
2342 /* Did we fail to remove breakpoints? If so, try
2343 to set the PC past the bp. (There's at least
2344 one situation in which we can fail to remove
2345 the bp's: On HP-UX's that use ttrace, we can't
2346 change the address space of a vforking child
2347 process until the child exits (well, okay, not
2348 then either :-) or execs. */
2349 if (remove_status
!= 0)
2350 error (_("Cannot step over breakpoint hit in wrong thread"));
2353 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2354 context_switch (ecs
->ptid
);
2358 /* Only need to require the next event from this
2359 thread in all-stop mode. */
2360 waiton_ptid
= ecs
->ptid
;
2361 infwait_state
= infwait_thread_hop_state
;
2364 tss
->stepping_over_breakpoint
= 1;
2366 registers_changed ();
2370 else if (singlestep_breakpoints_inserted_p
)
2372 sw_single_step_trap_p
= 1;
2373 ecs
->random_signal
= 0;
2377 ecs
->random_signal
= 1;
2379 /* See if something interesting happened to the non-current thread. If
2380 so, then switch to that thread. */
2381 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2384 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
2386 context_switch (ecs
->ptid
);
2388 if (deprecated_context_hook
)
2389 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2392 if (singlestep_breakpoints_inserted_p
)
2394 /* Pull the single step breakpoints out of the target. */
2395 remove_single_step_breakpoints ();
2396 singlestep_breakpoints_inserted_p
= 0;
2399 if (stepped_after_stopped_by_watchpoint
)
2400 stopped_by_watchpoint
= 0;
2402 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
2404 /* If necessary, step over this watchpoint. We'll be back to display
2406 if (stopped_by_watchpoint
2407 && (HAVE_STEPPABLE_WATCHPOINT
2408 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
2410 /* At this point, we are stopped at an instruction which has
2411 attempted to write to a piece of memory under control of
2412 a watchpoint. The instruction hasn't actually executed
2413 yet. If we were to evaluate the watchpoint expression
2414 now, we would get the old value, and therefore no change
2415 would seem to have occurred.
2417 In order to make watchpoints work `right', we really need
2418 to complete the memory write, and then evaluate the
2419 watchpoint expression. We do this by single-stepping the
2422 It may not be necessary to disable the watchpoint to stop over
2423 it. For example, the PA can (with some kernel cooperation)
2424 single step over a watchpoint without disabling the watchpoint.
2426 It is far more common to need to disable a watchpoint to step
2427 the inferior over it. If we have non-steppable watchpoints,
2428 we must disable the current watchpoint; it's simplest to
2429 disable all watchpoints and breakpoints. */
2431 if (!HAVE_STEPPABLE_WATCHPOINT
)
2432 remove_breakpoints ();
2433 registers_changed ();
2434 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2435 waiton_ptid
= ecs
->ptid
;
2436 if (HAVE_STEPPABLE_WATCHPOINT
)
2437 infwait_state
= infwait_step_watch_state
;
2439 infwait_state
= infwait_nonstep_watch_state
;
2440 prepare_to_wait (ecs
);
2444 ecs
->stop_func_start
= 0;
2445 ecs
->stop_func_end
= 0;
2446 ecs
->stop_func_name
= 0;
2447 /* Don't care about return value; stop_func_start and stop_func_name
2448 will both be 0 if it doesn't work. */
2449 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2450 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2451 ecs
->stop_func_start
2452 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
2453 tss
->stepping_over_breakpoint
= 0;
2454 bpstat_clear (&stop_bpstat
);
2456 stop_print_frame
= 1;
2457 ecs
->random_signal
= 0;
2458 stopped_by_random_signal
= 0;
2460 if (stop_signal
== TARGET_SIGNAL_TRAP
2461 && stepping_over_breakpoint
2462 && gdbarch_single_step_through_delay_p (current_gdbarch
)
2463 && currently_stepping (tss
))
2465 /* We're trying to step off a breakpoint. Turns out that we're
2466 also on an instruction that needs to be stepped multiple
2467 times before it's been fully executing. E.g., architectures
2468 with a delay slot. It needs to be stepped twice, once for
2469 the instruction and once for the delay slot. */
2470 int step_through_delay
2471 = gdbarch_single_step_through_delay (current_gdbarch
,
2472 get_current_frame ());
2473 if (debug_infrun
&& step_through_delay
)
2474 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
2475 if (step_range_end
== 0 && step_through_delay
)
2477 /* The user issued a continue when stopped at a breakpoint.
2478 Set up for another trap and get out of here. */
2479 tss
->stepping_over_breakpoint
= 1;
2483 else if (step_through_delay
)
2485 /* The user issued a step when stopped at a breakpoint.
2486 Maybe we should stop, maybe we should not - the delay
2487 slot *might* correspond to a line of source. In any
2488 case, don't decide that here, just set
2489 ecs->stepping_over_breakpoint, making sure we
2490 single-step again before breakpoints are re-inserted. */
2491 tss
->stepping_over_breakpoint
= 1;
2495 /* Look at the cause of the stop, and decide what to do.
2496 The alternatives are:
2497 1) stop_stepping and return; to really stop and return to the debugger,
2498 2) keep_going and return to start up again
2499 (set tss->stepping_over_breakpoint to 1 to single step once)
2500 3) set ecs->random_signal to 1, and the decision between 1 and 2
2501 will be made according to the signal handling tables. */
2503 /* First, distinguish signals caused by the debugger from signals
2504 that have to do with the program's own actions. Note that
2505 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2506 on the operating system version. Here we detect when a SIGILL or
2507 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2508 something similar for SIGSEGV, since a SIGSEGV will be generated
2509 when we're trying to execute a breakpoint instruction on a
2510 non-executable stack. This happens for call dummy breakpoints
2511 for architectures like SPARC that place call dummies on the
2514 If we're doing a displaced step past a breakpoint, then the
2515 breakpoint is always inserted at the original instruction;
2516 non-standard signals can't be explained by the breakpoint. */
2517 if (stop_signal
== TARGET_SIGNAL_TRAP
2518 || (! stepping_over_breakpoint
2519 && breakpoint_inserted_here_p (stop_pc
)
2520 && (stop_signal
== TARGET_SIGNAL_ILL
2521 || stop_signal
== TARGET_SIGNAL_SEGV
2522 || stop_signal
== TARGET_SIGNAL_EMT
))
2523 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2524 || stop_soon
== STOP_QUIETLY_REMOTE
)
2526 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2529 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
2530 stop_print_frame
= 0;
2531 stop_stepping (ecs
);
2535 /* This is originated from start_remote(), start_inferior() and
2536 shared libraries hook functions. */
2537 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
2540 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
2541 stop_stepping (ecs
);
2545 /* This originates from attach_command(). We need to overwrite
2546 the stop_signal here, because some kernels don't ignore a
2547 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2548 See more comments in inferior.h. On the other hand, if we
2549 get a non-SIGSTOP, report it to the user - assume the backend
2550 will handle the SIGSTOP if it should show up later. */
2551 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2552 && stop_signal
== TARGET_SIGNAL_STOP
)
2554 stop_stepping (ecs
);
2555 stop_signal
= TARGET_SIGNAL_0
;
2559 /* See if there is a breakpoint at the current PC. */
2560 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2562 /* Following in case break condition called a
2564 stop_print_frame
= 1;
2566 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2567 at one stage in the past included checks for an inferior
2568 function call's call dummy's return breakpoint. The original
2569 comment, that went with the test, read:
2571 ``End of a stack dummy. Some systems (e.g. Sony news) give
2572 another signal besides SIGTRAP, so check here as well as
2575 If someone ever tries to get get call dummys on a
2576 non-executable stack to work (where the target would stop
2577 with something like a SIGSEGV), then those tests might need
2578 to be re-instated. Given, however, that the tests were only
2579 enabled when momentary breakpoints were not being used, I
2580 suspect that it won't be the case.
2582 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2583 be necessary for call dummies on a non-executable stack on
2586 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2588 = !(bpstat_explains_signal (stop_bpstat
)
2589 || stepping_over_breakpoint
2590 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2593 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2594 if (!ecs
->random_signal
)
2595 stop_signal
= TARGET_SIGNAL_TRAP
;
2599 /* When we reach this point, we've pretty much decided
2600 that the reason for stopping must've been a random
2601 (unexpected) signal. */
2604 ecs
->random_signal
= 1;
2606 process_event_stop_test
:
2607 /* For the program's own signals, act according to
2608 the signal handling tables. */
2610 if (ecs
->random_signal
)
2612 /* Signal not for debugging purposes. */
2616 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n", stop_signal
);
2618 stopped_by_random_signal
= 1;
2620 if (signal_print
[stop_signal
])
2623 target_terminal_ours_for_output ();
2624 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2626 if (signal_stop_state (stop_signal
))
2628 stop_stepping (ecs
);
2631 /* If not going to stop, give terminal back
2632 if we took it away. */
2634 target_terminal_inferior ();
2636 /* Clear the signal if it should not be passed. */
2637 if (signal_program
[stop_signal
] == 0)
2638 stop_signal
= TARGET_SIGNAL_0
;
2640 if (prev_pc
== read_pc ()
2641 && stepping_over_breakpoint
2642 && step_resume_breakpoint
== NULL
)
2644 /* We were just starting a new sequence, attempting to
2645 single-step off of a breakpoint and expecting a SIGTRAP.
2646 Instead this signal arrives. This signal will take us out
2647 of the stepping range so GDB needs to remember to, when
2648 the signal handler returns, resume stepping off that
2650 /* To simplify things, "continue" is forced to use the same
2651 code paths as single-step - set a breakpoint at the
2652 signal return address and then, once hit, step off that
2655 fprintf_unfiltered (gdb_stdlog
,
2656 "infrun: signal arrived while stepping over "
2659 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2660 tss
->step_after_step_resume_breakpoint
= 1;
2665 if (step_range_end
!= 0
2666 && stop_signal
!= TARGET_SIGNAL_0
2667 && stop_pc
>= step_range_start
&& stop_pc
< step_range_end
2668 && frame_id_eq (get_frame_id (get_current_frame ()),
2670 && step_resume_breakpoint
== NULL
)
2672 /* The inferior is about to take a signal that will take it
2673 out of the single step range. Set a breakpoint at the
2674 current PC (which is presumably where the signal handler
2675 will eventually return) and then allow the inferior to
2678 Note that this is only needed for a signal delivered
2679 while in the single-step range. Nested signals aren't a
2680 problem as they eventually all return. */
2682 fprintf_unfiltered (gdb_stdlog
,
2683 "infrun: signal may take us out of "
2684 "single-step range\n");
2686 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2691 /* Note: step_resume_breakpoint may be non-NULL. This occures
2692 when either there's a nested signal, or when there's a
2693 pending signal enabled just as the signal handler returns
2694 (leaving the inferior at the step-resume-breakpoint without
2695 actually executing it). Either way continue until the
2696 breakpoint is really hit. */
2701 /* Handle cases caused by hitting a breakpoint. */
2703 CORE_ADDR jmp_buf_pc
;
2704 struct bpstat_what what
;
2706 what
= bpstat_what (stop_bpstat
);
2708 if (what
.call_dummy
)
2710 stop_stack_dummy
= 1;
2713 switch (what
.main_action
)
2715 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2716 /* If we hit the breakpoint at longjmp while stepping, we
2717 install a momentary breakpoint at the target of the
2721 fprintf_unfiltered (gdb_stdlog
,
2722 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2724 tss
->stepping_over_breakpoint
= 1;
2726 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
2727 || !gdbarch_get_longjmp_target (current_gdbarch
,
2728 get_current_frame (), &jmp_buf_pc
))
2731 fprintf_unfiltered (gdb_stdlog
, "\
2732 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
2737 /* We're going to replace the current step-resume breakpoint
2738 with a longjmp-resume breakpoint. */
2739 if (step_resume_breakpoint
!= NULL
)
2740 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2742 /* Insert a breakpoint at resume address. */
2743 insert_longjmp_resume_breakpoint (jmp_buf_pc
);
2748 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2750 fprintf_unfiltered (gdb_stdlog
,
2751 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2753 gdb_assert (step_resume_breakpoint
!= NULL
);
2754 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2757 print_stop_reason (END_STEPPING_RANGE
, 0);
2758 stop_stepping (ecs
);
2761 case BPSTAT_WHAT_SINGLE
:
2763 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
2764 tss
->stepping_over_breakpoint
= 1;
2765 /* Still need to check other stuff, at least the case
2766 where we are stepping and step out of the right range. */
2769 case BPSTAT_WHAT_STOP_NOISY
:
2771 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2772 stop_print_frame
= 1;
2774 /* We are about to nuke the step_resume_breakpointt via the
2775 cleanup chain, so no need to worry about it here. */
2777 stop_stepping (ecs
);
2780 case BPSTAT_WHAT_STOP_SILENT
:
2782 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2783 stop_print_frame
= 0;
2785 /* We are about to nuke the step_resume_breakpoin via the
2786 cleanup chain, so no need to worry about it here. */
2788 stop_stepping (ecs
);
2791 case BPSTAT_WHAT_STEP_RESUME
:
2792 /* This proably demands a more elegant solution, but, yeah
2795 This function's use of the simple variable
2796 step_resume_breakpoint doesn't seem to accomodate
2797 simultaneously active step-resume bp's, although the
2798 breakpoint list certainly can.
2800 If we reach here and step_resume_breakpoint is already
2801 NULL, then apparently we have multiple active
2802 step-resume bp's. We'll just delete the breakpoint we
2803 stopped at, and carry on.
2805 Correction: what the code currently does is delete a
2806 step-resume bp, but it makes no effort to ensure that
2807 the one deleted is the one currently stopped at. MVS */
2810 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2812 if (step_resume_breakpoint
== NULL
)
2814 step_resume_breakpoint
=
2815 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2817 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2818 if (tss
->step_after_step_resume_breakpoint
)
2820 /* Back when the step-resume breakpoint was inserted, we
2821 were trying to single-step off a breakpoint. Go back
2823 tss
->step_after_step_resume_breakpoint
= 0;
2824 tss
->stepping_over_breakpoint
= 1;
2830 case BPSTAT_WHAT_CHECK_SHLIBS
:
2831 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2834 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2836 /* Check for any newly added shared libraries if we're
2837 supposed to be adding them automatically. Switch
2838 terminal for any messages produced by
2839 breakpoint_re_set. */
2840 target_terminal_ours_for_output ();
2841 /* NOTE: cagney/2003-11-25: Make certain that the target
2842 stack's section table is kept up-to-date. Architectures,
2843 (e.g., PPC64), use the section table to perform
2844 operations such as address => section name and hence
2845 require the table to contain all sections (including
2846 those found in shared libraries). */
2847 /* NOTE: cagney/2003-11-25: Pass current_target and not
2848 exec_ops to SOLIB_ADD. This is because current GDB is
2849 only tooled to propagate section_table changes out from
2850 the "current_target" (see target_resize_to_sections), and
2851 not up from the exec stratum. This, of course, isn't
2852 right. "infrun.c" should only interact with the
2853 exec/process stratum, instead relying on the target stack
2854 to propagate relevant changes (stop, section table
2855 changed, ...) up to other layers. */
2857 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2859 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2861 target_terminal_inferior ();
2863 /* If requested, stop when the dynamic linker notifies
2864 gdb of events. This allows the user to get control
2865 and place breakpoints in initializer routines for
2866 dynamically loaded objects (among other things). */
2867 if (stop_on_solib_events
|| stop_stack_dummy
)
2869 stop_stepping (ecs
);
2873 /* If we stopped due to an explicit catchpoint, then the
2874 (see above) call to SOLIB_ADD pulled in any symbols
2875 from a newly-loaded library, if appropriate.
2877 We do want the inferior to stop, but not where it is
2878 now, which is in the dynamic linker callback. Rather,
2879 we would like it stop in the user's program, just after
2880 the call that caused this catchpoint to trigger. That
2881 gives the user a more useful vantage from which to
2882 examine their program's state. */
2883 else if (what
.main_action
2884 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2886 /* ??rehrauer: If I could figure out how to get the
2887 right return PC from here, we could just set a temp
2888 breakpoint and resume. I'm not sure we can without
2889 cracking open the dld's shared libraries and sniffing
2890 their unwind tables and text/data ranges, and that's
2891 not a terribly portable notion.
2893 Until that time, we must step the inferior out of the
2894 dld callback, and also out of the dld itself (and any
2895 code or stubs in libdld.sl, such as "shl_load" and
2896 friends) until we reach non-dld code. At that point,
2897 we can stop stepping. */
2898 bpstat_get_triggered_catchpoints (stop_bpstat
,
2900 stepping_through_solib_catchpoints
);
2901 tss
->stepping_through_solib_after_catch
= 1;
2903 /* Be sure to lift all breakpoints, so the inferior does
2904 actually step past this point... */
2905 tss
->stepping_over_breakpoint
= 1;
2910 /* We want to step over this breakpoint, then keep going. */
2911 tss
->stepping_over_breakpoint
= 1;
2917 case BPSTAT_WHAT_LAST
:
2918 /* Not a real code, but listed here to shut up gcc -Wall. */
2920 case BPSTAT_WHAT_KEEP_CHECKING
:
2925 /* We come here if we hit a breakpoint but should not
2926 stop for it. Possibly we also were stepping
2927 and should stop for that. So fall through and
2928 test for stepping. But, if not stepping,
2931 /* Are we stepping to get the inferior out of the dynamic linker's
2932 hook (and possibly the dld itself) after catching a shlib
2934 if (tss
->stepping_through_solib_after_catch
)
2936 #if defined(SOLIB_ADD)
2937 /* Have we reached our destination? If not, keep going. */
2938 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2941 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
2942 tss
->stepping_over_breakpoint
= 1;
2948 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
2949 /* Else, stop and report the catchpoint(s) whose triggering
2950 caused us to begin stepping. */
2951 tss
->stepping_through_solib_after_catch
= 0;
2952 bpstat_clear (&stop_bpstat
);
2953 stop_bpstat
= bpstat_copy (tss
->stepping_through_solib_catchpoints
);
2954 bpstat_clear (&tss
->stepping_through_solib_catchpoints
);
2955 stop_print_frame
= 1;
2956 stop_stepping (ecs
);
2960 if (step_resume_breakpoint
)
2963 fprintf_unfiltered (gdb_stdlog
,
2964 "infrun: step-resume breakpoint is inserted\n");
2966 /* Having a step-resume breakpoint overrides anything
2967 else having to do with stepping commands until
2968 that breakpoint is reached. */
2973 if (step_range_end
== 0)
2976 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
2977 /* Likewise if we aren't even stepping. */
2982 /* If stepping through a line, keep going if still within it.
2984 Note that step_range_end is the address of the first instruction
2985 beyond the step range, and NOT the address of the last instruction
2987 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2990 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
2991 paddr_nz (step_range_start
),
2992 paddr_nz (step_range_end
));
2997 /* We stepped out of the stepping range. */
2999 /* If we are stepping at the source level and entered the runtime
3000 loader dynamic symbol resolution code, we keep on single stepping
3001 until we exit the run time loader code and reach the callee's
3003 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3004 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
3005 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
)
3007 && in_solib_dynsym_resolve_code (stop_pc
)
3011 CORE_ADDR pc_after_resolver
=
3012 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
3015 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
3017 if (pc_after_resolver
)
3019 /* Set up a step-resume breakpoint at the address
3020 indicated by SKIP_SOLIB_RESOLVER. */
3021 struct symtab_and_line sr_sal
;
3023 sr_sal
.pc
= pc_after_resolver
;
3025 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3032 if (step_range_end
!= 1
3033 && (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3034 || step_over_calls
== STEP_OVER_ALL
)
3035 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
3038 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
3039 /* The inferior, while doing a "step" or "next", has ended up in
3040 a signal trampoline (either by a signal being delivered or by
3041 the signal handler returning). Just single-step until the
3042 inferior leaves the trampoline (either by calling the handler
3048 /* Check for subroutine calls. The check for the current frame
3049 equalling the step ID is not necessary - the check of the
3050 previous frame's ID is sufficient - but it is a common case and
3051 cheaper than checking the previous frame's ID.
3053 NOTE: frame_id_eq will never report two invalid frame IDs as
3054 being equal, so to get into this block, both the current and
3055 previous frame must have valid frame IDs. */
3056 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id
)
3057 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id
))
3059 CORE_ADDR real_stop_pc
;
3062 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
3064 if ((step_over_calls
== STEP_OVER_NONE
)
3065 || ((step_range_end
== 1)
3066 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
3068 /* I presume that step_over_calls is only 0 when we're
3069 supposed to be stepping at the assembly language level
3070 ("stepi"). Just stop. */
3071 /* Also, maybe we just did a "nexti" inside a prolog, so we
3072 thought it was a subroutine call but it was not. Stop as
3075 print_stop_reason (END_STEPPING_RANGE
, 0);
3076 stop_stepping (ecs
);
3080 if (step_over_calls
== STEP_OVER_ALL
)
3082 /* We're doing a "next", set a breakpoint at callee's return
3083 address (the address at which the caller will
3085 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3090 /* If we are in a function call trampoline (a stub between the
3091 calling routine and the real function), locate the real
3092 function. That's what tells us (a) whether we want to step
3093 into it at all, and (b) what prologue we want to run to the
3094 end of, if we do step into it. */
3095 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
3096 if (real_stop_pc
== 0)
3097 real_stop_pc
= gdbarch_skip_trampoline_code
3098 (current_gdbarch
, get_current_frame (), stop_pc
);
3099 if (real_stop_pc
!= 0)
3100 ecs
->stop_func_start
= real_stop_pc
;
3103 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
3104 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs
->stop_func_start
)
3106 in_solib_dynsym_resolve_code (ecs
->stop_func_start
)
3110 struct symtab_and_line sr_sal
;
3112 sr_sal
.pc
= ecs
->stop_func_start
;
3114 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3119 /* If we have line number information for the function we are
3120 thinking of stepping into, step into it.
3122 If there are several symtabs at that PC (e.g. with include
3123 files), just want to know whether *any* of them have line
3124 numbers. find_pc_line handles this. */
3126 struct symtab_and_line tmp_sal
;
3128 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
3129 if (tmp_sal
.line
!= 0)
3131 step_into_function (ecs
);
3136 /* If we have no line number and the step-stop-if-no-debug is
3137 set, we stop the step so that the user has a chance to switch
3138 in assembly mode. */
3139 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
3142 print_stop_reason (END_STEPPING_RANGE
, 0);
3143 stop_stepping (ecs
);
3147 /* Set a breakpoint at callee's return address (the address at
3148 which the caller will resume). */
3149 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3154 /* If we're in the return path from a shared library trampoline,
3155 we want to proceed through the trampoline when stepping. */
3156 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
3157 stop_pc
, ecs
->stop_func_name
))
3159 /* Determine where this trampoline returns. */
3160 CORE_ADDR real_stop_pc
;
3161 real_stop_pc
= gdbarch_skip_trampoline_code
3162 (current_gdbarch
, get_current_frame (), stop_pc
);
3165 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3167 /* Only proceed through if we know where it's going. */
3170 /* And put the step-breakpoint there and go until there. */
3171 struct symtab_and_line sr_sal
;
3173 init_sal (&sr_sal
); /* initialize to zeroes */
3174 sr_sal
.pc
= real_stop_pc
;
3175 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3177 /* Do not specify what the fp should be when we stop since
3178 on some machines the prologue is where the new fp value
3180 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3182 /* Restart without fiddling with the step ranges or
3189 tss
->sal
= find_pc_line (stop_pc
, 0);
3191 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3192 the trampoline processing logic, however, there are some trampolines
3193 that have no names, so we should do trampoline handling first. */
3194 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3195 && ecs
->stop_func_name
== NULL
3196 && tss
->sal
.line
== 0)
3199 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3201 /* The inferior just stepped into, or returned to, an
3202 undebuggable function (where there is no debugging information
3203 and no line number corresponding to the address where the
3204 inferior stopped). Since we want to skip this kind of code,
3205 we keep going until the inferior returns from this
3206 function - unless the user has asked us not to (via
3207 set step-mode) or we no longer know how to get back
3208 to the call site. */
3209 if (step_stop_if_no_debug
3210 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3212 /* If we have no line number and the step-stop-if-no-debug
3213 is set, we stop the step so that the user has a chance to
3214 switch in assembly mode. */
3216 print_stop_reason (END_STEPPING_RANGE
, 0);
3217 stop_stepping (ecs
);
3222 /* Set a breakpoint at callee's return address (the address
3223 at which the caller will resume). */
3224 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3230 if (step_range_end
== 1)
3232 /* It is stepi or nexti. We always want to stop stepping after
3235 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
3237 print_stop_reason (END_STEPPING_RANGE
, 0);
3238 stop_stepping (ecs
);
3242 if (tss
->sal
.line
== 0)
3244 /* We have no line number information. That means to stop
3245 stepping (does this always happen right after one instruction,
3246 when we do "s" in a function with no line numbers,
3247 or can this happen as a result of a return or longjmp?). */
3249 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
3251 print_stop_reason (END_STEPPING_RANGE
, 0);
3252 stop_stepping (ecs
);
3256 if ((stop_pc
== tss
->sal
.pc
)
3257 && (tss
->current_line
!= tss
->sal
.line
3258 || tss
->current_symtab
!= tss
->sal
.symtab
))
3260 /* We are at the start of a different line. So stop. Note that
3261 we don't stop if we step into the middle of a different line.
3262 That is said to make things like for (;;) statements work
3265 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
3267 print_stop_reason (END_STEPPING_RANGE
, 0);
3268 stop_stepping (ecs
);
3272 /* We aren't done stepping.
3274 Optimize by setting the stepping range to the line.
3275 (We might not be in the original line, but if we entered a
3276 new line in mid-statement, we continue stepping. This makes
3277 things like for(;;) statements work better.) */
3279 step_range_start
= tss
->sal
.pc
;
3280 step_range_end
= tss
->sal
.end
;
3281 step_frame_id
= get_frame_id (get_current_frame ());
3282 tss
->current_line
= tss
->sal
.line
;
3283 tss
->current_symtab
= tss
->sal
.symtab
;
3285 /* In the case where we just stepped out of a function into the
3286 middle of a line of the caller, continue stepping, but
3287 step_frame_id must be modified to current frame */
3289 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
3290 generous. It will trigger on things like a step into a frameless
3291 stackless leaf function. I think the logic should instead look
3292 at the unwound frame ID has that should give a more robust
3293 indication of what happened. */
3294 if (step
- ID
== current
- ID
)
3295 still stepping in same function
;
3296 else if (step
- ID
== unwind (current
- ID
))
3297 stepped into a function
;
3299 stepped out of a function
;
3300 /* Of course this assumes that the frame ID unwind code is robust
3301 and we're willing to introduce frame unwind logic into this
3302 function. Fortunately, those days are nearly upon us. */
3305 struct frame_info
*frame
= get_current_frame ();
3306 struct frame_id current_frame
= get_frame_id (frame
);
3307 if (!(frame_id_inner (get_frame_arch (frame
), current_frame
,
3309 step_frame_id
= current_frame
;
3313 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
3317 /* Are we in the middle of stepping? */
3320 currently_stepping (struct thread_stepping_state
*tss
)
3322 return (((step_range_end
&& step_resume_breakpoint
== NULL
)
3323 || stepping_over_breakpoint
)
3324 || tss
->stepping_through_solib_after_catch
3325 || bpstat_should_step ());
3328 /* Subroutine call with source code we should not step over. Do step
3329 to the first line of code in it. */
3332 step_into_function (struct execution_control_state
*ecs
)
3335 struct symtab_and_line sr_sal
;
3337 s
= find_pc_symtab (stop_pc
);
3338 if (s
&& s
->language
!= language_asm
)
3339 ecs
->stop_func_start
= gdbarch_skip_prologue
3340 (current_gdbarch
, ecs
->stop_func_start
);
3342 tss
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3343 /* Use the step_resume_break to step until the end of the prologue,
3344 even if that involves jumps (as it seems to on the vax under
3346 /* If the prologue ends in the middle of a source line, continue to
3347 the end of that source line (if it is still within the function).
3348 Otherwise, just go to end of prologue. */
3350 && tss
->sal
.pc
!= ecs
->stop_func_start
3351 && tss
->sal
.end
< ecs
->stop_func_end
)
3352 ecs
->stop_func_start
= tss
->sal
.end
;
3354 /* Architectures which require breakpoint adjustment might not be able
3355 to place a breakpoint at the computed address. If so, the test
3356 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3357 ecs->stop_func_start to an address at which a breakpoint may be
3358 legitimately placed.
3360 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3361 made, GDB will enter an infinite loop when stepping through
3362 optimized code consisting of VLIW instructions which contain
3363 subinstructions corresponding to different source lines. On
3364 FR-V, it's not permitted to place a breakpoint on any but the
3365 first subinstruction of a VLIW instruction. When a breakpoint is
3366 set, GDB will adjust the breakpoint address to the beginning of
3367 the VLIW instruction. Thus, we need to make the corresponding
3368 adjustment here when computing the stop address. */
3370 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3372 ecs
->stop_func_start
3373 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
3374 ecs
->stop_func_start
);
3377 if (ecs
->stop_func_start
== stop_pc
)
3379 /* We are already there: stop now. */
3381 print_stop_reason (END_STEPPING_RANGE
, 0);
3382 stop_stepping (ecs
);
3387 /* Put the step-breakpoint there and go until there. */
3388 init_sal (&sr_sal
); /* initialize to zeroes */
3389 sr_sal
.pc
= ecs
->stop_func_start
;
3390 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3392 /* Do not specify what the fp should be when we stop since on
3393 some machines the prologue is where the new fp value is
3395 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3397 /* And make sure stepping stops right away then. */
3398 step_range_end
= step_range_start
;
3403 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3404 This is used to both functions and to skip over code. */
3407 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
3408 struct frame_id sr_id
)
3410 /* There should never be more than one step-resume or longjmp-resume
3411 breakpoint per thread, so we should never be setting a new
3412 step_resume_breakpoint when one is already active. */
3413 gdb_assert (step_resume_breakpoint
== NULL
);
3416 fprintf_unfiltered (gdb_stdlog
,
3417 "infrun: inserting step-resume breakpoint at 0x%s\n",
3418 paddr_nz (sr_sal
.pc
));
3420 step_resume_breakpoint
= set_momentary_breakpoint (sr_sal
, sr_id
,
3424 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3425 to skip a potential signal handler.
3427 This is called with the interrupted function's frame. The signal
3428 handler, when it returns, will resume the interrupted function at
3432 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
3434 struct symtab_and_line sr_sal
;
3436 gdb_assert (return_frame
!= NULL
);
3437 init_sal (&sr_sal
); /* initialize to zeros */
3439 sr_sal
.pc
= gdbarch_addr_bits_remove
3440 (current_gdbarch
, get_frame_pc (return_frame
));
3441 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3443 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
3446 /* Similar to insert_step_resume_breakpoint_at_frame, except
3447 but a breakpoint at the previous frame's PC. This is used to
3448 skip a function after stepping into it (for "next" or if the called
3449 function has no debugging information).
3451 The current function has almost always been reached by single
3452 stepping a call or return instruction. NEXT_FRAME belongs to the
3453 current function, and the breakpoint will be set at the caller's
3456 This is a separate function rather than reusing
3457 insert_step_resume_breakpoint_at_frame in order to avoid
3458 get_prev_frame, which may stop prematurely (see the implementation
3459 of frame_unwind_id for an example). */
3462 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
3464 struct symtab_and_line sr_sal
;
3466 /* We shouldn't have gotten here if we don't know where the call site
3468 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
3470 init_sal (&sr_sal
); /* initialize to zeros */
3472 sr_sal
.pc
= gdbarch_addr_bits_remove
3473 (current_gdbarch
, frame_pc_unwind (next_frame
));
3474 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3476 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
3479 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
3480 new breakpoint at the target of a jmp_buf. The handling of
3481 longjmp-resume uses the same mechanisms used for handling
3482 "step-resume" breakpoints. */
3485 insert_longjmp_resume_breakpoint (CORE_ADDR pc
)
3487 /* There should never be more than one step-resume or longjmp-resume
3488 breakpoint per thread, so we should never be setting a new
3489 longjmp_resume_breakpoint when one is already active. */
3490 gdb_assert (step_resume_breakpoint
== NULL
);
3493 fprintf_unfiltered (gdb_stdlog
,
3494 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
3497 step_resume_breakpoint
=
3498 set_momentary_breakpoint_at_pc (pc
, bp_longjmp_resume
);
3502 stop_stepping (struct execution_control_state
*ecs
)
3505 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
3507 /* Let callers know we don't want to wait for the inferior anymore. */
3508 ecs
->wait_some_more
= 0;
3511 /* This function handles various cases where we need to continue
3512 waiting for the inferior. */
3513 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3516 keep_going (struct execution_control_state
*ecs
)
3518 /* Save the pc before execution, to compare with pc after stop. */
3519 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3521 /* If we did not do break;, it means we should keep running the
3522 inferior and not return to debugger. */
3524 if (stepping_over_breakpoint
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3526 /* We took a signal (which we are supposed to pass through to
3527 the inferior, else we'd have done a break above) and we
3528 haven't yet gotten our trap. Simply continue. */
3529 resume (currently_stepping (tss
), stop_signal
);
3533 /* Either the trap was not expected, but we are continuing
3534 anyway (the user asked that this signal be passed to the
3537 The signal was SIGTRAP, e.g. it was our signal, but we
3538 decided we should resume from it.
3540 We're going to run this baby now!
3542 Note that insert_breakpoints won't try to re-insert
3543 already inserted breakpoints. Therefore, we don't
3544 care if breakpoints were already inserted, or not. */
3546 if (tss
->stepping_over_breakpoint
)
3548 if (! use_displaced_stepping (current_gdbarch
))
3549 /* Since we can't do a displaced step, we have to remove
3550 the breakpoint while we step it. To keep things
3551 simple, we remove them all. */
3552 remove_breakpoints ();
3556 struct gdb_exception e
;
3557 /* Stop stepping when inserting breakpoints
3559 TRY_CATCH (e
, RETURN_MASK_ERROR
)
3561 insert_breakpoints ();
3565 stop_stepping (ecs
);
3570 stepping_over_breakpoint
= tss
->stepping_over_breakpoint
;
3572 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3573 specifies that such a signal should be delivered to the
3576 Typically, this would occure when a user is debugging a
3577 target monitor on a simulator: the target monitor sets a
3578 breakpoint; the simulator encounters this break-point and
3579 halts the simulation handing control to GDB; GDB, noteing
3580 that the break-point isn't valid, returns control back to the
3581 simulator; the simulator then delivers the hardware
3582 equivalent of a SIGNAL_TRAP to the program being debugged. */
3584 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3585 stop_signal
= TARGET_SIGNAL_0
;
3588 resume (currently_stepping (tss
), stop_signal
);
3591 prepare_to_wait (ecs
);
3594 /* This function normally comes after a resume, before
3595 handle_inferior_event exits. It takes care of any last bits of
3596 housekeeping, and sets the all-important wait_some_more flag. */
3599 prepare_to_wait (struct execution_control_state
*ecs
)
3602 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
3603 if (infwait_state
== infwait_normal_state
)
3605 overlay_cache_invalid
= 1;
3607 /* We have to invalidate the registers BEFORE calling
3608 target_wait because they can be loaded from the target while
3609 in target_wait. This makes remote debugging a bit more
3610 efficient for those targets that provide critical registers
3611 as part of their normal status mechanism. */
3613 registers_changed ();
3614 waiton_ptid
= pid_to_ptid (-1);
3616 /* This is the old end of the while loop. Let everybody know we
3617 want to wait for the inferior some more and get called again
3619 ecs
->wait_some_more
= 1;
3622 /* Print why the inferior has stopped. We always print something when
3623 the inferior exits, or receives a signal. The rest of the cases are
3624 dealt with later on in normal_stop() and print_it_typical(). Ideally
3625 there should be a call to this function from handle_inferior_event()
3626 each time stop_stepping() is called.*/
3628 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3630 switch (stop_reason
)
3632 case END_STEPPING_RANGE
:
3633 /* We are done with a step/next/si/ni command. */
3634 /* For now print nothing. */
3635 /* Print a message only if not in the middle of doing a "step n"
3636 operation for n > 1 */
3637 if (!step_multi
|| !stop_step
)
3638 if (ui_out_is_mi_like_p (uiout
))
3641 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
3644 /* The inferior was terminated by a signal. */
3645 annotate_signalled ();
3646 if (ui_out_is_mi_like_p (uiout
))
3649 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
3650 ui_out_text (uiout
, "\nProgram terminated with signal ");
3651 annotate_signal_name ();
3652 ui_out_field_string (uiout
, "signal-name",
3653 target_signal_to_name (stop_info
));
3654 annotate_signal_name_end ();
3655 ui_out_text (uiout
, ", ");
3656 annotate_signal_string ();
3657 ui_out_field_string (uiout
, "signal-meaning",
3658 target_signal_to_string (stop_info
));
3659 annotate_signal_string_end ();
3660 ui_out_text (uiout
, ".\n");
3661 ui_out_text (uiout
, "The program no longer exists.\n");
3664 /* The inferior program is finished. */
3665 annotate_exited (stop_info
);
3668 if (ui_out_is_mi_like_p (uiout
))
3669 ui_out_field_string (uiout
, "reason",
3670 async_reason_lookup (EXEC_ASYNC_EXITED
));
3671 ui_out_text (uiout
, "\nProgram exited with code ");
3672 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3673 (unsigned int) stop_info
);
3674 ui_out_text (uiout
, ".\n");
3678 if (ui_out_is_mi_like_p (uiout
))
3681 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
3682 ui_out_text (uiout
, "\nProgram exited normally.\n");
3684 /* Support the --return-child-result option. */
3685 return_child_result_value
= stop_info
;
3687 case SIGNAL_RECEIVED
:
3688 /* Signal received. The signal table tells us to print about
3691 ui_out_text (uiout
, "\nProgram received signal ");
3692 annotate_signal_name ();
3693 if (ui_out_is_mi_like_p (uiout
))
3695 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
3696 ui_out_field_string (uiout
, "signal-name",
3697 target_signal_to_name (stop_info
));
3698 annotate_signal_name_end ();
3699 ui_out_text (uiout
, ", ");
3700 annotate_signal_string ();
3701 ui_out_field_string (uiout
, "signal-meaning",
3702 target_signal_to_string (stop_info
));
3703 annotate_signal_string_end ();
3704 ui_out_text (uiout
, ".\n");
3707 internal_error (__FILE__
, __LINE__
,
3708 _("print_stop_reason: unrecognized enum value"));
3714 /* Here to return control to GDB when the inferior stops for real.
3715 Print appropriate messages, remove breakpoints, give terminal our modes.
3717 STOP_PRINT_FRAME nonzero means print the executing frame
3718 (pc, function, args, file, line number and line text).
3719 BREAKPOINTS_FAILED nonzero means stop was due to error
3720 attempting to insert breakpoints. */
3725 struct target_waitstatus last
;
3728 get_last_target_status (&last_ptid
, &last
);
3730 /* In non-stop mode, we don't want GDB to switch threads behind the
3731 user's back, to avoid races where the user is typing a command to
3732 apply to thread x, but GDB switches to thread y before the user
3733 finishes entering the command. */
3735 /* As with the notification of thread events, we want to delay
3736 notifying the user that we've switched thread context until
3737 the inferior actually stops.
3739 There's no point in saying anything if the inferior has exited.
3740 Note that SIGNALLED here means "exited with a signal", not
3741 "received a signal". */
3743 && !ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3744 && target_has_execution
3745 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3746 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3748 target_terminal_ours_for_output ();
3749 printf_filtered (_("[Switching to %s]\n"),
3750 target_pid_to_str (inferior_ptid
));
3751 annotate_thread_changed ();
3752 previous_inferior_ptid
= inferior_ptid
;
3755 /* NOTE drow/2004-01-17: Is this still necessary? */
3756 /* Make sure that the current_frame's pc is correct. This
3757 is a correction for setting up the frame info before doing
3758 gdbarch_decr_pc_after_break */
3759 if (target_has_execution
)
3760 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3761 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3762 frame code to check for this and sort out any resultant mess.
3763 gdbarch_decr_pc_after_break needs to just go away. */
3764 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3766 if (!breakpoints_always_inserted_mode () && target_has_execution
)
3768 if (remove_breakpoints ())
3770 target_terminal_ours_for_output ();
3771 printf_filtered (_("\
3772 Cannot remove breakpoints because program is no longer writable.\n\
3773 It might be running in another process.\n\
3774 Further execution is probably impossible.\n"));
3778 /* If an auto-display called a function and that got a signal,
3779 delete that auto-display to avoid an infinite recursion. */
3781 if (stopped_by_random_signal
)
3782 disable_current_display ();
3784 /* Don't print a message if in the middle of doing a "step n"
3785 operation for n > 1 */
3786 if (step_multi
&& stop_step
)
3789 target_terminal_ours ();
3791 /* Set the current source location. This will also happen if we
3792 display the frame below, but the current SAL will be incorrect
3793 during a user hook-stop function. */
3794 if (target_has_stack
&& !stop_stack_dummy
)
3795 set_current_sal_from_frame (get_current_frame (), 1);
3797 /* Look up the hook_stop and run it (CLI internally handles problem
3798 of stop_command's pre-hook not existing). */
3800 catch_errors (hook_stop_stub
, stop_command
,
3801 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3803 if (!target_has_stack
)
3809 /* Select innermost stack frame - i.e., current frame is frame 0,
3810 and current location is based on that.
3811 Don't do this on return from a stack dummy routine,
3812 or if the program has exited. */
3814 if (!stop_stack_dummy
)
3816 select_frame (get_current_frame ());
3818 /* Print current location without a level number, if
3819 we have changed functions or hit a breakpoint.
3820 Print source line if we have one.
3821 bpstat_print() contains the logic deciding in detail
3822 what to print, based on the event(s) that just occurred. */
3824 /* If --batch-silent is enabled then there's no need to print the current
3825 source location, and to try risks causing an error message about
3826 missing source files. */
3827 if (stop_print_frame
&& !batch_silent
)
3831 int do_frame_printing
= 1;
3833 bpstat_ret
= bpstat_print (stop_bpstat
);
3837 /* If we had hit a shared library event breakpoint,
3838 bpstat_print would print out this message. If we hit
3839 an OS-level shared library event, do the same
3841 if (last
.kind
== TARGET_WAITKIND_LOADED
)
3843 printf_filtered (_("Stopped due to shared library event\n"));
3844 source_flag
= SRC_LINE
; /* something bogus */
3845 do_frame_printing
= 0;
3849 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3850 (or should) carry around the function and does (or
3851 should) use that when doing a frame comparison. */
3853 && frame_id_eq (step_frame_id
,
3854 get_frame_id (get_current_frame ()))
3855 && step_start_function
== find_pc_function (stop_pc
))
3856 source_flag
= SRC_LINE
; /* finished step, just print source line */
3858 source_flag
= SRC_AND_LOC
; /* print location and source line */
3860 case PRINT_SRC_AND_LOC
:
3861 source_flag
= SRC_AND_LOC
; /* print location and source line */
3863 case PRINT_SRC_ONLY
:
3864 source_flag
= SRC_LINE
;
3867 source_flag
= SRC_LINE
; /* something bogus */
3868 do_frame_printing
= 0;
3871 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
3874 if (ui_out_is_mi_like_p (uiout
))
3875 ui_out_field_int (uiout
, "thread-id",
3876 pid_to_thread_id (inferior_ptid
));
3877 /* The behavior of this routine with respect to the source
3879 SRC_LINE: Print only source line
3880 LOCATION: Print only location
3881 SRC_AND_LOC: Print location and source line */
3882 if (do_frame_printing
)
3883 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
3885 /* Display the auto-display expressions. */
3890 /* Save the function value return registers, if we care.
3891 We might be about to restore their previous contents. */
3892 if (proceed_to_finish
)
3894 /* This should not be necessary. */
3896 regcache_xfree (stop_registers
);
3898 /* NB: The copy goes through to the target picking up the value of
3899 all the registers. */
3900 stop_registers
= regcache_dup (get_current_regcache ());
3903 if (stop_stack_dummy
)
3905 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3906 ends with a setting of the current frame, so we can use that
3908 frame_pop (get_current_frame ());
3909 /* Set stop_pc to what it was before we called the function.
3910 Can't rely on restore_inferior_status because that only gets
3911 called if we don't stop in the called function. */
3912 stop_pc
= read_pc ();
3913 select_frame (get_current_frame ());
3917 annotate_stopped ();
3918 if (!suppress_stop_observer
&& !step_multi
)
3919 observer_notify_normal_stop (stop_bpstat
);
3920 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3921 Delete any breakpoint that is to be deleted at the next stop. */
3922 breakpoint_auto_delete (stop_bpstat
);
3924 if (target_has_execution
3925 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3926 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3929 set_running (pid_to_ptid (-1), 0);
3931 set_running (inferior_ptid
, 0);
3936 hook_stop_stub (void *cmd
)
3938 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3943 signal_stop_state (int signo
)
3945 /* Always stop on signals if we're just gaining control of the
3947 return signal_stop
[signo
] || stop_soon
!= NO_STOP_QUIETLY
;
3951 signal_print_state (int signo
)
3953 return signal_print
[signo
];
3957 signal_pass_state (int signo
)
3959 return signal_program
[signo
];
3963 signal_stop_update (int signo
, int state
)
3965 int ret
= signal_stop
[signo
];
3966 signal_stop
[signo
] = state
;
3971 signal_print_update (int signo
, int state
)
3973 int ret
= signal_print
[signo
];
3974 signal_print
[signo
] = state
;
3979 signal_pass_update (int signo
, int state
)
3981 int ret
= signal_program
[signo
];
3982 signal_program
[signo
] = state
;
3987 sig_print_header (void)
3989 printf_filtered (_("\
3990 Signal Stop\tPrint\tPass to program\tDescription\n"));
3994 sig_print_info (enum target_signal oursig
)
3996 char *name
= target_signal_to_name (oursig
);
3997 int name_padding
= 13 - strlen (name
);
3999 if (name_padding
<= 0)
4002 printf_filtered ("%s", name
);
4003 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
4004 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
4005 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
4006 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
4007 printf_filtered ("%s\n", target_signal_to_string (oursig
));
4010 /* Specify how various signals in the inferior should be handled. */
4013 handle_command (char *args
, int from_tty
)
4016 int digits
, wordlen
;
4017 int sigfirst
, signum
, siglast
;
4018 enum target_signal oursig
;
4021 unsigned char *sigs
;
4022 struct cleanup
*old_chain
;
4026 error_no_arg (_("signal to handle"));
4029 /* Allocate and zero an array of flags for which signals to handle. */
4031 nsigs
= (int) TARGET_SIGNAL_LAST
;
4032 sigs
= (unsigned char *) alloca (nsigs
);
4033 memset (sigs
, 0, nsigs
);
4035 /* Break the command line up into args. */
4037 argv
= buildargv (args
);
4042 old_chain
= make_cleanup_freeargv (argv
);
4044 /* Walk through the args, looking for signal oursigs, signal names, and
4045 actions. Signal numbers and signal names may be interspersed with
4046 actions, with the actions being performed for all signals cumulatively
4047 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
4049 while (*argv
!= NULL
)
4051 wordlen
= strlen (*argv
);
4052 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
4056 sigfirst
= siglast
= -1;
4058 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
4060 /* Apply action to all signals except those used by the
4061 debugger. Silently skip those. */
4064 siglast
= nsigs
- 1;
4066 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
4068 SET_SIGS (nsigs
, sigs
, signal_stop
);
4069 SET_SIGS (nsigs
, sigs
, signal_print
);
4071 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
4073 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4075 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
4077 SET_SIGS (nsigs
, sigs
, signal_print
);
4079 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
4081 SET_SIGS (nsigs
, sigs
, signal_program
);
4083 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
4085 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4087 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
4089 SET_SIGS (nsigs
, sigs
, signal_program
);
4091 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
4093 UNSET_SIGS (nsigs
, sigs
, signal_print
);
4094 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
4096 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
4098 UNSET_SIGS (nsigs
, sigs
, signal_program
);
4100 else if (digits
> 0)
4102 /* It is numeric. The numeric signal refers to our own
4103 internal signal numbering from target.h, not to host/target
4104 signal number. This is a feature; users really should be
4105 using symbolic names anyway, and the common ones like
4106 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
4108 sigfirst
= siglast
= (int)
4109 target_signal_from_command (atoi (*argv
));
4110 if ((*argv
)[digits
] == '-')
4113 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
4115 if (sigfirst
> siglast
)
4117 /* Bet he didn't figure we'd think of this case... */
4125 oursig
= target_signal_from_name (*argv
);
4126 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
4128 sigfirst
= siglast
= (int) oursig
;
4132 /* Not a number and not a recognized flag word => complain. */
4133 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
4137 /* If any signal numbers or symbol names were found, set flags for
4138 which signals to apply actions to. */
4140 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
4142 switch ((enum target_signal
) signum
)
4144 case TARGET_SIGNAL_TRAP
:
4145 case TARGET_SIGNAL_INT
:
4146 if (!allsigs
&& !sigs
[signum
])
4148 if (query ("%s is used by the debugger.\n\
4149 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
4155 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4156 gdb_flush (gdb_stdout
);
4160 case TARGET_SIGNAL_0
:
4161 case TARGET_SIGNAL_DEFAULT
:
4162 case TARGET_SIGNAL_UNKNOWN
:
4163 /* Make sure that "all" doesn't print these. */
4174 target_notice_signals (inferior_ptid
);
4178 /* Show the results. */
4179 sig_print_header ();
4180 for (signum
= 0; signum
< nsigs
; signum
++)
4184 sig_print_info (signum
);
4189 do_cleanups (old_chain
);
4193 xdb_handle_command (char *args
, int from_tty
)
4196 struct cleanup
*old_chain
;
4198 /* Break the command line up into args. */
4200 argv
= buildargv (args
);
4205 old_chain
= make_cleanup_freeargv (argv
);
4206 if (argv
[1] != (char *) NULL
)
4211 bufLen
= strlen (argv
[0]) + 20;
4212 argBuf
= (char *) xmalloc (bufLen
);
4216 enum target_signal oursig
;
4218 oursig
= target_signal_from_name (argv
[0]);
4219 memset (argBuf
, 0, bufLen
);
4220 if (strcmp (argv
[1], "Q") == 0)
4221 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4224 if (strcmp (argv
[1], "s") == 0)
4226 if (!signal_stop
[oursig
])
4227 sprintf (argBuf
, "%s %s", argv
[0], "stop");
4229 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
4231 else if (strcmp (argv
[1], "i") == 0)
4233 if (!signal_program
[oursig
])
4234 sprintf (argBuf
, "%s %s", argv
[0], "pass");
4236 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
4238 else if (strcmp (argv
[1], "r") == 0)
4240 if (!signal_print
[oursig
])
4241 sprintf (argBuf
, "%s %s", argv
[0], "print");
4243 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4249 handle_command (argBuf
, from_tty
);
4251 printf_filtered (_("Invalid signal handling flag.\n"));
4256 do_cleanups (old_chain
);
4259 /* Print current contents of the tables set by the handle command.
4260 It is possible we should just be printing signals actually used
4261 by the current target (but for things to work right when switching
4262 targets, all signals should be in the signal tables). */
4265 signals_info (char *signum_exp
, int from_tty
)
4267 enum target_signal oursig
;
4268 sig_print_header ();
4272 /* First see if this is a symbol name. */
4273 oursig
= target_signal_from_name (signum_exp
);
4274 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
4276 /* No, try numeric. */
4278 target_signal_from_command (parse_and_eval_long (signum_exp
));
4280 sig_print_info (oursig
);
4284 printf_filtered ("\n");
4285 /* These ugly casts brought to you by the native VAX compiler. */
4286 for (oursig
= TARGET_SIGNAL_FIRST
;
4287 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
4288 oursig
= (enum target_signal
) ((int) oursig
+ 1))
4292 if (oursig
!= TARGET_SIGNAL_UNKNOWN
4293 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
4294 sig_print_info (oursig
);
4297 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4300 struct inferior_status
4302 enum target_signal stop_signal
;
4306 int stop_stack_dummy
;
4307 int stopped_by_random_signal
;
4308 int stepping_over_breakpoint
;
4309 CORE_ADDR step_range_start
;
4310 CORE_ADDR step_range_end
;
4311 struct frame_id step_frame_id
;
4312 enum step_over_calls_kind step_over_calls
;
4313 CORE_ADDR step_resume_break_address
;
4314 int stop_after_trap
;
4317 /* These are here because if call_function_by_hand has written some
4318 registers and then decides to call error(), we better not have changed
4320 struct regcache
*registers
;
4322 /* A frame unique identifier. */
4323 struct frame_id selected_frame_id
;
4325 int breakpoint_proceeded
;
4326 int restore_stack_info
;
4327 int proceed_to_finish
;
4331 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
4334 int size
= register_size (current_gdbarch
, regno
);
4335 void *buf
= alloca (size
);
4336 store_signed_integer (buf
, size
, val
);
4337 regcache_raw_write (inf_status
->registers
, regno
, buf
);
4340 /* Save all of the information associated with the inferior<==>gdb
4341 connection. INF_STATUS is a pointer to a "struct inferior_status"
4342 (defined in inferior.h). */
4344 struct inferior_status
*
4345 save_inferior_status (int restore_stack_info
)
4347 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
4349 inf_status
->stop_signal
= stop_signal
;
4350 inf_status
->stop_pc
= stop_pc
;
4351 inf_status
->stop_step
= stop_step
;
4352 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
4353 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
4354 inf_status
->stepping_over_breakpoint
= stepping_over_breakpoint
;
4355 inf_status
->step_range_start
= step_range_start
;
4356 inf_status
->step_range_end
= step_range_end
;
4357 inf_status
->step_frame_id
= step_frame_id
;
4358 inf_status
->step_over_calls
= step_over_calls
;
4359 inf_status
->stop_after_trap
= stop_after_trap
;
4360 inf_status
->stop_soon
= stop_soon
;
4361 /* Save original bpstat chain here; replace it with copy of chain.
4362 If caller's caller is walking the chain, they'll be happier if we
4363 hand them back the original chain when restore_inferior_status is
4365 inf_status
->stop_bpstat
= stop_bpstat
;
4366 stop_bpstat
= bpstat_copy (stop_bpstat
);
4367 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4368 inf_status
->restore_stack_info
= restore_stack_info
;
4369 inf_status
->proceed_to_finish
= proceed_to_finish
;
4371 inf_status
->registers
= regcache_dup (get_current_regcache ());
4373 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
4378 restore_selected_frame (void *args
)
4380 struct frame_id
*fid
= (struct frame_id
*) args
;
4381 struct frame_info
*frame
;
4383 frame
= frame_find_by_id (*fid
);
4385 /* If inf_status->selected_frame_id is NULL, there was no previously
4389 warning (_("Unable to restore previously selected frame."));
4393 select_frame (frame
);
4399 restore_inferior_status (struct inferior_status
*inf_status
)
4401 stop_signal
= inf_status
->stop_signal
;
4402 stop_pc
= inf_status
->stop_pc
;
4403 stop_step
= inf_status
->stop_step
;
4404 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4405 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4406 stepping_over_breakpoint
= inf_status
->stepping_over_breakpoint
;
4407 step_range_start
= inf_status
->step_range_start
;
4408 step_range_end
= inf_status
->step_range_end
;
4409 step_frame_id
= inf_status
->step_frame_id
;
4410 step_over_calls
= inf_status
->step_over_calls
;
4411 stop_after_trap
= inf_status
->stop_after_trap
;
4412 stop_soon
= inf_status
->stop_soon
;
4413 bpstat_clear (&stop_bpstat
);
4414 stop_bpstat
= inf_status
->stop_bpstat
;
4415 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4416 proceed_to_finish
= inf_status
->proceed_to_finish
;
4418 /* The inferior can be gone if the user types "print exit(0)"
4419 (and perhaps other times). */
4420 if (target_has_execution
)
4421 /* NB: The register write goes through to the target. */
4422 regcache_cpy (get_current_regcache (), inf_status
->registers
);
4423 regcache_xfree (inf_status
->registers
);
4425 /* FIXME: If we are being called after stopping in a function which
4426 is called from gdb, we should not be trying to restore the
4427 selected frame; it just prints a spurious error message (The
4428 message is useful, however, in detecting bugs in gdb (like if gdb
4429 clobbers the stack)). In fact, should we be restoring the
4430 inferior status at all in that case? . */
4432 if (target_has_stack
&& inf_status
->restore_stack_info
)
4434 /* The point of catch_errors is that if the stack is clobbered,
4435 walking the stack might encounter a garbage pointer and
4436 error() trying to dereference it. */
4438 (restore_selected_frame
, &inf_status
->selected_frame_id
,
4439 "Unable to restore previously selected frame:\n",
4440 RETURN_MASK_ERROR
) == 0)
4441 /* Error in restoring the selected frame. Select the innermost
4443 select_frame (get_current_frame ());
4451 do_restore_inferior_status_cleanup (void *sts
)
4453 restore_inferior_status (sts
);
4457 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4459 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4463 discard_inferior_status (struct inferior_status
*inf_status
)
4465 /* See save_inferior_status for info on stop_bpstat. */
4466 bpstat_clear (&inf_status
->stop_bpstat
);
4467 regcache_xfree (inf_status
->registers
);
4472 inferior_has_forked (ptid_t pid
, ptid_t
*child_pid
)
4474 struct target_waitstatus last
;
4477 get_last_target_status (&last_ptid
, &last
);
4479 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
4482 if (!ptid_equal (last_ptid
, pid
))
4485 *child_pid
= last
.value
.related_pid
;
4490 inferior_has_vforked (ptid_t pid
, ptid_t
*child_pid
)
4492 struct target_waitstatus last
;
4495 get_last_target_status (&last_ptid
, &last
);
4497 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
4500 if (!ptid_equal (last_ptid
, pid
))
4503 *child_pid
= last
.value
.related_pid
;
4508 inferior_has_execd (ptid_t pid
, char **execd_pathname
)
4510 struct target_waitstatus last
;
4513 get_last_target_status (&last_ptid
, &last
);
4515 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
4518 if (!ptid_equal (last_ptid
, pid
))
4521 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
4525 /* Oft used ptids */
4527 ptid_t minus_one_ptid
;
4529 /* Create a ptid given the necessary PID, LWP, and TID components. */
4532 ptid_build (int pid
, long lwp
, long tid
)
4542 /* Create a ptid from just a pid. */
4545 pid_to_ptid (int pid
)
4547 return ptid_build (pid
, 0, 0);
4550 /* Fetch the pid (process id) component from a ptid. */
4553 ptid_get_pid (ptid_t ptid
)
4558 /* Fetch the lwp (lightweight process) component from a ptid. */
4561 ptid_get_lwp (ptid_t ptid
)
4566 /* Fetch the tid (thread id) component from a ptid. */
4569 ptid_get_tid (ptid_t ptid
)
4574 /* ptid_equal() is used to test equality of two ptids. */
4577 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4579 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4580 && ptid1
.tid
== ptid2
.tid
);
4583 /* restore_inferior_ptid() will be used by the cleanup machinery
4584 to restore the inferior_ptid value saved in a call to
4585 save_inferior_ptid(). */
4588 restore_inferior_ptid (void *arg
)
4590 ptid_t
*saved_ptid_ptr
= arg
;
4591 inferior_ptid
= *saved_ptid_ptr
;
4595 /* Save the value of inferior_ptid so that it may be restored by a
4596 later call to do_cleanups(). Returns the struct cleanup pointer
4597 needed for later doing the cleanup. */
4600 save_inferior_ptid (void)
4602 ptid_t
*saved_ptid_ptr
;
4604 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4605 *saved_ptid_ptr
= inferior_ptid
;
4606 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4611 static int non_stop_1
= 0;
4614 set_non_stop (char *args
, int from_tty
,
4615 struct cmd_list_element
*c
)
4617 if (target_has_execution
)
4619 non_stop_1
= non_stop
;
4620 error (_("Cannot change this setting while the inferior is running."));
4623 non_stop
= non_stop_1
;
4627 show_non_stop (struct ui_file
*file
, int from_tty
,
4628 struct cmd_list_element
*c
, const char *value
)
4630 fprintf_filtered (file
,
4631 _("Controlling the inferior in non-stop mode is %s.\n"),
4637 _initialize_infrun (void)
4641 struct cmd_list_element
*c
;
4643 add_info ("signals", signals_info
, _("\
4644 What debugger does when program gets various signals.\n\
4645 Specify a signal as argument to print info on that signal only."));
4646 add_info_alias ("handle", "signals", 0);
4648 add_com ("handle", class_run
, handle_command
, _("\
4649 Specify how to handle a signal.\n\
4650 Args are signals and actions to apply to those signals.\n\
4651 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4652 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4653 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4654 The special arg \"all\" is recognized to mean all signals except those\n\
4655 used by the debugger, typically SIGTRAP and SIGINT.\n\
4656 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4657 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4658 Stop means reenter debugger if this signal happens (implies print).\n\
4659 Print means print a message if this signal happens.\n\
4660 Pass means let program see this signal; otherwise program doesn't know.\n\
4661 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4662 Pass and Stop may be combined."));
4665 add_com ("lz", class_info
, signals_info
, _("\
4666 What debugger does when program gets various signals.\n\
4667 Specify a signal as argument to print info on that signal only."));
4668 add_com ("z", class_run
, xdb_handle_command
, _("\
4669 Specify how to handle a signal.\n\
4670 Args are signals and actions to apply to those signals.\n\
4671 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4672 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4673 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4674 The special arg \"all\" is recognized to mean all signals except those\n\
4675 used by the debugger, typically SIGTRAP and SIGINT.\n\
4676 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4677 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4678 nopass), \"Q\" (noprint)\n\
4679 Stop means reenter debugger if this signal happens (implies print).\n\
4680 Print means print a message if this signal happens.\n\
4681 Pass means let program see this signal; otherwise program doesn't know.\n\
4682 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4683 Pass and Stop may be combined."));
4687 stop_command
= add_cmd ("stop", class_obscure
,
4688 not_just_help_class_command
, _("\
4689 There is no `stop' command, but you can set a hook on `stop'.\n\
4690 This allows you to set a list of commands to be run each time execution\n\
4691 of the program stops."), &cmdlist
);
4693 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
4694 Set inferior debugging."), _("\
4695 Show inferior debugging."), _("\
4696 When non-zero, inferior specific debugging is enabled."),
4699 &setdebuglist
, &showdebuglist
);
4701 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
4702 Set displaced stepping debugging."), _("\
4703 Show displaced stepping debugging."), _("\
4704 When non-zero, displaced stepping specific debugging is enabled."),
4706 show_debug_displaced
,
4707 &setdebuglist
, &showdebuglist
);
4709 add_setshow_boolean_cmd ("non-stop", no_class
,
4711 Set whether gdb controls the inferior in non-stop mode."), _("\
4712 Show whether gdb controls the inferior in non-stop mode."), _("\
4713 When debugging a multi-threaded program and this setting is\n\
4714 off (the default, also called all-stop mode), when one thread stops\n\
4715 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
4716 all other threads in the program while you interact with the thread of\n\
4717 interest. When you continue or step a thread, you can allow the other\n\
4718 threads to run, or have them remain stopped, but while you inspect any\n\
4719 thread's state, all threads stop.\n\
4721 In non-stop mode, when one thread stops, other threads can continue\n\
4722 to run freely. You'll be able to step each thread independently,\n\
4723 leave it stopped or free to run as needed."),
4729 numsigs
= (int) TARGET_SIGNAL_LAST
;
4730 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4731 signal_print
= (unsigned char *)
4732 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4733 signal_program
= (unsigned char *)
4734 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4735 for (i
= 0; i
< numsigs
; i
++)
4738 signal_print
[i
] = 1;
4739 signal_program
[i
] = 1;
4742 /* Signals caused by debugger's own actions
4743 should not be given to the program afterwards. */
4744 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4745 signal_program
[TARGET_SIGNAL_INT
] = 0;
4747 /* Signals that are not errors should not normally enter the debugger. */
4748 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4749 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4750 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4751 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4752 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4753 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4754 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4755 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4756 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4757 signal_print
[TARGET_SIGNAL_IO
] = 0;
4758 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4759 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4760 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4761 signal_print
[TARGET_SIGNAL_URG
] = 0;
4762 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4763 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4765 /* These signals are used internally by user-level thread
4766 implementations. (See signal(5) on Solaris.) Like the above
4767 signals, a healthy program receives and handles them as part of
4768 its normal operation. */
4769 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4770 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4771 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4772 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4773 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4774 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4776 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
4777 &stop_on_solib_events
, _("\
4778 Set stopping for shared library events."), _("\
4779 Show stopping for shared library events."), _("\
4780 If nonzero, gdb will give control to the user when the dynamic linker\n\
4781 notifies gdb of shared library events. The most common event of interest\n\
4782 to the user would be loading/unloading of a new library."),
4784 show_stop_on_solib_events
,
4785 &setlist
, &showlist
);
4787 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
4788 follow_fork_mode_kind_names
,
4789 &follow_fork_mode_string
, _("\
4790 Set debugger response to a program call of fork or vfork."), _("\
4791 Show debugger response to a program call of fork or vfork."), _("\
4792 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4793 parent - the original process is debugged after a fork\n\
4794 child - the new process is debugged after a fork\n\
4795 The unfollowed process will continue to run.\n\
4796 By default, the debugger will follow the parent process."),
4798 show_follow_fork_mode_string
,
4799 &setlist
, &showlist
);
4801 add_setshow_enum_cmd ("scheduler-locking", class_run
,
4802 scheduler_enums
, &scheduler_mode
, _("\
4803 Set mode for locking scheduler during execution."), _("\
4804 Show mode for locking scheduler during execution."), _("\
4805 off == no locking (threads may preempt at any time)\n\
4806 on == full locking (no thread except the current thread may run)\n\
4807 step == scheduler locked during every single-step operation.\n\
4808 In this mode, no other thread may run during a step command.\n\
4809 Other threads may run while stepping over a function call ('next')."),
4810 set_schedlock_func
, /* traps on target vector */
4811 show_scheduler_mode
,
4812 &setlist
, &showlist
);
4814 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
4815 Set mode of the step operation."), _("\
4816 Show mode of the step operation."), _("\
4817 When set, doing a step over a function without debug line information\n\
4818 will stop at the first instruction of that function. Otherwise, the\n\
4819 function is skipped and the step command stops at a different source line."),
4821 show_step_stop_if_no_debug
,
4822 &setlist
, &showlist
);
4824 add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance
,
4825 &can_use_displaced_stepping
, _("\
4826 Set debugger's willingness to use displaced stepping."), _("\
4827 Show debugger's willingness to use displaced stepping."), _("\
4828 If zero, gdb will not use displaced stepping to step over\n\
4829 breakpoints, even if such is supported by the target."),
4831 show_can_use_displaced_stepping
,
4832 &maintenance_set_cmdlist
,
4833 &maintenance_show_cmdlist
);
4835 /* ptid initializations */
4836 null_ptid
= ptid_build (0, 0, 0);
4837 minus_one_ptid
= ptid_build (-1, 0, 0);
4838 inferior_ptid
= null_ptid
;
4839 target_last_wait_ptid
= minus_one_ptid
;
4840 displaced_step_ptid
= null_ptid
;