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