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