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