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