1 /* Target-struct-independent code to start (run) and stop an inferior
4 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
5 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
6 2008 Free Software Foundation, Inc.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "gdb_string.h"
29 #include "exceptions.h"
30 #include "breakpoint.h"
34 #include "cli/cli-script.h"
36 #include "gdbthread.h"
49 #include "gdb_assert.h"
50 #include "mi/mi-common.h"
52 /* Prototypes for local functions */
54 static void signals_info (char *, int);
56 static void handle_command (char *, int);
58 static void sig_print_info (enum target_signal
);
60 static void sig_print_header (void);
62 static void resume_cleanups (void *);
64 static int hook_stop_stub (void *);
66 static int restore_selected_frame (void *);
68 static void build_infrun (void);
70 static int follow_fork (void);
72 static void set_schedlock_func (char *args
, int from_tty
,
73 struct cmd_list_element
*c
);
75 struct execution_control_state
;
77 static int currently_stepping (struct execution_control_state
*ecs
);
79 static void xdb_handle_command (char *args
, int from_tty
);
81 static int prepare_to_proceed (int);
83 void _initialize_infrun (void);
85 /* When set, stop the 'step' command if we enter a function which has
86 no line number information. The normal behavior is that we step
87 over such function. */
88 int step_stop_if_no_debug
= 0;
90 show_step_stop_if_no_debug (struct ui_file
*file
, int from_tty
,
91 struct cmd_list_element
*c
, const char *value
)
93 fprintf_filtered (file
, _("Mode of the step operation is %s.\n"), value
);
96 /* In asynchronous mode, but simulating synchronous execution. */
98 int sync_execution
= 0;
100 /* wait_for_inferior and normal_stop use this to notify the user
101 when the inferior stopped in a different thread than it had been
104 static ptid_t previous_inferior_ptid
;
106 int debug_displaced
= 0;
108 show_debug_displaced (struct ui_file
*file
, int from_tty
,
109 struct cmd_list_element
*c
, const char *value
)
111 fprintf_filtered (file
, _("Displace stepping debugging is %s.\n"), value
);
114 static int debug_infrun
= 0;
116 show_debug_infrun (struct ui_file
*file
, int from_tty
,
117 struct cmd_list_element
*c
, const char *value
)
119 fprintf_filtered (file
, _("Inferior debugging is %s.\n"), value
);
122 /* If the program uses ELF-style shared libraries, then calls to
123 functions in shared libraries go through stubs, which live in a
124 table called the PLT (Procedure Linkage Table). The first time the
125 function is called, the stub sends control to the dynamic linker,
126 which looks up the function's real address, patches the stub so
127 that future calls will go directly to the function, and then passes
128 control to the function.
130 If we are stepping at the source level, we don't want to see any of
131 this --- we just want to skip over the stub and the dynamic linker.
132 The simple approach is to single-step until control leaves the
135 However, on some systems (e.g., Red Hat's 5.2 distribution) the
136 dynamic linker calls functions in the shared C library, so you
137 can't tell from the PC alone whether the dynamic linker is still
138 running. In this case, we use a step-resume breakpoint to get us
139 past the dynamic linker, as if we were using "next" to step over a
142 IN_SOLIB_DYNSYM_RESOLVE_CODE says whether we're in the dynamic
143 linker code or not. Normally, this means we single-step. However,
144 if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an
145 address where we can place a step-resume breakpoint to get past the
146 linker's symbol resolution function.
148 IN_SOLIB_DYNSYM_RESOLVE_CODE can generally be implemented in a
149 pretty portable way, by comparing the PC against the address ranges
150 of the dynamic linker's sections.
152 SKIP_SOLIB_RESOLVER is generally going to be system-specific, since
153 it depends on internal details of the dynamic linker. It's usually
154 not too hard to figure out where to put a breakpoint, but it
155 certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of
156 sanity checking. If it can't figure things out, returning zero and
157 getting the (possibly confusing) stepping behavior is better than
158 signalling an error, which will obscure the change in the
161 /* This function returns TRUE if pc is the address of an instruction
162 that lies within the dynamic linker (such as the event hook, or the
165 This function must be used only when a dynamic linker event has
166 been caught, and the inferior is being stepped out of the hook, or
167 undefined results are guaranteed. */
169 #ifndef SOLIB_IN_DYNAMIC_LINKER
170 #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0
174 /* Convert the #defines into values. This is temporary until wfi control
175 flow is completely sorted out. */
177 #ifndef CANNOT_STEP_HW_WATCHPOINTS
178 #define CANNOT_STEP_HW_WATCHPOINTS 0
180 #undef CANNOT_STEP_HW_WATCHPOINTS
181 #define CANNOT_STEP_HW_WATCHPOINTS 1
184 /* Tables of how to react to signals; the user sets them. */
186 static unsigned char *signal_stop
;
187 static unsigned char *signal_print
;
188 static unsigned char *signal_program
;
190 #define SET_SIGS(nsigs,sigs,flags) \
192 int signum = (nsigs); \
193 while (signum-- > 0) \
194 if ((sigs)[signum]) \
195 (flags)[signum] = 1; \
198 #define UNSET_SIGS(nsigs,sigs,flags) \
200 int signum = (nsigs); \
201 while (signum-- > 0) \
202 if ((sigs)[signum]) \
203 (flags)[signum] = 0; \
206 /* Value to pass to target_resume() to cause all threads to resume */
208 #define RESUME_ALL (pid_to_ptid (-1))
210 /* Command list pointer for the "stop" placeholder. */
212 static struct cmd_list_element
*stop_command
;
214 /* Function inferior was in as of last step command. */
216 static struct symbol
*step_start_function
;
218 /* Nonzero if we are presently stepping over a breakpoint.
220 If we hit a breakpoint or watchpoint, and then continue,
221 we need to single step the current thread with breakpoints
222 disabled, to avoid hitting the same breakpoint or
223 watchpoint again. And we should step just a single
224 thread and keep other threads stopped, so that
225 other threads don't miss breakpoints while they are removed.
227 So, this variable simultaneously means that we need to single
228 step the current thread, keep other threads stopped, and that
229 breakpoints should be removed while we step.
231 This variable is set either:
232 - in proceed, when we resume inferior on user's explicit request
233 - in keep_going, if handle_inferior_event decides we need to
234 step over breakpoint.
236 The variable is cleared in clear_proceed_status, called every
237 time before we call proceed. The proceed calls wait_for_inferior,
238 which calls handle_inferior_event in a loop, and until
239 wait_for_inferior exits, this variable is changed only by keep_going. */
241 static int stepping_over_breakpoint
;
243 /* Nonzero if we want to give control to the user when we're notified
244 of shared library events by the dynamic linker. */
245 static int stop_on_solib_events
;
247 show_stop_on_solib_events (struct ui_file
*file
, int from_tty
,
248 struct cmd_list_element
*c
, const char *value
)
250 fprintf_filtered (file
, _("Stopping for shared library events is %s.\n"),
254 /* Nonzero means expecting a trace trap
255 and should stop the inferior and return silently when it happens. */
259 /* Nonzero means expecting a trap and caller will handle it themselves.
260 It is used after attach, due to attaching to a process;
261 when running in the shell before the child program has been exec'd;
262 and when running some kinds of remote stuff (FIXME?). */
264 enum stop_kind stop_soon
;
266 /* Nonzero if proceed is being used for a "finish" command or a similar
267 situation when stop_registers should be saved. */
269 int proceed_to_finish
;
271 /* Save register contents here when about to pop a stack dummy frame,
272 if-and-only-if proceed_to_finish is set.
273 Thus this contains the return value from the called function (assuming
274 values are returned in a register). */
276 struct regcache
*stop_registers
;
278 /* Nonzero after stop if current stack frame should be printed. */
280 static int stop_print_frame
;
282 static struct breakpoint
*step_resume_breakpoint
= NULL
;
284 /* This is a cached copy of the pid/waitstatus of the last event
285 returned by target_wait()/deprecated_target_wait_hook(). This
286 information is returned by get_last_target_status(). */
287 static ptid_t target_last_wait_ptid
;
288 static struct target_waitstatus target_last_waitstatus
;
290 /* This is used to remember when a fork, vfork or exec event
291 was caught by a catchpoint, and thus the event is to be
292 followed at the next resume of the inferior, and not
296 enum target_waitkind kind
;
303 char *execd_pathname
;
307 static const char follow_fork_mode_child
[] = "child";
308 static const char follow_fork_mode_parent
[] = "parent";
310 static const char *follow_fork_mode_kind_names
[] = {
311 follow_fork_mode_child
,
312 follow_fork_mode_parent
,
316 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
318 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
319 struct cmd_list_element
*c
, const char *value
)
321 fprintf_filtered (file
, _("\
322 Debugger response to a program call of fork or vfork is \"%s\".\n"),
330 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
332 return target_follow_fork (follow_child
);
336 follow_inferior_reset_breakpoints (void)
338 /* Was there a step_resume breakpoint? (There was if the user
339 did a "next" at the fork() call.) If so, explicitly reset its
342 step_resumes are a form of bp that are made to be per-thread.
343 Since we created the step_resume bp when the parent process
344 was being debugged, and now are switching to the child process,
345 from the breakpoint package's viewpoint, that's a switch of
346 "threads". We must update the bp's notion of which thread
347 it is for, or it'll be ignored when it triggers. */
349 if (step_resume_breakpoint
)
350 breakpoint_re_set_thread (step_resume_breakpoint
);
352 /* Reinsert all breakpoints in the child. The user may have set
353 breakpoints after catching the fork, in which case those
354 were never set in the child, but only in the parent. This makes
355 sure the inserted breakpoints match the breakpoint list. */
357 breakpoint_re_set ();
358 insert_breakpoints ();
361 /* EXECD_PATHNAME is assumed to be non-NULL. */
364 follow_exec (int pid
, char *execd_pathname
)
367 struct target_ops
*tgt
;
369 /* This is an exec event that we actually wish to pay attention to.
370 Refresh our symbol table to the newly exec'd program, remove any
373 If there are breakpoints, they aren't really inserted now,
374 since the exec() transformed our inferior into a fresh set
377 We want to preserve symbolic breakpoints on the list, since
378 we have hopes that they can be reset after the new a.out's
379 symbol table is read.
381 However, any "raw" breakpoints must be removed from the list
382 (e.g., the solib bp's), since their address is probably invalid
385 And, we DON'T want to call delete_breakpoints() here, since
386 that may write the bp's "shadow contents" (the instruction
387 value that was overwritten witha TRAP instruction). Since
388 we now have a new a.out, those shadow contents aren't valid. */
389 update_breakpoints_after_exec ();
391 /* If there was one, it's gone now. We cannot truly step-to-next
392 statement through an exec(). */
393 step_resume_breakpoint
= NULL
;
394 step_range_start
= 0;
397 /* What is this a.out's name? */
398 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
400 /* We've followed the inferior through an exec. Therefore, the
401 inferior has essentially been killed & reborn. */
403 gdb_flush (gdb_stdout
);
404 generic_mourn_inferior ();
405 /* Because mourn_inferior resets inferior_ptid. */
406 inferior_ptid
= pid_to_ptid (saved_pid
);
408 if (gdb_sysroot
&& *gdb_sysroot
)
410 char *name
= alloca (strlen (gdb_sysroot
)
411 + strlen (execd_pathname
)
413 strcpy (name
, gdb_sysroot
);
414 strcat (name
, execd_pathname
);
415 execd_pathname
= name
;
418 /* That a.out is now the one to use. */
419 exec_file_attach (execd_pathname
, 0);
421 /* And also is where symbols can be found. */
422 symbol_file_add_main (execd_pathname
, 0);
424 /* Reset the shared library package. This ensures that we get
425 a shlib event when the child reaches "_start", at which point
426 the dld will have had a chance to initialize the child. */
427 no_shared_libraries (NULL
, 0);
428 #ifdef SOLIB_CREATE_INFERIOR_HOOK
429 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
431 solib_create_inferior_hook ();
434 /* Reinsert all breakpoints. (Those which were symbolic have
435 been reset to the proper address in the new a.out, thanks
436 to symbol_file_command...) */
437 insert_breakpoints ();
439 /* The next resume of this inferior should bring it to the shlib
440 startup breakpoints. (If the user had also set bp's on
441 "main" from the old (parent) process, then they'll auto-
442 matically get reset there in the new process.) */
445 /* Non-zero if we just simulating a single-step. This is needed
446 because we cannot remove the breakpoints in the inferior process
447 until after the `wait' in `wait_for_inferior'. */
448 static int singlestep_breakpoints_inserted_p
= 0;
450 /* The thread we inserted single-step breakpoints for. */
451 static ptid_t singlestep_ptid
;
453 /* PC when we started this single-step. */
454 static CORE_ADDR singlestep_pc
;
456 /* If another thread hit the singlestep breakpoint, we save the original
457 thread here so that we can resume single-stepping it later. */
458 static ptid_t saved_singlestep_ptid
;
459 static int stepping_past_singlestep_breakpoint
;
461 /* If not equal to null_ptid, this means that after stepping over breakpoint
462 is finished, we need to switch to deferred_step_ptid, and step it.
464 The use case is when one thread has hit a breakpoint, and then the user
465 has switched to another thread and issued 'step'. We need to step over
466 breakpoint in the thread which hit the breakpoint, but then continue
467 stepping the thread user has selected. */
468 static ptid_t deferred_step_ptid
;
470 /* Displaced stepping. */
472 /* In non-stop debugging mode, we must take special care to manage
473 breakpoints properly; in particular, the traditional strategy for
474 stepping a thread past a breakpoint it has hit is unsuitable.
475 'Displaced stepping' is a tactic for stepping one thread past a
476 breakpoint it has hit while ensuring that other threads running
477 concurrently will hit the breakpoint as they should.
479 The traditional way to step a thread T off a breakpoint in a
480 multi-threaded program in all-stop mode is as follows:
482 a0) Initially, all threads are stopped, and breakpoints are not
484 a1) We single-step T, leaving breakpoints uninserted.
485 a2) We insert breakpoints, and resume all threads.
487 In non-stop debugging, however, this strategy is unsuitable: we
488 don't want to have to stop all threads in the system in order to
489 continue or step T past a breakpoint. Instead, we use displaced
492 n0) Initially, T is stopped, other threads are running, and
493 breakpoints are inserted.
494 n1) We copy the instruction "under" the breakpoint to a separate
495 location, outside the main code stream, making any adjustments
496 to the instruction, register, and memory state as directed by
498 n2) We single-step T over the instruction at its new location.
499 n3) We adjust the resulting register and memory state as directed
500 by T's architecture. This includes resetting T's PC to point
501 back into the main instruction stream.
504 This approach depends on the following gdbarch methods:
506 - gdbarch_max_insn_length and gdbarch_displaced_step_location
507 indicate where to copy the instruction, and how much space must
508 be reserved there. We use these in step n1.
510 - gdbarch_displaced_step_copy_insn copies a instruction to a new
511 address, and makes any necessary adjustments to the instruction,
512 register contents, and memory. We use this in step n1.
514 - gdbarch_displaced_step_fixup adjusts registers and memory after
515 we have successfuly single-stepped the instruction, to yield the
516 same effect the instruction would have had if we had executed it
517 at its original address. We use this in step n3.
519 - gdbarch_displaced_step_free_closure provides cleanup.
521 The gdbarch_displaced_step_copy_insn and
522 gdbarch_displaced_step_fixup functions must be written so that
523 copying an instruction with gdbarch_displaced_step_copy_insn,
524 single-stepping across the copied instruction, and then applying
525 gdbarch_displaced_insn_fixup should have the same effects on the
526 thread's memory and registers as stepping the instruction in place
527 would have. Exactly which responsibilities fall to the copy and
528 which fall to the fixup is up to the author of those functions.
530 See the comments in gdbarch.sh for details.
532 Note that displaced stepping and software single-step cannot
533 currently be used in combination, although with some care I think
534 they could be made to. Software single-step works by placing
535 breakpoints on all possible subsequent instructions; if the
536 displaced instruction is a PC-relative jump, those breakpoints
537 could fall in very strange places --- on pages that aren't
538 executable, or at addresses that are not proper instruction
539 boundaries. (We do generally let other threads run while we wait
540 to hit the software single-step breakpoint, and they might
541 encounter such a corrupted instruction.) One way to work around
542 this would be to have gdbarch_displaced_step_copy_insn fully
543 simulate the effect of PC-relative instructions (and return NULL)
544 on architectures that use software single-stepping.
546 In non-stop mode, we can have independent and simultaneous step
547 requests, so more than one thread may need to simultaneously step
548 over a breakpoint. The current implementation assumes there is
549 only one scratch space per process. In this case, we have to
550 serialize access to the scratch space. If thread A wants to step
551 over a breakpoint, but we are currently waiting for some other
552 thread to complete a displaced step, we leave thread A stopped and
553 place it in the displaced_step_request_queue. Whenever a displaced
554 step finishes, we pick the next thread in the queue and start a new
555 displaced step operation on it. See displaced_step_prepare and
556 displaced_step_fixup for details. */
558 /* If this is not null_ptid, this is the thread carrying out a
559 displaced single-step. This thread's state will require fixing up
560 once it has completed its step. */
561 static ptid_t displaced_step_ptid
;
563 struct displaced_step_request
566 struct displaced_step_request
*next
;
569 /* A queue of pending displaced stepping requests. */
570 struct displaced_step_request
*displaced_step_request_queue
;
572 /* The architecture the thread had when we stepped it. */
573 static struct gdbarch
*displaced_step_gdbarch
;
575 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
576 for post-step cleanup. */
577 static struct displaced_step_closure
*displaced_step_closure
;
579 /* The address of the original instruction, and the copy we made. */
580 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
582 /* Saved contents of copy area. */
583 static gdb_byte
*displaced_step_saved_copy
;
585 /* When this is non-zero, we are allowed to use displaced stepping, if
586 the architecture supports it. When this is zero, we use
587 traditional the hold-and-step approach. */
588 int can_use_displaced_stepping
= 1;
590 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
591 struct cmd_list_element
*c
,
594 fprintf_filtered (file
, _("\
595 Debugger's willingness to use displaced stepping to step over "
596 "breakpoints is %s.\n"), value
);
599 /* Return non-zero if displaced stepping is enabled, and can be used
602 use_displaced_stepping (struct gdbarch
*gdbarch
)
604 return (can_use_displaced_stepping
605 && gdbarch_displaced_step_copy_insn_p (gdbarch
));
608 /* Clean out any stray displaced stepping state. */
610 displaced_step_clear (void)
612 /* Indicate that there is no cleanup pending. */
613 displaced_step_ptid
= null_ptid
;
615 if (displaced_step_closure
)
617 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
618 displaced_step_closure
);
619 displaced_step_closure
= NULL
;
624 cleanup_displaced_step_closure (void *ptr
)
626 struct displaced_step_closure
*closure
= ptr
;
628 gdbarch_displaced_step_free_closure (current_gdbarch
, closure
);
631 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
633 displaced_step_dump_bytes (struct ui_file
*file
,
639 for (i
= 0; i
< len
; i
++)
640 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
641 fputs_unfiltered ("\n", file
);
644 /* Prepare to single-step, using displaced stepping.
646 Note that we cannot use displaced stepping when we have a signal to
647 deliver. If we have a signal to deliver and an instruction to step
648 over, then after the step, there will be no indication from the
649 target whether the thread entered a signal handler or ignored the
650 signal and stepped over the instruction successfully --- both cases
651 result in a simple SIGTRAP. In the first case we mustn't do a
652 fixup, and in the second case we must --- but we can't tell which.
653 Comments in the code for 'random signals' in handle_inferior_event
654 explain how we handle this case instead.
656 Returns 1 if preparing was successful -- this thread is going to be
657 stepped now; or 0 if displaced stepping this thread got queued. */
659 displaced_step_prepare (ptid_t ptid
)
661 struct cleanup
*old_cleanups
;
662 struct regcache
*regcache
= get_thread_regcache (ptid
);
663 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
664 CORE_ADDR original
, copy
;
666 struct displaced_step_closure
*closure
;
668 /* We should never reach this function if the architecture does not
669 support displaced stepping. */
670 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
672 /* For the first cut, we're displaced stepping one thread at a
675 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
677 /* Already waiting for a displaced step to finish. Defer this
678 request and place in queue. */
679 struct displaced_step_request
*req
, *new_req
;
682 fprintf_unfiltered (gdb_stdlog
,
683 "displaced: defering step of %s\n",
684 target_pid_to_str (ptid
));
686 new_req
= xmalloc (sizeof (*new_req
));
687 new_req
->ptid
= ptid
;
688 new_req
->next
= NULL
;
690 if (displaced_step_request_queue
)
692 for (req
= displaced_step_request_queue
;
699 displaced_step_request_queue
= new_req
;
706 fprintf_unfiltered (gdb_stdlog
,
707 "displaced: stepping %s now\n",
708 target_pid_to_str (ptid
));
711 displaced_step_clear ();
713 original
= read_pc_pid (ptid
);
715 copy
= gdbarch_displaced_step_location (gdbarch
);
716 len
= gdbarch_max_insn_length (gdbarch
);
718 /* Save the original contents of the copy area. */
719 displaced_step_saved_copy
= xmalloc (len
);
720 old_cleanups
= make_cleanup (free_current_contents
,
721 &displaced_step_saved_copy
);
722 read_memory (copy
, displaced_step_saved_copy
, len
);
725 fprintf_unfiltered (gdb_stdlog
, "displaced: saved 0x%s: ",
727 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
730 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
731 original
, copy
, regcache
);
733 /* We don't support the fully-simulated case at present. */
734 gdb_assert (closure
);
736 make_cleanup (cleanup_displaced_step_closure
, closure
);
738 /* Resume execution at the copy. */
739 write_pc_pid (copy
, ptid
);
741 discard_cleanups (old_cleanups
);
744 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to 0x%s\n",
747 /* Save the information we need to fix things up if the step
749 displaced_step_ptid
= ptid
;
750 displaced_step_gdbarch
= gdbarch
;
751 displaced_step_closure
= closure
;
752 displaced_step_original
= original
;
753 displaced_step_copy
= copy
;
758 displaced_step_clear_cleanup (void *ignore
)
760 displaced_step_clear ();
764 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
766 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
767 inferior_ptid
= ptid
;
768 write_memory (memaddr
, myaddr
, len
);
769 do_cleanups (ptid_cleanup
);
773 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
775 struct cleanup
*old_cleanups
;
777 /* Was this event for the pid we displaced? */
778 if (ptid_equal (displaced_step_ptid
, null_ptid
)
779 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
782 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
784 /* Restore the contents of the copy area. */
786 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
787 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
788 displaced_step_saved_copy
, len
);
790 fprintf_unfiltered (gdb_stdlog
, "displaced: restored 0x%s\n",
791 paddr_nz (displaced_step_copy
));
794 /* Did the instruction complete successfully? */
795 if (signal
== TARGET_SIGNAL_TRAP
)
797 /* Fix up the resulting state. */
798 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
799 displaced_step_closure
,
800 displaced_step_original
,
802 get_thread_regcache (displaced_step_ptid
));
806 /* Since the instruction didn't complete, all we can do is
808 CORE_ADDR pc
= read_pc_pid (event_ptid
);
809 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
810 write_pc_pid (pc
, event_ptid
);
813 do_cleanups (old_cleanups
);
815 /* Are there any pending displaced stepping requests? If so, run
817 if (displaced_step_request_queue
)
819 struct displaced_step_request
*head
;
822 head
= displaced_step_request_queue
;
824 displaced_step_request_queue
= head
->next
;
828 fprintf_unfiltered (gdb_stdlog
,
829 "displaced: stepping queued %s now\n",
830 target_pid_to_str (ptid
));
833 displaced_step_ptid
= null_ptid
;
834 displaced_step_prepare (ptid
);
835 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
842 /* Things to clean up if we QUIT out of resume (). */
844 resume_cleanups (void *ignore
)
849 static const char schedlock_off
[] = "off";
850 static const char schedlock_on
[] = "on";
851 static const char schedlock_step
[] = "step";
852 static const char *scheduler_enums
[] = {
858 static const char *scheduler_mode
= schedlock_off
;
860 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
861 struct cmd_list_element
*c
, const char *value
)
863 fprintf_filtered (file
, _("\
864 Mode for locking scheduler during execution is \"%s\".\n"),
869 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
871 if (!target_can_lock_scheduler
)
873 scheduler_mode
= schedlock_off
;
874 error (_("Target '%s' cannot support this command."), target_shortname
);
879 /* Resume the inferior, but allow a QUIT. This is useful if the user
880 wants to interrupt some lengthy single-stepping operation
881 (for child processes, the SIGINT goes to the inferior, and so
882 we get a SIGINT random_signal, but for remote debugging and perhaps
883 other targets, that's not true).
885 STEP nonzero if we should step (zero to continue instead).
886 SIG is the signal to give the inferior (zero for none). */
888 resume (int step
, enum target_signal sig
)
890 int should_resume
= 1;
891 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
892 CORE_ADDR pc
= read_pc ();
896 fprintf_unfiltered (gdb_stdlog
,
897 "infrun: resume (step=%d, signal=%d), "
898 "stepping_over_breakpoint=%d\n",
899 step
, sig
, stepping_over_breakpoint
);
901 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
902 over an instruction that causes a page fault without triggering
903 a hardware watchpoint. The kernel properly notices that it shouldn't
904 stop, because the hardware watchpoint is not triggered, but it forgets
905 the step request and continues the program normally.
906 Work around the problem by removing hardware watchpoints if a step is
907 requested, GDB will check for a hardware watchpoint trigger after the
909 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
910 remove_hw_watchpoints ();
913 /* Normally, by the time we reach `resume', the breakpoints are either
914 removed or inserted, as appropriate. The exception is if we're sitting
915 at a permanent breakpoint; we need to step over it, but permanent
916 breakpoints can't be removed. So we have to test for it here. */
917 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
919 if (gdbarch_skip_permanent_breakpoint_p (current_gdbarch
))
920 gdbarch_skip_permanent_breakpoint (current_gdbarch
,
921 get_current_regcache ());
924 The program is stopped at a permanent breakpoint, but GDB does not know\n\
925 how to step past a permanent breakpoint on this architecture. Try using\n\
926 a command like `return' or `jump' to continue execution."));
929 /* If enabled, step over breakpoints by executing a copy of the
930 instruction at a different address.
932 We can't use displaced stepping when we have a signal to deliver;
933 the comments for displaced_step_prepare explain why. The
934 comments in the handle_inferior event for dealing with 'random
935 signals' explain what we do instead. */
936 if (use_displaced_stepping (current_gdbarch
)
937 && stepping_over_breakpoint
938 && sig
== TARGET_SIGNAL_0
)
940 if (!displaced_step_prepare (inferior_ptid
))
941 /* Got placed in displaced stepping queue. Will be resumed
942 later when all the currently queued displaced stepping
947 if (step
&& gdbarch_software_single_step_p (current_gdbarch
))
949 /* Do it the hard way, w/temp breakpoints */
950 if (gdbarch_software_single_step (current_gdbarch
, get_current_frame ()))
952 /* ...and don't ask hardware to do it. */
954 /* and do not pull these breakpoints until after a `wait' in
955 `wait_for_inferior' */
956 singlestep_breakpoints_inserted_p
= 1;
957 singlestep_ptid
= inferior_ptid
;
962 /* If there were any forks/vforks/execs that were caught and are
963 now to be followed, then do so. */
964 switch (pending_follow
.kind
)
966 case TARGET_WAITKIND_FORKED
:
967 case TARGET_WAITKIND_VFORKED
:
968 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
973 case TARGET_WAITKIND_EXECD
:
974 /* follow_exec is called as soon as the exec event is seen. */
975 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
982 /* Install inferior's terminal modes. */
983 target_terminal_inferior ();
989 resume_ptid
= RESUME_ALL
; /* Default */
991 /* If STEP is set, it's a request to use hardware stepping
992 facilities. But in that case, we should never
993 use singlestep breakpoint. */
994 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
996 if (singlestep_breakpoints_inserted_p
997 && stepping_past_singlestep_breakpoint
)
999 /* The situation here is as follows. In thread T1 we wanted to
1000 single-step. Lacking hardware single-stepping we've
1001 set breakpoint at the PC of the next instruction -- call it
1002 P. After resuming, we've hit that breakpoint in thread T2.
1003 Now we've removed original breakpoint, inserted breakpoint
1004 at P+1, and try to step to advance T2 past breakpoint.
1005 We need to step only T2, as if T1 is allowed to freely run,
1006 it can run past P, and if other threads are allowed to run,
1007 they can hit breakpoint at P+1, and nested hits of single-step
1008 breakpoints is not something we'd want -- that's complicated
1009 to support, and has no value. */
1010 resume_ptid
= inferior_ptid
;
1013 if ((step
|| singlestep_breakpoints_inserted_p
)
1014 && stepping_over_breakpoint
)
1016 /* We're allowing a thread to run past a breakpoint it has
1017 hit, by single-stepping the thread with the breakpoint
1018 removed. In which case, we need to single-step only this
1019 thread, and keep others stopped, as they can miss this
1020 breakpoint if allowed to run.
1022 The current code actually removes all breakpoints when
1023 doing this, not just the one being stepped over, so if we
1024 let other threads run, we can actually miss any
1025 breakpoint, not just the one at PC. */
1026 resume_ptid
= inferior_ptid
;
1029 if ((scheduler_mode
== schedlock_on
)
1030 || (scheduler_mode
== schedlock_step
1031 && (step
|| singlestep_breakpoints_inserted_p
)))
1033 /* User-settable 'scheduler' mode requires solo thread resume. */
1034 resume_ptid
= inferior_ptid
;
1037 if (gdbarch_cannot_step_breakpoint (current_gdbarch
))
1039 /* Most targets can step a breakpoint instruction, thus
1040 executing it normally. But if this one cannot, just
1041 continue and we will hit it anyway. */
1042 if (step
&& breakpoint_inserted_here_p (pc
))
1047 && use_displaced_stepping (current_gdbarch
)
1048 && stepping_over_breakpoint
)
1050 CORE_ADDR actual_pc
= read_pc_pid (resume_ptid
);
1053 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
1054 paddr_nz (actual_pc
));
1055 read_memory (actual_pc
, buf
, sizeof (buf
));
1056 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1059 target_resume (resume_ptid
, step
, sig
);
1062 discard_cleanups (old_cleanups
);
1067 /* Clear out all variables saying what to do when inferior is continued.
1068 First do this, then set the ones you want, then call `proceed'. */
1071 clear_proceed_status (void)
1073 stepping_over_breakpoint
= 0;
1074 step_range_start
= 0;
1076 step_frame_id
= null_frame_id
;
1077 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1078 stop_after_trap
= 0;
1079 stop_soon
= NO_STOP_QUIETLY
;
1080 proceed_to_finish
= 0;
1081 breakpoint_proceeded
= 1; /* We're about to proceed... */
1085 regcache_xfree (stop_registers
);
1086 stop_registers
= NULL
;
1089 /* Discard any remaining commands or status from previous stop. */
1090 bpstat_clear (&stop_bpstat
);
1093 /* This should be suitable for any targets that support threads. */
1096 prepare_to_proceed (int step
)
1099 struct target_waitstatus wait_status
;
1101 /* Get the last target status returned by target_wait(). */
1102 get_last_target_status (&wait_ptid
, &wait_status
);
1104 /* Make sure we were stopped at a breakpoint. */
1105 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1106 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1111 /* Switched over from WAIT_PID. */
1112 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1113 && !ptid_equal (inferior_ptid
, wait_ptid
)
1114 && breakpoint_here_p (read_pc_pid (wait_ptid
)))
1116 /* If stepping, remember current thread to switch back to. */
1119 deferred_step_ptid
= inferior_ptid
;
1122 /* Switch back to WAIT_PID thread. */
1123 switch_to_thread (wait_ptid
);
1125 /* We return 1 to indicate that there is a breakpoint here,
1126 so we need to step over it before continuing to avoid
1127 hitting it straight away. */
1134 /* Record the pc of the program the last time it stopped. This is
1135 just used internally by wait_for_inferior, but need to be preserved
1136 over calls to it and cleared when the inferior is started. */
1137 static CORE_ADDR prev_pc
;
1139 /* Basic routine for continuing the program in various fashions.
1141 ADDR is the address to resume at, or -1 for resume where stopped.
1142 SIGGNAL is the signal to give it, or 0 for none,
1143 or -1 for act according to how it stopped.
1144 STEP is nonzero if should trap after one instruction.
1145 -1 means return after that and print nothing.
1146 You should probably set various step_... variables
1147 before calling here, if you are stepping.
1149 You should call clear_proceed_status before calling proceed. */
1152 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1157 step_start_function
= find_pc_function (read_pc ());
1159 stop_after_trap
= 1;
1161 if (addr
== (CORE_ADDR
) -1)
1163 if (read_pc () == stop_pc
&& breakpoint_here_p (read_pc ()))
1164 /* There is a breakpoint at the address we will resume at,
1165 step one instruction before inserting breakpoints so that
1166 we do not stop right away (and report a second hit at this
1169 else if (gdbarch_single_step_through_delay_p (current_gdbarch
)
1170 && gdbarch_single_step_through_delay (current_gdbarch
,
1171 get_current_frame ()))
1172 /* We stepped onto an instruction that needs to be stepped
1173 again before re-inserting the breakpoint, do so. */
1182 fprintf_unfiltered (gdb_stdlog
,
1183 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1184 paddr_nz (addr
), siggnal
, step
);
1186 /* In a multi-threaded task we may select another thread
1187 and then continue or step.
1189 But if the old thread was stopped at a breakpoint, it
1190 will immediately cause another breakpoint stop without
1191 any execution (i.e. it will report a breakpoint hit
1192 incorrectly). So we must step over it first.
1194 prepare_to_proceed checks the current thread against the thread
1195 that reported the most recent event. If a step-over is required
1196 it returns TRUE and sets the current thread to the old thread. */
1197 if (prepare_to_proceed (step
))
1202 stepping_over_breakpoint
= 1;
1203 /* If displaced stepping is enabled, we can step over the
1204 breakpoint without hitting it, so leave all breakpoints
1205 inserted. Otherwise we need to disable all breakpoints, step
1206 one instruction, and then re-add them when that step is
1208 if (!use_displaced_stepping (current_gdbarch
))
1209 remove_breakpoints ();
1212 /* We can insert breakpoints if we're not trying to step over one,
1213 or if we are stepping over one but we're using displaced stepping
1215 if (! stepping_over_breakpoint
|| use_displaced_stepping (current_gdbarch
))
1216 insert_breakpoints ();
1218 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1219 stop_signal
= siggnal
;
1220 /* If this signal should not be seen by program,
1221 give it zero. Used for debugging signals. */
1222 else if (!signal_program
[stop_signal
])
1223 stop_signal
= TARGET_SIGNAL_0
;
1225 annotate_starting ();
1227 /* Make sure that output from GDB appears before output from the
1229 gdb_flush (gdb_stdout
);
1231 /* Refresh prev_pc value just prior to resuming. This used to be
1232 done in stop_stepping, however, setting prev_pc there did not handle
1233 scenarios such as inferior function calls or returning from
1234 a function via the return command. In those cases, the prev_pc
1235 value was not set properly for subsequent commands. The prev_pc value
1236 is used to initialize the starting line number in the ecs. With an
1237 invalid value, the gdb next command ends up stopping at the position
1238 represented by the next line table entry past our start position.
1239 On platforms that generate one line table entry per line, this
1240 is not a problem. However, on the ia64, the compiler generates
1241 extraneous line table entries that do not increase the line number.
1242 When we issue the gdb next command on the ia64 after an inferior call
1243 or a return command, we often end up a few instructions forward, still
1244 within the original line we started.
1246 An attempt was made to have init_execution_control_state () refresh
1247 the prev_pc value before calculating the line number. This approach
1248 did not work because on platforms that use ptrace, the pc register
1249 cannot be read unless the inferior is stopped. At that point, we
1250 are not guaranteed the inferior is stopped and so the read_pc ()
1251 call can fail. Setting the prev_pc value here ensures the value is
1252 updated correctly when the inferior is stopped. */
1253 prev_pc
= read_pc ();
1255 /* Resume inferior. */
1256 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1258 /* Wait for it to stop (if not standalone)
1259 and in any case decode why it stopped, and act accordingly. */
1260 /* Do this only if we are not using the event loop, or if the target
1261 does not support asynchronous execution. */
1262 if (!target_can_async_p ())
1264 wait_for_inferior (0);
1270 /* Start remote-debugging of a machine over a serial link. */
1273 start_remote (int from_tty
)
1275 init_thread_list ();
1276 init_wait_for_inferior ();
1277 stop_soon
= STOP_QUIETLY_REMOTE
;
1278 stepping_over_breakpoint
= 0;
1280 /* Always go on waiting for the target, regardless of the mode. */
1281 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1282 indicate to wait_for_inferior that a target should timeout if
1283 nothing is returned (instead of just blocking). Because of this,
1284 targets expecting an immediate response need to, internally, set
1285 things up so that the target_wait() is forced to eventually
1287 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1288 differentiate to its caller what the state of the target is after
1289 the initial open has been performed. Here we're assuming that
1290 the target has stopped. It should be possible to eventually have
1291 target_open() return to the caller an indication that the target
1292 is currently running and GDB state should be set to the same as
1293 for an async run. */
1294 wait_for_inferior (0);
1296 /* Now that the inferior has stopped, do any bookkeeping like
1297 loading shared libraries. We want to do this before normal_stop,
1298 so that the displayed frame is up to date. */
1299 post_create_inferior (¤t_target
, from_tty
);
1304 /* Initialize static vars when a new inferior begins. */
1307 init_wait_for_inferior (void)
1309 /* These are meaningless until the first time through wait_for_inferior. */
1312 breakpoint_init_inferior (inf_starting
);
1314 /* Don't confuse first call to proceed(). */
1315 stop_signal
= TARGET_SIGNAL_0
;
1317 /* The first resume is not following a fork/vfork/exec. */
1318 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1320 clear_proceed_status ();
1322 stepping_past_singlestep_breakpoint
= 0;
1323 deferred_step_ptid
= null_ptid
;
1325 target_last_wait_ptid
= minus_one_ptid
;
1327 displaced_step_clear ();
1331 /* This enum encodes possible reasons for doing a target_wait, so that
1332 wfi can call target_wait in one place. (Ultimately the call will be
1333 moved out of the infinite loop entirely.) */
1337 infwait_normal_state
,
1338 infwait_thread_hop_state
,
1339 infwait_step_watch_state
,
1340 infwait_nonstep_watch_state
1343 /* Why did the inferior stop? Used to print the appropriate messages
1344 to the interface from within handle_inferior_event(). */
1345 enum inferior_stop_reason
1347 /* Step, next, nexti, stepi finished. */
1349 /* Inferior terminated by signal. */
1351 /* Inferior exited. */
1353 /* Inferior received signal, and user asked to be notified. */
1357 /* This structure contains what used to be local variables in
1358 wait_for_inferior. Probably many of them can return to being
1359 locals in handle_inferior_event. */
1361 struct execution_control_state
1363 struct target_waitstatus ws
;
1364 struct target_waitstatus
*wp
;
1365 /* Should we step over breakpoint next time keep_going
1367 int stepping_over_breakpoint
;
1369 CORE_ADDR stop_func_start
;
1370 CORE_ADDR stop_func_end
;
1371 char *stop_func_name
;
1372 struct symtab_and_line sal
;
1374 struct symtab
*current_symtab
;
1375 int handling_longjmp
; /* FIXME */
1377 ptid_t saved_inferior_ptid
;
1378 int step_after_step_resume_breakpoint
;
1379 int stepping_through_solib_after_catch
;
1380 bpstat stepping_through_solib_catchpoints
;
1381 int new_thread_event
;
1382 struct target_waitstatus tmpstatus
;
1383 enum infwait_states infwait_state
;
1388 void init_execution_control_state (struct execution_control_state
*ecs
);
1390 void handle_inferior_event (struct execution_control_state
*ecs
);
1392 static void step_into_function (struct execution_control_state
*ecs
);
1393 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1394 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1395 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
1396 struct frame_id sr_id
);
1397 static void stop_stepping (struct execution_control_state
*ecs
);
1398 static void prepare_to_wait (struct execution_control_state
*ecs
);
1399 static void keep_going (struct execution_control_state
*ecs
);
1400 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1403 /* Wait for control to return from inferior to debugger.
1405 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1406 as if they were SIGTRAP signals. This can be useful during
1407 the startup sequence on some targets such as HP/UX, where
1408 we receive an EXEC event instead of the expected SIGTRAP.
1410 If inferior gets a signal, we may decide to start it up again
1411 instead of returning. That is why there is a loop in this function.
1412 When this function actually returns it means the inferior
1413 should be left stopped and GDB should read more commands. */
1416 wait_for_inferior (int treat_exec_as_sigtrap
)
1418 struct cleanup
*old_cleanups
;
1419 struct execution_control_state ecss
;
1420 struct execution_control_state
*ecs
;
1424 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1425 treat_exec_as_sigtrap
);
1427 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1428 &step_resume_breakpoint
);
1430 /* wfi still stays in a loop, so it's OK just to take the address of
1431 a local to get the ecs pointer. */
1434 /* Fill in with reasonable starting values. */
1435 init_execution_control_state (ecs
);
1437 /* We'll update this if & when we switch to a new thread. */
1438 previous_inferior_ptid
= inferior_ptid
;
1440 overlay_cache_invalid
= 1;
1442 /* We have to invalidate the registers BEFORE calling target_wait
1443 because they can be loaded from the target while in target_wait.
1444 This makes remote debugging a bit more efficient for those
1445 targets that provide critical registers as part of their normal
1446 status mechanism. */
1448 registers_changed ();
1452 if (deprecated_target_wait_hook
)
1453 ecs
->ptid
= deprecated_target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1455 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1457 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1459 xfree (ecs
->ws
.value
.execd_pathname
);
1460 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1461 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
1464 /* Now figure out what to do with the result of the result. */
1465 handle_inferior_event (ecs
);
1467 if (!ecs
->wait_some_more
)
1470 do_cleanups (old_cleanups
);
1473 /* Asynchronous version of wait_for_inferior. It is called by the
1474 event loop whenever a change of state is detected on the file
1475 descriptor corresponding to the target. It can be called more than
1476 once to complete a single execution command. In such cases we need
1477 to keep the state in a global variable ASYNC_ECSS. If it is the
1478 last time that this function is called for a single execution
1479 command, then report to the user that the inferior has stopped, and
1480 do the necessary cleanups. */
1482 struct execution_control_state async_ecss
;
1483 struct execution_control_state
*async_ecs
;
1486 fetch_inferior_event (void *client_data
)
1488 static struct cleanup
*old_cleanups
;
1490 async_ecs
= &async_ecss
;
1492 if (!async_ecs
->wait_some_more
)
1494 /* Fill in with reasonable starting values. */
1495 init_execution_control_state (async_ecs
);
1497 /* We'll update this if & when we switch to a new thread. */
1498 previous_inferior_ptid
= inferior_ptid
;
1500 overlay_cache_invalid
= 1;
1502 /* We have to invalidate the registers BEFORE calling target_wait
1503 because they can be loaded from the target while in target_wait.
1504 This makes remote debugging a bit more efficient for those
1505 targets that provide critical registers as part of their normal
1506 status mechanism. */
1508 registers_changed ();
1511 if (deprecated_target_wait_hook
)
1513 deprecated_target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1515 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1517 /* Now figure out what to do with the result of the result. */
1518 handle_inferior_event (async_ecs
);
1520 if (!async_ecs
->wait_some_more
)
1522 delete_step_resume_breakpoint (&step_resume_breakpoint
);
1525 if (step_multi
&& stop_step
)
1526 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1528 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1532 /* Prepare an execution control state for looping through a
1533 wait_for_inferior-type loop. */
1536 init_execution_control_state (struct execution_control_state
*ecs
)
1538 ecs
->stepping_over_breakpoint
= 0;
1539 ecs
->random_signal
= 0;
1540 ecs
->step_after_step_resume_breakpoint
= 0;
1541 ecs
->handling_longjmp
= 0; /* FIXME */
1542 ecs
->stepping_through_solib_after_catch
= 0;
1543 ecs
->stepping_through_solib_catchpoints
= NULL
;
1544 ecs
->sal
= find_pc_line (prev_pc
, 0);
1545 ecs
->current_line
= ecs
->sal
.line
;
1546 ecs
->current_symtab
= ecs
->sal
.symtab
;
1547 ecs
->infwait_state
= infwait_normal_state
;
1548 ecs
->waiton_ptid
= pid_to_ptid (-1);
1549 ecs
->wp
= &(ecs
->ws
);
1552 /* Return the cached copy of the last pid/waitstatus returned by
1553 target_wait()/deprecated_target_wait_hook(). The data is actually
1554 cached by handle_inferior_event(), which gets called immediately
1555 after target_wait()/deprecated_target_wait_hook(). */
1558 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1560 *ptidp
= target_last_wait_ptid
;
1561 *status
= target_last_waitstatus
;
1565 nullify_last_target_wait_ptid (void)
1567 target_last_wait_ptid
= minus_one_ptid
;
1570 /* Switch thread contexts, maintaining "infrun state". */
1573 context_switch (struct execution_control_state
*ecs
)
1575 /* Caution: it may happen that the new thread (or the old one!)
1576 is not in the thread list. In this case we must not attempt
1577 to "switch context", or we run the risk that our context may
1578 be lost. This may happen as a result of the target module
1579 mishandling thread creation. */
1583 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
1584 target_pid_to_str (inferior_ptid
));
1585 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
1586 target_pid_to_str (ecs
->ptid
));
1589 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1590 { /* Perform infrun state context switch: */
1591 /* Save infrun state for the old thread. */
1592 save_infrun_state (inferior_ptid
, prev_pc
,
1593 stepping_over_breakpoint
, step_resume_breakpoint
,
1595 step_range_end
, &step_frame_id
,
1596 ecs
->handling_longjmp
, ecs
->stepping_over_breakpoint
,
1597 ecs
->stepping_through_solib_after_catch
,
1598 ecs
->stepping_through_solib_catchpoints
,
1599 ecs
->current_line
, ecs
->current_symtab
);
1601 /* Load infrun state for the new thread. */
1602 load_infrun_state (ecs
->ptid
, &prev_pc
,
1603 &stepping_over_breakpoint
, &step_resume_breakpoint
,
1605 &step_range_end
, &step_frame_id
,
1606 &ecs
->handling_longjmp
, &ecs
->stepping_over_breakpoint
,
1607 &ecs
->stepping_through_solib_after_catch
,
1608 &ecs
->stepping_through_solib_catchpoints
,
1609 &ecs
->current_line
, &ecs
->current_symtab
);
1612 switch_to_thread (ecs
->ptid
);
1616 adjust_pc_after_break (struct execution_control_state
*ecs
)
1618 CORE_ADDR breakpoint_pc
;
1620 /* If this target does not decrement the PC after breakpoints, then
1621 we have nothing to do. */
1622 if (gdbarch_decr_pc_after_break (current_gdbarch
) == 0)
1625 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1626 we aren't, just return.
1628 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1629 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1630 implemented by software breakpoints should be handled through the normal
1633 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1634 different signals (SIGILL or SIGEMT for instance), but it is less
1635 clear where the PC is pointing afterwards. It may not match
1636 gdbarch_decr_pc_after_break. I don't know any specific target that
1637 generates these signals at breakpoints (the code has been in GDB since at
1638 least 1992) so I can not guess how to handle them here.
1640 In earlier versions of GDB, a target with
1641 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1642 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1643 target with both of these set in GDB history, and it seems unlikely to be
1644 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1646 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
1649 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1652 /* Find the location where (if we've hit a breakpoint) the
1653 breakpoint would be. */
1654 breakpoint_pc
= read_pc_pid (ecs
->ptid
) - gdbarch_decr_pc_after_break
1657 /* Check whether there actually is a software breakpoint inserted
1658 at that location. */
1659 if (software_breakpoint_inserted_here_p (breakpoint_pc
))
1661 /* When using hardware single-step, a SIGTRAP is reported for both
1662 a completed single-step and a software breakpoint. Need to
1663 differentiate between the two, as the latter needs adjusting
1664 but the former does not.
1666 The SIGTRAP can be due to a completed hardware single-step only if
1667 - we didn't insert software single-step breakpoints
1668 - the thread to be examined is still the current thread
1669 - this thread is currently being stepped
1671 If any of these events did not occur, we must have stopped due
1672 to hitting a software breakpoint, and have to back up to the
1675 As a special case, we could have hardware single-stepped a
1676 software breakpoint. In this case (prev_pc == breakpoint_pc),
1677 we also need to back up to the breakpoint address. */
1679 if (singlestep_breakpoints_inserted_p
1680 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
1681 || !currently_stepping (ecs
)
1682 || prev_pc
== breakpoint_pc
)
1683 write_pc_pid (breakpoint_pc
, ecs
->ptid
);
1687 /* Given an execution control state that has been freshly filled in
1688 by an event from the inferior, figure out what it means and take
1689 appropriate action. */
1692 handle_inferior_event (struct execution_control_state
*ecs
)
1694 int sw_single_step_trap_p
= 0;
1695 int stopped_by_watchpoint
;
1696 int stepped_after_stopped_by_watchpoint
= 0;
1698 /* Cache the last pid/waitstatus. */
1699 target_last_wait_ptid
= ecs
->ptid
;
1700 target_last_waitstatus
= *ecs
->wp
;
1702 /* Always clear state belonging to the previous time we stopped. */
1703 stop_stack_dummy
= 0;
1705 adjust_pc_after_break (ecs
);
1707 switch (ecs
->infwait_state
)
1709 case infwait_thread_hop_state
:
1711 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
1712 /* Cancel the waiton_ptid. */
1713 ecs
->waiton_ptid
= pid_to_ptid (-1);
1716 case infwait_normal_state
:
1718 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
1721 case infwait_step_watch_state
:
1723 fprintf_unfiltered (gdb_stdlog
,
1724 "infrun: infwait_step_watch_state\n");
1726 stepped_after_stopped_by_watchpoint
= 1;
1729 case infwait_nonstep_watch_state
:
1731 fprintf_unfiltered (gdb_stdlog
,
1732 "infrun: infwait_nonstep_watch_state\n");
1733 insert_breakpoints ();
1735 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1736 handle things like signals arriving and other things happening
1737 in combination correctly? */
1738 stepped_after_stopped_by_watchpoint
= 1;
1742 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1744 ecs
->infwait_state
= infwait_normal_state
;
1746 reinit_frame_cache ();
1748 /* If it's a new process, add it to the thread database */
1750 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1751 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
1752 && !in_thread_list (ecs
->ptid
));
1754 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1755 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1756 add_thread (ecs
->ptid
);
1758 switch (ecs
->ws
.kind
)
1760 case TARGET_WAITKIND_LOADED
:
1762 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
1763 /* Ignore gracefully during startup of the inferior, as it might
1764 be the shell which has just loaded some objects, otherwise
1765 add the symbols for the newly loaded objects. Also ignore at
1766 the beginning of an attach or remote session; we will query
1767 the full list of libraries once the connection is
1769 if (stop_soon
== NO_STOP_QUIETLY
)
1771 /* Check for any newly added shared libraries if we're
1772 supposed to be adding them automatically. Switch
1773 terminal for any messages produced by
1774 breakpoint_re_set. */
1775 target_terminal_ours_for_output ();
1776 /* NOTE: cagney/2003-11-25: Make certain that the target
1777 stack's section table is kept up-to-date. Architectures,
1778 (e.g., PPC64), use the section table to perform
1779 operations such as address => section name and hence
1780 require the table to contain all sections (including
1781 those found in shared libraries). */
1782 /* NOTE: cagney/2003-11-25: Pass current_target and not
1783 exec_ops to SOLIB_ADD. This is because current GDB is
1784 only tooled to propagate section_table changes out from
1785 the "current_target" (see target_resize_to_sections), and
1786 not up from the exec stratum. This, of course, isn't
1787 right. "infrun.c" should only interact with the
1788 exec/process stratum, instead relying on the target stack
1789 to propagate relevant changes (stop, section table
1790 changed, ...) up to other layers. */
1792 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
1794 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
1796 target_terminal_inferior ();
1798 /* If requested, stop when the dynamic linker notifies
1799 gdb of events. This allows the user to get control
1800 and place breakpoints in initializer routines for
1801 dynamically loaded objects (among other things). */
1802 if (stop_on_solib_events
)
1804 stop_stepping (ecs
);
1808 /* NOTE drow/2007-05-11: This might be a good place to check
1809 for "catch load". */
1812 /* If we are skipping through a shell, or through shared library
1813 loading that we aren't interested in, resume the program. If
1814 we're running the program normally, also resume. But stop if
1815 we're attaching or setting up a remote connection. */
1816 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
1818 /* Loading of shared libraries might have changed breakpoint
1819 addresses. Make sure new breakpoints are inserted. */
1820 if (!breakpoints_always_inserted_mode ())
1821 insert_breakpoints ();
1822 resume (0, TARGET_SIGNAL_0
);
1823 prepare_to_wait (ecs
);
1829 case TARGET_WAITKIND_SPURIOUS
:
1831 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
1832 resume (0, TARGET_SIGNAL_0
);
1833 prepare_to_wait (ecs
);
1836 case TARGET_WAITKIND_EXITED
:
1838 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
1839 target_terminal_ours (); /* Must do this before mourn anyway */
1840 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1842 /* Record the exit code in the convenience variable $_exitcode, so
1843 that the user can inspect this again later. */
1844 set_internalvar (lookup_internalvar ("_exitcode"),
1845 value_from_longest (builtin_type_int
,
1846 (LONGEST
) ecs
->ws
.value
.integer
));
1847 gdb_flush (gdb_stdout
);
1848 target_mourn_inferior ();
1849 singlestep_breakpoints_inserted_p
= 0;
1850 stop_print_frame
= 0;
1851 stop_stepping (ecs
);
1854 case TARGET_WAITKIND_SIGNALLED
:
1856 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
1857 stop_print_frame
= 0;
1858 stop_signal
= ecs
->ws
.value
.sig
;
1859 target_terminal_ours (); /* Must do this before mourn anyway */
1861 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1862 reach here unless the inferior is dead. However, for years
1863 target_kill() was called here, which hints that fatal signals aren't
1864 really fatal on some systems. If that's true, then some changes
1866 target_mourn_inferior ();
1868 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1869 singlestep_breakpoints_inserted_p
= 0;
1870 stop_stepping (ecs
);
1873 /* The following are the only cases in which we keep going;
1874 the above cases end in a continue or goto. */
1875 case TARGET_WAITKIND_FORKED
:
1876 case TARGET_WAITKIND_VFORKED
:
1878 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
1879 stop_signal
= TARGET_SIGNAL_TRAP
;
1880 pending_follow
.kind
= ecs
->ws
.kind
;
1882 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1883 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1885 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1887 context_switch (ecs
);
1888 reinit_frame_cache ();
1891 stop_pc
= read_pc ();
1893 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
1895 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1897 /* If no catchpoint triggered for this, then keep going. */
1898 if (ecs
->random_signal
)
1900 stop_signal
= TARGET_SIGNAL_0
;
1904 goto process_event_stop_test
;
1906 case TARGET_WAITKIND_EXECD
:
1908 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
1909 stop_signal
= TARGET_SIGNAL_TRAP
;
1911 pending_follow
.execd_pathname
=
1912 savestring (ecs
->ws
.value
.execd_pathname
,
1913 strlen (ecs
->ws
.value
.execd_pathname
));
1915 /* This causes the eventpoints and symbol table to be reset. Must
1916 do this now, before trying to determine whether to stop. */
1917 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1918 xfree (pending_follow
.execd_pathname
);
1920 stop_pc
= read_pc_pid (ecs
->ptid
);
1921 ecs
->saved_inferior_ptid
= inferior_ptid
;
1922 inferior_ptid
= ecs
->ptid
;
1924 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
1926 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1927 inferior_ptid
= ecs
->saved_inferior_ptid
;
1929 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1931 context_switch (ecs
);
1932 reinit_frame_cache ();
1935 /* If no catchpoint triggered for this, then keep going. */
1936 if (ecs
->random_signal
)
1938 stop_signal
= TARGET_SIGNAL_0
;
1942 goto process_event_stop_test
;
1944 /* Be careful not to try to gather much state about a thread
1945 that's in a syscall. It's frequently a losing proposition. */
1946 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1948 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
1949 resume (0, TARGET_SIGNAL_0
);
1950 prepare_to_wait (ecs
);
1953 /* Before examining the threads further, step this thread to
1954 get it entirely out of the syscall. (We get notice of the
1955 event when the thread is just on the verge of exiting a
1956 syscall. Stepping one instruction seems to get it back
1958 case TARGET_WAITKIND_SYSCALL_RETURN
:
1960 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
1961 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1962 prepare_to_wait (ecs
);
1965 case TARGET_WAITKIND_STOPPED
:
1967 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
1968 stop_signal
= ecs
->ws
.value
.sig
;
1971 /* We had an event in the inferior, but we are not interested
1972 in handling it at this level. The lower layers have already
1973 done what needs to be done, if anything.
1975 One of the possible circumstances for this is when the
1976 inferior produces output for the console. The inferior has
1977 not stopped, and we are ignoring the event. Another possible
1978 circumstance is any event which the lower level knows will be
1979 reported multiple times without an intervening resume. */
1980 case TARGET_WAITKIND_IGNORE
:
1982 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
1983 prepare_to_wait (ecs
);
1987 /* We may want to consider not doing a resume here in order to give
1988 the user a chance to play with the new thread. It might be good
1989 to make that a user-settable option. */
1991 /* At this point, all threads are stopped (happens automatically in
1992 either the OS or the native code). Therefore we need to continue
1993 all threads in order to make progress. */
1994 if (ecs
->new_thread_event
)
1996 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
1997 prepare_to_wait (ecs
);
2001 /* Do we need to clean up the state of a thread that has completed a
2002 displaced single-step? (Doing so usually affects the PC, so do
2003 it here, before we set stop_pc.) */
2004 displaced_step_fixup (ecs
->ptid
, stop_signal
);
2006 stop_pc
= read_pc_pid (ecs
->ptid
);
2010 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n",
2011 paddr_nz (stop_pc
));
2012 if (STOPPED_BY_WATCHPOINT (&ecs
->ws
))
2015 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2017 if (target_stopped_data_address (¤t_target
, &addr
))
2018 fprintf_unfiltered (gdb_stdlog
,
2019 "infrun: stopped data address = 0x%s\n",
2022 fprintf_unfiltered (gdb_stdlog
,
2023 "infrun: (no data address available)\n");
2027 if (stepping_past_singlestep_breakpoint
)
2029 gdb_assert (singlestep_breakpoints_inserted_p
);
2030 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2031 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2033 stepping_past_singlestep_breakpoint
= 0;
2035 /* We've either finished single-stepping past the single-step
2036 breakpoint, or stopped for some other reason. It would be nice if
2037 we could tell, but we can't reliably. */
2038 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2041 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2042 /* Pull the single step breakpoints out of the target. */
2043 remove_single_step_breakpoints ();
2044 singlestep_breakpoints_inserted_p
= 0;
2046 ecs
->random_signal
= 0;
2048 ecs
->ptid
= saved_singlestep_ptid
;
2049 context_switch (ecs
);
2050 if (deprecated_context_hook
)
2051 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2053 resume (1, TARGET_SIGNAL_0
);
2054 prepare_to_wait (ecs
);
2059 stepping_past_singlestep_breakpoint
= 0;
2061 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2063 /* If we stopped for some other reason than single-stepping, ignore
2064 the fact that we were supposed to switch back. */
2065 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2068 fprintf_unfiltered (gdb_stdlog
,
2069 "infrun: handling deferred step\n");
2071 /* Pull the single step breakpoints out of the target. */
2072 if (singlestep_breakpoints_inserted_p
)
2074 remove_single_step_breakpoints ();
2075 singlestep_breakpoints_inserted_p
= 0;
2078 /* Note: We do not call context_switch at this point, as the
2079 context is already set up for stepping the original thread. */
2080 switch_to_thread (deferred_step_ptid
);
2081 deferred_step_ptid
= null_ptid
;
2082 /* Suppress spurious "Switching to ..." message. */
2083 previous_inferior_ptid
= inferior_ptid
;
2085 resume (1, TARGET_SIGNAL_0
);
2086 prepare_to_wait (ecs
);
2090 deferred_step_ptid
= null_ptid
;
2093 /* See if a thread hit a thread-specific breakpoint that was meant for
2094 another thread. If so, then step that thread past the breakpoint,
2097 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2099 int thread_hop_needed
= 0;
2101 /* Check if a regular breakpoint has been hit before checking
2102 for a potential single step breakpoint. Otherwise, GDB will
2103 not see this breakpoint hit when stepping onto breakpoints. */
2104 if (regular_breakpoint_inserted_here_p (stop_pc
))
2106 ecs
->random_signal
= 0;
2107 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2108 thread_hop_needed
= 1;
2110 else if (singlestep_breakpoints_inserted_p
)
2112 /* We have not context switched yet, so this should be true
2113 no matter which thread hit the singlestep breakpoint. */
2114 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2116 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2118 target_pid_to_str (ecs
->ptid
));
2120 ecs
->random_signal
= 0;
2121 /* The call to in_thread_list is necessary because PTIDs sometimes
2122 change when we go from single-threaded to multi-threaded. If
2123 the singlestep_ptid is still in the list, assume that it is
2124 really different from ecs->ptid. */
2125 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2126 && in_thread_list (singlestep_ptid
))
2128 /* If the PC of the thread we were trying to single-step
2129 has changed, discard this event (which we were going
2130 to ignore anyway), and pretend we saw that thread
2131 trap. This prevents us continuously moving the
2132 single-step breakpoint forward, one instruction at a
2133 time. If the PC has changed, then the thread we were
2134 trying to single-step has trapped or been signalled,
2135 but the event has not been reported to GDB yet.
2137 There might be some cases where this loses signal
2138 information, if a signal has arrived at exactly the
2139 same time that the PC changed, but this is the best
2140 we can do with the information available. Perhaps we
2141 should arrange to report all events for all threads
2142 when they stop, or to re-poll the remote looking for
2143 this particular thread (i.e. temporarily enable
2145 if (read_pc_pid (singlestep_ptid
) != singlestep_pc
)
2148 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2149 " but expected thread advanced also\n");
2151 /* The current context still belongs to
2152 singlestep_ptid. Don't swap here, since that's
2153 the context we want to use. Just fudge our
2154 state and continue. */
2155 ecs
->ptid
= singlestep_ptid
;
2156 stop_pc
= read_pc_pid (ecs
->ptid
);
2161 fprintf_unfiltered (gdb_stdlog
,
2162 "infrun: unexpected thread\n");
2164 thread_hop_needed
= 1;
2165 stepping_past_singlestep_breakpoint
= 1;
2166 saved_singlestep_ptid
= singlestep_ptid
;
2171 if (thread_hop_needed
)
2173 int remove_status
= 0;
2176 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2178 /* Saw a breakpoint, but it was hit by the wrong thread.
2181 if (singlestep_breakpoints_inserted_p
)
2183 /* Pull the single step breakpoints out of the target. */
2184 remove_single_step_breakpoints ();
2185 singlestep_breakpoints_inserted_p
= 0;
2188 /* If the arch can displace step, don't remove the
2190 if (!use_displaced_stepping (current_gdbarch
))
2191 remove_status
= remove_breakpoints ();
2193 /* Did we fail to remove breakpoints? If so, try
2194 to set the PC past the bp. (There's at least
2195 one situation in which we can fail to remove
2196 the bp's: On HP-UX's that use ttrace, we can't
2197 change the address space of a vforking child
2198 process until the child exits (well, okay, not
2199 then either :-) or execs. */
2200 if (remove_status
!= 0)
2201 error (_("Cannot step over breakpoint hit in wrong thread"));
2204 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2205 context_switch (ecs
);
2206 ecs
->waiton_ptid
= ecs
->ptid
;
2207 ecs
->wp
= &(ecs
->ws
);
2208 ecs
->stepping_over_breakpoint
= 1;
2210 ecs
->infwait_state
= infwait_thread_hop_state
;
2212 registers_changed ();
2216 else if (singlestep_breakpoints_inserted_p
)
2218 sw_single_step_trap_p
= 1;
2219 ecs
->random_signal
= 0;
2223 ecs
->random_signal
= 1;
2225 /* See if something interesting happened to the non-current thread. If
2226 so, then switch to that thread. */
2227 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2230 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
2232 context_switch (ecs
);
2234 if (deprecated_context_hook
)
2235 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2238 if (singlestep_breakpoints_inserted_p
)
2240 /* Pull the single step breakpoints out of the target. */
2241 remove_single_step_breakpoints ();
2242 singlestep_breakpoints_inserted_p
= 0;
2245 if (stepped_after_stopped_by_watchpoint
)
2246 stopped_by_watchpoint
= 0;
2248 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
2250 /* If necessary, step over this watchpoint. We'll be back to display
2252 if (stopped_by_watchpoint
2253 && (HAVE_STEPPABLE_WATCHPOINT
2254 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
2256 /* At this point, we are stopped at an instruction which has
2257 attempted to write to a piece of memory under control of
2258 a watchpoint. The instruction hasn't actually executed
2259 yet. If we were to evaluate the watchpoint expression
2260 now, we would get the old value, and therefore no change
2261 would seem to have occurred.
2263 In order to make watchpoints work `right', we really need
2264 to complete the memory write, and then evaluate the
2265 watchpoint expression. We do this by single-stepping the
2268 It may not be necessary to disable the watchpoint to stop over
2269 it. For example, the PA can (with some kernel cooperation)
2270 single step over a watchpoint without disabling the watchpoint.
2272 It is far more common to need to disable a watchpoint to step
2273 the inferior over it. If we have non-steppable watchpoints,
2274 we must disable the current watchpoint; it's simplest to
2275 disable all watchpoints and breakpoints. */
2277 if (!HAVE_STEPPABLE_WATCHPOINT
)
2278 remove_breakpoints ();
2279 registers_changed ();
2280 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2281 ecs
->waiton_ptid
= ecs
->ptid
;
2282 if (HAVE_STEPPABLE_WATCHPOINT
)
2283 ecs
->infwait_state
= infwait_step_watch_state
;
2285 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2286 prepare_to_wait (ecs
);
2290 ecs
->stop_func_start
= 0;
2291 ecs
->stop_func_end
= 0;
2292 ecs
->stop_func_name
= 0;
2293 /* Don't care about return value; stop_func_start and stop_func_name
2294 will both be 0 if it doesn't work. */
2295 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2296 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2297 ecs
->stop_func_start
2298 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
2299 ecs
->stepping_over_breakpoint
= 0;
2300 bpstat_clear (&stop_bpstat
);
2302 stop_print_frame
= 1;
2303 ecs
->random_signal
= 0;
2304 stopped_by_random_signal
= 0;
2306 if (stop_signal
== TARGET_SIGNAL_TRAP
2307 && stepping_over_breakpoint
2308 && gdbarch_single_step_through_delay_p (current_gdbarch
)
2309 && currently_stepping (ecs
))
2311 /* We're trying to step off a breakpoint. Turns out that we're
2312 also on an instruction that needs to be stepped multiple
2313 times before it's been fully executing. E.g., architectures
2314 with a delay slot. It needs to be stepped twice, once for
2315 the instruction and once for the delay slot. */
2316 int step_through_delay
2317 = gdbarch_single_step_through_delay (current_gdbarch
,
2318 get_current_frame ());
2319 if (debug_infrun
&& step_through_delay
)
2320 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
2321 if (step_range_end
== 0 && step_through_delay
)
2323 /* The user issued a continue when stopped at a breakpoint.
2324 Set up for another trap and get out of here. */
2325 ecs
->stepping_over_breakpoint
= 1;
2329 else if (step_through_delay
)
2331 /* The user issued a step when stopped at a breakpoint.
2332 Maybe we should stop, maybe we should not - the delay
2333 slot *might* correspond to a line of source. In any
2334 case, don't decide that here, just set
2335 ecs->stepping_over_breakpoint, making sure we
2336 single-step again before breakpoints are re-inserted. */
2337 ecs
->stepping_over_breakpoint
= 1;
2341 /* Look at the cause of the stop, and decide what to do.
2342 The alternatives are:
2343 1) break; to really stop and return to the debugger,
2344 2) drop through to start up again
2345 (set ecs->stepping_over_breakpoint to 1 to single step once)
2346 3) set ecs->random_signal to 1, and the decision between 1 and 2
2347 will be made according to the signal handling tables. */
2349 /* First, distinguish signals caused by the debugger from signals
2350 that have to do with the program's own actions. Note that
2351 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2352 on the operating system version. Here we detect when a SIGILL or
2353 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2354 something similar for SIGSEGV, since a SIGSEGV will be generated
2355 when we're trying to execute a breakpoint instruction on a
2356 non-executable stack. This happens for call dummy breakpoints
2357 for architectures like SPARC that place call dummies on the
2360 If we're doing a displaced step past a breakpoint, then the
2361 breakpoint is always inserted at the original instruction;
2362 non-standard signals can't be explained by the breakpoint. */
2363 if (stop_signal
== TARGET_SIGNAL_TRAP
2364 || (! stepping_over_breakpoint
2365 && breakpoint_inserted_here_p (stop_pc
)
2366 && (stop_signal
== TARGET_SIGNAL_ILL
2367 || stop_signal
== TARGET_SIGNAL_SEGV
2368 || stop_signal
== TARGET_SIGNAL_EMT
))
2369 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2370 || stop_soon
== STOP_QUIETLY_REMOTE
)
2372 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2375 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
2376 stop_print_frame
= 0;
2377 stop_stepping (ecs
);
2381 /* This is originated from start_remote(), start_inferior() and
2382 shared libraries hook functions. */
2383 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
2386 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
2387 stop_stepping (ecs
);
2391 /* This originates from attach_command(). We need to overwrite
2392 the stop_signal here, because some kernels don't ignore a
2393 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2394 See more comments in inferior.h. On the other hand, if we
2395 get a non-SIGSTOP, report it to the user - assume the backend
2396 will handle the SIGSTOP if it should show up later. */
2397 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2398 && stop_signal
== TARGET_SIGNAL_STOP
)
2400 stop_stepping (ecs
);
2401 stop_signal
= TARGET_SIGNAL_0
;
2405 /* See if there is a breakpoint at the current PC. */
2406 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2408 /* Following in case break condition called a
2410 stop_print_frame
= 1;
2412 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2413 at one stage in the past included checks for an inferior
2414 function call's call dummy's return breakpoint. The original
2415 comment, that went with the test, read:
2417 ``End of a stack dummy. Some systems (e.g. Sony news) give
2418 another signal besides SIGTRAP, so check here as well as
2421 If someone ever tries to get get call dummys on a
2422 non-executable stack to work (where the target would stop
2423 with something like a SIGSEGV), then those tests might need
2424 to be re-instated. Given, however, that the tests were only
2425 enabled when momentary breakpoints were not being used, I
2426 suspect that it won't be the case.
2428 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2429 be necessary for call dummies on a non-executable stack on
2432 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2434 = !(bpstat_explains_signal (stop_bpstat
)
2435 || stepping_over_breakpoint
2436 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2439 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2440 if (!ecs
->random_signal
)
2441 stop_signal
= TARGET_SIGNAL_TRAP
;
2445 /* When we reach this point, we've pretty much decided
2446 that the reason for stopping must've been a random
2447 (unexpected) signal. */
2450 ecs
->random_signal
= 1;
2452 process_event_stop_test
:
2453 /* For the program's own signals, act according to
2454 the signal handling tables. */
2456 if (ecs
->random_signal
)
2458 /* Signal not for debugging purposes. */
2462 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n", stop_signal
);
2464 stopped_by_random_signal
= 1;
2466 if (signal_print
[stop_signal
])
2469 target_terminal_ours_for_output ();
2470 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2472 if (signal_stop_state (stop_signal
))
2474 stop_stepping (ecs
);
2477 /* If not going to stop, give terminal back
2478 if we took it away. */
2480 target_terminal_inferior ();
2482 /* Clear the signal if it should not be passed. */
2483 if (signal_program
[stop_signal
] == 0)
2484 stop_signal
= TARGET_SIGNAL_0
;
2486 if (prev_pc
== read_pc ()
2487 && stepping_over_breakpoint
2488 && step_resume_breakpoint
== NULL
)
2490 /* We were just starting a new sequence, attempting to
2491 single-step off of a breakpoint and expecting a SIGTRAP.
2492 Instead this signal arrives. This signal will take us out
2493 of the stepping range so GDB needs to remember to, when
2494 the signal handler returns, resume stepping off that
2496 /* To simplify things, "continue" is forced to use the same
2497 code paths as single-step - set a breakpoint at the
2498 signal return address and then, once hit, step off that
2501 fprintf_unfiltered (gdb_stdlog
,
2502 "infrun: signal arrived while stepping over "
2505 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2506 ecs
->step_after_step_resume_breakpoint
= 1;
2511 if (step_range_end
!= 0
2512 && stop_signal
!= TARGET_SIGNAL_0
2513 && stop_pc
>= step_range_start
&& stop_pc
< step_range_end
2514 && frame_id_eq (get_frame_id (get_current_frame ()),
2516 && step_resume_breakpoint
== NULL
)
2518 /* The inferior is about to take a signal that will take it
2519 out of the single step range. Set a breakpoint at the
2520 current PC (which is presumably where the signal handler
2521 will eventually return) and then allow the inferior to
2524 Note that this is only needed for a signal delivered
2525 while in the single-step range. Nested signals aren't a
2526 problem as they eventually all return. */
2528 fprintf_unfiltered (gdb_stdlog
,
2529 "infrun: signal may take us out of "
2530 "single-step range\n");
2532 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2537 /* Note: step_resume_breakpoint may be non-NULL. This occures
2538 when either there's a nested signal, or when there's a
2539 pending signal enabled just as the signal handler returns
2540 (leaving the inferior at the step-resume-breakpoint without
2541 actually executing it). Either way continue until the
2542 breakpoint is really hit. */
2547 /* Handle cases caused by hitting a breakpoint. */
2549 CORE_ADDR jmp_buf_pc
;
2550 struct bpstat_what what
;
2552 what
= bpstat_what (stop_bpstat
);
2554 if (what
.call_dummy
)
2556 stop_stack_dummy
= 1;
2559 switch (what
.main_action
)
2561 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2562 /* If we hit the breakpoint at longjmp, disable it for the
2563 duration of this command. Then, install a temporary
2564 breakpoint at the target of the jmp_buf. */
2566 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2567 disable_longjmp_breakpoint ();
2568 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
2569 || !gdbarch_get_longjmp_target (current_gdbarch
,
2570 get_current_frame (), &jmp_buf_pc
))
2576 /* Need to blow away step-resume breakpoint, as it
2577 interferes with us */
2578 if (step_resume_breakpoint
!= NULL
)
2580 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2583 set_longjmp_resume_breakpoint (jmp_buf_pc
, null_frame_id
);
2584 ecs
->handling_longjmp
= 1; /* FIXME */
2588 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2590 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2591 disable_longjmp_breakpoint ();
2592 ecs
->handling_longjmp
= 0; /* FIXME */
2595 case BPSTAT_WHAT_SINGLE
:
2597 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
2598 ecs
->stepping_over_breakpoint
= 1;
2599 /* Still need to check other stuff, at least the case
2600 where we are stepping and step out of the right range. */
2603 case BPSTAT_WHAT_STOP_NOISY
:
2605 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2606 stop_print_frame
= 1;
2608 /* We are about to nuke the step_resume_breakpointt via the
2609 cleanup chain, so no need to worry about it here. */
2611 stop_stepping (ecs
);
2614 case BPSTAT_WHAT_STOP_SILENT
:
2616 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2617 stop_print_frame
= 0;
2619 /* We are about to nuke the step_resume_breakpoin via the
2620 cleanup chain, so no need to worry about it here. */
2622 stop_stepping (ecs
);
2625 case BPSTAT_WHAT_STEP_RESUME
:
2626 /* This proably demands a more elegant solution, but, yeah
2629 This function's use of the simple variable
2630 step_resume_breakpoint doesn't seem to accomodate
2631 simultaneously active step-resume bp's, although the
2632 breakpoint list certainly can.
2634 If we reach here and step_resume_breakpoint is already
2635 NULL, then apparently we have multiple active
2636 step-resume bp's. We'll just delete the breakpoint we
2637 stopped at, and carry on.
2639 Correction: what the code currently does is delete a
2640 step-resume bp, but it makes no effort to ensure that
2641 the one deleted is the one currently stopped at. MVS */
2644 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2646 if (step_resume_breakpoint
== NULL
)
2648 step_resume_breakpoint
=
2649 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2651 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2652 if (ecs
->step_after_step_resume_breakpoint
)
2654 /* Back when the step-resume breakpoint was inserted, we
2655 were trying to single-step off a breakpoint. Go back
2657 ecs
->step_after_step_resume_breakpoint
= 0;
2658 ecs
->stepping_over_breakpoint
= 1;
2664 case BPSTAT_WHAT_CHECK_SHLIBS
:
2665 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2668 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2670 /* Check for any newly added shared libraries if we're
2671 supposed to be adding them automatically. Switch
2672 terminal for any messages produced by
2673 breakpoint_re_set. */
2674 target_terminal_ours_for_output ();
2675 /* NOTE: cagney/2003-11-25: Make certain that the target
2676 stack's section table is kept up-to-date. Architectures,
2677 (e.g., PPC64), use the section table to perform
2678 operations such as address => section name and hence
2679 require the table to contain all sections (including
2680 those found in shared libraries). */
2681 /* NOTE: cagney/2003-11-25: Pass current_target and not
2682 exec_ops to SOLIB_ADD. This is because current GDB is
2683 only tooled to propagate section_table changes out from
2684 the "current_target" (see target_resize_to_sections), and
2685 not up from the exec stratum. This, of course, isn't
2686 right. "infrun.c" should only interact with the
2687 exec/process stratum, instead relying on the target stack
2688 to propagate relevant changes (stop, section table
2689 changed, ...) up to other layers. */
2691 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2693 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2695 target_terminal_inferior ();
2697 /* If requested, stop when the dynamic linker notifies
2698 gdb of events. This allows the user to get control
2699 and place breakpoints in initializer routines for
2700 dynamically loaded objects (among other things). */
2701 if (stop_on_solib_events
|| stop_stack_dummy
)
2703 stop_stepping (ecs
);
2707 /* If we stopped due to an explicit catchpoint, then the
2708 (see above) call to SOLIB_ADD pulled in any symbols
2709 from a newly-loaded library, if appropriate.
2711 We do want the inferior to stop, but not where it is
2712 now, which is in the dynamic linker callback. Rather,
2713 we would like it stop in the user's program, just after
2714 the call that caused this catchpoint to trigger. That
2715 gives the user a more useful vantage from which to
2716 examine their program's state. */
2717 else if (what
.main_action
2718 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2720 /* ??rehrauer: If I could figure out how to get the
2721 right return PC from here, we could just set a temp
2722 breakpoint and resume. I'm not sure we can without
2723 cracking open the dld's shared libraries and sniffing
2724 their unwind tables and text/data ranges, and that's
2725 not a terribly portable notion.
2727 Until that time, we must step the inferior out of the
2728 dld callback, and also out of the dld itself (and any
2729 code or stubs in libdld.sl, such as "shl_load" and
2730 friends) until we reach non-dld code. At that point,
2731 we can stop stepping. */
2732 bpstat_get_triggered_catchpoints (stop_bpstat
,
2734 stepping_through_solib_catchpoints
);
2735 ecs
->stepping_through_solib_after_catch
= 1;
2737 /* Be sure to lift all breakpoints, so the inferior does
2738 actually step past this point... */
2739 ecs
->stepping_over_breakpoint
= 1;
2744 /* We want to step over this breakpoint, then keep going. */
2745 ecs
->stepping_over_breakpoint
= 1;
2751 case BPSTAT_WHAT_LAST
:
2752 /* Not a real code, but listed here to shut up gcc -Wall. */
2754 case BPSTAT_WHAT_KEEP_CHECKING
:
2759 /* We come here if we hit a breakpoint but should not
2760 stop for it. Possibly we also were stepping
2761 and should stop for that. So fall through and
2762 test for stepping. But, if not stepping,
2765 /* Are we stepping to get the inferior out of the dynamic linker's
2766 hook (and possibly the dld itself) after catching a shlib
2768 if (ecs
->stepping_through_solib_after_catch
)
2770 #if defined(SOLIB_ADD)
2771 /* Have we reached our destination? If not, keep going. */
2772 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2775 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
2776 ecs
->stepping_over_breakpoint
= 1;
2782 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
2783 /* Else, stop and report the catchpoint(s) whose triggering
2784 caused us to begin stepping. */
2785 ecs
->stepping_through_solib_after_catch
= 0;
2786 bpstat_clear (&stop_bpstat
);
2787 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2788 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2789 stop_print_frame
= 1;
2790 stop_stepping (ecs
);
2794 if (step_resume_breakpoint
)
2797 fprintf_unfiltered (gdb_stdlog
,
2798 "infrun: step-resume breakpoint is inserted\n");
2800 /* Having a step-resume breakpoint overrides anything
2801 else having to do with stepping commands until
2802 that breakpoint is reached. */
2807 if (step_range_end
== 0)
2810 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
2811 /* Likewise if we aren't even stepping. */
2816 /* If stepping through a line, keep going if still within it.
2818 Note that step_range_end is the address of the first instruction
2819 beyond the step range, and NOT the address of the last instruction
2821 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2824 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
2825 paddr_nz (step_range_start
),
2826 paddr_nz (step_range_end
));
2831 /* We stepped out of the stepping range. */
2833 /* If we are stepping at the source level and entered the runtime
2834 loader dynamic symbol resolution code, we keep on single stepping
2835 until we exit the run time loader code and reach the callee's
2837 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2838 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2839 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
)
2841 && in_solib_dynsym_resolve_code (stop_pc
)
2845 CORE_ADDR pc_after_resolver
=
2846 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
2849 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
2851 if (pc_after_resolver
)
2853 /* Set up a step-resume breakpoint at the address
2854 indicated by SKIP_SOLIB_RESOLVER. */
2855 struct symtab_and_line sr_sal
;
2857 sr_sal
.pc
= pc_after_resolver
;
2859 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2866 if (step_range_end
!= 1
2867 && (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2868 || step_over_calls
== STEP_OVER_ALL
)
2869 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
2872 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
2873 /* The inferior, while doing a "step" or "next", has ended up in
2874 a signal trampoline (either by a signal being delivered or by
2875 the signal handler returning). Just single-step until the
2876 inferior leaves the trampoline (either by calling the handler
2882 /* Check for subroutine calls. The check for the current frame
2883 equalling the step ID is not necessary - the check of the
2884 previous frame's ID is sufficient - but it is a common case and
2885 cheaper than checking the previous frame's ID.
2887 NOTE: frame_id_eq will never report two invalid frame IDs as
2888 being equal, so to get into this block, both the current and
2889 previous frame must have valid frame IDs. */
2890 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id
)
2891 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id
))
2893 CORE_ADDR real_stop_pc
;
2896 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
2898 if ((step_over_calls
== STEP_OVER_NONE
)
2899 || ((step_range_end
== 1)
2900 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2902 /* I presume that step_over_calls is only 0 when we're
2903 supposed to be stepping at the assembly language level
2904 ("stepi"). Just stop. */
2905 /* Also, maybe we just did a "nexti" inside a prolog, so we
2906 thought it was a subroutine call but it was not. Stop as
2909 print_stop_reason (END_STEPPING_RANGE
, 0);
2910 stop_stepping (ecs
);
2914 if (step_over_calls
== STEP_OVER_ALL
)
2916 /* We're doing a "next", set a breakpoint at callee's return
2917 address (the address at which the caller will
2919 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2924 /* If we are in a function call trampoline (a stub between the
2925 calling routine and the real function), locate the real
2926 function. That's what tells us (a) whether we want to step
2927 into it at all, and (b) what prologue we want to run to the
2928 end of, if we do step into it. */
2929 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
2930 if (real_stop_pc
== 0)
2931 real_stop_pc
= gdbarch_skip_trampoline_code
2932 (current_gdbarch
, get_current_frame (), stop_pc
);
2933 if (real_stop_pc
!= 0)
2934 ecs
->stop_func_start
= real_stop_pc
;
2937 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2938 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs
->stop_func_start
)
2940 in_solib_dynsym_resolve_code (ecs
->stop_func_start
)
2944 struct symtab_and_line sr_sal
;
2946 sr_sal
.pc
= ecs
->stop_func_start
;
2948 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2953 /* If we have line number information for the function we are
2954 thinking of stepping into, step into it.
2956 If there are several symtabs at that PC (e.g. with include
2957 files), just want to know whether *any* of them have line
2958 numbers. find_pc_line handles this. */
2960 struct symtab_and_line tmp_sal
;
2962 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2963 if (tmp_sal
.line
!= 0)
2965 step_into_function (ecs
);
2970 /* If we have no line number and the step-stop-if-no-debug is
2971 set, we stop the step so that the user has a chance to switch
2972 in assembly mode. */
2973 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
2976 print_stop_reason (END_STEPPING_RANGE
, 0);
2977 stop_stepping (ecs
);
2981 /* Set a breakpoint at callee's return address (the address at
2982 which the caller will resume). */
2983 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2988 /* If we're in the return path from a shared library trampoline,
2989 we want to proceed through the trampoline when stepping. */
2990 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
2991 stop_pc
, ecs
->stop_func_name
))
2993 /* Determine where this trampoline returns. */
2994 CORE_ADDR real_stop_pc
;
2995 real_stop_pc
= gdbarch_skip_trampoline_code
2996 (current_gdbarch
, get_current_frame (), stop_pc
);
2999 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3001 /* Only proceed through if we know where it's going. */
3004 /* And put the step-breakpoint there and go until there. */
3005 struct symtab_and_line sr_sal
;
3007 init_sal (&sr_sal
); /* initialize to zeroes */
3008 sr_sal
.pc
= real_stop_pc
;
3009 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3011 /* Do not specify what the fp should be when we stop since
3012 on some machines the prologue is where the new fp value
3014 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3016 /* Restart without fiddling with the step ranges or
3023 ecs
->sal
= find_pc_line (stop_pc
, 0);
3025 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3026 the trampoline processing logic, however, there are some trampolines
3027 that have no names, so we should do trampoline handling first. */
3028 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3029 && ecs
->stop_func_name
== NULL
3030 && ecs
->sal
.line
== 0)
3033 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3035 /* The inferior just stepped into, or returned to, an
3036 undebuggable function (where there is no debugging information
3037 and no line number corresponding to the address where the
3038 inferior stopped). Since we want to skip this kind of code,
3039 we keep going until the inferior returns from this
3040 function - unless the user has asked us not to (via
3041 set step-mode) or we no longer know how to get back
3042 to the call site. */
3043 if (step_stop_if_no_debug
3044 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3046 /* If we have no line number and the step-stop-if-no-debug
3047 is set, we stop the step so that the user has a chance to
3048 switch in assembly mode. */
3050 print_stop_reason (END_STEPPING_RANGE
, 0);
3051 stop_stepping (ecs
);
3056 /* Set a breakpoint at callee's return address (the address
3057 at which the caller will resume). */
3058 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3064 if (step_range_end
== 1)
3066 /* It is stepi or nexti. We always want to stop stepping after
3069 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
3071 print_stop_reason (END_STEPPING_RANGE
, 0);
3072 stop_stepping (ecs
);
3076 if (ecs
->sal
.line
== 0)
3078 /* We have no line number information. That means to stop
3079 stepping (does this always happen right after one instruction,
3080 when we do "s" in a function with no line numbers,
3081 or can this happen as a result of a return or longjmp?). */
3083 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
3085 print_stop_reason (END_STEPPING_RANGE
, 0);
3086 stop_stepping (ecs
);
3090 if ((stop_pc
== ecs
->sal
.pc
)
3091 && (ecs
->current_line
!= ecs
->sal
.line
3092 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
3094 /* We are at the start of a different line. So stop. Note that
3095 we don't stop if we step into the middle of a different line.
3096 That is said to make things like for (;;) statements work
3099 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
3101 print_stop_reason (END_STEPPING_RANGE
, 0);
3102 stop_stepping (ecs
);
3106 /* We aren't done stepping.
3108 Optimize by setting the stepping range to the line.
3109 (We might not be in the original line, but if we entered a
3110 new line in mid-statement, we continue stepping. This makes
3111 things like for(;;) statements work better.) */
3113 step_range_start
= ecs
->sal
.pc
;
3114 step_range_end
= ecs
->sal
.end
;
3115 step_frame_id
= get_frame_id (get_current_frame ());
3116 ecs
->current_line
= ecs
->sal
.line
;
3117 ecs
->current_symtab
= ecs
->sal
.symtab
;
3119 /* In the case where we just stepped out of a function into the
3120 middle of a line of the caller, continue stepping, but
3121 step_frame_id must be modified to current frame */
3123 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
3124 generous. It will trigger on things like a step into a frameless
3125 stackless leaf function. I think the logic should instead look
3126 at the unwound frame ID has that should give a more robust
3127 indication of what happened. */
3128 if (step
- ID
== current
- ID
)
3129 still stepping in same function
;
3130 else if (step
- ID
== unwind (current
- ID
))
3131 stepped into a function
;
3133 stepped out of a function
;
3134 /* Of course this assumes that the frame ID unwind code is robust
3135 and we're willing to introduce frame unwind logic into this
3136 function. Fortunately, those days are nearly upon us. */
3139 struct frame_info
*frame
= get_current_frame ();
3140 struct frame_id current_frame
= get_frame_id (frame
);
3141 if (!(frame_id_inner (get_frame_arch (frame
), current_frame
,
3143 step_frame_id
= current_frame
;
3147 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
3151 /* Are we in the middle of stepping? */
3154 currently_stepping (struct execution_control_state
*ecs
)
3156 return ((!ecs
->handling_longjmp
3157 && ((step_range_end
&& step_resume_breakpoint
== NULL
)
3158 || stepping_over_breakpoint
))
3159 || ecs
->stepping_through_solib_after_catch
3160 || bpstat_should_step ());
3163 /* Subroutine call with source code we should not step over. Do step
3164 to the first line of code in it. */
3167 step_into_function (struct execution_control_state
*ecs
)
3170 struct symtab_and_line sr_sal
;
3172 s
= find_pc_symtab (stop_pc
);
3173 if (s
&& s
->language
!= language_asm
)
3174 ecs
->stop_func_start
= gdbarch_skip_prologue
3175 (current_gdbarch
, ecs
->stop_func_start
);
3177 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3178 /* Use the step_resume_break to step until the end of the prologue,
3179 even if that involves jumps (as it seems to on the vax under
3181 /* If the prologue ends in the middle of a source line, continue to
3182 the end of that source line (if it is still within the function).
3183 Otherwise, just go to end of prologue. */
3185 && ecs
->sal
.pc
!= ecs
->stop_func_start
3186 && ecs
->sal
.end
< ecs
->stop_func_end
)
3187 ecs
->stop_func_start
= ecs
->sal
.end
;
3189 /* Architectures which require breakpoint adjustment might not be able
3190 to place a breakpoint at the computed address. If so, the test
3191 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3192 ecs->stop_func_start to an address at which a breakpoint may be
3193 legitimately placed.
3195 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3196 made, GDB will enter an infinite loop when stepping through
3197 optimized code consisting of VLIW instructions which contain
3198 subinstructions corresponding to different source lines. On
3199 FR-V, it's not permitted to place a breakpoint on any but the
3200 first subinstruction of a VLIW instruction. When a breakpoint is
3201 set, GDB will adjust the breakpoint address to the beginning of
3202 the VLIW instruction. Thus, we need to make the corresponding
3203 adjustment here when computing the stop address. */
3205 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3207 ecs
->stop_func_start
3208 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
3209 ecs
->stop_func_start
);
3212 if (ecs
->stop_func_start
== stop_pc
)
3214 /* We are already there: stop now. */
3216 print_stop_reason (END_STEPPING_RANGE
, 0);
3217 stop_stepping (ecs
);
3222 /* Put the step-breakpoint there and go until there. */
3223 init_sal (&sr_sal
); /* initialize to zeroes */
3224 sr_sal
.pc
= ecs
->stop_func_start
;
3225 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3227 /* Do not specify what the fp should be when we stop since on
3228 some machines the prologue is where the new fp value is
3230 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3232 /* And make sure stepping stops right away then. */
3233 step_range_end
= step_range_start
;
3238 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3239 This is used to both functions and to skip over code. */
3242 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
3243 struct frame_id sr_id
)
3245 /* There should never be more than one step-resume breakpoint per
3246 thread, so we should never be setting a new
3247 step_resume_breakpoint when one is already active. */
3248 gdb_assert (step_resume_breakpoint
== NULL
);
3251 fprintf_unfiltered (gdb_stdlog
,
3252 "infrun: inserting step-resume breakpoint at 0x%s\n",
3253 paddr_nz (sr_sal
.pc
));
3255 step_resume_breakpoint
= set_momentary_breakpoint (sr_sal
, sr_id
,
3259 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3260 to skip a potential signal handler.
3262 This is called with the interrupted function's frame. The signal
3263 handler, when it returns, will resume the interrupted function at
3267 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
3269 struct symtab_and_line sr_sal
;
3271 gdb_assert (return_frame
!= NULL
);
3272 init_sal (&sr_sal
); /* initialize to zeros */
3274 sr_sal
.pc
= gdbarch_addr_bits_remove
3275 (current_gdbarch
, get_frame_pc (return_frame
));
3276 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3278 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
3281 /* Similar to insert_step_resume_breakpoint_at_frame, except
3282 but a breakpoint at the previous frame's PC. This is used to
3283 skip a function after stepping into it (for "next" or if the called
3284 function has no debugging information).
3286 The current function has almost always been reached by single
3287 stepping a call or return instruction. NEXT_FRAME belongs to the
3288 current function, and the breakpoint will be set at the caller's
3291 This is a separate function rather than reusing
3292 insert_step_resume_breakpoint_at_frame in order to avoid
3293 get_prev_frame, which may stop prematurely (see the implementation
3294 of frame_unwind_id for an example). */
3297 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
3299 struct symtab_and_line sr_sal
;
3301 /* We shouldn't have gotten here if we don't know where the call site
3303 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
3305 init_sal (&sr_sal
); /* initialize to zeros */
3307 sr_sal
.pc
= gdbarch_addr_bits_remove
3308 (current_gdbarch
, frame_pc_unwind (next_frame
));
3309 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3311 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
3315 stop_stepping (struct execution_control_state
*ecs
)
3318 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
3320 /* Let callers know we don't want to wait for the inferior anymore. */
3321 ecs
->wait_some_more
= 0;
3324 /* This function handles various cases where we need to continue
3325 waiting for the inferior. */
3326 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3329 keep_going (struct execution_control_state
*ecs
)
3331 /* Save the pc before execution, to compare with pc after stop. */
3332 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3334 /* If we did not do break;, it means we should keep running the
3335 inferior and not return to debugger. */
3337 if (stepping_over_breakpoint
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3339 /* We took a signal (which we are supposed to pass through to
3340 the inferior, else we'd have done a break above) and we
3341 haven't yet gotten our trap. Simply continue. */
3342 resume (currently_stepping (ecs
), stop_signal
);
3346 /* Either the trap was not expected, but we are continuing
3347 anyway (the user asked that this signal be passed to the
3350 The signal was SIGTRAP, e.g. it was our signal, but we
3351 decided we should resume from it.
3353 We're going to run this baby now!
3355 Note that insert_breakpoints won't try to re-insert
3356 already inserted breakpoints. Therefore, we don't
3357 care if breakpoints were already inserted, or not. */
3359 if (ecs
->stepping_over_breakpoint
)
3361 if (! use_displaced_stepping (current_gdbarch
))
3362 /* Since we can't do a displaced step, we have to remove
3363 the breakpoint while we step it. To keep things
3364 simple, we remove them all. */
3365 remove_breakpoints ();
3369 struct gdb_exception e
;
3370 /* Stop stepping when inserting breakpoints
3372 TRY_CATCH (e
, RETURN_MASK_ERROR
)
3374 insert_breakpoints ();
3378 stop_stepping (ecs
);
3383 stepping_over_breakpoint
= ecs
->stepping_over_breakpoint
;
3385 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3386 specifies that such a signal should be delivered to the
3389 Typically, this would occure when a user is debugging a
3390 target monitor on a simulator: the target monitor sets a
3391 breakpoint; the simulator encounters this break-point and
3392 halts the simulation handing control to GDB; GDB, noteing
3393 that the break-point isn't valid, returns control back to the
3394 simulator; the simulator then delivers the hardware
3395 equivalent of a SIGNAL_TRAP to the program being debugged. */
3397 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3398 stop_signal
= TARGET_SIGNAL_0
;
3401 resume (currently_stepping (ecs
), stop_signal
);
3404 prepare_to_wait (ecs
);
3407 /* This function normally comes after a resume, before
3408 handle_inferior_event exits. It takes care of any last bits of
3409 housekeeping, and sets the all-important wait_some_more flag. */
3412 prepare_to_wait (struct execution_control_state
*ecs
)
3415 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
3416 if (ecs
->infwait_state
== infwait_normal_state
)
3418 overlay_cache_invalid
= 1;
3420 /* We have to invalidate the registers BEFORE calling
3421 target_wait because they can be loaded from the target while
3422 in target_wait. This makes remote debugging a bit more
3423 efficient for those targets that provide critical registers
3424 as part of their normal status mechanism. */
3426 registers_changed ();
3427 ecs
->waiton_ptid
= pid_to_ptid (-1);
3428 ecs
->wp
= &(ecs
->ws
);
3430 /* This is the old end of the while loop. Let everybody know we
3431 want to wait for the inferior some more and get called again
3433 ecs
->wait_some_more
= 1;
3436 /* Print why the inferior has stopped. We always print something when
3437 the inferior exits, or receives a signal. The rest of the cases are
3438 dealt with later on in normal_stop() and print_it_typical(). Ideally
3439 there should be a call to this function from handle_inferior_event()
3440 each time stop_stepping() is called.*/
3442 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3444 switch (stop_reason
)
3446 case END_STEPPING_RANGE
:
3447 /* We are done with a step/next/si/ni command. */
3448 /* For now print nothing. */
3449 /* Print a message only if not in the middle of doing a "step n"
3450 operation for n > 1 */
3451 if (!step_multi
|| !stop_step
)
3452 if (ui_out_is_mi_like_p (uiout
))
3455 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
3458 /* The inferior was terminated by a signal. */
3459 annotate_signalled ();
3460 if (ui_out_is_mi_like_p (uiout
))
3463 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
3464 ui_out_text (uiout
, "\nProgram terminated with signal ");
3465 annotate_signal_name ();
3466 ui_out_field_string (uiout
, "signal-name",
3467 target_signal_to_name (stop_info
));
3468 annotate_signal_name_end ();
3469 ui_out_text (uiout
, ", ");
3470 annotate_signal_string ();
3471 ui_out_field_string (uiout
, "signal-meaning",
3472 target_signal_to_string (stop_info
));
3473 annotate_signal_string_end ();
3474 ui_out_text (uiout
, ".\n");
3475 ui_out_text (uiout
, "The program no longer exists.\n");
3478 /* The inferior program is finished. */
3479 annotate_exited (stop_info
);
3482 if (ui_out_is_mi_like_p (uiout
))
3483 ui_out_field_string (uiout
, "reason",
3484 async_reason_lookup (EXEC_ASYNC_EXITED
));
3485 ui_out_text (uiout
, "\nProgram exited with code ");
3486 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3487 (unsigned int) stop_info
);
3488 ui_out_text (uiout
, ".\n");
3492 if (ui_out_is_mi_like_p (uiout
))
3495 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
3496 ui_out_text (uiout
, "\nProgram exited normally.\n");
3498 /* Support the --return-child-result option. */
3499 return_child_result_value
= stop_info
;
3501 case SIGNAL_RECEIVED
:
3502 /* Signal received. The signal table tells us to print about
3505 ui_out_text (uiout
, "\nProgram received signal ");
3506 annotate_signal_name ();
3507 if (ui_out_is_mi_like_p (uiout
))
3509 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
3510 ui_out_field_string (uiout
, "signal-name",
3511 target_signal_to_name (stop_info
));
3512 annotate_signal_name_end ();
3513 ui_out_text (uiout
, ", ");
3514 annotate_signal_string ();
3515 ui_out_field_string (uiout
, "signal-meaning",
3516 target_signal_to_string (stop_info
));
3517 annotate_signal_string_end ();
3518 ui_out_text (uiout
, ".\n");
3521 internal_error (__FILE__
, __LINE__
,
3522 _("print_stop_reason: unrecognized enum value"));
3528 /* Here to return control to GDB when the inferior stops for real.
3529 Print appropriate messages, remove breakpoints, give terminal our modes.
3531 STOP_PRINT_FRAME nonzero means print the executing frame
3532 (pc, function, args, file, line number and line text).
3533 BREAKPOINTS_FAILED nonzero means stop was due to error
3534 attempting to insert breakpoints. */
3539 struct target_waitstatus last
;
3542 get_last_target_status (&last_ptid
, &last
);
3544 /* As with the notification of thread events, we want to delay
3545 notifying the user that we've switched thread context until
3546 the inferior actually stops.
3548 There's no point in saying anything if the inferior has exited.
3549 Note that SIGNALLED here means "exited with a signal", not
3550 "received a signal". */
3551 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3552 && target_has_execution
3553 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3554 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3556 target_terminal_ours_for_output ();
3557 printf_filtered (_("[Switching to %s]\n"),
3558 target_pid_to_str (inferior_ptid
));
3559 previous_inferior_ptid
= inferior_ptid
;
3562 /* NOTE drow/2004-01-17: Is this still necessary? */
3563 /* Make sure that the current_frame's pc is correct. This
3564 is a correction for setting up the frame info before doing
3565 gdbarch_decr_pc_after_break */
3566 if (target_has_execution
)
3567 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3568 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3569 frame code to check for this and sort out any resultant mess.
3570 gdbarch_decr_pc_after_break needs to just go away. */
3571 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3573 if (!breakpoints_always_inserted_mode () && target_has_execution
)
3575 if (remove_breakpoints ())
3577 target_terminal_ours_for_output ();
3578 printf_filtered (_("\
3579 Cannot remove breakpoints because program is no longer writable.\n\
3580 It might be running in another process.\n\
3581 Further execution is probably impossible.\n"));
3585 /* If an auto-display called a function and that got a signal,
3586 delete that auto-display to avoid an infinite recursion. */
3588 if (stopped_by_random_signal
)
3589 disable_current_display ();
3591 /* Don't print a message if in the middle of doing a "step n"
3592 operation for n > 1 */
3593 if (step_multi
&& stop_step
)
3596 target_terminal_ours ();
3598 /* Set the current source location. This will also happen if we
3599 display the frame below, but the current SAL will be incorrect
3600 during a user hook-stop function. */
3601 if (target_has_stack
&& !stop_stack_dummy
)
3602 set_current_sal_from_frame (get_current_frame (), 1);
3604 /* Look up the hook_stop and run it (CLI internally handles problem
3605 of stop_command's pre-hook not existing). */
3607 catch_errors (hook_stop_stub
, stop_command
,
3608 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3610 if (!target_has_stack
)
3616 /* Select innermost stack frame - i.e., current frame is frame 0,
3617 and current location is based on that.
3618 Don't do this on return from a stack dummy routine,
3619 or if the program has exited. */
3621 if (!stop_stack_dummy
)
3623 select_frame (get_current_frame ());
3625 /* Print current location without a level number, if
3626 we have changed functions or hit a breakpoint.
3627 Print source line if we have one.
3628 bpstat_print() contains the logic deciding in detail
3629 what to print, based on the event(s) that just occurred. */
3631 /* If --batch-silent is enabled then there's no need to print the current
3632 source location, and to try risks causing an error message about
3633 missing source files. */
3634 if (stop_print_frame
&& !batch_silent
)
3638 int do_frame_printing
= 1;
3640 bpstat_ret
= bpstat_print (stop_bpstat
);
3644 /* If we had hit a shared library event breakpoint,
3645 bpstat_print would print out this message. If we hit
3646 an OS-level shared library event, do the same
3648 if (last
.kind
== TARGET_WAITKIND_LOADED
)
3650 printf_filtered (_("Stopped due to shared library event\n"));
3651 source_flag
= SRC_LINE
; /* something bogus */
3652 do_frame_printing
= 0;
3656 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3657 (or should) carry around the function and does (or
3658 should) use that when doing a frame comparison. */
3660 && frame_id_eq (step_frame_id
,
3661 get_frame_id (get_current_frame ()))
3662 && step_start_function
== find_pc_function (stop_pc
))
3663 source_flag
= SRC_LINE
; /* finished step, just print source line */
3665 source_flag
= SRC_AND_LOC
; /* print location and source line */
3667 case PRINT_SRC_AND_LOC
:
3668 source_flag
= SRC_AND_LOC
; /* print location and source line */
3670 case PRINT_SRC_ONLY
:
3671 source_flag
= SRC_LINE
;
3674 source_flag
= SRC_LINE
; /* something bogus */
3675 do_frame_printing
= 0;
3678 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
3681 if (ui_out_is_mi_like_p (uiout
))
3682 ui_out_field_int (uiout
, "thread-id",
3683 pid_to_thread_id (inferior_ptid
));
3684 /* The behavior of this routine with respect to the source
3686 SRC_LINE: Print only source line
3687 LOCATION: Print only location
3688 SRC_AND_LOC: Print location and source line */
3689 if (do_frame_printing
)
3690 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
3692 /* Display the auto-display expressions. */
3697 /* Save the function value return registers, if we care.
3698 We might be about to restore their previous contents. */
3699 if (proceed_to_finish
)
3701 /* This should not be necessary. */
3703 regcache_xfree (stop_registers
);
3705 /* NB: The copy goes through to the target picking up the value of
3706 all the registers. */
3707 stop_registers
= regcache_dup (get_current_regcache ());
3710 if (stop_stack_dummy
)
3712 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3713 ends with a setting of the current frame, so we can use that
3715 frame_pop (get_current_frame ());
3716 /* Set stop_pc to what it was before we called the function.
3717 Can't rely on restore_inferior_status because that only gets
3718 called if we don't stop in the called function. */
3719 stop_pc
= read_pc ();
3720 select_frame (get_current_frame ());
3724 annotate_stopped ();
3725 observer_notify_normal_stop (stop_bpstat
);
3726 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3727 Delete any breakpoint that is to be deleted at the next stop. */
3728 breakpoint_auto_delete (stop_bpstat
);
3732 hook_stop_stub (void *cmd
)
3734 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3739 signal_stop_state (int signo
)
3741 /* Always stop on signals if we're just gaining control of the
3743 return signal_stop
[signo
] || stop_soon
!= NO_STOP_QUIETLY
;
3747 signal_print_state (int signo
)
3749 return signal_print
[signo
];
3753 signal_pass_state (int signo
)
3755 return signal_program
[signo
];
3759 signal_stop_update (int signo
, int state
)
3761 int ret
= signal_stop
[signo
];
3762 signal_stop
[signo
] = state
;
3767 signal_print_update (int signo
, int state
)
3769 int ret
= signal_print
[signo
];
3770 signal_print
[signo
] = state
;
3775 signal_pass_update (int signo
, int state
)
3777 int ret
= signal_program
[signo
];
3778 signal_program
[signo
] = state
;
3783 sig_print_header (void)
3785 printf_filtered (_("\
3786 Signal Stop\tPrint\tPass to program\tDescription\n"));
3790 sig_print_info (enum target_signal oursig
)
3792 char *name
= target_signal_to_name (oursig
);
3793 int name_padding
= 13 - strlen (name
);
3795 if (name_padding
<= 0)
3798 printf_filtered ("%s", name
);
3799 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3800 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3801 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3802 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3803 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3806 /* Specify how various signals in the inferior should be handled. */
3809 handle_command (char *args
, int from_tty
)
3812 int digits
, wordlen
;
3813 int sigfirst
, signum
, siglast
;
3814 enum target_signal oursig
;
3817 unsigned char *sigs
;
3818 struct cleanup
*old_chain
;
3822 error_no_arg (_("signal to handle"));
3825 /* Allocate and zero an array of flags for which signals to handle. */
3827 nsigs
= (int) TARGET_SIGNAL_LAST
;
3828 sigs
= (unsigned char *) alloca (nsigs
);
3829 memset (sigs
, 0, nsigs
);
3831 /* Break the command line up into args. */
3833 argv
= buildargv (args
);
3838 old_chain
= make_cleanup_freeargv (argv
);
3840 /* Walk through the args, looking for signal oursigs, signal names, and
3841 actions. Signal numbers and signal names may be interspersed with
3842 actions, with the actions being performed for all signals cumulatively
3843 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3845 while (*argv
!= NULL
)
3847 wordlen
= strlen (*argv
);
3848 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3852 sigfirst
= siglast
= -1;
3854 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3856 /* Apply action to all signals except those used by the
3857 debugger. Silently skip those. */
3860 siglast
= nsigs
- 1;
3862 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3864 SET_SIGS (nsigs
, sigs
, signal_stop
);
3865 SET_SIGS (nsigs
, sigs
, signal_print
);
3867 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3869 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3871 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3873 SET_SIGS (nsigs
, sigs
, signal_print
);
3875 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3877 SET_SIGS (nsigs
, sigs
, signal_program
);
3879 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3881 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3883 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3885 SET_SIGS (nsigs
, sigs
, signal_program
);
3887 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3889 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3890 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3892 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3894 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3896 else if (digits
> 0)
3898 /* It is numeric. The numeric signal refers to our own
3899 internal signal numbering from target.h, not to host/target
3900 signal number. This is a feature; users really should be
3901 using symbolic names anyway, and the common ones like
3902 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3904 sigfirst
= siglast
= (int)
3905 target_signal_from_command (atoi (*argv
));
3906 if ((*argv
)[digits
] == '-')
3909 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3911 if (sigfirst
> siglast
)
3913 /* Bet he didn't figure we'd think of this case... */
3921 oursig
= target_signal_from_name (*argv
);
3922 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3924 sigfirst
= siglast
= (int) oursig
;
3928 /* Not a number and not a recognized flag word => complain. */
3929 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
3933 /* If any signal numbers or symbol names were found, set flags for
3934 which signals to apply actions to. */
3936 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3938 switch ((enum target_signal
) signum
)
3940 case TARGET_SIGNAL_TRAP
:
3941 case TARGET_SIGNAL_INT
:
3942 if (!allsigs
&& !sigs
[signum
])
3944 if (query ("%s is used by the debugger.\n\
3945 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
3951 printf_unfiltered (_("Not confirmed, unchanged.\n"));
3952 gdb_flush (gdb_stdout
);
3956 case TARGET_SIGNAL_0
:
3957 case TARGET_SIGNAL_DEFAULT
:
3958 case TARGET_SIGNAL_UNKNOWN
:
3959 /* Make sure that "all" doesn't print these. */
3970 target_notice_signals (inferior_ptid
);
3974 /* Show the results. */
3975 sig_print_header ();
3976 for (signum
= 0; signum
< nsigs
; signum
++)
3980 sig_print_info (signum
);
3985 do_cleanups (old_chain
);
3989 xdb_handle_command (char *args
, int from_tty
)
3992 struct cleanup
*old_chain
;
3994 /* Break the command line up into args. */
3996 argv
= buildargv (args
);
4001 old_chain
= make_cleanup_freeargv (argv
);
4002 if (argv
[1] != (char *) NULL
)
4007 bufLen
= strlen (argv
[0]) + 20;
4008 argBuf
= (char *) xmalloc (bufLen
);
4012 enum target_signal oursig
;
4014 oursig
= target_signal_from_name (argv
[0]);
4015 memset (argBuf
, 0, bufLen
);
4016 if (strcmp (argv
[1], "Q") == 0)
4017 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4020 if (strcmp (argv
[1], "s") == 0)
4022 if (!signal_stop
[oursig
])
4023 sprintf (argBuf
, "%s %s", argv
[0], "stop");
4025 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
4027 else if (strcmp (argv
[1], "i") == 0)
4029 if (!signal_program
[oursig
])
4030 sprintf (argBuf
, "%s %s", argv
[0], "pass");
4032 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
4034 else if (strcmp (argv
[1], "r") == 0)
4036 if (!signal_print
[oursig
])
4037 sprintf (argBuf
, "%s %s", argv
[0], "print");
4039 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4045 handle_command (argBuf
, from_tty
);
4047 printf_filtered (_("Invalid signal handling flag.\n"));
4052 do_cleanups (old_chain
);
4055 /* Print current contents of the tables set by the handle command.
4056 It is possible we should just be printing signals actually used
4057 by the current target (but for things to work right when switching
4058 targets, all signals should be in the signal tables). */
4061 signals_info (char *signum_exp
, int from_tty
)
4063 enum target_signal oursig
;
4064 sig_print_header ();
4068 /* First see if this is a symbol name. */
4069 oursig
= target_signal_from_name (signum_exp
);
4070 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
4072 /* No, try numeric. */
4074 target_signal_from_command (parse_and_eval_long (signum_exp
));
4076 sig_print_info (oursig
);
4080 printf_filtered ("\n");
4081 /* These ugly casts brought to you by the native VAX compiler. */
4082 for (oursig
= TARGET_SIGNAL_FIRST
;
4083 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
4084 oursig
= (enum target_signal
) ((int) oursig
+ 1))
4088 if (oursig
!= TARGET_SIGNAL_UNKNOWN
4089 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
4090 sig_print_info (oursig
);
4093 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4096 struct inferior_status
4098 enum target_signal stop_signal
;
4102 int stop_stack_dummy
;
4103 int stopped_by_random_signal
;
4104 int stepping_over_breakpoint
;
4105 CORE_ADDR step_range_start
;
4106 CORE_ADDR step_range_end
;
4107 struct frame_id step_frame_id
;
4108 enum step_over_calls_kind step_over_calls
;
4109 CORE_ADDR step_resume_break_address
;
4110 int stop_after_trap
;
4113 /* These are here because if call_function_by_hand has written some
4114 registers and then decides to call error(), we better not have changed
4116 struct regcache
*registers
;
4118 /* A frame unique identifier. */
4119 struct frame_id selected_frame_id
;
4121 int breakpoint_proceeded
;
4122 int restore_stack_info
;
4123 int proceed_to_finish
;
4127 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
4130 int size
= register_size (current_gdbarch
, regno
);
4131 void *buf
= alloca (size
);
4132 store_signed_integer (buf
, size
, val
);
4133 regcache_raw_write (inf_status
->registers
, regno
, buf
);
4136 /* Save all of the information associated with the inferior<==>gdb
4137 connection. INF_STATUS is a pointer to a "struct inferior_status"
4138 (defined in inferior.h). */
4140 struct inferior_status
*
4141 save_inferior_status (int restore_stack_info
)
4143 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
4145 inf_status
->stop_signal
= stop_signal
;
4146 inf_status
->stop_pc
= stop_pc
;
4147 inf_status
->stop_step
= stop_step
;
4148 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
4149 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
4150 inf_status
->stepping_over_breakpoint
= stepping_over_breakpoint
;
4151 inf_status
->step_range_start
= step_range_start
;
4152 inf_status
->step_range_end
= step_range_end
;
4153 inf_status
->step_frame_id
= step_frame_id
;
4154 inf_status
->step_over_calls
= step_over_calls
;
4155 inf_status
->stop_after_trap
= stop_after_trap
;
4156 inf_status
->stop_soon
= stop_soon
;
4157 /* Save original bpstat chain here; replace it with copy of chain.
4158 If caller's caller is walking the chain, they'll be happier if we
4159 hand them back the original chain when restore_inferior_status is
4161 inf_status
->stop_bpstat
= stop_bpstat
;
4162 stop_bpstat
= bpstat_copy (stop_bpstat
);
4163 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4164 inf_status
->restore_stack_info
= restore_stack_info
;
4165 inf_status
->proceed_to_finish
= proceed_to_finish
;
4167 inf_status
->registers
= regcache_dup (get_current_regcache ());
4169 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
4174 restore_selected_frame (void *args
)
4176 struct frame_id
*fid
= (struct frame_id
*) args
;
4177 struct frame_info
*frame
;
4179 frame
= frame_find_by_id (*fid
);
4181 /* If inf_status->selected_frame_id is NULL, there was no previously
4185 warning (_("Unable to restore previously selected frame."));
4189 select_frame (frame
);
4195 restore_inferior_status (struct inferior_status
*inf_status
)
4197 stop_signal
= inf_status
->stop_signal
;
4198 stop_pc
= inf_status
->stop_pc
;
4199 stop_step
= inf_status
->stop_step
;
4200 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4201 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4202 stepping_over_breakpoint
= inf_status
->stepping_over_breakpoint
;
4203 step_range_start
= inf_status
->step_range_start
;
4204 step_range_end
= inf_status
->step_range_end
;
4205 step_frame_id
= inf_status
->step_frame_id
;
4206 step_over_calls
= inf_status
->step_over_calls
;
4207 stop_after_trap
= inf_status
->stop_after_trap
;
4208 stop_soon
= inf_status
->stop_soon
;
4209 bpstat_clear (&stop_bpstat
);
4210 stop_bpstat
= inf_status
->stop_bpstat
;
4211 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4212 proceed_to_finish
= inf_status
->proceed_to_finish
;
4214 /* The inferior can be gone if the user types "print exit(0)"
4215 (and perhaps other times). */
4216 if (target_has_execution
)
4217 /* NB: The register write goes through to the target. */
4218 regcache_cpy (get_current_regcache (), inf_status
->registers
);
4219 regcache_xfree (inf_status
->registers
);
4221 /* FIXME: If we are being called after stopping in a function which
4222 is called from gdb, we should not be trying to restore the
4223 selected frame; it just prints a spurious error message (The
4224 message is useful, however, in detecting bugs in gdb (like if gdb
4225 clobbers the stack)). In fact, should we be restoring the
4226 inferior status at all in that case? . */
4228 if (target_has_stack
&& inf_status
->restore_stack_info
)
4230 /* The point of catch_errors is that if the stack is clobbered,
4231 walking the stack might encounter a garbage pointer and
4232 error() trying to dereference it. */
4234 (restore_selected_frame
, &inf_status
->selected_frame_id
,
4235 "Unable to restore previously selected frame:\n",
4236 RETURN_MASK_ERROR
) == 0)
4237 /* Error in restoring the selected frame. Select the innermost
4239 select_frame (get_current_frame ());
4247 do_restore_inferior_status_cleanup (void *sts
)
4249 restore_inferior_status (sts
);
4253 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4255 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4259 discard_inferior_status (struct inferior_status
*inf_status
)
4261 /* See save_inferior_status for info on stop_bpstat. */
4262 bpstat_clear (&inf_status
->stop_bpstat
);
4263 regcache_xfree (inf_status
->registers
);
4268 inferior_has_forked (int pid
, int *child_pid
)
4270 struct target_waitstatus last
;
4273 get_last_target_status (&last_ptid
, &last
);
4275 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
4278 if (ptid_get_pid (last_ptid
) != pid
)
4281 *child_pid
= last
.value
.related_pid
;
4286 inferior_has_vforked (int pid
, int *child_pid
)
4288 struct target_waitstatus last
;
4291 get_last_target_status (&last_ptid
, &last
);
4293 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
4296 if (ptid_get_pid (last_ptid
) != pid
)
4299 *child_pid
= last
.value
.related_pid
;
4304 inferior_has_execd (int pid
, char **execd_pathname
)
4306 struct target_waitstatus last
;
4309 get_last_target_status (&last_ptid
, &last
);
4311 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
4314 if (ptid_get_pid (last_ptid
) != pid
)
4317 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
4321 /* Oft used ptids */
4323 ptid_t minus_one_ptid
;
4325 /* Create a ptid given the necessary PID, LWP, and TID components. */
4328 ptid_build (int pid
, long lwp
, long tid
)
4338 /* Create a ptid from just a pid. */
4341 pid_to_ptid (int pid
)
4343 return ptid_build (pid
, 0, 0);
4346 /* Fetch the pid (process id) component from a ptid. */
4349 ptid_get_pid (ptid_t ptid
)
4354 /* Fetch the lwp (lightweight process) component from a ptid. */
4357 ptid_get_lwp (ptid_t ptid
)
4362 /* Fetch the tid (thread id) component from a ptid. */
4365 ptid_get_tid (ptid_t ptid
)
4370 /* ptid_equal() is used to test equality of two ptids. */
4373 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4375 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4376 && ptid1
.tid
== ptid2
.tid
);
4379 /* restore_inferior_ptid() will be used by the cleanup machinery
4380 to restore the inferior_ptid value saved in a call to
4381 save_inferior_ptid(). */
4384 restore_inferior_ptid (void *arg
)
4386 ptid_t
*saved_ptid_ptr
= arg
;
4387 inferior_ptid
= *saved_ptid_ptr
;
4391 /* Save the value of inferior_ptid so that it may be restored by a
4392 later call to do_cleanups(). Returns the struct cleanup pointer
4393 needed for later doing the cleanup. */
4396 save_inferior_ptid (void)
4398 ptid_t
*saved_ptid_ptr
;
4400 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4401 *saved_ptid_ptr
= inferior_ptid
;
4402 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4407 _initialize_infrun (void)
4411 struct cmd_list_element
*c
;
4413 add_info ("signals", signals_info
, _("\
4414 What debugger does when program gets various signals.\n\
4415 Specify a signal as argument to print info on that signal only."));
4416 add_info_alias ("handle", "signals", 0);
4418 add_com ("handle", class_run
, handle_command
, _("\
4419 Specify how to handle a signal.\n\
4420 Args are signals and actions to apply to those signals.\n\
4421 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4422 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4423 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4424 The special arg \"all\" is recognized to mean all signals except those\n\
4425 used by the debugger, typically SIGTRAP and SIGINT.\n\
4426 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4427 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4428 Stop means reenter debugger if this signal happens (implies print).\n\
4429 Print means print a message if this signal happens.\n\
4430 Pass means let program see this signal; otherwise program doesn't know.\n\
4431 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4432 Pass and Stop may be combined."));
4435 add_com ("lz", class_info
, signals_info
, _("\
4436 What debugger does when program gets various signals.\n\
4437 Specify a signal as argument to print info on that signal only."));
4438 add_com ("z", class_run
, xdb_handle_command
, _("\
4439 Specify how to handle a signal.\n\
4440 Args are signals and actions to apply to those signals.\n\
4441 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4442 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4443 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4444 The special arg \"all\" is recognized to mean all signals except those\n\
4445 used by the debugger, typically SIGTRAP and SIGINT.\n\
4446 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4447 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4448 nopass), \"Q\" (noprint)\n\
4449 Stop means reenter debugger if this signal happens (implies print).\n\
4450 Print means print a message if this signal happens.\n\
4451 Pass means let program see this signal; otherwise program doesn't know.\n\
4452 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4453 Pass and Stop may be combined."));
4457 stop_command
= add_cmd ("stop", class_obscure
,
4458 not_just_help_class_command
, _("\
4459 There is no `stop' command, but you can set a hook on `stop'.\n\
4460 This allows you to set a list of commands to be run each time execution\n\
4461 of the program stops."), &cmdlist
);
4463 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
4464 Set inferior debugging."), _("\
4465 Show inferior debugging."), _("\
4466 When non-zero, inferior specific debugging is enabled."),
4469 &setdebuglist
, &showdebuglist
);
4471 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
4472 Set displaced stepping debugging."), _("\
4473 Show displaced stepping debugging."), _("\
4474 When non-zero, displaced stepping specific debugging is enabled."),
4476 show_debug_displaced
,
4477 &setdebuglist
, &showdebuglist
);
4479 numsigs
= (int) TARGET_SIGNAL_LAST
;
4480 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4481 signal_print
= (unsigned char *)
4482 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4483 signal_program
= (unsigned char *)
4484 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4485 for (i
= 0; i
< numsigs
; i
++)
4488 signal_print
[i
] = 1;
4489 signal_program
[i
] = 1;
4492 /* Signals caused by debugger's own actions
4493 should not be given to the program afterwards. */
4494 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4495 signal_program
[TARGET_SIGNAL_INT
] = 0;
4497 /* Signals that are not errors should not normally enter the debugger. */
4498 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4499 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4500 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4501 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4502 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4503 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4504 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4505 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4506 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4507 signal_print
[TARGET_SIGNAL_IO
] = 0;
4508 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4509 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4510 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4511 signal_print
[TARGET_SIGNAL_URG
] = 0;
4512 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4513 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4515 /* These signals are used internally by user-level thread
4516 implementations. (See signal(5) on Solaris.) Like the above
4517 signals, a healthy program receives and handles them as part of
4518 its normal operation. */
4519 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4520 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4521 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4522 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4523 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4524 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4526 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
4527 &stop_on_solib_events
, _("\
4528 Set stopping for shared library events."), _("\
4529 Show stopping for shared library events."), _("\
4530 If nonzero, gdb will give control to the user when the dynamic linker\n\
4531 notifies gdb of shared library events. The most common event of interest\n\
4532 to the user would be loading/unloading of a new library."),
4534 show_stop_on_solib_events
,
4535 &setlist
, &showlist
);
4537 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
4538 follow_fork_mode_kind_names
,
4539 &follow_fork_mode_string
, _("\
4540 Set debugger response to a program call of fork or vfork."), _("\
4541 Show debugger response to a program call of fork or vfork."), _("\
4542 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4543 parent - the original process is debugged after a fork\n\
4544 child - the new process is debugged after a fork\n\
4545 The unfollowed process will continue to run.\n\
4546 By default, the debugger will follow the parent process."),
4548 show_follow_fork_mode_string
,
4549 &setlist
, &showlist
);
4551 add_setshow_enum_cmd ("scheduler-locking", class_run
,
4552 scheduler_enums
, &scheduler_mode
, _("\
4553 Set mode for locking scheduler during execution."), _("\
4554 Show mode for locking scheduler during execution."), _("\
4555 off == no locking (threads may preempt at any time)\n\
4556 on == full locking (no thread except the current thread may run)\n\
4557 step == scheduler locked during every single-step operation.\n\
4558 In this mode, no other thread may run during a step command.\n\
4559 Other threads may run while stepping over a function call ('next')."),
4560 set_schedlock_func
, /* traps on target vector */
4561 show_scheduler_mode
,
4562 &setlist
, &showlist
);
4564 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
4565 Set mode of the step operation."), _("\
4566 Show mode of the step operation."), _("\
4567 When set, doing a step over a function without debug line information\n\
4568 will stop at the first instruction of that function. Otherwise, the\n\
4569 function is skipped and the step command stops at a different source line."),
4571 show_step_stop_if_no_debug
,
4572 &setlist
, &showlist
);
4574 add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance
,
4575 &can_use_displaced_stepping
, _("\
4576 Set debugger's willingness to use displaced stepping."), _("\
4577 Show debugger's willingness to use displaced stepping."), _("\
4578 If zero, gdb will not use to use displaced stepping to step over\n\
4579 breakpoints, even if such is supported by the target."),
4581 show_can_use_displaced_stepping
,
4582 &maintenance_set_cmdlist
,
4583 &maintenance_show_cmdlist
);
4586 /* ptid initializations */
4587 null_ptid
= ptid_build (0, 0, 0);
4588 minus_one_ptid
= ptid_build (-1, 0, 0);
4589 inferior_ptid
= null_ptid
;
4590 target_last_wait_ptid
= minus_one_ptid
;
4591 displaced_step_ptid
= null_ptid
;