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