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