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 /* Step-resume or longjmp-resume breakpoint. */
283 static struct breakpoint
*step_resume_breakpoint
= NULL
;
285 /* This is a cached copy of the pid/waitstatus of the last event
286 returned by target_wait()/deprecated_target_wait_hook(). This
287 information is returned by get_last_target_status(). */
288 static ptid_t target_last_wait_ptid
;
289 static struct target_waitstatus target_last_waitstatus
;
291 /* This is used to remember when a fork, vfork or exec event
292 was caught by a catchpoint, and thus the event is to be
293 followed at the next resume of the inferior, and not
297 enum target_waitkind kind
;
304 char *execd_pathname
;
308 static const char follow_fork_mode_child
[] = "child";
309 static const char follow_fork_mode_parent
[] = "parent";
311 static const char *follow_fork_mode_kind_names
[] = {
312 follow_fork_mode_child
,
313 follow_fork_mode_parent
,
317 static const char *follow_fork_mode_string
= follow_fork_mode_parent
;
319 show_follow_fork_mode_string (struct ui_file
*file
, int from_tty
,
320 struct cmd_list_element
*c
, const char *value
)
322 fprintf_filtered (file
, _("\
323 Debugger response to a program call of fork or vfork is \"%s\".\n"),
331 int follow_child
= (follow_fork_mode_string
== follow_fork_mode_child
);
333 return target_follow_fork (follow_child
);
337 follow_inferior_reset_breakpoints (void)
339 /* Was there a step_resume breakpoint? (There was if the user
340 did a "next" at the fork() call.) If so, explicitly reset its
343 step_resumes are a form of bp that are made to be per-thread.
344 Since we created the step_resume bp when the parent process
345 was being debugged, and now are switching to the child process,
346 from the breakpoint package's viewpoint, that's a switch of
347 "threads". We must update the bp's notion of which thread
348 it is for, or it'll be ignored when it triggers. */
350 if (step_resume_breakpoint
)
351 breakpoint_re_set_thread (step_resume_breakpoint
);
353 /* Reinsert all breakpoints in the child. The user may have set
354 breakpoints after catching the fork, in which case those
355 were never set in the child, but only in the parent. This makes
356 sure the inserted breakpoints match the breakpoint list. */
358 breakpoint_re_set ();
359 insert_breakpoints ();
362 /* EXECD_PATHNAME is assumed to be non-NULL. */
365 follow_exec (int pid
, char *execd_pathname
)
368 struct target_ops
*tgt
;
370 /* This is an exec event that we actually wish to pay attention to.
371 Refresh our symbol table to the newly exec'd program, remove any
374 If there are breakpoints, they aren't really inserted now,
375 since the exec() transformed our inferior into a fresh set
378 We want to preserve symbolic breakpoints on the list, since
379 we have hopes that they can be reset after the new a.out's
380 symbol table is read.
382 However, any "raw" breakpoints must be removed from the list
383 (e.g., the solib bp's), since their address is probably invalid
386 And, we DON'T want to call delete_breakpoints() here, since
387 that may write the bp's "shadow contents" (the instruction
388 value that was overwritten witha TRAP instruction). Since
389 we now have a new a.out, those shadow contents aren't valid. */
390 update_breakpoints_after_exec ();
392 /* If there was one, it's gone now. We cannot truly step-to-next
393 statement through an exec(). */
394 step_resume_breakpoint
= NULL
;
395 step_range_start
= 0;
398 /* What is this a.out's name? */
399 printf_unfiltered (_("Executing new program: %s\n"), execd_pathname
);
401 /* We've followed the inferior through an exec. Therefore, the
402 inferior has essentially been killed & reborn. */
404 gdb_flush (gdb_stdout
);
405 generic_mourn_inferior ();
406 /* Because mourn_inferior resets inferior_ptid. */
407 inferior_ptid
= pid_to_ptid (saved_pid
);
409 if (gdb_sysroot
&& *gdb_sysroot
)
411 char *name
= alloca (strlen (gdb_sysroot
)
412 + strlen (execd_pathname
)
414 strcpy (name
, gdb_sysroot
);
415 strcat (name
, execd_pathname
);
416 execd_pathname
= name
;
419 /* That a.out is now the one to use. */
420 exec_file_attach (execd_pathname
, 0);
422 /* And also is where symbols can be found. */
423 symbol_file_add_main (execd_pathname
, 0);
425 /* Reset the shared library package. This ensures that we get
426 a shlib event when the child reaches "_start", at which point
427 the dld will have had a chance to initialize the child. */
428 no_shared_libraries (NULL
, 0);
429 #ifdef SOLIB_CREATE_INFERIOR_HOOK
430 SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid
));
432 solib_create_inferior_hook ();
435 /* Reinsert all breakpoints. (Those which were symbolic have
436 been reset to the proper address in the new a.out, thanks
437 to symbol_file_command...) */
438 insert_breakpoints ();
440 /* The next resume of this inferior should bring it to the shlib
441 startup breakpoints. (If the user had also set bp's on
442 "main" from the old (parent) process, then they'll auto-
443 matically get reset there in the new process.) */
446 /* Non-zero if we just simulating a single-step. This is needed
447 because we cannot remove the breakpoints in the inferior process
448 until after the `wait' in `wait_for_inferior'. */
449 static int singlestep_breakpoints_inserted_p
= 0;
451 /* The thread we inserted single-step breakpoints for. */
452 static ptid_t singlestep_ptid
;
454 /* PC when we started this single-step. */
455 static CORE_ADDR singlestep_pc
;
457 /* If another thread hit the singlestep breakpoint, we save the original
458 thread here so that we can resume single-stepping it later. */
459 static ptid_t saved_singlestep_ptid
;
460 static int stepping_past_singlestep_breakpoint
;
462 /* If not equal to null_ptid, this means that after stepping over breakpoint
463 is finished, we need to switch to deferred_step_ptid, and step it.
465 The use case is when one thread has hit a breakpoint, and then the user
466 has switched to another thread and issued 'step'. We need to step over
467 breakpoint in the thread which hit the breakpoint, but then continue
468 stepping the thread user has selected. */
469 static ptid_t deferred_step_ptid
;
471 /* Displaced stepping. */
473 /* In non-stop debugging mode, we must take special care to manage
474 breakpoints properly; in particular, the traditional strategy for
475 stepping a thread past a breakpoint it has hit is unsuitable.
476 'Displaced stepping' is a tactic for stepping one thread past a
477 breakpoint it has hit while ensuring that other threads running
478 concurrently will hit the breakpoint as they should.
480 The traditional way to step a thread T off a breakpoint in a
481 multi-threaded program in all-stop mode is as follows:
483 a0) Initially, all threads are stopped, and breakpoints are not
485 a1) We single-step T, leaving breakpoints uninserted.
486 a2) We insert breakpoints, and resume all threads.
488 In non-stop debugging, however, this strategy is unsuitable: we
489 don't want to have to stop all threads in the system in order to
490 continue or step T past a breakpoint. Instead, we use displaced
493 n0) Initially, T is stopped, other threads are running, and
494 breakpoints are inserted.
495 n1) We copy the instruction "under" the breakpoint to a separate
496 location, outside the main code stream, making any adjustments
497 to the instruction, register, and memory state as directed by
499 n2) We single-step T over the instruction at its new location.
500 n3) We adjust the resulting register and memory state as directed
501 by T's architecture. This includes resetting T's PC to point
502 back into the main instruction stream.
505 This approach depends on the following gdbarch methods:
507 - gdbarch_max_insn_length and gdbarch_displaced_step_location
508 indicate where to copy the instruction, and how much space must
509 be reserved there. We use these in step n1.
511 - gdbarch_displaced_step_copy_insn copies a instruction to a new
512 address, and makes any necessary adjustments to the instruction,
513 register contents, and memory. We use this in step n1.
515 - gdbarch_displaced_step_fixup adjusts registers and memory after
516 we have successfuly single-stepped the instruction, to yield the
517 same effect the instruction would have had if we had executed it
518 at its original address. We use this in step n3.
520 - gdbarch_displaced_step_free_closure provides cleanup.
522 The gdbarch_displaced_step_copy_insn and
523 gdbarch_displaced_step_fixup functions must be written so that
524 copying an instruction with gdbarch_displaced_step_copy_insn,
525 single-stepping across the copied instruction, and then applying
526 gdbarch_displaced_insn_fixup should have the same effects on the
527 thread's memory and registers as stepping the instruction in place
528 would have. Exactly which responsibilities fall to the copy and
529 which fall to the fixup is up to the author of those functions.
531 See the comments in gdbarch.sh for details.
533 Note that displaced stepping and software single-step cannot
534 currently be used in combination, although with some care I think
535 they could be made to. Software single-step works by placing
536 breakpoints on all possible subsequent instructions; if the
537 displaced instruction is a PC-relative jump, those breakpoints
538 could fall in very strange places --- on pages that aren't
539 executable, or at addresses that are not proper instruction
540 boundaries. (We do generally let other threads run while we wait
541 to hit the software single-step breakpoint, and they might
542 encounter such a corrupted instruction.) One way to work around
543 this would be to have gdbarch_displaced_step_copy_insn fully
544 simulate the effect of PC-relative instructions (and return NULL)
545 on architectures that use software single-stepping.
547 In non-stop mode, we can have independent and simultaneous step
548 requests, so more than one thread may need to simultaneously step
549 over a breakpoint. The current implementation assumes there is
550 only one scratch space per process. In this case, we have to
551 serialize access to the scratch space. If thread A wants to step
552 over a breakpoint, but we are currently waiting for some other
553 thread to complete a displaced step, we leave thread A stopped and
554 place it in the displaced_step_request_queue. Whenever a displaced
555 step finishes, we pick the next thread in the queue and start a new
556 displaced step operation on it. See displaced_step_prepare and
557 displaced_step_fixup for details. */
559 /* If this is not null_ptid, this is the thread carrying out a
560 displaced single-step. This thread's state will require fixing up
561 once it has completed its step. */
562 static ptid_t displaced_step_ptid
;
564 struct displaced_step_request
567 struct displaced_step_request
*next
;
570 /* A queue of pending displaced stepping requests. */
571 struct displaced_step_request
*displaced_step_request_queue
;
573 /* The architecture the thread had when we stepped it. */
574 static struct gdbarch
*displaced_step_gdbarch
;
576 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
577 for post-step cleanup. */
578 static struct displaced_step_closure
*displaced_step_closure
;
580 /* The address of the original instruction, and the copy we made. */
581 static CORE_ADDR displaced_step_original
, displaced_step_copy
;
583 /* Saved contents of copy area. */
584 static gdb_byte
*displaced_step_saved_copy
;
586 /* When this is non-zero, we are allowed to use displaced stepping, if
587 the architecture supports it. When this is zero, we use
588 traditional the hold-and-step approach. */
589 int can_use_displaced_stepping
= 1;
591 show_can_use_displaced_stepping (struct ui_file
*file
, int from_tty
,
592 struct cmd_list_element
*c
,
595 fprintf_filtered (file
, _("\
596 Debugger's willingness to use displaced stepping to step over "
597 "breakpoints is %s.\n"), value
);
600 /* Return non-zero if displaced stepping is enabled, and can be used
603 use_displaced_stepping (struct gdbarch
*gdbarch
)
605 return (can_use_displaced_stepping
606 && gdbarch_displaced_step_copy_insn_p (gdbarch
));
609 /* Clean out any stray displaced stepping state. */
611 displaced_step_clear (void)
613 /* Indicate that there is no cleanup pending. */
614 displaced_step_ptid
= null_ptid
;
616 if (displaced_step_closure
)
618 gdbarch_displaced_step_free_closure (displaced_step_gdbarch
,
619 displaced_step_closure
);
620 displaced_step_closure
= NULL
;
625 cleanup_displaced_step_closure (void *ptr
)
627 struct displaced_step_closure
*closure
= ptr
;
629 gdbarch_displaced_step_free_closure (current_gdbarch
, closure
);
632 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
634 displaced_step_dump_bytes (struct ui_file
*file
,
640 for (i
= 0; i
< len
; i
++)
641 fprintf_unfiltered (file
, "%02x ", buf
[i
]);
642 fputs_unfiltered ("\n", file
);
645 /* Prepare to single-step, using displaced stepping.
647 Note that we cannot use displaced stepping when we have a signal to
648 deliver. If we have a signal to deliver and an instruction to step
649 over, then after the step, there will be no indication from the
650 target whether the thread entered a signal handler or ignored the
651 signal and stepped over the instruction successfully --- both cases
652 result in a simple SIGTRAP. In the first case we mustn't do a
653 fixup, and in the second case we must --- but we can't tell which.
654 Comments in the code for 'random signals' in handle_inferior_event
655 explain how we handle this case instead.
657 Returns 1 if preparing was successful -- this thread is going to be
658 stepped now; or 0 if displaced stepping this thread got queued. */
660 displaced_step_prepare (ptid_t ptid
)
662 struct cleanup
*old_cleanups
;
663 struct regcache
*regcache
= get_thread_regcache (ptid
);
664 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
665 CORE_ADDR original
, copy
;
667 struct displaced_step_closure
*closure
;
669 /* We should never reach this function if the architecture does not
670 support displaced stepping. */
671 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch
));
673 /* For the first cut, we're displaced stepping one thread at a
676 if (!ptid_equal (displaced_step_ptid
, null_ptid
))
678 /* Already waiting for a displaced step to finish. Defer this
679 request and place in queue. */
680 struct displaced_step_request
*req
, *new_req
;
683 fprintf_unfiltered (gdb_stdlog
,
684 "displaced: defering step of %s\n",
685 target_pid_to_str (ptid
));
687 new_req
= xmalloc (sizeof (*new_req
));
688 new_req
->ptid
= ptid
;
689 new_req
->next
= NULL
;
691 if (displaced_step_request_queue
)
693 for (req
= displaced_step_request_queue
;
700 displaced_step_request_queue
= new_req
;
707 fprintf_unfiltered (gdb_stdlog
,
708 "displaced: stepping %s now\n",
709 target_pid_to_str (ptid
));
712 displaced_step_clear ();
714 original
= regcache_read_pc (regcache
);
716 copy
= gdbarch_displaced_step_location (gdbarch
);
717 len
= gdbarch_max_insn_length (gdbarch
);
719 /* Save the original contents of the copy area. */
720 displaced_step_saved_copy
= xmalloc (len
);
721 old_cleanups
= make_cleanup (free_current_contents
,
722 &displaced_step_saved_copy
);
723 read_memory (copy
, displaced_step_saved_copy
, len
);
726 fprintf_unfiltered (gdb_stdlog
, "displaced: saved 0x%s: ",
728 displaced_step_dump_bytes (gdb_stdlog
, displaced_step_saved_copy
, len
);
731 closure
= gdbarch_displaced_step_copy_insn (gdbarch
,
732 original
, copy
, regcache
);
734 /* We don't support the fully-simulated case at present. */
735 gdb_assert (closure
);
737 make_cleanup (cleanup_displaced_step_closure
, closure
);
739 /* Resume execution at the copy. */
740 regcache_write_pc (regcache
, copy
);
742 discard_cleanups (old_cleanups
);
745 fprintf_unfiltered (gdb_stdlog
, "displaced: displaced pc to 0x%s\n",
748 /* Save the information we need to fix things up if the step
750 displaced_step_ptid
= ptid
;
751 displaced_step_gdbarch
= gdbarch
;
752 displaced_step_closure
= closure
;
753 displaced_step_original
= original
;
754 displaced_step_copy
= copy
;
759 displaced_step_clear_cleanup (void *ignore
)
761 displaced_step_clear ();
765 write_memory_ptid (ptid_t ptid
, CORE_ADDR memaddr
, const gdb_byte
*myaddr
, int len
)
767 struct cleanup
*ptid_cleanup
= save_inferior_ptid ();
768 inferior_ptid
= ptid
;
769 write_memory (memaddr
, myaddr
, len
);
770 do_cleanups (ptid_cleanup
);
774 displaced_step_fixup (ptid_t event_ptid
, enum target_signal signal
)
776 struct cleanup
*old_cleanups
;
778 /* Was this event for the pid we displaced? */
779 if (ptid_equal (displaced_step_ptid
, null_ptid
)
780 || ! ptid_equal (displaced_step_ptid
, event_ptid
))
783 old_cleanups
= make_cleanup (displaced_step_clear_cleanup
, 0);
785 /* Restore the contents of the copy area. */
787 ULONGEST len
= gdbarch_max_insn_length (displaced_step_gdbarch
);
788 write_memory_ptid (displaced_step_ptid
, displaced_step_copy
,
789 displaced_step_saved_copy
, len
);
791 fprintf_unfiltered (gdb_stdlog
, "displaced: restored 0x%s\n",
792 paddr_nz (displaced_step_copy
));
795 /* Did the instruction complete successfully? */
796 if (signal
== TARGET_SIGNAL_TRAP
)
798 /* Fix up the resulting state. */
799 gdbarch_displaced_step_fixup (displaced_step_gdbarch
,
800 displaced_step_closure
,
801 displaced_step_original
,
803 get_thread_regcache (displaced_step_ptid
));
807 /* Since the instruction didn't complete, all we can do is
809 struct regcache
*regcache
= get_thread_regcache (event_ptid
);
810 CORE_ADDR pc
= regcache_read_pc (regcache
);
811 pc
= displaced_step_original
+ (pc
- displaced_step_copy
);
812 regcache_write_pc (regcache
, pc
);
815 do_cleanups (old_cleanups
);
817 /* Are there any pending displaced stepping requests? If so, run
819 if (displaced_step_request_queue
)
821 struct displaced_step_request
*head
;
824 head
= displaced_step_request_queue
;
826 displaced_step_request_queue
= head
->next
;
830 fprintf_unfiltered (gdb_stdlog
,
831 "displaced: stepping queued %s now\n",
832 target_pid_to_str (ptid
));
835 displaced_step_ptid
= null_ptid
;
836 displaced_step_prepare (ptid
);
837 target_resume (ptid
, 1, TARGET_SIGNAL_0
);
844 /* Things to clean up if we QUIT out of resume (). */
846 resume_cleanups (void *ignore
)
851 static const char schedlock_off
[] = "off";
852 static const char schedlock_on
[] = "on";
853 static const char schedlock_step
[] = "step";
854 static const char *scheduler_enums
[] = {
860 static const char *scheduler_mode
= schedlock_off
;
862 show_scheduler_mode (struct ui_file
*file
, int from_tty
,
863 struct cmd_list_element
*c
, const char *value
)
865 fprintf_filtered (file
, _("\
866 Mode for locking scheduler during execution is \"%s\".\n"),
871 set_schedlock_func (char *args
, int from_tty
, struct cmd_list_element
*c
)
873 if (!target_can_lock_scheduler
)
875 scheduler_mode
= schedlock_off
;
876 error (_("Target '%s' cannot support this command."), target_shortname
);
881 /* Resume the inferior, but allow a QUIT. This is useful if the user
882 wants to interrupt some lengthy single-stepping operation
883 (for child processes, the SIGINT goes to the inferior, and so
884 we get a SIGINT random_signal, but for remote debugging and perhaps
885 other targets, that's not true).
887 STEP nonzero if we should step (zero to continue instead).
888 SIG is the signal to give the inferior (zero for none). */
890 resume (int step
, enum target_signal sig
)
892 int should_resume
= 1;
893 struct cleanup
*old_cleanups
= make_cleanup (resume_cleanups
, 0);
894 struct regcache
*regcache
= get_current_regcache ();
895 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
896 CORE_ADDR pc
= regcache_read_pc (regcache
);
900 fprintf_unfiltered (gdb_stdlog
,
901 "infrun: resume (step=%d, signal=%d), "
902 "stepping_over_breakpoint=%d\n",
903 step
, sig
, stepping_over_breakpoint
);
905 /* Some targets (e.g. Solaris x86) have a kernel bug when stepping
906 over an instruction that causes a page fault without triggering
907 a hardware watchpoint. The kernel properly notices that it shouldn't
908 stop, because the hardware watchpoint is not triggered, but it forgets
909 the step request and continues the program normally.
910 Work around the problem by removing hardware watchpoints if a step is
911 requested, GDB will check for a hardware watchpoint trigger after the
913 if (CANNOT_STEP_HW_WATCHPOINTS
&& step
)
914 remove_hw_watchpoints ();
917 /* Normally, by the time we reach `resume', the breakpoints are either
918 removed or inserted, as appropriate. The exception is if we're sitting
919 at a permanent breakpoint; we need to step over it, but permanent
920 breakpoints can't be removed. So we have to test for it here. */
921 if (breakpoint_here_p (pc
) == permanent_breakpoint_here
)
923 if (gdbarch_skip_permanent_breakpoint_p (gdbarch
))
924 gdbarch_skip_permanent_breakpoint (gdbarch
, regcache
);
927 The program is stopped at a permanent breakpoint, but GDB does not know\n\
928 how to step past a permanent breakpoint on this architecture. Try using\n\
929 a command like `return' or `jump' to continue execution."));
932 /* If enabled, step over breakpoints by executing a copy of the
933 instruction at a different address.
935 We can't use displaced stepping when we have a signal to deliver;
936 the comments for displaced_step_prepare explain why. The
937 comments in the handle_inferior event for dealing with 'random
938 signals' explain what we do instead. */
939 if (use_displaced_stepping (gdbarch
)
940 && stepping_over_breakpoint
941 && sig
== TARGET_SIGNAL_0
)
943 if (!displaced_step_prepare (inferior_ptid
))
944 /* Got placed in displaced stepping queue. Will be resumed
945 later when all the currently queued displaced stepping
950 if (step
&& gdbarch_software_single_step_p (gdbarch
))
952 /* Do it the hard way, w/temp breakpoints */
953 if (gdbarch_software_single_step (gdbarch
, get_current_frame ()))
955 /* ...and don't ask hardware to do it. */
957 /* and do not pull these breakpoints until after a `wait' in
958 `wait_for_inferior' */
959 singlestep_breakpoints_inserted_p
= 1;
960 singlestep_ptid
= inferior_ptid
;
965 /* If there were any forks/vforks/execs that were caught and are
966 now to be followed, then do so. */
967 switch (pending_follow
.kind
)
969 case TARGET_WAITKIND_FORKED
:
970 case TARGET_WAITKIND_VFORKED
:
971 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
976 case TARGET_WAITKIND_EXECD
:
977 /* follow_exec is called as soon as the exec event is seen. */
978 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
;
985 /* Install inferior's terminal modes. */
986 target_terminal_inferior ();
992 resume_ptid
= RESUME_ALL
; /* Default */
994 /* If STEP is set, it's a request to use hardware stepping
995 facilities. But in that case, we should never
996 use singlestep breakpoint. */
997 gdb_assert (!(singlestep_breakpoints_inserted_p
&& step
));
999 if (singlestep_breakpoints_inserted_p
1000 && stepping_past_singlestep_breakpoint
)
1002 /* The situation here is as follows. In thread T1 we wanted to
1003 single-step. Lacking hardware single-stepping we've
1004 set breakpoint at the PC of the next instruction -- call it
1005 P. After resuming, we've hit that breakpoint in thread T2.
1006 Now we've removed original breakpoint, inserted breakpoint
1007 at P+1, and try to step to advance T2 past breakpoint.
1008 We need to step only T2, as if T1 is allowed to freely run,
1009 it can run past P, and if other threads are allowed to run,
1010 they can hit breakpoint at P+1, and nested hits of single-step
1011 breakpoints is not something we'd want -- that's complicated
1012 to support, and has no value. */
1013 resume_ptid
= inferior_ptid
;
1016 if ((step
|| singlestep_breakpoints_inserted_p
)
1017 && stepping_over_breakpoint
)
1019 /* We're allowing a thread to run past a breakpoint it has
1020 hit, by single-stepping the thread with the breakpoint
1021 removed. In which case, we need to single-step only this
1022 thread, and keep others stopped, as they can miss this
1023 breakpoint if allowed to run.
1025 The current code actually removes all breakpoints when
1026 doing this, not just the one being stepped over, so if we
1027 let other threads run, we can actually miss any
1028 breakpoint, not just the one at PC. */
1029 resume_ptid
= inferior_ptid
;
1032 if ((scheduler_mode
== schedlock_on
)
1033 || (scheduler_mode
== schedlock_step
1034 && (step
|| singlestep_breakpoints_inserted_p
)))
1036 /* User-settable 'scheduler' mode requires solo thread resume. */
1037 resume_ptid
= inferior_ptid
;
1040 if (gdbarch_cannot_step_breakpoint (gdbarch
))
1042 /* Most targets can step a breakpoint instruction, thus
1043 executing it normally. But if this one cannot, just
1044 continue and we will hit it anyway. */
1045 if (step
&& breakpoint_inserted_here_p (pc
))
1050 && use_displaced_stepping (gdbarch
)
1051 && stepping_over_breakpoint
)
1053 struct regcache
*resume_regcache
= get_thread_regcache (resume_ptid
);
1054 CORE_ADDR actual_pc
= regcache_read_pc (resume_regcache
);
1057 fprintf_unfiltered (gdb_stdlog
, "displaced: run 0x%s: ",
1058 paddr_nz (actual_pc
));
1059 read_memory (actual_pc
, buf
, sizeof (buf
));
1060 displaced_step_dump_bytes (gdb_stdlog
, buf
, sizeof (buf
));
1063 target_resume (resume_ptid
, step
, sig
);
1066 discard_cleanups (old_cleanups
);
1071 /* Clear out all variables saying what to do when inferior is continued.
1072 First do this, then set the ones you want, then call `proceed'. */
1075 clear_proceed_status (void)
1077 stepping_over_breakpoint
= 0;
1078 step_range_start
= 0;
1080 step_frame_id
= null_frame_id
;
1081 step_over_calls
= STEP_OVER_UNDEBUGGABLE
;
1082 stop_after_trap
= 0;
1083 stop_soon
= NO_STOP_QUIETLY
;
1084 proceed_to_finish
= 0;
1085 breakpoint_proceeded
= 1; /* We're about to proceed... */
1089 regcache_xfree (stop_registers
);
1090 stop_registers
= NULL
;
1093 /* Discard any remaining commands or status from previous stop. */
1094 bpstat_clear (&stop_bpstat
);
1097 /* This should be suitable for any targets that support threads. */
1100 prepare_to_proceed (int step
)
1103 struct target_waitstatus wait_status
;
1105 /* Get the last target status returned by target_wait(). */
1106 get_last_target_status (&wait_ptid
, &wait_status
);
1108 /* Make sure we were stopped at a breakpoint. */
1109 if (wait_status
.kind
!= TARGET_WAITKIND_STOPPED
1110 || wait_status
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1115 /* Switched over from WAIT_PID. */
1116 if (!ptid_equal (wait_ptid
, minus_one_ptid
)
1117 && !ptid_equal (inferior_ptid
, wait_ptid
))
1119 struct regcache
*regcache
= get_thread_regcache (wait_ptid
);
1121 if (breakpoint_here_p (regcache_read_pc (regcache
)))
1123 /* If stepping, remember current thread to switch back to. */
1125 deferred_step_ptid
= inferior_ptid
;
1127 /* Switch back to WAIT_PID thread. */
1128 switch_to_thread (wait_ptid
);
1130 /* We return 1 to indicate that there is a breakpoint here,
1131 so we need to step over it before continuing to avoid
1132 hitting it straight away. */
1140 /* Record the pc of the program the last time it stopped. This is
1141 just used internally by wait_for_inferior, but need to be preserved
1142 over calls to it and cleared when the inferior is started. */
1143 static CORE_ADDR prev_pc
;
1145 /* Basic routine for continuing the program in various fashions.
1147 ADDR is the address to resume at, or -1 for resume where stopped.
1148 SIGGNAL is the signal to give it, or 0 for none,
1149 or -1 for act according to how it stopped.
1150 STEP is nonzero if should trap after one instruction.
1151 -1 means return after that and print nothing.
1152 You should probably set various step_... variables
1153 before calling here, if you are stepping.
1155 You should call clear_proceed_status before calling proceed. */
1158 proceed (CORE_ADDR addr
, enum target_signal siggnal
, int step
)
1160 struct regcache
*regcache
= get_current_regcache ();
1161 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1162 CORE_ADDR pc
= regcache_read_pc (regcache
);
1166 step_start_function
= find_pc_function (pc
);
1168 stop_after_trap
= 1;
1170 if (addr
== (CORE_ADDR
) -1)
1172 if (pc
== stop_pc
&& breakpoint_here_p (pc
))
1173 /* There is a breakpoint at the address we will resume at,
1174 step one instruction before inserting breakpoints so that
1175 we do not stop right away (and report a second hit at this
1178 else if (gdbarch_single_step_through_delay_p (gdbarch
)
1179 && gdbarch_single_step_through_delay (gdbarch
,
1180 get_current_frame ()))
1181 /* We stepped onto an instruction that needs to be stepped
1182 again before re-inserting the breakpoint, do so. */
1187 regcache_write_pc (regcache
, addr
);
1191 fprintf_unfiltered (gdb_stdlog
,
1192 "infrun: proceed (addr=0x%s, signal=%d, step=%d)\n",
1193 paddr_nz (addr
), siggnal
, step
);
1195 /* In a multi-threaded task we may select another thread
1196 and then continue or step.
1198 But if the old thread was stopped at a breakpoint, it
1199 will immediately cause another breakpoint stop without
1200 any execution (i.e. it will report a breakpoint hit
1201 incorrectly). So we must step over it first.
1203 prepare_to_proceed checks the current thread against the thread
1204 that reported the most recent event. If a step-over is required
1205 it returns TRUE and sets the current thread to the old thread. */
1206 if (prepare_to_proceed (step
))
1211 stepping_over_breakpoint
= 1;
1212 /* If displaced stepping is enabled, we can step over the
1213 breakpoint without hitting it, so leave all breakpoints
1214 inserted. Otherwise we need to disable all breakpoints, step
1215 one instruction, and then re-add them when that step is
1217 if (!use_displaced_stepping (gdbarch
))
1218 remove_breakpoints ();
1221 /* We can insert breakpoints if we're not trying to step over one,
1222 or if we are stepping over one but we're using displaced stepping
1224 if (! stepping_over_breakpoint
|| use_displaced_stepping (gdbarch
))
1225 insert_breakpoints ();
1227 if (siggnal
!= TARGET_SIGNAL_DEFAULT
)
1228 stop_signal
= siggnal
;
1229 /* If this signal should not be seen by program,
1230 give it zero. Used for debugging signals. */
1231 else if (!signal_program
[stop_signal
])
1232 stop_signal
= TARGET_SIGNAL_0
;
1234 annotate_starting ();
1236 /* Make sure that output from GDB appears before output from the
1238 gdb_flush (gdb_stdout
);
1240 /* Refresh prev_pc value just prior to resuming. This used to be
1241 done in stop_stepping, however, setting prev_pc there did not handle
1242 scenarios such as inferior function calls or returning from
1243 a function via the return command. In those cases, the prev_pc
1244 value was not set properly for subsequent commands. The prev_pc value
1245 is used to initialize the starting line number in the ecs. With an
1246 invalid value, the gdb next command ends up stopping at the position
1247 represented by the next line table entry past our start position.
1248 On platforms that generate one line table entry per line, this
1249 is not a problem. However, on the ia64, the compiler generates
1250 extraneous line table entries that do not increase the line number.
1251 When we issue the gdb next command on the ia64 after an inferior call
1252 or a return command, we often end up a few instructions forward, still
1253 within the original line we started.
1255 An attempt was made to have init_execution_control_state () refresh
1256 the prev_pc value before calculating the line number. This approach
1257 did not work because on platforms that use ptrace, the pc register
1258 cannot be read unless the inferior is stopped. At that point, we
1259 are not guaranteed the inferior is stopped and so the regcache_read_pc ()
1260 call can fail. Setting the prev_pc value here ensures the value is
1261 updated correctly when the inferior is stopped. */
1262 prev_pc
= regcache_read_pc (get_current_regcache ());
1264 /* Resume inferior. */
1265 resume (oneproc
|| step
|| bpstat_should_step (), stop_signal
);
1267 /* Wait for it to stop (if not standalone)
1268 and in any case decode why it stopped, and act accordingly. */
1269 /* Do this only if we are not using the event loop, or if the target
1270 does not support asynchronous execution. */
1271 if (!target_can_async_p ())
1273 wait_for_inferior (0);
1279 /* Start remote-debugging of a machine over a serial link. */
1282 start_remote (int from_tty
)
1284 init_thread_list ();
1285 init_wait_for_inferior ();
1286 stop_soon
= STOP_QUIETLY_REMOTE
;
1287 stepping_over_breakpoint
= 0;
1289 /* Always go on waiting for the target, regardless of the mode. */
1290 /* FIXME: cagney/1999-09-23: At present it isn't possible to
1291 indicate to wait_for_inferior that a target should timeout if
1292 nothing is returned (instead of just blocking). Because of this,
1293 targets expecting an immediate response need to, internally, set
1294 things up so that the target_wait() is forced to eventually
1296 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
1297 differentiate to its caller what the state of the target is after
1298 the initial open has been performed. Here we're assuming that
1299 the target has stopped. It should be possible to eventually have
1300 target_open() return to the caller an indication that the target
1301 is currently running and GDB state should be set to the same as
1302 for an async run. */
1303 wait_for_inferior (0);
1305 /* Now that the inferior has stopped, do any bookkeeping like
1306 loading shared libraries. We want to do this before normal_stop,
1307 so that the displayed frame is up to date. */
1308 post_create_inferior (¤t_target
, from_tty
);
1313 /* Initialize static vars when a new inferior begins. */
1316 init_wait_for_inferior (void)
1318 /* These are meaningless until the first time through wait_for_inferior. */
1321 breakpoint_init_inferior (inf_starting
);
1323 /* Don't confuse first call to proceed(). */
1324 stop_signal
= TARGET_SIGNAL_0
;
1326 /* The first resume is not following a fork/vfork/exec. */
1327 pending_follow
.kind
= TARGET_WAITKIND_SPURIOUS
; /* I.e., none. */
1329 clear_proceed_status ();
1331 stepping_past_singlestep_breakpoint
= 0;
1332 deferred_step_ptid
= null_ptid
;
1334 target_last_wait_ptid
= minus_one_ptid
;
1336 displaced_step_clear ();
1340 /* This enum encodes possible reasons for doing a target_wait, so that
1341 wfi can call target_wait in one place. (Ultimately the call will be
1342 moved out of the infinite loop entirely.) */
1346 infwait_normal_state
,
1347 infwait_thread_hop_state
,
1348 infwait_step_watch_state
,
1349 infwait_nonstep_watch_state
1352 /* Why did the inferior stop? Used to print the appropriate messages
1353 to the interface from within handle_inferior_event(). */
1354 enum inferior_stop_reason
1356 /* Step, next, nexti, stepi finished. */
1358 /* Inferior terminated by signal. */
1360 /* Inferior exited. */
1362 /* Inferior received signal, and user asked to be notified. */
1366 /* This structure contains what used to be local variables in
1367 wait_for_inferior. Probably many of them can return to being
1368 locals in handle_inferior_event. */
1370 struct execution_control_state
1372 struct target_waitstatus ws
;
1373 struct target_waitstatus
*wp
;
1374 /* Should we step over breakpoint next time keep_going
1376 int stepping_over_breakpoint
;
1378 CORE_ADDR stop_func_start
;
1379 CORE_ADDR stop_func_end
;
1380 char *stop_func_name
;
1381 struct symtab_and_line sal
;
1383 struct symtab
*current_symtab
;
1385 ptid_t saved_inferior_ptid
;
1386 int step_after_step_resume_breakpoint
;
1387 int stepping_through_solib_after_catch
;
1388 bpstat stepping_through_solib_catchpoints
;
1389 int new_thread_event
;
1390 struct target_waitstatus tmpstatus
;
1391 enum infwait_states infwait_state
;
1396 void init_execution_control_state (struct execution_control_state
*ecs
);
1398 void handle_inferior_event (struct execution_control_state
*ecs
);
1400 static void step_into_function (struct execution_control_state
*ecs
);
1401 static void insert_step_resume_breakpoint_at_frame (struct frame_info
*step_frame
);
1402 static void insert_step_resume_breakpoint_at_caller (struct frame_info
*);
1403 static void insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
1404 struct frame_id sr_id
);
1405 static void insert_longjmp_resume_breakpoint (CORE_ADDR
);
1407 static void stop_stepping (struct execution_control_state
*ecs
);
1408 static void prepare_to_wait (struct execution_control_state
*ecs
);
1409 static void keep_going (struct execution_control_state
*ecs
);
1410 static void print_stop_reason (enum inferior_stop_reason stop_reason
,
1413 /* Wait for control to return from inferior to debugger.
1415 If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals
1416 as if they were SIGTRAP signals. This can be useful during
1417 the startup sequence on some targets such as HP/UX, where
1418 we receive an EXEC event instead of the expected SIGTRAP.
1420 If inferior gets a signal, we may decide to start it up again
1421 instead of returning. That is why there is a loop in this function.
1422 When this function actually returns it means the inferior
1423 should be left stopped and GDB should read more commands. */
1426 wait_for_inferior (int treat_exec_as_sigtrap
)
1428 struct cleanup
*old_cleanups
;
1429 struct execution_control_state ecss
;
1430 struct execution_control_state
*ecs
;
1434 (gdb_stdlog
, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n",
1435 treat_exec_as_sigtrap
);
1437 old_cleanups
= make_cleanup (delete_step_resume_breakpoint
,
1438 &step_resume_breakpoint
);
1440 /* wfi still stays in a loop, so it's OK just to take the address of
1441 a local to get the ecs pointer. */
1444 /* Fill in with reasonable starting values. */
1445 init_execution_control_state (ecs
);
1447 /* We'll update this if & when we switch to a new thread. */
1448 previous_inferior_ptid
= inferior_ptid
;
1450 overlay_cache_invalid
= 1;
1452 /* We have to invalidate the registers BEFORE calling target_wait
1453 because they can be loaded from the target while in target_wait.
1454 This makes remote debugging a bit more efficient for those
1455 targets that provide critical registers as part of their normal
1456 status mechanism. */
1458 registers_changed ();
1462 if (deprecated_target_wait_hook
)
1463 ecs
->ptid
= deprecated_target_wait_hook (ecs
->waiton_ptid
, ecs
->wp
);
1465 ecs
->ptid
= target_wait (ecs
->waiton_ptid
, ecs
->wp
);
1467 if (treat_exec_as_sigtrap
&& ecs
->ws
.kind
== TARGET_WAITKIND_EXECD
)
1469 xfree (ecs
->ws
.value
.execd_pathname
);
1470 ecs
->ws
.kind
= TARGET_WAITKIND_STOPPED
;
1471 ecs
->ws
.value
.sig
= TARGET_SIGNAL_TRAP
;
1474 /* Now figure out what to do with the result of the result. */
1475 handle_inferior_event (ecs
);
1477 if (!ecs
->wait_some_more
)
1480 do_cleanups (old_cleanups
);
1483 /* Asynchronous version of wait_for_inferior. It is called by the
1484 event loop whenever a change of state is detected on the file
1485 descriptor corresponding to the target. It can be called more than
1486 once to complete a single execution command. In such cases we need
1487 to keep the state in a global variable ASYNC_ECSS. If it is the
1488 last time that this function is called for a single execution
1489 command, then report to the user that the inferior has stopped, and
1490 do the necessary cleanups. */
1492 struct execution_control_state async_ecss
;
1493 struct execution_control_state
*async_ecs
;
1496 fetch_inferior_event (void *client_data
)
1498 static struct cleanup
*old_cleanups
;
1500 async_ecs
= &async_ecss
;
1502 if (!async_ecs
->wait_some_more
)
1504 /* Fill in with reasonable starting values. */
1505 init_execution_control_state (async_ecs
);
1507 /* We'll update this if & when we switch to a new thread. */
1508 previous_inferior_ptid
= inferior_ptid
;
1510 overlay_cache_invalid
= 1;
1512 /* We have to invalidate the registers BEFORE calling target_wait
1513 because they can be loaded from the target while in target_wait.
1514 This makes remote debugging a bit more efficient for those
1515 targets that provide critical registers as part of their normal
1516 status mechanism. */
1518 registers_changed ();
1521 if (deprecated_target_wait_hook
)
1523 deprecated_target_wait_hook (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1525 async_ecs
->ptid
= target_wait (async_ecs
->waiton_ptid
, async_ecs
->wp
);
1527 /* Now figure out what to do with the result of the result. */
1528 handle_inferior_event (async_ecs
);
1530 if (!async_ecs
->wait_some_more
)
1532 delete_step_resume_breakpoint (&step_resume_breakpoint
);
1535 if (step_multi
&& stop_step
)
1536 inferior_event_handler (INF_EXEC_CONTINUE
, NULL
);
1538 inferior_event_handler (INF_EXEC_COMPLETE
, NULL
);
1542 /* Prepare an execution control state for looping through a
1543 wait_for_inferior-type loop. */
1546 init_execution_control_state (struct execution_control_state
*ecs
)
1548 ecs
->stepping_over_breakpoint
= 0;
1549 ecs
->random_signal
= 0;
1550 ecs
->step_after_step_resume_breakpoint
= 0;
1551 ecs
->stepping_through_solib_after_catch
= 0;
1552 ecs
->stepping_through_solib_catchpoints
= NULL
;
1553 ecs
->sal
= find_pc_line (prev_pc
, 0);
1554 ecs
->current_line
= ecs
->sal
.line
;
1555 ecs
->current_symtab
= ecs
->sal
.symtab
;
1556 ecs
->infwait_state
= infwait_normal_state
;
1557 ecs
->waiton_ptid
= pid_to_ptid (-1);
1558 ecs
->wp
= &(ecs
->ws
);
1561 /* Return the cached copy of the last pid/waitstatus returned by
1562 target_wait()/deprecated_target_wait_hook(). The data is actually
1563 cached by handle_inferior_event(), which gets called immediately
1564 after target_wait()/deprecated_target_wait_hook(). */
1567 get_last_target_status (ptid_t
*ptidp
, struct target_waitstatus
*status
)
1569 *ptidp
= target_last_wait_ptid
;
1570 *status
= target_last_waitstatus
;
1574 nullify_last_target_wait_ptid (void)
1576 target_last_wait_ptid
= minus_one_ptid
;
1579 /* Switch thread contexts, maintaining "infrun state". */
1582 context_switch (struct execution_control_state
*ecs
)
1584 /* Caution: it may happen that the new thread (or the old one!)
1585 is not in the thread list. In this case we must not attempt
1586 to "switch context", or we run the risk that our context may
1587 be lost. This may happen as a result of the target module
1588 mishandling thread creation. */
1592 fprintf_unfiltered (gdb_stdlog
, "infrun: Switching context from %s ",
1593 target_pid_to_str (inferior_ptid
));
1594 fprintf_unfiltered (gdb_stdlog
, "to %s\n",
1595 target_pid_to_str (ecs
->ptid
));
1598 if (in_thread_list (inferior_ptid
) && in_thread_list (ecs
->ptid
))
1599 { /* Perform infrun state context switch: */
1600 /* Save infrun state for the old thread. */
1601 save_infrun_state (inferior_ptid
, prev_pc
,
1602 stepping_over_breakpoint
, step_resume_breakpoint
,
1604 step_range_end
, &step_frame_id
,
1605 ecs
->stepping_over_breakpoint
,
1606 ecs
->stepping_through_solib_after_catch
,
1607 ecs
->stepping_through_solib_catchpoints
,
1608 ecs
->current_line
, ecs
->current_symtab
);
1610 /* Load infrun state for the new thread. */
1611 load_infrun_state (ecs
->ptid
, &prev_pc
,
1612 &stepping_over_breakpoint
, &step_resume_breakpoint
,
1614 &step_range_end
, &step_frame_id
,
1615 &ecs
->stepping_over_breakpoint
,
1616 &ecs
->stepping_through_solib_after_catch
,
1617 &ecs
->stepping_through_solib_catchpoints
,
1618 &ecs
->current_line
, &ecs
->current_symtab
);
1621 switch_to_thread (ecs
->ptid
);
1625 adjust_pc_after_break (struct execution_control_state
*ecs
)
1627 struct regcache
*regcache
= get_thread_regcache (ecs
->ptid
);
1628 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
1629 CORE_ADDR breakpoint_pc
;
1631 /* If this target does not decrement the PC after breakpoints, then
1632 we have nothing to do. */
1633 if (gdbarch_decr_pc_after_break (gdbarch
) == 0)
1636 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
1637 we aren't, just return.
1639 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
1640 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
1641 implemented by software breakpoints should be handled through the normal
1644 NOTE drow/2004-01-31: On some targets, breakpoints may generate
1645 different signals (SIGILL or SIGEMT for instance), but it is less
1646 clear where the PC is pointing afterwards. It may not match
1647 gdbarch_decr_pc_after_break. I don't know any specific target that
1648 generates these signals at breakpoints (the code has been in GDB since at
1649 least 1992) so I can not guess how to handle them here.
1651 In earlier versions of GDB, a target with
1652 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
1653 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
1654 target with both of these set in GDB history, and it seems unlikely to be
1655 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
1657 if (ecs
->ws
.kind
!= TARGET_WAITKIND_STOPPED
)
1660 if (ecs
->ws
.value
.sig
!= TARGET_SIGNAL_TRAP
)
1663 /* Find the location where (if we've hit a breakpoint) the
1664 breakpoint would be. */
1665 breakpoint_pc
= regcache_read_pc (regcache
)
1666 - gdbarch_decr_pc_after_break (gdbarch
);
1668 /* Check whether there actually is a software breakpoint inserted
1669 at that location. */
1670 if (software_breakpoint_inserted_here_p (breakpoint_pc
))
1672 /* When using hardware single-step, a SIGTRAP is reported for both
1673 a completed single-step and a software breakpoint. Need to
1674 differentiate between the two, as the latter needs adjusting
1675 but the former does not.
1677 The SIGTRAP can be due to a completed hardware single-step only if
1678 - we didn't insert software single-step breakpoints
1679 - the thread to be examined is still the current thread
1680 - this thread is currently being stepped
1682 If any of these events did not occur, we must have stopped due
1683 to hitting a software breakpoint, and have to back up to the
1686 As a special case, we could have hardware single-stepped a
1687 software breakpoint. In this case (prev_pc == breakpoint_pc),
1688 we also need to back up to the breakpoint address. */
1690 if (singlestep_breakpoints_inserted_p
1691 || !ptid_equal (ecs
->ptid
, inferior_ptid
)
1692 || !currently_stepping (ecs
)
1693 || prev_pc
== breakpoint_pc
)
1694 regcache_write_pc (regcache
, breakpoint_pc
);
1698 /* Given an execution control state that has been freshly filled in
1699 by an event from the inferior, figure out what it means and take
1700 appropriate action. */
1703 handle_inferior_event (struct execution_control_state
*ecs
)
1705 int sw_single_step_trap_p
= 0;
1706 int stopped_by_watchpoint
;
1707 int stepped_after_stopped_by_watchpoint
= 0;
1709 /* Cache the last pid/waitstatus. */
1710 target_last_wait_ptid
= ecs
->ptid
;
1711 target_last_waitstatus
= *ecs
->wp
;
1713 /* Always clear state belonging to the previous time we stopped. */
1714 stop_stack_dummy
= 0;
1716 adjust_pc_after_break (ecs
);
1718 switch (ecs
->infwait_state
)
1720 case infwait_thread_hop_state
:
1722 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_thread_hop_state\n");
1723 /* Cancel the waiton_ptid. */
1724 ecs
->waiton_ptid
= pid_to_ptid (-1);
1727 case infwait_normal_state
:
1729 fprintf_unfiltered (gdb_stdlog
, "infrun: infwait_normal_state\n");
1732 case infwait_step_watch_state
:
1734 fprintf_unfiltered (gdb_stdlog
,
1735 "infrun: infwait_step_watch_state\n");
1737 stepped_after_stopped_by_watchpoint
= 1;
1740 case infwait_nonstep_watch_state
:
1742 fprintf_unfiltered (gdb_stdlog
,
1743 "infrun: infwait_nonstep_watch_state\n");
1744 insert_breakpoints ();
1746 /* FIXME-maybe: is this cleaner than setting a flag? Does it
1747 handle things like signals arriving and other things happening
1748 in combination correctly? */
1749 stepped_after_stopped_by_watchpoint
= 1;
1753 internal_error (__FILE__
, __LINE__
, _("bad switch"));
1755 ecs
->infwait_state
= infwait_normal_state
;
1757 reinit_frame_cache ();
1759 /* If it's a new process, add it to the thread database */
1761 ecs
->new_thread_event
= (!ptid_equal (ecs
->ptid
, inferior_ptid
)
1762 && !ptid_equal (ecs
->ptid
, minus_one_ptid
)
1763 && !in_thread_list (ecs
->ptid
));
1765 if (ecs
->ws
.kind
!= TARGET_WAITKIND_EXITED
1766 && ecs
->ws
.kind
!= TARGET_WAITKIND_SIGNALLED
&& ecs
->new_thread_event
)
1767 add_thread (ecs
->ptid
);
1769 switch (ecs
->ws
.kind
)
1771 case TARGET_WAITKIND_LOADED
:
1773 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_LOADED\n");
1774 /* Ignore gracefully during startup of the inferior, as it might
1775 be the shell which has just loaded some objects, otherwise
1776 add the symbols for the newly loaded objects. Also ignore at
1777 the beginning of an attach or remote session; we will query
1778 the full list of libraries once the connection is
1780 if (stop_soon
== NO_STOP_QUIETLY
)
1782 /* Check for any newly added shared libraries if we're
1783 supposed to be adding them automatically. Switch
1784 terminal for any messages produced by
1785 breakpoint_re_set. */
1786 target_terminal_ours_for_output ();
1787 /* NOTE: cagney/2003-11-25: Make certain that the target
1788 stack's section table is kept up-to-date. Architectures,
1789 (e.g., PPC64), use the section table to perform
1790 operations such as address => section name and hence
1791 require the table to contain all sections (including
1792 those found in shared libraries). */
1793 /* NOTE: cagney/2003-11-25: Pass current_target and not
1794 exec_ops to SOLIB_ADD. This is because current GDB is
1795 only tooled to propagate section_table changes out from
1796 the "current_target" (see target_resize_to_sections), and
1797 not up from the exec stratum. This, of course, isn't
1798 right. "infrun.c" should only interact with the
1799 exec/process stratum, instead relying on the target stack
1800 to propagate relevant changes (stop, section table
1801 changed, ...) up to other layers. */
1803 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
1805 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
1807 target_terminal_inferior ();
1809 /* If requested, stop when the dynamic linker notifies
1810 gdb of events. This allows the user to get control
1811 and place breakpoints in initializer routines for
1812 dynamically loaded objects (among other things). */
1813 if (stop_on_solib_events
)
1815 stop_stepping (ecs
);
1819 /* NOTE drow/2007-05-11: This might be a good place to check
1820 for "catch load". */
1823 /* If we are skipping through a shell, or through shared library
1824 loading that we aren't interested in, resume the program. If
1825 we're running the program normally, also resume. But stop if
1826 we're attaching or setting up a remote connection. */
1827 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== NO_STOP_QUIETLY
)
1829 /* Loading of shared libraries might have changed breakpoint
1830 addresses. Make sure new breakpoints are inserted. */
1831 if (stop_soon
== NO_STOP_QUIETLY
1832 && !breakpoints_always_inserted_mode ())
1833 insert_breakpoints ();
1834 resume (0, TARGET_SIGNAL_0
);
1835 prepare_to_wait (ecs
);
1841 case TARGET_WAITKIND_SPURIOUS
:
1843 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SPURIOUS\n");
1844 resume (0, TARGET_SIGNAL_0
);
1845 prepare_to_wait (ecs
);
1848 case TARGET_WAITKIND_EXITED
:
1850 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXITED\n");
1851 target_terminal_ours (); /* Must do this before mourn anyway */
1852 print_stop_reason (EXITED
, ecs
->ws
.value
.integer
);
1854 /* Record the exit code in the convenience variable $_exitcode, so
1855 that the user can inspect this again later. */
1856 set_internalvar (lookup_internalvar ("_exitcode"),
1857 value_from_longest (builtin_type_int
,
1858 (LONGEST
) ecs
->ws
.value
.integer
));
1859 gdb_flush (gdb_stdout
);
1860 target_mourn_inferior ();
1861 singlestep_breakpoints_inserted_p
= 0;
1862 stop_print_frame
= 0;
1863 stop_stepping (ecs
);
1866 case TARGET_WAITKIND_SIGNALLED
:
1868 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SIGNALLED\n");
1869 stop_print_frame
= 0;
1870 stop_signal
= ecs
->ws
.value
.sig
;
1871 target_terminal_ours (); /* Must do this before mourn anyway */
1873 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
1874 reach here unless the inferior is dead. However, for years
1875 target_kill() was called here, which hints that fatal signals aren't
1876 really fatal on some systems. If that's true, then some changes
1878 target_mourn_inferior ();
1880 print_stop_reason (SIGNAL_EXITED
, stop_signal
);
1881 singlestep_breakpoints_inserted_p
= 0;
1882 stop_stepping (ecs
);
1885 /* The following are the only cases in which we keep going;
1886 the above cases end in a continue or goto. */
1887 case TARGET_WAITKIND_FORKED
:
1888 case TARGET_WAITKIND_VFORKED
:
1890 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_FORKED\n");
1891 stop_signal
= TARGET_SIGNAL_TRAP
;
1892 pending_follow
.kind
= ecs
->ws
.kind
;
1894 pending_follow
.fork_event
.parent_pid
= PIDGET (ecs
->ptid
);
1895 pending_follow
.fork_event
.child_pid
= ecs
->ws
.value
.related_pid
;
1897 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1899 context_switch (ecs
);
1900 reinit_frame_cache ();
1903 stop_pc
= read_pc ();
1905 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
1907 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1909 /* If no catchpoint triggered for this, then keep going. */
1910 if (ecs
->random_signal
)
1912 stop_signal
= TARGET_SIGNAL_0
;
1916 goto process_event_stop_test
;
1918 case TARGET_WAITKIND_EXECD
:
1920 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_EXECD\n");
1921 stop_signal
= TARGET_SIGNAL_TRAP
;
1923 pending_follow
.execd_pathname
=
1924 savestring (ecs
->ws
.value
.execd_pathname
,
1925 strlen (ecs
->ws
.value
.execd_pathname
));
1927 /* This causes the eventpoints and symbol table to be reset. Must
1928 do this now, before trying to determine whether to stop. */
1929 follow_exec (PIDGET (inferior_ptid
), pending_follow
.execd_pathname
);
1930 xfree (pending_follow
.execd_pathname
);
1932 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
1933 ecs
->saved_inferior_ptid
= inferior_ptid
;
1934 inferior_ptid
= ecs
->ptid
;
1936 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
1938 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
1939 inferior_ptid
= ecs
->saved_inferior_ptid
;
1941 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
1943 context_switch (ecs
);
1944 reinit_frame_cache ();
1947 /* If no catchpoint triggered for this, then keep going. */
1948 if (ecs
->random_signal
)
1950 stop_signal
= TARGET_SIGNAL_0
;
1954 goto process_event_stop_test
;
1956 /* Be careful not to try to gather much state about a thread
1957 that's in a syscall. It's frequently a losing proposition. */
1958 case TARGET_WAITKIND_SYSCALL_ENTRY
:
1960 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
1961 resume (0, TARGET_SIGNAL_0
);
1962 prepare_to_wait (ecs
);
1965 /* Before examining the threads further, step this thread to
1966 get it entirely out of the syscall. (We get notice of the
1967 event when the thread is just on the verge of exiting a
1968 syscall. Stepping one instruction seems to get it back
1970 case TARGET_WAITKIND_SYSCALL_RETURN
:
1972 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
1973 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
);
1974 prepare_to_wait (ecs
);
1977 case TARGET_WAITKIND_STOPPED
:
1979 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_STOPPED\n");
1980 stop_signal
= ecs
->ws
.value
.sig
;
1983 /* We had an event in the inferior, but we are not interested
1984 in handling it at this level. The lower layers have already
1985 done what needs to be done, if anything.
1987 One of the possible circumstances for this is when the
1988 inferior produces output for the console. The inferior has
1989 not stopped, and we are ignoring the event. Another possible
1990 circumstance is any event which the lower level knows will be
1991 reported multiple times without an intervening resume. */
1992 case TARGET_WAITKIND_IGNORE
:
1994 fprintf_unfiltered (gdb_stdlog
, "infrun: TARGET_WAITKIND_IGNORE\n");
1995 prepare_to_wait (ecs
);
1999 /* We may want to consider not doing a resume here in order to give
2000 the user a chance to play with the new thread. It might be good
2001 to make that a user-settable option. */
2003 /* At this point, all threads are stopped (happens automatically in
2004 either the OS or the native code). Therefore we need to continue
2005 all threads in order to make progress. */
2006 if (ecs
->new_thread_event
)
2008 target_resume (RESUME_ALL
, 0, TARGET_SIGNAL_0
);
2009 prepare_to_wait (ecs
);
2013 /* Do we need to clean up the state of a thread that has completed a
2014 displaced single-step? (Doing so usually affects the PC, so do
2015 it here, before we set stop_pc.) */
2016 displaced_step_fixup (ecs
->ptid
, stop_signal
);
2018 stop_pc
= regcache_read_pc (get_thread_regcache (ecs
->ptid
));
2022 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_pc = 0x%s\n",
2023 paddr_nz (stop_pc
));
2024 if (STOPPED_BY_WATCHPOINT (&ecs
->ws
))
2027 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped by watchpoint\n");
2029 if (target_stopped_data_address (¤t_target
, &addr
))
2030 fprintf_unfiltered (gdb_stdlog
,
2031 "infrun: stopped data address = 0x%s\n",
2034 fprintf_unfiltered (gdb_stdlog
,
2035 "infrun: (no data address available)\n");
2039 if (stepping_past_singlestep_breakpoint
)
2041 gdb_assert (singlestep_breakpoints_inserted_p
);
2042 gdb_assert (ptid_equal (singlestep_ptid
, ecs
->ptid
));
2043 gdb_assert (!ptid_equal (singlestep_ptid
, saved_singlestep_ptid
));
2045 stepping_past_singlestep_breakpoint
= 0;
2047 /* We've either finished single-stepping past the single-step
2048 breakpoint, or stopped for some other reason. It would be nice if
2049 we could tell, but we can't reliably. */
2050 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2053 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping_past_singlestep_breakpoint\n");
2054 /* Pull the single step breakpoints out of the target. */
2055 remove_single_step_breakpoints ();
2056 singlestep_breakpoints_inserted_p
= 0;
2058 ecs
->random_signal
= 0;
2060 ecs
->ptid
= saved_singlestep_ptid
;
2061 context_switch (ecs
);
2062 if (deprecated_context_hook
)
2063 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2065 resume (1, TARGET_SIGNAL_0
);
2066 prepare_to_wait (ecs
);
2071 stepping_past_singlestep_breakpoint
= 0;
2073 if (!ptid_equal (deferred_step_ptid
, null_ptid
))
2075 /* If we stopped for some other reason than single-stepping, ignore
2076 the fact that we were supposed to switch back. */
2077 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2080 fprintf_unfiltered (gdb_stdlog
,
2081 "infrun: handling deferred step\n");
2083 /* Pull the single step breakpoints out of the target. */
2084 if (singlestep_breakpoints_inserted_p
)
2086 remove_single_step_breakpoints ();
2087 singlestep_breakpoints_inserted_p
= 0;
2090 /* Note: We do not call context_switch at this point, as the
2091 context is already set up for stepping the original thread. */
2092 switch_to_thread (deferred_step_ptid
);
2093 deferred_step_ptid
= null_ptid
;
2094 /* Suppress spurious "Switching to ..." message. */
2095 previous_inferior_ptid
= inferior_ptid
;
2097 resume (1, TARGET_SIGNAL_0
);
2098 prepare_to_wait (ecs
);
2102 deferred_step_ptid
= null_ptid
;
2105 /* See if a thread hit a thread-specific breakpoint that was meant for
2106 another thread. If so, then step that thread past the breakpoint,
2109 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2111 int thread_hop_needed
= 0;
2113 /* Check if a regular breakpoint has been hit before checking
2114 for a potential single step breakpoint. Otherwise, GDB will
2115 not see this breakpoint hit when stepping onto breakpoints. */
2116 if (regular_breakpoint_inserted_here_p (stop_pc
))
2118 ecs
->random_signal
= 0;
2119 if (!breakpoint_thread_match (stop_pc
, ecs
->ptid
))
2120 thread_hop_needed
= 1;
2122 else if (singlestep_breakpoints_inserted_p
)
2124 /* We have not context switched yet, so this should be true
2125 no matter which thread hit the singlestep breakpoint. */
2126 gdb_assert (ptid_equal (inferior_ptid
, singlestep_ptid
));
2128 fprintf_unfiltered (gdb_stdlog
, "infrun: software single step "
2130 target_pid_to_str (ecs
->ptid
));
2132 ecs
->random_signal
= 0;
2133 /* The call to in_thread_list is necessary because PTIDs sometimes
2134 change when we go from single-threaded to multi-threaded. If
2135 the singlestep_ptid is still in the list, assume that it is
2136 really different from ecs->ptid. */
2137 if (!ptid_equal (singlestep_ptid
, ecs
->ptid
)
2138 && in_thread_list (singlestep_ptid
))
2140 /* If the PC of the thread we were trying to single-step
2141 has changed, discard this event (which we were going
2142 to ignore anyway), and pretend we saw that thread
2143 trap. This prevents us continuously moving the
2144 single-step breakpoint forward, one instruction at a
2145 time. If the PC has changed, then the thread we were
2146 trying to single-step has trapped or been signalled,
2147 but the event has not been reported to GDB yet.
2149 There might be some cases where this loses signal
2150 information, if a signal has arrived at exactly the
2151 same time that the PC changed, but this is the best
2152 we can do with the information available. Perhaps we
2153 should arrange to report all events for all threads
2154 when they stop, or to re-poll the remote looking for
2155 this particular thread (i.e. temporarily enable
2158 CORE_ADDR new_singlestep_pc
2159 = regcache_read_pc (get_thread_regcache (singlestep_ptid
));
2161 if (new_singlestep_pc
!= singlestep_pc
)
2164 fprintf_unfiltered (gdb_stdlog
, "infrun: unexpected thread,"
2165 " but expected thread advanced also\n");
2167 /* The current context still belongs to
2168 singlestep_ptid. Don't swap here, since that's
2169 the context we want to use. Just fudge our
2170 state and continue. */
2171 ecs
->ptid
= singlestep_ptid
;
2172 stop_pc
= new_singlestep_pc
;
2177 fprintf_unfiltered (gdb_stdlog
,
2178 "infrun: unexpected thread\n");
2180 thread_hop_needed
= 1;
2181 stepping_past_singlestep_breakpoint
= 1;
2182 saved_singlestep_ptid
= singlestep_ptid
;
2187 if (thread_hop_needed
)
2189 int remove_status
= 0;
2192 fprintf_unfiltered (gdb_stdlog
, "infrun: thread_hop_needed\n");
2194 /* Saw a breakpoint, but it was hit by the wrong thread.
2197 if (singlestep_breakpoints_inserted_p
)
2199 /* Pull the single step breakpoints out of the target. */
2200 remove_single_step_breakpoints ();
2201 singlestep_breakpoints_inserted_p
= 0;
2204 /* If the arch can displace step, don't remove the
2206 if (!use_displaced_stepping (current_gdbarch
))
2207 remove_status
= remove_breakpoints ();
2209 /* Did we fail to remove breakpoints? If so, try
2210 to set the PC past the bp. (There's at least
2211 one situation in which we can fail to remove
2212 the bp's: On HP-UX's that use ttrace, we can't
2213 change the address space of a vforking child
2214 process until the child exits (well, okay, not
2215 then either :-) or execs. */
2216 if (remove_status
!= 0)
2217 error (_("Cannot step over breakpoint hit in wrong thread"));
2220 if (!ptid_equal (inferior_ptid
, ecs
->ptid
))
2221 context_switch (ecs
);
2222 ecs
->waiton_ptid
= ecs
->ptid
;
2223 ecs
->wp
= &(ecs
->ws
);
2224 ecs
->stepping_over_breakpoint
= 1;
2226 ecs
->infwait_state
= infwait_thread_hop_state
;
2228 registers_changed ();
2232 else if (singlestep_breakpoints_inserted_p
)
2234 sw_single_step_trap_p
= 1;
2235 ecs
->random_signal
= 0;
2239 ecs
->random_signal
= 1;
2241 /* See if something interesting happened to the non-current thread. If
2242 so, then switch to that thread. */
2243 if (!ptid_equal (ecs
->ptid
, inferior_ptid
))
2246 fprintf_unfiltered (gdb_stdlog
, "infrun: context switch\n");
2248 context_switch (ecs
);
2250 if (deprecated_context_hook
)
2251 deprecated_context_hook (pid_to_thread_id (ecs
->ptid
));
2254 if (singlestep_breakpoints_inserted_p
)
2256 /* Pull the single step breakpoints out of the target. */
2257 remove_single_step_breakpoints ();
2258 singlestep_breakpoints_inserted_p
= 0;
2261 if (stepped_after_stopped_by_watchpoint
)
2262 stopped_by_watchpoint
= 0;
2264 stopped_by_watchpoint
= watchpoints_triggered (&ecs
->ws
);
2266 /* If necessary, step over this watchpoint. We'll be back to display
2268 if (stopped_by_watchpoint
2269 && (HAVE_STEPPABLE_WATCHPOINT
2270 || gdbarch_have_nonsteppable_watchpoint (current_gdbarch
)))
2272 /* At this point, we are stopped at an instruction which has
2273 attempted to write to a piece of memory under control of
2274 a watchpoint. The instruction hasn't actually executed
2275 yet. If we were to evaluate the watchpoint expression
2276 now, we would get the old value, and therefore no change
2277 would seem to have occurred.
2279 In order to make watchpoints work `right', we really need
2280 to complete the memory write, and then evaluate the
2281 watchpoint expression. We do this by single-stepping the
2284 It may not be necessary to disable the watchpoint to stop over
2285 it. For example, the PA can (with some kernel cooperation)
2286 single step over a watchpoint without disabling the watchpoint.
2288 It is far more common to need to disable a watchpoint to step
2289 the inferior over it. If we have non-steppable watchpoints,
2290 we must disable the current watchpoint; it's simplest to
2291 disable all watchpoints and breakpoints. */
2293 if (!HAVE_STEPPABLE_WATCHPOINT
)
2294 remove_breakpoints ();
2295 registers_changed ();
2296 target_resume (ecs
->ptid
, 1, TARGET_SIGNAL_0
); /* Single step */
2297 ecs
->waiton_ptid
= ecs
->ptid
;
2298 if (HAVE_STEPPABLE_WATCHPOINT
)
2299 ecs
->infwait_state
= infwait_step_watch_state
;
2301 ecs
->infwait_state
= infwait_nonstep_watch_state
;
2302 prepare_to_wait (ecs
);
2306 ecs
->stop_func_start
= 0;
2307 ecs
->stop_func_end
= 0;
2308 ecs
->stop_func_name
= 0;
2309 /* Don't care about return value; stop_func_start and stop_func_name
2310 will both be 0 if it doesn't work. */
2311 find_pc_partial_function (stop_pc
, &ecs
->stop_func_name
,
2312 &ecs
->stop_func_start
, &ecs
->stop_func_end
);
2313 ecs
->stop_func_start
2314 += gdbarch_deprecated_function_start_offset (current_gdbarch
);
2315 ecs
->stepping_over_breakpoint
= 0;
2316 bpstat_clear (&stop_bpstat
);
2318 stop_print_frame
= 1;
2319 ecs
->random_signal
= 0;
2320 stopped_by_random_signal
= 0;
2322 if (stop_signal
== TARGET_SIGNAL_TRAP
2323 && stepping_over_breakpoint
2324 && gdbarch_single_step_through_delay_p (current_gdbarch
)
2325 && currently_stepping (ecs
))
2327 /* We're trying to step off a breakpoint. Turns out that we're
2328 also on an instruction that needs to be stepped multiple
2329 times before it's been fully executing. E.g., architectures
2330 with a delay slot. It needs to be stepped twice, once for
2331 the instruction and once for the delay slot. */
2332 int step_through_delay
2333 = gdbarch_single_step_through_delay (current_gdbarch
,
2334 get_current_frame ());
2335 if (debug_infrun
&& step_through_delay
)
2336 fprintf_unfiltered (gdb_stdlog
, "infrun: step through delay\n");
2337 if (step_range_end
== 0 && step_through_delay
)
2339 /* The user issued a continue when stopped at a breakpoint.
2340 Set up for another trap and get out of here. */
2341 ecs
->stepping_over_breakpoint
= 1;
2345 else if (step_through_delay
)
2347 /* The user issued a step when stopped at a breakpoint.
2348 Maybe we should stop, maybe we should not - the delay
2349 slot *might* correspond to a line of source. In any
2350 case, don't decide that here, just set
2351 ecs->stepping_over_breakpoint, making sure we
2352 single-step again before breakpoints are re-inserted. */
2353 ecs
->stepping_over_breakpoint
= 1;
2357 /* Look at the cause of the stop, and decide what to do.
2358 The alternatives are:
2359 1) break; to really stop and return to the debugger,
2360 2) drop through to start up again
2361 (set ecs->stepping_over_breakpoint to 1 to single step once)
2362 3) set ecs->random_signal to 1, and the decision between 1 and 2
2363 will be made according to the signal handling tables. */
2365 /* First, distinguish signals caused by the debugger from signals
2366 that have to do with the program's own actions. Note that
2367 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
2368 on the operating system version. Here we detect when a SIGILL or
2369 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
2370 something similar for SIGSEGV, since a SIGSEGV will be generated
2371 when we're trying to execute a breakpoint instruction on a
2372 non-executable stack. This happens for call dummy breakpoints
2373 for architectures like SPARC that place call dummies on the
2376 If we're doing a displaced step past a breakpoint, then the
2377 breakpoint is always inserted at the original instruction;
2378 non-standard signals can't be explained by the breakpoint. */
2379 if (stop_signal
== TARGET_SIGNAL_TRAP
2380 || (! stepping_over_breakpoint
2381 && breakpoint_inserted_here_p (stop_pc
)
2382 && (stop_signal
== TARGET_SIGNAL_ILL
2383 || stop_signal
== TARGET_SIGNAL_SEGV
2384 || stop_signal
== TARGET_SIGNAL_EMT
))
2385 || stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2386 || stop_soon
== STOP_QUIETLY_REMOTE
)
2388 if (stop_signal
== TARGET_SIGNAL_TRAP
&& stop_after_trap
)
2391 fprintf_unfiltered (gdb_stdlog
, "infrun: stopped\n");
2392 stop_print_frame
= 0;
2393 stop_stepping (ecs
);
2397 /* This is originated from start_remote(), start_inferior() and
2398 shared libraries hook functions. */
2399 if (stop_soon
== STOP_QUIETLY
|| stop_soon
== STOP_QUIETLY_REMOTE
)
2402 fprintf_unfiltered (gdb_stdlog
, "infrun: quietly stopped\n");
2403 stop_stepping (ecs
);
2407 /* This originates from attach_command(). We need to overwrite
2408 the stop_signal here, because some kernels don't ignore a
2409 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
2410 See more comments in inferior.h. On the other hand, if we
2411 get a non-SIGSTOP, report it to the user - assume the backend
2412 will handle the SIGSTOP if it should show up later. */
2413 if (stop_soon
== STOP_QUIETLY_NO_SIGSTOP
2414 && stop_signal
== TARGET_SIGNAL_STOP
)
2416 stop_stepping (ecs
);
2417 stop_signal
= TARGET_SIGNAL_0
;
2421 /* See if there is a breakpoint at the current PC. */
2422 stop_bpstat
= bpstat_stop_status (stop_pc
, ecs
->ptid
);
2424 /* Following in case break condition called a
2426 stop_print_frame
= 1;
2428 /* NOTE: cagney/2003-03-29: These two checks for a random signal
2429 at one stage in the past included checks for an inferior
2430 function call's call dummy's return breakpoint. The original
2431 comment, that went with the test, read:
2433 ``End of a stack dummy. Some systems (e.g. Sony news) give
2434 another signal besides SIGTRAP, so check here as well as
2437 If someone ever tries to get get call dummys on a
2438 non-executable stack to work (where the target would stop
2439 with something like a SIGSEGV), then those tests might need
2440 to be re-instated. Given, however, that the tests were only
2441 enabled when momentary breakpoints were not being used, I
2442 suspect that it won't be the case.
2444 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
2445 be necessary for call dummies on a non-executable stack on
2448 if (stop_signal
== TARGET_SIGNAL_TRAP
)
2450 = !(bpstat_explains_signal (stop_bpstat
)
2451 || stepping_over_breakpoint
2452 || (step_range_end
&& step_resume_breakpoint
== NULL
));
2455 ecs
->random_signal
= !bpstat_explains_signal (stop_bpstat
);
2456 if (!ecs
->random_signal
)
2457 stop_signal
= TARGET_SIGNAL_TRAP
;
2461 /* When we reach this point, we've pretty much decided
2462 that the reason for stopping must've been a random
2463 (unexpected) signal. */
2466 ecs
->random_signal
= 1;
2468 process_event_stop_test
:
2469 /* For the program's own signals, act according to
2470 the signal handling tables. */
2472 if (ecs
->random_signal
)
2474 /* Signal not for debugging purposes. */
2478 fprintf_unfiltered (gdb_stdlog
, "infrun: random signal %d\n", stop_signal
);
2480 stopped_by_random_signal
= 1;
2482 if (signal_print
[stop_signal
])
2485 target_terminal_ours_for_output ();
2486 print_stop_reason (SIGNAL_RECEIVED
, stop_signal
);
2488 if (signal_stop_state (stop_signal
))
2490 stop_stepping (ecs
);
2493 /* If not going to stop, give terminal back
2494 if we took it away. */
2496 target_terminal_inferior ();
2498 /* Clear the signal if it should not be passed. */
2499 if (signal_program
[stop_signal
] == 0)
2500 stop_signal
= TARGET_SIGNAL_0
;
2502 if (prev_pc
== read_pc ()
2503 && stepping_over_breakpoint
2504 && step_resume_breakpoint
== NULL
)
2506 /* We were just starting a new sequence, attempting to
2507 single-step off of a breakpoint and expecting a SIGTRAP.
2508 Instead this signal arrives. This signal will take us out
2509 of the stepping range so GDB needs to remember to, when
2510 the signal handler returns, resume stepping off that
2512 /* To simplify things, "continue" is forced to use the same
2513 code paths as single-step - set a breakpoint at the
2514 signal return address and then, once hit, step off that
2517 fprintf_unfiltered (gdb_stdlog
,
2518 "infrun: signal arrived while stepping over "
2521 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2522 ecs
->step_after_step_resume_breakpoint
= 1;
2527 if (step_range_end
!= 0
2528 && stop_signal
!= TARGET_SIGNAL_0
2529 && stop_pc
>= step_range_start
&& stop_pc
< step_range_end
2530 && frame_id_eq (get_frame_id (get_current_frame ()),
2532 && step_resume_breakpoint
== NULL
)
2534 /* The inferior is about to take a signal that will take it
2535 out of the single step range. Set a breakpoint at the
2536 current PC (which is presumably where the signal handler
2537 will eventually return) and then allow the inferior to
2540 Note that this is only needed for a signal delivered
2541 while in the single-step range. Nested signals aren't a
2542 problem as they eventually all return. */
2544 fprintf_unfiltered (gdb_stdlog
,
2545 "infrun: signal may take us out of "
2546 "single-step range\n");
2548 insert_step_resume_breakpoint_at_frame (get_current_frame ());
2553 /* Note: step_resume_breakpoint may be non-NULL. This occures
2554 when either there's a nested signal, or when there's a
2555 pending signal enabled just as the signal handler returns
2556 (leaving the inferior at the step-resume-breakpoint without
2557 actually executing it). Either way continue until the
2558 breakpoint is really hit. */
2563 /* Handle cases caused by hitting a breakpoint. */
2565 CORE_ADDR jmp_buf_pc
;
2566 struct bpstat_what what
;
2568 what
= bpstat_what (stop_bpstat
);
2570 if (what
.call_dummy
)
2572 stop_stack_dummy
= 1;
2575 switch (what
.main_action
)
2577 case BPSTAT_WHAT_SET_LONGJMP_RESUME
:
2578 /* If we hit the breakpoint at longjmp while stepping, we
2579 install a momentary breakpoint at the target of the
2583 fprintf_unfiltered (gdb_stdlog
,
2584 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
2586 ecs
->stepping_over_breakpoint
= 1;
2588 if (!gdbarch_get_longjmp_target_p (current_gdbarch
)
2589 || !gdbarch_get_longjmp_target (current_gdbarch
,
2590 get_current_frame (), &jmp_buf_pc
))
2593 fprintf_unfiltered (gdb_stdlog
, "\
2594 infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (!gdbarch_get_longjmp_target)\n");
2599 /* We're going to replace the current step-resume breakpoint
2600 with a longjmp-resume breakpoint. */
2601 if (step_resume_breakpoint
!= NULL
)
2602 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2604 /* Insert a breakpoint at resume address. */
2605 insert_longjmp_resume_breakpoint (jmp_buf_pc
);
2610 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
:
2612 fprintf_unfiltered (gdb_stdlog
,
2613 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
2615 gdb_assert (step_resume_breakpoint
!= NULL
);
2616 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2619 print_stop_reason (END_STEPPING_RANGE
, 0);
2620 stop_stepping (ecs
);
2623 case BPSTAT_WHAT_SINGLE
:
2625 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_SINGLE\n");
2626 ecs
->stepping_over_breakpoint
= 1;
2627 /* Still need to check other stuff, at least the case
2628 where we are stepping and step out of the right range. */
2631 case BPSTAT_WHAT_STOP_NOISY
:
2633 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
2634 stop_print_frame
= 1;
2636 /* We are about to nuke the step_resume_breakpointt via the
2637 cleanup chain, so no need to worry about it here. */
2639 stop_stepping (ecs
);
2642 case BPSTAT_WHAT_STOP_SILENT
:
2644 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
2645 stop_print_frame
= 0;
2647 /* We are about to nuke the step_resume_breakpoin via the
2648 cleanup chain, so no need to worry about it here. */
2650 stop_stepping (ecs
);
2653 case BPSTAT_WHAT_STEP_RESUME
:
2654 /* This proably demands a more elegant solution, but, yeah
2657 This function's use of the simple variable
2658 step_resume_breakpoint doesn't seem to accomodate
2659 simultaneously active step-resume bp's, although the
2660 breakpoint list certainly can.
2662 If we reach here and step_resume_breakpoint is already
2663 NULL, then apparently we have multiple active
2664 step-resume bp's. We'll just delete the breakpoint we
2665 stopped at, and carry on.
2667 Correction: what the code currently does is delete a
2668 step-resume bp, but it makes no effort to ensure that
2669 the one deleted is the one currently stopped at. MVS */
2672 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
2674 if (step_resume_breakpoint
== NULL
)
2676 step_resume_breakpoint
=
2677 bpstat_find_step_resume_breakpoint (stop_bpstat
);
2679 delete_step_resume_breakpoint (&step_resume_breakpoint
);
2680 if (ecs
->step_after_step_resume_breakpoint
)
2682 /* Back when the step-resume breakpoint was inserted, we
2683 were trying to single-step off a breakpoint. Go back
2685 ecs
->step_after_step_resume_breakpoint
= 0;
2686 ecs
->stepping_over_breakpoint
= 1;
2692 case BPSTAT_WHAT_CHECK_SHLIBS
:
2693 case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
:
2696 fprintf_unfiltered (gdb_stdlog
, "infrun: BPSTAT_WHAT_CHECK_SHLIBS\n");
2698 /* Check for any newly added shared libraries if we're
2699 supposed to be adding them automatically. Switch
2700 terminal for any messages produced by
2701 breakpoint_re_set. */
2702 target_terminal_ours_for_output ();
2703 /* NOTE: cagney/2003-11-25: Make certain that the target
2704 stack's section table is kept up-to-date. Architectures,
2705 (e.g., PPC64), use the section table to perform
2706 operations such as address => section name and hence
2707 require the table to contain all sections (including
2708 those found in shared libraries). */
2709 /* NOTE: cagney/2003-11-25: Pass current_target and not
2710 exec_ops to SOLIB_ADD. This is because current GDB is
2711 only tooled to propagate section_table changes out from
2712 the "current_target" (see target_resize_to_sections), and
2713 not up from the exec stratum. This, of course, isn't
2714 right. "infrun.c" should only interact with the
2715 exec/process stratum, instead relying on the target stack
2716 to propagate relevant changes (stop, section table
2717 changed, ...) up to other layers. */
2719 SOLIB_ADD (NULL
, 0, ¤t_target
, auto_solib_add
);
2721 solib_add (NULL
, 0, ¤t_target
, auto_solib_add
);
2723 target_terminal_inferior ();
2725 /* If requested, stop when the dynamic linker notifies
2726 gdb of events. This allows the user to get control
2727 and place breakpoints in initializer routines for
2728 dynamically loaded objects (among other things). */
2729 if (stop_on_solib_events
|| stop_stack_dummy
)
2731 stop_stepping (ecs
);
2735 /* If we stopped due to an explicit catchpoint, then the
2736 (see above) call to SOLIB_ADD pulled in any symbols
2737 from a newly-loaded library, if appropriate.
2739 We do want the inferior to stop, but not where it is
2740 now, which is in the dynamic linker callback. Rather,
2741 we would like it stop in the user's program, just after
2742 the call that caused this catchpoint to trigger. That
2743 gives the user a more useful vantage from which to
2744 examine their program's state. */
2745 else if (what
.main_action
2746 == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
)
2748 /* ??rehrauer: If I could figure out how to get the
2749 right return PC from here, we could just set a temp
2750 breakpoint and resume. I'm not sure we can without
2751 cracking open the dld's shared libraries and sniffing
2752 their unwind tables and text/data ranges, and that's
2753 not a terribly portable notion.
2755 Until that time, we must step the inferior out of the
2756 dld callback, and also out of the dld itself (and any
2757 code or stubs in libdld.sl, such as "shl_load" and
2758 friends) until we reach non-dld code. At that point,
2759 we can stop stepping. */
2760 bpstat_get_triggered_catchpoints (stop_bpstat
,
2762 stepping_through_solib_catchpoints
);
2763 ecs
->stepping_through_solib_after_catch
= 1;
2765 /* Be sure to lift all breakpoints, so the inferior does
2766 actually step past this point... */
2767 ecs
->stepping_over_breakpoint
= 1;
2772 /* We want to step over this breakpoint, then keep going. */
2773 ecs
->stepping_over_breakpoint
= 1;
2779 case BPSTAT_WHAT_LAST
:
2780 /* Not a real code, but listed here to shut up gcc -Wall. */
2782 case BPSTAT_WHAT_KEEP_CHECKING
:
2787 /* We come here if we hit a breakpoint but should not
2788 stop for it. Possibly we also were stepping
2789 and should stop for that. So fall through and
2790 test for stepping. But, if not stepping,
2793 /* Are we stepping to get the inferior out of the dynamic linker's
2794 hook (and possibly the dld itself) after catching a shlib
2796 if (ecs
->stepping_through_solib_after_catch
)
2798 #if defined(SOLIB_ADD)
2799 /* Have we reached our destination? If not, keep going. */
2800 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs
->ptid
), stop_pc
))
2803 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping in dynamic linker\n");
2804 ecs
->stepping_over_breakpoint
= 1;
2810 fprintf_unfiltered (gdb_stdlog
, "infrun: step past dynamic linker\n");
2811 /* Else, stop and report the catchpoint(s) whose triggering
2812 caused us to begin stepping. */
2813 ecs
->stepping_through_solib_after_catch
= 0;
2814 bpstat_clear (&stop_bpstat
);
2815 stop_bpstat
= bpstat_copy (ecs
->stepping_through_solib_catchpoints
);
2816 bpstat_clear (&ecs
->stepping_through_solib_catchpoints
);
2817 stop_print_frame
= 1;
2818 stop_stepping (ecs
);
2822 if (step_resume_breakpoint
)
2825 fprintf_unfiltered (gdb_stdlog
,
2826 "infrun: step-resume breakpoint is inserted\n");
2828 /* Having a step-resume breakpoint overrides anything
2829 else having to do with stepping commands until
2830 that breakpoint is reached. */
2835 if (step_range_end
== 0)
2838 fprintf_unfiltered (gdb_stdlog
, "infrun: no stepping, continue\n");
2839 /* Likewise if we aren't even stepping. */
2844 /* If stepping through a line, keep going if still within it.
2846 Note that step_range_end is the address of the first instruction
2847 beyond the step range, and NOT the address of the last instruction
2849 if (stop_pc
>= step_range_start
&& stop_pc
< step_range_end
)
2852 fprintf_unfiltered (gdb_stdlog
, "infrun: stepping inside range [0x%s-0x%s]\n",
2853 paddr_nz (step_range_start
),
2854 paddr_nz (step_range_end
));
2859 /* We stepped out of the stepping range. */
2861 /* If we are stepping at the source level and entered the runtime
2862 loader dynamic symbol resolution code, we keep on single stepping
2863 until we exit the run time loader code and reach the callee's
2865 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2866 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2867 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc
)
2869 && in_solib_dynsym_resolve_code (stop_pc
)
2873 CORE_ADDR pc_after_resolver
=
2874 gdbarch_skip_solib_resolver (current_gdbarch
, stop_pc
);
2877 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into dynsym resolve code\n");
2879 if (pc_after_resolver
)
2881 /* Set up a step-resume breakpoint at the address
2882 indicated by SKIP_SOLIB_RESOLVER. */
2883 struct symtab_and_line sr_sal
;
2885 sr_sal
.pc
= pc_after_resolver
;
2887 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2894 if (step_range_end
!= 1
2895 && (step_over_calls
== STEP_OVER_UNDEBUGGABLE
2896 || step_over_calls
== STEP_OVER_ALL
)
2897 && get_frame_type (get_current_frame ()) == SIGTRAMP_FRAME
)
2900 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into signal trampoline\n");
2901 /* The inferior, while doing a "step" or "next", has ended up in
2902 a signal trampoline (either by a signal being delivered or by
2903 the signal handler returning). Just single-step until the
2904 inferior leaves the trampoline (either by calling the handler
2910 /* Check for subroutine calls. The check for the current frame
2911 equalling the step ID is not necessary - the check of the
2912 previous frame's ID is sufficient - but it is a common case and
2913 cheaper than checking the previous frame's ID.
2915 NOTE: frame_id_eq will never report two invalid frame IDs as
2916 being equal, so to get into this block, both the current and
2917 previous frame must have valid frame IDs. */
2918 if (!frame_id_eq (get_frame_id (get_current_frame ()), step_frame_id
)
2919 && frame_id_eq (frame_unwind_id (get_current_frame ()), step_frame_id
))
2921 CORE_ADDR real_stop_pc
;
2924 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into subroutine\n");
2926 if ((step_over_calls
== STEP_OVER_NONE
)
2927 || ((step_range_end
== 1)
2928 && in_prologue (prev_pc
, ecs
->stop_func_start
)))
2930 /* I presume that step_over_calls is only 0 when we're
2931 supposed to be stepping at the assembly language level
2932 ("stepi"). Just stop. */
2933 /* Also, maybe we just did a "nexti" inside a prolog, so we
2934 thought it was a subroutine call but it was not. Stop as
2937 print_stop_reason (END_STEPPING_RANGE
, 0);
2938 stop_stepping (ecs
);
2942 if (step_over_calls
== STEP_OVER_ALL
)
2944 /* We're doing a "next", set a breakpoint at callee's return
2945 address (the address at which the caller will
2947 insert_step_resume_breakpoint_at_caller (get_current_frame ());
2952 /* If we are in a function call trampoline (a stub between the
2953 calling routine and the real function), locate the real
2954 function. That's what tells us (a) whether we want to step
2955 into it at all, and (b) what prologue we want to run to the
2956 end of, if we do step into it. */
2957 real_stop_pc
= skip_language_trampoline (get_current_frame (), stop_pc
);
2958 if (real_stop_pc
== 0)
2959 real_stop_pc
= gdbarch_skip_trampoline_code
2960 (current_gdbarch
, get_current_frame (), stop_pc
);
2961 if (real_stop_pc
!= 0)
2962 ecs
->stop_func_start
= real_stop_pc
;
2965 #ifdef IN_SOLIB_DYNSYM_RESOLVE_CODE
2966 IN_SOLIB_DYNSYM_RESOLVE_CODE (ecs
->stop_func_start
)
2968 in_solib_dynsym_resolve_code (ecs
->stop_func_start
)
2972 struct symtab_and_line sr_sal
;
2974 sr_sal
.pc
= ecs
->stop_func_start
;
2976 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
2981 /* If we have line number information for the function we are
2982 thinking of stepping into, step into it.
2984 If there are several symtabs at that PC (e.g. with include
2985 files), just want to know whether *any* of them have line
2986 numbers. find_pc_line handles this. */
2988 struct symtab_and_line tmp_sal
;
2990 tmp_sal
= find_pc_line (ecs
->stop_func_start
, 0);
2991 if (tmp_sal
.line
!= 0)
2993 step_into_function (ecs
);
2998 /* If we have no line number and the step-stop-if-no-debug is
2999 set, we stop the step so that the user has a chance to switch
3000 in assembly mode. */
3001 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
&& step_stop_if_no_debug
)
3004 print_stop_reason (END_STEPPING_RANGE
, 0);
3005 stop_stepping (ecs
);
3009 /* Set a breakpoint at callee's return address (the address at
3010 which the caller will resume). */
3011 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3016 /* If we're in the return path from a shared library trampoline,
3017 we want to proceed through the trampoline when stepping. */
3018 if (gdbarch_in_solib_return_trampoline (current_gdbarch
,
3019 stop_pc
, ecs
->stop_func_name
))
3021 /* Determine where this trampoline returns. */
3022 CORE_ADDR real_stop_pc
;
3023 real_stop_pc
= gdbarch_skip_trampoline_code
3024 (current_gdbarch
, get_current_frame (), stop_pc
);
3027 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into solib return tramp\n");
3029 /* Only proceed through if we know where it's going. */
3032 /* And put the step-breakpoint there and go until there. */
3033 struct symtab_and_line sr_sal
;
3035 init_sal (&sr_sal
); /* initialize to zeroes */
3036 sr_sal
.pc
= real_stop_pc
;
3037 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3039 /* Do not specify what the fp should be when we stop since
3040 on some machines the prologue is where the new fp value
3042 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3044 /* Restart without fiddling with the step ranges or
3051 ecs
->sal
= find_pc_line (stop_pc
, 0);
3053 /* NOTE: tausq/2004-05-24: This if block used to be done before all
3054 the trampoline processing logic, however, there are some trampolines
3055 that have no names, so we should do trampoline handling first. */
3056 if (step_over_calls
== STEP_OVER_UNDEBUGGABLE
3057 && ecs
->stop_func_name
== NULL
3058 && ecs
->sal
.line
== 0)
3061 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped into undebuggable function\n");
3063 /* The inferior just stepped into, or returned to, an
3064 undebuggable function (where there is no debugging information
3065 and no line number corresponding to the address where the
3066 inferior stopped). Since we want to skip this kind of code,
3067 we keep going until the inferior returns from this
3068 function - unless the user has asked us not to (via
3069 set step-mode) or we no longer know how to get back
3070 to the call site. */
3071 if (step_stop_if_no_debug
3072 || !frame_id_p (frame_unwind_id (get_current_frame ())))
3074 /* If we have no line number and the step-stop-if-no-debug
3075 is set, we stop the step so that the user has a chance to
3076 switch in assembly mode. */
3078 print_stop_reason (END_STEPPING_RANGE
, 0);
3079 stop_stepping (ecs
);
3084 /* Set a breakpoint at callee's return address (the address
3085 at which the caller will resume). */
3086 insert_step_resume_breakpoint_at_caller (get_current_frame ());
3092 if (step_range_end
== 1)
3094 /* It is stepi or nexti. We always want to stop stepping after
3097 fprintf_unfiltered (gdb_stdlog
, "infrun: stepi/nexti\n");
3099 print_stop_reason (END_STEPPING_RANGE
, 0);
3100 stop_stepping (ecs
);
3104 if (ecs
->sal
.line
== 0)
3106 /* We have no line number information. That means to stop
3107 stepping (does this always happen right after one instruction,
3108 when we do "s" in a function with no line numbers,
3109 or can this happen as a result of a return or longjmp?). */
3111 fprintf_unfiltered (gdb_stdlog
, "infrun: no line number info\n");
3113 print_stop_reason (END_STEPPING_RANGE
, 0);
3114 stop_stepping (ecs
);
3118 if ((stop_pc
== ecs
->sal
.pc
)
3119 && (ecs
->current_line
!= ecs
->sal
.line
3120 || ecs
->current_symtab
!= ecs
->sal
.symtab
))
3122 /* We are at the start of a different line. So stop. Note that
3123 we don't stop if we step into the middle of a different line.
3124 That is said to make things like for (;;) statements work
3127 fprintf_unfiltered (gdb_stdlog
, "infrun: stepped to a different line\n");
3129 print_stop_reason (END_STEPPING_RANGE
, 0);
3130 stop_stepping (ecs
);
3134 /* We aren't done stepping.
3136 Optimize by setting the stepping range to the line.
3137 (We might not be in the original line, but if we entered a
3138 new line in mid-statement, we continue stepping. This makes
3139 things like for(;;) statements work better.) */
3141 step_range_start
= ecs
->sal
.pc
;
3142 step_range_end
= ecs
->sal
.end
;
3143 step_frame_id
= get_frame_id (get_current_frame ());
3144 ecs
->current_line
= ecs
->sal
.line
;
3145 ecs
->current_symtab
= ecs
->sal
.symtab
;
3147 /* In the case where we just stepped out of a function into the
3148 middle of a line of the caller, continue stepping, but
3149 step_frame_id must be modified to current frame */
3151 /* NOTE: cagney/2003-10-16: I think this frame ID inner test is too
3152 generous. It will trigger on things like a step into a frameless
3153 stackless leaf function. I think the logic should instead look
3154 at the unwound frame ID has that should give a more robust
3155 indication of what happened. */
3156 if (step
- ID
== current
- ID
)
3157 still stepping in same function
;
3158 else if (step
- ID
== unwind (current
- ID
))
3159 stepped into a function
;
3161 stepped out of a function
;
3162 /* Of course this assumes that the frame ID unwind code is robust
3163 and we're willing to introduce frame unwind logic into this
3164 function. Fortunately, those days are nearly upon us. */
3167 struct frame_info
*frame
= get_current_frame ();
3168 struct frame_id current_frame
= get_frame_id (frame
);
3169 if (!(frame_id_inner (get_frame_arch (frame
), current_frame
,
3171 step_frame_id
= current_frame
;
3175 fprintf_unfiltered (gdb_stdlog
, "infrun: keep going\n");
3179 /* Are we in the middle of stepping? */
3182 currently_stepping (struct execution_control_state
*ecs
)
3184 return (((step_range_end
&& step_resume_breakpoint
== NULL
)
3185 || stepping_over_breakpoint
)
3186 || ecs
->stepping_through_solib_after_catch
3187 || bpstat_should_step ());
3190 /* Subroutine call with source code we should not step over. Do step
3191 to the first line of code in it. */
3194 step_into_function (struct execution_control_state
*ecs
)
3197 struct symtab_and_line sr_sal
;
3199 s
= find_pc_symtab (stop_pc
);
3200 if (s
&& s
->language
!= language_asm
)
3201 ecs
->stop_func_start
= gdbarch_skip_prologue
3202 (current_gdbarch
, ecs
->stop_func_start
);
3204 ecs
->sal
= find_pc_line (ecs
->stop_func_start
, 0);
3205 /* Use the step_resume_break to step until the end of the prologue,
3206 even if that involves jumps (as it seems to on the vax under
3208 /* If the prologue ends in the middle of a source line, continue to
3209 the end of that source line (if it is still within the function).
3210 Otherwise, just go to end of prologue. */
3212 && ecs
->sal
.pc
!= ecs
->stop_func_start
3213 && ecs
->sal
.end
< ecs
->stop_func_end
)
3214 ecs
->stop_func_start
= ecs
->sal
.end
;
3216 /* Architectures which require breakpoint adjustment might not be able
3217 to place a breakpoint at the computed address. If so, the test
3218 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
3219 ecs->stop_func_start to an address at which a breakpoint may be
3220 legitimately placed.
3222 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
3223 made, GDB will enter an infinite loop when stepping through
3224 optimized code consisting of VLIW instructions which contain
3225 subinstructions corresponding to different source lines. On
3226 FR-V, it's not permitted to place a breakpoint on any but the
3227 first subinstruction of a VLIW instruction. When a breakpoint is
3228 set, GDB will adjust the breakpoint address to the beginning of
3229 the VLIW instruction. Thus, we need to make the corresponding
3230 adjustment here when computing the stop address. */
3232 if (gdbarch_adjust_breakpoint_address_p (current_gdbarch
))
3234 ecs
->stop_func_start
3235 = gdbarch_adjust_breakpoint_address (current_gdbarch
,
3236 ecs
->stop_func_start
);
3239 if (ecs
->stop_func_start
== stop_pc
)
3241 /* We are already there: stop now. */
3243 print_stop_reason (END_STEPPING_RANGE
, 0);
3244 stop_stepping (ecs
);
3249 /* Put the step-breakpoint there and go until there. */
3250 init_sal (&sr_sal
); /* initialize to zeroes */
3251 sr_sal
.pc
= ecs
->stop_func_start
;
3252 sr_sal
.section
= find_pc_overlay (ecs
->stop_func_start
);
3254 /* Do not specify what the fp should be when we stop since on
3255 some machines the prologue is where the new fp value is
3257 insert_step_resume_breakpoint_at_sal (sr_sal
, null_frame_id
);
3259 /* And make sure stepping stops right away then. */
3260 step_range_end
= step_range_start
;
3265 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
3266 This is used to both functions and to skip over code. */
3269 insert_step_resume_breakpoint_at_sal (struct symtab_and_line sr_sal
,
3270 struct frame_id sr_id
)
3272 /* There should never be more than one step-resume or longjmp-resume
3273 breakpoint per thread, so we should never be setting a new
3274 step_resume_breakpoint when one is already active. */
3275 gdb_assert (step_resume_breakpoint
== NULL
);
3278 fprintf_unfiltered (gdb_stdlog
,
3279 "infrun: inserting step-resume breakpoint at 0x%s\n",
3280 paddr_nz (sr_sal
.pc
));
3282 step_resume_breakpoint
= set_momentary_breakpoint (sr_sal
, sr_id
,
3286 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
3287 to skip a potential signal handler.
3289 This is called with the interrupted function's frame. The signal
3290 handler, when it returns, will resume the interrupted function at
3294 insert_step_resume_breakpoint_at_frame (struct frame_info
*return_frame
)
3296 struct symtab_and_line sr_sal
;
3298 gdb_assert (return_frame
!= NULL
);
3299 init_sal (&sr_sal
); /* initialize to zeros */
3301 sr_sal
.pc
= gdbarch_addr_bits_remove
3302 (current_gdbarch
, get_frame_pc (return_frame
));
3303 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3305 insert_step_resume_breakpoint_at_sal (sr_sal
, get_frame_id (return_frame
));
3308 /* Similar to insert_step_resume_breakpoint_at_frame, except
3309 but a breakpoint at the previous frame's PC. This is used to
3310 skip a function after stepping into it (for "next" or if the called
3311 function has no debugging information).
3313 The current function has almost always been reached by single
3314 stepping a call or return instruction. NEXT_FRAME belongs to the
3315 current function, and the breakpoint will be set at the caller's
3318 This is a separate function rather than reusing
3319 insert_step_resume_breakpoint_at_frame in order to avoid
3320 get_prev_frame, which may stop prematurely (see the implementation
3321 of frame_unwind_id for an example). */
3324 insert_step_resume_breakpoint_at_caller (struct frame_info
*next_frame
)
3326 struct symtab_and_line sr_sal
;
3328 /* We shouldn't have gotten here if we don't know where the call site
3330 gdb_assert (frame_id_p (frame_unwind_id (next_frame
)));
3332 init_sal (&sr_sal
); /* initialize to zeros */
3334 sr_sal
.pc
= gdbarch_addr_bits_remove
3335 (current_gdbarch
, frame_pc_unwind (next_frame
));
3336 sr_sal
.section
= find_pc_overlay (sr_sal
.pc
);
3338 insert_step_resume_breakpoint_at_sal (sr_sal
, frame_unwind_id (next_frame
));
3341 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
3342 new breakpoint at the target of a jmp_buf. The handling of
3343 longjmp-resume uses the same mechanisms used for handling
3344 "step-resume" breakpoints. */
3347 insert_longjmp_resume_breakpoint (CORE_ADDR pc
)
3349 /* There should never be more than one step-resume or longjmp-resume
3350 breakpoint per thread, so we should never be setting a new
3351 longjmp_resume_breakpoint when one is already active. */
3352 gdb_assert (step_resume_breakpoint
== NULL
);
3355 fprintf_unfiltered (gdb_stdlog
,
3356 "infrun: inserting longjmp-resume breakpoint at 0x%s\n",
3359 step_resume_breakpoint
=
3360 set_momentary_breakpoint_at_pc (pc
, bp_longjmp_resume
);
3364 stop_stepping (struct execution_control_state
*ecs
)
3367 fprintf_unfiltered (gdb_stdlog
, "infrun: stop_stepping\n");
3369 /* Let callers know we don't want to wait for the inferior anymore. */
3370 ecs
->wait_some_more
= 0;
3373 /* This function handles various cases where we need to continue
3374 waiting for the inferior. */
3375 /* (Used to be the keep_going: label in the old wait_for_inferior) */
3378 keep_going (struct execution_control_state
*ecs
)
3380 /* Save the pc before execution, to compare with pc after stop. */
3381 prev_pc
= read_pc (); /* Might have been DECR_AFTER_BREAK */
3383 /* If we did not do break;, it means we should keep running the
3384 inferior and not return to debugger. */
3386 if (stepping_over_breakpoint
&& stop_signal
!= TARGET_SIGNAL_TRAP
)
3388 /* We took a signal (which we are supposed to pass through to
3389 the inferior, else we'd have done a break above) and we
3390 haven't yet gotten our trap. Simply continue. */
3391 resume (currently_stepping (ecs
), stop_signal
);
3395 /* Either the trap was not expected, but we are continuing
3396 anyway (the user asked that this signal be passed to the
3399 The signal was SIGTRAP, e.g. it was our signal, but we
3400 decided we should resume from it.
3402 We're going to run this baby now!
3404 Note that insert_breakpoints won't try to re-insert
3405 already inserted breakpoints. Therefore, we don't
3406 care if breakpoints were already inserted, or not. */
3408 if (ecs
->stepping_over_breakpoint
)
3410 if (! use_displaced_stepping (current_gdbarch
))
3411 /* Since we can't do a displaced step, we have to remove
3412 the breakpoint while we step it. To keep things
3413 simple, we remove them all. */
3414 remove_breakpoints ();
3418 struct gdb_exception e
;
3419 /* Stop stepping when inserting breakpoints
3421 TRY_CATCH (e
, RETURN_MASK_ERROR
)
3423 insert_breakpoints ();
3427 stop_stepping (ecs
);
3432 stepping_over_breakpoint
= ecs
->stepping_over_breakpoint
;
3434 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
3435 specifies that such a signal should be delivered to the
3438 Typically, this would occure when a user is debugging a
3439 target monitor on a simulator: the target monitor sets a
3440 breakpoint; the simulator encounters this break-point and
3441 halts the simulation handing control to GDB; GDB, noteing
3442 that the break-point isn't valid, returns control back to the
3443 simulator; the simulator then delivers the hardware
3444 equivalent of a SIGNAL_TRAP to the program being debugged. */
3446 if (stop_signal
== TARGET_SIGNAL_TRAP
&& !signal_program
[stop_signal
])
3447 stop_signal
= TARGET_SIGNAL_0
;
3450 resume (currently_stepping (ecs
), stop_signal
);
3453 prepare_to_wait (ecs
);
3456 /* This function normally comes after a resume, before
3457 handle_inferior_event exits. It takes care of any last bits of
3458 housekeeping, and sets the all-important wait_some_more flag. */
3461 prepare_to_wait (struct execution_control_state
*ecs
)
3464 fprintf_unfiltered (gdb_stdlog
, "infrun: prepare_to_wait\n");
3465 if (ecs
->infwait_state
== infwait_normal_state
)
3467 overlay_cache_invalid
= 1;
3469 /* We have to invalidate the registers BEFORE calling
3470 target_wait because they can be loaded from the target while
3471 in target_wait. This makes remote debugging a bit more
3472 efficient for those targets that provide critical registers
3473 as part of their normal status mechanism. */
3475 registers_changed ();
3476 ecs
->waiton_ptid
= pid_to_ptid (-1);
3477 ecs
->wp
= &(ecs
->ws
);
3479 /* This is the old end of the while loop. Let everybody know we
3480 want to wait for the inferior some more and get called again
3482 ecs
->wait_some_more
= 1;
3485 /* Print why the inferior has stopped. We always print something when
3486 the inferior exits, or receives a signal. The rest of the cases are
3487 dealt with later on in normal_stop() and print_it_typical(). Ideally
3488 there should be a call to this function from handle_inferior_event()
3489 each time stop_stepping() is called.*/
3491 print_stop_reason (enum inferior_stop_reason stop_reason
, int stop_info
)
3493 switch (stop_reason
)
3495 case END_STEPPING_RANGE
:
3496 /* We are done with a step/next/si/ni command. */
3497 /* For now print nothing. */
3498 /* Print a message only if not in the middle of doing a "step n"
3499 operation for n > 1 */
3500 if (!step_multi
|| !stop_step
)
3501 if (ui_out_is_mi_like_p (uiout
))
3504 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE
));
3507 /* The inferior was terminated by a signal. */
3508 annotate_signalled ();
3509 if (ui_out_is_mi_like_p (uiout
))
3512 async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED
));
3513 ui_out_text (uiout
, "\nProgram terminated with signal ");
3514 annotate_signal_name ();
3515 ui_out_field_string (uiout
, "signal-name",
3516 target_signal_to_name (stop_info
));
3517 annotate_signal_name_end ();
3518 ui_out_text (uiout
, ", ");
3519 annotate_signal_string ();
3520 ui_out_field_string (uiout
, "signal-meaning",
3521 target_signal_to_string (stop_info
));
3522 annotate_signal_string_end ();
3523 ui_out_text (uiout
, ".\n");
3524 ui_out_text (uiout
, "The program no longer exists.\n");
3527 /* The inferior program is finished. */
3528 annotate_exited (stop_info
);
3531 if (ui_out_is_mi_like_p (uiout
))
3532 ui_out_field_string (uiout
, "reason",
3533 async_reason_lookup (EXEC_ASYNC_EXITED
));
3534 ui_out_text (uiout
, "\nProgram exited with code ");
3535 ui_out_field_fmt (uiout
, "exit-code", "0%o",
3536 (unsigned int) stop_info
);
3537 ui_out_text (uiout
, ".\n");
3541 if (ui_out_is_mi_like_p (uiout
))
3544 async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY
));
3545 ui_out_text (uiout
, "\nProgram exited normally.\n");
3547 /* Support the --return-child-result option. */
3548 return_child_result_value
= stop_info
;
3550 case SIGNAL_RECEIVED
:
3551 /* Signal received. The signal table tells us to print about
3554 ui_out_text (uiout
, "\nProgram received signal ");
3555 annotate_signal_name ();
3556 if (ui_out_is_mi_like_p (uiout
))
3558 (uiout
, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED
));
3559 ui_out_field_string (uiout
, "signal-name",
3560 target_signal_to_name (stop_info
));
3561 annotate_signal_name_end ();
3562 ui_out_text (uiout
, ", ");
3563 annotate_signal_string ();
3564 ui_out_field_string (uiout
, "signal-meaning",
3565 target_signal_to_string (stop_info
));
3566 annotate_signal_string_end ();
3567 ui_out_text (uiout
, ".\n");
3570 internal_error (__FILE__
, __LINE__
,
3571 _("print_stop_reason: unrecognized enum value"));
3577 /* Here to return control to GDB when the inferior stops for real.
3578 Print appropriate messages, remove breakpoints, give terminal our modes.
3580 STOP_PRINT_FRAME nonzero means print the executing frame
3581 (pc, function, args, file, line number and line text).
3582 BREAKPOINTS_FAILED nonzero means stop was due to error
3583 attempting to insert breakpoints. */
3588 struct target_waitstatus last
;
3591 get_last_target_status (&last_ptid
, &last
);
3593 /* As with the notification of thread events, we want to delay
3594 notifying the user that we've switched thread context until
3595 the inferior actually stops.
3597 There's no point in saying anything if the inferior has exited.
3598 Note that SIGNALLED here means "exited with a signal", not
3599 "received a signal". */
3600 if (!ptid_equal (previous_inferior_ptid
, inferior_ptid
)
3601 && target_has_execution
3602 && last
.kind
!= TARGET_WAITKIND_SIGNALLED
3603 && last
.kind
!= TARGET_WAITKIND_EXITED
)
3605 target_terminal_ours_for_output ();
3606 printf_filtered (_("[Switching to %s]\n"),
3607 target_pid_to_str (inferior_ptid
));
3608 previous_inferior_ptid
= inferior_ptid
;
3611 /* NOTE drow/2004-01-17: Is this still necessary? */
3612 /* Make sure that the current_frame's pc is correct. This
3613 is a correction for setting up the frame info before doing
3614 gdbarch_decr_pc_after_break */
3615 if (target_has_execution
)
3616 /* FIXME: cagney/2002-12-06: Has the PC changed? Thanks to
3617 gdbarch_decr_pc_after_break, the program counter can change. Ask the
3618 frame code to check for this and sort out any resultant mess.
3619 gdbarch_decr_pc_after_break needs to just go away. */
3620 deprecated_update_frame_pc_hack (get_current_frame (), read_pc ());
3622 if (!breakpoints_always_inserted_mode () && target_has_execution
)
3624 if (remove_breakpoints ())
3626 target_terminal_ours_for_output ();
3627 printf_filtered (_("\
3628 Cannot remove breakpoints because program is no longer writable.\n\
3629 It might be running in another process.\n\
3630 Further execution is probably impossible.\n"));
3634 /* If an auto-display called a function and that got a signal,
3635 delete that auto-display to avoid an infinite recursion. */
3637 if (stopped_by_random_signal
)
3638 disable_current_display ();
3640 /* Don't print a message if in the middle of doing a "step n"
3641 operation for n > 1 */
3642 if (step_multi
&& stop_step
)
3645 target_terminal_ours ();
3647 /* Set the current source location. This will also happen if we
3648 display the frame below, but the current SAL will be incorrect
3649 during a user hook-stop function. */
3650 if (target_has_stack
&& !stop_stack_dummy
)
3651 set_current_sal_from_frame (get_current_frame (), 1);
3653 /* Look up the hook_stop and run it (CLI internally handles problem
3654 of stop_command's pre-hook not existing). */
3656 catch_errors (hook_stop_stub
, stop_command
,
3657 "Error while running hook_stop:\n", RETURN_MASK_ALL
);
3659 if (!target_has_stack
)
3665 /* Select innermost stack frame - i.e., current frame is frame 0,
3666 and current location is based on that.
3667 Don't do this on return from a stack dummy routine,
3668 or if the program has exited. */
3670 if (!stop_stack_dummy
)
3672 select_frame (get_current_frame ());
3674 /* Print current location without a level number, if
3675 we have changed functions or hit a breakpoint.
3676 Print source line if we have one.
3677 bpstat_print() contains the logic deciding in detail
3678 what to print, based on the event(s) that just occurred. */
3680 /* If --batch-silent is enabled then there's no need to print the current
3681 source location, and to try risks causing an error message about
3682 missing source files. */
3683 if (stop_print_frame
&& !batch_silent
)
3687 int do_frame_printing
= 1;
3689 bpstat_ret
= bpstat_print (stop_bpstat
);
3693 /* If we had hit a shared library event breakpoint,
3694 bpstat_print would print out this message. If we hit
3695 an OS-level shared library event, do the same
3697 if (last
.kind
== TARGET_WAITKIND_LOADED
)
3699 printf_filtered (_("Stopped due to shared library event\n"));
3700 source_flag
= SRC_LINE
; /* something bogus */
3701 do_frame_printing
= 0;
3705 /* FIXME: cagney/2002-12-01: Given that a frame ID does
3706 (or should) carry around the function and does (or
3707 should) use that when doing a frame comparison. */
3709 && frame_id_eq (step_frame_id
,
3710 get_frame_id (get_current_frame ()))
3711 && step_start_function
== find_pc_function (stop_pc
))
3712 source_flag
= SRC_LINE
; /* finished step, just print source line */
3714 source_flag
= SRC_AND_LOC
; /* print location and source line */
3716 case PRINT_SRC_AND_LOC
:
3717 source_flag
= SRC_AND_LOC
; /* print location and source line */
3719 case PRINT_SRC_ONLY
:
3720 source_flag
= SRC_LINE
;
3723 source_flag
= SRC_LINE
; /* something bogus */
3724 do_frame_printing
= 0;
3727 internal_error (__FILE__
, __LINE__
, _("Unknown value."));
3730 if (ui_out_is_mi_like_p (uiout
))
3731 ui_out_field_int (uiout
, "thread-id",
3732 pid_to_thread_id (inferior_ptid
));
3733 /* The behavior of this routine with respect to the source
3735 SRC_LINE: Print only source line
3736 LOCATION: Print only location
3737 SRC_AND_LOC: Print location and source line */
3738 if (do_frame_printing
)
3739 print_stack_frame (get_selected_frame (NULL
), 0, source_flag
);
3741 /* Display the auto-display expressions. */
3746 /* Save the function value return registers, if we care.
3747 We might be about to restore their previous contents. */
3748 if (proceed_to_finish
)
3750 /* This should not be necessary. */
3752 regcache_xfree (stop_registers
);
3754 /* NB: The copy goes through to the target picking up the value of
3755 all the registers. */
3756 stop_registers
= regcache_dup (get_current_regcache ());
3759 if (stop_stack_dummy
)
3761 /* Pop the empty frame that contains the stack dummy. POP_FRAME
3762 ends with a setting of the current frame, so we can use that
3764 frame_pop (get_current_frame ());
3765 /* Set stop_pc to what it was before we called the function.
3766 Can't rely on restore_inferior_status because that only gets
3767 called if we don't stop in the called function. */
3768 stop_pc
= read_pc ();
3769 select_frame (get_current_frame ());
3773 annotate_stopped ();
3774 observer_notify_normal_stop (stop_bpstat
);
3775 /* Delete the breakpoint we stopped at, if it wants to be deleted.
3776 Delete any breakpoint that is to be deleted at the next stop. */
3777 breakpoint_auto_delete (stop_bpstat
);
3781 hook_stop_stub (void *cmd
)
3783 execute_cmd_pre_hook ((struct cmd_list_element
*) cmd
);
3788 signal_stop_state (int signo
)
3790 /* Always stop on signals if we're just gaining control of the
3792 return signal_stop
[signo
] || stop_soon
!= NO_STOP_QUIETLY
;
3796 signal_print_state (int signo
)
3798 return signal_print
[signo
];
3802 signal_pass_state (int signo
)
3804 return signal_program
[signo
];
3808 signal_stop_update (int signo
, int state
)
3810 int ret
= signal_stop
[signo
];
3811 signal_stop
[signo
] = state
;
3816 signal_print_update (int signo
, int state
)
3818 int ret
= signal_print
[signo
];
3819 signal_print
[signo
] = state
;
3824 signal_pass_update (int signo
, int state
)
3826 int ret
= signal_program
[signo
];
3827 signal_program
[signo
] = state
;
3832 sig_print_header (void)
3834 printf_filtered (_("\
3835 Signal Stop\tPrint\tPass to program\tDescription\n"));
3839 sig_print_info (enum target_signal oursig
)
3841 char *name
= target_signal_to_name (oursig
);
3842 int name_padding
= 13 - strlen (name
);
3844 if (name_padding
<= 0)
3847 printf_filtered ("%s", name
);
3848 printf_filtered ("%*.*s ", name_padding
, name_padding
, " ");
3849 printf_filtered ("%s\t", signal_stop
[oursig
] ? "Yes" : "No");
3850 printf_filtered ("%s\t", signal_print
[oursig
] ? "Yes" : "No");
3851 printf_filtered ("%s\t\t", signal_program
[oursig
] ? "Yes" : "No");
3852 printf_filtered ("%s\n", target_signal_to_string (oursig
));
3855 /* Specify how various signals in the inferior should be handled. */
3858 handle_command (char *args
, int from_tty
)
3861 int digits
, wordlen
;
3862 int sigfirst
, signum
, siglast
;
3863 enum target_signal oursig
;
3866 unsigned char *sigs
;
3867 struct cleanup
*old_chain
;
3871 error_no_arg (_("signal to handle"));
3874 /* Allocate and zero an array of flags for which signals to handle. */
3876 nsigs
= (int) TARGET_SIGNAL_LAST
;
3877 sigs
= (unsigned char *) alloca (nsigs
);
3878 memset (sigs
, 0, nsigs
);
3880 /* Break the command line up into args. */
3882 argv
= buildargv (args
);
3887 old_chain
= make_cleanup_freeargv (argv
);
3889 /* Walk through the args, looking for signal oursigs, signal names, and
3890 actions. Signal numbers and signal names may be interspersed with
3891 actions, with the actions being performed for all signals cumulatively
3892 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
3894 while (*argv
!= NULL
)
3896 wordlen
= strlen (*argv
);
3897 for (digits
= 0; isdigit ((*argv
)[digits
]); digits
++)
3901 sigfirst
= siglast
= -1;
3903 if (wordlen
>= 1 && !strncmp (*argv
, "all", wordlen
))
3905 /* Apply action to all signals except those used by the
3906 debugger. Silently skip those. */
3909 siglast
= nsigs
- 1;
3911 else if (wordlen
>= 1 && !strncmp (*argv
, "stop", wordlen
))
3913 SET_SIGS (nsigs
, sigs
, signal_stop
);
3914 SET_SIGS (nsigs
, sigs
, signal_print
);
3916 else if (wordlen
>= 1 && !strncmp (*argv
, "ignore", wordlen
))
3918 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3920 else if (wordlen
>= 2 && !strncmp (*argv
, "print", wordlen
))
3922 SET_SIGS (nsigs
, sigs
, signal_print
);
3924 else if (wordlen
>= 2 && !strncmp (*argv
, "pass", wordlen
))
3926 SET_SIGS (nsigs
, sigs
, signal_program
);
3928 else if (wordlen
>= 3 && !strncmp (*argv
, "nostop", wordlen
))
3930 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3932 else if (wordlen
>= 3 && !strncmp (*argv
, "noignore", wordlen
))
3934 SET_SIGS (nsigs
, sigs
, signal_program
);
3936 else if (wordlen
>= 4 && !strncmp (*argv
, "noprint", wordlen
))
3938 UNSET_SIGS (nsigs
, sigs
, signal_print
);
3939 UNSET_SIGS (nsigs
, sigs
, signal_stop
);
3941 else if (wordlen
>= 4 && !strncmp (*argv
, "nopass", wordlen
))
3943 UNSET_SIGS (nsigs
, sigs
, signal_program
);
3945 else if (digits
> 0)
3947 /* It is numeric. The numeric signal refers to our own
3948 internal signal numbering from target.h, not to host/target
3949 signal number. This is a feature; users really should be
3950 using symbolic names anyway, and the common ones like
3951 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
3953 sigfirst
= siglast
= (int)
3954 target_signal_from_command (atoi (*argv
));
3955 if ((*argv
)[digits
] == '-')
3958 target_signal_from_command (atoi ((*argv
) + digits
+ 1));
3960 if (sigfirst
> siglast
)
3962 /* Bet he didn't figure we'd think of this case... */
3970 oursig
= target_signal_from_name (*argv
);
3971 if (oursig
!= TARGET_SIGNAL_UNKNOWN
)
3973 sigfirst
= siglast
= (int) oursig
;
3977 /* Not a number and not a recognized flag word => complain. */
3978 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv
);
3982 /* If any signal numbers or symbol names were found, set flags for
3983 which signals to apply actions to. */
3985 for (signum
= sigfirst
; signum
>= 0 && signum
<= siglast
; signum
++)
3987 switch ((enum target_signal
) signum
)
3989 case TARGET_SIGNAL_TRAP
:
3990 case TARGET_SIGNAL_INT
:
3991 if (!allsigs
&& !sigs
[signum
])
3993 if (query ("%s is used by the debugger.\n\
3994 Are you sure you want to change it? ", target_signal_to_name ((enum target_signal
) signum
)))
4000 printf_unfiltered (_("Not confirmed, unchanged.\n"));
4001 gdb_flush (gdb_stdout
);
4005 case TARGET_SIGNAL_0
:
4006 case TARGET_SIGNAL_DEFAULT
:
4007 case TARGET_SIGNAL_UNKNOWN
:
4008 /* Make sure that "all" doesn't print these. */
4019 target_notice_signals (inferior_ptid
);
4023 /* Show the results. */
4024 sig_print_header ();
4025 for (signum
= 0; signum
< nsigs
; signum
++)
4029 sig_print_info (signum
);
4034 do_cleanups (old_chain
);
4038 xdb_handle_command (char *args
, int from_tty
)
4041 struct cleanup
*old_chain
;
4043 /* Break the command line up into args. */
4045 argv
= buildargv (args
);
4050 old_chain
= make_cleanup_freeargv (argv
);
4051 if (argv
[1] != (char *) NULL
)
4056 bufLen
= strlen (argv
[0]) + 20;
4057 argBuf
= (char *) xmalloc (bufLen
);
4061 enum target_signal oursig
;
4063 oursig
= target_signal_from_name (argv
[0]);
4064 memset (argBuf
, 0, bufLen
);
4065 if (strcmp (argv
[1], "Q") == 0)
4066 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4069 if (strcmp (argv
[1], "s") == 0)
4071 if (!signal_stop
[oursig
])
4072 sprintf (argBuf
, "%s %s", argv
[0], "stop");
4074 sprintf (argBuf
, "%s %s", argv
[0], "nostop");
4076 else if (strcmp (argv
[1], "i") == 0)
4078 if (!signal_program
[oursig
])
4079 sprintf (argBuf
, "%s %s", argv
[0], "pass");
4081 sprintf (argBuf
, "%s %s", argv
[0], "nopass");
4083 else if (strcmp (argv
[1], "r") == 0)
4085 if (!signal_print
[oursig
])
4086 sprintf (argBuf
, "%s %s", argv
[0], "print");
4088 sprintf (argBuf
, "%s %s", argv
[0], "noprint");
4094 handle_command (argBuf
, from_tty
);
4096 printf_filtered (_("Invalid signal handling flag.\n"));
4101 do_cleanups (old_chain
);
4104 /* Print current contents of the tables set by the handle command.
4105 It is possible we should just be printing signals actually used
4106 by the current target (but for things to work right when switching
4107 targets, all signals should be in the signal tables). */
4110 signals_info (char *signum_exp
, int from_tty
)
4112 enum target_signal oursig
;
4113 sig_print_header ();
4117 /* First see if this is a symbol name. */
4118 oursig
= target_signal_from_name (signum_exp
);
4119 if (oursig
== TARGET_SIGNAL_UNKNOWN
)
4121 /* No, try numeric. */
4123 target_signal_from_command (parse_and_eval_long (signum_exp
));
4125 sig_print_info (oursig
);
4129 printf_filtered ("\n");
4130 /* These ugly casts brought to you by the native VAX compiler. */
4131 for (oursig
= TARGET_SIGNAL_FIRST
;
4132 (int) oursig
< (int) TARGET_SIGNAL_LAST
;
4133 oursig
= (enum target_signal
) ((int) oursig
+ 1))
4137 if (oursig
!= TARGET_SIGNAL_UNKNOWN
4138 && oursig
!= TARGET_SIGNAL_DEFAULT
&& oursig
!= TARGET_SIGNAL_0
)
4139 sig_print_info (oursig
);
4142 printf_filtered (_("\nUse the \"handle\" command to change these tables.\n"));
4145 struct inferior_status
4147 enum target_signal stop_signal
;
4151 int stop_stack_dummy
;
4152 int stopped_by_random_signal
;
4153 int stepping_over_breakpoint
;
4154 CORE_ADDR step_range_start
;
4155 CORE_ADDR step_range_end
;
4156 struct frame_id step_frame_id
;
4157 enum step_over_calls_kind step_over_calls
;
4158 CORE_ADDR step_resume_break_address
;
4159 int stop_after_trap
;
4162 /* These are here because if call_function_by_hand has written some
4163 registers and then decides to call error(), we better not have changed
4165 struct regcache
*registers
;
4167 /* A frame unique identifier. */
4168 struct frame_id selected_frame_id
;
4170 int breakpoint_proceeded
;
4171 int restore_stack_info
;
4172 int proceed_to_finish
;
4176 write_inferior_status_register (struct inferior_status
*inf_status
, int regno
,
4179 int size
= register_size (current_gdbarch
, regno
);
4180 void *buf
= alloca (size
);
4181 store_signed_integer (buf
, size
, val
);
4182 regcache_raw_write (inf_status
->registers
, regno
, buf
);
4185 /* Save all of the information associated with the inferior<==>gdb
4186 connection. INF_STATUS is a pointer to a "struct inferior_status"
4187 (defined in inferior.h). */
4189 struct inferior_status
*
4190 save_inferior_status (int restore_stack_info
)
4192 struct inferior_status
*inf_status
= XMALLOC (struct inferior_status
);
4194 inf_status
->stop_signal
= stop_signal
;
4195 inf_status
->stop_pc
= stop_pc
;
4196 inf_status
->stop_step
= stop_step
;
4197 inf_status
->stop_stack_dummy
= stop_stack_dummy
;
4198 inf_status
->stopped_by_random_signal
= stopped_by_random_signal
;
4199 inf_status
->stepping_over_breakpoint
= stepping_over_breakpoint
;
4200 inf_status
->step_range_start
= step_range_start
;
4201 inf_status
->step_range_end
= step_range_end
;
4202 inf_status
->step_frame_id
= step_frame_id
;
4203 inf_status
->step_over_calls
= step_over_calls
;
4204 inf_status
->stop_after_trap
= stop_after_trap
;
4205 inf_status
->stop_soon
= stop_soon
;
4206 /* Save original bpstat chain here; replace it with copy of chain.
4207 If caller's caller is walking the chain, they'll be happier if we
4208 hand them back the original chain when restore_inferior_status is
4210 inf_status
->stop_bpstat
= stop_bpstat
;
4211 stop_bpstat
= bpstat_copy (stop_bpstat
);
4212 inf_status
->breakpoint_proceeded
= breakpoint_proceeded
;
4213 inf_status
->restore_stack_info
= restore_stack_info
;
4214 inf_status
->proceed_to_finish
= proceed_to_finish
;
4216 inf_status
->registers
= regcache_dup (get_current_regcache ());
4218 inf_status
->selected_frame_id
= get_frame_id (get_selected_frame (NULL
));
4223 restore_selected_frame (void *args
)
4225 struct frame_id
*fid
= (struct frame_id
*) args
;
4226 struct frame_info
*frame
;
4228 frame
= frame_find_by_id (*fid
);
4230 /* If inf_status->selected_frame_id is NULL, there was no previously
4234 warning (_("Unable to restore previously selected frame."));
4238 select_frame (frame
);
4244 restore_inferior_status (struct inferior_status
*inf_status
)
4246 stop_signal
= inf_status
->stop_signal
;
4247 stop_pc
= inf_status
->stop_pc
;
4248 stop_step
= inf_status
->stop_step
;
4249 stop_stack_dummy
= inf_status
->stop_stack_dummy
;
4250 stopped_by_random_signal
= inf_status
->stopped_by_random_signal
;
4251 stepping_over_breakpoint
= inf_status
->stepping_over_breakpoint
;
4252 step_range_start
= inf_status
->step_range_start
;
4253 step_range_end
= inf_status
->step_range_end
;
4254 step_frame_id
= inf_status
->step_frame_id
;
4255 step_over_calls
= inf_status
->step_over_calls
;
4256 stop_after_trap
= inf_status
->stop_after_trap
;
4257 stop_soon
= inf_status
->stop_soon
;
4258 bpstat_clear (&stop_bpstat
);
4259 stop_bpstat
= inf_status
->stop_bpstat
;
4260 breakpoint_proceeded
= inf_status
->breakpoint_proceeded
;
4261 proceed_to_finish
= inf_status
->proceed_to_finish
;
4263 /* The inferior can be gone if the user types "print exit(0)"
4264 (and perhaps other times). */
4265 if (target_has_execution
)
4266 /* NB: The register write goes through to the target. */
4267 regcache_cpy (get_current_regcache (), inf_status
->registers
);
4268 regcache_xfree (inf_status
->registers
);
4270 /* FIXME: If we are being called after stopping in a function which
4271 is called from gdb, we should not be trying to restore the
4272 selected frame; it just prints a spurious error message (The
4273 message is useful, however, in detecting bugs in gdb (like if gdb
4274 clobbers the stack)). In fact, should we be restoring the
4275 inferior status at all in that case? . */
4277 if (target_has_stack
&& inf_status
->restore_stack_info
)
4279 /* The point of catch_errors is that if the stack is clobbered,
4280 walking the stack might encounter a garbage pointer and
4281 error() trying to dereference it. */
4283 (restore_selected_frame
, &inf_status
->selected_frame_id
,
4284 "Unable to restore previously selected frame:\n",
4285 RETURN_MASK_ERROR
) == 0)
4286 /* Error in restoring the selected frame. Select the innermost
4288 select_frame (get_current_frame ());
4296 do_restore_inferior_status_cleanup (void *sts
)
4298 restore_inferior_status (sts
);
4302 make_cleanup_restore_inferior_status (struct inferior_status
*inf_status
)
4304 return make_cleanup (do_restore_inferior_status_cleanup
, inf_status
);
4308 discard_inferior_status (struct inferior_status
*inf_status
)
4310 /* See save_inferior_status for info on stop_bpstat. */
4311 bpstat_clear (&inf_status
->stop_bpstat
);
4312 regcache_xfree (inf_status
->registers
);
4317 inferior_has_forked (int pid
, int *child_pid
)
4319 struct target_waitstatus last
;
4322 get_last_target_status (&last_ptid
, &last
);
4324 if (last
.kind
!= TARGET_WAITKIND_FORKED
)
4327 if (ptid_get_pid (last_ptid
) != pid
)
4330 *child_pid
= last
.value
.related_pid
;
4335 inferior_has_vforked (int pid
, int *child_pid
)
4337 struct target_waitstatus last
;
4340 get_last_target_status (&last_ptid
, &last
);
4342 if (last
.kind
!= TARGET_WAITKIND_VFORKED
)
4345 if (ptid_get_pid (last_ptid
) != pid
)
4348 *child_pid
= last
.value
.related_pid
;
4353 inferior_has_execd (int pid
, char **execd_pathname
)
4355 struct target_waitstatus last
;
4358 get_last_target_status (&last_ptid
, &last
);
4360 if (last
.kind
!= TARGET_WAITKIND_EXECD
)
4363 if (ptid_get_pid (last_ptid
) != pid
)
4366 *execd_pathname
= xstrdup (last
.value
.execd_pathname
);
4370 /* Oft used ptids */
4372 ptid_t minus_one_ptid
;
4374 /* Create a ptid given the necessary PID, LWP, and TID components. */
4377 ptid_build (int pid
, long lwp
, long tid
)
4387 /* Create a ptid from just a pid. */
4390 pid_to_ptid (int pid
)
4392 return ptid_build (pid
, 0, 0);
4395 /* Fetch the pid (process id) component from a ptid. */
4398 ptid_get_pid (ptid_t ptid
)
4403 /* Fetch the lwp (lightweight process) component from a ptid. */
4406 ptid_get_lwp (ptid_t ptid
)
4411 /* Fetch the tid (thread id) component from a ptid. */
4414 ptid_get_tid (ptid_t ptid
)
4419 /* ptid_equal() is used to test equality of two ptids. */
4422 ptid_equal (ptid_t ptid1
, ptid_t ptid2
)
4424 return (ptid1
.pid
== ptid2
.pid
&& ptid1
.lwp
== ptid2
.lwp
4425 && ptid1
.tid
== ptid2
.tid
);
4428 /* restore_inferior_ptid() will be used by the cleanup machinery
4429 to restore the inferior_ptid value saved in a call to
4430 save_inferior_ptid(). */
4433 restore_inferior_ptid (void *arg
)
4435 ptid_t
*saved_ptid_ptr
= arg
;
4436 inferior_ptid
= *saved_ptid_ptr
;
4440 /* Save the value of inferior_ptid so that it may be restored by a
4441 later call to do_cleanups(). Returns the struct cleanup pointer
4442 needed for later doing the cleanup. */
4445 save_inferior_ptid (void)
4447 ptid_t
*saved_ptid_ptr
;
4449 saved_ptid_ptr
= xmalloc (sizeof (ptid_t
));
4450 *saved_ptid_ptr
= inferior_ptid
;
4451 return make_cleanup (restore_inferior_ptid
, saved_ptid_ptr
);
4456 _initialize_infrun (void)
4460 struct cmd_list_element
*c
;
4462 add_info ("signals", signals_info
, _("\
4463 What debugger does when program gets various signals.\n\
4464 Specify a signal as argument to print info on that signal only."));
4465 add_info_alias ("handle", "signals", 0);
4467 add_com ("handle", class_run
, handle_command
, _("\
4468 Specify how to handle a signal.\n\
4469 Args are signals and actions to apply to those signals.\n\
4470 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4471 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4472 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4473 The special arg \"all\" is recognized to mean all signals except those\n\
4474 used by the debugger, typically SIGTRAP and SIGINT.\n\
4475 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
4476 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
4477 Stop means reenter debugger if this signal happens (implies print).\n\
4478 Print means print a message if this signal happens.\n\
4479 Pass means let program see this signal; otherwise program doesn't know.\n\
4480 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4481 Pass and Stop may be combined."));
4484 add_com ("lz", class_info
, signals_info
, _("\
4485 What debugger does when program gets various signals.\n\
4486 Specify a signal as argument to print info on that signal only."));
4487 add_com ("z", class_run
, xdb_handle_command
, _("\
4488 Specify how to handle a signal.\n\
4489 Args are signals and actions to apply to those signals.\n\
4490 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
4491 from 1-15 are allowed for compatibility with old versions of GDB.\n\
4492 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
4493 The special arg \"all\" is recognized to mean all signals except those\n\
4494 used by the debugger, typically SIGTRAP and SIGINT.\n\
4495 Recognized actions include \"s\" (toggles between stop and nostop), \n\
4496 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
4497 nopass), \"Q\" (noprint)\n\
4498 Stop means reenter debugger if this signal happens (implies print).\n\
4499 Print means print a message if this signal happens.\n\
4500 Pass means let program see this signal; otherwise program doesn't know.\n\
4501 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
4502 Pass and Stop may be combined."));
4506 stop_command
= add_cmd ("stop", class_obscure
,
4507 not_just_help_class_command
, _("\
4508 There is no `stop' command, but you can set a hook on `stop'.\n\
4509 This allows you to set a list of commands to be run each time execution\n\
4510 of the program stops."), &cmdlist
);
4512 add_setshow_zinteger_cmd ("infrun", class_maintenance
, &debug_infrun
, _("\
4513 Set inferior debugging."), _("\
4514 Show inferior debugging."), _("\
4515 When non-zero, inferior specific debugging is enabled."),
4518 &setdebuglist
, &showdebuglist
);
4520 add_setshow_boolean_cmd ("displaced", class_maintenance
, &debug_displaced
, _("\
4521 Set displaced stepping debugging."), _("\
4522 Show displaced stepping debugging."), _("\
4523 When non-zero, displaced stepping specific debugging is enabled."),
4525 show_debug_displaced
,
4526 &setdebuglist
, &showdebuglist
);
4528 numsigs
= (int) TARGET_SIGNAL_LAST
;
4529 signal_stop
= (unsigned char *) xmalloc (sizeof (signal_stop
[0]) * numsigs
);
4530 signal_print
= (unsigned char *)
4531 xmalloc (sizeof (signal_print
[0]) * numsigs
);
4532 signal_program
= (unsigned char *)
4533 xmalloc (sizeof (signal_program
[0]) * numsigs
);
4534 for (i
= 0; i
< numsigs
; i
++)
4537 signal_print
[i
] = 1;
4538 signal_program
[i
] = 1;
4541 /* Signals caused by debugger's own actions
4542 should not be given to the program afterwards. */
4543 signal_program
[TARGET_SIGNAL_TRAP
] = 0;
4544 signal_program
[TARGET_SIGNAL_INT
] = 0;
4546 /* Signals that are not errors should not normally enter the debugger. */
4547 signal_stop
[TARGET_SIGNAL_ALRM
] = 0;
4548 signal_print
[TARGET_SIGNAL_ALRM
] = 0;
4549 signal_stop
[TARGET_SIGNAL_VTALRM
] = 0;
4550 signal_print
[TARGET_SIGNAL_VTALRM
] = 0;
4551 signal_stop
[TARGET_SIGNAL_PROF
] = 0;
4552 signal_print
[TARGET_SIGNAL_PROF
] = 0;
4553 signal_stop
[TARGET_SIGNAL_CHLD
] = 0;
4554 signal_print
[TARGET_SIGNAL_CHLD
] = 0;
4555 signal_stop
[TARGET_SIGNAL_IO
] = 0;
4556 signal_print
[TARGET_SIGNAL_IO
] = 0;
4557 signal_stop
[TARGET_SIGNAL_POLL
] = 0;
4558 signal_print
[TARGET_SIGNAL_POLL
] = 0;
4559 signal_stop
[TARGET_SIGNAL_URG
] = 0;
4560 signal_print
[TARGET_SIGNAL_URG
] = 0;
4561 signal_stop
[TARGET_SIGNAL_WINCH
] = 0;
4562 signal_print
[TARGET_SIGNAL_WINCH
] = 0;
4564 /* These signals are used internally by user-level thread
4565 implementations. (See signal(5) on Solaris.) Like the above
4566 signals, a healthy program receives and handles them as part of
4567 its normal operation. */
4568 signal_stop
[TARGET_SIGNAL_LWP
] = 0;
4569 signal_print
[TARGET_SIGNAL_LWP
] = 0;
4570 signal_stop
[TARGET_SIGNAL_WAITING
] = 0;
4571 signal_print
[TARGET_SIGNAL_WAITING
] = 0;
4572 signal_stop
[TARGET_SIGNAL_CANCEL
] = 0;
4573 signal_print
[TARGET_SIGNAL_CANCEL
] = 0;
4575 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support
,
4576 &stop_on_solib_events
, _("\
4577 Set stopping for shared library events."), _("\
4578 Show stopping for shared library events."), _("\
4579 If nonzero, gdb will give control to the user when the dynamic linker\n\
4580 notifies gdb of shared library events. The most common event of interest\n\
4581 to the user would be loading/unloading of a new library."),
4583 show_stop_on_solib_events
,
4584 &setlist
, &showlist
);
4586 add_setshow_enum_cmd ("follow-fork-mode", class_run
,
4587 follow_fork_mode_kind_names
,
4588 &follow_fork_mode_string
, _("\
4589 Set debugger response to a program call of fork or vfork."), _("\
4590 Show debugger response to a program call of fork or vfork."), _("\
4591 A fork or vfork creates a new process. follow-fork-mode can be:\n\
4592 parent - the original process is debugged after a fork\n\
4593 child - the new process is debugged after a fork\n\
4594 The unfollowed process will continue to run.\n\
4595 By default, the debugger will follow the parent process."),
4597 show_follow_fork_mode_string
,
4598 &setlist
, &showlist
);
4600 add_setshow_enum_cmd ("scheduler-locking", class_run
,
4601 scheduler_enums
, &scheduler_mode
, _("\
4602 Set mode for locking scheduler during execution."), _("\
4603 Show mode for locking scheduler during execution."), _("\
4604 off == no locking (threads may preempt at any time)\n\
4605 on == full locking (no thread except the current thread may run)\n\
4606 step == scheduler locked during every single-step operation.\n\
4607 In this mode, no other thread may run during a step command.\n\
4608 Other threads may run while stepping over a function call ('next')."),
4609 set_schedlock_func
, /* traps on target vector */
4610 show_scheduler_mode
,
4611 &setlist
, &showlist
);
4613 add_setshow_boolean_cmd ("step-mode", class_run
, &step_stop_if_no_debug
, _("\
4614 Set mode of the step operation."), _("\
4615 Show mode of the step operation."), _("\
4616 When set, doing a step over a function without debug line information\n\
4617 will stop at the first instruction of that function. Otherwise, the\n\
4618 function is skipped and the step command stops at a different source line."),
4620 show_step_stop_if_no_debug
,
4621 &setlist
, &showlist
);
4623 add_setshow_boolean_cmd ("can-use-displaced-stepping", class_maintenance
,
4624 &can_use_displaced_stepping
, _("\
4625 Set debugger's willingness to use displaced stepping."), _("\
4626 Show debugger's willingness to use displaced stepping."), _("\
4627 If zero, gdb will not use to use displaced stepping to step over\n\
4628 breakpoints, even if such is supported by the target."),
4630 show_can_use_displaced_stepping
,
4631 &maintenance_set_cmdlist
,
4632 &maintenance_show_cmdlist
);
4635 /* ptid initializations */
4636 null_ptid
= ptid_build (0, 0, 0);
4637 minus_one_ptid
= ptid_build (-1, 0, 0);
4638 inferior_ptid
= null_ptid
;
4639 target_last_wait_ptid
= minus_one_ptid
;
4640 displaced_step_ptid
= null_ptid
;