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