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