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