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