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