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