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