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