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