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