2011-05-20 Pedro Alves <pedro@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / infrun.c
1 /* Target-struct-independent code to start (run) and stop an inferior
2 process.
3
4 Copyright (C) 1986, 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 /* Return a ptid representing the set of threads that we will proceed,
1605 in the perspective of the user/frontend. We may actually resume
1606 fewer threads at first, e.g., if a thread is stopped at a
1607 breakpoint that needs stepping-off, but that should be visible to
1608 the user/frontend, and neither should the frontend/user be allowed
1609 to proceed any of the threads that happen to be stopped at for
1610 internal run control handling, if a previous command wanted them
1611 resumed. */
1612
1613 ptid_t
1614 user_visible_resume_ptid (int step)
1615 {
1616 /* By default, resume all threads of all processes. */
1617 ptid_t resume_ptid = RESUME_ALL;
1618
1619 /* Maybe resume only all threads of the current process. */
1620 if (!sched_multi && target_supports_multi_process ())
1621 {
1622 resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
1623 }
1624
1625 /* Maybe resume a single thread after all. */
1626 if (non_stop)
1627 {
1628 /* With non-stop mode on, threads are always handled
1629 individually. */
1630 resume_ptid = inferior_ptid;
1631 }
1632 else if ((scheduler_mode == schedlock_on)
1633 || (scheduler_mode == schedlock_step
1634 && (step || singlestep_breakpoints_inserted_p)))
1635 {
1636 /* User-settable 'scheduler' mode requires solo thread resume. */
1637 resume_ptid = inferior_ptid;
1638 }
1639
1640 return resume_ptid;
1641 }
1642
1643 /* Resume the inferior, but allow a QUIT. This is useful if the user
1644 wants to interrupt some lengthy single-stepping operation
1645 (for child processes, the SIGINT goes to the inferior, and so
1646 we get a SIGINT random_signal, but for remote debugging and perhaps
1647 other targets, that's not true).
1648
1649 STEP nonzero if we should step (zero to continue instead).
1650 SIG is the signal to give the inferior (zero for none). */
1651 void
1652 resume (int step, enum target_signal sig)
1653 {
1654 int should_resume = 1;
1655 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
1656 struct regcache *regcache = get_current_regcache ();
1657 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1658 struct thread_info *tp = inferior_thread ();
1659 CORE_ADDR pc = regcache_read_pc (regcache);
1660 struct address_space *aspace = get_regcache_aspace (regcache);
1661
1662 QUIT;
1663
1664 if (current_inferior ()->waiting_for_vfork_done)
1665 {
1666 /* Don't try to single-step a vfork parent that is waiting for
1667 the child to get out of the shared memory region (by exec'ing
1668 or exiting). This is particularly important on software
1669 single-step archs, as the child process would trip on the
1670 software single step breakpoint inserted for the parent
1671 process. Since the parent will not actually execute any
1672 instruction until the child is out of the shared region (such
1673 are vfork's semantics), it is safe to simply continue it.
1674 Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for
1675 the parent, and tell it to `keep_going', which automatically
1676 re-sets it stepping. */
1677 if (debug_infrun)
1678 fprintf_unfiltered (gdb_stdlog,
1679 "infrun: resume : clear step\n");
1680 step = 0;
1681 }
1682
1683 if (debug_infrun)
1684 fprintf_unfiltered (gdb_stdlog,
1685 "infrun: resume (step=%d, signal=%d), "
1686 "trap_expected=%d, current thread [%s] at %s\n",
1687 step, sig, tp->control.trap_expected,
1688 target_pid_to_str (inferior_ptid),
1689 paddress (gdbarch, pc));
1690
1691 /* Normally, by the time we reach `resume', the breakpoints are either
1692 removed or inserted, as appropriate. The exception is if we're sitting
1693 at a permanent breakpoint; we need to step over it, but permanent
1694 breakpoints can't be removed. So we have to test for it here. */
1695 if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here)
1696 {
1697 if (gdbarch_skip_permanent_breakpoint_p (gdbarch))
1698 gdbarch_skip_permanent_breakpoint (gdbarch, regcache);
1699 else
1700 error (_("\
1701 The program is stopped at a permanent breakpoint, but GDB does not know\n\
1702 how to step past a permanent breakpoint on this architecture. Try using\n\
1703 a command like `return' or `jump' to continue execution."));
1704 }
1705
1706 /* If enabled, step over breakpoints by executing a copy of the
1707 instruction at a different address.
1708
1709 We can't use displaced stepping when we have a signal to deliver;
1710 the comments for displaced_step_prepare explain why. The
1711 comments in the handle_inferior event for dealing with 'random
1712 signals' explain what we do instead.
1713
1714 We can't use displaced stepping when we are waiting for vfork_done
1715 event, displaced stepping breaks the vfork child similarly as single
1716 step software breakpoint. */
1717 if (use_displaced_stepping (gdbarch)
1718 && (tp->control.trap_expected
1719 || (step && gdbarch_software_single_step_p (gdbarch)))
1720 && sig == TARGET_SIGNAL_0
1721 && !current_inferior ()->waiting_for_vfork_done)
1722 {
1723 struct displaced_step_inferior_state *displaced;
1724
1725 if (!displaced_step_prepare (inferior_ptid))
1726 {
1727 /* Got placed in displaced stepping queue. Will be resumed
1728 later when all the currently queued displaced stepping
1729 requests finish. The thread is not executing at this point,
1730 and the call to set_executing will be made later. But we
1731 need to call set_running here, since from frontend point of view,
1732 the thread is running. */
1733 set_running (inferior_ptid, 1);
1734 discard_cleanups (old_cleanups);
1735 return;
1736 }
1737
1738 displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid));
1739 step = gdbarch_displaced_step_hw_singlestep (gdbarch,
1740 displaced->step_closure);
1741 }
1742
1743 /* Do we need to do it the hard way, w/temp breakpoints? */
1744 else if (step)
1745 step = maybe_software_singlestep (gdbarch, pc);
1746
1747 /* Currently, our software single-step implementation leads to different
1748 results than hardware single-stepping in one situation: when stepping
1749 into delivering a signal which has an associated signal handler,
1750 hardware single-step will stop at the first instruction of the handler,
1751 while software single-step will simply skip execution of the handler.
1752
1753 For now, this difference in behavior is accepted since there is no
1754 easy way to actually implement single-stepping into a signal handler
1755 without kernel support.
1756
1757 However, there is one scenario where this difference leads to follow-on
1758 problems: if we're stepping off a breakpoint by removing all breakpoints
1759 and then single-stepping. In this case, the software single-step
1760 behavior means that even if there is a *breakpoint* in the signal
1761 handler, GDB still would not stop.
1762
1763 Fortunately, we can at least fix this particular issue. We detect
1764 here the case where we are about to deliver a signal while software
1765 single-stepping with breakpoints removed. In this situation, we
1766 revert the decisions to remove all breakpoints and insert single-
1767 step breakpoints, and instead we install a step-resume breakpoint
1768 at the current address, deliver the signal without stepping, and
1769 once we arrive back at the step-resume breakpoint, actually step
1770 over the breakpoint we originally wanted to step over. */
1771 if (singlestep_breakpoints_inserted_p
1772 && tp->control.trap_expected && sig != TARGET_SIGNAL_0)
1773 {
1774 /* If we have nested signals or a pending signal is delivered
1775 immediately after a handler returns, might might already have
1776 a step-resume breakpoint set on the earlier handler. We cannot
1777 set another step-resume breakpoint; just continue on until the
1778 original breakpoint is hit. */
1779 if (tp->control.step_resume_breakpoint == NULL)
1780 {
1781 insert_step_resume_breakpoint_at_frame (get_current_frame ());
1782 tp->step_after_step_resume_breakpoint = 1;
1783 }
1784
1785 remove_single_step_breakpoints ();
1786 singlestep_breakpoints_inserted_p = 0;
1787
1788 insert_breakpoints ();
1789 tp->control.trap_expected = 0;
1790 }
1791
1792 if (should_resume)
1793 {
1794 ptid_t resume_ptid;
1795
1796 /* If STEP is set, it's a request to use hardware stepping
1797 facilities. But in that case, we should never
1798 use singlestep breakpoint. */
1799 gdb_assert (!(singlestep_breakpoints_inserted_p && step));
1800
1801 /* Decide the set of threads to ask the target to resume. Start
1802 by assuming everything will be resumed, than narrow the set
1803 by applying increasingly restricting conditions. */
1804 resume_ptid = user_visible_resume_ptid (step);
1805
1806 /* Maybe resume a single thread after all. */
1807 if (singlestep_breakpoints_inserted_p
1808 && stepping_past_singlestep_breakpoint)
1809 {
1810 /* The situation here is as follows. In thread T1 we wanted to
1811 single-step. Lacking hardware single-stepping we've
1812 set breakpoint at the PC of the next instruction -- call it
1813 P. After resuming, we've hit that breakpoint in thread T2.
1814 Now we've removed original breakpoint, inserted breakpoint
1815 at P+1, and try to step to advance T2 past breakpoint.
1816 We need to step only T2, as if T1 is allowed to freely run,
1817 it can run past P, and if other threads are allowed to run,
1818 they can hit breakpoint at P+1, and nested hits of single-step
1819 breakpoints is not something we'd want -- that's complicated
1820 to support, and has no value. */
1821 resume_ptid = inferior_ptid;
1822 }
1823 else if ((step || singlestep_breakpoints_inserted_p)
1824 && tp->control.trap_expected)
1825 {
1826 /* We're allowing a thread to run past a breakpoint it has
1827 hit, by single-stepping the thread with the breakpoint
1828 removed. In which case, we need to single-step only this
1829 thread, and keep others stopped, as they can miss this
1830 breakpoint if allowed to run.
1831
1832 The current code actually removes all breakpoints when
1833 doing this, not just the one being stepped over, so if we
1834 let other threads run, we can actually miss any
1835 breakpoint, not just the one at PC. */
1836 resume_ptid = inferior_ptid;
1837 }
1838
1839 if (gdbarch_cannot_step_breakpoint (gdbarch))
1840 {
1841 /* Most targets can step a breakpoint instruction, thus
1842 executing it normally. But if this one cannot, just
1843 continue and we will hit it anyway. */
1844 if (step && breakpoint_inserted_here_p (aspace, pc))
1845 step = 0;
1846 }
1847
1848 if (debug_displaced
1849 && use_displaced_stepping (gdbarch)
1850 && tp->control.trap_expected)
1851 {
1852 struct regcache *resume_regcache = get_thread_regcache (resume_ptid);
1853 struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache);
1854 CORE_ADDR actual_pc = regcache_read_pc (resume_regcache);
1855 gdb_byte buf[4];
1856
1857 fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ",
1858 paddress (resume_gdbarch, actual_pc));
1859 read_memory (actual_pc, buf, sizeof (buf));
1860 displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf));
1861 }
1862
1863 /* Install inferior's terminal modes. */
1864 target_terminal_inferior ();
1865
1866 /* Avoid confusing the next resume, if the next stop/resume
1867 happens to apply to another thread. */
1868 tp->suspend.stop_signal = TARGET_SIGNAL_0;
1869
1870 /* Advise target which signals may be handled silently. If we have
1871 removed breakpoints because we are stepping over one (which can
1872 happen only if we are not using displaced stepping), we need to
1873 receive all signals to avoid accidentally skipping a breakpoint
1874 during execution of a signal handler. */
1875 if ((step || singlestep_breakpoints_inserted_p)
1876 && tp->control.trap_expected
1877 && !use_displaced_stepping (gdbarch))
1878 target_pass_signals (0, NULL);
1879 else
1880 target_pass_signals ((int) TARGET_SIGNAL_LAST, signal_pass);
1881
1882 target_resume (resume_ptid, step, sig);
1883 }
1884
1885 discard_cleanups (old_cleanups);
1886 }
1887 \f
1888 /* Proceeding. */
1889
1890 /* Clear out all variables saying what to do when inferior is continued.
1891 First do this, then set the ones you want, then call `proceed'. */
1892
1893 static void
1894 clear_proceed_status_thread (struct thread_info *tp)
1895 {
1896 if (debug_infrun)
1897 fprintf_unfiltered (gdb_stdlog,
1898 "infrun: clear_proceed_status_thread (%s)\n",
1899 target_pid_to_str (tp->ptid));
1900
1901 tp->control.trap_expected = 0;
1902 tp->control.step_range_start = 0;
1903 tp->control.step_range_end = 0;
1904 tp->control.step_frame_id = null_frame_id;
1905 tp->control.step_stack_frame_id = null_frame_id;
1906 tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE;
1907 tp->stop_requested = 0;
1908
1909 tp->control.stop_step = 0;
1910
1911 tp->control.proceed_to_finish = 0;
1912
1913 /* Discard any remaining commands or status from previous stop. */
1914 bpstat_clear (&tp->control.stop_bpstat);
1915 }
1916
1917 static int
1918 clear_proceed_status_callback (struct thread_info *tp, void *data)
1919 {
1920 if (is_exited (tp->ptid))
1921 return 0;
1922
1923 clear_proceed_status_thread (tp);
1924 return 0;
1925 }
1926
1927 void
1928 clear_proceed_status (void)
1929 {
1930 if (!non_stop)
1931 {
1932 /* In all-stop mode, delete the per-thread status of all
1933 threads, even if inferior_ptid is null_ptid, there may be
1934 threads on the list. E.g., we may be launching a new
1935 process, while selecting the executable. */
1936 iterate_over_threads (clear_proceed_status_callback, NULL);
1937 }
1938
1939 if (!ptid_equal (inferior_ptid, null_ptid))
1940 {
1941 struct inferior *inferior;
1942
1943 if (non_stop)
1944 {
1945 /* If in non-stop mode, only delete the per-thread status of
1946 the current thread. */
1947 clear_proceed_status_thread (inferior_thread ());
1948 }
1949
1950 inferior = current_inferior ();
1951 inferior->control.stop_soon = NO_STOP_QUIETLY;
1952 }
1953
1954 stop_after_trap = 0;
1955
1956 observer_notify_about_to_proceed ();
1957
1958 if (stop_registers)
1959 {
1960 regcache_xfree (stop_registers);
1961 stop_registers = NULL;
1962 }
1963 }
1964
1965 /* Check the current thread against the thread that reported the most recent
1966 event. If a step-over is required return TRUE and set the current thread
1967 to the old thread. Otherwise return FALSE.
1968
1969 This should be suitable for any targets that support threads. */
1970
1971 static int
1972 prepare_to_proceed (int step)
1973 {
1974 ptid_t wait_ptid;
1975 struct target_waitstatus wait_status;
1976 int schedlock_enabled;
1977
1978 /* With non-stop mode on, threads are always handled individually. */
1979 gdb_assert (! non_stop);
1980
1981 /* Get the last target status returned by target_wait(). */
1982 get_last_target_status (&wait_ptid, &wait_status);
1983
1984 /* Make sure we were stopped at a breakpoint. */
1985 if (wait_status.kind != TARGET_WAITKIND_STOPPED
1986 || (wait_status.value.sig != TARGET_SIGNAL_TRAP
1987 && wait_status.value.sig != TARGET_SIGNAL_ILL
1988 && wait_status.value.sig != TARGET_SIGNAL_SEGV
1989 && wait_status.value.sig != TARGET_SIGNAL_EMT))
1990 {
1991 return 0;
1992 }
1993
1994 schedlock_enabled = (scheduler_mode == schedlock_on
1995 || (scheduler_mode == schedlock_step
1996 && step));
1997
1998 /* Don't switch over to WAIT_PTID if scheduler locking is on. */
1999 if (schedlock_enabled)
2000 return 0;
2001
2002 /* Don't switch over if we're about to resume some other process
2003 other than WAIT_PTID's, and schedule-multiple is off. */
2004 if (!sched_multi
2005 && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid))
2006 return 0;
2007
2008 /* Switched over from WAIT_PID. */
2009 if (!ptid_equal (wait_ptid, minus_one_ptid)
2010 && !ptid_equal (inferior_ptid, wait_ptid))
2011 {
2012 struct regcache *regcache = get_thread_regcache (wait_ptid);
2013
2014 if (breakpoint_here_p (get_regcache_aspace (regcache),
2015 regcache_read_pc (regcache)))
2016 {
2017 /* If stepping, remember current thread to switch back to. */
2018 if (step)
2019 deferred_step_ptid = inferior_ptid;
2020
2021 /* Switch back to WAIT_PID thread. */
2022 switch_to_thread (wait_ptid);
2023
2024 if (debug_infrun)
2025 fprintf_unfiltered (gdb_stdlog,
2026 "infrun: prepare_to_proceed (step=%d), "
2027 "switched to [%s]\n",
2028 step, target_pid_to_str (inferior_ptid));
2029
2030 /* We return 1 to indicate that there is a breakpoint here,
2031 so we need to step over it before continuing to avoid
2032 hitting it straight away. */
2033 return 1;
2034 }
2035 }
2036
2037 return 0;
2038 }
2039
2040 /* Basic routine for continuing the program in various fashions.
2041
2042 ADDR is the address to resume at, or -1 for resume where stopped.
2043 SIGGNAL is the signal to give it, or 0 for none,
2044 or -1 for act according to how it stopped.
2045 STEP is nonzero if should trap after one instruction.
2046 -1 means return after that and print nothing.
2047 You should probably set various step_... variables
2048 before calling here, if you are stepping.
2049
2050 You should call clear_proceed_status before calling proceed. */
2051
2052 void
2053 proceed (CORE_ADDR addr, enum target_signal siggnal, int step)
2054 {
2055 struct regcache *regcache;
2056 struct gdbarch *gdbarch;
2057 struct thread_info *tp;
2058 CORE_ADDR pc;
2059 struct address_space *aspace;
2060 int oneproc = 0;
2061
2062 /* If we're stopped at a fork/vfork, follow the branch set by the
2063 "set follow-fork-mode" command; otherwise, we'll just proceed
2064 resuming the current thread. */
2065 if (!follow_fork ())
2066 {
2067 /* The target for some reason decided not to resume. */
2068 normal_stop ();
2069 if (target_can_async_p ())
2070 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2071 return;
2072 }
2073
2074 /* We'll update this if & when we switch to a new thread. */
2075 previous_inferior_ptid = inferior_ptid;
2076
2077 regcache = get_current_regcache ();
2078 gdbarch = get_regcache_arch (regcache);
2079 aspace = get_regcache_aspace (regcache);
2080 pc = regcache_read_pc (regcache);
2081
2082 if (step > 0)
2083 step_start_function = find_pc_function (pc);
2084 if (step < 0)
2085 stop_after_trap = 1;
2086
2087 if (addr == (CORE_ADDR) -1)
2088 {
2089 if (pc == stop_pc && breakpoint_here_p (aspace, pc)
2090 && execution_direction != EXEC_REVERSE)
2091 /* There is a breakpoint at the address we will resume at,
2092 step one instruction before inserting breakpoints so that
2093 we do not stop right away (and report a second hit at this
2094 breakpoint).
2095
2096 Note, we don't do this in reverse, because we won't
2097 actually be executing the breakpoint insn anyway.
2098 We'll be (un-)executing the previous instruction. */
2099
2100 oneproc = 1;
2101 else if (gdbarch_single_step_through_delay_p (gdbarch)
2102 && gdbarch_single_step_through_delay (gdbarch,
2103 get_current_frame ()))
2104 /* We stepped onto an instruction that needs to be stepped
2105 again before re-inserting the breakpoint, do so. */
2106 oneproc = 1;
2107 }
2108 else
2109 {
2110 regcache_write_pc (regcache, addr);
2111 }
2112
2113 if (debug_infrun)
2114 fprintf_unfiltered (gdb_stdlog,
2115 "infrun: proceed (addr=%s, signal=%d, step=%d)\n",
2116 paddress (gdbarch, addr), siggnal, step);
2117
2118 if (non_stop)
2119 /* In non-stop, each thread is handled individually. The context
2120 must already be set to the right thread here. */
2121 ;
2122 else
2123 {
2124 /* In a multi-threaded task we may select another thread and
2125 then continue or step.
2126
2127 But if the old thread was stopped at a breakpoint, it will
2128 immediately cause another breakpoint stop without any
2129 execution (i.e. it will report a breakpoint hit incorrectly).
2130 So we must step over it first.
2131
2132 prepare_to_proceed checks the current thread against the
2133 thread that reported the most recent event. If a step-over
2134 is required it returns TRUE and sets the current thread to
2135 the old thread. */
2136 if (prepare_to_proceed (step))
2137 oneproc = 1;
2138 }
2139
2140 /* prepare_to_proceed may change the current thread. */
2141 tp = inferior_thread ();
2142
2143 if (oneproc)
2144 {
2145 tp->control.trap_expected = 1;
2146 /* If displaced stepping is enabled, we can step over the
2147 breakpoint without hitting it, so leave all breakpoints
2148 inserted. Otherwise we need to disable all breakpoints, step
2149 one instruction, and then re-add them when that step is
2150 finished. */
2151 if (!use_displaced_stepping (gdbarch))
2152 remove_breakpoints ();
2153 }
2154
2155 /* We can insert breakpoints if we're not trying to step over one,
2156 or if we are stepping over one but we're using displaced stepping
2157 to do so. */
2158 if (! tp->control.trap_expected || use_displaced_stepping (gdbarch))
2159 insert_breakpoints ();
2160
2161 if (!non_stop)
2162 {
2163 /* Pass the last stop signal to the thread we're resuming,
2164 irrespective of whether the current thread is the thread that
2165 got the last event or not. This was historically GDB's
2166 behaviour before keeping a stop_signal per thread. */
2167
2168 struct thread_info *last_thread;
2169 ptid_t last_ptid;
2170 struct target_waitstatus last_status;
2171
2172 get_last_target_status (&last_ptid, &last_status);
2173 if (!ptid_equal (inferior_ptid, last_ptid)
2174 && !ptid_equal (last_ptid, null_ptid)
2175 && !ptid_equal (last_ptid, minus_one_ptid))
2176 {
2177 last_thread = find_thread_ptid (last_ptid);
2178 if (last_thread)
2179 {
2180 tp->suspend.stop_signal = last_thread->suspend.stop_signal;
2181 last_thread->suspend.stop_signal = TARGET_SIGNAL_0;
2182 }
2183 }
2184 }
2185
2186 if (siggnal != TARGET_SIGNAL_DEFAULT)
2187 tp->suspend.stop_signal = siggnal;
2188 /* If this signal should not be seen by program,
2189 give it zero. Used for debugging signals. */
2190 else if (!signal_program[tp->suspend.stop_signal])
2191 tp->suspend.stop_signal = TARGET_SIGNAL_0;
2192
2193 annotate_starting ();
2194
2195 /* Make sure that output from GDB appears before output from the
2196 inferior. */
2197 gdb_flush (gdb_stdout);
2198
2199 /* Refresh prev_pc value just prior to resuming. This used to be
2200 done in stop_stepping, however, setting prev_pc there did not handle
2201 scenarios such as inferior function calls or returning from
2202 a function via the return command. In those cases, the prev_pc
2203 value was not set properly for subsequent commands. The prev_pc value
2204 is used to initialize the starting line number in the ecs. With an
2205 invalid value, the gdb next command ends up stopping at the position
2206 represented by the next line table entry past our start position.
2207 On platforms that generate one line table entry per line, this
2208 is not a problem. However, on the ia64, the compiler generates
2209 extraneous line table entries that do not increase the line number.
2210 When we issue the gdb next command on the ia64 after an inferior call
2211 or a return command, we often end up a few instructions forward, still
2212 within the original line we started.
2213
2214 An attempt was made to refresh the prev_pc at the same time the
2215 execution_control_state is initialized (for instance, just before
2216 waiting for an inferior event). But this approach did not work
2217 because of platforms that use ptrace, where the pc register cannot
2218 be read unless the inferior is stopped. At that point, we are not
2219 guaranteed the inferior is stopped and so the regcache_read_pc() call
2220 can fail. Setting the prev_pc value here ensures the value is updated
2221 correctly when the inferior is stopped. */
2222 tp->prev_pc = regcache_read_pc (get_current_regcache ());
2223
2224 /* Fill in with reasonable starting values. */
2225 init_thread_stepping_state (tp);
2226
2227 /* Reset to normal state. */
2228 init_infwait_state ();
2229
2230 /* Resume inferior. */
2231 resume (oneproc || step || bpstat_should_step (), tp->suspend.stop_signal);
2232
2233 /* Wait for it to stop (if not standalone)
2234 and in any case decode why it stopped, and act accordingly. */
2235 /* Do this only if we are not using the event loop, or if the target
2236 does not support asynchronous execution. */
2237 if (!target_can_async_p ())
2238 {
2239 wait_for_inferior ();
2240 normal_stop ();
2241 }
2242 }
2243 \f
2244
2245 /* Start remote-debugging of a machine over a serial link. */
2246
2247 void
2248 start_remote (int from_tty)
2249 {
2250 struct inferior *inferior;
2251
2252 init_wait_for_inferior ();
2253 inferior = current_inferior ();
2254 inferior->control.stop_soon = STOP_QUIETLY_REMOTE;
2255
2256 /* Always go on waiting for the target, regardless of the mode. */
2257 /* FIXME: cagney/1999-09-23: At present it isn't possible to
2258 indicate to wait_for_inferior that a target should timeout if
2259 nothing is returned (instead of just blocking). Because of this,
2260 targets expecting an immediate response need to, internally, set
2261 things up so that the target_wait() is forced to eventually
2262 timeout. */
2263 /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to
2264 differentiate to its caller what the state of the target is after
2265 the initial open has been performed. Here we're assuming that
2266 the target has stopped. It should be possible to eventually have
2267 target_open() return to the caller an indication that the target
2268 is currently running and GDB state should be set to the same as
2269 for an async run. */
2270 wait_for_inferior ();
2271
2272 /* Now that the inferior has stopped, do any bookkeeping like
2273 loading shared libraries. We want to do this before normal_stop,
2274 so that the displayed frame is up to date. */
2275 post_create_inferior (&current_target, from_tty);
2276
2277 normal_stop ();
2278 }
2279
2280 /* Initialize static vars when a new inferior begins. */
2281
2282 void
2283 init_wait_for_inferior (void)
2284 {
2285 /* These are meaningless until the first time through wait_for_inferior. */
2286
2287 breakpoint_init_inferior (inf_starting);
2288
2289 clear_proceed_status ();
2290
2291 stepping_past_singlestep_breakpoint = 0;
2292 deferred_step_ptid = null_ptid;
2293
2294 target_last_wait_ptid = minus_one_ptid;
2295
2296 previous_inferior_ptid = inferior_ptid;
2297 init_infwait_state ();
2298
2299 /* Discard any skipped inlined frames. */
2300 clear_inline_frame_state (minus_one_ptid);
2301 }
2302
2303 \f
2304 /* This enum encodes possible reasons for doing a target_wait, so that
2305 wfi can call target_wait in one place. (Ultimately the call will be
2306 moved out of the infinite loop entirely.) */
2307
2308 enum infwait_states
2309 {
2310 infwait_normal_state,
2311 infwait_thread_hop_state,
2312 infwait_step_watch_state,
2313 infwait_nonstep_watch_state
2314 };
2315
2316 /* The PTID we'll do a target_wait on.*/
2317 ptid_t waiton_ptid;
2318
2319 /* Current inferior wait state. */
2320 enum infwait_states infwait_state;
2321
2322 /* Data to be passed around while handling an event. This data is
2323 discarded between events. */
2324 struct execution_control_state
2325 {
2326 ptid_t ptid;
2327 /* The thread that got the event, if this was a thread event; NULL
2328 otherwise. */
2329 struct thread_info *event_thread;
2330
2331 struct target_waitstatus ws;
2332 int random_signal;
2333 CORE_ADDR stop_func_start;
2334 CORE_ADDR stop_func_end;
2335 char *stop_func_name;
2336 int new_thread_event;
2337 int wait_some_more;
2338 };
2339
2340 static void handle_inferior_event (struct execution_control_state *ecs);
2341
2342 static void handle_step_into_function (struct gdbarch *gdbarch,
2343 struct execution_control_state *ecs);
2344 static void handle_step_into_function_backward (struct gdbarch *gdbarch,
2345 struct execution_control_state *ecs);
2346 static void check_exception_resume (struct execution_control_state *,
2347 struct frame_info *, struct symbol *);
2348
2349 static void stop_stepping (struct execution_control_state *ecs);
2350 static void prepare_to_wait (struct execution_control_state *ecs);
2351 static void keep_going (struct execution_control_state *ecs);
2352
2353 /* Callback for iterate over threads. If the thread is stopped, but
2354 the user/frontend doesn't know about that yet, go through
2355 normal_stop, as if the thread had just stopped now. ARG points at
2356 a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If
2357 ptid_is_pid(PTID) is true, applies to all threads of the process
2358 pointed at by PTID. Otherwise, apply only to the thread pointed by
2359 PTID. */
2360
2361 static int
2362 infrun_thread_stop_requested_callback (struct thread_info *info, void *arg)
2363 {
2364 ptid_t ptid = * (ptid_t *) arg;
2365
2366 if ((ptid_equal (info->ptid, ptid)
2367 || ptid_equal (minus_one_ptid, ptid)
2368 || (ptid_is_pid (ptid)
2369 && ptid_get_pid (ptid) == ptid_get_pid (info->ptid)))
2370 && is_running (info->ptid)
2371 && !is_executing (info->ptid))
2372 {
2373 struct cleanup *old_chain;
2374 struct execution_control_state ecss;
2375 struct execution_control_state *ecs = &ecss;
2376
2377 memset (ecs, 0, sizeof (*ecs));
2378
2379 old_chain = make_cleanup_restore_current_thread ();
2380
2381 switch_to_thread (info->ptid);
2382
2383 /* Go through handle_inferior_event/normal_stop, so we always
2384 have consistent output as if the stop event had been
2385 reported. */
2386 ecs->ptid = info->ptid;
2387 ecs->event_thread = find_thread_ptid (info->ptid);
2388 ecs->ws.kind = TARGET_WAITKIND_STOPPED;
2389 ecs->ws.value.sig = TARGET_SIGNAL_0;
2390
2391 handle_inferior_event (ecs);
2392
2393 if (!ecs->wait_some_more)
2394 {
2395 struct thread_info *tp;
2396
2397 normal_stop ();
2398
2399 /* Finish off the continuations. The continations
2400 themselves are responsible for realising the thread
2401 didn't finish what it was supposed to do. */
2402 tp = inferior_thread ();
2403 do_all_intermediate_continuations_thread (tp);
2404 do_all_continuations_thread (tp);
2405 }
2406
2407 do_cleanups (old_chain);
2408 }
2409
2410 return 0;
2411 }
2412
2413 /* This function is attached as a "thread_stop_requested" observer.
2414 Cleanup local state that assumed the PTID was to be resumed, and
2415 report the stop to the frontend. */
2416
2417 static void
2418 infrun_thread_stop_requested (ptid_t ptid)
2419 {
2420 struct displaced_step_inferior_state *displaced;
2421
2422 /* PTID was requested to stop. Remove it from the displaced
2423 stepping queue, so we don't try to resume it automatically. */
2424
2425 for (displaced = displaced_step_inferior_states;
2426 displaced;
2427 displaced = displaced->next)
2428 {
2429 struct displaced_step_request *it, **prev_next_p;
2430
2431 it = displaced->step_request_queue;
2432 prev_next_p = &displaced->step_request_queue;
2433 while (it)
2434 {
2435 if (ptid_match (it->ptid, ptid))
2436 {
2437 *prev_next_p = it->next;
2438 it->next = NULL;
2439 xfree (it);
2440 }
2441 else
2442 {
2443 prev_next_p = &it->next;
2444 }
2445
2446 it = *prev_next_p;
2447 }
2448 }
2449
2450 iterate_over_threads (infrun_thread_stop_requested_callback, &ptid);
2451 }
2452
2453 static void
2454 infrun_thread_thread_exit (struct thread_info *tp, int silent)
2455 {
2456 if (ptid_equal (target_last_wait_ptid, tp->ptid))
2457 nullify_last_target_wait_ptid ();
2458 }
2459
2460 /* Callback for iterate_over_threads. */
2461
2462 static int
2463 delete_step_resume_breakpoint_callback (struct thread_info *info, void *data)
2464 {
2465 if (is_exited (info->ptid))
2466 return 0;
2467
2468 delete_step_resume_breakpoint (info);
2469 delete_exception_resume_breakpoint (info);
2470 return 0;
2471 }
2472
2473 /* In all-stop, delete the step resume breakpoint of any thread that
2474 had one. In non-stop, delete the step resume breakpoint of the
2475 thread that just stopped. */
2476
2477 static void
2478 delete_step_thread_step_resume_breakpoint (void)
2479 {
2480 if (!target_has_execution
2481 || ptid_equal (inferior_ptid, null_ptid))
2482 /* If the inferior has exited, we have already deleted the step
2483 resume breakpoints out of GDB's lists. */
2484 return;
2485
2486 if (non_stop)
2487 {
2488 /* If in non-stop mode, only delete the step-resume or
2489 longjmp-resume breakpoint of the thread that just stopped
2490 stepping. */
2491 struct thread_info *tp = inferior_thread ();
2492
2493 delete_step_resume_breakpoint (tp);
2494 delete_exception_resume_breakpoint (tp);
2495 }
2496 else
2497 /* In all-stop mode, delete all step-resume and longjmp-resume
2498 breakpoints of any thread that had them. */
2499 iterate_over_threads (delete_step_resume_breakpoint_callback, NULL);
2500 }
2501
2502 /* A cleanup wrapper. */
2503
2504 static void
2505 delete_step_thread_step_resume_breakpoint_cleanup (void *arg)
2506 {
2507 delete_step_thread_step_resume_breakpoint ();
2508 }
2509
2510 /* Pretty print the results of target_wait, for debugging purposes. */
2511
2512 static void
2513 print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid,
2514 const struct target_waitstatus *ws)
2515 {
2516 char *status_string = target_waitstatus_to_string (ws);
2517 struct ui_file *tmp_stream = mem_fileopen ();
2518 char *text;
2519
2520 /* The text is split over several lines because it was getting too long.
2521 Call fprintf_unfiltered (gdb_stdlog) once so that the text is still
2522 output as a unit; we want only one timestamp printed if debug_timestamp
2523 is set. */
2524
2525 fprintf_unfiltered (tmp_stream,
2526 "infrun: target_wait (%d", PIDGET (waiton_ptid));
2527 if (PIDGET (waiton_ptid) != -1)
2528 fprintf_unfiltered (tmp_stream,
2529 " [%s]", target_pid_to_str (waiton_ptid));
2530 fprintf_unfiltered (tmp_stream, ", status) =\n");
2531 fprintf_unfiltered (tmp_stream,
2532 "infrun: %d [%s],\n",
2533 PIDGET (result_ptid), target_pid_to_str (result_ptid));
2534 fprintf_unfiltered (tmp_stream,
2535 "infrun: %s\n",
2536 status_string);
2537
2538 text = ui_file_xstrdup (tmp_stream, NULL);
2539
2540 /* This uses %s in part to handle %'s in the text, but also to avoid
2541 a gcc error: the format attribute requires a string literal. */
2542 fprintf_unfiltered (gdb_stdlog, "%s", text);
2543
2544 xfree (status_string);
2545 xfree (text);
2546 ui_file_delete (tmp_stream);
2547 }
2548
2549 /* Prepare and stabilize the inferior for detaching it. E.g.,
2550 detaching while a thread is displaced stepping is a recipe for
2551 crashing it, as nothing would readjust the PC out of the scratch
2552 pad. */
2553
2554 void
2555 prepare_for_detach (void)
2556 {
2557 struct inferior *inf = current_inferior ();
2558 ptid_t pid_ptid = pid_to_ptid (inf->pid);
2559 struct cleanup *old_chain_1;
2560 struct displaced_step_inferior_state *displaced;
2561
2562 displaced = get_displaced_stepping_state (inf->pid);
2563
2564 /* Is any thread of this process displaced stepping? If not,
2565 there's nothing else to do. */
2566 if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid))
2567 return;
2568
2569 if (debug_infrun)
2570 fprintf_unfiltered (gdb_stdlog,
2571 "displaced-stepping in-process while detaching");
2572
2573 old_chain_1 = make_cleanup_restore_integer (&inf->detaching);
2574 inf->detaching = 1;
2575
2576 while (!ptid_equal (displaced->step_ptid, null_ptid))
2577 {
2578 struct cleanup *old_chain_2;
2579 struct execution_control_state ecss;
2580 struct execution_control_state *ecs;
2581
2582 ecs = &ecss;
2583 memset (ecs, 0, sizeof (*ecs));
2584
2585 overlay_cache_invalid = 1;
2586
2587 /* We have to invalidate the registers BEFORE calling
2588 target_wait because they can be loaded from the target while
2589 in target_wait. This makes remote debugging a bit more
2590 efficient for those targets that provide critical registers
2591 as part of their normal status mechanism. */
2592
2593 registers_changed ();
2594
2595 if (deprecated_target_wait_hook)
2596 ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0);
2597 else
2598 ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0);
2599
2600 if (debug_infrun)
2601 print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws);
2602
2603 /* If an error happens while handling the event, propagate GDB's
2604 knowledge of the executing state to the frontend/user running
2605 state. */
2606 old_chain_2 = make_cleanup (finish_thread_state_cleanup,
2607 &minus_one_ptid);
2608
2609 /* In non-stop mode, each thread is handled individually.
2610 Switch early, so the global state is set correctly for this
2611 thread. */
2612 if (non_stop
2613 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2614 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2615 context_switch (ecs->ptid);
2616
2617 /* Now figure out what to do with the result of the result. */
2618 handle_inferior_event (ecs);
2619
2620 /* No error, don't finish the state yet. */
2621 discard_cleanups (old_chain_2);
2622
2623 /* Breakpoints and watchpoints are not installed on the target
2624 at this point, and signals are passed directly to the
2625 inferior, so this must mean the process is gone. */
2626 if (!ecs->wait_some_more)
2627 {
2628 discard_cleanups (old_chain_1);
2629 error (_("Program exited while detaching"));
2630 }
2631 }
2632
2633 discard_cleanups (old_chain_1);
2634 }
2635
2636 /* Wait for control to return from inferior to debugger.
2637
2638 If inferior gets a signal, we may decide to start it up again
2639 instead of returning. That is why there is a loop in this function.
2640 When this function actually returns it means the inferior
2641 should be left stopped and GDB should read more commands. */
2642
2643 void
2644 wait_for_inferior (void)
2645 {
2646 struct cleanup *old_cleanups;
2647 struct execution_control_state ecss;
2648 struct execution_control_state *ecs;
2649
2650 if (debug_infrun)
2651 fprintf_unfiltered
2652 (gdb_stdlog, "infrun: wait_for_inferior ()\n");
2653
2654 old_cleanups =
2655 make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
2656
2657 ecs = &ecss;
2658 memset (ecs, 0, sizeof (*ecs));
2659
2660 while (1)
2661 {
2662 struct cleanup *old_chain;
2663
2664 /* We have to invalidate the registers BEFORE calling target_wait
2665 because they can be loaded from the target while in target_wait.
2666 This makes remote debugging a bit more efficient for those
2667 targets that provide critical registers as part of their normal
2668 status mechanism. */
2669
2670 overlay_cache_invalid = 1;
2671 registers_changed ();
2672
2673 if (deprecated_target_wait_hook)
2674 ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0);
2675 else
2676 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0);
2677
2678 if (debug_infrun)
2679 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2680
2681 /* If an error happens while handling the event, propagate GDB's
2682 knowledge of the executing state to the frontend/user running
2683 state. */
2684 old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2685
2686 if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY
2687 || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN)
2688 ecs->ws.value.syscall_number = UNKNOWN_SYSCALL;
2689
2690 /* Now figure out what to do with the result of the result. */
2691 handle_inferior_event (ecs);
2692
2693 /* No error, don't finish the state yet. */
2694 discard_cleanups (old_chain);
2695
2696 if (!ecs->wait_some_more)
2697 break;
2698 }
2699
2700 do_cleanups (old_cleanups);
2701 }
2702
2703 /* Asynchronous version of wait_for_inferior. It is called by the
2704 event loop whenever a change of state is detected on the file
2705 descriptor corresponding to the target. It can be called more than
2706 once to complete a single execution command. In such cases we need
2707 to keep the state in a global variable ECSS. If it is the last time
2708 that this function is called for a single execution command, then
2709 report to the user that the inferior has stopped, and do the
2710 necessary cleanups. */
2711
2712 void
2713 fetch_inferior_event (void *client_data)
2714 {
2715 struct execution_control_state ecss;
2716 struct execution_control_state *ecs = &ecss;
2717 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
2718 struct cleanup *ts_old_chain;
2719 int was_sync = sync_execution;
2720
2721 memset (ecs, 0, sizeof (*ecs));
2722
2723 /* We're handling a live event, so make sure we're doing live
2724 debugging. If we're looking at traceframes while the target is
2725 running, we're going to need to get back to that mode after
2726 handling the event. */
2727 if (non_stop)
2728 {
2729 make_cleanup_restore_current_traceframe ();
2730 set_current_traceframe (-1);
2731 }
2732
2733 if (non_stop)
2734 /* In non-stop mode, the user/frontend should not notice a thread
2735 switch due to internal events. Make sure we reverse to the
2736 user selected thread and frame after handling the event and
2737 running any breakpoint commands. */
2738 make_cleanup_restore_current_thread ();
2739
2740 /* We have to invalidate the registers BEFORE calling target_wait
2741 because they can be loaded from the target while in target_wait.
2742 This makes remote debugging a bit more efficient for those
2743 targets that provide critical registers as part of their normal
2744 status mechanism. */
2745
2746 overlay_cache_invalid = 1;
2747 registers_changed ();
2748
2749 if (deprecated_target_wait_hook)
2750 ecs->ptid =
2751 deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2752 else
2753 ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG);
2754
2755 if (debug_infrun)
2756 print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws);
2757
2758 if (non_stop
2759 && ecs->ws.kind != TARGET_WAITKIND_IGNORE
2760 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2761 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
2762 /* In non-stop mode, each thread is handled individually. Switch
2763 early, so the global state is set correctly for this
2764 thread. */
2765 context_switch (ecs->ptid);
2766
2767 /* If an error happens while handling the event, propagate GDB's
2768 knowledge of the executing state to the frontend/user running
2769 state. */
2770 if (!non_stop)
2771 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
2772 else
2773 ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid);
2774
2775 /* Now figure out what to do with the result of the result. */
2776 handle_inferior_event (ecs);
2777
2778 if (!ecs->wait_some_more)
2779 {
2780 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
2781
2782 delete_step_thread_step_resume_breakpoint ();
2783
2784 /* We may not find an inferior if this was a process exit. */
2785 if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY)
2786 normal_stop ();
2787
2788 if (target_has_execution
2789 && ecs->ws.kind != TARGET_WAITKIND_EXITED
2790 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
2791 && ecs->event_thread->step_multi
2792 && ecs->event_thread->control.stop_step)
2793 inferior_event_handler (INF_EXEC_CONTINUE, NULL);
2794 else
2795 inferior_event_handler (INF_EXEC_COMPLETE, NULL);
2796 }
2797
2798 /* No error, don't finish the thread states yet. */
2799 discard_cleanups (ts_old_chain);
2800
2801 /* Revert thread and frame. */
2802 do_cleanups (old_chain);
2803
2804 /* If the inferior was in sync execution mode, and now isn't,
2805 restore the prompt. */
2806 if (was_sync && !sync_execution)
2807 display_gdb_prompt (0);
2808 }
2809
2810 /* Record the frame and location we're currently stepping through. */
2811 void
2812 set_step_info (struct frame_info *frame, struct symtab_and_line sal)
2813 {
2814 struct thread_info *tp = inferior_thread ();
2815
2816 tp->control.step_frame_id = get_frame_id (frame);
2817 tp->control.step_stack_frame_id = get_stack_frame_id (frame);
2818
2819 tp->current_symtab = sal.symtab;
2820 tp->current_line = sal.line;
2821 }
2822
2823 /* Clear context switchable stepping state. */
2824
2825 void
2826 init_thread_stepping_state (struct thread_info *tss)
2827 {
2828 tss->stepping_over_breakpoint = 0;
2829 tss->step_after_step_resume_breakpoint = 0;
2830 tss->stepping_through_solib_after_catch = 0;
2831 tss->stepping_through_solib_catchpoints = NULL;
2832 }
2833
2834 /* Return the cached copy of the last pid/waitstatus returned by
2835 target_wait()/deprecated_target_wait_hook(). The data is actually
2836 cached by handle_inferior_event(), which gets called immediately
2837 after target_wait()/deprecated_target_wait_hook(). */
2838
2839 void
2840 get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status)
2841 {
2842 *ptidp = target_last_wait_ptid;
2843 *status = target_last_waitstatus;
2844 }
2845
2846 void
2847 nullify_last_target_wait_ptid (void)
2848 {
2849 target_last_wait_ptid = minus_one_ptid;
2850 }
2851
2852 /* Switch thread contexts. */
2853
2854 static void
2855 context_switch (ptid_t ptid)
2856 {
2857 if (debug_infrun)
2858 {
2859 fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ",
2860 target_pid_to_str (inferior_ptid));
2861 fprintf_unfiltered (gdb_stdlog, "to %s\n",
2862 target_pid_to_str (ptid));
2863 }
2864
2865 switch_to_thread (ptid);
2866 }
2867
2868 static void
2869 adjust_pc_after_break (struct execution_control_state *ecs)
2870 {
2871 struct regcache *regcache;
2872 struct gdbarch *gdbarch;
2873 struct address_space *aspace;
2874 CORE_ADDR breakpoint_pc;
2875
2876 /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If
2877 we aren't, just return.
2878
2879 We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not
2880 affected by gdbarch_decr_pc_after_break. Other waitkinds which are
2881 implemented by software breakpoints should be handled through the normal
2882 breakpoint layer.
2883
2884 NOTE drow/2004-01-31: On some targets, breakpoints may generate
2885 different signals (SIGILL or SIGEMT for instance), but it is less
2886 clear where the PC is pointing afterwards. It may not match
2887 gdbarch_decr_pc_after_break. I don't know any specific target that
2888 generates these signals at breakpoints (the code has been in GDB since at
2889 least 1992) so I can not guess how to handle them here.
2890
2891 In earlier versions of GDB, a target with
2892 gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a
2893 watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any
2894 target with both of these set in GDB history, and it seems unlikely to be
2895 correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */
2896
2897 if (ecs->ws.kind != TARGET_WAITKIND_STOPPED)
2898 return;
2899
2900 if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP)
2901 return;
2902
2903 /* In reverse execution, when a breakpoint is hit, the instruction
2904 under it has already been de-executed. The reported PC always
2905 points at the breakpoint address, so adjusting it further would
2906 be wrong. E.g., consider this case on a decr_pc_after_break == 1
2907 architecture:
2908
2909 B1 0x08000000 : INSN1
2910 B2 0x08000001 : INSN2
2911 0x08000002 : INSN3
2912 PC -> 0x08000003 : INSN4
2913
2914 Say you're stopped at 0x08000003 as above. Reverse continuing
2915 from that point should hit B2 as below. Reading the PC when the
2916 SIGTRAP is reported should read 0x08000001 and INSN2 should have
2917 been de-executed already.
2918
2919 B1 0x08000000 : INSN1
2920 B2 PC -> 0x08000001 : INSN2
2921 0x08000002 : INSN3
2922 0x08000003 : INSN4
2923
2924 We can't apply the same logic as for forward execution, because
2925 we would wrongly adjust the PC to 0x08000000, since there's a
2926 breakpoint at PC - 1. We'd then report a hit on B1, although
2927 INSN1 hadn't been de-executed yet. Doing nothing is the correct
2928 behaviour. */
2929 if (execution_direction == EXEC_REVERSE)
2930 return;
2931
2932 /* If this target does not decrement the PC after breakpoints, then
2933 we have nothing to do. */
2934 regcache = get_thread_regcache (ecs->ptid);
2935 gdbarch = get_regcache_arch (regcache);
2936 if (gdbarch_decr_pc_after_break (gdbarch) == 0)
2937 return;
2938
2939 aspace = get_regcache_aspace (regcache);
2940
2941 /* Find the location where (if we've hit a breakpoint) the
2942 breakpoint would be. */
2943 breakpoint_pc = regcache_read_pc (regcache)
2944 - gdbarch_decr_pc_after_break (gdbarch);
2945
2946 /* Check whether there actually is a software breakpoint inserted at
2947 that location.
2948
2949 If in non-stop mode, a race condition is possible where we've
2950 removed a breakpoint, but stop events for that breakpoint were
2951 already queued and arrive later. To suppress those spurious
2952 SIGTRAPs, we keep a list of such breakpoint locations for a bit,
2953 and retire them after a number of stop events are reported. */
2954 if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc)
2955 || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc)))
2956 {
2957 struct cleanup *old_cleanups = NULL;
2958
2959 if (RECORD_IS_USED)
2960 old_cleanups = record_gdb_operation_disable_set ();
2961
2962 /* When using hardware single-step, a SIGTRAP is reported for both
2963 a completed single-step and a software breakpoint. Need to
2964 differentiate between the two, as the latter needs adjusting
2965 but the former does not.
2966
2967 The SIGTRAP can be due to a completed hardware single-step only if
2968 - we didn't insert software single-step breakpoints
2969 - the thread to be examined is still the current thread
2970 - this thread is currently being stepped
2971
2972 If any of these events did not occur, we must have stopped due
2973 to hitting a software breakpoint, and have to back up to the
2974 breakpoint address.
2975
2976 As a special case, we could have hardware single-stepped a
2977 software breakpoint. In this case (prev_pc == breakpoint_pc),
2978 we also need to back up to the breakpoint address. */
2979
2980 if (singlestep_breakpoints_inserted_p
2981 || !ptid_equal (ecs->ptid, inferior_ptid)
2982 || !currently_stepping (ecs->event_thread)
2983 || ecs->event_thread->prev_pc == breakpoint_pc)
2984 regcache_write_pc (regcache, breakpoint_pc);
2985
2986 if (RECORD_IS_USED)
2987 do_cleanups (old_cleanups);
2988 }
2989 }
2990
2991 void
2992 init_infwait_state (void)
2993 {
2994 waiton_ptid = pid_to_ptid (-1);
2995 infwait_state = infwait_normal_state;
2996 }
2997
2998 void
2999 error_is_running (void)
3000 {
3001 error (_("Cannot execute this command while "
3002 "the selected thread is running."));
3003 }
3004
3005 void
3006 ensure_not_running (void)
3007 {
3008 if (is_running (inferior_ptid))
3009 error_is_running ();
3010 }
3011
3012 static int
3013 stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id)
3014 {
3015 for (frame = get_prev_frame (frame);
3016 frame != NULL;
3017 frame = get_prev_frame (frame))
3018 {
3019 if (frame_id_eq (get_frame_id (frame), step_frame_id))
3020 return 1;
3021 if (get_frame_type (frame) != INLINE_FRAME)
3022 break;
3023 }
3024
3025 return 0;
3026 }
3027
3028 /* Auxiliary function that handles syscall entry/return events.
3029 It returns 1 if the inferior should keep going (and GDB
3030 should ignore the event), or 0 if the event deserves to be
3031 processed. */
3032
3033 static int
3034 handle_syscall_event (struct execution_control_state *ecs)
3035 {
3036 struct regcache *regcache;
3037 struct gdbarch *gdbarch;
3038 int syscall_number;
3039
3040 if (!ptid_equal (ecs->ptid, inferior_ptid))
3041 context_switch (ecs->ptid);
3042
3043 regcache = get_thread_regcache (ecs->ptid);
3044 gdbarch = get_regcache_arch (regcache);
3045 syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid);
3046 stop_pc = regcache_read_pc (regcache);
3047
3048 target_last_waitstatus.value.syscall_number = syscall_number;
3049
3050 if (catch_syscall_enabled () > 0
3051 && catching_syscall_number (syscall_number) > 0)
3052 {
3053 if (debug_infrun)
3054 fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n",
3055 syscall_number);
3056
3057 ecs->event_thread->control.stop_bpstat
3058 = bpstat_stop_status (get_regcache_aspace (regcache),
3059 stop_pc, ecs->ptid);
3060 ecs->random_signal
3061 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
3062
3063 if (!ecs->random_signal)
3064 {
3065 /* Catchpoint hit. */
3066 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3067 return 0;
3068 }
3069 }
3070
3071 /* If no catchpoint triggered for this, then keep going. */
3072 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3073 keep_going (ecs);
3074 return 1;
3075 }
3076
3077 /* Given an execution control state that has been freshly filled in
3078 by an event from the inferior, figure out what it means and take
3079 appropriate action. */
3080
3081 static void
3082 handle_inferior_event (struct execution_control_state *ecs)
3083 {
3084 struct frame_info *frame;
3085 struct gdbarch *gdbarch;
3086 int sw_single_step_trap_p = 0;
3087 int stopped_by_watchpoint;
3088 int stepped_after_stopped_by_watchpoint = 0;
3089 struct symtab_and_line stop_pc_sal;
3090 enum stop_kind stop_soon;
3091
3092 if (ecs->ws.kind == TARGET_WAITKIND_IGNORE)
3093 {
3094 /* We had an event in the inferior, but we are not interested in
3095 handling it at this level. The lower layers have already
3096 done what needs to be done, if anything.
3097
3098 One of the possible circumstances for this is when the
3099 inferior produces output for the console. The inferior has
3100 not stopped, and we are ignoring the event. Another possible
3101 circumstance is any event which the lower level knows will be
3102 reported multiple times without an intervening resume. */
3103 if (debug_infrun)
3104 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n");
3105 prepare_to_wait (ecs);
3106 return;
3107 }
3108
3109 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3110 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
3111 {
3112 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
3113
3114 gdb_assert (inf);
3115 stop_soon = inf->control.stop_soon;
3116 }
3117 else
3118 stop_soon = NO_STOP_QUIETLY;
3119
3120 /* Cache the last pid/waitstatus. */
3121 target_last_wait_ptid = ecs->ptid;
3122 target_last_waitstatus = ecs->ws;
3123
3124 /* Always clear state belonging to the previous time we stopped. */
3125 stop_stack_dummy = STOP_NONE;
3126
3127 /* If it's a new process, add it to the thread database. */
3128
3129 ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
3130 && !ptid_equal (ecs->ptid, minus_one_ptid)
3131 && !in_thread_list (ecs->ptid));
3132
3133 if (ecs->ws.kind != TARGET_WAITKIND_EXITED
3134 && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event)
3135 add_thread (ecs->ptid);
3136
3137 ecs->event_thread = find_thread_ptid (ecs->ptid);
3138
3139 /* Dependent on valid ECS->EVENT_THREAD. */
3140 adjust_pc_after_break (ecs);
3141
3142 /* Dependent on the current PC value modified by adjust_pc_after_break. */
3143 reinit_frame_cache ();
3144
3145 breakpoint_retire_moribund ();
3146
3147 /* First, distinguish signals caused by the debugger from signals
3148 that have to do with the program's own actions. Note that
3149 breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending
3150 on the operating system version. Here we detect when a SIGILL or
3151 SIGEMT is really a breakpoint and change it to SIGTRAP. We do
3152 something similar for SIGSEGV, since a SIGSEGV will be generated
3153 when we're trying to execute a breakpoint instruction on a
3154 non-executable stack. This happens for call dummy breakpoints
3155 for architectures like SPARC that place call dummies on the
3156 stack. */
3157 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED
3158 && (ecs->ws.value.sig == TARGET_SIGNAL_ILL
3159 || ecs->ws.value.sig == TARGET_SIGNAL_SEGV
3160 || ecs->ws.value.sig == TARGET_SIGNAL_EMT))
3161 {
3162 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3163
3164 if (breakpoint_inserted_here_p (get_regcache_aspace (regcache),
3165 regcache_read_pc (regcache)))
3166 {
3167 if (debug_infrun)
3168 fprintf_unfiltered (gdb_stdlog,
3169 "infrun: Treating signal as SIGTRAP\n");
3170 ecs->ws.value.sig = TARGET_SIGNAL_TRAP;
3171 }
3172 }
3173
3174 /* Mark the non-executing threads accordingly. In all-stop, all
3175 threads of all processes are stopped when we get any event
3176 reported. In non-stop mode, only the event thread stops. If
3177 we're handling a process exit in non-stop mode, there's nothing
3178 to do, as threads of the dead process are gone, and threads of
3179 any other process were left running. */
3180 if (!non_stop)
3181 set_executing (minus_one_ptid, 0);
3182 else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
3183 && ecs->ws.kind != TARGET_WAITKIND_EXITED)
3184 set_executing (inferior_ptid, 0);
3185
3186 switch (infwait_state)
3187 {
3188 case infwait_thread_hop_state:
3189 if (debug_infrun)
3190 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
3191 break;
3192
3193 case infwait_normal_state:
3194 if (debug_infrun)
3195 fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n");
3196 break;
3197
3198 case infwait_step_watch_state:
3199 if (debug_infrun)
3200 fprintf_unfiltered (gdb_stdlog,
3201 "infrun: infwait_step_watch_state\n");
3202
3203 stepped_after_stopped_by_watchpoint = 1;
3204 break;
3205
3206 case infwait_nonstep_watch_state:
3207 if (debug_infrun)
3208 fprintf_unfiltered (gdb_stdlog,
3209 "infrun: infwait_nonstep_watch_state\n");
3210 insert_breakpoints ();
3211
3212 /* FIXME-maybe: is this cleaner than setting a flag? Does it
3213 handle things like signals arriving and other things happening
3214 in combination correctly? */
3215 stepped_after_stopped_by_watchpoint = 1;
3216 break;
3217
3218 default:
3219 internal_error (__FILE__, __LINE__, _("bad switch"));
3220 }
3221
3222 infwait_state = infwait_normal_state;
3223 waiton_ptid = pid_to_ptid (-1);
3224
3225 switch (ecs->ws.kind)
3226 {
3227 case TARGET_WAITKIND_LOADED:
3228 if (debug_infrun)
3229 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n");
3230 /* Ignore gracefully during startup of the inferior, as it might
3231 be the shell which has just loaded some objects, otherwise
3232 add the symbols for the newly loaded objects. Also ignore at
3233 the beginning of an attach or remote session; we will query
3234 the full list of libraries once the connection is
3235 established. */
3236 if (stop_soon == NO_STOP_QUIETLY)
3237 {
3238 /* Check for any newly added shared libraries if we're
3239 supposed to be adding them automatically. Switch
3240 terminal for any messages produced by
3241 breakpoint_re_set. */
3242 target_terminal_ours_for_output ();
3243 /* NOTE: cagney/2003-11-25: Make certain that the target
3244 stack's section table is kept up-to-date. Architectures,
3245 (e.g., PPC64), use the section table to perform
3246 operations such as address => section name and hence
3247 require the table to contain all sections (including
3248 those found in shared libraries). */
3249 #ifdef SOLIB_ADD
3250 SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
3251 #else
3252 solib_add (NULL, 0, &current_target, auto_solib_add);
3253 #endif
3254 target_terminal_inferior ();
3255
3256 /* If requested, stop when the dynamic linker notifies
3257 gdb of events. This allows the user to get control
3258 and place breakpoints in initializer routines for
3259 dynamically loaded objects (among other things). */
3260 if (stop_on_solib_events)
3261 {
3262 /* Make sure we print "Stopped due to solib-event" in
3263 normal_stop. */
3264 stop_print_frame = 1;
3265
3266 stop_stepping (ecs);
3267 return;
3268 }
3269
3270 /* NOTE drow/2007-05-11: This might be a good place to check
3271 for "catch load". */
3272 }
3273
3274 /* If we are skipping through a shell, or through shared library
3275 loading that we aren't interested in, resume the program. If
3276 we're running the program normally, also resume. But stop if
3277 we're attaching or setting up a remote connection. */
3278 if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY)
3279 {
3280 /* Loading of shared libraries might have changed breakpoint
3281 addresses. Make sure new breakpoints are inserted. */
3282 if (stop_soon == NO_STOP_QUIETLY
3283 && !breakpoints_always_inserted_mode ())
3284 insert_breakpoints ();
3285 resume (0, TARGET_SIGNAL_0);
3286 prepare_to_wait (ecs);
3287 return;
3288 }
3289
3290 break;
3291
3292 case TARGET_WAITKIND_SPURIOUS:
3293 if (debug_infrun)
3294 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n");
3295 resume (0, TARGET_SIGNAL_0);
3296 prepare_to_wait (ecs);
3297 return;
3298
3299 case TARGET_WAITKIND_EXITED:
3300 if (debug_infrun)
3301 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
3302 inferior_ptid = ecs->ptid;
3303 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3304 set_current_program_space (current_inferior ()->pspace);
3305 handle_vfork_child_exec_or_exit (0);
3306 target_terminal_ours (); /* Must do this before mourn anyway. */
3307 print_exited_reason (ecs->ws.value.integer);
3308
3309 /* Record the exit code in the convenience variable $_exitcode, so
3310 that the user can inspect this again later. */
3311 set_internalvar_integer (lookup_internalvar ("_exitcode"),
3312 (LONGEST) ecs->ws.value.integer);
3313 gdb_flush (gdb_stdout);
3314 target_mourn_inferior ();
3315 singlestep_breakpoints_inserted_p = 0;
3316 cancel_single_step_breakpoints ();
3317 stop_print_frame = 0;
3318 stop_stepping (ecs);
3319 return;
3320
3321 case TARGET_WAITKIND_SIGNALLED:
3322 if (debug_infrun)
3323 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n");
3324 inferior_ptid = ecs->ptid;
3325 set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid)));
3326 set_current_program_space (current_inferior ()->pspace);
3327 handle_vfork_child_exec_or_exit (0);
3328 stop_print_frame = 0;
3329 target_terminal_ours (); /* Must do this before mourn anyway. */
3330
3331 /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't
3332 reach here unless the inferior is dead. However, for years
3333 target_kill() was called here, which hints that fatal signals aren't
3334 really fatal on some systems. If that's true, then some changes
3335 may be needed. */
3336 target_mourn_inferior ();
3337
3338 print_signal_exited_reason (ecs->ws.value.sig);
3339 singlestep_breakpoints_inserted_p = 0;
3340 cancel_single_step_breakpoints ();
3341 stop_stepping (ecs);
3342 return;
3343
3344 /* The following are the only cases in which we keep going;
3345 the above cases end in a continue or goto. */
3346 case TARGET_WAITKIND_FORKED:
3347 case TARGET_WAITKIND_VFORKED:
3348 if (debug_infrun)
3349 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
3350
3351 if (!ptid_equal (ecs->ptid, inferior_ptid))
3352 {
3353 context_switch (ecs->ptid);
3354 reinit_frame_cache ();
3355 }
3356
3357 /* Immediately detach breakpoints from the child before there's
3358 any chance of letting the user delete breakpoints from the
3359 breakpoint lists. If we don't do this early, it's easy to
3360 leave left over traps in the child, vis: "break foo; catch
3361 fork; c; <fork>; del; c; <child calls foo>". We only follow
3362 the fork on the last `continue', and by that time the
3363 breakpoint at "foo" is long gone from the breakpoint table.
3364 If we vforked, then we don't need to unpatch here, since both
3365 parent and child are sharing the same memory pages; we'll
3366 need to unpatch at follow/detach time instead to be certain
3367 that new breakpoints added between catchpoint hit time and
3368 vfork follow are detached. */
3369 if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
3370 {
3371 int child_pid = ptid_get_pid (ecs->ws.value.related_pid);
3372
3373 /* This won't actually modify the breakpoint list, but will
3374 physically remove the breakpoints from the child. */
3375 detach_breakpoints (child_pid);
3376 }
3377
3378 if (singlestep_breakpoints_inserted_p)
3379 {
3380 /* Pull the single step breakpoints out of the target. */
3381 remove_single_step_breakpoints ();
3382 singlestep_breakpoints_inserted_p = 0;
3383 }
3384
3385 /* In case the event is caught by a catchpoint, remember that
3386 the event is to be followed at the next resume of the thread,
3387 and not immediately. */
3388 ecs->event_thread->pending_follow = ecs->ws;
3389
3390 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3391
3392 ecs->event_thread->control.stop_bpstat
3393 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3394 stop_pc, ecs->ptid);
3395
3396 /* Note that we're interested in knowing the bpstat actually
3397 causes a stop, not just if it may explain the signal.
3398 Software watchpoints, for example, always appear in the
3399 bpstat. */
3400 ecs->random_signal
3401 = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat);
3402
3403 /* If no catchpoint triggered for this, then keep going. */
3404 if (ecs->random_signal)
3405 {
3406 ptid_t parent;
3407 ptid_t child;
3408 int should_resume;
3409 int follow_child
3410 = (follow_fork_mode_string == follow_fork_mode_child);
3411
3412 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3413
3414 should_resume = follow_fork ();
3415
3416 parent = ecs->ptid;
3417 child = ecs->ws.value.related_pid;
3418
3419 /* In non-stop mode, also resume the other branch. */
3420 if (non_stop && !detach_fork)
3421 {
3422 if (follow_child)
3423 switch_to_thread (parent);
3424 else
3425 switch_to_thread (child);
3426
3427 ecs->event_thread = inferior_thread ();
3428 ecs->ptid = inferior_ptid;
3429 keep_going (ecs);
3430 }
3431
3432 if (follow_child)
3433 switch_to_thread (child);
3434 else
3435 switch_to_thread (parent);
3436
3437 ecs->event_thread = inferior_thread ();
3438 ecs->ptid = inferior_ptid;
3439
3440 if (should_resume)
3441 keep_going (ecs);
3442 else
3443 stop_stepping (ecs);
3444 return;
3445 }
3446 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3447 goto process_event_stop_test;
3448
3449 case TARGET_WAITKIND_VFORK_DONE:
3450 /* Done with the shared memory region. Re-insert breakpoints in
3451 the parent, and keep going. */
3452
3453 if (debug_infrun)
3454 fprintf_unfiltered (gdb_stdlog,
3455 "infrun: TARGET_WAITKIND_VFORK_DONE\n");
3456
3457 if (!ptid_equal (ecs->ptid, inferior_ptid))
3458 context_switch (ecs->ptid);
3459
3460 current_inferior ()->waiting_for_vfork_done = 0;
3461 current_inferior ()->pspace->breakpoints_not_allowed = 0;
3462 /* This also takes care of reinserting breakpoints in the
3463 previously locked inferior. */
3464 keep_going (ecs);
3465 return;
3466
3467 case TARGET_WAITKIND_EXECD:
3468 if (debug_infrun)
3469 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
3470
3471 if (!ptid_equal (ecs->ptid, inferior_ptid))
3472 {
3473 context_switch (ecs->ptid);
3474 reinit_frame_cache ();
3475 }
3476
3477 singlestep_breakpoints_inserted_p = 0;
3478 cancel_single_step_breakpoints ();
3479
3480 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3481
3482 /* Do whatever is necessary to the parent branch of the vfork. */
3483 handle_vfork_child_exec_or_exit (1);
3484
3485 /* This causes the eventpoints and symbol table to be reset.
3486 Must do this now, before trying to determine whether to
3487 stop. */
3488 follow_exec (inferior_ptid, ecs->ws.value.execd_pathname);
3489
3490 ecs->event_thread->control.stop_bpstat
3491 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
3492 stop_pc, ecs->ptid);
3493 ecs->random_signal
3494 = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat);
3495
3496 /* Note that this may be referenced from inside
3497 bpstat_stop_status above, through inferior_has_execd. */
3498 xfree (ecs->ws.value.execd_pathname);
3499 ecs->ws.value.execd_pathname = NULL;
3500
3501 /* If no catchpoint triggered for this, then keep going. */
3502 if (ecs->random_signal)
3503 {
3504 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3505 keep_going (ecs);
3506 return;
3507 }
3508 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
3509 goto process_event_stop_test;
3510
3511 /* Be careful not to try to gather much state about a thread
3512 that's in a syscall. It's frequently a losing proposition. */
3513 case TARGET_WAITKIND_SYSCALL_ENTRY:
3514 if (debug_infrun)
3515 fprintf_unfiltered (gdb_stdlog,
3516 "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n");
3517 /* Getting the current syscall number. */
3518 if (handle_syscall_event (ecs) != 0)
3519 return;
3520 goto process_event_stop_test;
3521
3522 /* Before examining the threads further, step this thread to
3523 get it entirely out of the syscall. (We get notice of the
3524 event when the thread is just on the verge of exiting a
3525 syscall. Stepping one instruction seems to get it back
3526 into user code.) */
3527 case TARGET_WAITKIND_SYSCALL_RETURN:
3528 if (debug_infrun)
3529 fprintf_unfiltered (gdb_stdlog,
3530 "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
3531 if (handle_syscall_event (ecs) != 0)
3532 return;
3533 goto process_event_stop_test;
3534
3535 case TARGET_WAITKIND_STOPPED:
3536 if (debug_infrun)
3537 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
3538 ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig;
3539 break;
3540
3541 case TARGET_WAITKIND_NO_HISTORY:
3542 /* Reverse execution: target ran out of history info. */
3543 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3544 print_no_history_reason ();
3545 stop_stepping (ecs);
3546 return;
3547 }
3548
3549 if (ecs->new_thread_event)
3550 {
3551 if (non_stop)
3552 /* Non-stop assumes that the target handles adding new threads
3553 to the thread list. */
3554 internal_error (__FILE__, __LINE__,
3555 "targets should add new threads to the thread "
3556 "list themselves in non-stop mode.");
3557
3558 /* We may want to consider not doing a resume here in order to
3559 give the user a chance to play with the new thread. It might
3560 be good to make that a user-settable option. */
3561
3562 /* At this point, all threads are stopped (happens automatically
3563 in either the OS or the native code). Therefore we need to
3564 continue all threads in order to make progress. */
3565
3566 if (!ptid_equal (ecs->ptid, inferior_ptid))
3567 context_switch (ecs->ptid);
3568 target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0);
3569 prepare_to_wait (ecs);
3570 return;
3571 }
3572
3573 if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
3574 {
3575 /* Do we need to clean up the state of a thread that has
3576 completed a displaced single-step? (Doing so usually affects
3577 the PC, so do it here, before we set stop_pc.) */
3578 displaced_step_fixup (ecs->ptid,
3579 ecs->event_thread->suspend.stop_signal);
3580
3581 /* If we either finished a single-step or hit a breakpoint, but
3582 the user wanted this thread to be stopped, pretend we got a
3583 SIG0 (generic unsignaled stop). */
3584
3585 if (ecs->event_thread->stop_requested
3586 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3587 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3588 }
3589
3590 stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
3591
3592 if (debug_infrun)
3593 {
3594 struct regcache *regcache = get_thread_regcache (ecs->ptid);
3595 struct gdbarch *gdbarch = get_regcache_arch (regcache);
3596 struct cleanup *old_chain = save_inferior_ptid ();
3597
3598 inferior_ptid = ecs->ptid;
3599
3600 fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n",
3601 paddress (gdbarch, stop_pc));
3602 if (target_stopped_by_watchpoint ())
3603 {
3604 CORE_ADDR addr;
3605
3606 fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
3607
3608 if (target_stopped_data_address (&current_target, &addr))
3609 fprintf_unfiltered (gdb_stdlog,
3610 "infrun: stopped data address = %s\n",
3611 paddress (gdbarch, addr));
3612 else
3613 fprintf_unfiltered (gdb_stdlog,
3614 "infrun: (no data address available)\n");
3615 }
3616
3617 do_cleanups (old_chain);
3618 }
3619
3620 if (stepping_past_singlestep_breakpoint)
3621 {
3622 gdb_assert (singlestep_breakpoints_inserted_p);
3623 gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
3624 gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
3625
3626 stepping_past_singlestep_breakpoint = 0;
3627
3628 /* We've either finished single-stepping past the single-step
3629 breakpoint, or stopped for some other reason. It would be nice if
3630 we could tell, but we can't reliably. */
3631 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3632 {
3633 if (debug_infrun)
3634 fprintf_unfiltered (gdb_stdlog,
3635 "infrun: stepping_past_"
3636 "singlestep_breakpoint\n");
3637 /* Pull the single step breakpoints out of the target. */
3638 remove_single_step_breakpoints ();
3639 singlestep_breakpoints_inserted_p = 0;
3640
3641 ecs->random_signal = 0;
3642 ecs->event_thread->control.trap_expected = 0;
3643
3644 context_switch (saved_singlestep_ptid);
3645 if (deprecated_context_hook)
3646 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3647
3648 resume (1, TARGET_SIGNAL_0);
3649 prepare_to_wait (ecs);
3650 return;
3651 }
3652 }
3653
3654 if (!ptid_equal (deferred_step_ptid, null_ptid))
3655 {
3656 /* In non-stop mode, there's never a deferred_step_ptid set. */
3657 gdb_assert (!non_stop);
3658
3659 /* If we stopped for some other reason than single-stepping, ignore
3660 the fact that we were supposed to switch back. */
3661 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3662 {
3663 if (debug_infrun)
3664 fprintf_unfiltered (gdb_stdlog,
3665 "infrun: handling deferred step\n");
3666
3667 /* Pull the single step breakpoints out of the target. */
3668 if (singlestep_breakpoints_inserted_p)
3669 {
3670 remove_single_step_breakpoints ();
3671 singlestep_breakpoints_inserted_p = 0;
3672 }
3673
3674 ecs->event_thread->control.trap_expected = 0;
3675
3676 /* Note: We do not call context_switch at this point, as the
3677 context is already set up for stepping the original thread. */
3678 switch_to_thread (deferred_step_ptid);
3679 deferred_step_ptid = null_ptid;
3680 /* Suppress spurious "Switching to ..." message. */
3681 previous_inferior_ptid = inferior_ptid;
3682
3683 resume (1, TARGET_SIGNAL_0);
3684 prepare_to_wait (ecs);
3685 return;
3686 }
3687
3688 deferred_step_ptid = null_ptid;
3689 }
3690
3691 /* See if a thread hit a thread-specific breakpoint that was meant for
3692 another thread. If so, then step that thread past the breakpoint,
3693 and continue it. */
3694
3695 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
3696 {
3697 int thread_hop_needed = 0;
3698 struct address_space *aspace =
3699 get_regcache_aspace (get_thread_regcache (ecs->ptid));
3700
3701 /* Check if a regular breakpoint has been hit before checking
3702 for a potential single step breakpoint. Otherwise, GDB will
3703 not see this breakpoint hit when stepping onto breakpoints. */
3704 if (regular_breakpoint_inserted_here_p (aspace, stop_pc))
3705 {
3706 ecs->random_signal = 0;
3707 if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid))
3708 thread_hop_needed = 1;
3709 }
3710 else if (singlestep_breakpoints_inserted_p)
3711 {
3712 /* We have not context switched yet, so this should be true
3713 no matter which thread hit the singlestep breakpoint. */
3714 gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
3715 if (debug_infrun)
3716 fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
3717 "trap for %s\n",
3718 target_pid_to_str (ecs->ptid));
3719
3720 ecs->random_signal = 0;
3721 /* The call to in_thread_list is necessary because PTIDs sometimes
3722 change when we go from single-threaded to multi-threaded. If
3723 the singlestep_ptid is still in the list, assume that it is
3724 really different from ecs->ptid. */
3725 if (!ptid_equal (singlestep_ptid, ecs->ptid)
3726 && in_thread_list (singlestep_ptid))
3727 {
3728 /* If the PC of the thread we were trying to single-step
3729 has changed, discard this event (which we were going
3730 to ignore anyway), and pretend we saw that thread
3731 trap. This prevents us continuously moving the
3732 single-step breakpoint forward, one instruction at a
3733 time. If the PC has changed, then the thread we were
3734 trying to single-step has trapped or been signalled,
3735 but the event has not been reported to GDB yet.
3736
3737 There might be some cases where this loses signal
3738 information, if a signal has arrived at exactly the
3739 same time that the PC changed, but this is the best
3740 we can do with the information available. Perhaps we
3741 should arrange to report all events for all threads
3742 when they stop, or to re-poll the remote looking for
3743 this particular thread (i.e. temporarily enable
3744 schedlock). */
3745
3746 CORE_ADDR new_singlestep_pc
3747 = regcache_read_pc (get_thread_regcache (singlestep_ptid));
3748
3749 if (new_singlestep_pc != singlestep_pc)
3750 {
3751 enum target_signal stop_signal;
3752
3753 if (debug_infrun)
3754 fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread,"
3755 " but expected thread advanced also\n");
3756
3757 /* The current context still belongs to
3758 singlestep_ptid. Don't swap here, since that's
3759 the context we want to use. Just fudge our
3760 state and continue. */
3761 stop_signal = ecs->event_thread->suspend.stop_signal;
3762 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
3763 ecs->ptid = singlestep_ptid;
3764 ecs->event_thread = find_thread_ptid (ecs->ptid);
3765 ecs->event_thread->suspend.stop_signal = stop_signal;
3766 stop_pc = new_singlestep_pc;
3767 }
3768 else
3769 {
3770 if (debug_infrun)
3771 fprintf_unfiltered (gdb_stdlog,
3772 "infrun: unexpected thread\n");
3773
3774 thread_hop_needed = 1;
3775 stepping_past_singlestep_breakpoint = 1;
3776 saved_singlestep_ptid = singlestep_ptid;
3777 }
3778 }
3779 }
3780
3781 if (thread_hop_needed)
3782 {
3783 struct regcache *thread_regcache;
3784 int remove_status = 0;
3785
3786 if (debug_infrun)
3787 fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n");
3788
3789 /* Switch context before touching inferior memory, the
3790 previous thread may have exited. */
3791 if (!ptid_equal (inferior_ptid, ecs->ptid))
3792 context_switch (ecs->ptid);
3793
3794 /* Saw a breakpoint, but it was hit by the wrong thread.
3795 Just continue. */
3796
3797 if (singlestep_breakpoints_inserted_p)
3798 {
3799 /* Pull the single step breakpoints out of the target. */
3800 remove_single_step_breakpoints ();
3801 singlestep_breakpoints_inserted_p = 0;
3802 }
3803
3804 /* If the arch can displace step, don't remove the
3805 breakpoints. */
3806 thread_regcache = get_thread_regcache (ecs->ptid);
3807 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
3808 remove_status = remove_breakpoints ();
3809
3810 /* Did we fail to remove breakpoints? If so, try
3811 to set the PC past the bp. (There's at least
3812 one situation in which we can fail to remove
3813 the bp's: On HP-UX's that use ttrace, we can't
3814 change the address space of a vforking child
3815 process until the child exits (well, okay, not
3816 then either :-) or execs. */
3817 if (remove_status != 0)
3818 error (_("Cannot step over breakpoint hit in wrong thread"));
3819 else
3820 { /* Single step */
3821 if (!non_stop)
3822 {
3823 /* Only need to require the next event from this
3824 thread in all-stop mode. */
3825 waiton_ptid = ecs->ptid;
3826 infwait_state = infwait_thread_hop_state;
3827 }
3828
3829 ecs->event_thread->stepping_over_breakpoint = 1;
3830 keep_going (ecs);
3831 return;
3832 }
3833 }
3834 else if (singlestep_breakpoints_inserted_p)
3835 {
3836 sw_single_step_trap_p = 1;
3837 ecs->random_signal = 0;
3838 }
3839 }
3840 else
3841 ecs->random_signal = 1;
3842
3843 /* See if something interesting happened to the non-current thread. If
3844 so, then switch to that thread. */
3845 if (!ptid_equal (ecs->ptid, inferior_ptid))
3846 {
3847 if (debug_infrun)
3848 fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
3849
3850 context_switch (ecs->ptid);
3851
3852 if (deprecated_context_hook)
3853 deprecated_context_hook (pid_to_thread_id (ecs->ptid));
3854 }
3855
3856 /* At this point, get hold of the now-current thread's frame. */
3857 frame = get_current_frame ();
3858 gdbarch = get_frame_arch (frame);
3859
3860 if (singlestep_breakpoints_inserted_p)
3861 {
3862 /* Pull the single step breakpoints out of the target. */
3863 remove_single_step_breakpoints ();
3864 singlestep_breakpoints_inserted_p = 0;
3865 }
3866
3867 if (stepped_after_stopped_by_watchpoint)
3868 stopped_by_watchpoint = 0;
3869 else
3870 stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
3871
3872 /* If necessary, step over this watchpoint. We'll be back to display
3873 it in a moment. */
3874 if (stopped_by_watchpoint
3875 && (target_have_steppable_watchpoint
3876 || gdbarch_have_nonsteppable_watchpoint (gdbarch)))
3877 {
3878 /* At this point, we are stopped at an instruction which has
3879 attempted to write to a piece of memory under control of
3880 a watchpoint. The instruction hasn't actually executed
3881 yet. If we were to evaluate the watchpoint expression
3882 now, we would get the old value, and therefore no change
3883 would seem to have occurred.
3884
3885 In order to make watchpoints work `right', we really need
3886 to complete the memory write, and then evaluate the
3887 watchpoint expression. We do this by single-stepping the
3888 target.
3889
3890 It may not be necessary to disable the watchpoint to stop over
3891 it. For example, the PA can (with some kernel cooperation)
3892 single step over a watchpoint without disabling the watchpoint.
3893
3894 It is far more common to need to disable a watchpoint to step
3895 the inferior over it. If we have non-steppable watchpoints,
3896 we must disable the current watchpoint; it's simplest to
3897 disable all watchpoints and breakpoints. */
3898 int hw_step = 1;
3899
3900 if (!target_have_steppable_watchpoint)
3901 {
3902 remove_breakpoints ();
3903 /* See comment in resume why we need to stop bypassing signals
3904 while breakpoints have been removed. */
3905 target_pass_signals (0, NULL);
3906 }
3907 /* Single step */
3908 hw_step = maybe_software_singlestep (gdbarch, stop_pc);
3909 target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0);
3910 waiton_ptid = ecs->ptid;
3911 if (target_have_steppable_watchpoint)
3912 infwait_state = infwait_step_watch_state;
3913 else
3914 infwait_state = infwait_nonstep_watch_state;
3915 prepare_to_wait (ecs);
3916 return;
3917 }
3918
3919 ecs->stop_func_start = 0;
3920 ecs->stop_func_end = 0;
3921 ecs->stop_func_name = 0;
3922 /* Don't care about return value; stop_func_start and stop_func_name
3923 will both be 0 if it doesn't work. */
3924 find_pc_partial_function (stop_pc, &ecs->stop_func_name,
3925 &ecs->stop_func_start, &ecs->stop_func_end);
3926 ecs->stop_func_start
3927 += gdbarch_deprecated_function_start_offset (gdbarch);
3928 ecs->event_thread->stepping_over_breakpoint = 0;
3929 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
3930 ecs->event_thread->control.stop_step = 0;
3931 stop_print_frame = 1;
3932 ecs->random_signal = 0;
3933 stopped_by_random_signal = 0;
3934
3935 /* Hide inlined functions starting here, unless we just performed stepi or
3936 nexti. After stepi and nexti, always show the innermost frame (not any
3937 inline function call sites). */
3938 if (ecs->event_thread->control.step_range_end != 1)
3939 skip_inline_frames (ecs->ptid);
3940
3941 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3942 && ecs->event_thread->control.trap_expected
3943 && gdbarch_single_step_through_delay_p (gdbarch)
3944 && currently_stepping (ecs->event_thread))
3945 {
3946 /* We're trying to step off a breakpoint. Turns out that we're
3947 also on an instruction that needs to be stepped multiple
3948 times before it's been fully executing. E.g., architectures
3949 with a delay slot. It needs to be stepped twice, once for
3950 the instruction and once for the delay slot. */
3951 int step_through_delay
3952 = gdbarch_single_step_through_delay (gdbarch, frame);
3953
3954 if (debug_infrun && step_through_delay)
3955 fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n");
3956 if (ecs->event_thread->control.step_range_end == 0
3957 && step_through_delay)
3958 {
3959 /* The user issued a continue when stopped at a breakpoint.
3960 Set up for another trap and get out of here. */
3961 ecs->event_thread->stepping_over_breakpoint = 1;
3962 keep_going (ecs);
3963 return;
3964 }
3965 else if (step_through_delay)
3966 {
3967 /* The user issued a step when stopped at a breakpoint.
3968 Maybe we should stop, maybe we should not - the delay
3969 slot *might* correspond to a line of source. In any
3970 case, don't decide that here, just set
3971 ecs->stepping_over_breakpoint, making sure we
3972 single-step again before breakpoints are re-inserted. */
3973 ecs->event_thread->stepping_over_breakpoint = 1;
3974 }
3975 }
3976
3977 /* Look at the cause of the stop, and decide what to do.
3978 The alternatives are:
3979 1) stop_stepping and return; to really stop and return to the debugger,
3980 2) keep_going and return to start up again
3981 (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once)
3982 3) set ecs->random_signal to 1, and the decision between 1 and 2
3983 will be made according to the signal handling tables. */
3984
3985 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3986 || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP
3987 || stop_soon == STOP_QUIETLY_REMOTE)
3988 {
3989 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
3990 && stop_after_trap)
3991 {
3992 if (debug_infrun)
3993 fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n");
3994 stop_print_frame = 0;
3995 stop_stepping (ecs);
3996 return;
3997 }
3998
3999 /* This is originated from start_remote(), start_inferior() and
4000 shared libraries hook functions. */
4001 if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE)
4002 {
4003 if (debug_infrun)
4004 fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n");
4005 stop_stepping (ecs);
4006 return;
4007 }
4008
4009 /* This originates from attach_command(). We need to overwrite
4010 the stop_signal here, because some kernels don't ignore a
4011 SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call.
4012 See more comments in inferior.h. On the other hand, if we
4013 get a non-SIGSTOP, report it to the user - assume the backend
4014 will handle the SIGSTOP if it should show up later.
4015
4016 Also consider that the attach is complete when we see a
4017 SIGTRAP. Some systems (e.g. Windows), and stubs supporting
4018 target extended-remote report it instead of a SIGSTOP
4019 (e.g. gdbserver). We already rely on SIGTRAP being our
4020 signal, so this is no exception.
4021
4022 Also consider that the attach is complete when we see a
4023 TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell
4024 the target to stop all threads of the inferior, in case the
4025 low level attach operation doesn't stop them implicitly. If
4026 they weren't stopped implicitly, then the stub will report a
4027 TARGET_SIGNAL_0, meaning: stopped for no particular reason
4028 other than GDB's request. */
4029 if (stop_soon == STOP_QUIETLY_NO_SIGSTOP
4030 && (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_STOP
4031 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
4032 || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_0))
4033 {
4034 stop_stepping (ecs);
4035 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
4036 return;
4037 }
4038
4039 /* See if there is a breakpoint at the current PC. */
4040 ecs->event_thread->control.stop_bpstat
4041 = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()),
4042 stop_pc, ecs->ptid);
4043
4044 /* Following in case break condition called a
4045 function. */
4046 stop_print_frame = 1;
4047
4048 /* This is where we handle "moribund" watchpoints. Unlike
4049 software breakpoints traps, hardware watchpoint traps are
4050 always distinguishable from random traps. If no high-level
4051 watchpoint is associated with the reported stop data address
4052 anymore, then the bpstat does not explain the signal ---
4053 simply make sure to ignore it if `stopped_by_watchpoint' is
4054 set. */
4055
4056 if (debug_infrun
4057 && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
4058 && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
4059 && stopped_by_watchpoint)
4060 fprintf_unfiltered (gdb_stdlog,
4061 "infrun: no user watchpoint explains "
4062 "watchpoint SIGTRAP, ignoring\n");
4063
4064 /* NOTE: cagney/2003-03-29: These two checks for a random signal
4065 at one stage in the past included checks for an inferior
4066 function call's call dummy's return breakpoint. The original
4067 comment, that went with the test, read:
4068
4069 ``End of a stack dummy. Some systems (e.g. Sony news) give
4070 another signal besides SIGTRAP, so check here as well as
4071 above.''
4072
4073 If someone ever tries to get call dummys on a
4074 non-executable stack to work (where the target would stop
4075 with something like a SIGSEGV), then those tests might need
4076 to be re-instated. Given, however, that the tests were only
4077 enabled when momentary breakpoints were not being used, I
4078 suspect that it won't be the case.
4079
4080 NOTE: kettenis/2004-02-05: Indeed such checks don't seem to
4081 be necessary for call dummies on a non-executable stack on
4082 SPARC. */
4083
4084 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP)
4085 ecs->random_signal
4086 = !(bpstat_explains_signal (ecs->event_thread->control.stop_bpstat)
4087 || stopped_by_watchpoint
4088 || ecs->event_thread->control.trap_expected
4089 || (ecs->event_thread->control.step_range_end
4090 && (ecs->event_thread->control.step_resume_breakpoint
4091 == NULL)));
4092 else
4093 {
4094 ecs->random_signal = !bpstat_explains_signal
4095 (ecs->event_thread->control.stop_bpstat);
4096 if (!ecs->random_signal)
4097 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP;
4098 }
4099 }
4100
4101 /* When we reach this point, we've pretty much decided
4102 that the reason for stopping must've been a random
4103 (unexpected) signal. */
4104
4105 else
4106 ecs->random_signal = 1;
4107
4108 process_event_stop_test:
4109
4110 /* Re-fetch current thread's frame in case we did a
4111 "goto process_event_stop_test" above. */
4112 frame = get_current_frame ();
4113 gdbarch = get_frame_arch (frame);
4114
4115 /* For the program's own signals, act according to
4116 the signal handling tables. */
4117
4118 if (ecs->random_signal)
4119 {
4120 /* Signal not for debugging purposes. */
4121 int printed = 0;
4122 struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
4123
4124 if (debug_infrun)
4125 fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n",
4126 ecs->event_thread->suspend.stop_signal);
4127
4128 stopped_by_random_signal = 1;
4129
4130 if (signal_print[ecs->event_thread->suspend.stop_signal])
4131 {
4132 printed = 1;
4133 target_terminal_ours_for_output ();
4134 print_signal_received_reason
4135 (ecs->event_thread->suspend.stop_signal);
4136 }
4137 /* Always stop on signals if we're either just gaining control
4138 of the program, or the user explicitly requested this thread
4139 to remain stopped. */
4140 if (stop_soon != NO_STOP_QUIETLY
4141 || ecs->event_thread->stop_requested
4142 || (!inf->detaching
4143 && signal_stop_state (ecs->event_thread->suspend.stop_signal)))
4144 {
4145 stop_stepping (ecs);
4146 return;
4147 }
4148 /* If not going to stop, give terminal back
4149 if we took it away. */
4150 else if (printed)
4151 target_terminal_inferior ();
4152
4153 /* Clear the signal if it should not be passed. */
4154 if (signal_program[ecs->event_thread->suspend.stop_signal] == 0)
4155 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
4156
4157 if (ecs->event_thread->prev_pc == stop_pc
4158 && ecs->event_thread->control.trap_expected
4159 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4160 {
4161 /* We were just starting a new sequence, attempting to
4162 single-step off of a breakpoint and expecting a SIGTRAP.
4163 Instead this signal arrives. This signal will take us out
4164 of the stepping range so GDB needs to remember to, when
4165 the signal handler returns, resume stepping off that
4166 breakpoint. */
4167 /* To simplify things, "continue" is forced to use the same
4168 code paths as single-step - set a breakpoint at the
4169 signal return address and then, once hit, step off that
4170 breakpoint. */
4171 if (debug_infrun)
4172 fprintf_unfiltered (gdb_stdlog,
4173 "infrun: signal arrived while stepping over "
4174 "breakpoint\n");
4175
4176 insert_step_resume_breakpoint_at_frame (frame);
4177 ecs->event_thread->step_after_step_resume_breakpoint = 1;
4178 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4179 ecs->event_thread->control.trap_expected = 0;
4180 keep_going (ecs);
4181 return;
4182 }
4183
4184 if (ecs->event_thread->control.step_range_end != 0
4185 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_0
4186 && (ecs->event_thread->control.step_range_start <= stop_pc
4187 && stop_pc < ecs->event_thread->control.step_range_end)
4188 && frame_id_eq (get_stack_frame_id (frame),
4189 ecs->event_thread->control.step_stack_frame_id)
4190 && ecs->event_thread->control.step_resume_breakpoint == NULL)
4191 {
4192 /* The inferior is about to take a signal that will take it
4193 out of the single step range. Set a breakpoint at the
4194 current PC (which is presumably where the signal handler
4195 will eventually return) and then allow the inferior to
4196 run free.
4197
4198 Note that this is only needed for a signal delivered
4199 while in the single-step range. Nested signals aren't a
4200 problem as they eventually all return. */
4201 if (debug_infrun)
4202 fprintf_unfiltered (gdb_stdlog,
4203 "infrun: signal may take us out of "
4204 "single-step range\n");
4205
4206 insert_step_resume_breakpoint_at_frame (frame);
4207 /* Reset trap_expected to ensure breakpoints are re-inserted. */
4208 ecs->event_thread->control.trap_expected = 0;
4209 keep_going (ecs);
4210 return;
4211 }
4212
4213 /* Note: step_resume_breakpoint may be non-NULL. This occures
4214 when either there's a nested signal, or when there's a
4215 pending signal enabled just as the signal handler returns
4216 (leaving the inferior at the step-resume-breakpoint without
4217 actually executing it). Either way continue until the
4218 breakpoint is really hit. */
4219 keep_going (ecs);
4220 return;
4221 }
4222
4223 /* Handle cases caused by hitting a breakpoint. */
4224 {
4225 CORE_ADDR jmp_buf_pc;
4226 struct bpstat_what what;
4227
4228 what = bpstat_what (ecs->event_thread->control.stop_bpstat);
4229
4230 if (what.call_dummy)
4231 {
4232 stop_stack_dummy = what.call_dummy;
4233 }
4234
4235 /* If we hit an internal event that triggers symbol changes, the
4236 current frame will be invalidated within bpstat_what (e.g., if
4237 we hit an internal solib event). Re-fetch it. */
4238 frame = get_current_frame ();
4239 gdbarch = get_frame_arch (frame);
4240
4241 switch (what.main_action)
4242 {
4243 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
4244 /* If we hit the breakpoint at longjmp while stepping, we
4245 install a momentary breakpoint at the target of the
4246 jmp_buf. */
4247
4248 if (debug_infrun)
4249 fprintf_unfiltered (gdb_stdlog,
4250 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n");
4251
4252 ecs->event_thread->stepping_over_breakpoint = 1;
4253
4254 if (what.is_longjmp)
4255 {
4256 if (!gdbarch_get_longjmp_target_p (gdbarch)
4257 || !gdbarch_get_longjmp_target (gdbarch,
4258 frame, &jmp_buf_pc))
4259 {
4260 if (debug_infrun)
4261 fprintf_unfiltered (gdb_stdlog,
4262 "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME "
4263 "(!gdbarch_get_longjmp_target)\n");
4264 keep_going (ecs);
4265 return;
4266 }
4267
4268 /* We're going to replace the current step-resume breakpoint
4269 with a longjmp-resume breakpoint. */
4270 delete_step_resume_breakpoint (ecs->event_thread);
4271
4272 /* Insert a breakpoint at resume address. */
4273 insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc);
4274 }
4275 else
4276 {
4277 struct symbol *func = get_frame_function (frame);
4278
4279 if (func)
4280 check_exception_resume (ecs, frame, func);
4281 }
4282 keep_going (ecs);
4283 return;
4284
4285 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
4286 if (debug_infrun)
4287 fprintf_unfiltered (gdb_stdlog,
4288 "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n");
4289
4290 if (what.is_longjmp)
4291 {
4292 gdb_assert (ecs->event_thread->control.step_resume_breakpoint
4293 != NULL);
4294 delete_step_resume_breakpoint (ecs->event_thread);
4295 }
4296 else
4297 {
4298 /* There are several cases to consider.
4299
4300 1. The initiating frame no longer exists. In this case
4301 we must stop, because the exception has gone too far.
4302
4303 2. The initiating frame exists, and is the same as the
4304 current frame. We stop, because the exception has been
4305 caught.
4306
4307 3. The initiating frame exists and is different from
4308 the current frame. This means the exception has been
4309 caught beneath the initiating frame, so keep going. */
4310 struct frame_info *init_frame
4311 = frame_find_by_id (ecs->event_thread->initiating_frame);
4312
4313 gdb_assert (ecs->event_thread->control.exception_resume_breakpoint
4314 != NULL);
4315 delete_exception_resume_breakpoint (ecs->event_thread);
4316
4317 if (init_frame)
4318 {
4319 struct frame_id current_id
4320 = get_frame_id (get_current_frame ());
4321 if (frame_id_eq (current_id,
4322 ecs->event_thread->initiating_frame))
4323 {
4324 /* Case 2. Fall through. */
4325 }
4326 else
4327 {
4328 /* Case 3. */
4329 keep_going (ecs);
4330 return;
4331 }
4332 }
4333
4334 /* For Cases 1 and 2, remove the step-resume breakpoint,
4335 if it exists. */
4336 delete_step_resume_breakpoint (ecs->event_thread);
4337 }
4338
4339 ecs->event_thread->control.stop_step = 1;
4340 print_end_stepping_range_reason ();
4341 stop_stepping (ecs);
4342 return;
4343
4344 case BPSTAT_WHAT_SINGLE:
4345 if (debug_infrun)
4346 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n");
4347 ecs->event_thread->stepping_over_breakpoint = 1;
4348 /* Still need to check other stuff, at least the case
4349 where we are stepping and step out of the right range. */
4350 break;
4351
4352 case BPSTAT_WHAT_STOP_NOISY:
4353 if (debug_infrun)
4354 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n");
4355 stop_print_frame = 1;
4356
4357 /* We are about to nuke the step_resume_breakpointt via the
4358 cleanup chain, so no need to worry about it here. */
4359
4360 stop_stepping (ecs);
4361 return;
4362
4363 case BPSTAT_WHAT_STOP_SILENT:
4364 if (debug_infrun)
4365 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n");
4366 stop_print_frame = 0;
4367
4368 /* We are about to nuke the step_resume_breakpoin via the
4369 cleanup chain, so no need to worry about it here. */
4370
4371 stop_stepping (ecs);
4372 return;
4373
4374 case BPSTAT_WHAT_STEP_RESUME:
4375 if (debug_infrun)
4376 fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n");
4377
4378 delete_step_resume_breakpoint (ecs->event_thread);
4379 if (ecs->event_thread->step_after_step_resume_breakpoint)
4380 {
4381 /* Back when the step-resume breakpoint was inserted, we
4382 were trying to single-step off a breakpoint. Go back
4383 to doing that. */
4384 ecs->event_thread->step_after_step_resume_breakpoint = 0;
4385 ecs->event_thread->stepping_over_breakpoint = 1;
4386 keep_going (ecs);
4387 return;
4388 }
4389 if (stop_pc == ecs->stop_func_start
4390 && execution_direction == EXEC_REVERSE)
4391 {
4392 /* We are stepping over a function call in reverse, and
4393 just hit the step-resume breakpoint at the start
4394 address of the function. Go back to single-stepping,
4395 which should take us back to the function call. */
4396 ecs->event_thread->stepping_over_breakpoint = 1;
4397 keep_going (ecs);
4398 return;
4399 }
4400 break;
4401
4402 case BPSTAT_WHAT_KEEP_CHECKING:
4403 break;
4404 }
4405 }
4406
4407 /* We come here if we hit a breakpoint but should not
4408 stop for it. Possibly we also were stepping
4409 and should stop for that. So fall through and
4410 test for stepping. But, if not stepping,
4411 do not stop. */
4412
4413 /* In all-stop mode, if we're currently stepping but have stopped in
4414 some other thread, we need to switch back to the stepped thread. */
4415 if (!non_stop)
4416 {
4417 struct thread_info *tp;
4418
4419 tp = iterate_over_threads (currently_stepping_or_nexting_callback,
4420 ecs->event_thread);
4421 if (tp)
4422 {
4423 /* However, if the current thread is blocked on some internal
4424 breakpoint, and we simply need to step over that breakpoint
4425 to get it going again, do that first. */
4426 if ((ecs->event_thread->control.trap_expected
4427 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
4428 || ecs->event_thread->stepping_over_breakpoint)
4429 {
4430 keep_going (ecs);
4431 return;
4432 }
4433
4434 /* If the stepping thread exited, then don't try to switch
4435 back and resume it, which could fail in several different
4436 ways depending on the target. Instead, just keep going.
4437
4438 We can find a stepping dead thread in the thread list in
4439 two cases:
4440
4441 - The target supports thread exit events, and when the
4442 target tries to delete the thread from the thread list,
4443 inferior_ptid pointed at the exiting thread. In such
4444 case, calling delete_thread does not really remove the
4445 thread from the list; instead, the thread is left listed,
4446 with 'exited' state.
4447
4448 - The target's debug interface does not support thread
4449 exit events, and so we have no idea whatsoever if the
4450 previously stepping thread is still alive. For that
4451 reason, we need to synchronously query the target
4452 now. */
4453 if (is_exited (tp->ptid)
4454 || !target_thread_alive (tp->ptid))
4455 {
4456 if (debug_infrun)
4457 fprintf_unfiltered (gdb_stdlog,
4458 "infrun: not switching back to "
4459 "stepped thread, it has vanished\n");
4460
4461 delete_thread (tp->ptid);
4462 keep_going (ecs);
4463 return;
4464 }
4465
4466 /* Otherwise, we no longer expect a trap in the current thread.
4467 Clear the trap_expected flag before switching back -- this is
4468 what keep_going would do as well, if we called it. */
4469 ecs->event_thread->control.trap_expected = 0;
4470
4471 if (debug_infrun)
4472 fprintf_unfiltered (gdb_stdlog,
4473 "infrun: switching back to stepped thread\n");
4474
4475 ecs->event_thread = tp;
4476 ecs->ptid = tp->ptid;
4477 context_switch (ecs->ptid);
4478 keep_going (ecs);
4479 return;
4480 }
4481 }
4482
4483 /* Are we stepping to get the inferior out of the dynamic linker's
4484 hook (and possibly the dld itself) after catching a shlib
4485 event? */
4486 if (ecs->event_thread->stepping_through_solib_after_catch)
4487 {
4488 #if defined(SOLIB_ADD)
4489 /* Have we reached our destination? If not, keep going. */
4490 if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
4491 {
4492 if (debug_infrun)
4493 fprintf_unfiltered (gdb_stdlog,
4494 "infrun: stepping in dynamic linker\n");
4495 ecs->event_thread->stepping_over_breakpoint = 1;
4496 keep_going (ecs);
4497 return;
4498 }
4499 #endif
4500 if (debug_infrun)
4501 fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n");
4502 /* Else, stop and report the catchpoint(s) whose triggering
4503 caused us to begin stepping. */
4504 ecs->event_thread->stepping_through_solib_after_catch = 0;
4505 bpstat_clear (&ecs->event_thread->control.stop_bpstat);
4506 ecs->event_thread->control.stop_bpstat
4507 = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints);
4508 bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints);
4509 stop_print_frame = 1;
4510 stop_stepping (ecs);
4511 return;
4512 }
4513
4514 if (ecs->event_thread->control.step_resume_breakpoint)
4515 {
4516 if (debug_infrun)
4517 fprintf_unfiltered (gdb_stdlog,
4518 "infrun: step-resume breakpoint is inserted\n");
4519
4520 /* Having a step-resume breakpoint overrides anything
4521 else having to do with stepping commands until
4522 that breakpoint is reached. */
4523 keep_going (ecs);
4524 return;
4525 }
4526
4527 if (ecs->event_thread->control.step_range_end == 0)
4528 {
4529 if (debug_infrun)
4530 fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n");
4531 /* Likewise if we aren't even stepping. */
4532 keep_going (ecs);
4533 return;
4534 }
4535
4536 /* Re-fetch current thread's frame in case the code above caused
4537 the frame cache to be re-initialized, making our FRAME variable
4538 a dangling pointer. */
4539 frame = get_current_frame ();
4540 gdbarch = get_frame_arch (frame);
4541
4542 /* If stepping through a line, keep going if still within it.
4543
4544 Note that step_range_end is the address of the first instruction
4545 beyond the step range, and NOT the address of the last instruction
4546 within it!
4547
4548 Note also that during reverse execution, we may be stepping
4549 through a function epilogue and therefore must detect when
4550 the current-frame changes in the middle of a line. */
4551
4552 if (stop_pc >= ecs->event_thread->control.step_range_start
4553 && stop_pc < ecs->event_thread->control.step_range_end
4554 && (execution_direction != EXEC_REVERSE
4555 || frame_id_eq (get_frame_id (frame),
4556 ecs->event_thread->control.step_frame_id)))
4557 {
4558 if (debug_infrun)
4559 fprintf_unfiltered
4560 (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n",
4561 paddress (gdbarch, ecs->event_thread->control.step_range_start),
4562 paddress (gdbarch, ecs->event_thread->control.step_range_end));
4563
4564 /* When stepping backward, stop at beginning of line range
4565 (unless it's the function entry point, in which case
4566 keep going back to the call point). */
4567 if (stop_pc == ecs->event_thread->control.step_range_start
4568 && stop_pc != ecs->stop_func_start
4569 && execution_direction == EXEC_REVERSE)
4570 {
4571 ecs->event_thread->control.stop_step = 1;
4572 print_end_stepping_range_reason ();
4573 stop_stepping (ecs);
4574 }
4575 else
4576 keep_going (ecs);
4577
4578 return;
4579 }
4580
4581 /* We stepped out of the stepping range. */
4582
4583 /* If we are stepping at the source level and entered the runtime
4584 loader dynamic symbol resolution code...
4585
4586 EXEC_FORWARD: we keep on single stepping until we exit the run
4587 time loader code and reach the callee's address.
4588
4589 EXEC_REVERSE: we've already executed the callee (backward), and
4590 the runtime loader code is handled just like any other
4591 undebuggable function call. Now we need only keep stepping
4592 backward through the trampoline code, and that's handled further
4593 down, so there is nothing for us to do here. */
4594
4595 if (execution_direction != EXEC_REVERSE
4596 && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4597 && in_solib_dynsym_resolve_code (stop_pc))
4598 {
4599 CORE_ADDR pc_after_resolver =
4600 gdbarch_skip_solib_resolver (gdbarch, stop_pc);
4601
4602 if (debug_infrun)
4603 fprintf_unfiltered (gdb_stdlog,
4604 "infrun: stepped into dynsym resolve code\n");
4605
4606 if (pc_after_resolver)
4607 {
4608 /* Set up a step-resume breakpoint at the address
4609 indicated by SKIP_SOLIB_RESOLVER. */
4610 struct symtab_and_line sr_sal;
4611
4612 init_sal (&sr_sal);
4613 sr_sal.pc = pc_after_resolver;
4614 sr_sal.pspace = get_frame_program_space (frame);
4615
4616 insert_step_resume_breakpoint_at_sal (gdbarch,
4617 sr_sal, null_frame_id);
4618 }
4619
4620 keep_going (ecs);
4621 return;
4622 }
4623
4624 if (ecs->event_thread->control.step_range_end != 1
4625 && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4626 || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4627 && get_frame_type (frame) == SIGTRAMP_FRAME)
4628 {
4629 if (debug_infrun)
4630 fprintf_unfiltered (gdb_stdlog,
4631 "infrun: stepped into signal trampoline\n");
4632 /* The inferior, while doing a "step" or "next", has ended up in
4633 a signal trampoline (either by a signal being delivered or by
4634 the signal handler returning). Just single-step until the
4635 inferior leaves the trampoline (either by calling the handler
4636 or returning). */
4637 keep_going (ecs);
4638 return;
4639 }
4640
4641 /* Check for subroutine calls. The check for the current frame
4642 equalling the step ID is not necessary - the check of the
4643 previous frame's ID is sufficient - but it is a common case and
4644 cheaper than checking the previous frame's ID.
4645
4646 NOTE: frame_id_eq will never report two invalid frame IDs as
4647 being equal, so to get into this block, both the current and
4648 previous frame must have valid frame IDs. */
4649 /* The outer_frame_id check is a heuristic to detect stepping
4650 through startup code. If we step over an instruction which
4651 sets the stack pointer from an invalid value to a valid value,
4652 we may detect that as a subroutine call from the mythical
4653 "outermost" function. This could be fixed by marking
4654 outermost frames as !stack_p,code_p,special_p. Then the
4655 initial outermost frame, before sp was valid, would
4656 have code_addr == &_start. See the comment in frame_id_eq
4657 for more. */
4658 if (!frame_id_eq (get_stack_frame_id (frame),
4659 ecs->event_thread->control.step_stack_frame_id)
4660 && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()),
4661 ecs->event_thread->control.step_stack_frame_id)
4662 && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id,
4663 outer_frame_id)
4664 || step_start_function != find_pc_function (stop_pc))))
4665 {
4666 CORE_ADDR real_stop_pc;
4667
4668 if (debug_infrun)
4669 fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n");
4670
4671 if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE)
4672 || ((ecs->event_thread->control.step_range_end == 1)
4673 && in_prologue (gdbarch, ecs->event_thread->prev_pc,
4674 ecs->stop_func_start)))
4675 {
4676 /* I presume that step_over_calls is only 0 when we're
4677 supposed to be stepping at the assembly language level
4678 ("stepi"). Just stop. */
4679 /* Also, maybe we just did a "nexti" inside a prolog, so we
4680 thought it was a subroutine call but it was not. Stop as
4681 well. FENN */
4682 /* And this works the same backward as frontward. MVS */
4683 ecs->event_thread->control.stop_step = 1;
4684 print_end_stepping_range_reason ();
4685 stop_stepping (ecs);
4686 return;
4687 }
4688
4689 /* Reverse stepping through solib trampolines. */
4690
4691 if (execution_direction == EXEC_REVERSE
4692 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE
4693 && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4694 || (ecs->stop_func_start == 0
4695 && in_solib_dynsym_resolve_code (stop_pc))))
4696 {
4697 /* Any solib trampoline code can be handled in reverse
4698 by simply continuing to single-step. We have already
4699 executed the solib function (backwards), and a few
4700 steps will take us back through the trampoline to the
4701 caller. */
4702 keep_going (ecs);
4703 return;
4704 }
4705
4706 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
4707 {
4708 /* We're doing a "next".
4709
4710 Normal (forward) execution: set a breakpoint at the
4711 callee's return address (the address at which the caller
4712 will resume).
4713
4714 Reverse (backward) execution. set the step-resume
4715 breakpoint at the start of the function that we just
4716 stepped into (backwards), and continue to there. When we
4717 get there, we'll need to single-step back to the caller. */
4718
4719 if (execution_direction == EXEC_REVERSE)
4720 {
4721 struct symtab_and_line sr_sal;
4722
4723 /* Normal function call return (static or dynamic). */
4724 init_sal (&sr_sal);
4725 sr_sal.pc = ecs->stop_func_start;
4726 sr_sal.pspace = get_frame_program_space (frame);
4727 insert_step_resume_breakpoint_at_sal (gdbarch,
4728 sr_sal, null_frame_id);
4729 }
4730 else
4731 insert_step_resume_breakpoint_at_caller (frame);
4732
4733 keep_going (ecs);
4734 return;
4735 }
4736
4737 /* If we are in a function call trampoline (a stub between the
4738 calling routine and the real function), locate the real
4739 function. That's what tells us (a) whether we want to step
4740 into it at all, and (b) what prologue we want to run to the
4741 end of, if we do step into it. */
4742 real_stop_pc = skip_language_trampoline (frame, stop_pc);
4743 if (real_stop_pc == 0)
4744 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4745 if (real_stop_pc != 0)
4746 ecs->stop_func_start = real_stop_pc;
4747
4748 if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc))
4749 {
4750 struct symtab_and_line sr_sal;
4751
4752 init_sal (&sr_sal);
4753 sr_sal.pc = ecs->stop_func_start;
4754 sr_sal.pspace = get_frame_program_space (frame);
4755
4756 insert_step_resume_breakpoint_at_sal (gdbarch,
4757 sr_sal, null_frame_id);
4758 keep_going (ecs);
4759 return;
4760 }
4761
4762 /* If we have line number information for the function we are
4763 thinking of stepping into, step into it.
4764
4765 If there are several symtabs at that PC (e.g. with include
4766 files), just want to know whether *any* of them have line
4767 numbers. find_pc_line handles this. */
4768 {
4769 struct symtab_and_line tmp_sal;
4770
4771 tmp_sal = find_pc_line (ecs->stop_func_start, 0);
4772 if (tmp_sal.line != 0)
4773 {
4774 if (execution_direction == EXEC_REVERSE)
4775 handle_step_into_function_backward (gdbarch, ecs);
4776 else
4777 handle_step_into_function (gdbarch, ecs);
4778 return;
4779 }
4780 }
4781
4782 /* If we have no line number and the step-stop-if-no-debug is
4783 set, we stop the step so that the user has a chance to switch
4784 in assembly mode. */
4785 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4786 && step_stop_if_no_debug)
4787 {
4788 ecs->event_thread->control.stop_step = 1;
4789 print_end_stepping_range_reason ();
4790 stop_stepping (ecs);
4791 return;
4792 }
4793
4794 if (execution_direction == EXEC_REVERSE)
4795 {
4796 /* Set a breakpoint at callee's start address.
4797 From there we can step once and be back in the caller. */
4798 struct symtab_and_line sr_sal;
4799
4800 init_sal (&sr_sal);
4801 sr_sal.pc = ecs->stop_func_start;
4802 sr_sal.pspace = get_frame_program_space (frame);
4803 insert_step_resume_breakpoint_at_sal (gdbarch,
4804 sr_sal, null_frame_id);
4805 }
4806 else
4807 /* Set a breakpoint at callee's return address (the address
4808 at which the caller will resume). */
4809 insert_step_resume_breakpoint_at_caller (frame);
4810
4811 keep_going (ecs);
4812 return;
4813 }
4814
4815 /* Reverse stepping through solib trampolines. */
4816
4817 if (execution_direction == EXEC_REVERSE
4818 && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE)
4819 {
4820 if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc)
4821 || (ecs->stop_func_start == 0
4822 && in_solib_dynsym_resolve_code (stop_pc)))
4823 {
4824 /* Any solib trampoline code can be handled in reverse
4825 by simply continuing to single-step. We have already
4826 executed the solib function (backwards), and a few
4827 steps will take us back through the trampoline to the
4828 caller. */
4829 keep_going (ecs);
4830 return;
4831 }
4832 else if (in_solib_dynsym_resolve_code (stop_pc))
4833 {
4834 /* Stepped backward into the solib dynsym resolver.
4835 Set a breakpoint at its start and continue, then
4836 one more step will take us out. */
4837 struct symtab_and_line sr_sal;
4838
4839 init_sal (&sr_sal);
4840 sr_sal.pc = ecs->stop_func_start;
4841 sr_sal.pspace = get_frame_program_space (frame);
4842 insert_step_resume_breakpoint_at_sal (gdbarch,
4843 sr_sal, null_frame_id);
4844 keep_going (ecs);
4845 return;
4846 }
4847 }
4848
4849 /* If we're in the return path from a shared library trampoline,
4850 we want to proceed through the trampoline when stepping. */
4851 if (gdbarch_in_solib_return_trampoline (gdbarch,
4852 stop_pc, ecs->stop_func_name))
4853 {
4854 /* Determine where this trampoline returns. */
4855 CORE_ADDR real_stop_pc;
4856
4857 real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc);
4858
4859 if (debug_infrun)
4860 fprintf_unfiltered (gdb_stdlog,
4861 "infrun: stepped into solib return tramp\n");
4862
4863 /* Only proceed through if we know where it's going. */
4864 if (real_stop_pc)
4865 {
4866 /* And put the step-breakpoint there and go until there. */
4867 struct symtab_and_line sr_sal;
4868
4869 init_sal (&sr_sal); /* initialize to zeroes */
4870 sr_sal.pc = real_stop_pc;
4871 sr_sal.section = find_pc_overlay (sr_sal.pc);
4872 sr_sal.pspace = get_frame_program_space (frame);
4873
4874 /* Do not specify what the fp should be when we stop since
4875 on some machines the prologue is where the new fp value
4876 is established. */
4877 insert_step_resume_breakpoint_at_sal (gdbarch,
4878 sr_sal, null_frame_id);
4879
4880 /* Restart without fiddling with the step ranges or
4881 other state. */
4882 keep_going (ecs);
4883 return;
4884 }
4885 }
4886
4887 stop_pc_sal = find_pc_line (stop_pc, 0);
4888
4889 /* NOTE: tausq/2004-05-24: This if block used to be done before all
4890 the trampoline processing logic, however, there are some trampolines
4891 that have no names, so we should do trampoline handling first. */
4892 if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE
4893 && ecs->stop_func_name == NULL
4894 && stop_pc_sal.line == 0)
4895 {
4896 if (debug_infrun)
4897 fprintf_unfiltered (gdb_stdlog,
4898 "infrun: stepped into undebuggable function\n");
4899
4900 /* The inferior just stepped into, or returned to, an
4901 undebuggable function (where there is no debugging information
4902 and no line number corresponding to the address where the
4903 inferior stopped). Since we want to skip this kind of code,
4904 we keep going until the inferior returns from this
4905 function - unless the user has asked us not to (via
4906 set step-mode) or we no longer know how to get back
4907 to the call site. */
4908 if (step_stop_if_no_debug
4909 || !frame_id_p (frame_unwind_caller_id (frame)))
4910 {
4911 /* If we have no line number and the step-stop-if-no-debug
4912 is set, we stop the step so that the user has a chance to
4913 switch in assembly mode. */
4914 ecs->event_thread->control.stop_step = 1;
4915 print_end_stepping_range_reason ();
4916 stop_stepping (ecs);
4917 return;
4918 }
4919 else
4920 {
4921 /* Set a breakpoint at callee's return address (the address
4922 at which the caller will resume). */
4923 insert_step_resume_breakpoint_at_caller (frame);
4924 keep_going (ecs);
4925 return;
4926 }
4927 }
4928
4929 if (ecs->event_thread->control.step_range_end == 1)
4930 {
4931 /* It is stepi or nexti. We always want to stop stepping after
4932 one instruction. */
4933 if (debug_infrun)
4934 fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n");
4935 ecs->event_thread->control.stop_step = 1;
4936 print_end_stepping_range_reason ();
4937 stop_stepping (ecs);
4938 return;
4939 }
4940
4941 if (stop_pc_sal.line == 0)
4942 {
4943 /* We have no line number information. That means to stop
4944 stepping (does this always happen right after one instruction,
4945 when we do "s" in a function with no line numbers,
4946 or can this happen as a result of a return or longjmp?). */
4947 if (debug_infrun)
4948 fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n");
4949 ecs->event_thread->control.stop_step = 1;
4950 print_end_stepping_range_reason ();
4951 stop_stepping (ecs);
4952 return;
4953 }
4954
4955 /* Look for "calls" to inlined functions, part one. If the inline
4956 frame machinery detected some skipped call sites, we have entered
4957 a new inline function. */
4958
4959 if (frame_id_eq (get_frame_id (get_current_frame ()),
4960 ecs->event_thread->control.step_frame_id)
4961 && inline_skipped_frames (ecs->ptid))
4962 {
4963 struct symtab_and_line call_sal;
4964
4965 if (debug_infrun)
4966 fprintf_unfiltered (gdb_stdlog,
4967 "infrun: stepped into inlined function\n");
4968
4969 find_frame_sal (get_current_frame (), &call_sal);
4970
4971 if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL)
4972 {
4973 /* For "step", we're going to stop. But if the call site
4974 for this inlined function is on the same source line as
4975 we were previously stepping, go down into the function
4976 first. Otherwise stop at the call site. */
4977
4978 if (call_sal.line == ecs->event_thread->current_line
4979 && call_sal.symtab == ecs->event_thread->current_symtab)
4980 step_into_inline_frame (ecs->ptid);
4981
4982 ecs->event_thread->control.stop_step = 1;
4983 print_end_stepping_range_reason ();
4984 stop_stepping (ecs);
4985 return;
4986 }
4987 else
4988 {
4989 /* For "next", we should stop at the call site if it is on a
4990 different source line. Otherwise continue through the
4991 inlined function. */
4992 if (call_sal.line == ecs->event_thread->current_line
4993 && call_sal.symtab == ecs->event_thread->current_symtab)
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
5005 /* Look for "calls" to inlined functions, part two. If we are still
5006 in the same real function we were stepping through, but we have
5007 to go further up to find the exact frame ID, we are stepping
5008 through a more inlined call beyond its call site. */
5009
5010 if (get_frame_type (get_current_frame ()) == INLINE_FRAME
5011 && !frame_id_eq (get_frame_id (get_current_frame ()),
5012 ecs->event_thread->control.step_frame_id)
5013 && stepped_in_from (get_current_frame (),
5014 ecs->event_thread->control.step_frame_id))
5015 {
5016 if (debug_infrun)
5017 fprintf_unfiltered (gdb_stdlog,
5018 "infrun: stepping through inlined function\n");
5019
5020 if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL)
5021 keep_going (ecs);
5022 else
5023 {
5024 ecs->event_thread->control.stop_step = 1;
5025 print_end_stepping_range_reason ();
5026 stop_stepping (ecs);
5027 }
5028 return;
5029 }
5030
5031 if ((stop_pc == stop_pc_sal.pc)
5032 && (ecs->event_thread->current_line != stop_pc_sal.line
5033 || ecs->event_thread->current_symtab != stop_pc_sal.symtab))
5034 {
5035 /* We are at the start of a different line. So stop. Note that
5036 we don't stop if we step into the middle of a different line.
5037 That is said to make things like for (;;) statements work
5038 better. */
5039 if (debug_infrun)
5040 fprintf_unfiltered (gdb_stdlog,
5041 "infrun: stepped to a different line\n");
5042 ecs->event_thread->control.stop_step = 1;
5043 print_end_stepping_range_reason ();
5044 stop_stepping (ecs);
5045 return;
5046 }
5047
5048 /* We aren't done stepping.
5049
5050 Optimize by setting the stepping range to the line.
5051 (We might not be in the original line, but if we entered a
5052 new line in mid-statement, we continue stepping. This makes
5053 things like for(;;) statements work better.) */
5054
5055 ecs->event_thread->control.step_range_start = stop_pc_sal.pc;
5056 ecs->event_thread->control.step_range_end = stop_pc_sal.end;
5057 set_step_info (frame, stop_pc_sal);
5058
5059 if (debug_infrun)
5060 fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n");
5061 keep_going (ecs);
5062 }
5063
5064 /* Is thread TP in the middle of single-stepping? */
5065
5066 static int
5067 currently_stepping (struct thread_info *tp)
5068 {
5069 return ((tp->control.step_range_end
5070 && tp->control.step_resume_breakpoint == NULL)
5071 || tp->control.trap_expected
5072 || tp->stepping_through_solib_after_catch
5073 || bpstat_should_step ());
5074 }
5075
5076 /* Returns true if any thread *but* the one passed in "data" is in the
5077 middle of stepping or of handling a "next". */
5078
5079 static int
5080 currently_stepping_or_nexting_callback (struct thread_info *tp, void *data)
5081 {
5082 if (tp == data)
5083 return 0;
5084
5085 return (tp->control.step_range_end
5086 || tp->control.trap_expected
5087 || tp->stepping_through_solib_after_catch);
5088 }
5089
5090 /* Inferior has stepped into a subroutine call with source code that
5091 we should not step over. Do step to the first line of code in
5092 it. */
5093
5094 static void
5095 handle_step_into_function (struct gdbarch *gdbarch,
5096 struct execution_control_state *ecs)
5097 {
5098 struct symtab *s;
5099 struct symtab_and_line stop_func_sal, sr_sal;
5100
5101 s = find_pc_symtab (stop_pc);
5102 if (s && s->language != language_asm)
5103 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5104 ecs->stop_func_start);
5105
5106 stop_func_sal = find_pc_line (ecs->stop_func_start, 0);
5107 /* Use the step_resume_break to step until the end of the prologue,
5108 even if that involves jumps (as it seems to on the vax under
5109 4.2). */
5110 /* If the prologue ends in the middle of a source line, continue to
5111 the end of that source line (if it is still within the function).
5112 Otherwise, just go to end of prologue. */
5113 if (stop_func_sal.end
5114 && stop_func_sal.pc != ecs->stop_func_start
5115 && stop_func_sal.end < ecs->stop_func_end)
5116 ecs->stop_func_start = stop_func_sal.end;
5117
5118 /* Architectures which require breakpoint adjustment might not be able
5119 to place a breakpoint at the computed address. If so, the test
5120 ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust
5121 ecs->stop_func_start to an address at which a breakpoint may be
5122 legitimately placed.
5123
5124 Note: kevinb/2004-01-19: On FR-V, if this adjustment is not
5125 made, GDB will enter an infinite loop when stepping through
5126 optimized code consisting of VLIW instructions which contain
5127 subinstructions corresponding to different source lines. On
5128 FR-V, it's not permitted to place a breakpoint on any but the
5129 first subinstruction of a VLIW instruction. When a breakpoint is
5130 set, GDB will adjust the breakpoint address to the beginning of
5131 the VLIW instruction. Thus, we need to make the corresponding
5132 adjustment here when computing the stop address. */
5133
5134 if (gdbarch_adjust_breakpoint_address_p (gdbarch))
5135 {
5136 ecs->stop_func_start
5137 = gdbarch_adjust_breakpoint_address (gdbarch,
5138 ecs->stop_func_start);
5139 }
5140
5141 if (ecs->stop_func_start == stop_pc)
5142 {
5143 /* We are already there: stop now. */
5144 ecs->event_thread->control.stop_step = 1;
5145 print_end_stepping_range_reason ();
5146 stop_stepping (ecs);
5147 return;
5148 }
5149 else
5150 {
5151 /* Put the step-breakpoint there and go until there. */
5152 init_sal (&sr_sal); /* initialize to zeroes */
5153 sr_sal.pc = ecs->stop_func_start;
5154 sr_sal.section = find_pc_overlay (ecs->stop_func_start);
5155 sr_sal.pspace = get_frame_program_space (get_current_frame ());
5156
5157 /* Do not specify what the fp should be when we stop since on
5158 some machines the prologue is where the new fp value is
5159 established. */
5160 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id);
5161
5162 /* And make sure stepping stops right away then. */
5163 ecs->event_thread->control.step_range_end
5164 = ecs->event_thread->control.step_range_start;
5165 }
5166 keep_going (ecs);
5167 }
5168
5169 /* Inferior has stepped backward into a subroutine call with source
5170 code that we should not step over. Do step to the beginning of the
5171 last line of code in it. */
5172
5173 static void
5174 handle_step_into_function_backward (struct gdbarch *gdbarch,
5175 struct execution_control_state *ecs)
5176 {
5177 struct symtab *s;
5178 struct symtab_and_line stop_func_sal;
5179
5180 s = find_pc_symtab (stop_pc);
5181 if (s && s->language != language_asm)
5182 ecs->stop_func_start = gdbarch_skip_prologue (gdbarch,
5183 ecs->stop_func_start);
5184
5185 stop_func_sal = find_pc_line (stop_pc, 0);
5186
5187 /* OK, we're just going to keep stepping here. */
5188 if (stop_func_sal.pc == stop_pc)
5189 {
5190 /* We're there already. Just stop stepping now. */
5191 ecs->event_thread->control.stop_step = 1;
5192 print_end_stepping_range_reason ();
5193 stop_stepping (ecs);
5194 }
5195 else
5196 {
5197 /* Else just reset the step range and keep going.
5198 No step-resume breakpoint, they don't work for
5199 epilogues, which can have multiple entry paths. */
5200 ecs->event_thread->control.step_range_start = stop_func_sal.pc;
5201 ecs->event_thread->control.step_range_end = stop_func_sal.end;
5202 keep_going (ecs);
5203 }
5204 return;
5205 }
5206
5207 /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID.
5208 This is used to both functions and to skip over code. */
5209
5210 static void
5211 insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch,
5212 struct symtab_and_line sr_sal,
5213 struct frame_id sr_id)
5214 {
5215 /* There should never be more than one step-resume or longjmp-resume
5216 breakpoint per thread, so we should never be setting a new
5217 step_resume_breakpoint when one is already active. */
5218 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5219
5220 if (debug_infrun)
5221 fprintf_unfiltered (gdb_stdlog,
5222 "infrun: inserting step-resume breakpoint at %s\n",
5223 paddress (gdbarch, sr_sal.pc));
5224
5225 inferior_thread ()->control.step_resume_breakpoint
5226 = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, bp_step_resume);
5227 }
5228
5229 /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used
5230 to skip a potential signal handler.
5231
5232 This is called with the interrupted function's frame. The signal
5233 handler, when it returns, will resume the interrupted function at
5234 RETURN_FRAME.pc. */
5235
5236 static void
5237 insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame)
5238 {
5239 struct symtab_and_line sr_sal;
5240 struct gdbarch *gdbarch;
5241
5242 gdb_assert (return_frame != NULL);
5243 init_sal (&sr_sal); /* initialize to zeros */
5244
5245 gdbarch = get_frame_arch (return_frame);
5246 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame));
5247 sr_sal.section = find_pc_overlay (sr_sal.pc);
5248 sr_sal.pspace = get_frame_program_space (return_frame);
5249
5250 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5251 get_stack_frame_id (return_frame));
5252 }
5253
5254 /* Similar to insert_step_resume_breakpoint_at_frame, except
5255 but a breakpoint at the previous frame's PC. This is used to
5256 skip a function after stepping into it (for "next" or if the called
5257 function has no debugging information).
5258
5259 The current function has almost always been reached by single
5260 stepping a call or return instruction. NEXT_FRAME belongs to the
5261 current function, and the breakpoint will be set at the caller's
5262 resume address.
5263
5264 This is a separate function rather than reusing
5265 insert_step_resume_breakpoint_at_frame in order to avoid
5266 get_prev_frame, which may stop prematurely (see the implementation
5267 of frame_unwind_caller_id for an example). */
5268
5269 static void
5270 insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame)
5271 {
5272 struct symtab_and_line sr_sal;
5273 struct gdbarch *gdbarch;
5274
5275 /* We shouldn't have gotten here if we don't know where the call site
5276 is. */
5277 gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame)));
5278
5279 init_sal (&sr_sal); /* initialize to zeros */
5280
5281 gdbarch = frame_unwind_caller_arch (next_frame);
5282 sr_sal.pc = gdbarch_addr_bits_remove (gdbarch,
5283 frame_unwind_caller_pc (next_frame));
5284 sr_sal.section = find_pc_overlay (sr_sal.pc);
5285 sr_sal.pspace = frame_unwind_program_space (next_frame);
5286
5287 insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal,
5288 frame_unwind_caller_id (next_frame));
5289 }
5290
5291 /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a
5292 new breakpoint at the target of a jmp_buf. The handling of
5293 longjmp-resume uses the same mechanisms used for handling
5294 "step-resume" breakpoints. */
5295
5296 static void
5297 insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc)
5298 {
5299 /* There should never be more than one step-resume or longjmp-resume
5300 breakpoint per thread, so we should never be setting a new
5301 longjmp_resume_breakpoint when one is already active. */
5302 gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL);
5303
5304 if (debug_infrun)
5305 fprintf_unfiltered (gdb_stdlog,
5306 "infrun: inserting longjmp-resume breakpoint at %s\n",
5307 paddress (gdbarch, pc));
5308
5309 inferior_thread ()->control.step_resume_breakpoint =
5310 set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume);
5311 }
5312
5313 /* Insert an exception resume breakpoint. TP is the thread throwing
5314 the exception. The block B is the block of the unwinder debug hook
5315 function. FRAME is the frame corresponding to the call to this
5316 function. SYM is the symbol of the function argument holding the
5317 target PC of the exception. */
5318
5319 static void
5320 insert_exception_resume_breakpoint (struct thread_info *tp,
5321 struct block *b,
5322 struct frame_info *frame,
5323 struct symbol *sym)
5324 {
5325 struct gdb_exception e;
5326
5327 /* We want to ignore errors here. */
5328 TRY_CATCH (e, RETURN_MASK_ERROR)
5329 {
5330 struct symbol *vsym;
5331 struct value *value;
5332 CORE_ADDR handler;
5333 struct breakpoint *bp;
5334
5335 vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
5336 value = read_var_value (vsym, frame);
5337 /* If the value was optimized out, revert to the old behavior. */
5338 if (! value_optimized_out (value))
5339 {
5340 handler = value_as_address (value);
5341
5342 if (debug_infrun)
5343 fprintf_unfiltered (gdb_stdlog,
5344 "infrun: exception resume at %lx\n",
5345 (unsigned long) handler);
5346
5347 bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
5348 handler, bp_exception_resume);
5349 bp->thread = tp->num;
5350 inferior_thread ()->control.exception_resume_breakpoint = bp;
5351 }
5352 }
5353 }
5354
5355 /* This is called when an exception has been intercepted. Check to
5356 see whether the exception's destination is of interest, and if so,
5357 set an exception resume breakpoint there. */
5358
5359 static void
5360 check_exception_resume (struct execution_control_state *ecs,
5361 struct frame_info *frame, struct symbol *func)
5362 {
5363 struct gdb_exception e;
5364
5365 TRY_CATCH (e, RETURN_MASK_ERROR)
5366 {
5367 struct block *b;
5368 struct dict_iterator iter;
5369 struct symbol *sym;
5370 int argno = 0;
5371
5372 /* The exception breakpoint is a thread-specific breakpoint on
5373 the unwinder's debug hook, declared as:
5374
5375 void _Unwind_DebugHook (void *cfa, void *handler);
5376
5377 The CFA argument indicates the frame to which control is
5378 about to be transferred. HANDLER is the destination PC.
5379
5380 We ignore the CFA and set a temporary breakpoint at HANDLER.
5381 This is not extremely efficient but it avoids issues in gdb
5382 with computing the DWARF CFA, and it also works even in weird
5383 cases such as throwing an exception from inside a signal
5384 handler. */
5385
5386 b = SYMBOL_BLOCK_VALUE (func);
5387 ALL_BLOCK_SYMBOLS (b, iter, sym)
5388 {
5389 if (!SYMBOL_IS_ARGUMENT (sym))
5390 continue;
5391
5392 if (argno == 0)
5393 ++argno;
5394 else
5395 {
5396 insert_exception_resume_breakpoint (ecs->event_thread,
5397 b, frame, sym);
5398 break;
5399 }
5400 }
5401 }
5402 }
5403
5404 static void
5405 stop_stepping (struct execution_control_state *ecs)
5406 {
5407 if (debug_infrun)
5408 fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n");
5409
5410 /* Let callers know we don't want to wait for the inferior anymore. */
5411 ecs->wait_some_more = 0;
5412 }
5413
5414 /* This function handles various cases where we need to continue
5415 waiting for the inferior. */
5416 /* (Used to be the keep_going: label in the old wait_for_inferior). */
5417
5418 static void
5419 keep_going (struct execution_control_state *ecs)
5420 {
5421 /* Make sure normal_stop is called if we get a QUIT handled before
5422 reaching resume. */
5423 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
5424
5425 /* Save the pc before execution, to compare with pc after stop. */
5426 ecs->event_thread->prev_pc
5427 = regcache_read_pc (get_thread_regcache (ecs->ptid));
5428
5429 /* If we did not do break;, it means we should keep running the
5430 inferior and not return to debugger. */
5431
5432 if (ecs->event_thread->control.trap_expected
5433 && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP)
5434 {
5435 /* We took a signal (which we are supposed to pass through to
5436 the inferior, else we'd not get here) and we haven't yet
5437 gotten our trap. Simply continue. */
5438
5439 discard_cleanups (old_cleanups);
5440 resume (currently_stepping (ecs->event_thread),
5441 ecs->event_thread->suspend.stop_signal);
5442 }
5443 else
5444 {
5445 /* Either the trap was not expected, but we are continuing
5446 anyway (the user asked that this signal be passed to the
5447 child)
5448 -- or --
5449 The signal was SIGTRAP, e.g. it was our signal, but we
5450 decided we should resume from it.
5451
5452 We're going to run this baby now!
5453
5454 Note that insert_breakpoints won't try to re-insert
5455 already inserted breakpoints. Therefore, we don't
5456 care if breakpoints were already inserted, or not. */
5457
5458 if (ecs->event_thread->stepping_over_breakpoint)
5459 {
5460 struct regcache *thread_regcache = get_thread_regcache (ecs->ptid);
5461
5462 if (!use_displaced_stepping (get_regcache_arch (thread_regcache)))
5463 /* Since we can't do a displaced step, we have to remove
5464 the breakpoint while we step it. To keep things
5465 simple, we remove them all. */
5466 remove_breakpoints ();
5467 }
5468 else
5469 {
5470 struct gdb_exception e;
5471
5472 /* Stop stepping when inserting breakpoints
5473 has failed. */
5474 TRY_CATCH (e, RETURN_MASK_ERROR)
5475 {
5476 insert_breakpoints ();
5477 }
5478 if (e.reason < 0)
5479 {
5480 exception_print (gdb_stderr, e);
5481 stop_stepping (ecs);
5482 return;
5483 }
5484 }
5485
5486 ecs->event_thread->control.trap_expected
5487 = ecs->event_thread->stepping_over_breakpoint;
5488
5489 /* Do not deliver SIGNAL_TRAP (except when the user explicitly
5490 specifies that such a signal should be delivered to the
5491 target program).
5492
5493 Typically, this would occure when a user is debugging a
5494 target monitor on a simulator: the target monitor sets a
5495 breakpoint; the simulator encounters this break-point and
5496 halts the simulation handing control to GDB; GDB, noteing
5497 that the break-point isn't valid, returns control back to the
5498 simulator; the simulator then delivers the hardware
5499 equivalent of a SIGNAL_TRAP to the program being debugged. */
5500
5501 if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP
5502 && !signal_program[ecs->event_thread->suspend.stop_signal])
5503 ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0;
5504
5505 discard_cleanups (old_cleanups);
5506 resume (currently_stepping (ecs->event_thread),
5507 ecs->event_thread->suspend.stop_signal);
5508 }
5509
5510 prepare_to_wait (ecs);
5511 }
5512
5513 /* This function normally comes after a resume, before
5514 handle_inferior_event exits. It takes care of any last bits of
5515 housekeeping, and sets the all-important wait_some_more flag. */
5516
5517 static void
5518 prepare_to_wait (struct execution_control_state *ecs)
5519 {
5520 if (debug_infrun)
5521 fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
5522
5523 /* This is the old end of the while loop. Let everybody know we
5524 want to wait for the inferior some more and get called again
5525 soon. */
5526 ecs->wait_some_more = 1;
5527 }
5528
5529 /* Several print_*_reason functions to print why the inferior has stopped.
5530 We always print something when the inferior exits, or receives a signal.
5531 The rest of the cases are dealt with later on in normal_stop and
5532 print_it_typical. Ideally there should be a call to one of these
5533 print_*_reason functions functions from handle_inferior_event each time
5534 stop_stepping is called. */
5535
5536 /* Print why the inferior has stopped.
5537 We are done with a step/next/si/ni command, print why the inferior has
5538 stopped. For now print nothing. Print a message only if not in the middle
5539 of doing a "step n" operation for n > 1. */
5540
5541 static void
5542 print_end_stepping_range_reason (void)
5543 {
5544 if ((!inferior_thread ()->step_multi
5545 || !inferior_thread ()->control.stop_step)
5546 && ui_out_is_mi_like_p (uiout))
5547 ui_out_field_string (uiout, "reason",
5548 async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE));
5549 }
5550
5551 /* The inferior was terminated by a signal, print why it stopped. */
5552
5553 static void
5554 print_signal_exited_reason (enum target_signal siggnal)
5555 {
5556 annotate_signalled ();
5557 if (ui_out_is_mi_like_p (uiout))
5558 ui_out_field_string
5559 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED));
5560 ui_out_text (uiout, "\nProgram terminated with signal ");
5561 annotate_signal_name ();
5562 ui_out_field_string (uiout, "signal-name",
5563 target_signal_to_name (siggnal));
5564 annotate_signal_name_end ();
5565 ui_out_text (uiout, ", ");
5566 annotate_signal_string ();
5567 ui_out_field_string (uiout, "signal-meaning",
5568 target_signal_to_string (siggnal));
5569 annotate_signal_string_end ();
5570 ui_out_text (uiout, ".\n");
5571 ui_out_text (uiout, "The program no longer exists.\n");
5572 }
5573
5574 /* The inferior program is finished, print why it stopped. */
5575
5576 static void
5577 print_exited_reason (int exitstatus)
5578 {
5579 struct inferior *inf = current_inferior ();
5580 const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid));
5581
5582 annotate_exited (exitstatus);
5583 if (exitstatus)
5584 {
5585 if (ui_out_is_mi_like_p (uiout))
5586 ui_out_field_string (uiout, "reason",
5587 async_reason_lookup (EXEC_ASYNC_EXITED));
5588 ui_out_text (uiout, "[Inferior ");
5589 ui_out_text (uiout, plongest (inf->num));
5590 ui_out_text (uiout, " (");
5591 ui_out_text (uiout, pidstr);
5592 ui_out_text (uiout, ") exited with code ");
5593 ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus);
5594 ui_out_text (uiout, "]\n");
5595 }
5596 else
5597 {
5598 if (ui_out_is_mi_like_p (uiout))
5599 ui_out_field_string
5600 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
5601 ui_out_text (uiout, "[Inferior ");
5602 ui_out_text (uiout, plongest (inf->num));
5603 ui_out_text (uiout, " (");
5604 ui_out_text (uiout, pidstr);
5605 ui_out_text (uiout, ") exited normally]\n");
5606 }
5607 /* Support the --return-child-result option. */
5608 return_child_result_value = exitstatus;
5609 }
5610
5611 /* Signal received, print why the inferior has stopped. The signal table
5612 tells us to print about it. */
5613
5614 static void
5615 print_signal_received_reason (enum target_signal siggnal)
5616 {
5617 annotate_signal ();
5618
5619 if (siggnal == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout))
5620 {
5621 struct thread_info *t = inferior_thread ();
5622
5623 ui_out_text (uiout, "\n[");
5624 ui_out_field_string (uiout, "thread-name",
5625 target_pid_to_str (t->ptid));
5626 ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num);
5627 ui_out_text (uiout, " stopped");
5628 }
5629 else
5630 {
5631 ui_out_text (uiout, "\nProgram received signal ");
5632 annotate_signal_name ();
5633 if (ui_out_is_mi_like_p (uiout))
5634 ui_out_field_string
5635 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED));
5636 ui_out_field_string (uiout, "signal-name",
5637 target_signal_to_name (siggnal));
5638 annotate_signal_name_end ();
5639 ui_out_text (uiout, ", ");
5640 annotate_signal_string ();
5641 ui_out_field_string (uiout, "signal-meaning",
5642 target_signal_to_string (siggnal));
5643 annotate_signal_string_end ();
5644 }
5645 ui_out_text (uiout, ".\n");
5646 }
5647
5648 /* Reverse execution: target ran out of history info, print why the inferior
5649 has stopped. */
5650
5651 static void
5652 print_no_history_reason (void)
5653 {
5654 ui_out_text (uiout, "\nNo more reverse-execution history.\n");
5655 }
5656
5657 /* Here to return control to GDB when the inferior stops for real.
5658 Print appropriate messages, remove breakpoints, give terminal our modes.
5659
5660 STOP_PRINT_FRAME nonzero means print the executing frame
5661 (pc, function, args, file, line number and line text).
5662 BREAKPOINTS_FAILED nonzero means stop was due to error
5663 attempting to insert breakpoints. */
5664
5665 void
5666 normal_stop (void)
5667 {
5668 struct target_waitstatus last;
5669 ptid_t last_ptid;
5670 struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
5671
5672 get_last_target_status (&last_ptid, &last);
5673
5674 /* If an exception is thrown from this point on, make sure to
5675 propagate GDB's knowledge of the executing state to the
5676 frontend/user running state. A QUIT is an easy exception to see
5677 here, so do this before any filtered output. */
5678 if (!non_stop)
5679 make_cleanup (finish_thread_state_cleanup, &minus_one_ptid);
5680 else if (last.kind != TARGET_WAITKIND_SIGNALLED
5681 && last.kind != TARGET_WAITKIND_EXITED)
5682 make_cleanup (finish_thread_state_cleanup, &inferior_ptid);
5683
5684 /* In non-stop mode, we don't want GDB to switch threads behind the
5685 user's back, to avoid races where the user is typing a command to
5686 apply to thread x, but GDB switches to thread y before the user
5687 finishes entering the command. */
5688
5689 /* As with the notification of thread events, we want to delay
5690 notifying the user that we've switched thread context until
5691 the inferior actually stops.
5692
5693 There's no point in saying anything if the inferior has exited.
5694 Note that SIGNALLED here means "exited with a signal", not
5695 "received a signal". */
5696 if (!non_stop
5697 && !ptid_equal (previous_inferior_ptid, inferior_ptid)
5698 && target_has_execution
5699 && last.kind != TARGET_WAITKIND_SIGNALLED
5700 && last.kind != TARGET_WAITKIND_EXITED)
5701 {
5702 target_terminal_ours_for_output ();
5703 printf_filtered (_("[Switching to %s]\n"),
5704 target_pid_to_str (inferior_ptid));
5705 annotate_thread_changed ();
5706 previous_inferior_ptid = inferior_ptid;
5707 }
5708
5709 if (!breakpoints_always_inserted_mode () && target_has_execution)
5710 {
5711 if (remove_breakpoints ())
5712 {
5713 target_terminal_ours_for_output ();
5714 printf_filtered (_("Cannot remove breakpoints because "
5715 "program is no longer writable.\nFurther "
5716 "execution is probably impossible.\n"));
5717 }
5718 }
5719
5720 /* If an auto-display called a function and that got a signal,
5721 delete that auto-display to avoid an infinite recursion. */
5722
5723 if (stopped_by_random_signal)
5724 disable_current_display ();
5725
5726 /* Don't print a message if in the middle of doing a "step n"
5727 operation for n > 1 */
5728 if (target_has_execution
5729 && last.kind != TARGET_WAITKIND_SIGNALLED
5730 && last.kind != TARGET_WAITKIND_EXITED
5731 && inferior_thread ()->step_multi
5732 && inferior_thread ()->control.stop_step)
5733 goto done;
5734
5735 target_terminal_ours ();
5736
5737 /* Set the current source location. This will also happen if we
5738 display the frame below, but the current SAL will be incorrect
5739 during a user hook-stop function. */
5740 if (has_stack_frames () && !stop_stack_dummy)
5741 set_current_sal_from_frame (get_current_frame (), 1);
5742
5743 /* Let the user/frontend see the threads as stopped. */
5744 do_cleanups (old_chain);
5745
5746 /* Look up the hook_stop and run it (CLI internally handles problem
5747 of stop_command's pre-hook not existing). */
5748 if (stop_command)
5749 catch_errors (hook_stop_stub, stop_command,
5750 "Error while running hook_stop:\n", RETURN_MASK_ALL);
5751
5752 if (!has_stack_frames ())
5753 goto done;
5754
5755 if (last.kind == TARGET_WAITKIND_SIGNALLED
5756 || last.kind == TARGET_WAITKIND_EXITED)
5757 goto done;
5758
5759 /* Select innermost stack frame - i.e., current frame is frame 0,
5760 and current location is based on that.
5761 Don't do this on return from a stack dummy routine,
5762 or if the program has exited. */
5763
5764 if (!stop_stack_dummy)
5765 {
5766 select_frame (get_current_frame ());
5767
5768 /* Print current location without a level number, if
5769 we have changed functions or hit a breakpoint.
5770 Print source line if we have one.
5771 bpstat_print() contains the logic deciding in detail
5772 what to print, based on the event(s) that just occurred. */
5773
5774 /* If --batch-silent is enabled then there's no need to print the current
5775 source location, and to try risks causing an error message about
5776 missing source files. */
5777 if (stop_print_frame && !batch_silent)
5778 {
5779 int bpstat_ret;
5780 int source_flag;
5781 int do_frame_printing = 1;
5782 struct thread_info *tp = inferior_thread ();
5783
5784 bpstat_ret = bpstat_print (tp->control.stop_bpstat);
5785 switch (bpstat_ret)
5786 {
5787 case PRINT_UNKNOWN:
5788 /* If we had hit a shared library event breakpoint,
5789 bpstat_print would print out this message. If we hit
5790 an OS-level shared library event, do the same
5791 thing. */
5792 if (last.kind == TARGET_WAITKIND_LOADED)
5793 {
5794 printf_filtered (_("Stopped due to shared library event\n"));
5795 source_flag = SRC_LINE; /* something bogus */
5796 do_frame_printing = 0;
5797 break;
5798 }
5799
5800 /* FIXME: cagney/2002-12-01: Given that a frame ID does
5801 (or should) carry around the function and does (or
5802 should) use that when doing a frame comparison. */
5803 if (tp->control.stop_step
5804 && frame_id_eq (tp->control.step_frame_id,
5805 get_frame_id (get_current_frame ()))
5806 && step_start_function == find_pc_function (stop_pc))
5807 source_flag = SRC_LINE; /* Finished step, just
5808 print source line. */
5809 else
5810 source_flag = SRC_AND_LOC; /* Print location and
5811 source line. */
5812 break;
5813 case PRINT_SRC_AND_LOC:
5814 source_flag = SRC_AND_LOC; /* Print location and
5815 source line. */
5816 break;
5817 case PRINT_SRC_ONLY:
5818 source_flag = SRC_LINE;
5819 break;
5820 case PRINT_NOTHING:
5821 source_flag = SRC_LINE; /* something bogus */
5822 do_frame_printing = 0;
5823 break;
5824 default:
5825 internal_error (__FILE__, __LINE__, _("Unknown value."));
5826 }
5827
5828 /* The behavior of this routine with respect to the source
5829 flag is:
5830 SRC_LINE: Print only source line
5831 LOCATION: Print only location
5832 SRC_AND_LOC: Print location and source line. */
5833 if (do_frame_printing)
5834 print_stack_frame (get_selected_frame (NULL), 0, source_flag);
5835
5836 /* Display the auto-display expressions. */
5837 do_displays ();
5838 }
5839 }
5840
5841 /* Save the function value return registers, if we care.
5842 We might be about to restore their previous contents. */
5843 if (inferior_thread ()->control.proceed_to_finish)
5844 {
5845 /* This should not be necessary. */
5846 if (stop_registers)
5847 regcache_xfree (stop_registers);
5848
5849 /* NB: The copy goes through to the target picking up the value of
5850 all the registers. */
5851 stop_registers = regcache_dup (get_current_regcache ());
5852 }
5853
5854 if (stop_stack_dummy == STOP_STACK_DUMMY)
5855 {
5856 /* Pop the empty frame that contains the stack dummy.
5857 This also restores inferior state prior to the call
5858 (struct infcall_suspend_state). */
5859 struct frame_info *frame = get_current_frame ();
5860
5861 gdb_assert (get_frame_type (frame) == DUMMY_FRAME);
5862 frame_pop (frame);
5863 /* frame_pop() calls reinit_frame_cache as the last thing it
5864 does which means there's currently no selected frame. We
5865 don't need to re-establish a selected frame if the dummy call
5866 returns normally, that will be done by
5867 restore_infcall_control_state. However, we do have to handle
5868 the case where the dummy call is returning after being
5869 stopped (e.g. the dummy call previously hit a breakpoint).
5870 We can't know which case we have so just always re-establish
5871 a selected frame here. */
5872 select_frame (get_current_frame ());
5873 }
5874
5875 done:
5876 annotate_stopped ();
5877
5878 /* Suppress the stop observer if we're in the middle of:
5879
5880 - a step n (n > 1), as there still more steps to be done.
5881
5882 - a "finish" command, as the observer will be called in
5883 finish_command_continuation, so it can include the inferior
5884 function's return value.
5885
5886 - calling an inferior function, as we pretend we inferior didn't
5887 run at all. The return value of the call is handled by the
5888 expression evaluator, through call_function_by_hand. */
5889
5890 if (!target_has_execution
5891 || last.kind == TARGET_WAITKIND_SIGNALLED
5892 || last.kind == TARGET_WAITKIND_EXITED
5893 || (!inferior_thread ()->step_multi
5894 && !(inferior_thread ()->control.stop_bpstat
5895 && inferior_thread ()->control.proceed_to_finish)
5896 && !inferior_thread ()->control.in_infcall))
5897 {
5898 if (!ptid_equal (inferior_ptid, null_ptid))
5899 observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat,
5900 stop_print_frame);
5901 else
5902 observer_notify_normal_stop (NULL, stop_print_frame);
5903 }
5904
5905 if (target_has_execution)
5906 {
5907 if (last.kind != TARGET_WAITKIND_SIGNALLED
5908 && last.kind != TARGET_WAITKIND_EXITED)
5909 /* Delete the breakpoint we stopped at, if it wants to be deleted.
5910 Delete any breakpoint that is to be deleted at the next stop. */
5911 breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat);
5912 }
5913
5914 /* Try to get rid of automatically added inferiors that are no
5915 longer needed. Keeping those around slows down things linearly.
5916 Note that this never removes the current inferior. */
5917 prune_inferiors ();
5918 }
5919
5920 static int
5921 hook_stop_stub (void *cmd)
5922 {
5923 execute_cmd_pre_hook ((struct cmd_list_element *) cmd);
5924 return (0);
5925 }
5926 \f
5927 int
5928 signal_stop_state (int signo)
5929 {
5930 return signal_stop[signo];
5931 }
5932
5933 int
5934 signal_print_state (int signo)
5935 {
5936 return signal_print[signo];
5937 }
5938
5939 int
5940 signal_pass_state (int signo)
5941 {
5942 return signal_program[signo];
5943 }
5944
5945 static void
5946 signal_cache_update (int signo)
5947 {
5948 if (signo == -1)
5949 {
5950 for (signo = 0; signo < (int) TARGET_SIGNAL_LAST; signo++)
5951 signal_cache_update (signo);
5952
5953 return;
5954 }
5955
5956 signal_pass[signo] = (signal_stop[signo] == 0
5957 && signal_print[signo] == 0
5958 && signal_program[signo] == 1);
5959 }
5960
5961 int
5962 signal_stop_update (int signo, int state)
5963 {
5964 int ret = signal_stop[signo];
5965
5966 signal_stop[signo] = state;
5967 signal_cache_update (signo);
5968 return ret;
5969 }
5970
5971 int
5972 signal_print_update (int signo, int state)
5973 {
5974 int ret = signal_print[signo];
5975
5976 signal_print[signo] = state;
5977 signal_cache_update (signo);
5978 return ret;
5979 }
5980
5981 int
5982 signal_pass_update (int signo, int state)
5983 {
5984 int ret = signal_program[signo];
5985
5986 signal_program[signo] = state;
5987 signal_cache_update (signo);
5988 return ret;
5989 }
5990
5991 static void
5992 sig_print_header (void)
5993 {
5994 printf_filtered (_("Signal Stop\tPrint\tPass "
5995 "to program\tDescription\n"));
5996 }
5997
5998 static void
5999 sig_print_info (enum target_signal oursig)
6000 {
6001 const char *name = target_signal_to_name (oursig);
6002 int name_padding = 13 - strlen (name);
6003
6004 if (name_padding <= 0)
6005 name_padding = 0;
6006
6007 printf_filtered ("%s", name);
6008 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
6009 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
6010 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
6011 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
6012 printf_filtered ("%s\n", target_signal_to_string (oursig));
6013 }
6014
6015 /* Specify how various signals in the inferior should be handled. */
6016
6017 static void
6018 handle_command (char *args, int from_tty)
6019 {
6020 char **argv;
6021 int digits, wordlen;
6022 int sigfirst, signum, siglast;
6023 enum target_signal oursig;
6024 int allsigs;
6025 int nsigs;
6026 unsigned char *sigs;
6027 struct cleanup *old_chain;
6028
6029 if (args == NULL)
6030 {
6031 error_no_arg (_("signal to handle"));
6032 }
6033
6034 /* Allocate and zero an array of flags for which signals to handle. */
6035
6036 nsigs = (int) TARGET_SIGNAL_LAST;
6037 sigs = (unsigned char *) alloca (nsigs);
6038 memset (sigs, 0, nsigs);
6039
6040 /* Break the command line up into args. */
6041
6042 argv = gdb_buildargv (args);
6043 old_chain = make_cleanup_freeargv (argv);
6044
6045 /* Walk through the args, looking for signal oursigs, signal names, and
6046 actions. Signal numbers and signal names may be interspersed with
6047 actions, with the actions being performed for all signals cumulatively
6048 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
6049
6050 while (*argv != NULL)
6051 {
6052 wordlen = strlen (*argv);
6053 for (digits = 0; isdigit ((*argv)[digits]); digits++)
6054 {;
6055 }
6056 allsigs = 0;
6057 sigfirst = siglast = -1;
6058
6059 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
6060 {
6061 /* Apply action to all signals except those used by the
6062 debugger. Silently skip those. */
6063 allsigs = 1;
6064 sigfirst = 0;
6065 siglast = nsigs - 1;
6066 }
6067 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
6068 {
6069 SET_SIGS (nsigs, sigs, signal_stop);
6070 SET_SIGS (nsigs, sigs, signal_print);
6071 }
6072 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
6073 {
6074 UNSET_SIGS (nsigs, sigs, signal_program);
6075 }
6076 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
6077 {
6078 SET_SIGS (nsigs, sigs, signal_print);
6079 }
6080 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
6081 {
6082 SET_SIGS (nsigs, sigs, signal_program);
6083 }
6084 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
6085 {
6086 UNSET_SIGS (nsigs, sigs, signal_stop);
6087 }
6088 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
6089 {
6090 SET_SIGS (nsigs, sigs, signal_program);
6091 }
6092 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
6093 {
6094 UNSET_SIGS (nsigs, sigs, signal_print);
6095 UNSET_SIGS (nsigs, sigs, signal_stop);
6096 }
6097 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
6098 {
6099 UNSET_SIGS (nsigs, sigs, signal_program);
6100 }
6101 else if (digits > 0)
6102 {
6103 /* It is numeric. The numeric signal refers to our own
6104 internal signal numbering from target.h, not to host/target
6105 signal number. This is a feature; users really should be
6106 using symbolic names anyway, and the common ones like
6107 SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */
6108
6109 sigfirst = siglast = (int)
6110 target_signal_from_command (atoi (*argv));
6111 if ((*argv)[digits] == '-')
6112 {
6113 siglast = (int)
6114 target_signal_from_command (atoi ((*argv) + digits + 1));
6115 }
6116 if (sigfirst > siglast)
6117 {
6118 /* Bet he didn't figure we'd think of this case... */
6119 signum = sigfirst;
6120 sigfirst = siglast;
6121 siglast = signum;
6122 }
6123 }
6124 else
6125 {
6126 oursig = target_signal_from_name (*argv);
6127 if (oursig != TARGET_SIGNAL_UNKNOWN)
6128 {
6129 sigfirst = siglast = (int) oursig;
6130 }
6131 else
6132 {
6133 /* Not a number and not a recognized flag word => complain. */
6134 error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv);
6135 }
6136 }
6137
6138 /* If any signal numbers or symbol names were found, set flags for
6139 which signals to apply actions to. */
6140
6141 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
6142 {
6143 switch ((enum target_signal) signum)
6144 {
6145 case TARGET_SIGNAL_TRAP:
6146 case TARGET_SIGNAL_INT:
6147 if (!allsigs && !sigs[signum])
6148 {
6149 if (query (_("%s is used by the debugger.\n\
6150 Are you sure you want to change it? "),
6151 target_signal_to_name ((enum target_signal) signum)))
6152 {
6153 sigs[signum] = 1;
6154 }
6155 else
6156 {
6157 printf_unfiltered (_("Not confirmed, unchanged.\n"));
6158 gdb_flush (gdb_stdout);
6159 }
6160 }
6161 break;
6162 case TARGET_SIGNAL_0:
6163 case TARGET_SIGNAL_DEFAULT:
6164 case TARGET_SIGNAL_UNKNOWN:
6165 /* Make sure that "all" doesn't print these. */
6166 break;
6167 default:
6168 sigs[signum] = 1;
6169 break;
6170 }
6171 }
6172
6173 argv++;
6174 }
6175
6176 for (signum = 0; signum < nsigs; signum++)
6177 if (sigs[signum])
6178 {
6179 signal_cache_update (-1);
6180 target_pass_signals ((int) TARGET_SIGNAL_LAST, signal_pass);
6181
6182 if (from_tty)
6183 {
6184 /* Show the results. */
6185 sig_print_header ();
6186 for (; signum < nsigs; signum++)
6187 if (sigs[signum])
6188 sig_print_info (signum);
6189 }
6190
6191 break;
6192 }
6193
6194 do_cleanups (old_chain);
6195 }
6196
6197 static void
6198 xdb_handle_command (char *args, int from_tty)
6199 {
6200 char **argv;
6201 struct cleanup *old_chain;
6202
6203 if (args == NULL)
6204 error_no_arg (_("xdb command"));
6205
6206 /* Break the command line up into args. */
6207
6208 argv = gdb_buildargv (args);
6209 old_chain = make_cleanup_freeargv (argv);
6210 if (argv[1] != (char *) NULL)
6211 {
6212 char *argBuf;
6213 int bufLen;
6214
6215 bufLen = strlen (argv[0]) + 20;
6216 argBuf = (char *) xmalloc (bufLen);
6217 if (argBuf)
6218 {
6219 int validFlag = 1;
6220 enum target_signal oursig;
6221
6222 oursig = target_signal_from_name (argv[0]);
6223 memset (argBuf, 0, bufLen);
6224 if (strcmp (argv[1], "Q") == 0)
6225 sprintf (argBuf, "%s %s", argv[0], "noprint");
6226 else
6227 {
6228 if (strcmp (argv[1], "s") == 0)
6229 {
6230 if (!signal_stop[oursig])
6231 sprintf (argBuf, "%s %s", argv[0], "stop");
6232 else
6233 sprintf (argBuf, "%s %s", argv[0], "nostop");
6234 }
6235 else if (strcmp (argv[1], "i") == 0)
6236 {
6237 if (!signal_program[oursig])
6238 sprintf (argBuf, "%s %s", argv[0], "pass");
6239 else
6240 sprintf (argBuf, "%s %s", argv[0], "nopass");
6241 }
6242 else if (strcmp (argv[1], "r") == 0)
6243 {
6244 if (!signal_print[oursig])
6245 sprintf (argBuf, "%s %s", argv[0], "print");
6246 else
6247 sprintf (argBuf, "%s %s", argv[0], "noprint");
6248 }
6249 else
6250 validFlag = 0;
6251 }
6252 if (validFlag)
6253 handle_command (argBuf, from_tty);
6254 else
6255 printf_filtered (_("Invalid signal handling flag.\n"));
6256 if (argBuf)
6257 xfree (argBuf);
6258 }
6259 }
6260 do_cleanups (old_chain);
6261 }
6262
6263 /* Print current contents of the tables set by the handle command.
6264 It is possible we should just be printing signals actually used
6265 by the current target (but for things to work right when switching
6266 targets, all signals should be in the signal tables). */
6267
6268 static void
6269 signals_info (char *signum_exp, int from_tty)
6270 {
6271 enum target_signal oursig;
6272
6273 sig_print_header ();
6274
6275 if (signum_exp)
6276 {
6277 /* First see if this is a symbol name. */
6278 oursig = target_signal_from_name (signum_exp);
6279 if (oursig == TARGET_SIGNAL_UNKNOWN)
6280 {
6281 /* No, try numeric. */
6282 oursig =
6283 target_signal_from_command (parse_and_eval_long (signum_exp));
6284 }
6285 sig_print_info (oursig);
6286 return;
6287 }
6288
6289 printf_filtered ("\n");
6290 /* These ugly casts brought to you by the native VAX compiler. */
6291 for (oursig = TARGET_SIGNAL_FIRST;
6292 (int) oursig < (int) TARGET_SIGNAL_LAST;
6293 oursig = (enum target_signal) ((int) oursig + 1))
6294 {
6295 QUIT;
6296
6297 if (oursig != TARGET_SIGNAL_UNKNOWN
6298 && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0)
6299 sig_print_info (oursig);
6300 }
6301
6302 printf_filtered (_("\nUse the \"handle\" command "
6303 "to change these tables.\n"));
6304 }
6305
6306 /* The $_siginfo convenience variable is a bit special. We don't know
6307 for sure the type of the value until we actually have a chance to
6308 fetch the data. The type can change depending on gdbarch, so it is
6309 also dependent on which thread you have selected.
6310
6311 1. making $_siginfo be an internalvar that creates a new value on
6312 access.
6313
6314 2. making the value of $_siginfo be an lval_computed value. */
6315
6316 /* This function implements the lval_computed support for reading a
6317 $_siginfo value. */
6318
6319 static void
6320 siginfo_value_read (struct value *v)
6321 {
6322 LONGEST transferred;
6323
6324 transferred =
6325 target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO,
6326 NULL,
6327 value_contents_all_raw (v),
6328 value_offset (v),
6329 TYPE_LENGTH (value_type (v)));
6330
6331 if (transferred != TYPE_LENGTH (value_type (v)))
6332 error (_("Unable to read siginfo"));
6333 }
6334
6335 /* This function implements the lval_computed support for writing a
6336 $_siginfo value. */
6337
6338 static void
6339 siginfo_value_write (struct value *v, struct value *fromval)
6340 {
6341 LONGEST transferred;
6342
6343 transferred = target_write (&current_target,
6344 TARGET_OBJECT_SIGNAL_INFO,
6345 NULL,
6346 value_contents_all_raw (fromval),
6347 value_offset (v),
6348 TYPE_LENGTH (value_type (fromval)));
6349
6350 if (transferred != TYPE_LENGTH (value_type (fromval)))
6351 error (_("Unable to write siginfo"));
6352 }
6353
6354 static struct lval_funcs siginfo_value_funcs =
6355 {
6356 siginfo_value_read,
6357 siginfo_value_write
6358 };
6359
6360 /* Return a new value with the correct type for the siginfo object of
6361 the current thread using architecture GDBARCH. Return a void value
6362 if there's no object available. */
6363
6364 static struct value *
6365 siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var)
6366 {
6367 if (target_has_stack
6368 && !ptid_equal (inferior_ptid, null_ptid)
6369 && gdbarch_get_siginfo_type_p (gdbarch))
6370 {
6371 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6372
6373 return allocate_computed_value (type, &siginfo_value_funcs, NULL);
6374 }
6375
6376 return allocate_value (builtin_type (gdbarch)->builtin_void);
6377 }
6378
6379 \f
6380 /* infcall_suspend_state contains state about the program itself like its
6381 registers and any signal it received when it last stopped.
6382 This state must be restored regardless of how the inferior function call
6383 ends (either successfully, or after it hits a breakpoint or signal)
6384 if the program is to properly continue where it left off. */
6385
6386 struct infcall_suspend_state
6387 {
6388 struct thread_suspend_state thread_suspend;
6389 struct inferior_suspend_state inferior_suspend;
6390
6391 /* Other fields: */
6392 CORE_ADDR stop_pc;
6393 struct regcache *registers;
6394
6395 /* Format of SIGINFO_DATA or NULL if it is not present. */
6396 struct gdbarch *siginfo_gdbarch;
6397
6398 /* The inferior format depends on SIGINFO_GDBARCH and it has a length of
6399 TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the
6400 content would be invalid. */
6401 gdb_byte *siginfo_data;
6402 };
6403
6404 struct infcall_suspend_state *
6405 save_infcall_suspend_state (void)
6406 {
6407 struct infcall_suspend_state *inf_state;
6408 struct thread_info *tp = inferior_thread ();
6409 struct inferior *inf = current_inferior ();
6410 struct regcache *regcache = get_current_regcache ();
6411 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6412 gdb_byte *siginfo_data = NULL;
6413
6414 if (gdbarch_get_siginfo_type_p (gdbarch))
6415 {
6416 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6417 size_t len = TYPE_LENGTH (type);
6418 struct cleanup *back_to;
6419
6420 siginfo_data = xmalloc (len);
6421 back_to = make_cleanup (xfree, siginfo_data);
6422
6423 if (target_read (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6424 siginfo_data, 0, len) == len)
6425 discard_cleanups (back_to);
6426 else
6427 {
6428 /* Errors ignored. */
6429 do_cleanups (back_to);
6430 siginfo_data = NULL;
6431 }
6432 }
6433
6434 inf_state = XZALLOC (struct infcall_suspend_state);
6435
6436 if (siginfo_data)
6437 {
6438 inf_state->siginfo_gdbarch = gdbarch;
6439 inf_state->siginfo_data = siginfo_data;
6440 }
6441
6442 inf_state->thread_suspend = tp->suspend;
6443 inf_state->inferior_suspend = inf->suspend;
6444
6445 /* run_inferior_call will not use the signal due to its `proceed' call with
6446 TARGET_SIGNAL_0 anyway. */
6447 tp->suspend.stop_signal = TARGET_SIGNAL_0;
6448
6449 inf_state->stop_pc = stop_pc;
6450
6451 inf_state->registers = regcache_dup (regcache);
6452
6453 return inf_state;
6454 }
6455
6456 /* Restore inferior session state to INF_STATE. */
6457
6458 void
6459 restore_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6460 {
6461 struct thread_info *tp = inferior_thread ();
6462 struct inferior *inf = current_inferior ();
6463 struct regcache *regcache = get_current_regcache ();
6464 struct gdbarch *gdbarch = get_regcache_arch (regcache);
6465
6466 tp->suspend = inf_state->thread_suspend;
6467 inf->suspend = inf_state->inferior_suspend;
6468
6469 stop_pc = inf_state->stop_pc;
6470
6471 if (inf_state->siginfo_gdbarch == gdbarch)
6472 {
6473 struct type *type = gdbarch_get_siginfo_type (gdbarch);
6474 size_t len = TYPE_LENGTH (type);
6475
6476 /* Errors ignored. */
6477 target_write (&current_target, TARGET_OBJECT_SIGNAL_INFO, NULL,
6478 inf_state->siginfo_data, 0, len);
6479 }
6480
6481 /* The inferior can be gone if the user types "print exit(0)"
6482 (and perhaps other times). */
6483 if (target_has_execution)
6484 /* NB: The register write goes through to the target. */
6485 regcache_cpy (regcache, inf_state->registers);
6486
6487 discard_infcall_suspend_state (inf_state);
6488 }
6489
6490 static void
6491 do_restore_infcall_suspend_state_cleanup (void *state)
6492 {
6493 restore_infcall_suspend_state (state);
6494 }
6495
6496 struct cleanup *
6497 make_cleanup_restore_infcall_suspend_state
6498 (struct infcall_suspend_state *inf_state)
6499 {
6500 return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state);
6501 }
6502
6503 void
6504 discard_infcall_suspend_state (struct infcall_suspend_state *inf_state)
6505 {
6506 regcache_xfree (inf_state->registers);
6507 xfree (inf_state->siginfo_data);
6508 xfree (inf_state);
6509 }
6510
6511 struct regcache *
6512 get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state)
6513 {
6514 return inf_state->registers;
6515 }
6516
6517 /* infcall_control_state contains state regarding gdb's control of the
6518 inferior itself like stepping control. It also contains session state like
6519 the user's currently selected frame. */
6520
6521 struct infcall_control_state
6522 {
6523 struct thread_control_state thread_control;
6524 struct inferior_control_state inferior_control;
6525
6526 /* Other fields: */
6527 enum stop_stack_kind stop_stack_dummy;
6528 int stopped_by_random_signal;
6529 int stop_after_trap;
6530
6531 /* ID if the selected frame when the inferior function call was made. */
6532 struct frame_id selected_frame_id;
6533 };
6534
6535 /* Save all of the information associated with the inferior<==>gdb
6536 connection. */
6537
6538 struct infcall_control_state *
6539 save_infcall_control_state (void)
6540 {
6541 struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status));
6542 struct thread_info *tp = inferior_thread ();
6543 struct inferior *inf = current_inferior ();
6544
6545 inf_status->thread_control = tp->control;
6546 inf_status->inferior_control = inf->control;
6547
6548 tp->control.step_resume_breakpoint = NULL;
6549 tp->control.exception_resume_breakpoint = NULL;
6550
6551 /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of
6552 chain. If caller's caller is walking the chain, they'll be happier if we
6553 hand them back the original chain when restore_infcall_control_state is
6554 called. */
6555 tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat);
6556
6557 /* Other fields: */
6558 inf_status->stop_stack_dummy = stop_stack_dummy;
6559 inf_status->stopped_by_random_signal = stopped_by_random_signal;
6560 inf_status->stop_after_trap = stop_after_trap;
6561
6562 inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL));
6563
6564 return inf_status;
6565 }
6566
6567 static int
6568 restore_selected_frame (void *args)
6569 {
6570 struct frame_id *fid = (struct frame_id *) args;
6571 struct frame_info *frame;
6572
6573 frame = frame_find_by_id (*fid);
6574
6575 /* If inf_status->selected_frame_id is NULL, there was no previously
6576 selected frame. */
6577 if (frame == NULL)
6578 {
6579 warning (_("Unable to restore previously selected frame."));
6580 return 0;
6581 }
6582
6583 select_frame (frame);
6584
6585 return (1);
6586 }
6587
6588 /* Restore inferior session state to INF_STATUS. */
6589
6590 void
6591 restore_infcall_control_state (struct infcall_control_state *inf_status)
6592 {
6593 struct thread_info *tp = inferior_thread ();
6594 struct inferior *inf = current_inferior ();
6595
6596 if (tp->control.step_resume_breakpoint)
6597 tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop;
6598
6599 if (tp->control.exception_resume_breakpoint)
6600 tp->control.exception_resume_breakpoint->disposition
6601 = disp_del_at_next_stop;
6602
6603 /* Handle the bpstat_copy of the chain. */
6604 bpstat_clear (&tp->control.stop_bpstat);
6605
6606 tp->control = inf_status->thread_control;
6607 inf->control = inf_status->inferior_control;
6608
6609 /* Other fields: */
6610 stop_stack_dummy = inf_status->stop_stack_dummy;
6611 stopped_by_random_signal = inf_status->stopped_by_random_signal;
6612 stop_after_trap = inf_status->stop_after_trap;
6613
6614 if (target_has_stack)
6615 {
6616 /* The point of catch_errors is that if the stack is clobbered,
6617 walking the stack might encounter a garbage pointer and
6618 error() trying to dereference it. */
6619 if (catch_errors
6620 (restore_selected_frame, &inf_status->selected_frame_id,
6621 "Unable to restore previously selected frame:\n",
6622 RETURN_MASK_ERROR) == 0)
6623 /* Error in restoring the selected frame. Select the innermost
6624 frame. */
6625 select_frame (get_current_frame ());
6626 }
6627
6628 xfree (inf_status);
6629 }
6630
6631 static void
6632 do_restore_infcall_control_state_cleanup (void *sts)
6633 {
6634 restore_infcall_control_state (sts);
6635 }
6636
6637 struct cleanup *
6638 make_cleanup_restore_infcall_control_state
6639 (struct infcall_control_state *inf_status)
6640 {
6641 return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status);
6642 }
6643
6644 void
6645 discard_infcall_control_state (struct infcall_control_state *inf_status)
6646 {
6647 if (inf_status->thread_control.step_resume_breakpoint)
6648 inf_status->thread_control.step_resume_breakpoint->disposition
6649 = disp_del_at_next_stop;
6650
6651 if (inf_status->thread_control.exception_resume_breakpoint)
6652 inf_status->thread_control.exception_resume_breakpoint->disposition
6653 = disp_del_at_next_stop;
6654
6655 /* See save_infcall_control_state for info on stop_bpstat. */
6656 bpstat_clear (&inf_status->thread_control.stop_bpstat);
6657
6658 xfree (inf_status);
6659 }
6660 \f
6661 int
6662 inferior_has_forked (ptid_t pid, ptid_t *child_pid)
6663 {
6664 struct target_waitstatus last;
6665 ptid_t last_ptid;
6666
6667 get_last_target_status (&last_ptid, &last);
6668
6669 if (last.kind != TARGET_WAITKIND_FORKED)
6670 return 0;
6671
6672 if (!ptid_equal (last_ptid, pid))
6673 return 0;
6674
6675 *child_pid = last.value.related_pid;
6676 return 1;
6677 }
6678
6679 int
6680 inferior_has_vforked (ptid_t pid, ptid_t *child_pid)
6681 {
6682 struct target_waitstatus last;
6683 ptid_t last_ptid;
6684
6685 get_last_target_status (&last_ptid, &last);
6686
6687 if (last.kind != TARGET_WAITKIND_VFORKED)
6688 return 0;
6689
6690 if (!ptid_equal (last_ptid, pid))
6691 return 0;
6692
6693 *child_pid = last.value.related_pid;
6694 return 1;
6695 }
6696
6697 int
6698 inferior_has_execd (ptid_t pid, char **execd_pathname)
6699 {
6700 struct target_waitstatus last;
6701 ptid_t last_ptid;
6702
6703 get_last_target_status (&last_ptid, &last);
6704
6705 if (last.kind != TARGET_WAITKIND_EXECD)
6706 return 0;
6707
6708 if (!ptid_equal (last_ptid, pid))
6709 return 0;
6710
6711 *execd_pathname = xstrdup (last.value.execd_pathname);
6712 return 1;
6713 }
6714
6715 int
6716 inferior_has_called_syscall (ptid_t pid, int *syscall_number)
6717 {
6718 struct target_waitstatus last;
6719 ptid_t last_ptid;
6720
6721 get_last_target_status (&last_ptid, &last);
6722
6723 if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY &&
6724 last.kind != TARGET_WAITKIND_SYSCALL_RETURN)
6725 return 0;
6726
6727 if (!ptid_equal (last_ptid, pid))
6728 return 0;
6729
6730 *syscall_number = last.value.syscall_number;
6731 return 1;
6732 }
6733
6734 /* Oft used ptids */
6735 ptid_t null_ptid;
6736 ptid_t minus_one_ptid;
6737
6738 /* Create a ptid given the necessary PID, LWP, and TID components. */
6739
6740 ptid_t
6741 ptid_build (int pid, long lwp, long tid)
6742 {
6743 ptid_t ptid;
6744
6745 ptid.pid = pid;
6746 ptid.lwp = lwp;
6747 ptid.tid = tid;
6748 return ptid;
6749 }
6750
6751 /* Create a ptid from just a pid. */
6752
6753 ptid_t
6754 pid_to_ptid (int pid)
6755 {
6756 return ptid_build (pid, 0, 0);
6757 }
6758
6759 /* Fetch the pid (process id) component from a ptid. */
6760
6761 int
6762 ptid_get_pid (ptid_t ptid)
6763 {
6764 return ptid.pid;
6765 }
6766
6767 /* Fetch the lwp (lightweight process) component from a ptid. */
6768
6769 long
6770 ptid_get_lwp (ptid_t ptid)
6771 {
6772 return ptid.lwp;
6773 }
6774
6775 /* Fetch the tid (thread id) component from a ptid. */
6776
6777 long
6778 ptid_get_tid (ptid_t ptid)
6779 {
6780 return ptid.tid;
6781 }
6782
6783 /* ptid_equal() is used to test equality of two ptids. */
6784
6785 int
6786 ptid_equal (ptid_t ptid1, ptid_t ptid2)
6787 {
6788 return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp
6789 && ptid1.tid == ptid2.tid);
6790 }
6791
6792 /* Returns true if PTID represents a process. */
6793
6794 int
6795 ptid_is_pid (ptid_t ptid)
6796 {
6797 if (ptid_equal (minus_one_ptid, ptid))
6798 return 0;
6799 if (ptid_equal (null_ptid, ptid))
6800 return 0;
6801
6802 return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0);
6803 }
6804
6805 int
6806 ptid_match (ptid_t ptid, ptid_t filter)
6807 {
6808 if (ptid_equal (filter, minus_one_ptid))
6809 return 1;
6810 if (ptid_is_pid (filter)
6811 && ptid_get_pid (ptid) == ptid_get_pid (filter))
6812 return 1;
6813 else if (ptid_equal (ptid, filter))
6814 return 1;
6815
6816 return 0;
6817 }
6818
6819 /* restore_inferior_ptid() will be used by the cleanup machinery
6820 to restore the inferior_ptid value saved in a call to
6821 save_inferior_ptid(). */
6822
6823 static void
6824 restore_inferior_ptid (void *arg)
6825 {
6826 ptid_t *saved_ptid_ptr = arg;
6827
6828 inferior_ptid = *saved_ptid_ptr;
6829 xfree (arg);
6830 }
6831
6832 /* Save the value of inferior_ptid so that it may be restored by a
6833 later call to do_cleanups(). Returns the struct cleanup pointer
6834 needed for later doing the cleanup. */
6835
6836 struct cleanup *
6837 save_inferior_ptid (void)
6838 {
6839 ptid_t *saved_ptid_ptr;
6840
6841 saved_ptid_ptr = xmalloc (sizeof (ptid_t));
6842 *saved_ptid_ptr = inferior_ptid;
6843 return make_cleanup (restore_inferior_ptid, saved_ptid_ptr);
6844 }
6845 \f
6846
6847 /* User interface for reverse debugging:
6848 Set exec-direction / show exec-direction commands
6849 (returns error unless target implements to_set_exec_direction method). */
6850
6851 enum exec_direction_kind execution_direction = EXEC_FORWARD;
6852 static const char exec_forward[] = "forward";
6853 static const char exec_reverse[] = "reverse";
6854 static const char *exec_direction = exec_forward;
6855 static const char *exec_direction_names[] = {
6856 exec_forward,
6857 exec_reverse,
6858 NULL
6859 };
6860
6861 static void
6862 set_exec_direction_func (char *args, int from_tty,
6863 struct cmd_list_element *cmd)
6864 {
6865 if (target_can_execute_reverse)
6866 {
6867 if (!strcmp (exec_direction, exec_forward))
6868 execution_direction = EXEC_FORWARD;
6869 else if (!strcmp (exec_direction, exec_reverse))
6870 execution_direction = EXEC_REVERSE;
6871 }
6872 else
6873 {
6874 exec_direction = exec_forward;
6875 error (_("Target does not support this operation."));
6876 }
6877 }
6878
6879 static void
6880 show_exec_direction_func (struct ui_file *out, int from_tty,
6881 struct cmd_list_element *cmd, const char *value)
6882 {
6883 switch (execution_direction) {
6884 case EXEC_FORWARD:
6885 fprintf_filtered (out, _("Forward.\n"));
6886 break;
6887 case EXEC_REVERSE:
6888 fprintf_filtered (out, _("Reverse.\n"));
6889 break;
6890 case EXEC_ERROR:
6891 default:
6892 fprintf_filtered (out, _("Forward (target `%s' does not "
6893 "support exec-direction).\n"),
6894 target_shortname);
6895 break;
6896 }
6897 }
6898
6899 /* User interface for non-stop mode. */
6900
6901 int non_stop = 0;
6902
6903 static void
6904 set_non_stop (char *args, int from_tty,
6905 struct cmd_list_element *c)
6906 {
6907 if (target_has_execution)
6908 {
6909 non_stop_1 = non_stop;
6910 error (_("Cannot change this setting while the inferior is running."));
6911 }
6912
6913 non_stop = non_stop_1;
6914 }
6915
6916 static void
6917 show_non_stop (struct ui_file *file, int from_tty,
6918 struct cmd_list_element *c, const char *value)
6919 {
6920 fprintf_filtered (file,
6921 _("Controlling the inferior in non-stop mode is %s.\n"),
6922 value);
6923 }
6924
6925 static void
6926 show_schedule_multiple (struct ui_file *file, int from_tty,
6927 struct cmd_list_element *c, const char *value)
6928 {
6929 fprintf_filtered (file, _("Resuming the execution of threads "
6930 "of all processes is %s.\n"), value);
6931 }
6932
6933 void
6934 _initialize_infrun (void)
6935 {
6936 int i;
6937 int numsigs;
6938
6939 add_info ("signals", signals_info, _("\
6940 What debugger does when program gets various signals.\n\
6941 Specify a signal as argument to print info on that signal only."));
6942 add_info_alias ("handle", "signals", 0);
6943
6944 add_com ("handle", class_run, handle_command, _("\
6945 Specify how to handle a signal.\n\
6946 Args are signals and actions to apply to those signals.\n\
6947 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6948 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6949 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6950 The special arg \"all\" is recognized to mean all signals except those\n\
6951 used by the debugger, typically SIGTRAP and SIGINT.\n\
6952 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
6953 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
6954 Stop means reenter debugger if this signal happens (implies print).\n\
6955 Print means print a message if this signal happens.\n\
6956 Pass means let program see this signal; otherwise program doesn't know.\n\
6957 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6958 Pass and Stop may be combined."));
6959 if (xdb_commands)
6960 {
6961 add_com ("lz", class_info, signals_info, _("\
6962 What debugger does when program gets various signals.\n\
6963 Specify a signal as argument to print info on that signal only."));
6964 add_com ("z", class_run, xdb_handle_command, _("\
6965 Specify how to handle a signal.\n\
6966 Args are signals and actions to apply to those signals.\n\
6967 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
6968 from 1-15 are allowed for compatibility with old versions of GDB.\n\
6969 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
6970 The special arg \"all\" is recognized to mean all signals except those\n\
6971 used by the debugger, typically SIGTRAP and SIGINT.\n\
6972 Recognized actions include \"s\" (toggles between stop and nostop),\n\
6973 \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \
6974 nopass), \"Q\" (noprint)\n\
6975 Stop means reenter debugger if this signal happens (implies print).\n\
6976 Print means print a message if this signal happens.\n\
6977 Pass means let program see this signal; otherwise program doesn't know.\n\
6978 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
6979 Pass and Stop may be combined."));
6980 }
6981
6982 if (!dbx_commands)
6983 stop_command = add_cmd ("stop", class_obscure,
6984 not_just_help_class_command, _("\
6985 There is no `stop' command, but you can set a hook on `stop'.\n\
6986 This allows you to set a list of commands to be run each time execution\n\
6987 of the program stops."), &cmdlist);
6988
6989 add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\
6990 Set inferior debugging."), _("\
6991 Show inferior debugging."), _("\
6992 When non-zero, inferior specific debugging is enabled."),
6993 NULL,
6994 show_debug_infrun,
6995 &setdebuglist, &showdebuglist);
6996
6997 add_setshow_boolean_cmd ("displaced", class_maintenance,
6998 &debug_displaced, _("\
6999 Set displaced stepping debugging."), _("\
7000 Show displaced stepping debugging."), _("\
7001 When non-zero, displaced stepping specific debugging is enabled."),
7002 NULL,
7003 show_debug_displaced,
7004 &setdebuglist, &showdebuglist);
7005
7006 add_setshow_boolean_cmd ("non-stop", no_class,
7007 &non_stop_1, _("\
7008 Set whether gdb controls the inferior in non-stop mode."), _("\
7009 Show whether gdb controls the inferior in non-stop mode."), _("\
7010 When debugging a multi-threaded program and this setting is\n\
7011 off (the default, also called all-stop mode), when one thread stops\n\
7012 (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\
7013 all other threads in the program while you interact with the thread of\n\
7014 interest. When you continue or step a thread, you can allow the other\n\
7015 threads to run, or have them remain stopped, but while you inspect any\n\
7016 thread's state, all threads stop.\n\
7017 \n\
7018 In non-stop mode, when one thread stops, other threads can continue\n\
7019 to run freely. You'll be able to step each thread independently,\n\
7020 leave it stopped or free to run as needed."),
7021 set_non_stop,
7022 show_non_stop,
7023 &setlist,
7024 &showlist);
7025
7026 numsigs = (int) TARGET_SIGNAL_LAST;
7027 signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs);
7028 signal_print = (unsigned char *)
7029 xmalloc (sizeof (signal_print[0]) * numsigs);
7030 signal_program = (unsigned char *)
7031 xmalloc (sizeof (signal_program[0]) * numsigs);
7032 signal_pass = (unsigned char *)
7033 xmalloc (sizeof (signal_program[0]) * numsigs);
7034 for (i = 0; i < numsigs; i++)
7035 {
7036 signal_stop[i] = 1;
7037 signal_print[i] = 1;
7038 signal_program[i] = 1;
7039 }
7040
7041 /* Signals caused by debugger's own actions
7042 should not be given to the program afterwards. */
7043 signal_program[TARGET_SIGNAL_TRAP] = 0;
7044 signal_program[TARGET_SIGNAL_INT] = 0;
7045
7046 /* Signals that are not errors should not normally enter the debugger. */
7047 signal_stop[TARGET_SIGNAL_ALRM] = 0;
7048 signal_print[TARGET_SIGNAL_ALRM] = 0;
7049 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
7050 signal_print[TARGET_SIGNAL_VTALRM] = 0;
7051 signal_stop[TARGET_SIGNAL_PROF] = 0;
7052 signal_print[TARGET_SIGNAL_PROF] = 0;
7053 signal_stop[TARGET_SIGNAL_CHLD] = 0;
7054 signal_print[TARGET_SIGNAL_CHLD] = 0;
7055 signal_stop[TARGET_SIGNAL_IO] = 0;
7056 signal_print[TARGET_SIGNAL_IO] = 0;
7057 signal_stop[TARGET_SIGNAL_POLL] = 0;
7058 signal_print[TARGET_SIGNAL_POLL] = 0;
7059 signal_stop[TARGET_SIGNAL_URG] = 0;
7060 signal_print[TARGET_SIGNAL_URG] = 0;
7061 signal_stop[TARGET_SIGNAL_WINCH] = 0;
7062 signal_print[TARGET_SIGNAL_WINCH] = 0;
7063 signal_stop[TARGET_SIGNAL_PRIO] = 0;
7064 signal_print[TARGET_SIGNAL_PRIO] = 0;
7065
7066 /* These signals are used internally by user-level thread
7067 implementations. (See signal(5) on Solaris.) Like the above
7068 signals, a healthy program receives and handles them as part of
7069 its normal operation. */
7070 signal_stop[TARGET_SIGNAL_LWP] = 0;
7071 signal_print[TARGET_SIGNAL_LWP] = 0;
7072 signal_stop[TARGET_SIGNAL_WAITING] = 0;
7073 signal_print[TARGET_SIGNAL_WAITING] = 0;
7074 signal_stop[TARGET_SIGNAL_CANCEL] = 0;
7075 signal_print[TARGET_SIGNAL_CANCEL] = 0;
7076
7077 /* Update cached state. */
7078 signal_cache_update (-1);
7079
7080 add_setshow_zinteger_cmd ("stop-on-solib-events", class_support,
7081 &stop_on_solib_events, _("\
7082 Set stopping for shared library events."), _("\
7083 Show stopping for shared library events."), _("\
7084 If nonzero, gdb will give control to the user when the dynamic linker\n\
7085 notifies gdb of shared library events. The most common event of interest\n\
7086 to the user would be loading/unloading of a new library."),
7087 NULL,
7088 show_stop_on_solib_events,
7089 &setlist, &showlist);
7090
7091 add_setshow_enum_cmd ("follow-fork-mode", class_run,
7092 follow_fork_mode_kind_names,
7093 &follow_fork_mode_string, _("\
7094 Set debugger response to a program call of fork or vfork."), _("\
7095 Show debugger response to a program call of fork or vfork."), _("\
7096 A fork or vfork creates a new process. follow-fork-mode can be:\n\
7097 parent - the original process is debugged after a fork\n\
7098 child - the new process is debugged after a fork\n\
7099 The unfollowed process will continue to run.\n\
7100 By default, the debugger will follow the parent process."),
7101 NULL,
7102 show_follow_fork_mode_string,
7103 &setlist, &showlist);
7104
7105 add_setshow_enum_cmd ("follow-exec-mode", class_run,
7106 follow_exec_mode_names,
7107 &follow_exec_mode_string, _("\
7108 Set debugger response to a program call of exec."), _("\
7109 Show debugger response to a program call of exec."), _("\
7110 An exec call replaces the program image of a process.\n\
7111 \n\
7112 follow-exec-mode can be:\n\
7113 \n\
7114 new - the debugger creates a new inferior and rebinds the process\n\
7115 to this new inferior. The program the process was running before\n\
7116 the exec call can be restarted afterwards by restarting the original\n\
7117 inferior.\n\
7118 \n\
7119 same - the debugger keeps the process bound to the same inferior.\n\
7120 The new executable image replaces the previous executable loaded in\n\
7121 the inferior. Restarting the inferior after the exec call restarts\n\
7122 the executable the process was running after the exec call.\n\
7123 \n\
7124 By default, the debugger will use the same inferior."),
7125 NULL,
7126 show_follow_exec_mode_string,
7127 &setlist, &showlist);
7128
7129 add_setshow_enum_cmd ("scheduler-locking", class_run,
7130 scheduler_enums, &scheduler_mode, _("\
7131 Set mode for locking scheduler during execution."), _("\
7132 Show mode for locking scheduler during execution."), _("\
7133 off == no locking (threads may preempt at any time)\n\
7134 on == full locking (no thread except the current thread may run)\n\
7135 step == scheduler locked during every single-step operation.\n\
7136 In this mode, no other thread may run during a step command.\n\
7137 Other threads may run while stepping over a function call ('next')."),
7138 set_schedlock_func, /* traps on target vector */
7139 show_scheduler_mode,
7140 &setlist, &showlist);
7141
7142 add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\
7143 Set mode for resuming threads of all processes."), _("\
7144 Show mode for resuming threads of all processes."), _("\
7145 When on, execution commands (such as 'continue' or 'next') resume all\n\
7146 threads of all processes. When off (which is the default), execution\n\
7147 commands only resume the threads of the current process. The set of\n\
7148 threads that are resumed is further refined by the scheduler-locking\n\
7149 mode (see help set scheduler-locking)."),
7150 NULL,
7151 show_schedule_multiple,
7152 &setlist, &showlist);
7153
7154 add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\
7155 Set mode of the step operation."), _("\
7156 Show mode of the step operation."), _("\
7157 When set, doing a step over a function without debug line information\n\
7158 will stop at the first instruction of that function. Otherwise, the\n\
7159 function is skipped and the step command stops at a different source line."),
7160 NULL,
7161 show_step_stop_if_no_debug,
7162 &setlist, &showlist);
7163
7164 add_setshow_enum_cmd ("displaced-stepping", class_run,
7165 can_use_displaced_stepping_enum,
7166 &can_use_displaced_stepping, _("\
7167 Set debugger's willingness to use displaced stepping."), _("\
7168 Show debugger's willingness to use displaced stepping."), _("\
7169 If on, gdb will use displaced stepping to step over breakpoints if it is\n\
7170 supported by the target architecture. If off, gdb will not use displaced\n\
7171 stepping to step over breakpoints, even if such is supported by the target\n\
7172 architecture. If auto (which is the default), gdb will use displaced stepping\n\
7173 if the target architecture supports it and non-stop mode is active, but will not\n\
7174 use it in all-stop mode (see help set non-stop)."),
7175 NULL,
7176 show_can_use_displaced_stepping,
7177 &setlist, &showlist);
7178
7179 add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names,
7180 &exec_direction, _("Set direction of execution.\n\
7181 Options are 'forward' or 'reverse'."),
7182 _("Show direction of execution (forward/reverse)."),
7183 _("Tells gdb whether to execute forward or backward."),
7184 set_exec_direction_func, show_exec_direction_func,
7185 &setlist, &showlist);
7186
7187 /* Set/show detach-on-fork: user-settable mode. */
7188
7189 add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\
7190 Set whether gdb will detach the child of a fork."), _("\
7191 Show whether gdb will detach the child of a fork."), _("\
7192 Tells gdb whether to detach the child of a fork."),
7193 NULL, NULL, &setlist, &showlist);
7194
7195 /* ptid initializations */
7196 null_ptid = ptid_build (0, 0, 0);
7197 minus_one_ptid = ptid_build (-1, 0, 0);
7198 inferior_ptid = null_ptid;
7199 target_last_wait_ptid = minus_one_ptid;
7200
7201 observer_attach_thread_ptid_changed (infrun_thread_ptid_changed);
7202 observer_attach_thread_stop_requested (infrun_thread_stop_requested);
7203 observer_attach_thread_exit (infrun_thread_thread_exit);
7204 observer_attach_inferior_exit (infrun_inferior_exit);
7205
7206 /* Explicitly create without lookup, since that tries to create a
7207 value with a void typed value, and when we get here, gdbarch
7208 isn't initialized yet. At this point, we're quite sure there
7209 isn't another convenience variable of the same name. */
7210 create_internalvar_type_lazy ("_siginfo", siginfo_make_value);
7211
7212 add_setshow_boolean_cmd ("observer", no_class,
7213 &observer_mode_1, _("\
7214 Set whether gdb controls the inferior in observer mode."), _("\
7215 Show whether gdb controls the inferior in observer mode."), _("\
7216 In observer mode, GDB can get data from the inferior, but not\n\
7217 affect its execution. Registers and memory may not be changed,\n\
7218 breakpoints may not be set, and the program cannot be interrupted\n\
7219 or signalled."),
7220 set_observer_mode,
7221 show_observer_mode,
7222 &setlist,
7223 &showlist);
7224 }
This page took 0.215994 seconds and 5 git commands to generate.