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