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