* dwarf2read.c (record_line_ftype): Remove, duplicate.
[deliverable/binutils-gdb.git] / gdb / infrun.c
... / ...
CommitLineData
1/* Target-struct-independent code to start (run) and stop an inferior
2 process.
3
4 Copyright (C) 1986-2015 Free Software Foundation, Inc.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21#include "defs.h"
22#include "infrun.h"
23#include <ctype.h>
24#include "symtab.h"
25#include "frame.h"
26#include "inferior.h"
27#include "breakpoint.h"
28#include "gdb_wait.h"
29#include "gdbcore.h"
30#include "gdbcmd.h"
31#include "cli/cli-script.h"
32#include "target.h"
33#include "gdbthread.h"
34#include "annotate.h"
35#include "symfile.h"
36#include "top.h"
37#include <signal.h>
38#include "inf-loop.h"
39#include "regcache.h"
40#include "value.h"
41#include "observer.h"
42#include "language.h"
43#include "solib.h"
44#include "main.h"
45#include "dictionary.h"
46#include "block.h"
47#include "mi/mi-common.h"
48#include "event-top.h"
49#include "record.h"
50#include "record-full.h"
51#include "inline-frame.h"
52#include "jit.h"
53#include "tracepoint.h"
54#include "continuations.h"
55#include "interps.h"
56#include "skip.h"
57#include "probe.h"
58#include "objfiles.h"
59#include "completer.h"
60#include "target-descriptions.h"
61#include "target-dcache.h"
62#include "terminal.h"
63#include "solist.h"
64
65/* Prototypes for local functions */
66
67static void signals_info (char *, int);
68
69static void handle_command (char *, int);
70
71static void sig_print_info (enum gdb_signal);
72
73static void sig_print_header (void);
74
75static void resume_cleanups (void *);
76
77static int hook_stop_stub (void *);
78
79static int restore_selected_frame (void *);
80
81static int follow_fork (void);
82
83static int follow_fork_inferior (int follow_child, int detach_fork);
84
85static void follow_inferior_reset_breakpoints (void);
86
87static void set_schedlock_func (char *args, int from_tty,
88 struct cmd_list_element *c);
89
90static int currently_stepping (struct thread_info *tp);
91
92void _initialize_infrun (void);
93
94void nullify_last_target_wait_ptid (void);
95
96static void insert_hp_step_resume_breakpoint_at_frame (struct frame_info *);
97
98static void insert_step_resume_breakpoint_at_caller (struct frame_info *);
99
100static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR);
101
102static int maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc);
103
104/* When set, stop the 'step' command if we enter a function which has
105 no line number information. The normal behavior is that we step
106 over such function. */
107int step_stop_if_no_debug = 0;
108static void
109show_step_stop_if_no_debug (struct ui_file *file, int from_tty,
110 struct cmd_list_element *c, const char *value)
111{
112 fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value);
113}
114
115/* In asynchronous mode, but simulating synchronous execution. */
116
117int sync_execution = 0;
118
119/* proceed and normal_stop use this to notify the user when the
120 inferior stopped in a different thread than it had been running
121 in. */
122
123static ptid_t previous_inferior_ptid;
124
125/* If set (default for legacy reasons), when following a fork, GDB
126 will detach from one of the fork branches, child or parent.
127 Exactly which branch is detached depends on 'set follow-fork-mode'
128 setting. */
129
130static int detach_fork = 1;
131
132int debug_displaced = 0;
133static void
134show_debug_displaced (struct ui_file *file, int from_tty,
135 struct cmd_list_element *c, const char *value)
136{
137 fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value);
138}
139
140unsigned int debug_infrun = 0;
141static void
142show_debug_infrun (struct ui_file *file, int from_tty,
143 struct cmd_list_element *c, const char *value)
144{
145 fprintf_filtered (file, _("Inferior debugging is %s.\n"), value);
146}
147
148
149/* Support for disabling address space randomization. */
150
151int disable_randomization = 1;
152
153static void
154show_disable_randomization (struct ui_file *file, int from_tty,
155 struct cmd_list_element *c, const char *value)
156{
157 if (target_supports_disable_randomization ())
158 fprintf_filtered (file,
159 _("Disabling randomization of debuggee's "
160 "virtual address space is %s.\n"),
161 value);
162 else
163 fputs_filtered (_("Disabling randomization of debuggee's "
164 "virtual address space is unsupported on\n"
165 "this platform.\n"), file);
166}
167
168static void
169set_disable_randomization (char *args, int from_tty,
170 struct cmd_list_element *c)
171{
172 if (!target_supports_disable_randomization ())
173 error (_("Disabling randomization of debuggee's "
174 "virtual address space is unsupported on\n"
175 "this platform."));
176}
177
178/* User interface for non-stop mode. */
179
180int non_stop = 0;
181static int non_stop_1 = 0;
182
183static void
184set_non_stop (char *args, int from_tty,
185 struct cmd_list_element *c)
186{
187 if (target_has_execution)
188 {
189 non_stop_1 = non_stop;
190 error (_("Cannot change this setting while the inferior is running."));
191 }
192
193 non_stop = non_stop_1;
194}
195
196static void
197show_non_stop (struct ui_file *file, int from_tty,
198 struct cmd_list_element *c, const char *value)
199{
200 fprintf_filtered (file,
201 _("Controlling the inferior in non-stop mode is %s.\n"),
202 value);
203}
204
205/* "Observer mode" is somewhat like a more extreme version of
206 non-stop, in which all GDB operations that might affect the
207 target's execution have been disabled. */
208
209int observer_mode = 0;
210static int observer_mode_1 = 0;
211
212static void
213set_observer_mode (char *args, int from_tty,
214 struct cmd_list_element *c)
215{
216 if (target_has_execution)
217 {
218 observer_mode_1 = observer_mode;
219 error (_("Cannot change this setting while the inferior is running."));
220 }
221
222 observer_mode = observer_mode_1;
223
224 may_write_registers = !observer_mode;
225 may_write_memory = !observer_mode;
226 may_insert_breakpoints = !observer_mode;
227 may_insert_tracepoints = !observer_mode;
228 /* We can insert fast tracepoints in or out of observer mode,
229 but enable them if we're going into this mode. */
230 if (observer_mode)
231 may_insert_fast_tracepoints = 1;
232 may_stop = !observer_mode;
233 update_target_permissions ();
234
235 /* Going *into* observer mode we must force non-stop, then
236 going out we leave it that way. */
237 if (observer_mode)
238 {
239 pagination_enabled = 0;
240 non_stop = non_stop_1 = 1;
241 }
242
243 if (from_tty)
244 printf_filtered (_("Observer mode is now %s.\n"),
245 (observer_mode ? "on" : "off"));
246}
247
248static void
249show_observer_mode (struct ui_file *file, int from_tty,
250 struct cmd_list_element *c, const char *value)
251{
252 fprintf_filtered (file, _("Observer mode is %s.\n"), value);
253}
254
255/* This updates the value of observer mode based on changes in
256 permissions. Note that we are deliberately ignoring the values of
257 may-write-registers and may-write-memory, since the user may have
258 reason to enable these during a session, for instance to turn on a
259 debugging-related global. */
260
261void
262update_observer_mode (void)
263{
264 int newval;
265
266 newval = (!may_insert_breakpoints
267 && !may_insert_tracepoints
268 && may_insert_fast_tracepoints
269 && !may_stop
270 && non_stop);
271
272 /* Let the user know if things change. */
273 if (newval != observer_mode)
274 printf_filtered (_("Observer mode is now %s.\n"),
275 (newval ? "on" : "off"));
276
277 observer_mode = observer_mode_1 = newval;
278}
279
280/* Tables of how to react to signals; the user sets them. */
281
282static unsigned char *signal_stop;
283static unsigned char *signal_print;
284static unsigned char *signal_program;
285
286/* Table of signals that are registered with "catch signal". A
287 non-zero entry indicates that the signal is caught by some "catch
288 signal" command. This has size GDB_SIGNAL_LAST, to accommodate all
289 signals. */
290static unsigned char *signal_catch;
291
292/* Table of signals that the target may silently handle.
293 This is automatically determined from the flags above,
294 and simply cached here. */
295static unsigned char *signal_pass;
296
297#define SET_SIGS(nsigs,sigs,flags) \
298 do { \
299 int signum = (nsigs); \
300 while (signum-- > 0) \
301 if ((sigs)[signum]) \
302 (flags)[signum] = 1; \
303 } while (0)
304
305#define UNSET_SIGS(nsigs,sigs,flags) \
306 do { \
307 int signum = (nsigs); \
308 while (signum-- > 0) \
309 if ((sigs)[signum]) \
310 (flags)[signum] = 0; \
311 } while (0)
312
313/* Update the target's copy of SIGNAL_PROGRAM. The sole purpose of
314 this function is to avoid exporting `signal_program'. */
315
316void
317update_signals_program_target (void)
318{
319 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
320}
321
322/* Value to pass to target_resume() to cause all threads to resume. */
323
324#define RESUME_ALL minus_one_ptid
325
326/* Command list pointer for the "stop" placeholder. */
327
328static struct cmd_list_element *stop_command;
329
330/* Nonzero if we want to give control to the user when we're notified
331 of shared library events by the dynamic linker. */
332int stop_on_solib_events;
333
334/* Enable or disable optional shared library event breakpoints
335 as appropriate when the above flag is changed. */
336
337static void
338set_stop_on_solib_events (char *args, int from_tty, struct cmd_list_element *c)
339{
340 update_solib_breakpoints ();
341}
342
343static void
344show_stop_on_solib_events (struct ui_file *file, int from_tty,
345 struct cmd_list_element *c, const char *value)
346{
347 fprintf_filtered (file, _("Stopping for shared library events is %s.\n"),
348 value);
349}
350
351/* Nonzero means expecting a trace trap
352 and should stop the inferior and return silently when it happens. */
353
354int stop_after_trap;
355
356/* Nonzero after stop if current stack frame should be printed. */
357
358static int stop_print_frame;
359
360/* This is a cached copy of the pid/waitstatus of the last event
361 returned by target_wait()/deprecated_target_wait_hook(). This
362 information is returned by get_last_target_status(). */
363static ptid_t target_last_wait_ptid;
364static struct target_waitstatus target_last_waitstatus;
365
366static void context_switch (ptid_t ptid);
367
368void init_thread_stepping_state (struct thread_info *tss);
369
370static const char follow_fork_mode_child[] = "child";
371static const char follow_fork_mode_parent[] = "parent";
372
373static const char *const follow_fork_mode_kind_names[] = {
374 follow_fork_mode_child,
375 follow_fork_mode_parent,
376 NULL
377};
378
379static const char *follow_fork_mode_string = follow_fork_mode_parent;
380static void
381show_follow_fork_mode_string (struct ui_file *file, int from_tty,
382 struct cmd_list_element *c, const char *value)
383{
384 fprintf_filtered (file,
385 _("Debugger response to a program "
386 "call of fork or vfork is \"%s\".\n"),
387 value);
388}
389\f
390
391/* Handle changes to the inferior list based on the type of fork,
392 which process is being followed, and whether the other process
393 should be detached. On entry inferior_ptid must be the ptid of
394 the fork parent. At return inferior_ptid is the ptid of the
395 followed inferior. */
396
397static int
398follow_fork_inferior (int follow_child, int detach_fork)
399{
400 int has_vforked;
401 ptid_t parent_ptid, child_ptid;
402
403 has_vforked = (inferior_thread ()->pending_follow.kind
404 == TARGET_WAITKIND_VFORKED);
405 parent_ptid = inferior_ptid;
406 child_ptid = inferior_thread ()->pending_follow.value.related_pid;
407
408 if (has_vforked
409 && !non_stop /* Non-stop always resumes both branches. */
410 && (!target_is_async_p () || sync_execution)
411 && !(follow_child || detach_fork || sched_multi))
412 {
413 /* The parent stays blocked inside the vfork syscall until the
414 child execs or exits. If we don't let the child run, then
415 the parent stays blocked. If we're telling the parent to run
416 in the foreground, the user will not be able to ctrl-c to get
417 back the terminal, effectively hanging the debug session. */
418 fprintf_filtered (gdb_stderr, _("\
419Can not resume the parent process over vfork in the foreground while\n\
420holding the child stopped. Try \"set detach-on-fork\" or \
421\"set schedule-multiple\".\n"));
422 /* FIXME output string > 80 columns. */
423 return 1;
424 }
425
426 if (!follow_child)
427 {
428 /* Detach new forked process? */
429 if (detach_fork)
430 {
431 struct cleanup *old_chain;
432
433 /* Before detaching from the child, remove all breakpoints
434 from it. If we forked, then this has already been taken
435 care of by infrun.c. If we vforked however, any
436 breakpoint inserted in the parent is visible in the
437 child, even those added while stopped in a vfork
438 catchpoint. This will remove the breakpoints from the
439 parent also, but they'll be reinserted below. */
440 if (has_vforked)
441 {
442 /* Keep breakpoints list in sync. */
443 remove_breakpoints_pid (ptid_get_pid (inferior_ptid));
444 }
445
446 if (info_verbose || debug_infrun)
447 {
448 target_terminal_ours_for_output ();
449 fprintf_filtered (gdb_stdlog,
450 _("Detaching after %s from child %s.\n"),
451 has_vforked ? "vfork" : "fork",
452 target_pid_to_str (child_ptid));
453 }
454 }
455 else
456 {
457 struct inferior *parent_inf, *child_inf;
458 struct cleanup *old_chain;
459
460 /* Add process to GDB's tables. */
461 child_inf = add_inferior (ptid_get_pid (child_ptid));
462
463 parent_inf = current_inferior ();
464 child_inf->attach_flag = parent_inf->attach_flag;
465 copy_terminal_info (child_inf, parent_inf);
466 child_inf->gdbarch = parent_inf->gdbarch;
467 copy_inferior_target_desc_info (child_inf, parent_inf);
468
469 old_chain = save_inferior_ptid ();
470 save_current_program_space ();
471
472 inferior_ptid = child_ptid;
473 add_thread (inferior_ptid);
474 child_inf->symfile_flags = SYMFILE_NO_READ;
475
476 /* If this is a vfork child, then the address-space is
477 shared with the parent. */
478 if (has_vforked)
479 {
480 child_inf->pspace = parent_inf->pspace;
481 child_inf->aspace = parent_inf->aspace;
482
483 /* The parent will be frozen until the child is done
484 with the shared region. Keep track of the
485 parent. */
486 child_inf->vfork_parent = parent_inf;
487 child_inf->pending_detach = 0;
488 parent_inf->vfork_child = child_inf;
489 parent_inf->pending_detach = 0;
490 }
491 else
492 {
493 child_inf->aspace = new_address_space ();
494 child_inf->pspace = add_program_space (child_inf->aspace);
495 child_inf->removable = 1;
496 set_current_program_space (child_inf->pspace);
497 clone_program_space (child_inf->pspace, parent_inf->pspace);
498
499 /* Let the shared library layer (e.g., solib-svr4) learn
500 about this new process, relocate the cloned exec, pull
501 in shared libraries, and install the solib event
502 breakpoint. If a "cloned-VM" event was propagated
503 better throughout the core, this wouldn't be
504 required. */
505 solib_create_inferior_hook (0);
506 }
507
508 do_cleanups (old_chain);
509 }
510
511 if (has_vforked)
512 {
513 struct inferior *parent_inf;
514
515 parent_inf = current_inferior ();
516
517 /* If we detached from the child, then we have to be careful
518 to not insert breakpoints in the parent until the child
519 is done with the shared memory region. However, if we're
520 staying attached to the child, then we can and should
521 insert breakpoints, so that we can debug it. A
522 subsequent child exec or exit is enough to know when does
523 the child stops using the parent's address space. */
524 parent_inf->waiting_for_vfork_done = detach_fork;
525 parent_inf->pspace->breakpoints_not_allowed = detach_fork;
526 }
527 }
528 else
529 {
530 /* Follow the child. */
531 struct inferior *parent_inf, *child_inf;
532 struct program_space *parent_pspace;
533
534 if (info_verbose || debug_infrun)
535 {
536 target_terminal_ours_for_output ();
537 fprintf_filtered (gdb_stdlog,
538 _("Attaching after %s %s to child %s.\n"),
539 target_pid_to_str (parent_ptid),
540 has_vforked ? "vfork" : "fork",
541 target_pid_to_str (child_ptid));
542 }
543
544 /* Add the new inferior first, so that the target_detach below
545 doesn't unpush the target. */
546
547 child_inf = add_inferior (ptid_get_pid (child_ptid));
548
549 parent_inf = current_inferior ();
550 child_inf->attach_flag = parent_inf->attach_flag;
551 copy_terminal_info (child_inf, parent_inf);
552 child_inf->gdbarch = parent_inf->gdbarch;
553 copy_inferior_target_desc_info (child_inf, parent_inf);
554
555 parent_pspace = parent_inf->pspace;
556
557 /* If we're vforking, we want to hold on to the parent until the
558 child exits or execs. At child exec or exit time we can
559 remove the old breakpoints from the parent and detach or
560 resume debugging it. Otherwise, detach the parent now; we'll
561 want to reuse it's program/address spaces, but we can't set
562 them to the child before removing breakpoints from the
563 parent, otherwise, the breakpoints module could decide to
564 remove breakpoints from the wrong process (since they'd be
565 assigned to the same address space). */
566
567 if (has_vforked)
568 {
569 gdb_assert (child_inf->vfork_parent == NULL);
570 gdb_assert (parent_inf->vfork_child == NULL);
571 child_inf->vfork_parent = parent_inf;
572 child_inf->pending_detach = 0;
573 parent_inf->vfork_child = child_inf;
574 parent_inf->pending_detach = detach_fork;
575 parent_inf->waiting_for_vfork_done = 0;
576 }
577 else if (detach_fork)
578 {
579 if (info_verbose || debug_infrun)
580 {
581 target_terminal_ours_for_output ();
582 fprintf_filtered (gdb_stdlog,
583 _("Detaching after fork from "
584 "child %s.\n"),
585 target_pid_to_str (child_ptid));
586 }
587
588 target_detach (NULL, 0);
589 }
590
591 /* Note that the detach above makes PARENT_INF dangling. */
592
593 /* Add the child thread to the appropriate lists, and switch to
594 this new thread, before cloning the program space, and
595 informing the solib layer about this new process. */
596
597 inferior_ptid = child_ptid;
598 add_thread (inferior_ptid);
599
600 /* If this is a vfork child, then the address-space is shared
601 with the parent. If we detached from the parent, then we can
602 reuse the parent's program/address spaces. */
603 if (has_vforked || detach_fork)
604 {
605 child_inf->pspace = parent_pspace;
606 child_inf->aspace = child_inf->pspace->aspace;
607 }
608 else
609 {
610 child_inf->aspace = new_address_space ();
611 child_inf->pspace = add_program_space (child_inf->aspace);
612 child_inf->removable = 1;
613 child_inf->symfile_flags = SYMFILE_NO_READ;
614 set_current_program_space (child_inf->pspace);
615 clone_program_space (child_inf->pspace, parent_pspace);
616
617 /* Let the shared library layer (e.g., solib-svr4) learn
618 about this new process, relocate the cloned exec, pull in
619 shared libraries, and install the solib event breakpoint.
620 If a "cloned-VM" event was propagated better throughout
621 the core, this wouldn't be required. */
622 solib_create_inferior_hook (0);
623 }
624 }
625
626 return target_follow_fork (follow_child, detach_fork);
627}
628
629/* Tell the target to follow the fork we're stopped at. Returns true
630 if the inferior should be resumed; false, if the target for some
631 reason decided it's best not to resume. */
632
633static int
634follow_fork (void)
635{
636 int follow_child = (follow_fork_mode_string == follow_fork_mode_child);
637 int should_resume = 1;
638 struct thread_info *tp;
639
640 /* Copy user stepping state to the new inferior thread. FIXME: the
641 followed fork child thread should have a copy of most of the
642 parent thread structure's run control related fields, not just these.
643 Initialized to avoid "may be used uninitialized" warnings from gcc. */
644 struct breakpoint *step_resume_breakpoint = NULL;
645 struct breakpoint *exception_resume_breakpoint = NULL;
646 CORE_ADDR step_range_start = 0;
647 CORE_ADDR step_range_end = 0;
648 struct frame_id step_frame_id = { 0 };
649 struct interp *command_interp = NULL;
650
651 if (!non_stop)
652 {
653 ptid_t wait_ptid;
654 struct target_waitstatus wait_status;
655
656 /* Get the last target status returned by target_wait(). */
657 get_last_target_status (&wait_ptid, &wait_status);
658
659 /* If not stopped at a fork event, then there's nothing else to
660 do. */
661 if (wait_status.kind != TARGET_WAITKIND_FORKED
662 && wait_status.kind != TARGET_WAITKIND_VFORKED)
663 return 1;
664
665 /* Check if we switched over from WAIT_PTID, since the event was
666 reported. */
667 if (!ptid_equal (wait_ptid, minus_one_ptid)
668 && !ptid_equal (inferior_ptid, wait_ptid))
669 {
670 /* We did. Switch back to WAIT_PTID thread, to tell the
671 target to follow it (in either direction). We'll
672 afterwards refuse to resume, and inform the user what
673 happened. */
674 switch_to_thread (wait_ptid);
675 should_resume = 0;
676 }
677 }
678
679 tp = inferior_thread ();
680
681 /* If there were any forks/vforks that were caught and are now to be
682 followed, then do so now. */
683 switch (tp->pending_follow.kind)
684 {
685 case TARGET_WAITKIND_FORKED:
686 case TARGET_WAITKIND_VFORKED:
687 {
688 ptid_t parent, child;
689
690 /* If the user did a next/step, etc, over a fork call,
691 preserve the stepping state in the fork child. */
692 if (follow_child && should_resume)
693 {
694 step_resume_breakpoint = clone_momentary_breakpoint
695 (tp->control.step_resume_breakpoint);
696 step_range_start = tp->control.step_range_start;
697 step_range_end = tp->control.step_range_end;
698 step_frame_id = tp->control.step_frame_id;
699 exception_resume_breakpoint
700 = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint);
701 command_interp = tp->control.command_interp;
702
703 /* For now, delete the parent's sr breakpoint, otherwise,
704 parent/child sr breakpoints are considered duplicates,
705 and the child version will not be installed. Remove
706 this when the breakpoints module becomes aware of
707 inferiors and address spaces. */
708 delete_step_resume_breakpoint (tp);
709 tp->control.step_range_start = 0;
710 tp->control.step_range_end = 0;
711 tp->control.step_frame_id = null_frame_id;
712 delete_exception_resume_breakpoint (tp);
713 tp->control.command_interp = NULL;
714 }
715
716 parent = inferior_ptid;
717 child = tp->pending_follow.value.related_pid;
718
719 /* Set up inferior(s) as specified by the caller, and tell the
720 target to do whatever is necessary to follow either parent
721 or child. */
722 if (follow_fork_inferior (follow_child, detach_fork))
723 {
724 /* Target refused to follow, or there's some other reason
725 we shouldn't resume. */
726 should_resume = 0;
727 }
728 else
729 {
730 /* This pending follow fork event is now handled, one way
731 or another. The previous selected thread may be gone
732 from the lists by now, but if it is still around, need
733 to clear the pending follow request. */
734 tp = find_thread_ptid (parent);
735 if (tp)
736 tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS;
737
738 /* This makes sure we don't try to apply the "Switched
739 over from WAIT_PID" logic above. */
740 nullify_last_target_wait_ptid ();
741
742 /* If we followed the child, switch to it... */
743 if (follow_child)
744 {
745 switch_to_thread (child);
746
747 /* ... and preserve the stepping state, in case the
748 user was stepping over the fork call. */
749 if (should_resume)
750 {
751 tp = inferior_thread ();
752 tp->control.step_resume_breakpoint
753 = step_resume_breakpoint;
754 tp->control.step_range_start = step_range_start;
755 tp->control.step_range_end = step_range_end;
756 tp->control.step_frame_id = step_frame_id;
757 tp->control.exception_resume_breakpoint
758 = exception_resume_breakpoint;
759 tp->control.command_interp = command_interp;
760 }
761 else
762 {
763 /* If we get here, it was because we're trying to
764 resume from a fork catchpoint, but, the user
765 has switched threads away from the thread that
766 forked. In that case, the resume command
767 issued is most likely not applicable to the
768 child, so just warn, and refuse to resume. */
769 warning (_("Not resuming: switched threads "
770 "before following fork child.\n"));
771 }
772
773 /* Reset breakpoints in the child as appropriate. */
774 follow_inferior_reset_breakpoints ();
775 }
776 else
777 switch_to_thread (parent);
778 }
779 }
780 break;
781 case TARGET_WAITKIND_SPURIOUS:
782 /* Nothing to follow. */
783 break;
784 default:
785 internal_error (__FILE__, __LINE__,
786 "Unexpected pending_follow.kind %d\n",
787 tp->pending_follow.kind);
788 break;
789 }
790
791 return should_resume;
792}
793
794static void
795follow_inferior_reset_breakpoints (void)
796{
797 struct thread_info *tp = inferior_thread ();
798
799 /* Was there a step_resume breakpoint? (There was if the user
800 did a "next" at the fork() call.) If so, explicitly reset its
801 thread number. Cloned step_resume breakpoints are disabled on
802 creation, so enable it here now that it is associated with the
803 correct thread.
804
805 step_resumes are a form of bp that are made to be per-thread.
806 Since we created the step_resume bp when the parent process
807 was being debugged, and now are switching to the child process,
808 from the breakpoint package's viewpoint, that's a switch of
809 "threads". We must update the bp's notion of which thread
810 it is for, or it'll be ignored when it triggers. */
811
812 if (tp->control.step_resume_breakpoint)
813 {
814 breakpoint_re_set_thread (tp->control.step_resume_breakpoint);
815 tp->control.step_resume_breakpoint->loc->enabled = 1;
816 }
817
818 /* Treat exception_resume breakpoints like step_resume breakpoints. */
819 if (tp->control.exception_resume_breakpoint)
820 {
821 breakpoint_re_set_thread (tp->control.exception_resume_breakpoint);
822 tp->control.exception_resume_breakpoint->loc->enabled = 1;
823 }
824
825 /* Reinsert all breakpoints in the child. The user may have set
826 breakpoints after catching the fork, in which case those
827 were never set in the child, but only in the parent. This makes
828 sure the inserted breakpoints match the breakpoint list. */
829
830 breakpoint_re_set ();
831 insert_breakpoints ();
832}
833
834/* The child has exited or execed: resume threads of the parent the
835 user wanted to be executing. */
836
837static int
838proceed_after_vfork_done (struct thread_info *thread,
839 void *arg)
840{
841 int pid = * (int *) arg;
842
843 if (ptid_get_pid (thread->ptid) == pid
844 && is_running (thread->ptid)
845 && !is_executing (thread->ptid)
846 && !thread->stop_requested
847 && thread->suspend.stop_signal == GDB_SIGNAL_0)
848 {
849 if (debug_infrun)
850 fprintf_unfiltered (gdb_stdlog,
851 "infrun: resuming vfork parent thread %s\n",
852 target_pid_to_str (thread->ptid));
853
854 switch_to_thread (thread->ptid);
855 clear_proceed_status (0);
856 proceed ((CORE_ADDR) -1, GDB_SIGNAL_DEFAULT);
857 }
858
859 return 0;
860}
861
862/* Called whenever we notice an exec or exit event, to handle
863 detaching or resuming a vfork parent. */
864
865static void
866handle_vfork_child_exec_or_exit (int exec)
867{
868 struct inferior *inf = current_inferior ();
869
870 if (inf->vfork_parent)
871 {
872 int resume_parent = -1;
873
874 /* This exec or exit marks the end of the shared memory region
875 between the parent and the child. If the user wanted to
876 detach from the parent, now is the time. */
877
878 if (inf->vfork_parent->pending_detach)
879 {
880 struct thread_info *tp;
881 struct cleanup *old_chain;
882 struct program_space *pspace;
883 struct address_space *aspace;
884
885 /* follow-fork child, detach-on-fork on. */
886
887 inf->vfork_parent->pending_detach = 0;
888
889 if (!exec)
890 {
891 /* If we're handling a child exit, then inferior_ptid
892 points at the inferior's pid, not to a thread. */
893 old_chain = save_inferior_ptid ();
894 save_current_program_space ();
895 save_current_inferior ();
896 }
897 else
898 old_chain = save_current_space_and_thread ();
899
900 /* We're letting loose of the parent. */
901 tp = any_live_thread_of_process (inf->vfork_parent->pid);
902 switch_to_thread (tp->ptid);
903
904 /* We're about to detach from the parent, which implicitly
905 removes breakpoints from its address space. There's a
906 catch here: we want to reuse the spaces for the child,
907 but, parent/child are still sharing the pspace at this
908 point, although the exec in reality makes the kernel give
909 the child a fresh set of new pages. The problem here is
910 that the breakpoints module being unaware of this, would
911 likely chose the child process to write to the parent
912 address space. Swapping the child temporarily away from
913 the spaces has the desired effect. Yes, this is "sort
914 of" a hack. */
915
916 pspace = inf->pspace;
917 aspace = inf->aspace;
918 inf->aspace = NULL;
919 inf->pspace = NULL;
920
921 if (debug_infrun || info_verbose)
922 {
923 target_terminal_ours_for_output ();
924
925 if (exec)
926 {
927 fprintf_filtered (gdb_stdlog,
928 _("Detaching vfork parent process "
929 "%d after child exec.\n"),
930 inf->vfork_parent->pid);
931 }
932 else
933 {
934 fprintf_filtered (gdb_stdlog,
935 _("Detaching vfork parent process "
936 "%d after child exit.\n"),
937 inf->vfork_parent->pid);
938 }
939 }
940
941 target_detach (NULL, 0);
942
943 /* Put it back. */
944 inf->pspace = pspace;
945 inf->aspace = aspace;
946
947 do_cleanups (old_chain);
948 }
949 else if (exec)
950 {
951 /* We're staying attached to the parent, so, really give the
952 child a new address space. */
953 inf->pspace = add_program_space (maybe_new_address_space ());
954 inf->aspace = inf->pspace->aspace;
955 inf->removable = 1;
956 set_current_program_space (inf->pspace);
957
958 resume_parent = inf->vfork_parent->pid;
959
960 /* Break the bonds. */
961 inf->vfork_parent->vfork_child = NULL;
962 }
963 else
964 {
965 struct cleanup *old_chain;
966 struct program_space *pspace;
967
968 /* If this is a vfork child exiting, then the pspace and
969 aspaces were shared with the parent. Since we're
970 reporting the process exit, we'll be mourning all that is
971 found in the address space, and switching to null_ptid,
972 preparing to start a new inferior. But, since we don't
973 want to clobber the parent's address/program spaces, we
974 go ahead and create a new one for this exiting
975 inferior. */
976
977 /* Switch to null_ptid, so that clone_program_space doesn't want
978 to read the selected frame of a dead process. */
979 old_chain = save_inferior_ptid ();
980 inferior_ptid = null_ptid;
981
982 /* This inferior is dead, so avoid giving the breakpoints
983 module the option to write through to it (cloning a
984 program space resets breakpoints). */
985 inf->aspace = NULL;
986 inf->pspace = NULL;
987 pspace = add_program_space (maybe_new_address_space ());
988 set_current_program_space (pspace);
989 inf->removable = 1;
990 inf->symfile_flags = SYMFILE_NO_READ;
991 clone_program_space (pspace, inf->vfork_parent->pspace);
992 inf->pspace = pspace;
993 inf->aspace = pspace->aspace;
994
995 /* Put back inferior_ptid. We'll continue mourning this
996 inferior. */
997 do_cleanups (old_chain);
998
999 resume_parent = inf->vfork_parent->pid;
1000 /* Break the bonds. */
1001 inf->vfork_parent->vfork_child = NULL;
1002 }
1003
1004 inf->vfork_parent = NULL;
1005
1006 gdb_assert (current_program_space == inf->pspace);
1007
1008 if (non_stop && resume_parent != -1)
1009 {
1010 /* If the user wanted the parent to be running, let it go
1011 free now. */
1012 struct cleanup *old_chain = make_cleanup_restore_current_thread ();
1013
1014 if (debug_infrun)
1015 fprintf_unfiltered (gdb_stdlog,
1016 "infrun: resuming vfork parent process %d\n",
1017 resume_parent);
1018
1019 iterate_over_threads (proceed_after_vfork_done, &resume_parent);
1020
1021 do_cleanups (old_chain);
1022 }
1023 }
1024}
1025
1026/* Enum strings for "set|show follow-exec-mode". */
1027
1028static const char follow_exec_mode_new[] = "new";
1029static const char follow_exec_mode_same[] = "same";
1030static const char *const follow_exec_mode_names[] =
1031{
1032 follow_exec_mode_new,
1033 follow_exec_mode_same,
1034 NULL,
1035};
1036
1037static const char *follow_exec_mode_string = follow_exec_mode_same;
1038static void
1039show_follow_exec_mode_string (struct ui_file *file, int from_tty,
1040 struct cmd_list_element *c, const char *value)
1041{
1042 fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value);
1043}
1044
1045/* EXECD_PATHNAME is assumed to be non-NULL. */
1046
1047static void
1048follow_exec (ptid_t ptid, char *execd_pathname)
1049{
1050 struct thread_info *th, *tmp;
1051 struct inferior *inf = current_inferior ();
1052 int pid = ptid_get_pid (ptid);
1053
1054 /* This is an exec event that we actually wish to pay attention to.
1055 Refresh our symbol table to the newly exec'd program, remove any
1056 momentary bp's, etc.
1057
1058 If there are breakpoints, they aren't really inserted now,
1059 since the exec() transformed our inferior into a fresh set
1060 of instructions.
1061
1062 We want to preserve symbolic breakpoints on the list, since
1063 we have hopes that they can be reset after the new a.out's
1064 symbol table is read.
1065
1066 However, any "raw" breakpoints must be removed from the list
1067 (e.g., the solib bp's), since their address is probably invalid
1068 now.
1069
1070 And, we DON'T want to call delete_breakpoints() here, since
1071 that may write the bp's "shadow contents" (the instruction
1072 value that was overwritten witha TRAP instruction). Since
1073 we now have a new a.out, those shadow contents aren't valid. */
1074
1075 mark_breakpoints_out ();
1076
1077 /* The target reports the exec event to the main thread, even if
1078 some other thread does the exec, and even if the main thread was
1079 stopped or already gone. We may still have non-leader threads of
1080 the process on our list. E.g., on targets that don't have thread
1081 exit events (like remote); or on native Linux in non-stop mode if
1082 there were only two threads in the inferior and the non-leader
1083 one is the one that execs (and nothing forces an update of the
1084 thread list up to here). When debugging remotely, it's best to
1085 avoid extra traffic, when possible, so avoid syncing the thread
1086 list with the target, and instead go ahead and delete all threads
1087 of the process but one that reported the event. Note this must
1088 be done before calling update_breakpoints_after_exec, as
1089 otherwise clearing the threads' resources would reference stale
1090 thread breakpoints -- it may have been one of these threads that
1091 stepped across the exec. We could just clear their stepping
1092 states, but as long as we're iterating, might as well delete
1093 them. Deleting them now rather than at the next user-visible
1094 stop provides a nicer sequence of events for user and MI
1095 notifications. */
1096 ALL_THREADS_SAFE (th, tmp)
1097 if (ptid_get_pid (th->ptid) == pid && !ptid_equal (th->ptid, ptid))
1098 delete_thread (th->ptid);
1099
1100 /* We also need to clear any left over stale state for the
1101 leader/event thread. E.g., if there was any step-resume
1102 breakpoint or similar, it's gone now. We cannot truly
1103 step-to-next statement through an exec(). */
1104 th = inferior_thread ();
1105 th->control.step_resume_breakpoint = NULL;
1106 th->control.exception_resume_breakpoint = NULL;
1107 th->control.single_step_breakpoints = NULL;
1108 th->control.step_range_start = 0;
1109 th->control.step_range_end = 0;
1110
1111 /* The user may have had the main thread held stopped in the
1112 previous image (e.g., schedlock on, or non-stop). Release
1113 it now. */
1114 th->stop_requested = 0;
1115
1116 update_breakpoints_after_exec ();
1117
1118 /* What is this a.out's name? */
1119 printf_unfiltered (_("%s is executing new program: %s\n"),
1120 target_pid_to_str (inferior_ptid),
1121 execd_pathname);
1122
1123 /* We've followed the inferior through an exec. Therefore, the
1124 inferior has essentially been killed & reborn. */
1125
1126 gdb_flush (gdb_stdout);
1127
1128 breakpoint_init_inferior (inf_execd);
1129
1130 if (gdb_sysroot != NULL && *gdb_sysroot != '\0')
1131 {
1132 char *name = exec_file_find (execd_pathname, NULL);
1133
1134 execd_pathname = alloca (strlen (name) + 1);
1135 strcpy (execd_pathname, name);
1136 xfree (name);
1137 }
1138
1139 /* Reset the shared library package. This ensures that we get a
1140 shlib event when the child reaches "_start", at which point the
1141 dld will have had a chance to initialize the child. */
1142 /* Also, loading a symbol file below may trigger symbol lookups, and
1143 we don't want those to be satisfied by the libraries of the
1144 previous incarnation of this process. */
1145 no_shared_libraries (NULL, 0);
1146
1147 if (follow_exec_mode_string == follow_exec_mode_new)
1148 {
1149 struct program_space *pspace;
1150
1151 /* The user wants to keep the old inferior and program spaces
1152 around. Create a new fresh one, and switch to it. */
1153
1154 inf = add_inferior (current_inferior ()->pid);
1155 pspace = add_program_space (maybe_new_address_space ());
1156 inf->pspace = pspace;
1157 inf->aspace = pspace->aspace;
1158
1159 exit_inferior_num_silent (current_inferior ()->num);
1160
1161 set_current_inferior (inf);
1162 set_current_program_space (pspace);
1163 }
1164 else
1165 {
1166 /* The old description may no longer be fit for the new image.
1167 E.g, a 64-bit process exec'ed a 32-bit process. Clear the
1168 old description; we'll read a new one below. No need to do
1169 this on "follow-exec-mode new", as the old inferior stays
1170 around (its description is later cleared/refetched on
1171 restart). */
1172 target_clear_description ();
1173 }
1174
1175 gdb_assert (current_program_space == inf->pspace);
1176
1177 /* That a.out is now the one to use. */
1178 exec_file_attach (execd_pathname, 0);
1179
1180 /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE
1181 (Position Independent Executable) main symbol file will get applied by
1182 solib_create_inferior_hook below. breakpoint_re_set would fail to insert
1183 the breakpoints with the zero displacement. */
1184
1185 symbol_file_add (execd_pathname,
1186 (inf->symfile_flags
1187 | SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET),
1188 NULL, 0);
1189
1190 if ((inf->symfile_flags & SYMFILE_NO_READ) == 0)
1191 set_initial_language ();
1192
1193 /* If the target can specify a description, read it. Must do this
1194 after flipping to the new executable (because the target supplied
1195 description must be compatible with the executable's
1196 architecture, and the old executable may e.g., be 32-bit, while
1197 the new one 64-bit), and before anything involving memory or
1198 registers. */
1199 target_find_description ();
1200
1201 solib_create_inferior_hook (0);
1202
1203 jit_inferior_created_hook ();
1204
1205 breakpoint_re_set ();
1206
1207 /* Reinsert all breakpoints. (Those which were symbolic have
1208 been reset to the proper address in the new a.out, thanks
1209 to symbol_file_command...). */
1210 insert_breakpoints ();
1211
1212 /* The next resume of this inferior should bring it to the shlib
1213 startup breakpoints. (If the user had also set bp's on
1214 "main" from the old (parent) process, then they'll auto-
1215 matically get reset there in the new process.). */
1216}
1217
1218/* Info about an instruction that is being stepped over. */
1219
1220struct step_over_info
1221{
1222 /* If we're stepping past a breakpoint, this is the address space
1223 and address of the instruction the breakpoint is set at. We'll
1224 skip inserting all breakpoints here. Valid iff ASPACE is
1225 non-NULL. */
1226 struct address_space *aspace;
1227 CORE_ADDR address;
1228
1229 /* The instruction being stepped over triggers a nonsteppable
1230 watchpoint. If true, we'll skip inserting watchpoints. */
1231 int nonsteppable_watchpoint_p;
1232};
1233
1234/* The step-over info of the location that is being stepped over.
1235
1236 Note that with async/breakpoint always-inserted mode, a user might
1237 set a new breakpoint/watchpoint/etc. exactly while a breakpoint is
1238 being stepped over. As setting a new breakpoint inserts all
1239 breakpoints, we need to make sure the breakpoint being stepped over
1240 isn't inserted then. We do that by only clearing the step-over
1241 info when the step-over is actually finished (or aborted).
1242
1243 Presently GDB can only step over one breakpoint at any given time.
1244 Given threads that can't run code in the same address space as the
1245 breakpoint's can't really miss the breakpoint, GDB could be taught
1246 to step-over at most one breakpoint per address space (so this info
1247 could move to the address space object if/when GDB is extended).
1248 The set of breakpoints being stepped over will normally be much
1249 smaller than the set of all breakpoints, so a flag in the
1250 breakpoint location structure would be wasteful. A separate list
1251 also saves complexity and run-time, as otherwise we'd have to go
1252 through all breakpoint locations clearing their flag whenever we
1253 start a new sequence. Similar considerations weigh against storing
1254 this info in the thread object. Plus, not all step overs actually
1255 have breakpoint locations -- e.g., stepping past a single-step
1256 breakpoint, or stepping to complete a non-continuable
1257 watchpoint. */
1258static struct step_over_info step_over_info;
1259
1260/* Record the address of the breakpoint/instruction we're currently
1261 stepping over. */
1262
1263static void
1264set_step_over_info (struct address_space *aspace, CORE_ADDR address,
1265 int nonsteppable_watchpoint_p)
1266{
1267 step_over_info.aspace = aspace;
1268 step_over_info.address = address;
1269 step_over_info.nonsteppable_watchpoint_p = nonsteppable_watchpoint_p;
1270}
1271
1272/* Called when we're not longer stepping over a breakpoint / an
1273 instruction, so all breakpoints are free to be (re)inserted. */
1274
1275static void
1276clear_step_over_info (void)
1277{
1278 step_over_info.aspace = NULL;
1279 step_over_info.address = 0;
1280 step_over_info.nonsteppable_watchpoint_p = 0;
1281}
1282
1283/* See infrun.h. */
1284
1285int
1286stepping_past_instruction_at (struct address_space *aspace,
1287 CORE_ADDR address)
1288{
1289 return (step_over_info.aspace != NULL
1290 && breakpoint_address_match (aspace, address,
1291 step_over_info.aspace,
1292 step_over_info.address));
1293}
1294
1295/* See infrun.h. */
1296
1297int
1298stepping_past_nonsteppable_watchpoint (void)
1299{
1300 return step_over_info.nonsteppable_watchpoint_p;
1301}
1302
1303/* Returns true if step-over info is valid. */
1304
1305static int
1306step_over_info_valid_p (void)
1307{
1308 return (step_over_info.aspace != NULL
1309 || stepping_past_nonsteppable_watchpoint ());
1310}
1311
1312\f
1313/* Displaced stepping. */
1314
1315/* In non-stop debugging mode, we must take special care to manage
1316 breakpoints properly; in particular, the traditional strategy for
1317 stepping a thread past a breakpoint it has hit is unsuitable.
1318 'Displaced stepping' is a tactic for stepping one thread past a
1319 breakpoint it has hit while ensuring that other threads running
1320 concurrently will hit the breakpoint as they should.
1321
1322 The traditional way to step a thread T off a breakpoint in a
1323 multi-threaded program in all-stop mode is as follows:
1324
1325 a0) Initially, all threads are stopped, and breakpoints are not
1326 inserted.
1327 a1) We single-step T, leaving breakpoints uninserted.
1328 a2) We insert breakpoints, and resume all threads.
1329
1330 In non-stop debugging, however, this strategy is unsuitable: we
1331 don't want to have to stop all threads in the system in order to
1332 continue or step T past a breakpoint. Instead, we use displaced
1333 stepping:
1334
1335 n0) Initially, T is stopped, other threads are running, and
1336 breakpoints are inserted.
1337 n1) We copy the instruction "under" the breakpoint to a separate
1338 location, outside the main code stream, making any adjustments
1339 to the instruction, register, and memory state as directed by
1340 T's architecture.
1341 n2) We single-step T over the instruction at its new location.
1342 n3) We adjust the resulting register and memory state as directed
1343 by T's architecture. This includes resetting T's PC to point
1344 back into the main instruction stream.
1345 n4) We resume T.
1346
1347 This approach depends on the following gdbarch methods:
1348
1349 - gdbarch_max_insn_length and gdbarch_displaced_step_location
1350 indicate where to copy the instruction, and how much space must
1351 be reserved there. We use these in step n1.
1352
1353 - gdbarch_displaced_step_copy_insn copies a instruction to a new
1354 address, and makes any necessary adjustments to the instruction,
1355 register contents, and memory. We use this in step n1.
1356
1357 - gdbarch_displaced_step_fixup adjusts registers and memory after
1358 we have successfuly single-stepped the instruction, to yield the
1359 same effect the instruction would have had if we had executed it
1360 at its original address. We use this in step n3.
1361
1362 - gdbarch_displaced_step_free_closure provides cleanup.
1363
1364 The gdbarch_displaced_step_copy_insn and
1365 gdbarch_displaced_step_fixup functions must be written so that
1366 copying an instruction with gdbarch_displaced_step_copy_insn,
1367 single-stepping across the copied instruction, and then applying
1368 gdbarch_displaced_insn_fixup should have the same effects on the
1369 thread's memory and registers as stepping the instruction in place
1370 would have. Exactly which responsibilities fall to the copy and
1371 which fall to the fixup is up to the author of those functions.
1372
1373 See the comments in gdbarch.sh for details.
1374
1375 Note that displaced stepping and software single-step cannot
1376 currently be used in combination, although with some care I think
1377 they could be made to. Software single-step works by placing
1378 breakpoints on all possible subsequent instructions; if the
1379 displaced instruction is a PC-relative jump, those breakpoints
1380 could fall in very strange places --- on pages that aren't
1381 executable, or at addresses that are not proper instruction
1382 boundaries. (We do generally let other threads run while we wait
1383 to hit the software single-step breakpoint, and they might
1384 encounter such a corrupted instruction.) One way to work around
1385 this would be to have gdbarch_displaced_step_copy_insn fully
1386 simulate the effect of PC-relative instructions (and return NULL)
1387 on architectures that use software single-stepping.
1388
1389 In non-stop mode, we can have independent and simultaneous step
1390 requests, so more than one thread may need to simultaneously step
1391 over a breakpoint. The current implementation assumes there is
1392 only one scratch space per process. In this case, we have to
1393 serialize access to the scratch space. If thread A wants to step
1394 over a breakpoint, but we are currently waiting for some other
1395 thread to complete a displaced step, we leave thread A stopped and
1396 place it in the displaced_step_request_queue. Whenever a displaced
1397 step finishes, we pick the next thread in the queue and start a new
1398 displaced step operation on it. See displaced_step_prepare and
1399 displaced_step_fixup for details. */
1400
1401struct displaced_step_request
1402{
1403 ptid_t ptid;
1404 struct displaced_step_request *next;
1405};
1406
1407/* Per-inferior displaced stepping state. */
1408struct displaced_step_inferior_state
1409{
1410 /* Pointer to next in linked list. */
1411 struct displaced_step_inferior_state *next;
1412
1413 /* The process this displaced step state refers to. */
1414 int pid;
1415
1416 /* A queue of pending displaced stepping requests. One entry per
1417 thread that needs to do a displaced step. */
1418 struct displaced_step_request *step_request_queue;
1419
1420 /* If this is not null_ptid, this is the thread carrying out a
1421 displaced single-step in process PID. This thread's state will
1422 require fixing up once it has completed its step. */
1423 ptid_t step_ptid;
1424
1425 /* The architecture the thread had when we stepped it. */
1426 struct gdbarch *step_gdbarch;
1427
1428 /* The closure provided gdbarch_displaced_step_copy_insn, to be used
1429 for post-step cleanup. */
1430 struct displaced_step_closure *step_closure;
1431
1432 /* The address of the original instruction, and the copy we
1433 made. */
1434 CORE_ADDR step_original, step_copy;
1435
1436 /* Saved contents of copy area. */
1437 gdb_byte *step_saved_copy;
1438};
1439
1440/* The list of states of processes involved in displaced stepping
1441 presently. */
1442static struct displaced_step_inferior_state *displaced_step_inferior_states;
1443
1444/* Get the displaced stepping state of process PID. */
1445
1446static struct displaced_step_inferior_state *
1447get_displaced_stepping_state (int pid)
1448{
1449 struct displaced_step_inferior_state *state;
1450
1451 for (state = displaced_step_inferior_states;
1452 state != NULL;
1453 state = state->next)
1454 if (state->pid == pid)
1455 return state;
1456
1457 return NULL;
1458}
1459
1460/* Return true if process PID has a thread doing a displaced step. */
1461
1462static int
1463displaced_step_in_progress (int pid)
1464{
1465 struct displaced_step_inferior_state *displaced;
1466
1467 displaced = get_displaced_stepping_state (pid);
1468 if (displaced != NULL && !ptid_equal (displaced->step_ptid, null_ptid))
1469 return 1;
1470
1471 return 0;
1472}
1473
1474/* Add a new displaced stepping state for process PID to the displaced
1475 stepping state list, or return a pointer to an already existing
1476 entry, if it already exists. Never returns NULL. */
1477
1478static struct displaced_step_inferior_state *
1479add_displaced_stepping_state (int pid)
1480{
1481 struct displaced_step_inferior_state *state;
1482
1483 for (state = displaced_step_inferior_states;
1484 state != NULL;
1485 state = state->next)
1486 if (state->pid == pid)
1487 return state;
1488
1489 state = xcalloc (1, sizeof (*state));
1490 state->pid = pid;
1491 state->next = displaced_step_inferior_states;
1492 displaced_step_inferior_states = state;
1493
1494 return state;
1495}
1496
1497/* If inferior is in displaced stepping, and ADDR equals to starting address
1498 of copy area, return corresponding displaced_step_closure. Otherwise,
1499 return NULL. */
1500
1501struct displaced_step_closure*
1502get_displaced_step_closure_by_addr (CORE_ADDR addr)
1503{
1504 struct displaced_step_inferior_state *displaced
1505 = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1506
1507 /* If checking the mode of displaced instruction in copy area. */
1508 if (displaced && !ptid_equal (displaced->step_ptid, null_ptid)
1509 && (displaced->step_copy == addr))
1510 return displaced->step_closure;
1511
1512 return NULL;
1513}
1514
1515/* Remove the displaced stepping state of process PID. */
1516
1517static void
1518remove_displaced_stepping_state (int pid)
1519{
1520 struct displaced_step_inferior_state *it, **prev_next_p;
1521
1522 gdb_assert (pid != 0);
1523
1524 it = displaced_step_inferior_states;
1525 prev_next_p = &displaced_step_inferior_states;
1526 while (it)
1527 {
1528 if (it->pid == pid)
1529 {
1530 *prev_next_p = it->next;
1531 xfree (it);
1532 return;
1533 }
1534
1535 prev_next_p = &it->next;
1536 it = *prev_next_p;
1537 }
1538}
1539
1540static void
1541infrun_inferior_exit (struct inferior *inf)
1542{
1543 remove_displaced_stepping_state (inf->pid);
1544}
1545
1546/* If ON, and the architecture supports it, GDB will use displaced
1547 stepping to step over breakpoints. If OFF, or if the architecture
1548 doesn't support it, GDB will instead use the traditional
1549 hold-and-step approach. If AUTO (which is the default), GDB will
1550 decide which technique to use to step over breakpoints depending on
1551 which of all-stop or non-stop mode is active --- displaced stepping
1552 in non-stop mode; hold-and-step in all-stop mode. */
1553
1554static enum auto_boolean can_use_displaced_stepping = AUTO_BOOLEAN_AUTO;
1555
1556static void
1557show_can_use_displaced_stepping (struct ui_file *file, int from_tty,
1558 struct cmd_list_element *c,
1559 const char *value)
1560{
1561 if (can_use_displaced_stepping == AUTO_BOOLEAN_AUTO)
1562 fprintf_filtered (file,
1563 _("Debugger's willingness to use displaced stepping "
1564 "to step over breakpoints is %s (currently %s).\n"),
1565 value, non_stop ? "on" : "off");
1566 else
1567 fprintf_filtered (file,
1568 _("Debugger's willingness to use displaced stepping "
1569 "to step over breakpoints is %s.\n"), value);
1570}
1571
1572/* Return non-zero if displaced stepping can/should be used to step
1573 over breakpoints. */
1574
1575static int
1576use_displaced_stepping (struct gdbarch *gdbarch)
1577{
1578 return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop)
1579 || can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
1580 && gdbarch_displaced_step_copy_insn_p (gdbarch)
1581 && find_record_target () == NULL);
1582}
1583
1584/* Clean out any stray displaced stepping state. */
1585static void
1586displaced_step_clear (struct displaced_step_inferior_state *displaced)
1587{
1588 /* Indicate that there is no cleanup pending. */
1589 displaced->step_ptid = null_ptid;
1590
1591 if (displaced->step_closure)
1592 {
1593 gdbarch_displaced_step_free_closure (displaced->step_gdbarch,
1594 displaced->step_closure);
1595 displaced->step_closure = NULL;
1596 }
1597}
1598
1599static void
1600displaced_step_clear_cleanup (void *arg)
1601{
1602 struct displaced_step_inferior_state *state = arg;
1603
1604 displaced_step_clear (state);
1605}
1606
1607/* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */
1608void
1609displaced_step_dump_bytes (struct ui_file *file,
1610 const gdb_byte *buf,
1611 size_t len)
1612{
1613 int i;
1614
1615 for (i = 0; i < len; i++)
1616 fprintf_unfiltered (file, "%02x ", buf[i]);
1617 fputs_unfiltered ("\n", file);
1618}
1619
1620/* Prepare to single-step, using displaced stepping.
1621
1622 Note that we cannot use displaced stepping when we have a signal to
1623 deliver. If we have a signal to deliver and an instruction to step
1624 over, then after the step, there will be no indication from the
1625 target whether the thread entered a signal handler or ignored the
1626 signal and stepped over the instruction successfully --- both cases
1627 result in a simple SIGTRAP. In the first case we mustn't do a
1628 fixup, and in the second case we must --- but we can't tell which.
1629 Comments in the code for 'random signals' in handle_inferior_event
1630 explain how we handle this case instead.
1631
1632 Returns 1 if preparing was successful -- this thread is going to be
1633 stepped now; or 0 if displaced stepping this thread got queued. */
1634static int
1635displaced_step_prepare (ptid_t ptid)
1636{
1637 struct cleanup *old_cleanups, *ignore_cleanups;
1638 struct thread_info *tp = find_thread_ptid (ptid);
1639 struct regcache *regcache = get_thread_regcache (ptid);
1640 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1641 CORE_ADDR original, copy;
1642 ULONGEST len;
1643 struct displaced_step_closure *closure;
1644 struct displaced_step_inferior_state *displaced;
1645 int status;
1646
1647 /* We should never reach this function if the architecture does not
1648 support displaced stepping. */
1649 gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch));
1650
1651 /* Disable range stepping while executing in the scratch pad. We
1652 want a single-step even if executing the displaced instruction in
1653 the scratch buffer lands within the stepping range (e.g., a
1654 jump/branch). */
1655 tp->control.may_range_step = 0;
1656
1657 /* We have to displaced step one thread at a time, as we only have
1658 access to a single scratch space per inferior. */
1659
1660 displaced = add_displaced_stepping_state (ptid_get_pid (ptid));
1661
1662 if (!ptid_equal (displaced->step_ptid, null_ptid))
1663 {
1664 /* Already waiting for a displaced step to finish. Defer this
1665 request and place in queue. */
1666 struct displaced_step_request *req, *new_req;
1667
1668 if (debug_displaced)
1669 fprintf_unfiltered (gdb_stdlog,
1670 "displaced: defering step of %s\n",
1671 target_pid_to_str (ptid));
1672
1673 new_req = xmalloc (sizeof (*new_req));
1674 new_req->ptid = ptid;
1675 new_req->next = NULL;
1676
1677 if (displaced->step_request_queue)
1678 {
1679 for (req = displaced->step_request_queue;
1680 req && req->next;
1681 req = req->next)
1682 ;
1683 req->next = new_req;
1684 }
1685 else
1686 displaced->step_request_queue = new_req;
1687
1688 return 0;
1689 }
1690 else
1691 {
1692 if (debug_displaced)
1693 fprintf_unfiltered (gdb_stdlog,
1694 "displaced: stepping %s now\n",
1695 target_pid_to_str (ptid));
1696 }
1697
1698 displaced_step_clear (displaced);
1699
1700 old_cleanups = save_inferior_ptid ();
1701 inferior_ptid = ptid;
1702
1703 original = regcache_read_pc (regcache);
1704
1705 copy = gdbarch_displaced_step_location (gdbarch);
1706 len = gdbarch_max_insn_length (gdbarch);
1707
1708 /* Save the original contents of the copy area. */
1709 displaced->step_saved_copy = xmalloc (len);
1710 ignore_cleanups = make_cleanup (free_current_contents,
1711 &displaced->step_saved_copy);
1712 status = target_read_memory (copy, displaced->step_saved_copy, len);
1713 if (status != 0)
1714 throw_error (MEMORY_ERROR,
1715 _("Error accessing memory address %s (%s) for "
1716 "displaced-stepping scratch space."),
1717 paddress (gdbarch, copy), safe_strerror (status));
1718 if (debug_displaced)
1719 {
1720 fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ",
1721 paddress (gdbarch, copy));
1722 displaced_step_dump_bytes (gdb_stdlog,
1723 displaced->step_saved_copy,
1724 len);
1725 };
1726
1727 closure = gdbarch_displaced_step_copy_insn (gdbarch,
1728 original, copy, regcache);
1729
1730 /* We don't support the fully-simulated case at present. */
1731 gdb_assert (closure);
1732
1733 /* Save the information we need to fix things up if the step
1734 succeeds. */
1735 displaced->step_ptid = ptid;
1736 displaced->step_gdbarch = gdbarch;
1737 displaced->step_closure = closure;
1738 displaced->step_original = original;
1739 displaced->step_copy = copy;
1740
1741 make_cleanup (displaced_step_clear_cleanup, displaced);
1742
1743 /* Resume execution at the copy. */
1744 regcache_write_pc (regcache, copy);
1745
1746 discard_cleanups (ignore_cleanups);
1747
1748 do_cleanups (old_cleanups);
1749
1750 if (debug_displaced)
1751 fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
1752 paddress (gdbarch, copy));
1753
1754 return 1;
1755}
1756
1757static void
1758write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr,
1759 const gdb_byte *myaddr, int len)
1760{
1761 struct cleanup *ptid_cleanup = save_inferior_ptid ();
1762
1763 inferior_ptid = ptid;
1764 write_memory (memaddr, myaddr, len);
1765 do_cleanups (ptid_cleanup);
1766}
1767
1768/* Restore the contents of the copy area for thread PTID. */
1769
1770static void
1771displaced_step_restore (struct displaced_step_inferior_state *displaced,
1772 ptid_t ptid)
1773{
1774 ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch);
1775
1776 write_memory_ptid (ptid, displaced->step_copy,
1777 displaced->step_saved_copy, len);
1778 if (debug_displaced)
1779 fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n",
1780 target_pid_to_str (ptid),
1781 paddress (displaced->step_gdbarch,
1782 displaced->step_copy));
1783}
1784
1785static void
1786displaced_step_fixup (ptid_t event_ptid, enum gdb_signal signal)
1787{
1788 struct cleanup *old_cleanups;
1789 struct displaced_step_inferior_state *displaced
1790 = get_displaced_stepping_state (ptid_get_pid (event_ptid));
1791
1792 /* Was any thread of this process doing a displaced step? */
1793 if (displaced == NULL)
1794 return;
1795
1796 /* Was this event for the pid we displaced? */
1797 if (ptid_equal (displaced->step_ptid, null_ptid)
1798 || ! ptid_equal (displaced->step_ptid, event_ptid))
1799 return;
1800
1801 old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
1802
1803 displaced_step_restore (displaced, displaced->step_ptid);
1804
1805 /* Fixup may need to read memory/registers. Switch to the thread
1806 that we're fixing up. Also, target_stopped_by_watchpoint checks
1807 the current thread. */
1808 switch_to_thread (event_ptid);
1809
1810 /* Did the instruction complete successfully? */
1811 if (signal == GDB_SIGNAL_TRAP
1812 && !(target_stopped_by_watchpoint ()
1813 && (gdbarch_have_nonsteppable_watchpoint (displaced->step_gdbarch)
1814 || target_have_steppable_watchpoint)))
1815 {
1816 /* Fix up the resulting state. */
1817 gdbarch_displaced_step_fixup (displaced->step_gdbarch,
1818 displaced->step_closure,
1819 displaced->step_original,
1820 displaced->step_copy,
1821 get_thread_regcache (displaced->step_ptid));
1822 }
1823 else
1824 {
1825 /* Since the instruction didn't complete, all we can do is
1826 relocate the PC. */
1827 struct regcache *regcache = get_thread_regcache (event_ptid);
1828 CORE_ADDR pc = regcache_read_pc (regcache);
1829
1830 pc = displaced->step_original + (pc - displaced->step_copy);
1831 regcache_write_pc (regcache, pc);
1832 }
1833
1834 do_cleanups (old_cleanups);
1835
1836 displaced->step_ptid = null_ptid;
1837
1838 /* Are there any pending displaced stepping requests? If so, run
1839 one now. Leave the state object around, since we're likely to
1840 need it again soon. */
1841 while (displaced->step_request_queue)
1842 {
1843 struct displaced_step_request *head;
1844 ptid_t ptid;
1845 struct regcache *regcache;
1846 struct gdbarch *gdbarch;
1847 CORE_ADDR actual_pc;
1848 struct address_space *aspace;
1849
1850 head = displaced->step_request_queue;
1851 ptid = head->ptid;
1852 displaced->step_request_queue = head->next;
1853 xfree (head);
1854
1855 context_switch (ptid);
1856
1857 regcache = get_thread_regcache (ptid);
1858 actual_pc = regcache_read_pc (regcache);
1859 aspace = get_regcache_aspace (regcache);
1860 gdbarch = get_regcache_arch (regcache);
1861
1862 if (breakpoint_here_p (aspace, actual_pc))
1863 {
1864 if (debug_displaced)
1865 fprintf_unfiltered (gdb_stdlog,
1866 "displaced: stepping queued %s now\n",
1867 target_pid_to_str (ptid));
1868
1869 displaced_step_prepare (ptid);
1870
1871 if (debug_displaced)
1872 {
1873 CORE_ADDR actual_pc = regcache_read_pc (regcache);
1874 gdb_byte buf[4];
1875
1876 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1877 paddress (gdbarch, actual_pc));
1878 read_memory (actual_pc, buf, sizeof (buf));
1879 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1880 }
1881
1882 if (gdbarch_displaced_step_hw_singlestep (gdbarch,
1883 displaced->step_closure))
1884 target_resume (ptid, 1, GDB_SIGNAL_0);
1885 else
1886 target_resume (ptid, 0, GDB_SIGNAL_0);
1887
1888 /* Done, we're stepping a thread. */
1889 break;
1890 }
1891 else
1892 {
1893 int step;
1894 struct thread_info *tp = inferior_thread ();
1895
1896 /* The breakpoint we were sitting under has since been
1897 removed. */
1898 tp->control.trap_expected = 0;
1899
1900 /* Go back to what we were trying to do. */
1901 step = currently_stepping (tp);
1902
1903 if (step)
1904 step = maybe_software_singlestep (gdbarch, actual_pc);
1905
1906 if (debug_displaced)
1907 fprintf_unfiltered (gdb_stdlog,
1908 "displaced: breakpoint is gone: %s, step(%d)\n",
1909 target_pid_to_str (tp->ptid), step);
1910
1911 target_resume (ptid, step, GDB_SIGNAL_0);
1912 tp->suspend.stop_signal = GDB_SIGNAL_0;
1913
1914 /* This request was discarded. See if there's any other
1915 thread waiting for its turn. */
1916 }
1917 }
1918}
1919
1920/* Update global variables holding ptids to hold NEW_PTID if they were
1921 holding OLD_PTID. */
1922static void
1923infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid)
1924{
1925 struct displaced_step_request *it;
1926 struct displaced_step_inferior_state *displaced;
1927
1928 if (ptid_equal (inferior_ptid, old_ptid))
1929 inferior_ptid = new_ptid;
1930
1931 for (displaced = displaced_step_inferior_states;
1932 displaced;
1933 displaced = displaced->next)
1934 {
1935 if (ptid_equal (displaced->step_ptid, old_ptid))
1936 displaced->step_ptid = new_ptid;
1937
1938 for (it = displaced->step_request_queue; it; it = it->next)
1939 if (ptid_equal (it->ptid, old_ptid))
1940 it->ptid = new_ptid;
1941 }
1942}
1943
1944\f
1945/* Resuming. */
1946
1947/* Things to clean up if we QUIT out of resume (). */
1948static void
1949resume_cleanups (void *ignore)
1950{
1951 if (!ptid_equal (inferior_ptid, null_ptid))
1952 delete_single_step_breakpoints (inferior_thread ());
1953
1954 normal_stop ();
1955}
1956
1957static const char schedlock_off[] = "off";
1958static const char schedlock_on[] = "on";
1959static const char schedlock_step[] = "step";
1960static const char *const scheduler_enums[] = {
1961 schedlock_off,
1962 schedlock_on,
1963 schedlock_step,
1964 NULL
1965};
1966static const char *scheduler_mode = schedlock_off;
1967static void
1968show_scheduler_mode (struct ui_file *file, int from_tty,
1969 struct cmd_list_element *c, const char *value)
1970{
1971 fprintf_filtered (file,
1972 _("Mode for locking scheduler "
1973 "during execution is \"%s\".\n"),
1974 value);
1975}
1976
1977static void
1978set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c)
1979{
1980 if (!target_can_lock_scheduler)
1981 {
1982 scheduler_mode = schedlock_off;
1983 error (_("Target '%s' cannot support this command."), target_shortname);
1984 }
1985}
1986
1987/* True if execution commands resume all threads of all processes by
1988 default; otherwise, resume only threads of the current inferior
1989 process. */
1990int sched_multi = 0;
1991
1992/* Try to setup for software single stepping over the specified location.
1993 Return 1 if target_resume() should use hardware single step.
1994
1995 GDBARCH the current gdbarch.
1996 PC the location to step over. */
1997
1998static int
1999maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc)
2000{
2001 int hw_step = 1;
2002
2003 if (execution_direction == EXEC_FORWARD
2004 && gdbarch_software_single_step_p (gdbarch)
2005 && gdbarch_software_single_step (gdbarch, get_current_frame ()))
2006 {
2007 hw_step = 0;
2008 }
2009 return hw_step;
2010}
2011
2012/* See infrun.h. */
2013
2014ptid_t
2015user_visible_resume_ptid (int step)
2016{
2017 ptid_t resume_ptid;
2018
2019 if (non_stop)
2020 {
2021 /* With non-stop mode on, threads are always handled
2022 individually. */
2023 resume_ptid = inferior_ptid;
2024 }
2025 else if ((scheduler_mode == schedlock_on)
2026 || (scheduler_mode == schedlock_step && step))
2027 {
2028 /* User-settable 'scheduler' mode requires solo thread
2029 resume. */
2030 resume_ptid = inferior_ptid;
2031 }
2032 else if (!sched_multi && target_supports_multi_process ())
2033 {
2034 /* Resume all threads of the current process (and none of other
2035 processes). */
2036 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
2037 }
2038 else
2039 {
2040 /* Resume all threads of all processes. */
2041 resume_ptid = RESUME_ALL;
2042 }
2043
2044 return resume_ptid;
2045}
2046
2047/* Wrapper for target_resume, that handles infrun-specific
2048 bookkeeping. */
2049
2050static void
2051do_target_resume (ptid_t resume_ptid, int step, enum gdb_signal sig)
2052{
2053 struct thread_info *tp = inferior_thread ();
2054
2055 /* Install inferior's terminal modes. */
2056 target_terminal_inferior ();
2057
2058 /* Avoid confusing the next resume, if the next stop/resume
2059 happens to apply to another thread. */
2060 tp->suspend.stop_signal = GDB_SIGNAL_0;
2061
2062 /* Advise target which signals may be handled silently.
2063
2064 If we have removed breakpoints because we are stepping over one
2065 in-line (in any thread), we need to receive all signals to avoid
2066 accidentally skipping a breakpoint during execution of a signal
2067 handler.
2068
2069 Likewise if we're displaced stepping, otherwise a trap for a
2070 breakpoint in a signal handler might be confused with the
2071 displaced step finishing. We don't make the displaced_step_fixup
2072 step distinguish the cases instead, because:
2073
2074 - a backtrace while stopped in the signal handler would show the
2075 scratch pad as frame older than the signal handler, instead of
2076 the real mainline code.
2077
2078 - when the thread is later resumed, the signal handler would
2079 return to the scratch pad area, which would no longer be
2080 valid. */
2081 if (step_over_info_valid_p ()
2082 || displaced_step_in_progress (ptid_get_pid (tp->ptid)))
2083 target_pass_signals (0, NULL);
2084 else
2085 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
2086
2087 target_resume (resume_ptid, step, sig);
2088}
2089
2090/* Resume the inferior, but allow a QUIT. This is useful if the user
2091 wants to interrupt some lengthy single-stepping operation
2092 (for child processes, the SIGINT goes to the inferior, and so
2093 we get a SIGINT random_signal, but for remote debugging and perhaps
2094 other targets, that's not true).
2095
2096 SIG is the signal to give the inferior (zero for none). */
2097void
2098resume (enum gdb_signal sig)
2099{
2100 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
2101 struct regcache *regcache = get_current_regcache ();
2102 struct gdbarch *gdbarch = get_regcache_arch (regcache);
2103 struct thread_info *tp = inferior_thread ();
2104 CORE_ADDR pc = regcache_read_pc (regcache);
2105 struct address_space *aspace = get_regcache_aspace (regcache);
2106 ptid_t resume_ptid;
2107 /* This represents the user's step vs continue request. When
2108 deciding whether "set scheduler-locking step" applies, it's the
2109 user's intention that counts. */
2110 const int user_step = tp->control.stepping_command;
2111 /* This represents what we'll actually request the target to do.
2112 This can decay from a step to a continue, if e.g., we need to
2113 implement single-stepping with breakpoints (software
2114 single-step). */
2115 int step;
2116
2117 tp->stepped_breakpoint = 0;
2118
2119 QUIT;
2120
2121 /* Depends on stepped_breakpoint. */
2122 step = currently_stepping (tp);
2123
2124 if (current_inferior ()->waiting_for_vfork_done)
2125 {
2126 /* Don't try to single-step a vfork parent that is waiting for
2127 the child to get out of the shared memory region (by exec'ing
2128 or exiting). This is particularly important on software
2129 single-step archs, as the child process would trip on the
2130 software single step breakpoint inserted for the parent
2131 process. Since the parent will not actually execute any
2132 instruction until the child is out of the shared region (such
2133 are vfork's semantics), it is safe to simply continue it.
2134 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
2135 the parent, and tell it to `keep_going', which automatically
2136 re-sets it stepping. */
2137 if (debug_infrun)
2138 fprintf_unfiltered (gdb_stdlog,
2139 "infrun: resume : clear step\n");
2140 step = 0;
2141 }
2142
2143 if (debug_infrun)
2144 fprintf_unfiltered (gdb_stdlog,
2145 "infrun: resume (step=%d, signal=%s), "
2146 "trap_expected=%d, current thread [%s] at %s\n",
2147 step, gdb_signal_to_symbol_string (sig),
2148 tp->control.trap_expected,
2149 target_pid_to_str (inferior_ptid),
2150 paddress (gdbarch, pc));
2151
2152 /* Normally, by the time we reach `resume', the breakpoints are either
2153 removed or inserted, as appropriate. The exception is if we're sitting
2154 at a permanent breakpoint; we need to step over it, but permanent
2155 breakpoints can't be removed. So we have to test for it here. */
2156 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
2157 {
2158 if (sig != GDB_SIGNAL_0)
2159 {
2160 /* We have a signal to pass to the inferior. The resume
2161 may, or may not take us to the signal handler. If this
2162 is a step, we'll need to stop in the signal handler, if
2163 there's one, (if the target supports stepping into
2164 handlers), or in the next mainline instruction, if
2165 there's no handler. If this is a continue, we need to be
2166 sure to run the handler with all breakpoints inserted.
2167 In all cases, set a breakpoint at the current address
2168 (where the handler returns to), and once that breakpoint
2169 is hit, resume skipping the permanent breakpoint. If
2170 that breakpoint isn't hit, then we've stepped into the
2171 signal handler (or hit some other event). We'll delete
2172 the step-resume breakpoint then. */
2173
2174 if (debug_infrun)
2175 fprintf_unfiltered (gdb_stdlog,
2176 "infrun: resume: skipping permanent breakpoint, "
2177 "deliver signal first\n");
2178
2179 clear_step_over_info ();
2180 tp->control.trap_expected = 0;
2181
2182 if (tp->control.step_resume_breakpoint == NULL)
2183 {
2184 /* Set a "high-priority" step-resume, as we don't want
2185 user breakpoints at PC to trigger (again) when this
2186 hits. */
2187 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2188 gdb_assert (tp->control.step_resume_breakpoint->loc->permanent);
2189
2190 tp->step_after_step_resume_breakpoint = step;
2191 }
2192
2193 insert_breakpoints ();
2194 }
2195 else
2196 {
2197 /* There's no signal to pass, we can go ahead and skip the
2198 permanent breakpoint manually. */
2199 if (debug_infrun)
2200 fprintf_unfiltered (gdb_stdlog,
2201 "infrun: resume: skipping permanent breakpoint\n");
2202 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
2203 /* Update pc to reflect the new address from which we will
2204 execute instructions. */
2205 pc = regcache_read_pc (regcache);
2206
2207 if (step)
2208 {
2209 /* We've already advanced the PC, so the stepping part
2210 is done. Now we need to arrange for a trap to be
2211 reported to handle_inferior_event. Set a breakpoint
2212 at the current PC, and run to it. Don't update
2213 prev_pc, because if we end in
2214 switch_back_to_stepped_thread, we want the "expected
2215 thread advanced also" branch to be taken. IOW, we
2216 don't want this thread to step further from PC
2217 (overstep). */
2218 gdb_assert (!step_over_info_valid_p ());
2219 insert_single_step_breakpoint (gdbarch, aspace, pc);
2220 insert_breakpoints ();
2221
2222 resume_ptid = user_visible_resume_ptid (user_step);
2223 do_target_resume (resume_ptid, 0, GDB_SIGNAL_0);
2224 discard_cleanups (old_cleanups);
2225 return;
2226 }
2227 }
2228 }
2229
2230 /* If we have a breakpoint to step over, make sure to do a single
2231 step only. Same if we have software watchpoints. */
2232 if (tp->control.trap_expected || bpstat_should_step ())
2233 tp->control.may_range_step = 0;
2234
2235 /* If enabled, step over breakpoints by executing a copy of the
2236 instruction at a different address.
2237
2238 We can't use displaced stepping when we have a signal to deliver;
2239 the comments for displaced_step_prepare explain why. The
2240 comments in the handle_inferior event for dealing with 'random
2241 signals' explain what we do instead.
2242
2243 We can't use displaced stepping when we are waiting for vfork_done
2244 event, displaced stepping breaks the vfork child similarly as single
2245 step software breakpoint. */
2246 if (use_displaced_stepping (gdbarch)
2247 && tp->control.trap_expected
2248 && !step_over_info_valid_p ()
2249 && sig == GDB_SIGNAL_0
2250 && !current_inferior ()->waiting_for_vfork_done)
2251 {
2252 struct displaced_step_inferior_state *displaced;
2253
2254 if (!displaced_step_prepare (inferior_ptid))
2255 {
2256 /* Got placed in displaced stepping queue. Will be resumed
2257 later when all the currently queued displaced stepping
2258 requests finish. The thread is not executing at this
2259 point, and the call to set_executing will be made later.
2260 But we need to call set_running here, since from the
2261 user/frontend's point of view, threads were set running.
2262 Unless we're calling an inferior function, as in that
2263 case we pretend the inferior doesn't run at all. */
2264 if (!tp->control.in_infcall)
2265 set_running (user_visible_resume_ptid (user_step), 1);
2266 discard_cleanups (old_cleanups);
2267 return;
2268 }
2269
2270 /* Update pc to reflect the new address from which we will execute
2271 instructions due to displaced stepping. */
2272 pc = regcache_read_pc (get_thread_regcache (inferior_ptid));
2273
2274 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
2275 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
2276 displaced->step_closure);
2277 }
2278
2279 /* Do we need to do it the hard way, w/temp breakpoints? */
2280 else if (step)
2281 step = maybe_software_singlestep (gdbarch, pc);
2282
2283 /* Currently, our software single-step implementation leads to different
2284 results than hardware single-stepping in one situation: when stepping
2285 into delivering a signal which has an associated signal handler,
2286 hardware single-step will stop at the first instruction of the handler,
2287 while software single-step will simply skip execution of the handler.
2288
2289 For now, this difference in behavior is accepted since there is no
2290 easy way to actually implement single-stepping into a signal handler
2291 without kernel support.
2292
2293 However, there is one scenario where this difference leads to follow-on
2294 problems: if we're stepping off a breakpoint by removing all breakpoints
2295 and then single-stepping. In this case, the software single-step
2296 behavior means that even if there is a *breakpoint* in the signal
2297 handler, GDB still would not stop.
2298
2299 Fortunately, we can at least fix this particular issue. We detect
2300 here the case where we are about to deliver a signal while software
2301 single-stepping with breakpoints removed. In this situation, we
2302 revert the decisions to remove all breakpoints and insert single-
2303 step breakpoints, and instead we install a step-resume breakpoint
2304 at the current address, deliver the signal without stepping, and
2305 once we arrive back at the step-resume breakpoint, actually step
2306 over the breakpoint we originally wanted to step over. */
2307 if (thread_has_single_step_breakpoints_set (tp)
2308 && sig != GDB_SIGNAL_0
2309 && step_over_info_valid_p ())
2310 {
2311 /* If we have nested signals or a pending signal is delivered
2312 immediately after a handler returns, might might already have
2313 a step-resume breakpoint set on the earlier handler. We cannot
2314 set another step-resume breakpoint; just continue on until the
2315 original breakpoint is hit. */
2316 if (tp->control.step_resume_breakpoint == NULL)
2317 {
2318 insert_hp_step_resume_breakpoint_at_frame (get_current_frame ());
2319 tp->step_after_step_resume_breakpoint = 1;
2320 }
2321
2322 delete_single_step_breakpoints (tp);
2323
2324 clear_step_over_info ();
2325 tp->control.trap_expected = 0;
2326
2327 insert_breakpoints ();
2328 }
2329
2330 /* If STEP is set, it's a request to use hardware stepping
2331 facilities. But in that case, we should never
2332 use singlestep breakpoint. */
2333 gdb_assert (!(thread_has_single_step_breakpoints_set (tp) && step));
2334
2335 /* Decide the set of threads to ask the target to resume. Start
2336 by assuming everything will be resumed, than narrow the set
2337 by applying increasingly restricting conditions. */
2338 resume_ptid = user_visible_resume_ptid (user_step);
2339
2340 /* Even if RESUME_PTID is a wildcard, and we end up resuming less
2341 (e.g., we might need to step over a breakpoint), from the
2342 user/frontend's point of view, all threads in RESUME_PTID are now
2343 running. Unless we're calling an inferior function, as in that
2344 case pretend we inferior doesn't run at all. */
2345 if (!tp->control.in_infcall)
2346 set_running (resume_ptid, 1);
2347
2348 /* Maybe resume a single thread after all. */
2349 if ((step || thread_has_single_step_breakpoints_set (tp))
2350 && tp->control.trap_expected)
2351 {
2352 /* We're allowing a thread to run past a breakpoint it has
2353 hit, by single-stepping the thread with the breakpoint
2354 removed. In which case, we need to single-step only this
2355 thread, and keep others stopped, as they can miss this
2356 breakpoint if allowed to run. */
2357 resume_ptid = inferior_ptid;
2358 }
2359
2360 if (execution_direction != EXEC_REVERSE
2361 && step && breakpoint_inserted_here_p (aspace, pc))
2362 {
2363 /* The only case we currently need to step a breakpoint
2364 instruction is when we have a signal to deliver. See
2365 handle_signal_stop where we handle random signals that could
2366 take out us out of the stepping range. Normally, in that
2367 case we end up continuing (instead of stepping) over the
2368 signal handler with a breakpoint at PC, but there are cases
2369 where we should _always_ single-step, even if we have a
2370 step-resume breakpoint, like when a software watchpoint is
2371 set. Assuming single-stepping and delivering a signal at the
2372 same time would takes us to the signal handler, then we could
2373 have removed the breakpoint at PC to step over it. However,
2374 some hardware step targets (like e.g., Mac OS) can't step
2375 into signal handlers, and for those, we need to leave the
2376 breakpoint at PC inserted, as otherwise if the handler
2377 recurses and executes PC again, it'll miss the breakpoint.
2378 So we leave the breakpoint inserted anyway, but we need to
2379 record that we tried to step a breakpoint instruction, so
2380 that adjust_pc_after_break doesn't end up confused. */
2381 gdb_assert (sig != GDB_SIGNAL_0);
2382
2383 tp->stepped_breakpoint = 1;
2384
2385 /* Most targets can step a breakpoint instruction, thus
2386 executing it normally. But if this one cannot, just
2387 continue and we will hit it anyway. */
2388 if (gdbarch_cannot_step_breakpoint (gdbarch))
2389 step = 0;
2390 }
2391
2392 if (debug_displaced
2393 && use_displaced_stepping (gdbarch)
2394 && tp->control.trap_expected
2395 && !step_over_info_valid_p ())
2396 {
2397 struct regcache *resume_regcache = get_thread_regcache (tp->ptid);
2398 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
2399 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
2400 gdb_byte buf[4];
2401
2402 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
2403 paddress (resume_gdbarch, actual_pc));
2404 read_memory (actual_pc, buf, sizeof (buf));
2405 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
2406 }
2407
2408 if (tp->control.may_range_step)
2409 {
2410 /* If we're resuming a thread with the PC out of the step
2411 range, then we're doing some nested/finer run control
2412 operation, like stepping the thread out of the dynamic
2413 linker or the displaced stepping scratch pad. We
2414 shouldn't have allowed a range step then. */
2415 gdb_assert (pc_in_thread_step_range (pc, tp));
2416 }
2417
2418 do_target_resume (resume_ptid, step, sig);
2419 discard_cleanups (old_cleanups);
2420}
2421\f
2422/* Proceeding. */
2423
2424/* Clear out all variables saying what to do when inferior is continued.
2425 First do this, then set the ones you want, then call `proceed'. */
2426
2427static void
2428clear_proceed_status_thread (struct thread_info *tp)
2429{
2430 if (debug_infrun)
2431 fprintf_unfiltered (gdb_stdlog,
2432 "infrun: clear_proceed_status_thread (%s)\n",
2433 target_pid_to_str (tp->ptid));
2434
2435 /* If this signal should not be seen by program, give it zero.
2436 Used for debugging signals. */
2437 if (!signal_pass_state (tp->suspend.stop_signal))
2438 tp->suspend.stop_signal = GDB_SIGNAL_0;
2439
2440 tp->control.trap_expected = 0;
2441 tp->control.step_range_start = 0;
2442 tp->control.step_range_end = 0;
2443 tp->control.may_range_step = 0;
2444 tp->control.step_frame_id = null_frame_id;
2445 tp->control.step_stack_frame_id = null_frame_id;
2446 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
2447 tp->control.step_start_function = NULL;
2448 tp->stop_requested = 0;
2449
2450 tp->control.stop_step = 0;
2451
2452 tp->control.proceed_to_finish = 0;
2453
2454 tp->control.command_interp = NULL;
2455 tp->control.stepping_command = 0;
2456
2457 /* Discard any remaining commands or status from previous stop. */
2458 bpstat_clear (&tp->control.stop_bpstat);
2459}
2460
2461void
2462clear_proceed_status (int step)
2463{
2464 if (!non_stop)
2465 {
2466 struct thread_info *tp;
2467 ptid_t resume_ptid;
2468
2469 resume_ptid = user_visible_resume_ptid (step);
2470
2471 /* In all-stop mode, delete the per-thread status of all threads
2472 we're about to resume, implicitly and explicitly. */
2473 ALL_NON_EXITED_THREADS (tp)
2474 {
2475 if (!ptid_match (tp->ptid, resume_ptid))
2476 continue;
2477 clear_proceed_status_thread (tp);
2478 }
2479 }
2480
2481 if (!ptid_equal (inferior_ptid, null_ptid))
2482 {
2483 struct inferior *inferior;
2484
2485 if (non_stop)
2486 {
2487 /* If in non-stop mode, only delete the per-thread status of
2488 the current thread. */
2489 clear_proceed_status_thread (inferior_thread ());
2490 }
2491
2492 inferior = current_inferior ();
2493 inferior->control.stop_soon = NO_STOP_QUIETLY;
2494 }
2495
2496 stop_after_trap = 0;
2497
2498 clear_step_over_info ();
2499
2500 observer_notify_about_to_proceed ();
2501}
2502
2503/* Returns true if TP is still stopped at a breakpoint that needs
2504 stepping-over in order to make progress. If the breakpoint is gone
2505 meanwhile, we can skip the whole step-over dance. */
2506
2507static int
2508thread_still_needs_step_over (struct thread_info *tp)
2509{
2510 if (tp->stepping_over_breakpoint)
2511 {
2512 struct regcache *regcache = get_thread_regcache (tp->ptid);
2513
2514 if (breakpoint_here_p (get_regcache_aspace (regcache),
2515 regcache_read_pc (regcache))
2516 == ordinary_breakpoint_here)
2517 return 1;
2518
2519 tp->stepping_over_breakpoint = 0;
2520 }
2521
2522 return 0;
2523}
2524
2525/* Returns true if scheduler locking applies. STEP indicates whether
2526 we're about to do a step/next-like command to a thread. */
2527
2528static int
2529schedlock_applies (struct thread_info *tp)
2530{
2531 return (scheduler_mode == schedlock_on
2532 || (scheduler_mode == schedlock_step
2533 && tp->control.stepping_command));
2534}
2535
2536/* Look a thread other than EXCEPT that has previously reported a
2537 breakpoint event, and thus needs a step-over in order to make
2538 progress. Returns NULL is none is found. */
2539
2540static struct thread_info *
2541find_thread_needs_step_over (struct thread_info *except)
2542{
2543 struct thread_info *tp, *current;
2544
2545 /* With non-stop mode on, threads are always handled individually. */
2546 gdb_assert (! non_stop);
2547
2548 current = inferior_thread ();
2549
2550 /* If scheduler locking applies, we can avoid iterating over all
2551 threads. */
2552 if (schedlock_applies (except))
2553 {
2554 if (except != current
2555 && thread_still_needs_step_over (current))
2556 return current;
2557
2558 return NULL;
2559 }
2560
2561 ALL_NON_EXITED_THREADS (tp)
2562 {
2563 /* Ignore the EXCEPT thread. */
2564 if (tp == except)
2565 continue;
2566 /* Ignore threads of processes we're not resuming. */
2567 if (!sched_multi
2568 && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
2569 continue;
2570
2571 if (thread_still_needs_step_over (tp))
2572 return tp;
2573 }
2574
2575 return NULL;
2576}
2577
2578/* Basic routine for continuing the program in various fashions.
2579
2580 ADDR is the address to resume at, or -1 for resume where stopped.
2581 SIGGNAL is the signal to give it, or 0 for none,
2582 or -1 for act according to how it stopped.
2583 STEP is nonzero if should trap after one instruction.
2584 -1 means return after that and print nothing.
2585 You should probably set various step_... variables
2586 before calling here, if you are stepping.
2587
2588 You should call clear_proceed_status before calling proceed. */
2589
2590void
2591proceed (CORE_ADDR addr, enum gdb_signal siggnal)
2592{
2593 struct regcache *regcache;
2594 struct gdbarch *gdbarch;
2595 struct thread_info *tp;
2596 CORE_ADDR pc;
2597 struct address_space *aspace;
2598
2599 /* If we're stopped at a fork/vfork, follow the branch set by the
2600 "set follow-fork-mode" command; otherwise, we'll just proceed
2601 resuming the current thread. */
2602 if (!follow_fork ())
2603 {
2604 /* The target for some reason decided not to resume. */
2605 normal_stop ();
2606 if (target_can_async_p ())
2607 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2608 return;
2609 }
2610
2611 /* We'll update this if & when we switch to a new thread. */
2612 previous_inferior_ptid = inferior_ptid;
2613
2614 regcache = get_current_regcache ();
2615 gdbarch = get_regcache_arch (regcache);
2616 aspace = get_regcache_aspace (regcache);
2617 pc = regcache_read_pc (regcache);
2618 tp = inferior_thread ();
2619
2620 /* Fill in with reasonable starting values. */
2621 init_thread_stepping_state (tp);
2622
2623 if (addr == (CORE_ADDR) -1)
2624 {
2625 if (pc == stop_pc
2626 && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here
2627 && execution_direction != EXEC_REVERSE)
2628 /* There is a breakpoint at the address we will resume at,
2629 step one instruction before inserting breakpoints so that
2630 we do not stop right away (and report a second hit at this
2631 breakpoint).
2632
2633 Note, we don't do this in reverse, because we won't
2634 actually be executing the breakpoint insn anyway.
2635 We'll be (un-)executing the previous instruction. */
2636 tp->stepping_over_breakpoint = 1;
2637 else if (gdbarch_single_step_through_delay_p (gdbarch)
2638 && gdbarch_single_step_through_delay (gdbarch,
2639 get_current_frame ()))
2640 /* We stepped onto an instruction that needs to be stepped
2641 again before re-inserting the breakpoint, do so. */
2642 tp->stepping_over_breakpoint = 1;
2643 }
2644 else
2645 {
2646 regcache_write_pc (regcache, addr);
2647 }
2648
2649 if (siggnal != GDB_SIGNAL_DEFAULT)
2650 tp->suspend.stop_signal = siggnal;
2651
2652 /* Record the interpreter that issued the execution command that
2653 caused this thread to resume. If the top level interpreter is
2654 MI/async, and the execution command was a CLI command
2655 (next/step/etc.), we'll want to print stop event output to the MI
2656 console channel (the stepped-to line, etc.), as if the user
2657 entered the execution command on a real GDB console. */
2658 inferior_thread ()->control.command_interp = command_interp ();
2659
2660 if (debug_infrun)
2661 fprintf_unfiltered (gdb_stdlog,
2662 "infrun: proceed (addr=%s, signal=%s)\n",
2663 paddress (gdbarch, addr),
2664 gdb_signal_to_symbol_string (siggnal));
2665
2666 if (non_stop)
2667 /* In non-stop, each thread is handled individually. The context
2668 must already be set to the right thread here. */
2669 ;
2670 else
2671 {
2672 struct thread_info *step_over;
2673
2674 /* In a multi-threaded task we may select another thread and
2675 then continue or step.
2676
2677 But if the old thread was stopped at a breakpoint, it will
2678 immediately cause another breakpoint stop without any
2679 execution (i.e. it will report a breakpoint hit incorrectly).
2680 So we must step over it first.
2681
2682 Look for a thread other than the current (TP) that reported a
2683 breakpoint hit and hasn't been resumed yet since. */
2684 step_over = find_thread_needs_step_over (tp);
2685 if (step_over != NULL)
2686 {
2687 if (debug_infrun)
2688 fprintf_unfiltered (gdb_stdlog,
2689 "infrun: need to step-over [%s] first\n",
2690 target_pid_to_str (step_over->ptid));
2691
2692 /* Store the prev_pc for the stepping thread too, needed by
2693 switch_back_to_stepped_thread. */
2694 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2695 switch_to_thread (step_over->ptid);
2696 tp = step_over;
2697 }
2698 }
2699
2700 /* If we need to step over a breakpoint, and we're not using
2701 displaced stepping to do so, insert all breakpoints (watchpoints,
2702 etc.) but the one we're stepping over, step one instruction, and
2703 then re-insert the breakpoint when that step is finished. */
2704 if (tp->stepping_over_breakpoint && !use_displaced_stepping (gdbarch))
2705 {
2706 struct regcache *regcache = get_current_regcache ();
2707
2708 set_step_over_info (get_regcache_aspace (regcache),
2709 regcache_read_pc (regcache), 0);
2710 }
2711 else
2712 clear_step_over_info ();
2713
2714 insert_breakpoints ();
2715
2716 tp->control.trap_expected = tp->stepping_over_breakpoint;
2717
2718 annotate_starting ();
2719
2720 /* Make sure that output from GDB appears before output from the
2721 inferior. */
2722 gdb_flush (gdb_stdout);
2723
2724 /* Refresh prev_pc value just prior to resuming. This used to be
2725 done in stop_waiting, however, setting prev_pc there did not handle
2726 scenarios such as inferior function calls or returning from
2727 a function via the return command. In those cases, the prev_pc
2728 value was not set properly for subsequent commands. The prev_pc value
2729 is used to initialize the starting line number in the ecs. With an
2730 invalid value, the gdb next command ends up stopping at the position
2731 represented by the next line table entry past our start position.
2732 On platforms that generate one line table entry per line, this
2733 is not a problem. However, on the ia64, the compiler generates
2734 extraneous line table entries that do not increase the line number.
2735 When we issue the gdb next command on the ia64 after an inferior call
2736 or a return command, we often end up a few instructions forward, still
2737 within the original line we started.
2738
2739 An attempt was made to refresh the prev_pc at the same time the
2740 execution_control_state is initialized (for instance, just before
2741 waiting for an inferior event). But this approach did not work
2742 because of platforms that use ptrace, where the pc register cannot
2743 be read unless the inferior is stopped. At that point, we are not
2744 guaranteed the inferior is stopped and so the regcache_read_pc() call
2745 can fail. Setting the prev_pc value here ensures the value is updated
2746 correctly when the inferior is stopped. */
2747 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2748
2749 /* Resume inferior. */
2750 resume (tp->suspend.stop_signal);
2751
2752 /* Wait for it to stop (if not standalone)
2753 and in any case decode why it stopped, and act accordingly. */
2754 /* Do this only if we are not using the event loop, or if the target
2755 does not support asynchronous execution. */
2756 if (!target_can_async_p ())
2757 {
2758 wait_for_inferior ();
2759 normal_stop ();
2760 }
2761}
2762\f
2763
2764/* Start remote-debugging of a machine over a serial link. */
2765
2766void
2767start_remote (int from_tty)
2768{
2769 struct inferior *inferior;
2770
2771 inferior = current_inferior ();
2772 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2773
2774 /* Always go on waiting for the target, regardless of the mode. */
2775 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2776 indicate to wait_for_inferior that a target should timeout if
2777 nothing is returned (instead of just blocking). Because of this,
2778 targets expecting an immediate response need to, internally, set
2779 things up so that the target_wait() is forced to eventually
2780 timeout. */
2781 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2782 differentiate to its caller what the state of the target is after
2783 the initial open has been performed. Here we're assuming that
2784 the target has stopped. It should be possible to eventually have
2785 target_open() return to the caller an indication that the target
2786 is currently running and GDB state should be set to the same as
2787 for an async run. */
2788 wait_for_inferior ();
2789
2790 /* Now that the inferior has stopped, do any bookkeeping like
2791 loading shared libraries. We want to do this before normal_stop,
2792 so that the displayed frame is up to date. */
2793 post_create_inferior (&current_target, from_tty);
2794
2795 normal_stop ();
2796}
2797
2798/* Initialize static vars when a new inferior begins. */
2799
2800void
2801init_wait_for_inferior (void)
2802{
2803 /* These are meaningless until the first time through wait_for_inferior. */
2804
2805 breakpoint_init_inferior (inf_starting);
2806
2807 clear_proceed_status (0);
2808
2809 target_last_wait_ptid = minus_one_ptid;
2810
2811 previous_inferior_ptid = inferior_ptid;
2812
2813 /* Discard any skipped inlined frames. */
2814 clear_inline_frame_state (minus_one_ptid);
2815}
2816
2817\f
2818/* Data to be passed around while handling an event. This data is
2819 discarded between events. */
2820struct execution_control_state
2821{
2822 ptid_t ptid;
2823 /* The thread that got the event, if this was a thread event; NULL
2824 otherwise. */
2825 struct thread_info *event_thread;
2826
2827 struct target_waitstatus ws;
2828 int stop_func_filled_in;
2829 CORE_ADDR stop_func_start;
2830 CORE_ADDR stop_func_end;
2831 const char *stop_func_name;
2832 int wait_some_more;
2833
2834 /* True if the event thread hit the single-step breakpoint of
2835 another thread. Thus the event doesn't cause a stop, the thread
2836 needs to be single-stepped past the single-step breakpoint before
2837 we can switch back to the original stepping thread. */
2838 int hit_singlestep_breakpoint;
2839};
2840
2841static void handle_inferior_event (struct execution_control_state *ecs);
2842
2843static void handle_step_into_function (struct gdbarch *gdbarch,
2844 struct execution_control_state *ecs);
2845static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2846 struct execution_control_state *ecs);
2847static void handle_signal_stop (struct execution_control_state *ecs);
2848static void check_exception_resume (struct execution_control_state *,
2849 struct frame_info *);
2850
2851static void end_stepping_range (struct execution_control_state *ecs);
2852static void stop_waiting (struct execution_control_state *ecs);
2853static void prepare_to_wait (struct execution_control_state *ecs);
2854static void keep_going (struct execution_control_state *ecs);
2855static void process_event_stop_test (struct execution_control_state *ecs);
2856static int switch_back_to_stepped_thread (struct execution_control_state *ecs);
2857
2858/* Callback for iterate over threads. If the thread is stopped, but
2859 the user/frontend doesn't know about that yet, go through
2860 normal_stop, as if the thread had just stopped now. ARG points at
2861 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2862 ptid_is_pid(PTID) is true, applies to all threads of the process
2863 pointed at by PTID. Otherwise, apply only to the thread pointed by
2864 PTID. */
2865
2866static int
2867infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2868{
2869 ptid_t ptid = * (ptid_t *) arg;
2870
2871 if ((ptid_equal (info->ptid, ptid)
2872 || ptid_equal (minus_one_ptid, ptid)
2873 || (ptid_is_pid (ptid)
2874 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2875 && is_running (info->ptid)
2876 && !is_executing (info->ptid))
2877 {
2878 struct cleanup *old_chain;
2879 struct execution_control_state ecss;
2880 struct execution_control_state *ecs = &ecss;
2881
2882 memset (ecs, 0, sizeof (*ecs));
2883
2884 old_chain = make_cleanup_restore_current_thread ();
2885
2886 overlay_cache_invalid = 1;
2887 /* Flush target cache before starting to handle each event.
2888 Target was running and cache could be stale. This is just a
2889 heuristic. Running threads may modify target memory, but we
2890 don't get any event. */
2891 target_dcache_invalidate ();
2892
2893 /* Go through handle_inferior_event/normal_stop, so we always
2894 have consistent output as if the stop event had been
2895 reported. */
2896 ecs->ptid = info->ptid;
2897 ecs->event_thread = find_thread_ptid (info->ptid);
2898 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2899 ecs->ws.value.sig = GDB_SIGNAL_0;
2900
2901 handle_inferior_event (ecs);
2902
2903 if (!ecs->wait_some_more)
2904 {
2905 struct thread_info *tp;
2906
2907 normal_stop ();
2908
2909 /* Finish off the continuations. */
2910 tp = inferior_thread ();
2911 do_all_intermediate_continuations_thread (tp, 1);
2912 do_all_continuations_thread (tp, 1);
2913 }
2914
2915 do_cleanups (old_chain);
2916 }
2917
2918 return 0;
2919}
2920
2921/* This function is attached as a "thread_stop_requested" observer.
2922 Cleanup local state that assumed the PTID was to be resumed, and
2923 report the stop to the frontend. */
2924
2925static void
2926infrun_thread_stop_requested (ptid_t ptid)
2927{
2928 struct displaced_step_inferior_state *displaced;
2929
2930 /* PTID was requested to stop. Remove it from the displaced
2931 stepping queue, so we don't try to resume it automatically. */
2932
2933 for (displaced = displaced_step_inferior_states;
2934 displaced;
2935 displaced = displaced->next)
2936 {
2937 struct displaced_step_request *it, **prev_next_p;
2938
2939 it = displaced->step_request_queue;
2940 prev_next_p = &displaced->step_request_queue;
2941 while (it)
2942 {
2943 if (ptid_match (it->ptid, ptid))
2944 {
2945 *prev_next_p = it->next;
2946 it->next = NULL;
2947 xfree (it);
2948 }
2949 else
2950 {
2951 prev_next_p = &it->next;
2952 }
2953
2954 it = *prev_next_p;
2955 }
2956 }
2957
2958 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2959}
2960
2961static void
2962infrun_thread_thread_exit (struct thread_info *tp, int silent)
2963{
2964 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2965 nullify_last_target_wait_ptid ();
2966}
2967
2968/* Delete the step resume, single-step and longjmp/exception resume
2969 breakpoints of TP. */
2970
2971static void
2972delete_thread_infrun_breakpoints (struct thread_info *tp)
2973{
2974 delete_step_resume_breakpoint (tp);
2975 delete_exception_resume_breakpoint (tp);
2976 delete_single_step_breakpoints (tp);
2977}
2978
2979/* If the target still has execution, call FUNC for each thread that
2980 just stopped. In all-stop, that's all the non-exited threads; in
2981 non-stop, that's the current thread, only. */
2982
2983typedef void (*for_each_just_stopped_thread_callback_func)
2984 (struct thread_info *tp);
2985
2986static void
2987for_each_just_stopped_thread (for_each_just_stopped_thread_callback_func func)
2988{
2989 if (!target_has_execution || ptid_equal (inferior_ptid, null_ptid))
2990 return;
2991
2992 if (non_stop)
2993 {
2994 /* If in non-stop mode, only the current thread stopped. */
2995 func (inferior_thread ());
2996 }
2997 else
2998 {
2999 struct thread_info *tp;
3000
3001 /* In all-stop mode, all threads have stopped. */
3002 ALL_NON_EXITED_THREADS (tp)
3003 {
3004 func (tp);
3005 }
3006 }
3007}
3008
3009/* Delete the step resume and longjmp/exception resume breakpoints of
3010 the threads that just stopped. */
3011
3012static void
3013delete_just_stopped_threads_infrun_breakpoints (void)
3014{
3015 for_each_just_stopped_thread (delete_thread_infrun_breakpoints);
3016}
3017
3018/* Delete the single-step breakpoints of the threads that just
3019 stopped. */
3020
3021static void
3022delete_just_stopped_threads_single_step_breakpoints (void)
3023{
3024 for_each_just_stopped_thread (delete_single_step_breakpoints);
3025}
3026
3027/* A cleanup wrapper. */
3028
3029static void
3030delete_just_stopped_threads_infrun_breakpoints_cleanup (void *arg)
3031{
3032 delete_just_stopped_threads_infrun_breakpoints ();
3033}
3034
3035/* Pretty print the results of target_wait, for debugging purposes. */
3036
3037static void
3038print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
3039 const struct target_waitstatus *ws)
3040{
3041 char *status_string = target_waitstatus_to_string (ws);
3042 struct ui_file *tmp_stream = mem_fileopen ();
3043 char *text;
3044
3045 /* The text is split over several lines because it was getting too long.
3046 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
3047 output as a unit; we want only one timestamp printed if debug_timestamp
3048 is set. */
3049
3050 fprintf_unfiltered (tmp_stream,
3051 "infrun: target_wait (%d.%ld.%ld",
3052 ptid_get_pid (waiton_ptid),
3053 ptid_get_lwp (waiton_ptid),
3054 ptid_get_tid (waiton_ptid));
3055 if (ptid_get_pid (waiton_ptid) != -1)
3056 fprintf_unfiltered (tmp_stream,
3057 " [%s]", target_pid_to_str (waiton_ptid));
3058 fprintf_unfiltered (tmp_stream, ", status) =\n");
3059 fprintf_unfiltered (tmp_stream,
3060 "infrun: %d.%ld.%ld [%s],\n",
3061 ptid_get_pid (result_ptid),
3062 ptid_get_lwp (result_ptid),
3063 ptid_get_tid (result_ptid),
3064 target_pid_to_str (result_ptid));
3065 fprintf_unfiltered (tmp_stream,
3066 "infrun: %s\n",
3067 status_string);
3068
3069 text = ui_file_xstrdup (tmp_stream, NULL);
3070
3071 /* This uses %s in part to handle %'s in the text, but also to avoid
3072 a gcc error: the format attribute requires a string literal. */
3073 fprintf_unfiltered (gdb_stdlog, "%s", text);
3074
3075 xfree (status_string);
3076 xfree (text);
3077 ui_file_delete (tmp_stream);
3078}
3079
3080/* Prepare and stabilize the inferior for detaching it. E.g.,
3081 detaching while a thread is displaced stepping is a recipe for
3082 crashing it, as nothing would readjust the PC out of the scratch
3083 pad. */
3084
3085void
3086prepare_for_detach (void)
3087{
3088 struct inferior *inf = current_inferior ();
3089 ptid_t pid_ptid = pid_to_ptid (inf->pid);
3090 struct cleanup *old_chain_1;
3091 struct displaced_step_inferior_state *displaced;
3092
3093 displaced = get_displaced_stepping_state (inf->pid);
3094
3095 /* Is any thread of this process displaced stepping? If not,
3096 there's nothing else to do. */
3097 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
3098 return;
3099
3100 if (debug_infrun)
3101 fprintf_unfiltered (gdb_stdlog,
3102 "displaced-stepping in-process while detaching");
3103
3104 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
3105 inf->detaching = 1;
3106
3107 while (!ptid_equal (displaced->step_ptid, null_ptid))
3108 {
3109 struct cleanup *old_chain_2;
3110 struct execution_control_state ecss;
3111 struct execution_control_state *ecs;
3112
3113 ecs = &ecss;
3114 memset (ecs, 0, sizeof (*ecs));
3115
3116 overlay_cache_invalid = 1;
3117 /* Flush target cache before starting to handle each event.
3118 Target was running and cache could be stale. This is just a
3119 heuristic. Running threads may modify target memory, but we
3120 don't get any event. */
3121 target_dcache_invalidate ();
3122
3123 if (deprecated_target_wait_hook)
3124 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
3125 else
3126 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
3127
3128 if (debug_infrun)
3129 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
3130
3131 /* If an error happens while handling the event, propagate GDB's
3132 knowledge of the executing state to the frontend/user running
3133 state. */
3134 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
3135 &minus_one_ptid);
3136
3137 /* Now figure out what to do with the result of the result. */
3138 handle_inferior_event (ecs);
3139
3140 /* No error, don't finish the state yet. */
3141 discard_cleanups (old_chain_2);
3142
3143 /* Breakpoints and watchpoints are not installed on the target
3144 at this point, and signals are passed directly to the
3145 inferior, so this must mean the process is gone. */
3146 if (!ecs->wait_some_more)
3147 {
3148 discard_cleanups (old_chain_1);
3149 error (_("Program exited while detaching"));
3150 }
3151 }
3152
3153 discard_cleanups (old_chain_1);
3154}
3155
3156/* Wait for control to return from inferior to debugger.
3157
3158 If inferior gets a signal, we may decide to start it up again
3159 instead of returning. That is why there is a loop in this function.
3160 When this function actually returns it means the inferior
3161 should be left stopped and GDB should read more commands. */
3162
3163void
3164wait_for_inferior (void)
3165{
3166 struct cleanup *old_cleanups;
3167 struct cleanup *thread_state_chain;
3168
3169 if (debug_infrun)
3170 fprintf_unfiltered
3171 (gdb_stdlog, "infrun: wait_for_inferior ()\n");
3172
3173 old_cleanups
3174 = make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup,
3175 NULL);
3176
3177 /* If an error happens while handling the event, propagate GDB's
3178 knowledge of the executing state to the frontend/user running
3179 state. */
3180 thread_state_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
3181
3182 while (1)
3183 {
3184 struct execution_control_state ecss;
3185 struct execution_control_state *ecs = &ecss;
3186 ptid_t waiton_ptid = minus_one_ptid;
3187
3188 memset (ecs, 0, sizeof (*ecs));
3189
3190 overlay_cache_invalid = 1;
3191
3192 /* Flush target cache before starting to handle each event.
3193 Target was running and cache could be stale. This is just a
3194 heuristic. Running threads may modify target memory, but we
3195 don't get any event. */
3196 target_dcache_invalidate ();
3197
3198 if (deprecated_target_wait_hook)
3199 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
3200 else
3201 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
3202
3203 if (debug_infrun)
3204 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
3205
3206 /* Now figure out what to do with the result of the result. */
3207 handle_inferior_event (ecs);
3208
3209 if (!ecs->wait_some_more)
3210 break;
3211 }
3212
3213 /* No error, don't finish the state yet. */
3214 discard_cleanups (thread_state_chain);
3215
3216 do_cleanups (old_cleanups);
3217}
3218
3219/* Cleanup that reinstalls the readline callback handler, if the
3220 target is running in the background. If while handling the target
3221 event something triggered a secondary prompt, like e.g., a
3222 pagination prompt, we'll have removed the callback handler (see
3223 gdb_readline_wrapper_line). Need to do this as we go back to the
3224 event loop, ready to process further input. Note this has no
3225 effect if the handler hasn't actually been removed, because calling
3226 rl_callback_handler_install resets the line buffer, thus losing
3227 input. */
3228
3229static void
3230reinstall_readline_callback_handler_cleanup (void *arg)
3231{
3232 if (!interpreter_async)
3233 {
3234 /* We're not going back to the top level event loop yet. Don't
3235 install the readline callback, as it'd prep the terminal,
3236 readline-style (raw, noecho) (e.g., --batch). We'll install
3237 it the next time the prompt is displayed, when we're ready
3238 for input. */
3239 return;
3240 }
3241
3242 if (async_command_editing_p && !sync_execution)
3243 gdb_rl_callback_handler_reinstall ();
3244}
3245
3246/* Asynchronous version of wait_for_inferior. It is called by the
3247 event loop whenever a change of state is detected on the file
3248 descriptor corresponding to the target. It can be called more than
3249 once to complete a single execution command. In such cases we need
3250 to keep the state in a global variable ECSS. If it is the last time
3251 that this function is called for a single execution command, then
3252 report to the user that the inferior has stopped, and do the
3253 necessary cleanups. */
3254
3255void
3256fetch_inferior_event (void *client_data)
3257{
3258 struct execution_control_state ecss;
3259 struct execution_control_state *ecs = &ecss;
3260 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
3261 struct cleanup *ts_old_chain;
3262 int was_sync = sync_execution;
3263 int cmd_done = 0;
3264 ptid_t waiton_ptid = minus_one_ptid;
3265
3266 memset (ecs, 0, sizeof (*ecs));
3267
3268 /* End up with readline processing input, if necessary. */
3269 make_cleanup (reinstall_readline_callback_handler_cleanup, NULL);
3270
3271 /* We're handling a live event, so make sure we're doing live
3272 debugging. If we're looking at traceframes while the target is
3273 running, we're going to need to get back to that mode after
3274 handling the event. */
3275 if (non_stop)
3276 {
3277 make_cleanup_restore_current_traceframe ();
3278 set_current_traceframe (-1);
3279 }
3280
3281 if (non_stop)
3282 /* In non-stop mode, the user/frontend should not notice a thread
3283 switch due to internal events. Make sure we reverse to the
3284 user selected thread and frame after handling the event and
3285 running any breakpoint commands. */
3286 make_cleanup_restore_current_thread ();
3287
3288 overlay_cache_invalid = 1;
3289 /* Flush target cache before starting to handle each event. Target
3290 was running and cache could be stale. This is just a heuristic.
3291 Running threads may modify target memory, but we don't get any
3292 event. */
3293 target_dcache_invalidate ();
3294
3295 make_cleanup_restore_integer (&execution_direction);
3296 execution_direction = target_execution_direction ();
3297
3298 if (deprecated_target_wait_hook)
3299 ecs->ptid =
3300 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
3301 else
3302 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
3303
3304 if (debug_infrun)
3305 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
3306
3307 /* If an error happens while handling the event, propagate GDB's
3308 knowledge of the executing state to the frontend/user running
3309 state. */
3310 if (!non_stop)
3311 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
3312 else
3313 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
3314
3315 /* Get executed before make_cleanup_restore_current_thread above to apply
3316 still for the thread which has thrown the exception. */
3317 make_bpstat_clear_actions_cleanup ();
3318
3319 make_cleanup (delete_just_stopped_threads_infrun_breakpoints_cleanup, NULL);
3320
3321 /* Now figure out what to do with the result of the result. */
3322 handle_inferior_event (ecs);
3323
3324 if (!ecs->wait_some_more)
3325 {
3326 struct inferior *inf = find_inferior_ptid (ecs->ptid);
3327
3328 delete_just_stopped_threads_infrun_breakpoints ();
3329
3330 /* We may not find an inferior if this was a process exit. */
3331 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
3332 normal_stop ();
3333
3334 if (target_has_execution
3335 && ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
3336 && ecs->ws.kind != TARGET_WAITKIND_EXITED
3337 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3338 && ecs->event_thread->step_multi
3339 && ecs->event_thread->control.stop_step)
3340 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
3341 else
3342 {
3343 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
3344 cmd_done = 1;
3345 }
3346 }
3347
3348 /* No error, don't finish the thread states yet. */
3349 discard_cleanups (ts_old_chain);
3350
3351 /* Revert thread and frame. */
3352 do_cleanups (old_chain);
3353
3354 /* If the inferior was in sync execution mode, and now isn't,
3355 restore the prompt (a synchronous execution command has finished,
3356 and we're ready for input). */
3357 if (interpreter_async && was_sync && !sync_execution)
3358 observer_notify_sync_execution_done ();
3359
3360 if (cmd_done
3361 && !was_sync
3362 && exec_done_display_p
3363 && (ptid_equal (inferior_ptid, null_ptid)
3364 || !is_running (inferior_ptid)))
3365 printf_unfiltered (_("completed.\n"));
3366}
3367
3368/* Record the frame and location we're currently stepping through. */
3369void
3370set_step_info (struct frame_info *frame, struct symtab_and_line sal)
3371{
3372 struct thread_info *tp = inferior_thread ();
3373
3374 tp->control.step_frame_id = get_frame_id (frame);
3375 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
3376
3377 tp->current_symtab = sal.symtab;
3378 tp->current_line = sal.line;
3379}
3380
3381/* Clear context switchable stepping state. */
3382
3383void
3384init_thread_stepping_state (struct thread_info *tss)
3385{
3386 tss->stepped_breakpoint = 0;
3387 tss->stepping_over_breakpoint = 0;
3388 tss->stepping_over_watchpoint = 0;
3389 tss->step_after_step_resume_breakpoint = 0;
3390}
3391
3392/* Set the cached copy of the last ptid/waitstatus. */
3393
3394static void
3395set_last_target_status (ptid_t ptid, struct target_waitstatus status)
3396{
3397 target_last_wait_ptid = ptid;
3398 target_last_waitstatus = status;
3399}
3400
3401/* Return the cached copy of the last pid/waitstatus returned by
3402 target_wait()/deprecated_target_wait_hook(). The data is actually
3403 cached by handle_inferior_event(), which gets called immediately
3404 after target_wait()/deprecated_target_wait_hook(). */
3405
3406void
3407get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
3408{
3409 *ptidp = target_last_wait_ptid;
3410 *status = target_last_waitstatus;
3411}
3412
3413void
3414nullify_last_target_wait_ptid (void)
3415{
3416 target_last_wait_ptid = minus_one_ptid;
3417}
3418
3419/* Switch thread contexts. */
3420
3421static void
3422context_switch (ptid_t ptid)
3423{
3424 if (debug_infrun && !ptid_equal (ptid, inferior_ptid))
3425 {
3426 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
3427 target_pid_to_str (inferior_ptid));
3428 fprintf_unfiltered (gdb_stdlog, "to %s\n",
3429 target_pid_to_str (ptid));
3430 }
3431
3432 switch_to_thread (ptid);
3433}
3434
3435static void
3436adjust_pc_after_break (struct execution_control_state *ecs)
3437{
3438 struct regcache *regcache;
3439 struct gdbarch *gdbarch;
3440 struct address_space *aspace;
3441 CORE_ADDR breakpoint_pc, decr_pc;
3442
3443 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
3444 we aren't, just return.
3445
3446 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
3447 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
3448 implemented by software breakpoints should be handled through the normal
3449 breakpoint layer.
3450
3451 NOTE drow/2004-01-31: On some targets, breakpoints may generate
3452 different signals (SIGILL or SIGEMT for instance), but it is less
3453 clear where the PC is pointing afterwards. It may not match
3454 gdbarch_decr_pc_after_break. I don't know any specific target that
3455 generates these signals at breakpoints (the code has been in GDB since at
3456 least 1992) so I can not guess how to handle them here.
3457
3458 In earlier versions of GDB, a target with
3459 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
3460 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
3461 target with both of these set in GDB history, and it seems unlikely to be
3462 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
3463
3464 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
3465 return;
3466
3467 if (ecs->ws.value.sig != GDB_SIGNAL_TRAP)
3468 return;
3469
3470 /* In reverse execution, when a breakpoint is hit, the instruction
3471 under it has already been de-executed. The reported PC always
3472 points at the breakpoint address, so adjusting it further would
3473 be wrong. E.g., consider this case on a decr_pc_after_break == 1
3474 architecture:
3475
3476 B1 0x08000000 : INSN1
3477 B2 0x08000001 : INSN2
3478 0x08000002 : INSN3
3479 PC -> 0x08000003 : INSN4
3480
3481 Say you're stopped at 0x08000003 as above. Reverse continuing
3482 from that point should hit B2 as below. Reading the PC when the
3483 SIGTRAP is reported should read 0x08000001 and INSN2 should have
3484 been de-executed already.
3485
3486 B1 0x08000000 : INSN1
3487 B2 PC -> 0x08000001 : INSN2
3488 0x08000002 : INSN3
3489 0x08000003 : INSN4
3490
3491 We can't apply the same logic as for forward execution, because
3492 we would wrongly adjust the PC to 0x08000000, since there's a
3493 breakpoint at PC - 1. We'd then report a hit on B1, although
3494 INSN1 hadn't been de-executed yet. Doing nothing is the correct
3495 behaviour. */
3496 if (execution_direction == EXEC_REVERSE)
3497 return;
3498
3499 /* If the target can tell whether the thread hit a SW breakpoint,
3500 trust it. Targets that can tell also adjust the PC
3501 themselves. */
3502 if (target_supports_stopped_by_sw_breakpoint ())
3503 return;
3504
3505 /* Note that relying on whether a breakpoint is planted in memory to
3506 determine this can fail. E.g,. the breakpoint could have been
3507 removed since. Or the thread could have been told to step an
3508 instruction the size of a breakpoint instruction, and only
3509 _after_ was a breakpoint inserted at its address. */
3510
3511 /* If this target does not decrement the PC after breakpoints, then
3512 we have nothing to do. */
3513 regcache = get_thread_regcache (ecs->ptid);
3514 gdbarch = get_regcache_arch (regcache);
3515
3516 decr_pc = gdbarch_decr_pc_after_break (gdbarch);
3517 if (decr_pc == 0)
3518 return;
3519
3520 aspace = get_regcache_aspace (regcache);
3521
3522 /* Find the location where (if we've hit a breakpoint) the
3523 breakpoint would be. */
3524 breakpoint_pc = regcache_read_pc (regcache) - decr_pc;
3525
3526 /* If the target can't tell whether a software breakpoint triggered,
3527 fallback to figuring it out based on breakpoints we think were
3528 inserted in the target, and on whether the thread was stepped or
3529 continued. */
3530
3531 /* Check whether there actually is a software breakpoint inserted at
3532 that location.
3533
3534 If in non-stop mode, a race condition is possible where we've
3535 removed a breakpoint, but stop events for that breakpoint were
3536 already queued and arrive later. To suppress those spurious
3537 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
3538 and retire them after a number of stop events are reported. Note
3539 this is an heuristic and can thus get confused. The real fix is
3540 to get the "stopped by SW BP and needs adjustment" info out of
3541 the target/kernel (and thus never reach here; see above). */
3542 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
3543 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
3544 {
3545 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
3546
3547 if (record_full_is_used ())
3548 record_full_gdb_operation_disable_set ();
3549
3550 /* When using hardware single-step, a SIGTRAP is reported for both
3551 a completed single-step and a software breakpoint. Need to
3552 differentiate between the two, as the latter needs adjusting
3553 but the former does not.
3554
3555 The SIGTRAP can be due to a completed hardware single-step only if
3556 - we didn't insert software single-step breakpoints
3557 - this thread is currently being stepped
3558
3559 If any of these events did not occur, we must have stopped due
3560 to hitting a software breakpoint, and have to back up to the
3561 breakpoint address.
3562
3563 As a special case, we could have hardware single-stepped a
3564 software breakpoint. In this case (prev_pc == breakpoint_pc),
3565 we also need to back up to the breakpoint address. */
3566
3567 if (thread_has_single_step_breakpoints_set (ecs->event_thread)
3568 || !currently_stepping (ecs->event_thread)
3569 || (ecs->event_thread->stepped_breakpoint
3570 && ecs->event_thread->prev_pc == breakpoint_pc))
3571 regcache_write_pc (regcache, breakpoint_pc);
3572
3573 do_cleanups (old_cleanups);
3574 }
3575}
3576
3577static int
3578stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
3579{
3580 for (frame = get_prev_frame (frame);
3581 frame != NULL;
3582 frame = get_prev_frame (frame))
3583 {
3584 if (frame_id_eq (get_frame_id (frame), step_frame_id))
3585 return 1;
3586 if (get_frame_type (frame) != INLINE_FRAME)
3587 break;
3588 }
3589
3590 return 0;
3591}
3592
3593/* Auxiliary function that handles syscall entry/return events.
3594 It returns 1 if the inferior should keep going (and GDB
3595 should ignore the event), or 0 if the event deserves to be
3596 processed. */
3597
3598static int
3599handle_syscall_event (struct execution_control_state *ecs)
3600{
3601 struct regcache *regcache;
3602 int syscall_number;
3603
3604 if (!ptid_equal (ecs->ptid, inferior_ptid))
3605 context_switch (ecs->ptid);
3606
3607 regcache = get_thread_regcache (ecs->ptid);
3608 syscall_number = ecs->ws.value.syscall_number;
3609 stop_pc = regcache_read_pc (regcache);
3610
3611 if (catch_syscall_enabled () > 0
3612 && catching_syscall_number (syscall_number) > 0)
3613 {
3614 if (debug_infrun)
3615 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
3616 syscall_number);
3617
3618 ecs->event_thread->control.stop_bpstat
3619 = bpstat_stop_status (get_regcache_aspace (regcache),
3620 stop_pc, ecs->ptid, &ecs->ws);
3621
3622 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
3623 {
3624 /* Catchpoint hit. */
3625 return 0;
3626 }
3627 }
3628
3629 /* If no catchpoint triggered for this, then keep going. */
3630 keep_going (ecs);
3631 return 1;
3632}
3633
3634/* Lazily fill in the execution_control_state's stop_func_* fields. */
3635
3636static void
3637fill_in_stop_func (struct gdbarch *gdbarch,
3638 struct execution_control_state *ecs)
3639{
3640 if (!ecs->stop_func_filled_in)
3641 {
3642 /* Don't care about return value; stop_func_start and stop_func_name
3643 will both be 0 if it doesn't work. */
3644 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3645 &ecs->stop_func_start, &ecs->stop_func_end);
3646 ecs->stop_func_start
3647 += gdbarch_deprecated_function_start_offset (gdbarch);
3648
3649 if (gdbarch_skip_entrypoint_p (gdbarch))
3650 ecs->stop_func_start = gdbarch_skip_entrypoint (gdbarch,
3651 ecs->stop_func_start);
3652
3653 ecs->stop_func_filled_in = 1;
3654 }
3655}
3656
3657
3658/* Return the STOP_SOON field of the inferior pointed at by PTID. */
3659
3660static enum stop_kind
3661get_inferior_stop_soon (ptid_t ptid)
3662{
3663 struct inferior *inf = find_inferior_ptid (ptid);
3664
3665 gdb_assert (inf != NULL);
3666 return inf->control.stop_soon;
3667}
3668
3669/* Given an execution control state that has been freshly filled in by
3670 an event from the inferior, figure out what it means and take
3671 appropriate action.
3672
3673 The alternatives are:
3674
3675 1) stop_waiting and return; to really stop and return to the
3676 debugger.
3677
3678 2) keep_going and return; to wait for the next event (set
3679 ecs->event_thread->stepping_over_breakpoint to 1 to single step
3680 once). */
3681
3682static void
3683handle_inferior_event_1 (struct execution_control_state *ecs)
3684{
3685 enum stop_kind stop_soon;
3686
3687 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3688 {
3689 /* We had an event in the inferior, but we are not interested in
3690 handling it at this level. The lower layers have already
3691 done what needs to be done, if anything.
3692
3693 One of the possible circumstances for this is when the
3694 inferior produces output for the console. The inferior has
3695 not stopped, and we are ignoring the event. Another possible
3696 circumstance is any event which the lower level knows will be
3697 reported multiple times without an intervening resume. */
3698 if (debug_infrun)
3699 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3700 prepare_to_wait (ecs);
3701 return;
3702 }
3703
3704 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED
3705 && target_can_async_p () && !sync_execution)
3706 {
3707 /* There were no unwaited-for children left in the target, but,
3708 we're not synchronously waiting for events either. Just
3709 ignore. Otherwise, if we were running a synchronous
3710 execution command, we need to cancel it and give the user
3711 back the terminal. */
3712 if (debug_infrun)
3713 fprintf_unfiltered (gdb_stdlog,
3714 "infrun: TARGET_WAITKIND_NO_RESUMED (ignoring)\n");
3715 prepare_to_wait (ecs);
3716 return;
3717 }
3718
3719 /* Cache the last pid/waitstatus. */
3720 set_last_target_status (ecs->ptid, ecs->ws);
3721
3722 /* Always clear state belonging to the previous time we stopped. */
3723 stop_stack_dummy = STOP_NONE;
3724
3725 if (ecs->ws.kind == TARGET_WAITKIND_NO_RESUMED)
3726 {
3727 /* No unwaited-for children left. IOW, all resumed children
3728 have exited. */
3729 if (debug_infrun)
3730 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_RESUMED\n");
3731
3732 stop_print_frame = 0;
3733 stop_waiting (ecs);
3734 return;
3735 }
3736
3737 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3738 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3739 {
3740 ecs->event_thread = find_thread_ptid (ecs->ptid);
3741 /* If it's a new thread, add it to the thread database. */
3742 if (ecs->event_thread == NULL)
3743 ecs->event_thread = add_thread (ecs->ptid);
3744
3745 /* Disable range stepping. If the next step request could use a
3746 range, this will be end up re-enabled then. */
3747 ecs->event_thread->control.may_range_step = 0;
3748 }
3749
3750 /* Dependent on valid ECS->EVENT_THREAD. */
3751 adjust_pc_after_break (ecs);
3752
3753 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3754 reinit_frame_cache ();
3755
3756 breakpoint_retire_moribund ();
3757
3758 /* First, distinguish signals caused by the debugger from signals
3759 that have to do with the program's own actions. Note that
3760 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3761 on the operating system version. Here we detect when a SIGILL or
3762 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3763 something similar for SIGSEGV, since a SIGSEGV will be generated
3764 when we're trying to execute a breakpoint instruction on a
3765 non-executable stack. This happens for call dummy breakpoints
3766 for architectures like SPARC that place call dummies on the
3767 stack. */
3768 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3769 && (ecs->ws.value.sig == GDB_SIGNAL_ILL
3770 || ecs->ws.value.sig == GDB_SIGNAL_SEGV
3771 || ecs->ws.value.sig == GDB_SIGNAL_EMT))
3772 {
3773 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3774
3775 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3776 regcache_read_pc (regcache)))
3777 {
3778 if (debug_infrun)
3779 fprintf_unfiltered (gdb_stdlog,
3780 "infrun: Treating signal as SIGTRAP\n");
3781 ecs->ws.value.sig = GDB_SIGNAL_TRAP;
3782 }
3783 }
3784
3785 /* Mark the non-executing threads accordingly. In all-stop, all
3786 threads of all processes are stopped when we get any event
3787 reported. In non-stop mode, only the event thread stops. If
3788 we're handling a process exit in non-stop mode, there's nothing
3789 to do, as threads of the dead process are gone, and threads of
3790 any other process were left running. */
3791 if (!non_stop)
3792 set_executing (minus_one_ptid, 0);
3793 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3794 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3795 set_executing (ecs->ptid, 0);
3796
3797 switch (ecs->ws.kind)
3798 {
3799 case TARGET_WAITKIND_LOADED:
3800 if (debug_infrun)
3801 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3802 if (!ptid_equal (ecs->ptid, inferior_ptid))
3803 context_switch (ecs->ptid);
3804 /* Ignore gracefully during startup of the inferior, as it might
3805 be the shell which has just loaded some objects, otherwise
3806 add the symbols for the newly loaded objects. Also ignore at
3807 the beginning of an attach or remote session; we will query
3808 the full list of libraries once the connection is
3809 established. */
3810
3811 stop_soon = get_inferior_stop_soon (ecs->ptid);
3812 if (stop_soon == NO_STOP_QUIETLY)
3813 {
3814 struct regcache *regcache;
3815
3816 regcache = get_thread_regcache (ecs->ptid);
3817
3818 handle_solib_event ();
3819
3820 ecs->event_thread->control.stop_bpstat
3821 = bpstat_stop_status (get_regcache_aspace (regcache),
3822 stop_pc, ecs->ptid, &ecs->ws);
3823
3824 if (bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
3825 {
3826 /* A catchpoint triggered. */
3827 process_event_stop_test (ecs);
3828 return;
3829 }
3830
3831 /* If requested, stop when the dynamic linker notifies
3832 gdb of events. This allows the user to get control
3833 and place breakpoints in initializer routines for
3834 dynamically loaded objects (among other things). */
3835 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
3836 if (stop_on_solib_events)
3837 {
3838 /* Make sure we print "Stopped due to solib-event" in
3839 normal_stop. */
3840 stop_print_frame = 1;
3841
3842 stop_waiting (ecs);
3843 return;
3844 }
3845 }
3846
3847 /* If we are skipping through a shell, or through shared library
3848 loading that we aren't interested in, resume the program. If
3849 we're running the program normally, also resume. */
3850 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3851 {
3852 /* Loading of shared libraries might have changed breakpoint
3853 addresses. Make sure new breakpoints are inserted. */
3854 if (stop_soon == NO_STOP_QUIETLY)
3855 insert_breakpoints ();
3856 resume (GDB_SIGNAL_0);
3857 prepare_to_wait (ecs);
3858 return;
3859 }
3860
3861 /* But stop if we're attaching or setting up a remote
3862 connection. */
3863 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
3864 || stop_soon == STOP_QUIETLY_REMOTE)
3865 {
3866 if (debug_infrun)
3867 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
3868 stop_waiting (ecs);
3869 return;
3870 }
3871
3872 internal_error (__FILE__, __LINE__,
3873 _("unhandled stop_soon: %d"), (int) stop_soon);
3874
3875 case TARGET_WAITKIND_SPURIOUS:
3876 if (debug_infrun)
3877 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3878 if (!ptid_equal (ecs->ptid, inferior_ptid))
3879 context_switch (ecs->ptid);
3880 resume (GDB_SIGNAL_0);
3881 prepare_to_wait (ecs);
3882 return;
3883
3884 case TARGET_WAITKIND_EXITED:
3885 case TARGET_WAITKIND_SIGNALLED:
3886 if (debug_infrun)
3887 {
3888 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3889 fprintf_unfiltered (gdb_stdlog,
3890 "infrun: TARGET_WAITKIND_EXITED\n");
3891 else
3892 fprintf_unfiltered (gdb_stdlog,
3893 "infrun: TARGET_WAITKIND_SIGNALLED\n");
3894 }
3895
3896 inferior_ptid = ecs->ptid;
3897 set_current_inferior (find_inferior_ptid (ecs->ptid));
3898 set_current_program_space (current_inferior ()->pspace);
3899 handle_vfork_child_exec_or_exit (0);
3900 target_terminal_ours (); /* Must do this before mourn anyway. */
3901
3902 /* Clearing any previous state of convenience variables. */
3903 clear_exit_convenience_vars ();
3904
3905 if (ecs->ws.kind == TARGET_WAITKIND_EXITED)
3906 {
3907 /* Record the exit code in the convenience variable $_exitcode, so
3908 that the user can inspect this again later. */
3909 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3910 (LONGEST) ecs->ws.value.integer);
3911
3912 /* Also record this in the inferior itself. */
3913 current_inferior ()->has_exit_code = 1;
3914 current_inferior ()->exit_code = (LONGEST) ecs->ws.value.integer;
3915
3916 /* Support the --return-child-result option. */
3917 return_child_result_value = ecs->ws.value.integer;
3918
3919 observer_notify_exited (ecs->ws.value.integer);
3920 }
3921 else
3922 {
3923 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3924 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3925
3926 if (gdbarch_gdb_signal_to_target_p (gdbarch))
3927 {
3928 /* Set the value of the internal variable $_exitsignal,
3929 which holds the signal uncaught by the inferior. */
3930 set_internalvar_integer (lookup_internalvar ("_exitsignal"),
3931 gdbarch_gdb_signal_to_target (gdbarch,
3932 ecs->ws.value.sig));
3933 }
3934 else
3935 {
3936 /* We don't have access to the target's method used for
3937 converting between signal numbers (GDB's internal
3938 representation <-> target's representation).
3939 Therefore, we cannot do a good job at displaying this
3940 information to the user. It's better to just warn
3941 her about it (if infrun debugging is enabled), and
3942 give up. */
3943 if (debug_infrun)
3944 fprintf_filtered (gdb_stdlog, _("\
3945Cannot fill $_exitsignal with the correct signal number.\n"));
3946 }
3947
3948 observer_notify_signal_exited (ecs->ws.value.sig);
3949 }
3950
3951 gdb_flush (gdb_stdout);
3952 target_mourn_inferior ();
3953 stop_print_frame = 0;
3954 stop_waiting (ecs);
3955 return;
3956
3957 /* The following are the only cases in which we keep going;
3958 the above cases end in a continue or goto. */
3959 case TARGET_WAITKIND_FORKED:
3960 case TARGET_WAITKIND_VFORKED:
3961 if (debug_infrun)
3962 {
3963 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3964 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3965 else
3966 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_VFORKED\n");
3967 }
3968
3969 /* Check whether the inferior is displaced stepping. */
3970 {
3971 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3972 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3973 struct displaced_step_inferior_state *displaced
3974 = get_displaced_stepping_state (ptid_get_pid (ecs->ptid));
3975
3976 /* If checking displaced stepping is supported, and thread
3977 ecs->ptid is displaced stepping. */
3978 if (displaced && ptid_equal (displaced->step_ptid, ecs->ptid))
3979 {
3980 struct inferior *parent_inf
3981 = find_inferior_ptid (ecs->ptid);
3982 struct regcache *child_regcache;
3983 CORE_ADDR parent_pc;
3984
3985 /* GDB has got TARGET_WAITKIND_FORKED or TARGET_WAITKIND_VFORKED,
3986 indicating that the displaced stepping of syscall instruction
3987 has been done. Perform cleanup for parent process here. Note
3988 that this operation also cleans up the child process for vfork,
3989 because their pages are shared. */
3990 displaced_step_fixup (ecs->ptid, GDB_SIGNAL_TRAP);
3991
3992 if (ecs->ws.kind == TARGET_WAITKIND_FORKED)
3993 {
3994 /* Restore scratch pad for child process. */
3995 displaced_step_restore (displaced, ecs->ws.value.related_pid);
3996 }
3997
3998 /* Since the vfork/fork syscall instruction was executed in the scratchpad,
3999 the child's PC is also within the scratchpad. Set the child's PC
4000 to the parent's PC value, which has already been fixed up.
4001 FIXME: we use the parent's aspace here, although we're touching
4002 the child, because the child hasn't been added to the inferior
4003 list yet at this point. */
4004
4005 child_regcache
4006 = get_thread_arch_aspace_regcache (ecs->ws.value.related_pid,
4007 gdbarch,
4008 parent_inf->aspace);
4009 /* Read PC value of parent process. */
4010 parent_pc = regcache_read_pc (regcache);
4011
4012 if (debug_displaced)
4013 fprintf_unfiltered (gdb_stdlog,
4014 "displaced: write child pc from %s to %s\n",
4015 paddress (gdbarch,
4016 regcache_read_pc (child_regcache)),
4017 paddress (gdbarch, parent_pc));
4018
4019 regcache_write_pc (child_regcache, parent_pc);
4020 }
4021 }
4022
4023 if (!ptid_equal (ecs->ptid, inferior_ptid))
4024 context_switch (ecs->ptid);
4025
4026 /* Immediately detach breakpoints from the child before there's
4027 any chance of letting the user delete breakpoints from the
4028 breakpoint lists. If we don't do this early, it's easy to
4029 leave left over traps in the child, vis: "break foo; catch
4030 fork; c; <fork>; del; c; <child calls foo>". We only follow
4031 the fork on the last `continue', and by that time the
4032 breakpoint at "foo" is long gone from the breakpoint table.
4033 If we vforked, then we don't need to unpatch here, since both
4034 parent and child are sharing the same memory pages; we'll
4035 need to unpatch at follow/detach time instead to be certain
4036 that new breakpoints added between catchpoint hit time and
4037 vfork follow are detached. */
4038 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
4039 {
4040 /* This won't actually modify the breakpoint list, but will
4041 physically remove the breakpoints from the child. */
4042 detach_breakpoints (ecs->ws.value.related_pid);
4043 }
4044
4045 delete_just_stopped_threads_single_step_breakpoints ();
4046
4047 /* In case the event is caught by a catchpoint, remember that
4048 the event is to be followed at the next resume of the thread,
4049 and not immediately. */
4050 ecs->event_thread->pending_follow = ecs->ws;
4051
4052 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4053
4054 ecs->event_thread->control.stop_bpstat
4055 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4056 stop_pc, ecs->ptid, &ecs->ws);
4057
4058 /* If no catchpoint triggered for this, then keep going. Note
4059 that we're interested in knowing the bpstat actually causes a
4060 stop, not just if it may explain the signal. Software
4061 watchpoints, for example, always appear in the bpstat. */
4062 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
4063 {
4064 ptid_t parent;
4065 ptid_t child;
4066 int should_resume;
4067 int follow_child
4068 = (follow_fork_mode_string == follow_fork_mode_child);
4069
4070 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4071
4072 should_resume = follow_fork ();
4073
4074 parent = ecs->ptid;
4075 child = ecs->ws.value.related_pid;
4076
4077 /* In non-stop mode, also resume the other branch. */
4078 if (non_stop && !detach_fork)
4079 {
4080 if (follow_child)
4081 switch_to_thread (parent);
4082 else
4083 switch_to_thread (child);
4084
4085 ecs->event_thread = inferior_thread ();
4086 ecs->ptid = inferior_ptid;
4087 keep_going (ecs);
4088 }
4089
4090 if (follow_child)
4091 switch_to_thread (child);
4092 else
4093 switch_to_thread (parent);
4094
4095 ecs->event_thread = inferior_thread ();
4096 ecs->ptid = inferior_ptid;
4097
4098 if (should_resume)
4099 keep_going (ecs);
4100 else
4101 stop_waiting (ecs);
4102 return;
4103 }
4104 process_event_stop_test (ecs);
4105 return;
4106
4107 case TARGET_WAITKIND_VFORK_DONE:
4108 /* Done with the shared memory region. Re-insert breakpoints in
4109 the parent, and keep going. */
4110
4111 if (debug_infrun)
4112 fprintf_unfiltered (gdb_stdlog,
4113 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
4114
4115 if (!ptid_equal (ecs->ptid, inferior_ptid))
4116 context_switch (ecs->ptid);
4117
4118 current_inferior ()->waiting_for_vfork_done = 0;
4119 current_inferior ()->pspace->breakpoints_not_allowed = 0;
4120 /* This also takes care of reinserting breakpoints in the
4121 previously locked inferior. */
4122 keep_going (ecs);
4123 return;
4124
4125 case TARGET_WAITKIND_EXECD:
4126 if (debug_infrun)
4127 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
4128
4129 if (!ptid_equal (ecs->ptid, inferior_ptid))
4130 context_switch (ecs->ptid);
4131
4132 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4133
4134 /* Do whatever is necessary to the parent branch of the vfork. */
4135 handle_vfork_child_exec_or_exit (1);
4136
4137 /* This causes the eventpoints and symbol table to be reset.
4138 Must do this now, before trying to determine whether to
4139 stop. */
4140 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
4141
4142 ecs->event_thread->control.stop_bpstat
4143 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4144 stop_pc, ecs->ptid, &ecs->ws);
4145
4146 /* Note that this may be referenced from inside
4147 bpstat_stop_status above, through inferior_has_execd. */
4148 xfree (ecs->ws.value.execd_pathname);
4149 ecs->ws.value.execd_pathname = NULL;
4150
4151 /* If no catchpoint triggered for this, then keep going. */
4152 if (!bpstat_causes_stop (ecs->event_thread->control.stop_bpstat))
4153 {
4154 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4155 keep_going (ecs);
4156 return;
4157 }
4158 process_event_stop_test (ecs);
4159 return;
4160
4161 /* Be careful not to try to gather much state about a thread
4162 that's in a syscall. It's frequently a losing proposition. */
4163 case TARGET_WAITKIND_SYSCALL_ENTRY:
4164 if (debug_infrun)
4165 fprintf_unfiltered (gdb_stdlog,
4166 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
4167 /* Getting the current syscall number. */
4168 if (handle_syscall_event (ecs) == 0)
4169 process_event_stop_test (ecs);
4170 return;
4171
4172 /* Before examining the threads further, step this thread to
4173 get it entirely out of the syscall. (We get notice of the
4174 event when the thread is just on the verge of exiting a
4175 syscall. Stepping one instruction seems to get it back
4176 into user code.) */
4177 case TARGET_WAITKIND_SYSCALL_RETURN:
4178 if (debug_infrun)
4179 fprintf_unfiltered (gdb_stdlog,
4180 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
4181 if (handle_syscall_event (ecs) == 0)
4182 process_event_stop_test (ecs);
4183 return;
4184
4185 case TARGET_WAITKIND_STOPPED:
4186 if (debug_infrun)
4187 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
4188 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
4189 handle_signal_stop (ecs);
4190 return;
4191
4192 case TARGET_WAITKIND_NO_HISTORY:
4193 if (debug_infrun)
4194 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_NO_HISTORY\n");
4195 /* Reverse execution: target ran out of history info. */
4196
4197 delete_just_stopped_threads_single_step_breakpoints ();
4198 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4199 observer_notify_no_history ();
4200 stop_waiting (ecs);
4201 return;
4202 }
4203}
4204
4205/* A wrapper around handle_inferior_event_1, which also makes sure
4206 that all temporary struct value objects that were created during
4207 the handling of the event get deleted at the end. */
4208
4209static void
4210handle_inferior_event (struct execution_control_state *ecs)
4211{
4212 struct value *mark = value_mark ();
4213
4214 handle_inferior_event_1 (ecs);
4215 /* Purge all temporary values created during the event handling,
4216 as it could be a long time before we return to the command level
4217 where such values would otherwise be purged. */
4218 value_free_to_mark (mark);
4219}
4220
4221/* Come here when the program has stopped with a signal. */
4222
4223static void
4224handle_signal_stop (struct execution_control_state *ecs)
4225{
4226 struct frame_info *frame;
4227 struct gdbarch *gdbarch;
4228 int stopped_by_watchpoint;
4229 enum stop_kind stop_soon;
4230 int random_signal;
4231
4232 gdb_assert (ecs->ws.kind == TARGET_WAITKIND_STOPPED);
4233
4234 /* Do we need to clean up the state of a thread that has
4235 completed a displaced single-step? (Doing so usually affects
4236 the PC, so do it here, before we set stop_pc.) */
4237 displaced_step_fixup (ecs->ptid,
4238 ecs->event_thread->suspend.stop_signal);
4239
4240 /* If we either finished a single-step or hit a breakpoint, but
4241 the user wanted this thread to be stopped, pretend we got a
4242 SIG0 (generic unsignaled stop). */
4243 if (ecs->event_thread->stop_requested
4244 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
4245 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4246
4247 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
4248
4249 if (debug_infrun)
4250 {
4251 struct regcache *regcache = get_thread_regcache (ecs->ptid);
4252 struct gdbarch *gdbarch = get_regcache_arch (regcache);
4253 struct cleanup *old_chain = save_inferior_ptid ();
4254
4255 inferior_ptid = ecs->ptid;
4256
4257 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
4258 paddress (gdbarch, stop_pc));
4259 if (target_stopped_by_watchpoint ())
4260 {
4261 CORE_ADDR addr;
4262
4263 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
4264
4265 if (target_stopped_data_address (&current_target, &addr))
4266 fprintf_unfiltered (gdb_stdlog,
4267 "infrun: stopped data address = %s\n",
4268 paddress (gdbarch, addr));
4269 else
4270 fprintf_unfiltered (gdb_stdlog,
4271 "infrun: (no data address available)\n");
4272 }
4273
4274 do_cleanups (old_chain);
4275 }
4276
4277 /* This is originated from start_remote(), start_inferior() and
4278 shared libraries hook functions. */
4279 stop_soon = get_inferior_stop_soon (ecs->ptid);
4280 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
4281 {
4282 if (!ptid_equal (ecs->ptid, inferior_ptid))
4283 context_switch (ecs->ptid);
4284 if (debug_infrun)
4285 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
4286 stop_print_frame = 1;
4287 stop_waiting (ecs);
4288 return;
4289 }
4290
4291 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4292 && stop_after_trap)
4293 {
4294 if (!ptid_equal (ecs->ptid, inferior_ptid))
4295 context_switch (ecs->ptid);
4296 if (debug_infrun)
4297 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
4298 stop_print_frame = 0;
4299 stop_waiting (ecs);
4300 return;
4301 }
4302
4303 /* This originates from attach_command(). We need to overwrite
4304 the stop_signal here, because some kernels don't ignore a
4305 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4306 See more comments in inferior.h. On the other hand, if we
4307 get a non-SIGSTOP, report it to the user - assume the backend
4308 will handle the SIGSTOP if it should show up later.
4309
4310 Also consider that the attach is complete when we see a
4311 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4312 target extended-remote report it instead of a SIGSTOP
4313 (e.g. gdbserver). We already rely on SIGTRAP being our
4314 signal, so this is no exception.
4315
4316 Also consider that the attach is complete when we see a
4317 GDB_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4318 the target to stop all threads of the inferior, in case the
4319 low level attach operation doesn't stop them implicitly. If
4320 they weren't stopped implicitly, then the stub will report a
4321 GDB_SIGNAL_0, meaning: stopped for no particular reason
4322 other than GDB's request. */
4323 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
4324 && (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_STOP
4325 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4326 || ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_0))
4327 {
4328 stop_print_frame = 1;
4329 stop_waiting (ecs);
4330 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4331 return;
4332 }
4333
4334 /* See if something interesting happened to the non-current thread. If
4335 so, then switch to that thread. */
4336 if (!ptid_equal (ecs->ptid, inferior_ptid))
4337 {
4338 if (debug_infrun)
4339 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
4340
4341 context_switch (ecs->ptid);
4342
4343 if (deprecated_context_hook)
4344 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
4345 }
4346
4347 /* At this point, get hold of the now-current thread's frame. */
4348 frame = get_current_frame ();
4349 gdbarch = get_frame_arch (frame);
4350
4351 /* Pull the single step breakpoints out of the target. */
4352 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP)
4353 {
4354 struct regcache *regcache;
4355 struct address_space *aspace;
4356 CORE_ADDR pc;
4357
4358 regcache = get_thread_regcache (ecs->ptid);
4359 aspace = get_regcache_aspace (regcache);
4360 pc = regcache_read_pc (regcache);
4361
4362 /* However, before doing so, if this single-step breakpoint was
4363 actually for another thread, set this thread up for moving
4364 past it. */
4365 if (!thread_has_single_step_breakpoint_here (ecs->event_thread,
4366 aspace, pc))
4367 {
4368 if (single_step_breakpoint_inserted_here_p (aspace, pc))
4369 {
4370 if (debug_infrun)
4371 {
4372 fprintf_unfiltered (gdb_stdlog,
4373 "infrun: [%s] hit another thread's "
4374 "single-step breakpoint\n",
4375 target_pid_to_str (ecs->ptid));
4376 }
4377 ecs->hit_singlestep_breakpoint = 1;
4378 }
4379 }
4380 else
4381 {
4382 if (debug_infrun)
4383 {
4384 fprintf_unfiltered (gdb_stdlog,
4385 "infrun: [%s] hit its "
4386 "single-step breakpoint\n",
4387 target_pid_to_str (ecs->ptid));
4388 }
4389 }
4390 }
4391 delete_just_stopped_threads_single_step_breakpoints ();
4392
4393 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4394 && ecs->event_thread->control.trap_expected
4395 && ecs->event_thread->stepping_over_watchpoint)
4396 stopped_by_watchpoint = 0;
4397 else
4398 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
4399
4400 /* If necessary, step over this watchpoint. We'll be back to display
4401 it in a moment. */
4402 if (stopped_by_watchpoint
4403 && (target_have_steppable_watchpoint
4404 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
4405 {
4406 /* At this point, we are stopped at an instruction which has
4407 attempted to write to a piece of memory under control of
4408 a watchpoint. The instruction hasn't actually executed
4409 yet. If we were to evaluate the watchpoint expression
4410 now, we would get the old value, and therefore no change
4411 would seem to have occurred.
4412
4413 In order to make watchpoints work `right', we really need
4414 to complete the memory write, and then evaluate the
4415 watchpoint expression. We do this by single-stepping the
4416 target.
4417
4418 It may not be necessary to disable the watchpoint to step over
4419 it. For example, the PA can (with some kernel cooperation)
4420 single step over a watchpoint without disabling the watchpoint.
4421
4422 It is far more common to need to disable a watchpoint to step
4423 the inferior over it. If we have non-steppable watchpoints,
4424 we must disable the current watchpoint; it's simplest to
4425 disable all watchpoints.
4426
4427 Any breakpoint at PC must also be stepped over -- if there's
4428 one, it will have already triggered before the watchpoint
4429 triggered, and we either already reported it to the user, or
4430 it didn't cause a stop and we called keep_going. In either
4431 case, if there was a breakpoint at PC, we must be trying to
4432 step past it. */
4433 ecs->event_thread->stepping_over_watchpoint = 1;
4434 keep_going (ecs);
4435 return;
4436 }
4437
4438 ecs->event_thread->stepping_over_breakpoint = 0;
4439 ecs->event_thread->stepping_over_watchpoint = 0;
4440 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4441 ecs->event_thread->control.stop_step = 0;
4442 stop_print_frame = 1;
4443 stopped_by_random_signal = 0;
4444
4445 /* Hide inlined functions starting here, unless we just performed stepi or
4446 nexti. After stepi and nexti, always show the innermost frame (not any
4447 inline function call sites). */
4448 if (ecs->event_thread->control.step_range_end != 1)
4449 {
4450 struct address_space *aspace =
4451 get_regcache_aspace (get_thread_regcache (ecs->ptid));
4452
4453 /* skip_inline_frames is expensive, so we avoid it if we can
4454 determine that the address is one where functions cannot have
4455 been inlined. This improves performance with inferiors that
4456 load a lot of shared libraries, because the solib event
4457 breakpoint is defined as the address of a function (i.e. not
4458 inline). Note that we have to check the previous PC as well
4459 as the current one to catch cases when we have just
4460 single-stepped off a breakpoint prior to reinstating it.
4461 Note that we're assuming that the code we single-step to is
4462 not inline, but that's not definitive: there's nothing
4463 preventing the event breakpoint function from containing
4464 inlined code, and the single-step ending up there. If the
4465 user had set a breakpoint on that inlined code, the missing
4466 skip_inline_frames call would break things. Fortunately
4467 that's an extremely unlikely scenario. */
4468 if (!pc_at_non_inline_function (aspace, stop_pc, &ecs->ws)
4469 && !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4470 && ecs->event_thread->control.trap_expected
4471 && pc_at_non_inline_function (aspace,
4472 ecs->event_thread->prev_pc,
4473 &ecs->ws)))
4474 {
4475 skip_inline_frames (ecs->ptid);
4476
4477 /* Re-fetch current thread's frame in case that invalidated
4478 the frame cache. */
4479 frame = get_current_frame ();
4480 gdbarch = get_frame_arch (frame);
4481 }
4482 }
4483
4484 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4485 && ecs->event_thread->control.trap_expected
4486 && gdbarch_single_step_through_delay_p (gdbarch)
4487 && currently_stepping (ecs->event_thread))
4488 {
4489 /* We're trying to step off a breakpoint. Turns out that we're
4490 also on an instruction that needs to be stepped multiple
4491 times before it's been fully executing. E.g., architectures
4492 with a delay slot. It needs to be stepped twice, once for
4493 the instruction and once for the delay slot. */
4494 int step_through_delay
4495 = gdbarch_single_step_through_delay (gdbarch, frame);
4496
4497 if (debug_infrun && step_through_delay)
4498 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
4499 if (ecs->event_thread->control.step_range_end == 0
4500 && step_through_delay)
4501 {
4502 /* The user issued a continue when stopped at a breakpoint.
4503 Set up for another trap and get out of here. */
4504 ecs->event_thread->stepping_over_breakpoint = 1;
4505 keep_going (ecs);
4506 return;
4507 }
4508 else if (step_through_delay)
4509 {
4510 /* The user issued a step when stopped at a breakpoint.
4511 Maybe we should stop, maybe we should not - the delay
4512 slot *might* correspond to a line of source. In any
4513 case, don't decide that here, just set
4514 ecs->stepping_over_breakpoint, making sure we
4515 single-step again before breakpoints are re-inserted. */
4516 ecs->event_thread->stepping_over_breakpoint = 1;
4517 }
4518 }
4519
4520 /* See if there is a breakpoint/watchpoint/catchpoint/etc. that
4521 handles this event. */
4522 ecs->event_thread->control.stop_bpstat
4523 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4524 stop_pc, ecs->ptid, &ecs->ws);
4525
4526 /* Following in case break condition called a
4527 function. */
4528 stop_print_frame = 1;
4529
4530 /* This is where we handle "moribund" watchpoints. Unlike
4531 software breakpoints traps, hardware watchpoint traps are
4532 always distinguishable from random traps. If no high-level
4533 watchpoint is associated with the reported stop data address
4534 anymore, then the bpstat does not explain the signal ---
4535 simply make sure to ignore it if `stopped_by_watchpoint' is
4536 set. */
4537
4538 if (debug_infrun
4539 && ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4540 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4541 GDB_SIGNAL_TRAP)
4542 && stopped_by_watchpoint)
4543 fprintf_unfiltered (gdb_stdlog,
4544 "infrun: no user watchpoint explains "
4545 "watchpoint SIGTRAP, ignoring\n");
4546
4547 /* NOTE: cagney/2003-03-29: These checks for a random signal
4548 at one stage in the past included checks for an inferior
4549 function call's call dummy's return breakpoint. The original
4550 comment, that went with the test, read:
4551
4552 ``End of a stack dummy. Some systems (e.g. Sony news) give
4553 another signal besides SIGTRAP, so check here as well as
4554 above.''
4555
4556 If someone ever tries to get call dummys on a
4557 non-executable stack to work (where the target would stop
4558 with something like a SIGSEGV), then those tests might need
4559 to be re-instated. Given, however, that the tests were only
4560 enabled when momentary breakpoints were not being used, I
4561 suspect that it won't be the case.
4562
4563 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4564 be necessary for call dummies on a non-executable stack on
4565 SPARC. */
4566
4567 /* See if the breakpoints module can explain the signal. */
4568 random_signal
4569 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat,
4570 ecs->event_thread->suspend.stop_signal);
4571
4572 /* Maybe this was a trap for a software breakpoint that has since
4573 been removed. */
4574 if (random_signal && target_stopped_by_sw_breakpoint ())
4575 {
4576 if (program_breakpoint_here_p (gdbarch, stop_pc))
4577 {
4578 struct regcache *regcache;
4579 int decr_pc;
4580
4581 /* Re-adjust PC to what the program would see if GDB was not
4582 debugging it. */
4583 regcache = get_thread_regcache (ecs->event_thread->ptid);
4584 decr_pc = gdbarch_decr_pc_after_break (gdbarch);
4585 if (decr_pc != 0)
4586 {
4587 struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
4588
4589 if (record_full_is_used ())
4590 record_full_gdb_operation_disable_set ();
4591
4592 regcache_write_pc (regcache, stop_pc + decr_pc);
4593
4594 do_cleanups (old_cleanups);
4595 }
4596 }
4597 else
4598 {
4599 /* A delayed software breakpoint event. Ignore the trap. */
4600 if (debug_infrun)
4601 fprintf_unfiltered (gdb_stdlog,
4602 "infrun: delayed software breakpoint "
4603 "trap, ignoring\n");
4604 random_signal = 0;
4605 }
4606 }
4607
4608 /* Maybe this was a trap for a hardware breakpoint/watchpoint that
4609 has since been removed. */
4610 if (random_signal && target_stopped_by_hw_breakpoint ())
4611 {
4612 /* A delayed hardware breakpoint event. Ignore the trap. */
4613 if (debug_infrun)
4614 fprintf_unfiltered (gdb_stdlog,
4615 "infrun: delayed hardware breakpoint/watchpoint "
4616 "trap, ignoring\n");
4617 random_signal = 0;
4618 }
4619
4620 /* If not, perhaps stepping/nexting can. */
4621 if (random_signal)
4622 random_signal = !(ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
4623 && currently_stepping (ecs->event_thread));
4624
4625 /* Perhaps the thread hit a single-step breakpoint of _another_
4626 thread. Single-step breakpoints are transparent to the
4627 breakpoints module. */
4628 if (random_signal)
4629 random_signal = !ecs->hit_singlestep_breakpoint;
4630
4631 /* No? Perhaps we got a moribund watchpoint. */
4632 if (random_signal)
4633 random_signal = !stopped_by_watchpoint;
4634
4635 /* For the program's own signals, act according to
4636 the signal handling tables. */
4637
4638 if (random_signal)
4639 {
4640 /* Signal not for debugging purposes. */
4641 struct inferior *inf = find_inferior_ptid (ecs->ptid);
4642 enum gdb_signal stop_signal = ecs->event_thread->suspend.stop_signal;
4643
4644 if (debug_infrun)
4645 fprintf_unfiltered (gdb_stdlog, "infrun: random signal (%s)\n",
4646 gdb_signal_to_symbol_string (stop_signal));
4647
4648 stopped_by_random_signal = 1;
4649
4650 /* Always stop on signals if we're either just gaining control
4651 of the program, or the user explicitly requested this thread
4652 to remain stopped. */
4653 if (stop_soon != NO_STOP_QUIETLY
4654 || ecs->event_thread->stop_requested
4655 || (!inf->detaching
4656 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4657 {
4658 stop_waiting (ecs);
4659 return;
4660 }
4661
4662 /* Notify observers the signal has "handle print" set. Note we
4663 returned early above if stopping; normal_stop handles the
4664 printing in that case. */
4665 if (signal_print[ecs->event_thread->suspend.stop_signal])
4666 {
4667 /* The signal table tells us to print about this signal. */
4668 target_terminal_ours_for_output ();
4669 observer_notify_signal_received (ecs->event_thread->suspend.stop_signal);
4670 target_terminal_inferior ();
4671 }
4672
4673 /* Clear the signal if it should not be passed. */
4674 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4675 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
4676
4677 if (ecs->event_thread->prev_pc == stop_pc
4678 && ecs->event_thread->control.trap_expected
4679 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4680 {
4681 /* We were just starting a new sequence, attempting to
4682 single-step off of a breakpoint and expecting a SIGTRAP.
4683 Instead this signal arrives. This signal will take us out
4684 of the stepping range so GDB needs to remember to, when
4685 the signal handler returns, resume stepping off that
4686 breakpoint. */
4687 /* To simplify things, "continue" is forced to use the same
4688 code paths as single-step - set a breakpoint at the
4689 signal return address and then, once hit, step off that
4690 breakpoint. */
4691 if (debug_infrun)
4692 fprintf_unfiltered (gdb_stdlog,
4693 "infrun: signal arrived while stepping over "
4694 "breakpoint\n");
4695
4696 insert_hp_step_resume_breakpoint_at_frame (frame);
4697 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4698 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4699 ecs->event_thread->control.trap_expected = 0;
4700
4701 /* If we were nexting/stepping some other thread, switch to
4702 it, so that we don't continue it, losing control. */
4703 if (!switch_back_to_stepped_thread (ecs))
4704 keep_going (ecs);
4705 return;
4706 }
4707
4708 if (ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_0
4709 && (pc_in_thread_step_range (stop_pc, ecs->event_thread)
4710 || ecs->event_thread->control.step_range_end == 1)
4711 && frame_id_eq (get_stack_frame_id (frame),
4712 ecs->event_thread->control.step_stack_frame_id)
4713 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4714 {
4715 /* The inferior is about to take a signal that will take it
4716 out of the single step range. Set a breakpoint at the
4717 current PC (which is presumably where the signal handler
4718 will eventually return) and then allow the inferior to
4719 run free.
4720
4721 Note that this is only needed for a signal delivered
4722 while in the single-step range. Nested signals aren't a
4723 problem as they eventually all return. */
4724 if (debug_infrun)
4725 fprintf_unfiltered (gdb_stdlog,
4726 "infrun: signal may take us out of "
4727 "single-step range\n");
4728
4729 insert_hp_step_resume_breakpoint_at_frame (frame);
4730 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4731 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4732 ecs->event_thread->control.trap_expected = 0;
4733 keep_going (ecs);
4734 return;
4735 }
4736
4737 /* Note: step_resume_breakpoint may be non-NULL. This occures
4738 when either there's a nested signal, or when there's a
4739 pending signal enabled just as the signal handler returns
4740 (leaving the inferior at the step-resume-breakpoint without
4741 actually executing it). Either way continue until the
4742 breakpoint is really hit. */
4743
4744 if (!switch_back_to_stepped_thread (ecs))
4745 {
4746 if (debug_infrun)
4747 fprintf_unfiltered (gdb_stdlog,
4748 "infrun: random signal, keep going\n");
4749
4750 keep_going (ecs);
4751 }
4752 return;
4753 }
4754
4755 process_event_stop_test (ecs);
4756}
4757
4758/* Come here when we've got some debug event / signal we can explain
4759 (IOW, not a random signal), and test whether it should cause a
4760 stop, or whether we should resume the inferior (transparently).
4761 E.g., could be a breakpoint whose condition evaluates false; we
4762 could be still stepping within the line; etc. */
4763
4764static void
4765process_event_stop_test (struct execution_control_state *ecs)
4766{
4767 struct symtab_and_line stop_pc_sal;
4768 struct frame_info *frame;
4769 struct gdbarch *gdbarch;
4770 CORE_ADDR jmp_buf_pc;
4771 struct bpstat_what what;
4772
4773 /* Handle cases caused by hitting a breakpoint. */
4774
4775 frame = get_current_frame ();
4776 gdbarch = get_frame_arch (frame);
4777
4778 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4779
4780 if (what.call_dummy)
4781 {
4782 stop_stack_dummy = what.call_dummy;
4783 }
4784
4785 /* If we hit an internal event that triggers symbol changes, the
4786 current frame will be invalidated within bpstat_what (e.g., if we
4787 hit an internal solib event). Re-fetch it. */
4788 frame = get_current_frame ();
4789 gdbarch = get_frame_arch (frame);
4790
4791 switch (what.main_action)
4792 {
4793 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4794 /* If we hit the breakpoint at longjmp while stepping, we
4795 install a momentary breakpoint at the target of the
4796 jmp_buf. */
4797
4798 if (debug_infrun)
4799 fprintf_unfiltered (gdb_stdlog,
4800 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4801
4802 ecs->event_thread->stepping_over_breakpoint = 1;
4803
4804 if (what.is_longjmp)
4805 {
4806 struct value *arg_value;
4807
4808 /* If we set the longjmp breakpoint via a SystemTap probe,
4809 then use it to extract the arguments. The destination PC
4810 is the third argument to the probe. */
4811 arg_value = probe_safe_evaluate_at_pc (frame, 2);
4812 if (arg_value)
4813 {
4814 jmp_buf_pc = value_as_address (arg_value);
4815 jmp_buf_pc = gdbarch_addr_bits_remove (gdbarch, jmp_buf_pc);
4816 }
4817 else if (!gdbarch_get_longjmp_target_p (gdbarch)
4818 || !gdbarch_get_longjmp_target (gdbarch,
4819 frame, &jmp_buf_pc))
4820 {
4821 if (debug_infrun)
4822 fprintf_unfiltered (gdb_stdlog,
4823 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4824 "(!gdbarch_get_longjmp_target)\n");
4825 keep_going (ecs);
4826 return;
4827 }
4828
4829 /* Insert a breakpoint at resume address. */
4830 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4831 }
4832 else
4833 check_exception_resume (ecs, frame);
4834 keep_going (ecs);
4835 return;
4836
4837 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4838 {
4839 struct frame_info *init_frame;
4840
4841 /* There are several cases to consider.
4842
4843 1. The initiating frame no longer exists. In this case we
4844 must stop, because the exception or longjmp has gone too
4845 far.
4846
4847 2. The initiating frame exists, and is the same as the
4848 current frame. We stop, because the exception or longjmp
4849 has been caught.
4850
4851 3. The initiating frame exists and is different from the
4852 current frame. This means the exception or longjmp has
4853 been caught beneath the initiating frame, so keep going.
4854
4855 4. longjmp breakpoint has been placed just to protect
4856 against stale dummy frames and user is not interested in
4857 stopping around longjmps. */
4858
4859 if (debug_infrun)
4860 fprintf_unfiltered (gdb_stdlog,
4861 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4862
4863 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4864 != NULL);
4865 delete_exception_resume_breakpoint (ecs->event_thread);
4866
4867 if (what.is_longjmp)
4868 {
4869 check_longjmp_breakpoint_for_call_dummy (ecs->event_thread);
4870
4871 if (!frame_id_p (ecs->event_thread->initiating_frame))
4872 {
4873 /* Case 4. */
4874 keep_going (ecs);
4875 return;
4876 }
4877 }
4878
4879 init_frame = frame_find_by_id (ecs->event_thread->initiating_frame);
4880
4881 if (init_frame)
4882 {
4883 struct frame_id current_id
4884 = get_frame_id (get_current_frame ());
4885 if (frame_id_eq (current_id,
4886 ecs->event_thread->initiating_frame))
4887 {
4888 /* Case 2. Fall through. */
4889 }
4890 else
4891 {
4892 /* Case 3. */
4893 keep_going (ecs);
4894 return;
4895 }
4896 }
4897
4898 /* For Cases 1 and 2, remove the step-resume breakpoint, if it
4899 exists. */
4900 delete_step_resume_breakpoint (ecs->event_thread);
4901
4902 end_stepping_range (ecs);
4903 }
4904 return;
4905
4906 case BPSTAT_WHAT_SINGLE:
4907 if (debug_infrun)
4908 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4909 ecs->event_thread->stepping_over_breakpoint = 1;
4910 /* Still need to check other stuff, at least the case where we
4911 are stepping and step out of the right range. */
4912 break;
4913
4914 case BPSTAT_WHAT_STEP_RESUME:
4915 if (debug_infrun)
4916 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4917
4918 delete_step_resume_breakpoint (ecs->event_thread);
4919 if (ecs->event_thread->control.proceed_to_finish
4920 && execution_direction == EXEC_REVERSE)
4921 {
4922 struct thread_info *tp = ecs->event_thread;
4923
4924 /* We are finishing a function in reverse, and just hit the
4925 step-resume breakpoint at the start address of the
4926 function, and we're almost there -- just need to back up
4927 by one more single-step, which should take us back to the
4928 function call. */
4929 tp->control.step_range_start = tp->control.step_range_end = 1;
4930 keep_going (ecs);
4931 return;
4932 }
4933 fill_in_stop_func (gdbarch, ecs);
4934 if (stop_pc == ecs->stop_func_start
4935 && execution_direction == EXEC_REVERSE)
4936 {
4937 /* We are stepping over a function call in reverse, and just
4938 hit the step-resume breakpoint at the start address of
4939 the function. Go back to single-stepping, which should
4940 take us back to the function call. */
4941 ecs->event_thread->stepping_over_breakpoint = 1;
4942 keep_going (ecs);
4943 return;
4944 }
4945 break;
4946
4947 case BPSTAT_WHAT_STOP_NOISY:
4948 if (debug_infrun)
4949 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4950 stop_print_frame = 1;
4951
4952 /* Assume the thread stopped for a breapoint. We'll still check
4953 whether a/the breakpoint is there when the thread is next
4954 resumed. */
4955 ecs->event_thread->stepping_over_breakpoint = 1;
4956
4957 stop_waiting (ecs);
4958 return;
4959
4960 case BPSTAT_WHAT_STOP_SILENT:
4961 if (debug_infrun)
4962 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4963 stop_print_frame = 0;
4964
4965 /* Assume the thread stopped for a breapoint. We'll still check
4966 whether a/the breakpoint is there when the thread is next
4967 resumed. */
4968 ecs->event_thread->stepping_over_breakpoint = 1;
4969 stop_waiting (ecs);
4970 return;
4971
4972 case BPSTAT_WHAT_HP_STEP_RESUME:
4973 if (debug_infrun)
4974 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_HP_STEP_RESUME\n");
4975
4976 delete_step_resume_breakpoint (ecs->event_thread);
4977 if (ecs->event_thread->step_after_step_resume_breakpoint)
4978 {
4979 /* Back when the step-resume breakpoint was inserted, we
4980 were trying to single-step off a breakpoint. Go back to
4981 doing that. */
4982 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4983 ecs->event_thread->stepping_over_breakpoint = 1;
4984 keep_going (ecs);
4985 return;
4986 }
4987 break;
4988
4989 case BPSTAT_WHAT_KEEP_CHECKING:
4990 break;
4991 }
4992
4993 /* If we stepped a permanent breakpoint and we had a high priority
4994 step-resume breakpoint for the address we stepped, but we didn't
4995 hit it, then we must have stepped into the signal handler. The
4996 step-resume was only necessary to catch the case of _not_
4997 stepping into the handler, so delete it, and fall through to
4998 checking whether the step finished. */
4999 if (ecs->event_thread->stepped_breakpoint)
5000 {
5001 struct breakpoint *sr_bp
5002 = ecs->event_thread->control.step_resume_breakpoint;
5003
5004 if (sr_bp != NULL
5005 && sr_bp->loc->permanent
5006 && sr_bp->type == bp_hp_step_resume
5007 && sr_bp->loc->address == ecs->event_thread->prev_pc)
5008 {
5009 if (debug_infrun)
5010 fprintf_unfiltered (gdb_stdlog,
5011 "infrun: stepped permanent breakpoint, stopped in "
5012 "handler\n");
5013 delete_step_resume_breakpoint (ecs->event_thread);
5014 ecs->event_thread->step_after_step_resume_breakpoint = 0;
5015 }
5016 }
5017
5018 /* We come here if we hit a breakpoint but should not stop for it.
5019 Possibly we also were stepping and should stop for that. So fall
5020 through and test for stepping. But, if not stepping, do not
5021 stop. */
5022
5023 /* In all-stop mode, if we're currently stepping but have stopped in
5024 some other thread, we need to switch back to the stepped thread. */
5025 if (switch_back_to_stepped_thread (ecs))
5026 return;
5027
5028 if (ecs->event_thread->control.step_resume_breakpoint)
5029 {
5030 if (debug_infrun)
5031 fprintf_unfiltered (gdb_stdlog,
5032 "infrun: step-resume breakpoint is inserted\n");
5033
5034 /* Having a step-resume breakpoint overrides anything
5035 else having to do with stepping commands until
5036 that breakpoint is reached. */
5037 keep_going (ecs);
5038 return;
5039 }
5040
5041 if (ecs->event_thread->control.step_range_end == 0)
5042 {
5043 if (debug_infrun)
5044 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
5045 /* Likewise if we aren't even stepping. */
5046 keep_going (ecs);
5047 return;
5048 }
5049
5050 /* Re-fetch current thread's frame in case the code above caused
5051 the frame cache to be re-initialized, making our FRAME variable
5052 a dangling pointer. */
5053 frame = get_current_frame ();
5054 gdbarch = get_frame_arch (frame);
5055 fill_in_stop_func (gdbarch, ecs);
5056
5057 /* If stepping through a line, keep going if still within it.
5058
5059 Note that step_range_end is the address of the first instruction
5060 beyond the step range, and NOT the address of the last instruction
5061 within it!
5062
5063 Note also that during reverse execution, we may be stepping
5064 through a function epilogue and therefore must detect when
5065 the current-frame changes in the middle of a line. */
5066
5067 if (pc_in_thread_step_range (stop_pc, ecs->event_thread)
5068 && (execution_direction != EXEC_REVERSE
5069 || frame_id_eq (get_frame_id (frame),
5070 ecs->event_thread->control.step_frame_id)))
5071 {
5072 if (debug_infrun)
5073 fprintf_unfiltered
5074 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
5075 paddress (gdbarch, ecs->event_thread->control.step_range_start),
5076 paddress (gdbarch, ecs->event_thread->control.step_range_end));
5077
5078 /* Tentatively re-enable range stepping; `resume' disables it if
5079 necessary (e.g., if we're stepping over a breakpoint or we
5080 have software watchpoints). */
5081 ecs->event_thread->control.may_range_step = 1;
5082
5083 /* When stepping backward, stop at beginning of line range
5084 (unless it's the function entry point, in which case
5085 keep going back to the call point). */
5086 if (stop_pc == ecs->event_thread->control.step_range_start
5087 && stop_pc != ecs->stop_func_start
5088 && execution_direction == EXEC_REVERSE)
5089 end_stepping_range (ecs);
5090 else
5091 keep_going (ecs);
5092
5093 return;
5094 }
5095
5096 /* We stepped out of the stepping range. */
5097
5098 /* If we are stepping at the source level and entered the runtime
5099 loader dynamic symbol resolution code...
5100
5101 EXEC_FORWARD: we keep on single stepping until we exit the run
5102 time loader code and reach the callee's address.
5103
5104 EXEC_REVERSE: we've already executed the callee (backward), and
5105 the runtime loader code is handled just like any other
5106 undebuggable function call. Now we need only keep stepping
5107 backward through the trampoline code, and that's handled further
5108 down, so there is nothing for us to do here. */
5109
5110 if (execution_direction != EXEC_REVERSE
5111 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5112 && in_solib_dynsym_resolve_code (stop_pc))
5113 {
5114 CORE_ADDR pc_after_resolver =
5115 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
5116
5117 if (debug_infrun)
5118 fprintf_unfiltered (gdb_stdlog,
5119 "infrun: stepped into dynsym resolve code\n");
5120
5121 if (pc_after_resolver)
5122 {
5123 /* Set up a step-resume breakpoint at the address
5124 indicated by SKIP_SOLIB_RESOLVER. */
5125 struct symtab_and_line sr_sal;
5126
5127 init_sal (&sr_sal);
5128 sr_sal.pc = pc_after_resolver;
5129 sr_sal.pspace = get_frame_program_space (frame);
5130
5131 insert_step_resume_breakpoint_at_sal (gdbarch,
5132 sr_sal, null_frame_id);
5133 }
5134
5135 keep_going (ecs);
5136 return;
5137 }
5138
5139 if (ecs->event_thread->control.step_range_end != 1
5140 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5141 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5142 && get_frame_type (frame) == SIGTRAMP_FRAME)
5143 {
5144 if (debug_infrun)
5145 fprintf_unfiltered (gdb_stdlog,
5146 "infrun: stepped into signal trampoline\n");
5147 /* The inferior, while doing a "step" or "next", has ended up in
5148 a signal trampoline (either by a signal being delivered or by
5149 the signal handler returning). Just single-step until the
5150 inferior leaves the trampoline (either by calling the handler
5151 or returning). */
5152 keep_going (ecs);
5153 return;
5154 }
5155
5156 /* If we're in the return path from a shared library trampoline,
5157 we want to proceed through the trampoline when stepping. */
5158 /* macro/2012-04-25: This needs to come before the subroutine
5159 call check below as on some targets return trampolines look
5160 like subroutine calls (MIPS16 return thunks). */
5161 if (gdbarch_in_solib_return_trampoline (gdbarch,
5162 stop_pc, ecs->stop_func_name)
5163 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
5164 {
5165 /* Determine where this trampoline returns. */
5166 CORE_ADDR real_stop_pc;
5167
5168 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
5169
5170 if (debug_infrun)
5171 fprintf_unfiltered (gdb_stdlog,
5172 "infrun: stepped into solib return tramp\n");
5173
5174 /* Only proceed through if we know where it's going. */
5175 if (real_stop_pc)
5176 {
5177 /* And put the step-breakpoint there and go until there. */
5178 struct symtab_and_line sr_sal;
5179
5180 init_sal (&sr_sal); /* initialize to zeroes */
5181 sr_sal.pc = real_stop_pc;
5182 sr_sal.section = find_pc_overlay (sr_sal.pc);
5183 sr_sal.pspace = get_frame_program_space (frame);
5184
5185 /* Do not specify what the fp should be when we stop since
5186 on some machines the prologue is where the new fp value
5187 is established. */
5188 insert_step_resume_breakpoint_at_sal (gdbarch,
5189 sr_sal, null_frame_id);
5190
5191 /* Restart without fiddling with the step ranges or
5192 other state. */
5193 keep_going (ecs);
5194 return;
5195 }
5196 }
5197
5198 /* Check for subroutine calls. The check for the current frame
5199 equalling the step ID is not necessary - the check of the
5200 previous frame's ID is sufficient - but it is a common case and
5201 cheaper than checking the previous frame's ID.
5202
5203 NOTE: frame_id_eq will never report two invalid frame IDs as
5204 being equal, so to get into this block, both the current and
5205 previous frame must have valid frame IDs. */
5206 /* The outer_frame_id check is a heuristic to detect stepping
5207 through startup code. If we step over an instruction which
5208 sets the stack pointer from an invalid value to a valid value,
5209 we may detect that as a subroutine call from the mythical
5210 "outermost" function. This could be fixed by marking
5211 outermost frames as !stack_p,code_p,special_p. Then the
5212 initial outermost frame, before sp was valid, would
5213 have code_addr == &_start. See the comment in frame_id_eq
5214 for more. */
5215 if (!frame_id_eq (get_stack_frame_id (frame),
5216 ecs->event_thread->control.step_stack_frame_id)
5217 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
5218 ecs->event_thread->control.step_stack_frame_id)
5219 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
5220 outer_frame_id)
5221 || (ecs->event_thread->control.step_start_function
5222 != find_pc_function (stop_pc)))))
5223 {
5224 CORE_ADDR real_stop_pc;
5225
5226 if (debug_infrun)
5227 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
5228
5229 if (ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
5230 {
5231 /* I presume that step_over_calls is only 0 when we're
5232 supposed to be stepping at the assembly language level
5233 ("stepi"). Just stop. */
5234 /* And this works the same backward as frontward. MVS */
5235 end_stepping_range (ecs);
5236 return;
5237 }
5238
5239 /* Reverse stepping through solib trampolines. */
5240
5241 if (execution_direction == EXEC_REVERSE
5242 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
5243 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
5244 || (ecs->stop_func_start == 0
5245 && in_solib_dynsym_resolve_code (stop_pc))))
5246 {
5247 /* Any solib trampoline code can be handled in reverse
5248 by simply continuing to single-step. We have already
5249 executed the solib function (backwards), and a few
5250 steps will take us back through the trampoline to the
5251 caller. */
5252 keep_going (ecs);
5253 return;
5254 }
5255
5256 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5257 {
5258 /* We're doing a "next".
5259
5260 Normal (forward) execution: set a breakpoint at the
5261 callee's return address (the address at which the caller
5262 will resume).
5263
5264 Reverse (backward) execution. set the step-resume
5265 breakpoint at the start of the function that we just
5266 stepped into (backwards), and continue to there. When we
5267 get there, we'll need to single-step back to the caller. */
5268
5269 if (execution_direction == EXEC_REVERSE)
5270 {
5271 /* If we're already at the start of the function, we've either
5272 just stepped backward into a single instruction function,
5273 or stepped back out of a signal handler to the first instruction
5274 of the function. Just keep going, which will single-step back
5275 to the caller. */
5276 if (ecs->stop_func_start != stop_pc && ecs->stop_func_start != 0)
5277 {
5278 struct symtab_and_line sr_sal;
5279
5280 /* Normal function call return (static or dynamic). */
5281 init_sal (&sr_sal);
5282 sr_sal.pc = ecs->stop_func_start;
5283 sr_sal.pspace = get_frame_program_space (frame);
5284 insert_step_resume_breakpoint_at_sal (gdbarch,
5285 sr_sal, null_frame_id);
5286 }
5287 }
5288 else
5289 insert_step_resume_breakpoint_at_caller (frame);
5290
5291 keep_going (ecs);
5292 return;
5293 }
5294
5295 /* If we are in a function call trampoline (a stub between the
5296 calling routine and the real function), locate the real
5297 function. That's what tells us (a) whether we want to step
5298 into it at all, and (b) what prologue we want to run to the
5299 end of, if we do step into it. */
5300 real_stop_pc = skip_language_trampoline (frame, stop_pc);
5301 if (real_stop_pc == 0)
5302 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
5303 if (real_stop_pc != 0)
5304 ecs->stop_func_start = real_stop_pc;
5305
5306 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
5307 {
5308 struct symtab_and_line sr_sal;
5309
5310 init_sal (&sr_sal);
5311 sr_sal.pc = ecs->stop_func_start;
5312 sr_sal.pspace = get_frame_program_space (frame);
5313
5314 insert_step_resume_breakpoint_at_sal (gdbarch,
5315 sr_sal, null_frame_id);
5316 keep_going (ecs);
5317 return;
5318 }
5319
5320 /* If we have line number information for the function we are
5321 thinking of stepping into and the function isn't on the skip
5322 list, step into it.
5323
5324 If there are several symtabs at that PC (e.g. with include
5325 files), just want to know whether *any* of them have line
5326 numbers. find_pc_line handles this. */
5327 {
5328 struct symtab_and_line tmp_sal;
5329
5330 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
5331 if (tmp_sal.line != 0
5332 && !function_name_is_marked_for_skip (ecs->stop_func_name,
5333 &tmp_sal))
5334 {
5335 if (execution_direction == EXEC_REVERSE)
5336 handle_step_into_function_backward (gdbarch, ecs);
5337 else
5338 handle_step_into_function (gdbarch, ecs);
5339 return;
5340 }
5341 }
5342
5343 /* If we have no line number and the step-stop-if-no-debug is
5344 set, we stop the step so that the user has a chance to switch
5345 in assembly mode. */
5346 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5347 && step_stop_if_no_debug)
5348 {
5349 end_stepping_range (ecs);
5350 return;
5351 }
5352
5353 if (execution_direction == EXEC_REVERSE)
5354 {
5355 /* If we're already at the start of the function, we've either just
5356 stepped backward into a single instruction function without line
5357 number info, or stepped back out of a signal handler to the first
5358 instruction of the function without line number info. Just keep
5359 going, which will single-step back to the caller. */
5360 if (ecs->stop_func_start != stop_pc)
5361 {
5362 /* Set a breakpoint at callee's start address.
5363 From there we can step once and be back in the caller. */
5364 struct symtab_and_line sr_sal;
5365
5366 init_sal (&sr_sal);
5367 sr_sal.pc = ecs->stop_func_start;
5368 sr_sal.pspace = get_frame_program_space (frame);
5369 insert_step_resume_breakpoint_at_sal (gdbarch,
5370 sr_sal, null_frame_id);
5371 }
5372 }
5373 else
5374 /* Set a breakpoint at callee's return address (the address
5375 at which the caller will resume). */
5376 insert_step_resume_breakpoint_at_caller (frame);
5377
5378 keep_going (ecs);
5379 return;
5380 }
5381
5382 /* Reverse stepping through solib trampolines. */
5383
5384 if (execution_direction == EXEC_REVERSE
5385 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
5386 {
5387 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
5388 || (ecs->stop_func_start == 0
5389 && in_solib_dynsym_resolve_code (stop_pc)))
5390 {
5391 /* Any solib trampoline code can be handled in reverse
5392 by simply continuing to single-step. We have already
5393 executed the solib function (backwards), and a few
5394 steps will take us back through the trampoline to the
5395 caller. */
5396 keep_going (ecs);
5397 return;
5398 }
5399 else if (in_solib_dynsym_resolve_code (stop_pc))
5400 {
5401 /* Stepped backward into the solib dynsym resolver.
5402 Set a breakpoint at its start and continue, then
5403 one more step will take us out. */
5404 struct symtab_and_line sr_sal;
5405
5406 init_sal (&sr_sal);
5407 sr_sal.pc = ecs->stop_func_start;
5408 sr_sal.pspace = get_frame_program_space (frame);
5409 insert_step_resume_breakpoint_at_sal (gdbarch,
5410 sr_sal, null_frame_id);
5411 keep_going (ecs);
5412 return;
5413 }
5414 }
5415
5416 stop_pc_sal = find_pc_line (stop_pc, 0);
5417
5418 /* NOTE: tausq/2004-05-24: This if block used to be done before all
5419 the trampoline processing logic, however, there are some trampolines
5420 that have no names, so we should do trampoline handling first. */
5421 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
5422 && ecs->stop_func_name == NULL
5423 && stop_pc_sal.line == 0)
5424 {
5425 if (debug_infrun)
5426 fprintf_unfiltered (gdb_stdlog,
5427 "infrun: stepped into undebuggable function\n");
5428
5429 /* The inferior just stepped into, or returned to, an
5430 undebuggable function (where there is no debugging information
5431 and no line number corresponding to the address where the
5432 inferior stopped). Since we want to skip this kind of code,
5433 we keep going until the inferior returns from this
5434 function - unless the user has asked us not to (via
5435 set step-mode) or we no longer know how to get back
5436 to the call site. */
5437 if (step_stop_if_no_debug
5438 || !frame_id_p (frame_unwind_caller_id (frame)))
5439 {
5440 /* If we have no line number and the step-stop-if-no-debug
5441 is set, we stop the step so that the user has a chance to
5442 switch in assembly mode. */
5443 end_stepping_range (ecs);
5444 return;
5445 }
5446 else
5447 {
5448 /* Set a breakpoint at callee's return address (the address
5449 at which the caller will resume). */
5450 insert_step_resume_breakpoint_at_caller (frame);
5451 keep_going (ecs);
5452 return;
5453 }
5454 }
5455
5456 if (ecs->event_thread->control.step_range_end == 1)
5457 {
5458 /* It is stepi or nexti. We always want to stop stepping after
5459 one instruction. */
5460 if (debug_infrun)
5461 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
5462 end_stepping_range (ecs);
5463 return;
5464 }
5465
5466 if (stop_pc_sal.line == 0)
5467 {
5468 /* We have no line number information. That means to stop
5469 stepping (does this always happen right after one instruction,
5470 when we do "s" in a function with no line numbers,
5471 or can this happen as a result of a return or longjmp?). */
5472 if (debug_infrun)
5473 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
5474 end_stepping_range (ecs);
5475 return;
5476 }
5477
5478 /* Look for "calls" to inlined functions, part one. If the inline
5479 frame machinery detected some skipped call sites, we have entered
5480 a new inline function. */
5481
5482 if (frame_id_eq (get_frame_id (get_current_frame ()),
5483 ecs->event_thread->control.step_frame_id)
5484 && inline_skipped_frames (ecs->ptid))
5485 {
5486 struct symtab_and_line call_sal;
5487
5488 if (debug_infrun)
5489 fprintf_unfiltered (gdb_stdlog,
5490 "infrun: stepped into inlined function\n");
5491
5492 find_frame_sal (get_current_frame (), &call_sal);
5493
5494 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
5495 {
5496 /* For "step", we're going to stop. But if the call site
5497 for this inlined function is on the same source line as
5498 we were previously stepping, go down into the function
5499 first. Otherwise stop at the call site. */
5500
5501 if (call_sal.line == ecs->event_thread->current_line
5502 && call_sal.symtab == ecs->event_thread->current_symtab)
5503 step_into_inline_frame (ecs->ptid);
5504
5505 end_stepping_range (ecs);
5506 return;
5507 }
5508 else
5509 {
5510 /* For "next", we should stop at the call site if it is on a
5511 different source line. Otherwise continue through the
5512 inlined function. */
5513 if (call_sal.line == ecs->event_thread->current_line
5514 && call_sal.symtab == ecs->event_thread->current_symtab)
5515 keep_going (ecs);
5516 else
5517 end_stepping_range (ecs);
5518 return;
5519 }
5520 }
5521
5522 /* Look for "calls" to inlined functions, part two. If we are still
5523 in the same real function we were stepping through, but we have
5524 to go further up to find the exact frame ID, we are stepping
5525 through a more inlined call beyond its call site. */
5526
5527 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5528 && !frame_id_eq (get_frame_id (get_current_frame ()),
5529 ecs->event_thread->control.step_frame_id)
5530 && stepped_in_from (get_current_frame (),
5531 ecs->event_thread->control.step_frame_id))
5532 {
5533 if (debug_infrun)
5534 fprintf_unfiltered (gdb_stdlog,
5535 "infrun: stepping through inlined function\n");
5536
5537 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5538 keep_going (ecs);
5539 else
5540 end_stepping_range (ecs);
5541 return;
5542 }
5543
5544 if ((stop_pc == stop_pc_sal.pc)
5545 && (ecs->event_thread->current_line != stop_pc_sal.line
5546 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
5547 {
5548 /* We are at the start of a different line. So stop. Note that
5549 we don't stop if we step into the middle of a different line.
5550 That is said to make things like for (;;) statements work
5551 better. */
5552 if (debug_infrun)
5553 fprintf_unfiltered (gdb_stdlog,
5554 "infrun: stepped to a different line\n");
5555 end_stepping_range (ecs);
5556 return;
5557 }
5558
5559 /* We aren't done stepping.
5560
5561 Optimize by setting the stepping range to the line.
5562 (We might not be in the original line, but if we entered a
5563 new line in mid-statement, we continue stepping. This makes
5564 things like for(;;) statements work better.) */
5565
5566 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5567 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
5568 ecs->event_thread->control.may_range_step = 1;
5569 set_step_info (frame, stop_pc_sal);
5570
5571 if (debug_infrun)
5572 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
5573 keep_going (ecs);
5574}
5575
5576/* In all-stop mode, if we're currently stepping but have stopped in
5577 some other thread, we may need to switch back to the stepped
5578 thread. Returns true we set the inferior running, false if we left
5579 it stopped (and the event needs further processing). */
5580
5581static int
5582switch_back_to_stepped_thread (struct execution_control_state *ecs)
5583{
5584 if (!non_stop)
5585 {
5586 struct thread_info *tp;
5587 struct thread_info *stepping_thread;
5588 struct thread_info *step_over;
5589
5590 /* If any thread is blocked on some internal breakpoint, and we
5591 simply need to step over that breakpoint to get it going
5592 again, do that first. */
5593
5594 /* However, if we see an event for the stepping thread, then we
5595 know all other threads have been moved past their breakpoints
5596 already. Let the caller check whether the step is finished,
5597 etc., before deciding to move it past a breakpoint. */
5598 if (ecs->event_thread->control.step_range_end != 0)
5599 return 0;
5600
5601 /* Check if the current thread is blocked on an incomplete
5602 step-over, interrupted by a random signal. */
5603 if (ecs->event_thread->control.trap_expected
5604 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
5605 {
5606 if (debug_infrun)
5607 {
5608 fprintf_unfiltered (gdb_stdlog,
5609 "infrun: need to finish step-over of [%s]\n",
5610 target_pid_to_str (ecs->event_thread->ptid));
5611 }
5612 keep_going (ecs);
5613 return 1;
5614 }
5615
5616 /* Check if the current thread is blocked by a single-step
5617 breakpoint of another thread. */
5618 if (ecs->hit_singlestep_breakpoint)
5619 {
5620 if (debug_infrun)
5621 {
5622 fprintf_unfiltered (gdb_stdlog,
5623 "infrun: need to step [%s] over single-step "
5624 "breakpoint\n",
5625 target_pid_to_str (ecs->ptid));
5626 }
5627 keep_going (ecs);
5628 return 1;
5629 }
5630
5631 /* Otherwise, we no longer expect a trap in the current thread.
5632 Clear the trap_expected flag before switching back -- this is
5633 what keep_going does as well, if we call it. */
5634 ecs->event_thread->control.trap_expected = 0;
5635
5636 /* Likewise, clear the signal if it should not be passed. */
5637 if (!signal_program[ecs->event_thread->suspend.stop_signal])
5638 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
5639
5640 /* If scheduler locking applies even if not stepping, there's no
5641 need to walk over threads. Above we've checked whether the
5642 current thread is stepping. If some other thread not the
5643 event thread is stepping, then it must be that scheduler
5644 locking is not in effect. */
5645 if (schedlock_applies (ecs->event_thread))
5646 return 0;
5647
5648 /* Look for the stepping/nexting thread, and check if any other
5649 thread other than the stepping thread needs to start a
5650 step-over. Do all step-overs before actually proceeding with
5651 step/next/etc. */
5652 stepping_thread = NULL;
5653 step_over = NULL;
5654 ALL_NON_EXITED_THREADS (tp)
5655 {
5656 /* Ignore threads of processes we're not resuming. */
5657 if (!sched_multi
5658 && ptid_get_pid (tp->ptid) != ptid_get_pid (inferior_ptid))
5659 continue;
5660
5661 /* When stepping over a breakpoint, we lock all threads
5662 except the one that needs to move past the breakpoint.
5663 If a non-event thread has this set, the "incomplete
5664 step-over" check above should have caught it earlier. */
5665 gdb_assert (!tp->control.trap_expected);
5666
5667 /* Did we find the stepping thread? */
5668 if (tp->control.step_range_end)
5669 {
5670 /* Yep. There should only one though. */
5671 gdb_assert (stepping_thread == NULL);
5672
5673 /* The event thread is handled at the top, before we
5674 enter this loop. */
5675 gdb_assert (tp != ecs->event_thread);
5676
5677 /* If some thread other than the event thread is
5678 stepping, then scheduler locking can't be in effect,
5679 otherwise we wouldn't have resumed the current event
5680 thread in the first place. */
5681 gdb_assert (!schedlock_applies (tp));
5682
5683 stepping_thread = tp;
5684 }
5685 else if (thread_still_needs_step_over (tp))
5686 {
5687 step_over = tp;
5688
5689 /* At the top we've returned early if the event thread
5690 is stepping. If some other thread not the event
5691 thread is stepping, then scheduler locking can't be
5692 in effect, and we can resume this thread. No need to
5693 keep looking for the stepping thread then. */
5694 break;
5695 }
5696 }
5697
5698 if (step_over != NULL)
5699 {
5700 tp = step_over;
5701 if (debug_infrun)
5702 {
5703 fprintf_unfiltered (gdb_stdlog,
5704 "infrun: need to step-over [%s]\n",
5705 target_pid_to_str (tp->ptid));
5706 }
5707
5708 /* Only the stepping thread should have this set. */
5709 gdb_assert (tp->control.step_range_end == 0);
5710
5711 ecs->ptid = tp->ptid;
5712 ecs->event_thread = tp;
5713 switch_to_thread (ecs->ptid);
5714 keep_going (ecs);
5715 return 1;
5716 }
5717
5718 if (stepping_thread != NULL)
5719 {
5720 struct frame_info *frame;
5721 struct gdbarch *gdbarch;
5722
5723 tp = stepping_thread;
5724
5725 /* If the stepping thread exited, then don't try to switch
5726 back and resume it, which could fail in several different
5727 ways depending on the target. Instead, just keep going.
5728
5729 We can find a stepping dead thread in the thread list in
5730 two cases:
5731
5732 - The target supports thread exit events, and when the
5733 target tries to delete the thread from the thread list,
5734 inferior_ptid pointed at the exiting thread. In such
5735 case, calling delete_thread does not really remove the
5736 thread from the list; instead, the thread is left listed,
5737 with 'exited' state.
5738
5739 - The target's debug interface does not support thread
5740 exit events, and so we have no idea whatsoever if the
5741 previously stepping thread is still alive. For that
5742 reason, we need to synchronously query the target
5743 now. */
5744 if (is_exited (tp->ptid)
5745 || !target_thread_alive (tp->ptid))
5746 {
5747 if (debug_infrun)
5748 fprintf_unfiltered (gdb_stdlog,
5749 "infrun: not switching back to "
5750 "stepped thread, it has vanished\n");
5751
5752 delete_thread (tp->ptid);
5753 keep_going (ecs);
5754 return 1;
5755 }
5756
5757 if (debug_infrun)
5758 fprintf_unfiltered (gdb_stdlog,
5759 "infrun: switching back to stepped thread\n");
5760
5761 ecs->event_thread = tp;
5762 ecs->ptid = tp->ptid;
5763 context_switch (ecs->ptid);
5764
5765 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
5766 frame = get_current_frame ();
5767 gdbarch = get_frame_arch (frame);
5768
5769 /* If the PC of the thread we were trying to single-step has
5770 changed, then that thread has trapped or been signaled,
5771 but the event has not been reported to GDB yet. Re-poll
5772 the target looking for this particular thread's event
5773 (i.e. temporarily enable schedlock) by:
5774
5775 - setting a break at the current PC
5776 - resuming that particular thread, only (by setting
5777 trap expected)
5778
5779 This prevents us continuously moving the single-step
5780 breakpoint forward, one instruction at a time,
5781 overstepping. */
5782
5783 if (stop_pc != tp->prev_pc)
5784 {
5785 ptid_t resume_ptid;
5786
5787 if (debug_infrun)
5788 fprintf_unfiltered (gdb_stdlog,
5789 "infrun: expected thread advanced also\n");
5790
5791 /* Clear the info of the previous step-over, as it's no
5792 longer valid. It's what keep_going would do too, if
5793 we called it. Must do this before trying to insert
5794 the sss breakpoint, otherwise if we were previously
5795 trying to step over this exact address in another
5796 thread, the breakpoint ends up not installed. */
5797 clear_step_over_info ();
5798
5799 insert_single_step_breakpoint (get_frame_arch (frame),
5800 get_frame_address_space (frame),
5801 stop_pc);
5802
5803 resume_ptid = user_visible_resume_ptid (tp->control.stepping_command);
5804 do_target_resume (resume_ptid,
5805 currently_stepping (tp), GDB_SIGNAL_0);
5806 prepare_to_wait (ecs);
5807 }
5808 else
5809 {
5810 if (debug_infrun)
5811 fprintf_unfiltered (gdb_stdlog,
5812 "infrun: expected thread still "
5813 "hasn't advanced\n");
5814 keep_going (ecs);
5815 }
5816
5817 return 1;
5818 }
5819 }
5820 return 0;
5821}
5822
5823/* Is thread TP in the middle of single-stepping? */
5824
5825static int
5826currently_stepping (struct thread_info *tp)
5827{
5828 return ((tp->control.step_range_end
5829 && tp->control.step_resume_breakpoint == NULL)
5830 || tp->control.trap_expected
5831 || tp->stepped_breakpoint
5832 || bpstat_should_step ());
5833}
5834
5835/* Inferior has stepped into a subroutine call with source code that
5836 we should not step over. Do step to the first line of code in
5837 it. */
5838
5839static void
5840handle_step_into_function (struct gdbarch *gdbarch,
5841 struct execution_control_state *ecs)
5842{
5843 struct compunit_symtab *cust;
5844 struct symtab_and_line stop_func_sal, sr_sal;
5845
5846 fill_in_stop_func (gdbarch, ecs);
5847
5848 cust = find_pc_compunit_symtab (stop_pc);
5849 if (cust != NULL && compunit_language (cust) != language_asm)
5850 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5851 ecs->stop_func_start);
5852
5853 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5854 /* Use the step_resume_break to step until the end of the prologue,
5855 even if that involves jumps (as it seems to on the vax under
5856 4.2). */
5857 /* If the prologue ends in the middle of a source line, continue to
5858 the end of that source line (if it is still within the function).
5859 Otherwise, just go to end of prologue. */
5860 if (stop_func_sal.end
5861 && stop_func_sal.pc != ecs->stop_func_start
5862 && stop_func_sal.end < ecs->stop_func_end)
5863 ecs->stop_func_start = stop_func_sal.end;
5864
5865 /* Architectures which require breakpoint adjustment might not be able
5866 to place a breakpoint at the computed address. If so, the test
5867 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5868 ecs->stop_func_start to an address at which a breakpoint may be
5869 legitimately placed.
5870
5871 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5872 made, GDB will enter an infinite loop when stepping through
5873 optimized code consisting of VLIW instructions which contain
5874 subinstructions corresponding to different source lines. On
5875 FR-V, it's not permitted to place a breakpoint on any but the
5876 first subinstruction of a VLIW instruction. When a breakpoint is
5877 set, GDB will adjust the breakpoint address to the beginning of
5878 the VLIW instruction. Thus, we need to make the corresponding
5879 adjustment here when computing the stop address. */
5880
5881 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5882 {
5883 ecs->stop_func_start
5884 = gdbarch_adjust_breakpoint_address (gdbarch,
5885 ecs->stop_func_start);
5886 }
5887
5888 if (ecs->stop_func_start == stop_pc)
5889 {
5890 /* We are already there: stop now. */
5891 end_stepping_range (ecs);
5892 return;
5893 }
5894 else
5895 {
5896 /* Put the step-breakpoint there and go until there. */
5897 init_sal (&sr_sal); /* initialize to zeroes */
5898 sr_sal.pc = ecs->stop_func_start;
5899 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5900 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5901
5902 /* Do not specify what the fp should be when we stop since on
5903 some machines the prologue is where the new fp value is
5904 established. */
5905 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5906
5907 /* And make sure stepping stops right away then. */
5908 ecs->event_thread->control.step_range_end
5909 = ecs->event_thread->control.step_range_start;
5910 }
5911 keep_going (ecs);
5912}
5913
5914/* Inferior has stepped backward into a subroutine call with source
5915 code that we should not step over. Do step to the beginning of the
5916 last line of code in it. */
5917
5918static void
5919handle_step_into_function_backward (struct gdbarch *gdbarch,
5920 struct execution_control_state *ecs)
5921{
5922 struct compunit_symtab *cust;
5923 struct symtab_and_line stop_func_sal;
5924
5925 fill_in_stop_func (gdbarch, ecs);
5926
5927 cust = find_pc_compunit_symtab (stop_pc);
5928 if (cust != NULL && compunit_language (cust) != language_asm)
5929 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5930 ecs->stop_func_start);
5931
5932 stop_func_sal = find_pc_line (stop_pc, 0);
5933
5934 /* OK, we're just going to keep stepping here. */
5935 if (stop_func_sal.pc == stop_pc)
5936 {
5937 /* We're there already. Just stop stepping now. */
5938 end_stepping_range (ecs);
5939 }
5940 else
5941 {
5942 /* Else just reset the step range and keep going.
5943 No step-resume breakpoint, they don't work for
5944 epilogues, which can have multiple entry paths. */
5945 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5946 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5947 keep_going (ecs);
5948 }
5949 return;
5950}
5951
5952/* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5953 This is used to both functions and to skip over code. */
5954
5955static void
5956insert_step_resume_breakpoint_at_sal_1 (struct gdbarch *gdbarch,
5957 struct symtab_and_line sr_sal,
5958 struct frame_id sr_id,
5959 enum bptype sr_type)
5960{
5961 /* There should never be more than one step-resume or longjmp-resume
5962 breakpoint per thread, so we should never be setting a new
5963 step_resume_breakpoint when one is already active. */
5964 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5965 gdb_assert (sr_type == bp_step_resume || sr_type == bp_hp_step_resume);
5966
5967 if (debug_infrun)
5968 fprintf_unfiltered (gdb_stdlog,
5969 "infrun: inserting step-resume breakpoint at %s\n",
5970 paddress (gdbarch, sr_sal.pc));
5971
5972 inferior_thread ()->control.step_resume_breakpoint
5973 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, sr_type);
5974}
5975
5976void
5977insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5978 struct symtab_and_line sr_sal,
5979 struct frame_id sr_id)
5980{
5981 insert_step_resume_breakpoint_at_sal_1 (gdbarch,
5982 sr_sal, sr_id,
5983 bp_step_resume);
5984}
5985
5986/* Insert a "high-priority step-resume breakpoint" at RETURN_FRAME.pc.
5987 This is used to skip a potential signal handler.
5988
5989 This is called with the interrupted function's frame. The signal
5990 handler, when it returns, will resume the interrupted function at
5991 RETURN_FRAME.pc. */
5992
5993static void
5994insert_hp_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5995{
5996 struct symtab_and_line sr_sal;
5997 struct gdbarch *gdbarch;
5998
5999 gdb_assert (return_frame != NULL);
6000 init_sal (&sr_sal); /* initialize to zeros */
6001
6002 gdbarch = get_frame_arch (return_frame);
6003 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
6004 sr_sal.section = find_pc_overlay (sr_sal.pc);
6005 sr_sal.pspace = get_frame_program_space (return_frame);
6006
6007 insert_step_resume_breakpoint_at_sal_1 (gdbarch, sr_sal,
6008 get_stack_frame_id (return_frame),
6009 bp_hp_step_resume);
6010}
6011
6012/* Insert a "step-resume breakpoint" at the previous frame's PC. This
6013 is used to skip a function after stepping into it (for "next" or if
6014 the called function has no debugging information).
6015
6016 The current function has almost always been reached by single
6017 stepping a call or return instruction. NEXT_FRAME belongs to the
6018 current function, and the breakpoint will be set at the caller's
6019 resume address.
6020
6021 This is a separate function rather than reusing
6022 insert_hp_step_resume_breakpoint_at_frame in order to avoid
6023 get_prev_frame, which may stop prematurely (see the implementation
6024 of frame_unwind_caller_id for an example). */
6025
6026static void
6027insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
6028{
6029 struct symtab_and_line sr_sal;
6030 struct gdbarch *gdbarch;
6031
6032 /* We shouldn't have gotten here if we don't know where the call site
6033 is. */
6034 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
6035
6036 init_sal (&sr_sal); /* initialize to zeros */
6037
6038 gdbarch = frame_unwind_caller_arch (next_frame);
6039 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
6040 frame_unwind_caller_pc (next_frame));
6041 sr_sal.section = find_pc_overlay (sr_sal.pc);
6042 sr_sal.pspace = frame_unwind_program_space (next_frame);
6043
6044 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
6045 frame_unwind_caller_id (next_frame));
6046}
6047
6048/* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
6049 new breakpoint at the target of a jmp_buf. The handling of
6050 longjmp-resume uses the same mechanisms used for handling
6051 "step-resume" breakpoints. */
6052
6053static void
6054insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
6055{
6056 /* There should never be more than one longjmp-resume breakpoint per
6057 thread, so we should never be setting a new
6058 longjmp_resume_breakpoint when one is already active. */
6059 gdb_assert (inferior_thread ()->control.exception_resume_breakpoint == NULL);
6060
6061 if (debug_infrun)
6062 fprintf_unfiltered (gdb_stdlog,
6063 "infrun: inserting longjmp-resume breakpoint at %s\n",
6064 paddress (gdbarch, pc));
6065
6066 inferior_thread ()->control.exception_resume_breakpoint =
6067 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
6068}
6069
6070/* Insert an exception resume breakpoint. TP is the thread throwing
6071 the exception. The block B is the block of the unwinder debug hook
6072 function. FRAME is the frame corresponding to the call to this
6073 function. SYM is the symbol of the function argument holding the
6074 target PC of the exception. */
6075
6076static void
6077insert_exception_resume_breakpoint (struct thread_info *tp,
6078 const struct block *b,
6079 struct frame_info *frame,
6080 struct symbol *sym)
6081{
6082 TRY
6083 {
6084 struct symbol *vsym;
6085 struct value *value;
6086 CORE_ADDR handler;
6087 struct breakpoint *bp;
6088
6089 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
6090 value = read_var_value (vsym, frame);
6091 /* If the value was optimized out, revert to the old behavior. */
6092 if (! value_optimized_out (value))
6093 {
6094 handler = value_as_address (value);
6095
6096 if (debug_infrun)
6097 fprintf_unfiltered (gdb_stdlog,
6098 "infrun: exception resume at %lx\n",
6099 (unsigned long) handler);
6100
6101 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
6102 handler, bp_exception_resume);
6103
6104 /* set_momentary_breakpoint_at_pc invalidates FRAME. */
6105 frame = NULL;
6106
6107 bp->thread = tp->num;
6108 inferior_thread ()->control.exception_resume_breakpoint = bp;
6109 }
6110 }
6111 CATCH (e, RETURN_MASK_ERROR)
6112 {
6113 /* We want to ignore errors here. */
6114 }
6115 END_CATCH
6116}
6117
6118/* A helper for check_exception_resume that sets an
6119 exception-breakpoint based on a SystemTap probe. */
6120
6121static void
6122insert_exception_resume_from_probe (struct thread_info *tp,
6123 const struct bound_probe *probe,
6124 struct frame_info *frame)
6125{
6126 struct value *arg_value;
6127 CORE_ADDR handler;
6128 struct breakpoint *bp;
6129
6130 arg_value = probe_safe_evaluate_at_pc (frame, 1);
6131 if (!arg_value)
6132 return;
6133
6134 handler = value_as_address (arg_value);
6135
6136 if (debug_infrun)
6137 fprintf_unfiltered (gdb_stdlog,
6138 "infrun: exception resume at %s\n",
6139 paddress (get_objfile_arch (probe->objfile),
6140 handler));
6141
6142 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
6143 handler, bp_exception_resume);
6144 bp->thread = tp->num;
6145 inferior_thread ()->control.exception_resume_breakpoint = bp;
6146}
6147
6148/* This is called when an exception has been intercepted. Check to
6149 see whether the exception's destination is of interest, and if so,
6150 set an exception resume breakpoint there. */
6151
6152static void
6153check_exception_resume (struct execution_control_state *ecs,
6154 struct frame_info *frame)
6155{
6156 struct bound_probe probe;
6157 struct symbol *func;
6158
6159 /* First see if this exception unwinding breakpoint was set via a
6160 SystemTap probe point. If so, the probe has two arguments: the
6161 CFA and the HANDLER. We ignore the CFA, extract the handler, and
6162 set a breakpoint there. */
6163 probe = find_probe_by_pc (get_frame_pc (frame));
6164 if (probe.probe)
6165 {
6166 insert_exception_resume_from_probe (ecs->event_thread, &probe, frame);
6167 return;
6168 }
6169
6170 func = get_frame_function (frame);
6171 if (!func)
6172 return;
6173
6174 TRY
6175 {
6176 const struct block *b;
6177 struct block_iterator iter;
6178 struct symbol *sym;
6179 int argno = 0;
6180
6181 /* The exception breakpoint is a thread-specific breakpoint on
6182 the unwinder's debug hook, declared as:
6183
6184 void _Unwind_DebugHook (void *cfa, void *handler);
6185
6186 The CFA argument indicates the frame to which control is
6187 about to be transferred. HANDLER is the destination PC.
6188
6189 We ignore the CFA and set a temporary breakpoint at HANDLER.
6190 This is not extremely efficient but it avoids issues in gdb
6191 with computing the DWARF CFA, and it also works even in weird
6192 cases such as throwing an exception from inside a signal
6193 handler. */
6194
6195 b = SYMBOL_BLOCK_VALUE (func);
6196 ALL_BLOCK_SYMBOLS (b, iter, sym)
6197 {
6198 if (!SYMBOL_IS_ARGUMENT (sym))
6199 continue;
6200
6201 if (argno == 0)
6202 ++argno;
6203 else
6204 {
6205 insert_exception_resume_breakpoint (ecs->event_thread,
6206 b, frame, sym);
6207 break;
6208 }
6209 }
6210 }
6211 CATCH (e, RETURN_MASK_ERROR)
6212 {
6213 }
6214 END_CATCH
6215}
6216
6217static void
6218stop_waiting (struct execution_control_state *ecs)
6219{
6220 if (debug_infrun)
6221 fprintf_unfiltered (gdb_stdlog, "infrun: stop_waiting\n");
6222
6223 clear_step_over_info ();
6224
6225 /* Let callers know we don't want to wait for the inferior anymore. */
6226 ecs->wait_some_more = 0;
6227}
6228
6229/* Called when we should continue running the inferior, because the
6230 current event doesn't cause a user visible stop. This does the
6231 resuming part; waiting for the next event is done elsewhere. */
6232
6233static void
6234keep_going (struct execution_control_state *ecs)
6235{
6236 /* Make sure normal_stop is called if we get a QUIT handled before
6237 reaching resume. */
6238 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
6239
6240 /* Save the pc before execution, to compare with pc after stop. */
6241 ecs->event_thread->prev_pc
6242 = regcache_read_pc (get_thread_regcache (ecs->ptid));
6243
6244 if (ecs->event_thread->control.trap_expected
6245 && ecs->event_thread->suspend.stop_signal != GDB_SIGNAL_TRAP)
6246 {
6247 /* We haven't yet gotten our trap, and either: intercepted a
6248 non-signal event (e.g., a fork); or took a signal which we
6249 are supposed to pass through to the inferior. Simply
6250 continue. */
6251 discard_cleanups (old_cleanups);
6252 resume (ecs->event_thread->suspend.stop_signal);
6253 }
6254 else
6255 {
6256 struct regcache *regcache = get_current_regcache ();
6257 int remove_bp;
6258 int remove_wps;
6259
6260 /* Either the trap was not expected, but we are continuing
6261 anyway (if we got a signal, the user asked it be passed to
6262 the child)
6263 -- or --
6264 We got our expected trap, but decided we should resume from
6265 it.
6266
6267 We're going to run this baby now!
6268
6269 Note that insert_breakpoints won't try to re-insert
6270 already inserted breakpoints. Therefore, we don't
6271 care if breakpoints were already inserted, or not. */
6272
6273 /* If we need to step over a breakpoint, and we're not using
6274 displaced stepping to do so, insert all breakpoints
6275 (watchpoints, etc.) but the one we're stepping over, step one
6276 instruction, and then re-insert the breakpoint when that step
6277 is finished. */
6278
6279 remove_bp = (ecs->hit_singlestep_breakpoint
6280 || thread_still_needs_step_over (ecs->event_thread));
6281 remove_wps = (ecs->event_thread->stepping_over_watchpoint
6282 && !target_have_steppable_watchpoint);
6283
6284 /* We can't use displaced stepping if we need to step past a
6285 watchpoint. The instruction copied to the scratch pad would
6286 still trigger the watchpoint. */
6287 if (remove_bp
6288 && (remove_wps
6289 || !use_displaced_stepping (get_regcache_arch (regcache))))
6290 {
6291 set_step_over_info (get_regcache_aspace (regcache),
6292 regcache_read_pc (regcache), remove_wps);
6293 }
6294 else if (remove_wps)
6295 set_step_over_info (NULL, 0, remove_wps);
6296 else
6297 clear_step_over_info ();
6298
6299 /* Stop stepping if inserting breakpoints fails. */
6300 TRY
6301 {
6302 insert_breakpoints ();
6303 }
6304 CATCH (e, RETURN_MASK_ERROR)
6305 {
6306 exception_print (gdb_stderr, e);
6307 stop_waiting (ecs);
6308 discard_cleanups (old_cleanups);
6309 return;
6310 }
6311 END_CATCH
6312
6313 ecs->event_thread->control.trap_expected = (remove_bp || remove_wps);
6314
6315 /* Do not deliver GDB_SIGNAL_TRAP (except when the user
6316 explicitly specifies that such a signal should be delivered
6317 to the target program). Typically, that would occur when a
6318 user is debugging a target monitor on a simulator: the target
6319 monitor sets a breakpoint; the simulator encounters this
6320 breakpoint and halts the simulation handing control to GDB;
6321 GDB, noting that the stop address doesn't map to any known
6322 breakpoint, returns control back to the simulator; the
6323 simulator then delivers the hardware equivalent of a
6324 GDB_SIGNAL_TRAP to the program being debugged. */
6325 if (ecs->event_thread->suspend.stop_signal == GDB_SIGNAL_TRAP
6326 && !signal_program[ecs->event_thread->suspend.stop_signal])
6327 ecs->event_thread->suspend.stop_signal = GDB_SIGNAL_0;
6328
6329 discard_cleanups (old_cleanups);
6330 resume (ecs->event_thread->suspend.stop_signal);
6331 }
6332
6333 prepare_to_wait (ecs);
6334}
6335
6336/* This function normally comes after a resume, before
6337 handle_inferior_event exits. It takes care of any last bits of
6338 housekeeping, and sets the all-important wait_some_more flag. */
6339
6340static void
6341prepare_to_wait (struct execution_control_state *ecs)
6342{
6343 if (debug_infrun)
6344 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
6345
6346 /* This is the old end of the while loop. Let everybody know we
6347 want to wait for the inferior some more and get called again
6348 soon. */
6349 ecs->wait_some_more = 1;
6350}
6351
6352/* We are done with the step range of a step/next/si/ni command.
6353 Called once for each n of a "step n" operation. */
6354
6355static void
6356end_stepping_range (struct execution_control_state *ecs)
6357{
6358 ecs->event_thread->control.stop_step = 1;
6359 stop_waiting (ecs);
6360}
6361
6362/* Several print_*_reason functions to print why the inferior has stopped.
6363 We always print something when the inferior exits, or receives a signal.
6364 The rest of the cases are dealt with later on in normal_stop and
6365 print_it_typical. Ideally there should be a call to one of these
6366 print_*_reason functions functions from handle_inferior_event each time
6367 stop_waiting is called.
6368
6369 Note that we don't call these directly, instead we delegate that to
6370 the interpreters, through observers. Interpreters then call these
6371 with whatever uiout is right. */
6372
6373void
6374print_end_stepping_range_reason (struct ui_out *uiout)
6375{
6376 /* For CLI-like interpreters, print nothing. */
6377
6378 if (ui_out_is_mi_like_p (uiout))
6379 {
6380 ui_out_field_string (uiout, "reason",
6381 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
6382 }
6383}
6384
6385void
6386print_signal_exited_reason (struct ui_out *uiout, enum gdb_signal siggnal)
6387{
6388 annotate_signalled ();
6389 if (ui_out_is_mi_like_p (uiout))
6390 ui_out_field_string
6391 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
6392 ui_out_text (uiout, "\nProgram terminated with signal ");
6393 annotate_signal_name ();
6394 ui_out_field_string (uiout, "signal-name",
6395 gdb_signal_to_name (siggnal));
6396 annotate_signal_name_end ();
6397 ui_out_text (uiout, ", ");
6398 annotate_signal_string ();
6399 ui_out_field_string (uiout, "signal-meaning",
6400 gdb_signal_to_string (siggnal));
6401 annotate_signal_string_end ();
6402 ui_out_text (uiout, ".\n");
6403 ui_out_text (uiout, "The program no longer exists.\n");
6404}
6405
6406void
6407print_exited_reason (struct ui_out *uiout, int exitstatus)
6408{
6409 struct inferior *inf = current_inferior ();
6410 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
6411
6412 annotate_exited (exitstatus);
6413 if (exitstatus)
6414 {
6415 if (ui_out_is_mi_like_p (uiout))
6416 ui_out_field_string (uiout, "reason",
6417 async_reason_lookup (EXEC_ASYNC_EXITED));
6418 ui_out_text (uiout, "[Inferior ");
6419 ui_out_text (uiout, plongest (inf->num));
6420 ui_out_text (uiout, " (");
6421 ui_out_text (uiout, pidstr);
6422 ui_out_text (uiout, ") exited with code ");
6423 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
6424 ui_out_text (uiout, "]\n");
6425 }
6426 else
6427 {
6428 if (ui_out_is_mi_like_p (uiout))
6429 ui_out_field_string
6430 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
6431 ui_out_text (uiout, "[Inferior ");
6432 ui_out_text (uiout, plongest (inf->num));
6433 ui_out_text (uiout, " (");
6434 ui_out_text (uiout, pidstr);
6435 ui_out_text (uiout, ") exited normally]\n");
6436 }
6437}
6438
6439void
6440print_signal_received_reason (struct ui_out *uiout, enum gdb_signal siggnal)
6441{
6442 annotate_signal ();
6443
6444 if (siggnal == GDB_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
6445 {
6446 struct thread_info *t = inferior_thread ();
6447
6448 ui_out_text (uiout, "\n[");
6449 ui_out_field_string (uiout, "thread-name",
6450 target_pid_to_str (t->ptid));
6451 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
6452 ui_out_text (uiout, " stopped");
6453 }
6454 else
6455 {
6456 ui_out_text (uiout, "\nProgram received signal ");
6457 annotate_signal_name ();
6458 if (ui_out_is_mi_like_p (uiout))
6459 ui_out_field_string
6460 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
6461 ui_out_field_string (uiout, "signal-name",
6462 gdb_signal_to_name (siggnal));
6463 annotate_signal_name_end ();
6464 ui_out_text (uiout, ", ");
6465 annotate_signal_string ();
6466 ui_out_field_string (uiout, "signal-meaning",
6467 gdb_signal_to_string (siggnal));
6468 annotate_signal_string_end ();
6469 }
6470 ui_out_text (uiout, ".\n");
6471}
6472
6473void
6474print_no_history_reason (struct ui_out *uiout)
6475{
6476 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
6477}
6478
6479/* Print current location without a level number, if we have changed
6480 functions or hit a breakpoint. Print source line if we have one.
6481 bpstat_print contains the logic deciding in detail what to print,
6482 based on the event(s) that just occurred. */
6483
6484void
6485print_stop_event (struct target_waitstatus *ws)
6486{
6487 int bpstat_ret;
6488 int source_flag;
6489 int do_frame_printing = 1;
6490 struct thread_info *tp = inferior_thread ();
6491
6492 bpstat_ret = bpstat_print (tp->control.stop_bpstat, ws->kind);
6493 switch (bpstat_ret)
6494 {
6495 case PRINT_UNKNOWN:
6496 /* FIXME: cagney/2002-12-01: Given that a frame ID does (or
6497 should) carry around the function and does (or should) use
6498 that when doing a frame comparison. */
6499 if (tp->control.stop_step
6500 && frame_id_eq (tp->control.step_frame_id,
6501 get_frame_id (get_current_frame ()))
6502 && tp->control.step_start_function == find_pc_function (stop_pc))
6503 {
6504 /* Finished step, just print source line. */
6505 source_flag = SRC_LINE;
6506 }
6507 else
6508 {
6509 /* Print location and source line. */
6510 source_flag = SRC_AND_LOC;
6511 }
6512 break;
6513 case PRINT_SRC_AND_LOC:
6514 /* Print location and source line. */
6515 source_flag = SRC_AND_LOC;
6516 break;
6517 case PRINT_SRC_ONLY:
6518 source_flag = SRC_LINE;
6519 break;
6520 case PRINT_NOTHING:
6521 /* Something bogus. */
6522 source_flag = SRC_LINE;
6523 do_frame_printing = 0;
6524 break;
6525 default:
6526 internal_error (__FILE__, __LINE__, _("Unknown value."));
6527 }
6528
6529 /* The behavior of this routine with respect to the source
6530 flag is:
6531 SRC_LINE: Print only source line
6532 LOCATION: Print only location
6533 SRC_AND_LOC: Print location and source line. */
6534 if (do_frame_printing)
6535 print_stack_frame (get_selected_frame (NULL), 0, source_flag, 1);
6536
6537 /* Display the auto-display expressions. */
6538 do_displays ();
6539}
6540
6541/* Here to return control to GDB when the inferior stops for real.
6542 Print appropriate messages, remove breakpoints, give terminal our modes.
6543
6544 STOP_PRINT_FRAME nonzero means print the executing frame
6545 (pc, function, args, file, line number and line text).
6546 BREAKPOINTS_FAILED nonzero means stop was due to error
6547 attempting to insert breakpoints. */
6548
6549void
6550normal_stop (void)
6551{
6552 struct target_waitstatus last;
6553 ptid_t last_ptid;
6554 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
6555
6556 get_last_target_status (&last_ptid, &last);
6557
6558 /* If an exception is thrown from this point on, make sure to
6559 propagate GDB's knowledge of the executing state to the
6560 frontend/user running state. A QUIT is an easy exception to see
6561 here, so do this before any filtered output. */
6562 if (!non_stop)
6563 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
6564 else if (last.kind != TARGET_WAITKIND_SIGNALLED
6565 && last.kind != TARGET_WAITKIND_EXITED
6566 && last.kind != TARGET_WAITKIND_NO_RESUMED)
6567 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
6568
6569 /* As we're presenting a stop, and potentially removing breakpoints,
6570 update the thread list so we can tell whether there are threads
6571 running on the target. With target remote, for example, we can
6572 only learn about new threads when we explicitly update the thread
6573 list. Do this before notifying the interpreters about signal
6574 stops, end of stepping ranges, etc., so that the "new thread"
6575 output is emitted before e.g., "Program received signal FOO",
6576 instead of after. */
6577 update_thread_list ();
6578
6579 if (last.kind == TARGET_WAITKIND_STOPPED && stopped_by_random_signal)
6580 observer_notify_signal_received (inferior_thread ()->suspend.stop_signal);
6581
6582 /* As with the notification of thread events, we want to delay
6583 notifying the user that we've switched thread context until
6584 the inferior actually stops.
6585
6586 There's no point in saying anything if the inferior has exited.
6587 Note that SIGNALLED here means "exited with a signal", not
6588 "received a signal".
6589
6590 Also skip saying anything in non-stop mode. In that mode, as we
6591 don't want GDB to switch threads behind the user's back, to avoid
6592 races where the user is typing a command to apply to thread x,
6593 but GDB switches to thread y before the user finishes entering
6594 the command, fetch_inferior_event installs a cleanup to restore
6595 the current thread back to the thread the user had selected right
6596 after this event is handled, so we're not really switching, only
6597 informing of a stop. */
6598 if (!non_stop
6599 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
6600 && target_has_execution
6601 && last.kind != TARGET_WAITKIND_SIGNALLED
6602 && last.kind != TARGET_WAITKIND_EXITED
6603 && last.kind != TARGET_WAITKIND_NO_RESUMED)
6604 {
6605 target_terminal_ours_for_output ();
6606 printf_filtered (_("[Switching to %s]\n"),
6607 target_pid_to_str (inferior_ptid));
6608 annotate_thread_changed ();
6609 previous_inferior_ptid = inferior_ptid;
6610 }
6611
6612 if (last.kind == TARGET_WAITKIND_NO_RESUMED)
6613 {
6614 gdb_assert (sync_execution || !target_can_async_p ());
6615
6616 target_terminal_ours_for_output ();
6617 printf_filtered (_("No unwaited-for children left.\n"));
6618 }
6619
6620 /* Note: this depends on the update_thread_list call above. */
6621 if (!breakpoints_should_be_inserted_now () && target_has_execution)
6622 {
6623 if (remove_breakpoints ())
6624 {
6625 target_terminal_ours_for_output ();
6626 printf_filtered (_("Cannot remove breakpoints because "
6627 "program is no longer writable.\nFurther "
6628 "execution is probably impossible.\n"));
6629 }
6630 }
6631
6632 /* If an auto-display called a function and that got a signal,
6633 delete that auto-display to avoid an infinite recursion. */
6634
6635 if (stopped_by_random_signal)
6636 disable_current_display ();
6637
6638 /* Notify observers if we finished a "step"-like command, etc. */
6639 if (target_has_execution
6640 && last.kind != TARGET_WAITKIND_SIGNALLED
6641 && last.kind != TARGET_WAITKIND_EXITED
6642 && inferior_thread ()->control.stop_step)
6643 {
6644 /* But not if in the middle of doing a "step n" operation for
6645 n > 1 */
6646 if (inferior_thread ()->step_multi)
6647 goto done;
6648
6649 observer_notify_end_stepping_range ();
6650 }
6651
6652 target_terminal_ours ();
6653 async_enable_stdin ();
6654
6655 /* Set the current source location. This will also happen if we
6656 display the frame below, but the current SAL will be incorrect
6657 during a user hook-stop function. */
6658 if (has_stack_frames () && !stop_stack_dummy)
6659 set_current_sal_from_frame (get_current_frame ());
6660
6661 /* Let the user/frontend see the threads as stopped, but do nothing
6662 if the thread was running an infcall. We may be e.g., evaluating
6663 a breakpoint condition. In that case, the thread had state
6664 THREAD_RUNNING before the infcall, and shall remain set to
6665 running, all without informing the user/frontend about state
6666 transition changes. If this is actually a call command, then the
6667 thread was originally already stopped, so there's no state to
6668 finish either. */
6669 if (target_has_execution && inferior_thread ()->control.in_infcall)
6670 discard_cleanups (old_chain);
6671 else
6672 do_cleanups (old_chain);
6673
6674 /* Look up the hook_stop and run it (CLI internally handles problem
6675 of stop_command's pre-hook not existing). */
6676 if (stop_command)
6677 catch_errors (hook_stop_stub, stop_command,
6678 "Error while running hook_stop:\n", RETURN_MASK_ALL);
6679
6680 if (!has_stack_frames ())
6681 goto done;
6682
6683 if (last.kind == TARGET_WAITKIND_SIGNALLED
6684 || last.kind == TARGET_WAITKIND_EXITED)
6685 goto done;
6686
6687 /* Select innermost stack frame - i.e., current frame is frame 0,
6688 and current location is based on that.
6689 Don't do this on return from a stack dummy routine,
6690 or if the program has exited. */
6691
6692 if (!stop_stack_dummy)
6693 {
6694 select_frame (get_current_frame ());
6695
6696 /* If --batch-silent is enabled then there's no need to print the current
6697 source location, and to try risks causing an error message about
6698 missing source files. */
6699 if (stop_print_frame && !batch_silent)
6700 print_stop_event (&last);
6701 }
6702
6703 if (stop_stack_dummy == STOP_STACK_DUMMY)
6704 {
6705 /* Pop the empty frame that contains the stack dummy.
6706 This also restores inferior state prior to the call
6707 (struct infcall_suspend_state). */
6708 struct frame_info *frame = get_current_frame ();
6709
6710 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
6711 frame_pop (frame);
6712 /* frame_pop() calls reinit_frame_cache as the last thing it
6713 does which means there's currently no selected frame. We
6714 don't need to re-establish a selected frame if the dummy call
6715 returns normally, that will be done by
6716 restore_infcall_control_state. However, we do have to handle
6717 the case where the dummy call is returning after being
6718 stopped (e.g. the dummy call previously hit a breakpoint).
6719 We can't know which case we have so just always re-establish
6720 a selected frame here. */
6721 select_frame (get_current_frame ());
6722 }
6723
6724done:
6725 annotate_stopped ();
6726
6727 /* Suppress the stop observer if we're in the middle of:
6728
6729 - a step n (n > 1), as there still more steps to be done.
6730
6731 - a "finish" command, as the observer will be called in
6732 finish_command_continuation, so it can include the inferior
6733 function's return value.
6734
6735 - calling an inferior function, as we pretend we inferior didn't
6736 run at all. The return value of the call is handled by the
6737 expression evaluator, through call_function_by_hand. */
6738
6739 if (!target_has_execution
6740 || last.kind == TARGET_WAITKIND_SIGNALLED
6741 || last.kind == TARGET_WAITKIND_EXITED
6742 || last.kind == TARGET_WAITKIND_NO_RESUMED
6743 || (!(inferior_thread ()->step_multi
6744 && inferior_thread ()->control.stop_step)
6745 && !(inferior_thread ()->control.stop_bpstat
6746 && inferior_thread ()->control.proceed_to_finish)
6747 && !inferior_thread ()->control.in_infcall))
6748 {
6749 if (!ptid_equal (inferior_ptid, null_ptid))
6750 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
6751 stop_print_frame);
6752 else
6753 observer_notify_normal_stop (NULL, stop_print_frame);
6754 }
6755
6756 if (target_has_execution)
6757 {
6758 if (last.kind != TARGET_WAITKIND_SIGNALLED
6759 && last.kind != TARGET_WAITKIND_EXITED)
6760 /* Delete the breakpoint we stopped at, if it wants to be deleted.
6761 Delete any breakpoint that is to be deleted at the next stop. */
6762 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
6763 }
6764
6765 /* Try to get rid of automatically added inferiors that are no
6766 longer needed. Keeping those around slows down things linearly.
6767 Note that this never removes the current inferior. */
6768 prune_inferiors ();
6769}
6770
6771static int
6772hook_stop_stub (void *cmd)
6773{
6774 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
6775 return (0);
6776}
6777\f
6778int
6779signal_stop_state (int signo)
6780{
6781 return signal_stop[signo];
6782}
6783
6784int
6785signal_print_state (int signo)
6786{
6787 return signal_print[signo];
6788}
6789
6790int
6791signal_pass_state (int signo)
6792{
6793 return signal_program[signo];
6794}
6795
6796static void
6797signal_cache_update (int signo)
6798{
6799 if (signo == -1)
6800 {
6801 for (signo = 0; signo < (int) GDB_SIGNAL_LAST; signo++)
6802 signal_cache_update (signo);
6803
6804 return;
6805 }
6806
6807 signal_pass[signo] = (signal_stop[signo] == 0
6808 && signal_print[signo] == 0
6809 && signal_program[signo] == 1
6810 && signal_catch[signo] == 0);
6811}
6812
6813int
6814signal_stop_update (int signo, int state)
6815{
6816 int ret = signal_stop[signo];
6817
6818 signal_stop[signo] = state;
6819 signal_cache_update (signo);
6820 return ret;
6821}
6822
6823int
6824signal_print_update (int signo, int state)
6825{
6826 int ret = signal_print[signo];
6827
6828 signal_print[signo] = state;
6829 signal_cache_update (signo);
6830 return ret;
6831}
6832
6833int
6834signal_pass_update (int signo, int state)
6835{
6836 int ret = signal_program[signo];
6837
6838 signal_program[signo] = state;
6839 signal_cache_update (signo);
6840 return ret;
6841}
6842
6843/* Update the global 'signal_catch' from INFO and notify the
6844 target. */
6845
6846void
6847signal_catch_update (const unsigned int *info)
6848{
6849 int i;
6850
6851 for (i = 0; i < GDB_SIGNAL_LAST; ++i)
6852 signal_catch[i] = info[i] > 0;
6853 signal_cache_update (-1);
6854 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
6855}
6856
6857static void
6858sig_print_header (void)
6859{
6860 printf_filtered (_("Signal Stop\tPrint\tPass "
6861 "to program\tDescription\n"));
6862}
6863
6864static void
6865sig_print_info (enum gdb_signal oursig)
6866{
6867 const char *name = gdb_signal_to_name (oursig);
6868 int name_padding = 13 - strlen (name);
6869
6870 if (name_padding <= 0)
6871 name_padding = 0;
6872
6873 printf_filtered ("%s", name);
6874 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
6875 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
6876 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
6877 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
6878 printf_filtered ("%s\n", gdb_signal_to_string (oursig));
6879}
6880
6881/* Specify how various signals in the inferior should be handled. */
6882
6883static void
6884handle_command (char *args, int from_tty)
6885{
6886 char **argv;
6887 int digits, wordlen;
6888 int sigfirst, signum, siglast;
6889 enum gdb_signal oursig;
6890 int allsigs;
6891 int nsigs;
6892 unsigned char *sigs;
6893 struct cleanup *old_chain;
6894
6895 if (args == NULL)
6896 {
6897 error_no_arg (_("signal to handle"));
6898 }
6899
6900 /* Allocate and zero an array of flags for which signals to handle. */
6901
6902 nsigs = (int) GDB_SIGNAL_LAST;
6903 sigs = (unsigned char *) alloca (nsigs);
6904 memset (sigs, 0, nsigs);
6905
6906 /* Break the command line up into args. */
6907
6908 argv = gdb_buildargv (args);
6909 old_chain = make_cleanup_freeargv (argv);
6910
6911 /* Walk through the args, looking for signal oursigs, signal names, and
6912 actions. Signal numbers and signal names may be interspersed with
6913 actions, with the actions being performed for all signals cumulatively
6914 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6915
6916 while (*argv != NULL)
6917 {
6918 wordlen = strlen (*argv);
6919 for (digits = 0; isdigit ((*argv)[digits]); digits++)
6920 {;
6921 }
6922 allsigs = 0;
6923 sigfirst = siglast = -1;
6924
6925 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
6926 {
6927 /* Apply action to all signals except those used by the
6928 debugger. Silently skip those. */
6929 allsigs = 1;
6930 sigfirst = 0;
6931 siglast = nsigs - 1;
6932 }
6933 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
6934 {
6935 SET_SIGS (nsigs, sigs, signal_stop);
6936 SET_SIGS (nsigs, sigs, signal_print);
6937 }
6938 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
6939 {
6940 UNSET_SIGS (nsigs, sigs, signal_program);
6941 }
6942 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
6943 {
6944 SET_SIGS (nsigs, sigs, signal_print);
6945 }
6946 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
6947 {
6948 SET_SIGS (nsigs, sigs, signal_program);
6949 }
6950 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
6951 {
6952 UNSET_SIGS (nsigs, sigs, signal_stop);
6953 }
6954 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
6955 {
6956 SET_SIGS (nsigs, sigs, signal_program);
6957 }
6958 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
6959 {
6960 UNSET_SIGS (nsigs, sigs, signal_print);
6961 UNSET_SIGS (nsigs, sigs, signal_stop);
6962 }
6963 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
6964 {
6965 UNSET_SIGS (nsigs, sigs, signal_program);
6966 }
6967 else if (digits > 0)
6968 {
6969 /* It is numeric. The numeric signal refers to our own
6970 internal signal numbering from target.h, not to host/target
6971 signal number. This is a feature; users really should be
6972 using symbolic names anyway, and the common ones like
6973 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6974
6975 sigfirst = siglast = (int)
6976 gdb_signal_from_command (atoi (*argv));
6977 if ((*argv)[digits] == '-')
6978 {
6979 siglast = (int)
6980 gdb_signal_from_command (atoi ((*argv) + digits + 1));
6981 }
6982 if (sigfirst > siglast)
6983 {
6984 /* Bet he didn't figure we'd think of this case... */
6985 signum = sigfirst;
6986 sigfirst = siglast;
6987 siglast = signum;
6988 }
6989 }
6990 else
6991 {
6992 oursig = gdb_signal_from_name (*argv);
6993 if (oursig != GDB_SIGNAL_UNKNOWN)
6994 {
6995 sigfirst = siglast = (int) oursig;
6996 }
6997 else
6998 {
6999 /* Not a number and not a recognized flag word => complain. */
7000 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
7001 }
7002 }
7003
7004 /* If any signal numbers or symbol names were found, set flags for
7005 which signals to apply actions to. */
7006
7007 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
7008 {
7009 switch ((enum gdb_signal) signum)
7010 {
7011 case GDB_SIGNAL_TRAP:
7012 case GDB_SIGNAL_INT:
7013 if (!allsigs && !sigs[signum])
7014 {
7015 if (query (_("%s is used by the debugger.\n\
7016Are you sure you want to change it? "),
7017 gdb_signal_to_name ((enum gdb_signal) signum)))
7018 {
7019 sigs[signum] = 1;
7020 }
7021 else
7022 {
7023 printf_unfiltered (_("Not confirmed, unchanged.\n"));
7024 gdb_flush (gdb_stdout);
7025 }
7026 }
7027 break;
7028 case GDB_SIGNAL_0:
7029 case GDB_SIGNAL_DEFAULT:
7030 case GDB_SIGNAL_UNKNOWN:
7031 /* Make sure that "all" doesn't print these. */
7032 break;
7033 default:
7034 sigs[signum] = 1;
7035 break;
7036 }
7037 }
7038
7039 argv++;
7040 }
7041
7042 for (signum = 0; signum < nsigs; signum++)
7043 if (sigs[signum])
7044 {
7045 signal_cache_update (-1);
7046 target_pass_signals ((int) GDB_SIGNAL_LAST, signal_pass);
7047 target_program_signals ((int) GDB_SIGNAL_LAST, signal_program);
7048
7049 if (from_tty)
7050 {
7051 /* Show the results. */
7052 sig_print_header ();
7053 for (; signum < nsigs; signum++)
7054 if (sigs[signum])
7055 sig_print_info (signum);
7056 }
7057
7058 break;
7059 }
7060
7061 do_cleanups (old_chain);
7062}
7063
7064/* Complete the "handle" command. */
7065
7066static VEC (char_ptr) *
7067handle_completer (struct cmd_list_element *ignore,
7068 const char *text, const char *word)
7069{
7070 VEC (char_ptr) *vec_signals, *vec_keywords, *return_val;
7071 static const char * const keywords[] =
7072 {
7073 "all",
7074 "stop",
7075 "ignore",
7076 "print",
7077 "pass",
7078 "nostop",
7079 "noignore",
7080 "noprint",
7081 "nopass",
7082 NULL,
7083 };
7084
7085 vec_signals = signal_completer (ignore, text, word);
7086 vec_keywords = complete_on_enum (keywords, word, word);
7087
7088 return_val = VEC_merge (char_ptr, vec_signals, vec_keywords);
7089 VEC_free (char_ptr, vec_signals);
7090 VEC_free (char_ptr, vec_keywords);
7091 return return_val;
7092}
7093
7094enum gdb_signal
7095gdb_signal_from_command (int num)
7096{
7097 if (num >= 1 && num <= 15)
7098 return (enum gdb_signal) num;
7099 error (_("Only signals 1-15 are valid as numeric signals.\n\
7100Use \"info signals\" for a list of symbolic signals."));
7101}
7102
7103/* Print current contents of the tables set by the handle command.
7104 It is possible we should just be printing signals actually used
7105 by the current target (but for things to work right when switching
7106 targets, all signals should be in the signal tables). */
7107
7108static void
7109signals_info (char *signum_exp, int from_tty)
7110{
7111 enum gdb_signal oursig;
7112
7113 sig_print_header ();
7114
7115 if (signum_exp)
7116 {
7117 /* First see if this is a symbol name. */
7118 oursig = gdb_signal_from_name (signum_exp);
7119 if (oursig == GDB_SIGNAL_UNKNOWN)
7120 {
7121 /* No, try numeric. */
7122 oursig =
7123 gdb_signal_from_command (parse_and_eval_long (signum_exp));
7124 }
7125 sig_print_info (oursig);
7126 return;
7127 }
7128
7129 printf_filtered ("\n");
7130 /* These ugly casts brought to you by the native VAX compiler. */
7131 for (oursig = GDB_SIGNAL_FIRST;
7132 (int) oursig < (int) GDB_SIGNAL_LAST;
7133 oursig = (enum gdb_signal) ((int) oursig + 1))
7134 {
7135 QUIT;
7136
7137 if (oursig != GDB_SIGNAL_UNKNOWN
7138 && oursig != GDB_SIGNAL_DEFAULT && oursig != GDB_SIGNAL_0)
7139 sig_print_info (oursig);
7140 }
7141
7142 printf_filtered (_("\nUse the \"handle\" command "
7143 "to change these tables.\n"));
7144}
7145
7146/* Check if it makes sense to read $_siginfo from the current thread
7147 at this point. If not, throw an error. */
7148
7149static void
7150validate_siginfo_access (void)
7151{
7152 /* No current inferior, no siginfo. */
7153 if (ptid_equal (inferior_ptid, null_ptid))
7154 error (_("No thread selected."));
7155
7156 /* Don't try to read from a dead thread. */
7157 if (is_exited (inferior_ptid))
7158 error (_("The current thread has terminated"));
7159
7160 /* ... or from a spinning thread. */
7161 if (is_running (inferior_ptid))
7162 error (_("Selected thread is running."));
7163}
7164
7165/* The $_siginfo convenience variable is a bit special. We don't know
7166 for sure the type of the value until we actually have a chance to
7167 fetch the data. The type can change depending on gdbarch, so it is
7168 also dependent on which thread you have selected.
7169
7170 1. making $_siginfo be an internalvar that creates a new value on
7171 access.
7172
7173 2. making the value of $_siginfo be an lval_computed value. */
7174
7175/* This function implements the lval_computed support for reading a
7176 $_siginfo value. */
7177
7178static void
7179siginfo_value_read (struct value *v)
7180{
7181 LONGEST transferred;
7182
7183 validate_siginfo_access ();
7184
7185 transferred =
7186 target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO,
7187 NULL,
7188 value_contents_all_raw (v),
7189 value_offset (v),
7190 TYPE_LENGTH (value_type (v)));
7191
7192 if (transferred != TYPE_LENGTH (value_type (v)))
7193 error (_("Unable to read siginfo"));
7194}
7195
7196/* This function implements the lval_computed support for writing a
7197 $_siginfo value. */
7198
7199static void
7200siginfo_value_write (struct value *v, struct value *fromval)
7201{
7202 LONGEST transferred;
7203
7204 validate_siginfo_access ();
7205
7206 transferred = target_write (&current_target,
7207 TARGET_OBJECT_SIGNAL_INFO,
7208 NULL,
7209 value_contents_all_raw (fromval),
7210 value_offset (v),
7211 TYPE_LENGTH (value_type (fromval)));
7212
7213 if (transferred != TYPE_LENGTH (value_type (fromval)))
7214 error (_("Unable to write siginfo"));
7215}
7216
7217static const struct lval_funcs siginfo_value_funcs =
7218 {
7219 siginfo_value_read,
7220 siginfo_value_write
7221 };
7222
7223/* Return a new value with the correct type for the siginfo object of
7224 the current thread using architecture GDBARCH. Return a void value
7225 if there's no object available. */
7226
7227static struct value *
7228siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var,
7229 void *ignore)
7230{
7231 if (target_has_stack
7232 && !ptid_equal (inferior_ptid, null_ptid)
7233 && gdbarch_get_siginfo_type_p (gdbarch))
7234 {
7235 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7236
7237 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
7238 }
7239
7240 return allocate_value (builtin_type (gdbarch)->builtin_void);
7241}
7242
7243\f
7244/* infcall_suspend_state contains state about the program itself like its
7245 registers and any signal it received when it last stopped.
7246 This state must be restored regardless of how the inferior function call
7247 ends (either successfully, or after it hits a breakpoint or signal)
7248 if the program is to properly continue where it left off. */
7249
7250struct infcall_suspend_state
7251{
7252 struct thread_suspend_state thread_suspend;
7253#if 0 /* Currently unused and empty structures are not valid C. */
7254 struct inferior_suspend_state inferior_suspend;
7255#endif
7256
7257 /* Other fields: */
7258 CORE_ADDR stop_pc;
7259 struct regcache *registers;
7260
7261 /* Format of SIGINFO_DATA or NULL if it is not present. */
7262 struct gdbarch *siginfo_gdbarch;
7263
7264 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
7265 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
7266 content would be invalid. */
7267 gdb_byte *siginfo_data;
7268};
7269
7270struct infcall_suspend_state *
7271save_infcall_suspend_state (void)
7272{
7273 struct infcall_suspend_state *inf_state;
7274 struct thread_info *tp = inferior_thread ();
7275#if 0
7276 struct inferior *inf = current_inferior ();
7277#endif
7278 struct regcache *regcache = get_current_regcache ();
7279 struct gdbarch *gdbarch = get_regcache_arch (regcache);
7280 gdb_byte *siginfo_data = NULL;
7281
7282 if (gdbarch_get_siginfo_type_p (gdbarch))
7283 {
7284 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7285 size_t len = TYPE_LENGTH (type);
7286 struct cleanup *back_to;
7287
7288 siginfo_data = xmalloc (len);
7289 back_to = make_cleanup (xfree, siginfo_data);
7290
7291 if (target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
7292 siginfo_data, 0, len) == len)
7293 discard_cleanups (back_to);
7294 else
7295 {
7296 /* Errors ignored. */
7297 do_cleanups (back_to);
7298 siginfo_data = NULL;
7299 }
7300 }
7301
7302 inf_state = XCNEW (struct infcall_suspend_state);
7303
7304 if (siginfo_data)
7305 {
7306 inf_state->siginfo_gdbarch = gdbarch;
7307 inf_state->siginfo_data = siginfo_data;
7308 }
7309
7310 inf_state->thread_suspend = tp->suspend;
7311#if 0 /* Currently unused and empty structures are not valid C. */
7312 inf_state->inferior_suspend = inf->suspend;
7313#endif
7314
7315 /* run_inferior_call will not use the signal due to its `proceed' call with
7316 GDB_SIGNAL_0 anyway. */
7317 tp->suspend.stop_signal = GDB_SIGNAL_0;
7318
7319 inf_state->stop_pc = stop_pc;
7320
7321 inf_state->registers = regcache_dup (regcache);
7322
7323 return inf_state;
7324}
7325
7326/* Restore inferior session state to INF_STATE. */
7327
7328void
7329restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
7330{
7331 struct thread_info *tp = inferior_thread ();
7332#if 0
7333 struct inferior *inf = current_inferior ();
7334#endif
7335 struct regcache *regcache = get_current_regcache ();
7336 struct gdbarch *gdbarch = get_regcache_arch (regcache);
7337
7338 tp->suspend = inf_state->thread_suspend;
7339#if 0 /* Currently unused and empty structures are not valid C. */
7340 inf->suspend = inf_state->inferior_suspend;
7341#endif
7342
7343 stop_pc = inf_state->stop_pc;
7344
7345 if (inf_state->siginfo_gdbarch == gdbarch)
7346 {
7347 struct type *type = gdbarch_get_siginfo_type (gdbarch);
7348
7349 /* Errors ignored. */
7350 target_write (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
7351 inf_state->siginfo_data, 0, TYPE_LENGTH (type));
7352 }
7353
7354 /* The inferior can be gone if the user types "print exit(0)"
7355 (and perhaps other times). */
7356 if (target_has_execution)
7357 /* NB: The register write goes through to the target. */
7358 regcache_cpy (regcache, inf_state->registers);
7359
7360 discard_infcall_suspend_state (inf_state);
7361}
7362
7363static void
7364do_restore_infcall_suspend_state_cleanup (void *state)
7365{
7366 restore_infcall_suspend_state (state);
7367}
7368
7369struct cleanup *
7370make_cleanup_restore_infcall_suspend_state
7371 (struct infcall_suspend_state *inf_state)
7372{
7373 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
7374}
7375
7376void
7377discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
7378{
7379 regcache_xfree (inf_state->registers);
7380 xfree (inf_state->siginfo_data);
7381 xfree (inf_state);
7382}
7383
7384struct regcache *
7385get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
7386{
7387 return inf_state->registers;
7388}
7389
7390/* infcall_control_state contains state regarding gdb's control of the
7391 inferior itself like stepping control. It also contains session state like
7392 the user's currently selected frame. */
7393
7394struct infcall_control_state
7395{
7396 struct thread_control_state thread_control;
7397 struct inferior_control_state inferior_control;
7398
7399 /* Other fields: */
7400 enum stop_stack_kind stop_stack_dummy;
7401 int stopped_by_random_signal;
7402 int stop_after_trap;
7403
7404 /* ID if the selected frame when the inferior function call was made. */
7405 struct frame_id selected_frame_id;
7406};
7407
7408/* Save all of the information associated with the inferior<==>gdb
7409 connection. */
7410
7411struct infcall_control_state *
7412save_infcall_control_state (void)
7413{
7414 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
7415 struct thread_info *tp = inferior_thread ();
7416 struct inferior *inf = current_inferior ();
7417
7418 inf_status->thread_control = tp->control;
7419 inf_status->inferior_control = inf->control;
7420
7421 tp->control.step_resume_breakpoint = NULL;
7422 tp->control.exception_resume_breakpoint = NULL;
7423
7424 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
7425 chain. If caller's caller is walking the chain, they'll be happier if we
7426 hand them back the original chain when restore_infcall_control_state is
7427 called. */
7428 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
7429
7430 /* Other fields: */
7431 inf_status->stop_stack_dummy = stop_stack_dummy;
7432 inf_status->stopped_by_random_signal = stopped_by_random_signal;
7433 inf_status->stop_after_trap = stop_after_trap;
7434
7435 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
7436
7437 return inf_status;
7438}
7439
7440static int
7441restore_selected_frame (void *args)
7442{
7443 struct frame_id *fid = (struct frame_id *) args;
7444 struct frame_info *frame;
7445
7446 frame = frame_find_by_id (*fid);
7447
7448 /* If inf_status->selected_frame_id is NULL, there was no previously
7449 selected frame. */
7450 if (frame == NULL)
7451 {
7452 warning (_("Unable to restore previously selected frame."));
7453 return 0;
7454 }
7455
7456 select_frame (frame);
7457
7458 return (1);
7459}
7460
7461/* Restore inferior session state to INF_STATUS. */
7462
7463void
7464restore_infcall_control_state (struct infcall_control_state *inf_status)
7465{
7466 struct thread_info *tp = inferior_thread ();
7467 struct inferior *inf = current_inferior ();
7468
7469 if (tp->control.step_resume_breakpoint)
7470 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
7471
7472 if (tp->control.exception_resume_breakpoint)
7473 tp->control.exception_resume_breakpoint->disposition
7474 = disp_del_at_next_stop;
7475
7476 /* Handle the bpstat_copy of the chain. */
7477 bpstat_clear (&tp->control.stop_bpstat);
7478
7479 tp->control = inf_status->thread_control;
7480 inf->control = inf_status->inferior_control;
7481
7482 /* Other fields: */
7483 stop_stack_dummy = inf_status->stop_stack_dummy;
7484 stopped_by_random_signal = inf_status->stopped_by_random_signal;
7485 stop_after_trap = inf_status->stop_after_trap;
7486
7487 if (target_has_stack)
7488 {
7489 /* The point of catch_errors is that if the stack is clobbered,
7490 walking the stack might encounter a garbage pointer and
7491 error() trying to dereference it. */
7492 if (catch_errors
7493 (restore_selected_frame, &inf_status->selected_frame_id,
7494 "Unable to restore previously selected frame:\n",
7495 RETURN_MASK_ERROR) == 0)
7496 /* Error in restoring the selected frame. Select the innermost
7497 frame. */
7498 select_frame (get_current_frame ());
7499 }
7500
7501 xfree (inf_status);
7502}
7503
7504static void
7505do_restore_infcall_control_state_cleanup (void *sts)
7506{
7507 restore_infcall_control_state (sts);
7508}
7509
7510struct cleanup *
7511make_cleanup_restore_infcall_control_state
7512 (struct infcall_control_state *inf_status)
7513{
7514 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
7515}
7516
7517void
7518discard_infcall_control_state (struct infcall_control_state *inf_status)
7519{
7520 if (inf_status->thread_control.step_resume_breakpoint)
7521 inf_status->thread_control.step_resume_breakpoint->disposition
7522 = disp_del_at_next_stop;
7523
7524 if (inf_status->thread_control.exception_resume_breakpoint)
7525 inf_status->thread_control.exception_resume_breakpoint->disposition
7526 = disp_del_at_next_stop;
7527
7528 /* See save_infcall_control_state for info on stop_bpstat. */
7529 bpstat_clear (&inf_status->thread_control.stop_bpstat);
7530
7531 xfree (inf_status);
7532}
7533\f
7534/* restore_inferior_ptid() will be used by the cleanup machinery
7535 to restore the inferior_ptid value saved in a call to
7536 save_inferior_ptid(). */
7537
7538static void
7539restore_inferior_ptid (void *arg)
7540{
7541 ptid_t *saved_ptid_ptr = arg;
7542
7543 inferior_ptid = *saved_ptid_ptr;
7544 xfree (arg);
7545}
7546
7547/* Save the value of inferior_ptid so that it may be restored by a
7548 later call to do_cleanups(). Returns the struct cleanup pointer
7549 needed for later doing the cleanup. */
7550
7551struct cleanup *
7552save_inferior_ptid (void)
7553{
7554 ptid_t *saved_ptid_ptr;
7555
7556 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
7557 *saved_ptid_ptr = inferior_ptid;
7558 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
7559}
7560
7561/* See infrun.h. */
7562
7563void
7564clear_exit_convenience_vars (void)
7565{
7566 clear_internalvar (lookup_internalvar ("_exitsignal"));
7567 clear_internalvar (lookup_internalvar ("_exitcode"));
7568}
7569\f
7570
7571/* User interface for reverse debugging:
7572 Set exec-direction / show exec-direction commands
7573 (returns error unless target implements to_set_exec_direction method). */
7574
7575int execution_direction = EXEC_FORWARD;
7576static const char exec_forward[] = "forward";
7577static const char exec_reverse[] = "reverse";
7578static const char *exec_direction = exec_forward;
7579static const char *const exec_direction_names[] = {
7580 exec_forward,
7581 exec_reverse,
7582 NULL
7583};
7584
7585static void
7586set_exec_direction_func (char *args, int from_tty,
7587 struct cmd_list_element *cmd)
7588{
7589 if (target_can_execute_reverse)
7590 {
7591 if (!strcmp (exec_direction, exec_forward))
7592 execution_direction = EXEC_FORWARD;
7593 else if (!strcmp (exec_direction, exec_reverse))
7594 execution_direction = EXEC_REVERSE;
7595 }
7596 else
7597 {
7598 exec_direction = exec_forward;
7599 error (_("Target does not support this operation."));
7600 }
7601}
7602
7603static void
7604show_exec_direction_func (struct ui_file *out, int from_tty,
7605 struct cmd_list_element *cmd, const char *value)
7606{
7607 switch (execution_direction) {
7608 case EXEC_FORWARD:
7609 fprintf_filtered (out, _("Forward.\n"));
7610 break;
7611 case EXEC_REVERSE:
7612 fprintf_filtered (out, _("Reverse.\n"));
7613 break;
7614 default:
7615 internal_error (__FILE__, __LINE__,
7616 _("bogus execution_direction value: %d"),
7617 (int) execution_direction);
7618 }
7619}
7620
7621static void
7622show_schedule_multiple (struct ui_file *file, int from_tty,
7623 struct cmd_list_element *c, const char *value)
7624{
7625 fprintf_filtered (file, _("Resuming the execution of threads "
7626 "of all processes is %s.\n"), value);
7627}
7628
7629/* Implementation of `siginfo' variable. */
7630
7631static const struct internalvar_funcs siginfo_funcs =
7632{
7633 siginfo_make_value,
7634 NULL,
7635 NULL
7636};
7637
7638void
7639_initialize_infrun (void)
7640{
7641 int i;
7642 int numsigs;
7643 struct cmd_list_element *c;
7644
7645 add_info ("signals", signals_info, _("\
7646What debugger does when program gets various signals.\n\
7647Specify a signal as argument to print info on that signal only."));
7648 add_info_alias ("handle", "signals", 0);
7649
7650 c = add_com ("handle", class_run, handle_command, _("\
7651Specify how to handle signals.\n\
7652Usage: handle SIGNAL [ACTIONS]\n\
7653Args are signals and actions to apply to those signals.\n\
7654If no actions are specified, the current settings for the specified signals\n\
7655will be displayed instead.\n\
7656\n\
7657Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
7658from 1-15 are allowed for compatibility with old versions of GDB.\n\
7659Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
7660The special arg \"all\" is recognized to mean all signals except those\n\
7661used by the debugger, typically SIGTRAP and SIGINT.\n\
7662\n\
7663Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
7664\"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
7665Stop means reenter debugger if this signal happens (implies print).\n\
7666Print means print a message if this signal happens.\n\
7667Pass means let program see this signal; otherwise program doesn't know.\n\
7668Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
7669Pass and Stop may be combined.\n\
7670\n\
7671Multiple signals may be specified. Signal numbers and signal names\n\
7672may be interspersed with actions, with the actions being performed for\n\
7673all signals cumulatively specified."));
7674 set_cmd_completer (c, handle_completer);
7675
7676 if (!dbx_commands)
7677 stop_command = add_cmd ("stop", class_obscure,
7678 not_just_help_class_command, _("\
7679There is no `stop' command, but you can set a hook on `stop'.\n\
7680This allows you to set a list of commands to be run each time execution\n\
7681of the program stops."), &cmdlist);
7682
7683 add_setshow_zuinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
7684Set inferior debugging."), _("\
7685Show inferior debugging."), _("\
7686When non-zero, inferior specific debugging is enabled."),
7687 NULL,
7688 show_debug_infrun,
7689 &setdebuglist, &showdebuglist);
7690
7691 add_setshow_boolean_cmd ("displaced", class_maintenance,
7692 &debug_displaced, _("\
7693Set displaced stepping debugging."), _("\
7694Show displaced stepping debugging."), _("\
7695When non-zero, displaced stepping specific debugging is enabled."),
7696 NULL,
7697 show_debug_displaced,
7698 &setdebuglist, &showdebuglist);
7699
7700 add_setshow_boolean_cmd ("non-stop", no_class,
7701 &non_stop_1, _("\
7702Set whether gdb controls the inferior in non-stop mode."), _("\
7703Show whether gdb controls the inferior in non-stop mode."), _("\
7704When debugging a multi-threaded program and this setting is\n\
7705off (the default, also called all-stop mode), when one thread stops\n\
7706(for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7707all other threads in the program while you interact with the thread of\n\
7708interest. When you continue or step a thread, you can allow the other\n\
7709threads to run, or have them remain stopped, but while you inspect any\n\
7710thread's state, all threads stop.\n\
7711\n\
7712In non-stop mode, when one thread stops, other threads can continue\n\
7713to run freely. You'll be able to step each thread independently,\n\
7714leave it stopped or free to run as needed."),
7715 set_non_stop,
7716 show_non_stop,
7717 &setlist,
7718 &showlist);
7719
7720 numsigs = (int) GDB_SIGNAL_LAST;
7721 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
7722 signal_print = (unsigned char *)
7723 xmalloc (sizeof (signal_print[0]) * numsigs);
7724 signal_program = (unsigned char *)
7725 xmalloc (sizeof (signal_program[0]) * numsigs);
7726 signal_catch = (unsigned char *)
7727 xmalloc (sizeof (signal_catch[0]) * numsigs);
7728 signal_pass = (unsigned char *)
7729 xmalloc (sizeof (signal_pass[0]) * numsigs);
7730 for (i = 0; i < numsigs; i++)
7731 {
7732 signal_stop[i] = 1;
7733 signal_print[i] = 1;
7734 signal_program[i] = 1;
7735 signal_catch[i] = 0;
7736 }
7737
7738 /* Signals caused by debugger's own actions
7739 should not be given to the program afterwards. */
7740 signal_program[GDB_SIGNAL_TRAP] = 0;
7741 signal_program[GDB_SIGNAL_INT] = 0;
7742
7743 /* Signals that are not errors should not normally enter the debugger. */
7744 signal_stop[GDB_SIGNAL_ALRM] = 0;
7745 signal_print[GDB_SIGNAL_ALRM] = 0;
7746 signal_stop[GDB_SIGNAL_VTALRM] = 0;
7747 signal_print[GDB_SIGNAL_VTALRM] = 0;
7748 signal_stop[GDB_SIGNAL_PROF] = 0;
7749 signal_print[GDB_SIGNAL_PROF] = 0;
7750 signal_stop[GDB_SIGNAL_CHLD] = 0;
7751 signal_print[GDB_SIGNAL_CHLD] = 0;
7752 signal_stop[GDB_SIGNAL_IO] = 0;
7753 signal_print[GDB_SIGNAL_IO] = 0;
7754 signal_stop[GDB_SIGNAL_POLL] = 0;
7755 signal_print[GDB_SIGNAL_POLL] = 0;
7756 signal_stop[GDB_SIGNAL_URG] = 0;
7757 signal_print[GDB_SIGNAL_URG] = 0;
7758 signal_stop[GDB_SIGNAL_WINCH] = 0;
7759 signal_print[GDB_SIGNAL_WINCH] = 0;
7760 signal_stop[GDB_SIGNAL_PRIO] = 0;
7761 signal_print[GDB_SIGNAL_PRIO] = 0;
7762
7763 /* These signals are used internally by user-level thread
7764 implementations. (See signal(5) on Solaris.) Like the above
7765 signals, a healthy program receives and handles them as part of
7766 its normal operation. */
7767 signal_stop[GDB_SIGNAL_LWP] = 0;
7768 signal_print[GDB_SIGNAL_LWP] = 0;
7769 signal_stop[GDB_SIGNAL_WAITING] = 0;
7770 signal_print[GDB_SIGNAL_WAITING] = 0;
7771 signal_stop[GDB_SIGNAL_CANCEL] = 0;
7772 signal_print[GDB_SIGNAL_CANCEL] = 0;
7773
7774 /* Update cached state. */
7775 signal_cache_update (-1);
7776
7777 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
7778 &stop_on_solib_events, _("\
7779Set stopping for shared library events."), _("\
7780Show stopping for shared library events."), _("\
7781If nonzero, gdb will give control to the user when the dynamic linker\n\
7782notifies gdb of shared library events. The most common event of interest\n\
7783to the user would be loading/unloading of a new library."),
7784 set_stop_on_solib_events,
7785 show_stop_on_solib_events,
7786 &setlist, &showlist);
7787
7788 add_setshow_enum_cmd ("follow-fork-mode", class_run,
7789 follow_fork_mode_kind_names,
7790 &follow_fork_mode_string, _("\
7791Set debugger response to a program call of fork or vfork."), _("\
7792Show debugger response to a program call of fork or vfork."), _("\
7793A fork or vfork creates a new process. follow-fork-mode can be:\n\
7794 parent - the original process is debugged after a fork\n\
7795 child - the new process is debugged after a fork\n\
7796The unfollowed process will continue to run.\n\
7797By default, the debugger will follow the parent process."),
7798 NULL,
7799 show_follow_fork_mode_string,
7800 &setlist, &showlist);
7801
7802 add_setshow_enum_cmd ("follow-exec-mode", class_run,
7803 follow_exec_mode_names,
7804 &follow_exec_mode_string, _("\
7805Set debugger response to a program call of exec."), _("\
7806Show debugger response to a program call of exec."), _("\
7807An exec call replaces the program image of a process.\n\
7808\n\
7809follow-exec-mode can be:\n\
7810\n\
7811 new - the debugger creates a new inferior and rebinds the process\n\
7812to this new inferior. The program the process was running before\n\
7813the exec call can be restarted afterwards by restarting the original\n\
7814inferior.\n\
7815\n\
7816 same - the debugger keeps the process bound to the same inferior.\n\
7817The new executable image replaces the previous executable loaded in\n\
7818the inferior. Restarting the inferior after the exec call restarts\n\
7819the executable the process was running after the exec call.\n\
7820\n\
7821By default, the debugger will use the same inferior."),
7822 NULL,
7823 show_follow_exec_mode_string,
7824 &setlist, &showlist);
7825
7826 add_setshow_enum_cmd ("scheduler-locking", class_run,
7827 scheduler_enums, &scheduler_mode, _("\
7828Set mode for locking scheduler during execution."), _("\
7829Show mode for locking scheduler during execution."), _("\
7830off == no locking (threads may preempt at any time)\n\
7831on == full locking (no thread except the current thread may run)\n\
7832step == scheduler locked during stepping commands (step, next, stepi, nexti).\n\
7833 In this mode, other threads may run during other commands."),
7834 set_schedlock_func, /* traps on target vector */
7835 show_scheduler_mode,
7836 &setlist, &showlist);
7837
7838 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7839Set mode for resuming threads of all processes."), _("\
7840Show mode for resuming threads of all processes."), _("\
7841When on, execution commands (such as 'continue' or 'next') resume all\n\
7842threads of all processes. When off (which is the default), execution\n\
7843commands only resume the threads of the current process. The set of\n\
7844threads that are resumed is further refined by the scheduler-locking\n\
7845mode (see help set scheduler-locking)."),
7846 NULL,
7847 show_schedule_multiple,
7848 &setlist, &showlist);
7849
7850 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7851Set mode of the step operation."), _("\
7852Show mode of the step operation."), _("\
7853When set, doing a step over a function without debug line information\n\
7854will stop at the first instruction of that function. Otherwise, the\n\
7855function is skipped and the step command stops at a different source line."),
7856 NULL,
7857 show_step_stop_if_no_debug,
7858 &setlist, &showlist);
7859
7860 add_setshow_auto_boolean_cmd ("displaced-stepping", class_run,
7861 &can_use_displaced_stepping, _("\
7862Set debugger's willingness to use displaced stepping."), _("\
7863Show debugger's willingness to use displaced stepping."), _("\
7864If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7865supported by the target architecture. If off, gdb will not use displaced\n\
7866stepping to step over breakpoints, even if such is supported by the target\n\
7867architecture. If auto (which is the default), gdb will use displaced stepping\n\
7868if the target architecture supports it and non-stop mode is active, but will not\n\
7869use it in all-stop mode (see help set non-stop)."),
7870 NULL,
7871 show_can_use_displaced_stepping,
7872 &setlist, &showlist);
7873
7874 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7875 &exec_direction, _("Set direction of execution.\n\
7876Options are 'forward' or 'reverse'."),
7877 _("Show direction of execution (forward/reverse)."),
7878 _("Tells gdb whether to execute forward or backward."),
7879 set_exec_direction_func, show_exec_direction_func,
7880 &setlist, &showlist);
7881
7882 /* Set/show detach-on-fork: user-settable mode. */
7883
7884 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7885Set whether gdb will detach the child of a fork."), _("\
7886Show whether gdb will detach the child of a fork."), _("\
7887Tells gdb whether to detach the child of a fork."),
7888 NULL, NULL, &setlist, &showlist);
7889
7890 /* Set/show disable address space randomization mode. */
7891
7892 add_setshow_boolean_cmd ("disable-randomization", class_support,
7893 &disable_randomization, _("\
7894Set disabling of debuggee's virtual address space randomization."), _("\
7895Show disabling of debuggee's virtual address space randomization."), _("\
7896When this mode is on (which is the default), randomization of the virtual\n\
7897address space is disabled. Standalone programs run with the randomization\n\
7898enabled by default on some platforms."),
7899 &set_disable_randomization,
7900 &show_disable_randomization,
7901 &setlist, &showlist);
7902
7903 /* ptid initializations */
7904 inferior_ptid = null_ptid;
7905 target_last_wait_ptid = minus_one_ptid;
7906
7907 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7908 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7909 observer_attach_thread_exit (infrun_thread_thread_exit);
7910 observer_attach_inferior_exit (infrun_inferior_exit);
7911
7912 /* Explicitly create without lookup, since that tries to create a
7913 value with a void typed value, and when we get here, gdbarch
7914 isn't initialized yet. At this point, we're quite sure there
7915 isn't another convenience variable of the same name. */
7916 create_internalvar_type_lazy ("_siginfo", &siginfo_funcs, NULL);
7917
7918 add_setshow_boolean_cmd ("observer", no_class,
7919 &observer_mode_1, _("\
7920Set whether gdb controls the inferior in observer mode."), _("\
7921Show whether gdb controls the inferior in observer mode."), _("\
7922In observer mode, GDB can get data from the inferior, but not\n\
7923affect its execution. Registers and memory may not be changed,\n\
7924breakpoints may not be set, and the program cannot be interrupted\n\
7925or signalled."),
7926 set_observer_mode,
7927 show_observer_mode,
7928 &setlist,
7929 &showlist);
7930}
This page took 0.046915 seconds and 4 git commands to generate.