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