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