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