* gas/testsuite/all/gas.exp: No longer expect failures for
[deliverable/binutils-gdb.git] / gdb / infrun.c
1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "gdb_string.h"
23 #include <ctype.h>
24 #include "symtab.h"
25 #include "frame.h"
26 #include "inferior.h"
27 #include "breakpoint.h"
28 #include "wait.h"
29 #include "gdbcore.h"
30 #include "gdbcmd.h"
31 #include "target.h"
32 #include "gdbthread.h"
33 #include "annotate.h"
34 #include "symfile.h" /* for overlay functions */
35
36 #include <signal.h>
37
38 /* Prototypes for local functions */
39
40 static void signals_info PARAMS ((char *, int));
41
42 static void handle_command PARAMS ((char *, int));
43
44 static void sig_print_info PARAMS ((enum target_signal));
45
46 static void sig_print_header PARAMS ((void));
47
48 static void resume_cleanups PARAMS ((int));
49
50 static int hook_stop_stub PARAMS ((char *));
51
52 static void delete_breakpoint_current_contents PARAMS ((PTR));
53
54 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
55 program. It needs to examine the jmp_buf argument and extract the PC
56 from it. The return value is non-zero on success, zero otherwise. */
57
58 #ifndef GET_LONGJMP_TARGET
59 #define GET_LONGJMP_TARGET(PC_ADDR) 0
60 #endif
61
62
63 /* Some machines have trampoline code that sits between function callers
64 and the actual functions themselves. If this machine doesn't have
65 such things, disable their processing. */
66
67 #ifndef SKIP_TRAMPOLINE_CODE
68 #define SKIP_TRAMPOLINE_CODE(pc) 0
69 #endif
70
71 /* Dynamic function trampolines are similar to solib trampolines in that they
72 are between the caller and the callee. The difference is that when you
73 enter a dynamic trampoline, you can't determine the callee's address. Some
74 (usually complex) code needs to run in the dynamic trampoline to figure out
75 the callee's address. This macro is usually called twice. First, when we
76 enter the trampoline (looks like a normal function call at that point). It
77 should return the PC of a point within the trampoline where the callee's
78 address is known. Second, when we hit the breakpoint, this routine returns
79 the callee's address. At that point, things proceed as per a step resume
80 breakpoint. */
81
82 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
83 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
84 #endif
85
86 /* On SVR4 based systems, determining the callee's address is exceedingly
87 difficult and depends on the implementation of the run time loader.
88 If we are stepping at the source level, we single step until we exit
89 the run time loader code and reach the callee's address. */
90
91 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
92 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
93 #endif
94
95 /* For SVR4 shared libraries, each call goes through a small piece of
96 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
97 to nonzero if we are current stopped in one of these. */
98
99 #ifndef IN_SOLIB_CALL_TRAMPOLINE
100 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
101 #endif
102
103 /* In some shared library schemes, the return path from a shared library
104 call may need to go through a trampoline too. */
105
106 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
107 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
108 #endif
109
110 /* On MIPS16, a function that returns a floating point value may call
111 a library helper function to copy the return value to a floating point
112 register. The IGNORE_HELPER_CALL macro returns non-zero if we
113 should ignore (i.e. step over) this function call. */
114 #ifndef IGNORE_HELPER_CALL
115 #define IGNORE_HELPER_CALL(pc) 0
116 #endif
117
118 /* On some systems, the PC may be left pointing at an instruction that won't
119 actually be executed. This is usually indicated by a bit in the PSW. If
120 we find ourselves in such a state, then we step the target beyond the
121 nullified instruction before returning control to the user so as to avoid
122 confusion. */
123
124 #ifndef INSTRUCTION_NULLIFIED
125 #define INSTRUCTION_NULLIFIED 0
126 #endif
127
128 /* Tables of how to react to signals; the user sets them. */
129
130 static unsigned char *signal_stop;
131 static unsigned char *signal_print;
132 static unsigned char *signal_program;
133
134 #define SET_SIGS(nsigs,sigs,flags) \
135 do { \
136 int signum = (nsigs); \
137 while (signum-- > 0) \
138 if ((sigs)[signum]) \
139 (flags)[signum] = 1; \
140 } while (0)
141
142 #define UNSET_SIGS(nsigs,sigs,flags) \
143 do { \
144 int signum = (nsigs); \
145 while (signum-- > 0) \
146 if ((sigs)[signum]) \
147 (flags)[signum] = 0; \
148 } while (0)
149
150
151 /* Command list pointer for the "stop" placeholder. */
152
153 static struct cmd_list_element *stop_command;
154
155 /* Nonzero if breakpoints are now inserted in the inferior. */
156
157 static int breakpoints_inserted;
158
159 /* Function inferior was in as of last step command. */
160
161 static struct symbol *step_start_function;
162
163 /* Nonzero if we are expecting a trace trap and should proceed from it. */
164
165 static int trap_expected;
166
167 #ifdef SOLIB_ADD
168 /* Nonzero if we want to give control to the user when we're notified
169 of shared library events by the dynamic linker. */
170 static int stop_on_solib_events;
171 #endif
172
173 #ifdef HP_OS_BUG
174 /* Nonzero if the next time we try to continue the inferior, it will
175 step one instruction and generate a spurious trace trap.
176 This is used to compensate for a bug in HP-UX. */
177
178 static int trap_expected_after_continue;
179 #endif
180
181 /* Nonzero means expecting a trace trap
182 and should stop the inferior and return silently when it happens. */
183
184 int stop_after_trap;
185
186 /* Nonzero means expecting a trap and caller will handle it themselves.
187 It is used after attach, due to attaching to a process;
188 when running in the shell before the child program has been exec'd;
189 and when running some kinds of remote stuff (FIXME?). */
190
191 int stop_soon_quietly;
192
193 /* Nonzero if proceed is being used for a "finish" command or a similar
194 situation when stop_registers should be saved. */
195
196 int proceed_to_finish;
197
198 /* Save register contents here when about to pop a stack dummy frame,
199 if-and-only-if proceed_to_finish is set.
200 Thus this contains the return value from the called function (assuming
201 values are returned in a register). */
202
203 char stop_registers[REGISTER_BYTES];
204
205 /* Nonzero if program stopped due to error trying to insert breakpoints. */
206
207 static int breakpoints_failed;
208
209 /* Nonzero after stop if current stack frame should be printed. */
210
211 static int stop_print_frame;
212
213 \f
214 /* Things to clean up if we QUIT out of resume (). */
215 /* ARGSUSED */
216 static void
217 resume_cleanups (arg)
218 int arg;
219 {
220 normal_stop ();
221 }
222
223 /* Resume the inferior, but allow a QUIT. This is useful if the user
224 wants to interrupt some lengthy single-stepping operation
225 (for child processes, the SIGINT goes to the inferior, and so
226 we get a SIGINT random_signal, but for remote debugging and perhaps
227 other targets, that's not true).
228
229 STEP nonzero if we should step (zero to continue instead).
230 SIG is the signal to give the inferior (zero for none). */
231 void
232 resume (step, sig)
233 int step;
234 enum target_signal sig;
235 {
236 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
237 QUIT;
238
239 #ifdef CANNOT_STEP_BREAKPOINT
240 /* Most targets can step a breakpoint instruction, thus executing it
241 normally. But if this one cannot, just continue and we will hit
242 it anyway. */
243 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
244 step = 0;
245 #endif
246
247 #ifdef NO_SINGLE_STEP
248 if (step) {
249 single_step(sig); /* Do it the hard way, w/temp breakpoints */
250 step = 0; /* ...and don't ask hardware to do it. */
251 }
252 #endif
253
254 /* Handle any optimized stores to the inferior NOW... */
255 #ifdef DO_DEFERRED_STORES
256 DO_DEFERRED_STORES;
257 #endif
258
259 /* Install inferior's terminal modes. */
260 target_terminal_inferior ();
261
262 target_resume (-1, step, sig);
263 discard_cleanups (old_cleanups);
264 }
265
266 \f
267 /* Clear out all variables saying what to do when inferior is continued.
268 First do this, then set the ones you want, then call `proceed'. */
269
270 void
271 clear_proceed_status ()
272 {
273 trap_expected = 0;
274 step_range_start = 0;
275 step_range_end = 0;
276 step_frame_address = 0;
277 step_over_calls = -1;
278 stop_after_trap = 0;
279 stop_soon_quietly = 0;
280 proceed_to_finish = 0;
281 breakpoint_proceeded = 1; /* We're about to proceed... */
282
283 /* Discard any remaining commands or status from previous stop. */
284 bpstat_clear (&stop_bpstat);
285 }
286
287 /* Basic routine for continuing the program in various fashions.
288
289 ADDR is the address to resume at, or -1 for resume where stopped.
290 SIGGNAL is the signal to give it, or 0 for none,
291 or -1 for act according to how it stopped.
292 STEP is nonzero if should trap after one instruction.
293 -1 means return after that and print nothing.
294 You should probably set various step_... variables
295 before calling here, if you are stepping.
296
297 You should call clear_proceed_status before calling proceed. */
298
299 void
300 proceed (addr, siggnal, step)
301 CORE_ADDR addr;
302 enum target_signal siggnal;
303 int step;
304 {
305 int oneproc = 0;
306
307 if (step > 0)
308 step_start_function = find_pc_function (read_pc ());
309 if (step < 0)
310 stop_after_trap = 1;
311
312 if (addr == (CORE_ADDR)-1)
313 {
314 /* If there is a breakpoint at the address we will resume at,
315 step one instruction before inserting breakpoints
316 so that we do not stop right away. */
317
318 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
319 oneproc = 1;
320
321 #ifdef STEP_SKIPS_DELAY
322 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
323 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
324 is slow (it needs to read memory from the target). */
325 if (breakpoint_here_p (read_pc () + 4)
326 && STEP_SKIPS_DELAY (read_pc ()))
327 oneproc = 1;
328 #endif /* STEP_SKIPS_DELAY */
329 }
330 else
331 write_pc (addr);
332
333 #ifdef PREPARE_TO_PROCEED
334 /* In a multi-threaded task we may select another thread and then continue.
335
336 In this case the thread that stopped at a breakpoint will immediately
337 cause another stop, if it is not stepped over first. On the other hand,
338 if (ADDR != -1) we only want to single step over the breakpoint if we did
339 switch to another thread.
340
341 If we are single stepping, don't do any of the above.
342 (Note that in the current implementation single stepping another
343 thread after a breakpoint and then continuing will cause the original
344 breakpoint to be hit again, but you can always continue, so it's not
345 a big deal.) */
346
347 if (! step && PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
348 oneproc = 1;
349 #endif /* PREPARE_TO_PROCEED */
350
351 #ifdef HP_OS_BUG
352 if (trap_expected_after_continue)
353 {
354 /* If (step == 0), a trap will be automatically generated after
355 the first instruction is executed. Force step one
356 instruction to clear this condition. This should not occur
357 if step is nonzero, but it is harmless in that case. */
358 oneproc = 1;
359 trap_expected_after_continue = 0;
360 }
361 #endif /* HP_OS_BUG */
362
363 if (oneproc)
364 /* We will get a trace trap after one instruction.
365 Continue it automatically and insert breakpoints then. */
366 trap_expected = 1;
367 else
368 {
369 int temp = insert_breakpoints ();
370 if (temp)
371 {
372 print_sys_errmsg ("ptrace", temp);
373 error ("Cannot insert breakpoints.\n\
374 The same program may be running in another process.");
375 }
376 breakpoints_inserted = 1;
377 }
378
379 if (siggnal != TARGET_SIGNAL_DEFAULT)
380 stop_signal = siggnal;
381 /* If this signal should not be seen by program,
382 give it zero. Used for debugging signals. */
383 else if (!signal_program[stop_signal])
384 stop_signal = TARGET_SIGNAL_0;
385
386 annotate_starting ();
387
388 /* Make sure that output from GDB appears before output from the
389 inferior. */
390 gdb_flush (gdb_stdout);
391
392 /* Resume inferior. */
393 resume (oneproc || step || bpstat_should_step (), stop_signal);
394
395 /* Wait for it to stop (if not standalone)
396 and in any case decode why it stopped, and act accordingly. */
397
398 wait_for_inferior ();
399 normal_stop ();
400 }
401
402 /* Record the pc and sp of the program the last time it stopped.
403 These are just used internally by wait_for_inferior, but need
404 to be preserved over calls to it and cleared when the inferior
405 is started. */
406 static CORE_ADDR prev_pc;
407 static CORE_ADDR prev_func_start;
408 static char *prev_func_name;
409
410 \f
411 /* Start remote-debugging of a machine over a serial link. */
412
413 void
414 start_remote ()
415 {
416 init_thread_list ();
417 init_wait_for_inferior ();
418 clear_proceed_status ();
419 stop_soon_quietly = 1;
420 trap_expected = 0;
421 wait_for_inferior ();
422 normal_stop ();
423 }
424
425 /* Initialize static vars when a new inferior begins. */
426
427 void
428 init_wait_for_inferior ()
429 {
430 /* These are meaningless until the first time through wait_for_inferior. */
431 prev_pc = 0;
432 prev_func_start = 0;
433 prev_func_name = NULL;
434
435 #ifdef HP_OS_BUG
436 trap_expected_after_continue = 0;
437 #endif
438 breakpoints_inserted = 0;
439 breakpoint_init_inferior ();
440
441 /* Don't confuse first call to proceed(). */
442 stop_signal = TARGET_SIGNAL_0;
443 }
444
445 static void
446 delete_breakpoint_current_contents (arg)
447 PTR arg;
448 {
449 struct breakpoint **breakpointp = (struct breakpoint **)arg;
450 if (*breakpointp != NULL)
451 delete_breakpoint (*breakpointp);
452 }
453 \f
454 /* Wait for control to return from inferior to debugger.
455 If inferior gets a signal, we may decide to start it up again
456 instead of returning. That is why there is a loop in this function.
457 When this function actually returns it means the inferior
458 should be left stopped and GDB should read more commands. */
459
460 void
461 wait_for_inferior ()
462 {
463 struct cleanup *old_cleanups;
464 struct target_waitstatus w;
465 int another_trap;
466 int random_signal = 0;
467 CORE_ADDR stop_func_start;
468 CORE_ADDR stop_func_end;
469 char *stop_func_name;
470 #if 0
471 CORE_ADDR prologue_pc = 0;
472 #endif
473 CORE_ADDR tmp;
474 struct symtab_and_line sal;
475 int remove_breakpoints_on_following_step = 0;
476 int current_line;
477 struct symtab *current_symtab;
478 int handling_longjmp = 0; /* FIXME */
479 struct breakpoint *step_resume_breakpoint = NULL;
480 struct breakpoint *through_sigtramp_breakpoint = NULL;
481 int pid;
482 int update_step_sp = 0;
483
484 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
485 &step_resume_breakpoint);
486 make_cleanup (delete_breakpoint_current_contents,
487 &through_sigtramp_breakpoint);
488 sal = find_pc_line(prev_pc, 0);
489 current_line = sal.line;
490 current_symtab = sal.symtab;
491
492 /* Are we stepping? */
493 #define CURRENTLY_STEPPING() \
494 ((through_sigtramp_breakpoint == NULL \
495 && !handling_longjmp \
496 && ((step_range_end && step_resume_breakpoint == NULL) \
497 || trap_expected)) \
498 || bpstat_should_step ())
499
500 while (1)
501 {
502 extern int overlay_cache_invalid; /* declared in symfile.h */
503
504 overlay_cache_invalid = 1;
505
506 /* We have to invalidate the registers BEFORE calling target_wait because
507 they can be loaded from the target while in target_wait. This makes
508 remote debugging a bit more efficient for those targets that provide
509 critical registers as part of their normal status mechanism. */
510
511 registers_changed ();
512
513 if (target_wait_hook)
514 pid = target_wait_hook (-1, &w);
515 else
516 pid = target_wait (-1, &w);
517
518 /* Gross.
519
520 We goto this label from elsewhere in wait_for_inferior when we want
521 to continue the main loop without calling "wait" and trashing the
522 waitstatus contained in W. */
523 have_waited:
524
525 flush_cached_frames ();
526
527 /* If it's a new process, add it to the thread database */
528
529 if (w.kind != TARGET_WAITKIND_EXITED
530 && pid != inferior_pid
531 && !in_thread_list (pid))
532 {
533 add_thread (pid);
534 printf_filtered ("[New %s]\n", target_pid_to_str (pid));
535
536 /* We may want to consider not doing a resume here in order to give
537 the user a chance to play with the new thread. It might be good
538 to make that a user-settable option. */
539
540 /* At this point, all threads are stopped (happens automatically in
541 either the OS or the native code). Therefore we need to continue
542 all threads in order to make progress. */
543
544 target_resume (-1, 0, TARGET_SIGNAL_0);
545 continue;
546 }
547
548 switch (w.kind)
549 {
550 case TARGET_WAITKIND_LOADED:
551 /* Ignore gracefully during startup of the inferior, as it
552 might be the shell which has just loaded some objects,
553 otherwise add the symbols for the newly loaded objects. */
554 #ifdef SOLIB_ADD
555 if (!stop_soon_quietly)
556 {
557 extern int auto_solib_add;
558
559 /* Remove breakpoints, SOLIB_ADD might adjust
560 breakpoint addresses via breakpoint_re_set. */
561 if (breakpoints_inserted)
562 remove_breakpoints ();
563
564 /* Check for any newly added shared libraries if we're
565 supposed to be adding them automatically. */
566 if (auto_solib_add)
567 {
568 /* Switch terminal for any messages produced by
569 breakpoint_re_set. */
570 target_terminal_ours_for_output ();
571 SOLIB_ADD (NULL, 0, NULL);
572 target_terminal_inferior ();
573 }
574
575 /* Reinsert breakpoints and continue. */
576 if (breakpoints_inserted)
577 insert_breakpoints ();
578 }
579 #endif
580 resume (0, TARGET_SIGNAL_0);
581 continue;
582
583 case TARGET_WAITKIND_SPURIOUS:
584 resume (0, TARGET_SIGNAL_0);
585 continue;
586
587 case TARGET_WAITKIND_EXITED:
588 target_terminal_ours (); /* Must do this before mourn anyway */
589 annotate_exited (w.value.integer);
590 if (w.value.integer)
591 printf_filtered ("\nProgram exited with code 0%o.\n",
592 (unsigned int)w.value.integer);
593 else
594 printf_filtered ("\nProgram exited normally.\n");
595
596 /* Record the exit code in the convenience variable $_exitcode, so
597 that the user can inspect this again later. */
598 set_internalvar (lookup_internalvar ("_exitcode"),
599 value_from_longest (builtin_type_int,
600 (LONGEST) w.value.integer));
601 gdb_flush (gdb_stdout);
602 target_mourn_inferior ();
603 #ifdef NO_SINGLE_STEP
604 one_stepped = 0;
605 #endif
606 stop_print_frame = 0;
607 goto stop_stepping;
608
609 case TARGET_WAITKIND_SIGNALLED:
610 stop_print_frame = 0;
611 stop_signal = w.value.sig;
612 target_terminal_ours (); /* Must do this before mourn anyway */
613 annotate_signalled ();
614
615 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
616 mean it is already dead? This has been here since GDB 2.8, so
617 perhaps it means rms didn't understand unix waitstatuses?
618 For the moment I'm just kludging around this in remote.c
619 rather than trying to change it here --kingdon, 5 Dec 1994. */
620 target_kill (); /* kill mourns as well */
621
622 printf_filtered ("\nProgram terminated with signal ");
623 annotate_signal_name ();
624 printf_filtered ("%s", target_signal_to_name (stop_signal));
625 annotate_signal_name_end ();
626 printf_filtered (", ");
627 annotate_signal_string ();
628 printf_filtered ("%s", target_signal_to_string (stop_signal));
629 annotate_signal_string_end ();
630 printf_filtered (".\n");
631
632 printf_filtered ("The program no longer exists.\n");
633 gdb_flush (gdb_stdout);
634 #ifdef NO_SINGLE_STEP
635 one_stepped = 0;
636 #endif
637 goto stop_stepping;
638
639 case TARGET_WAITKIND_STOPPED:
640 /* This is the only case in which we keep going; the above cases
641 end in a continue or goto. */
642 break;
643 }
644
645 stop_signal = w.value.sig;
646
647 stop_pc = read_pc_pid (pid);
648
649 /* See if a thread hit a thread-specific breakpoint that was meant for
650 another thread. If so, then step that thread past the breakpoint,
651 and continue it. */
652
653 if (stop_signal == TARGET_SIGNAL_TRAP)
654 {
655 #ifdef NO_SINGLE_STEP
656 if (one_stepped)
657 random_signal = 0;
658 else
659 #endif
660 if (breakpoints_inserted
661 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
662 {
663 random_signal = 0;
664 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
665 {
666 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
667 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
668
669 remove_breakpoints ();
670 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
671 /* FIXME: What if a signal arrives instead of the single-step
672 happening? */
673
674 if (target_wait_hook)
675 target_wait_hook (pid, &w);
676 else
677 target_wait (pid, &w);
678 insert_breakpoints ();
679
680 /* We need to restart all the threads now. */
681 target_resume (-1, 0, TARGET_SIGNAL_0);
682 continue;
683 }
684 }
685 }
686 else
687 random_signal = 1;
688
689 /* See if something interesting happened to the non-current thread. If
690 so, then switch to that thread, and eventually give control back to
691 the user. */
692
693 if (pid != inferior_pid)
694 {
695 int printed = 0;
696
697 /* If it's a random signal for a non-current thread, notify user
698 if he's expressed an interest. */
699
700 if (random_signal
701 && signal_print[stop_signal])
702 {
703 printed = 1;
704 target_terminal_ours_for_output ();
705 printf_filtered ("\nProgram received signal %s, %s.\n",
706 target_signal_to_name (stop_signal),
707 target_signal_to_string (stop_signal));
708 gdb_flush (gdb_stdout);
709 }
710
711 /* If it's not SIGTRAP and not a signal we want to stop for, then
712 continue the thread. */
713
714 if (stop_signal != TARGET_SIGNAL_TRAP
715 && !signal_stop[stop_signal])
716 {
717 if (printed)
718 target_terminal_inferior ();
719
720 /* Clear the signal if it should not be passed. */
721 if (signal_program[stop_signal] == 0)
722 stop_signal = TARGET_SIGNAL_0;
723
724 target_resume (pid, 0, stop_signal);
725 continue;
726 }
727
728 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
729 and fall into the rest of wait_for_inferior(). */
730
731 /* Save infrun state for the old thread. */
732 save_infrun_state (inferior_pid, prev_pc,
733 prev_func_start, prev_func_name,
734 trap_expected, step_resume_breakpoint,
735 through_sigtramp_breakpoint,
736 step_range_start, step_range_end,
737 step_frame_address, handling_longjmp,
738 another_trap);
739
740 inferior_pid = pid;
741
742 /* Load infrun state for the new thread. */
743 load_infrun_state (inferior_pid, &prev_pc,
744 &prev_func_start, &prev_func_name,
745 &trap_expected, &step_resume_breakpoint,
746 &through_sigtramp_breakpoint,
747 &step_range_start, &step_range_end,
748 &step_frame_address, &handling_longjmp,
749 &another_trap);
750 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
751 flush_cached_frames ();
752 }
753
754 #ifdef NO_SINGLE_STEP
755 if (one_stepped)
756 single_step (0); /* This actually cleans up the ss */
757 #endif /* NO_SINGLE_STEP */
758
759 /* If PC is pointing at a nullified instruction, then step beyond
760 it so that the user won't be confused when GDB appears to be ready
761 to execute it. */
762
763 if (INSTRUCTION_NULLIFIED)
764 {
765 struct target_waitstatus tmpstatus;
766
767 registers_changed ();
768 target_resume (pid, 1, TARGET_SIGNAL_0);
769
770 /* We may have received a signal that we want to pass to
771 the inferior; therefore, we must not clobber the waitstatus
772 in W. So we call wait ourselves, then continue the loop
773 at the "have_waited" label. */
774 if (target_wait_hook)
775 target_wait_hook (pid, &tmpstatus);
776 else
777 target_wait (pid, &tmpstatus);
778
779
780 goto have_waited;
781 }
782
783 #ifdef HAVE_STEPPABLE_WATCHPOINT
784 /* It may not be necessary to disable the watchpoint to stop over
785 it. For example, the PA can (with some kernel cooperation)
786 single step over a watchpoint without disabling the watchpoint. */
787 if (STOPPED_BY_WATCHPOINT (w))
788 {
789 resume (1, 0);
790 continue;
791 }
792 #endif
793
794 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
795 /* It is far more common to need to disable a watchpoint
796 to step the inferior over it. FIXME. What else might
797 a debug register or page protection watchpoint scheme need
798 here? */
799 if (STOPPED_BY_WATCHPOINT (w))
800 {
801 /* At this point, we are stopped at an instruction which has attempted to write
802 to a piece of memory under control of a watchpoint. The instruction hasn't
803 actually executed yet. If we were to evaluate the watchpoint expression
804 now, we would get the old value, and therefore no change would seem to have
805 occurred.
806
807 In order to make watchpoints work `right', we really need to complete the
808 memory write, and then evaluate the watchpoint expression. The following
809 code does that by removing the watchpoint (actually, all watchpoints and
810 breakpoints), single-stepping the target, re-inserting watchpoints, and then
811 falling through to let normal single-step processing handle proceed. Since
812 this includes evaluating watchpoints, things will come to a stop in the
813 correct manner. */
814
815 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
816
817 remove_breakpoints ();
818 registers_changed();
819 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
820
821 if (target_wait_hook)
822 target_wait_hook (pid, &w);
823 else
824 target_wait (pid, &w);
825 insert_breakpoints ();
826 /* FIXME-maybe: is this cleaner than setting a flag? Does it
827 handle things like signals arriving and other things happening
828 in combination correctly? */
829 goto have_waited;
830 }
831 #endif
832
833 #ifdef HAVE_CONTINUABLE_WATCHPOINT
834 /* It may be possible to simply continue after a watchpoint. */
835 STOPPED_BY_WATCHPOINT (w);
836 #endif
837
838 stop_func_start = 0;
839 stop_func_end = 0;
840 stop_func_name = 0;
841 /* Don't care about return value; stop_func_start and stop_func_name
842 will both be 0 if it doesn't work. */
843 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
844 &stop_func_end);
845 stop_func_start += FUNCTION_START_OFFSET;
846 another_trap = 0;
847 bpstat_clear (&stop_bpstat);
848 stop_step = 0;
849 stop_stack_dummy = 0;
850 stop_print_frame = 1;
851 random_signal = 0;
852 stopped_by_random_signal = 0;
853 breakpoints_failed = 0;
854
855 /* Look at the cause of the stop, and decide what to do.
856 The alternatives are:
857 1) break; to really stop and return to the debugger,
858 2) drop through to start up again
859 (set another_trap to 1 to single step once)
860 3) set random_signal to 1, and the decision between 1 and 2
861 will be made according to the signal handling tables. */
862
863 /* First, distinguish signals caused by the debugger from signals
864 that have to do with the program's own actions.
865 Note that breakpoint insns may cause SIGTRAP or SIGILL
866 or SIGEMT, depending on the operating system version.
867 Here we detect when a SIGILL or SIGEMT is really a breakpoint
868 and change it to SIGTRAP. */
869
870 if (stop_signal == TARGET_SIGNAL_TRAP
871 || (breakpoints_inserted &&
872 (stop_signal == TARGET_SIGNAL_ILL
873 || stop_signal == TARGET_SIGNAL_EMT
874 ))
875 || stop_soon_quietly)
876 {
877 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
878 {
879 stop_print_frame = 0;
880 break;
881 }
882 if (stop_soon_quietly)
883 break;
884
885 /* Don't even think about breakpoints
886 if just proceeded over a breakpoint.
887
888 However, if we are trying to proceed over a breakpoint
889 and end up in sigtramp, then through_sigtramp_breakpoint
890 will be set and we should check whether we've hit the
891 step breakpoint. */
892 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
893 && through_sigtramp_breakpoint == NULL)
894 bpstat_clear (&stop_bpstat);
895 else
896 {
897 /* See if there is a breakpoint at the current PC. */
898 stop_bpstat = bpstat_stop_status
899 (&stop_pc,
900 (DECR_PC_AFTER_BREAK ?
901 /* Notice the case of stepping through a jump
902 that lands just after a breakpoint.
903 Don't confuse that with hitting the breakpoint.
904 What we check for is that 1) stepping is going on
905 and 2) the pc before the last insn does not match
906 the address of the breakpoint before the current pc. */
907 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
908 && CURRENTLY_STEPPING ()) :
909 0)
910 );
911 /* Following in case break condition called a
912 function. */
913 stop_print_frame = 1;
914 }
915
916 if (stop_signal == TARGET_SIGNAL_TRAP)
917 random_signal
918 = !(bpstat_explains_signal (stop_bpstat)
919 || trap_expected
920 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
921 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
922 FRAME_FP (get_current_frame ()))
923 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
924 || (step_range_end && step_resume_breakpoint == NULL));
925 else
926 {
927 random_signal
928 = !(bpstat_explains_signal (stop_bpstat)
929 /* End of a stack dummy. Some systems (e.g. Sony
930 news) give another signal besides SIGTRAP,
931 so check here as well as above. */
932 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
933 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
934 FRAME_FP (get_current_frame ()))
935 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
936 );
937 if (!random_signal)
938 stop_signal = TARGET_SIGNAL_TRAP;
939 }
940 }
941 else
942 random_signal = 1;
943
944 /* For the program's own signals, act according to
945 the signal handling tables. */
946
947 if (random_signal)
948 {
949 /* Signal not for debugging purposes. */
950 int printed = 0;
951
952 stopped_by_random_signal = 1;
953
954 if (signal_print[stop_signal])
955 {
956 printed = 1;
957 target_terminal_ours_for_output ();
958 annotate_signal ();
959 printf_filtered ("\nProgram received signal ");
960 annotate_signal_name ();
961 printf_filtered ("%s", target_signal_to_name (stop_signal));
962 annotate_signal_name_end ();
963 printf_filtered (", ");
964 annotate_signal_string ();
965 printf_filtered ("%s", target_signal_to_string (stop_signal));
966 annotate_signal_string_end ();
967 printf_filtered (".\n");
968 gdb_flush (gdb_stdout);
969 }
970 if (signal_stop[stop_signal])
971 break;
972 /* If not going to stop, give terminal back
973 if we took it away. */
974 else if (printed)
975 target_terminal_inferior ();
976
977 /* Clear the signal if it should not be passed. */
978 if (signal_program[stop_signal] == 0)
979 stop_signal = TARGET_SIGNAL_0;
980
981 /* I'm not sure whether this needs to be check_sigtramp2 or
982 whether it could/should be keep_going. */
983 goto check_sigtramp2;
984 }
985
986 /* Handle cases caused by hitting a breakpoint. */
987 {
988 CORE_ADDR jmp_buf_pc;
989 struct bpstat_what what;
990
991 what = bpstat_what (stop_bpstat);
992
993 if (what.call_dummy)
994 {
995 stop_stack_dummy = 1;
996 #ifdef HP_OS_BUG
997 trap_expected_after_continue = 1;
998 #endif
999 }
1000
1001 switch (what.main_action)
1002 {
1003 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1004 /* If we hit the breakpoint at longjmp, disable it for the
1005 duration of this command. Then, install a temporary
1006 breakpoint at the target of the jmp_buf. */
1007 disable_longjmp_breakpoint();
1008 remove_breakpoints ();
1009 breakpoints_inserted = 0;
1010 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
1011
1012 /* Need to blow away step-resume breakpoint, as it
1013 interferes with us */
1014 if (step_resume_breakpoint != NULL)
1015 {
1016 delete_breakpoint (step_resume_breakpoint);
1017 step_resume_breakpoint = NULL;
1018 }
1019 /* Not sure whether we need to blow this away too, but probably
1020 it is like the step-resume breakpoint. */
1021 if (through_sigtramp_breakpoint != NULL)
1022 {
1023 delete_breakpoint (through_sigtramp_breakpoint);
1024 through_sigtramp_breakpoint = NULL;
1025 }
1026
1027 #if 0
1028 /* FIXME - Need to implement nested temporary breakpoints */
1029 if (step_over_calls > 0)
1030 set_longjmp_resume_breakpoint(jmp_buf_pc,
1031 get_current_frame());
1032 else
1033 #endif /* 0 */
1034 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
1035 handling_longjmp = 1; /* FIXME */
1036 goto keep_going;
1037
1038 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1039 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1040 remove_breakpoints ();
1041 breakpoints_inserted = 0;
1042 #if 0
1043 /* FIXME - Need to implement nested temporary breakpoints */
1044 if (step_over_calls
1045 && (FRAME_FP (get_current_frame ())
1046 INNER_THAN step_frame_address))
1047 {
1048 another_trap = 1;
1049 goto keep_going;
1050 }
1051 #endif /* 0 */
1052 disable_longjmp_breakpoint();
1053 handling_longjmp = 0; /* FIXME */
1054 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1055 break;
1056 /* else fallthrough */
1057
1058 case BPSTAT_WHAT_SINGLE:
1059 if (breakpoints_inserted)
1060 remove_breakpoints ();
1061 breakpoints_inserted = 0;
1062 another_trap = 1;
1063 /* Still need to check other stuff, at least the case
1064 where we are stepping and step out of the right range. */
1065 break;
1066
1067 case BPSTAT_WHAT_STOP_NOISY:
1068 stop_print_frame = 1;
1069
1070 /* We are about to nuke the step_resume_breakpoint and
1071 through_sigtramp_breakpoint via the cleanup chain, so
1072 no need to worry about it here. */
1073
1074 goto stop_stepping;
1075
1076 case BPSTAT_WHAT_STOP_SILENT:
1077 stop_print_frame = 0;
1078
1079 /* We are about to nuke the step_resume_breakpoint and
1080 through_sigtramp_breakpoint via the cleanup chain, so
1081 no need to worry about it here. */
1082
1083 goto stop_stepping;
1084
1085 case BPSTAT_WHAT_STEP_RESUME:
1086 delete_breakpoint (step_resume_breakpoint);
1087 step_resume_breakpoint = NULL;
1088 break;
1089
1090 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
1091 if (through_sigtramp_breakpoint)
1092 delete_breakpoint (through_sigtramp_breakpoint);
1093 through_sigtramp_breakpoint = NULL;
1094
1095 /* If were waiting for a trap, hitting the step_resume_break
1096 doesn't count as getting it. */
1097 if (trap_expected)
1098 another_trap = 1;
1099 break;
1100
1101 case BPSTAT_WHAT_CHECK_SHLIBS:
1102 #ifdef SOLIB_ADD
1103 {
1104 extern int auto_solib_add;
1105
1106 /* Remove breakpoints, we eventually want to step over the
1107 shlib event breakpoint, and SOLIB_ADD might adjust
1108 breakpoint addresses via breakpoint_re_set. */
1109 if (breakpoints_inserted)
1110 remove_breakpoints ();
1111 breakpoints_inserted = 0;
1112
1113 /* Check for any newly added shared libraries if we're
1114 supposed to be adding them automatically. */
1115 if (auto_solib_add)
1116 {
1117 /* Switch terminal for any messages produced by
1118 breakpoint_re_set. */
1119 target_terminal_ours_for_output ();
1120 SOLIB_ADD (NULL, 0, NULL);
1121 target_terminal_inferior ();
1122 }
1123
1124 /* Try to reenable shared library breakpoints, additional
1125 code segments in shared libraries might be mapped in now. */
1126 re_enable_breakpoints_in_shlibs ();
1127
1128 /* If requested, stop when the dynamic linker notifies
1129 gdb of events. This allows the user to get control
1130 and place breakpoints in initializer routines for
1131 dynamically loaded objects (among other things). */
1132 if (stop_on_solib_events)
1133 {
1134 stop_print_frame = 0;
1135 goto stop_stepping;
1136 }
1137 else
1138 {
1139 /* We want to step over this breakpoint, then keep going. */
1140 another_trap = 1;
1141 break;
1142 }
1143 }
1144 #endif
1145 break;
1146
1147 case BPSTAT_WHAT_LAST:
1148 /* Not a real code, but listed here to shut up gcc -Wall. */
1149
1150 case BPSTAT_WHAT_KEEP_CHECKING:
1151 break;
1152 }
1153 }
1154
1155 /* We come here if we hit a breakpoint but should not
1156 stop for it. Possibly we also were stepping
1157 and should stop for that. So fall through and
1158 test for stepping. But, if not stepping,
1159 do not stop. */
1160
1161 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1162 /* This is the old way of detecting the end of the stack dummy.
1163 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
1164 handled above. As soon as we can test it on all of them, all
1165 architectures should define it. */
1166
1167 /* If this is the breakpoint at the end of a stack dummy,
1168 just stop silently, unless the user was doing an si/ni, in which
1169 case she'd better know what she's doing. */
1170
1171 if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ()))
1172 && !step_range_end)
1173 {
1174 stop_print_frame = 0;
1175 stop_stack_dummy = 1;
1176 #ifdef HP_OS_BUG
1177 trap_expected_after_continue = 1;
1178 #endif
1179 break;
1180 }
1181 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1182
1183 if (step_resume_breakpoint)
1184 /* Having a step-resume breakpoint overrides anything
1185 else having to do with stepping commands until
1186 that breakpoint is reached. */
1187 /* I'm not sure whether this needs to be check_sigtramp2 or
1188 whether it could/should be keep_going. */
1189 goto check_sigtramp2;
1190
1191 if (step_range_end == 0)
1192 /* Likewise if we aren't even stepping. */
1193 /* I'm not sure whether this needs to be check_sigtramp2 or
1194 whether it could/should be keep_going. */
1195 goto check_sigtramp2;
1196
1197 /* If stepping through a line, keep going if still within it. */
1198 if (stop_pc >= step_range_start
1199 && stop_pc < step_range_end
1200 #if 0
1201 /* I haven't a clue what might trigger this clause, and it seems wrong anyway,
1202 so I've disabled it until someone complains. -Stu 10/24/95 */
1203
1204 /* The step range might include the start of the
1205 function, so if we are at the start of the
1206 step range and either the stack or frame pointers
1207 just changed, we've stepped outside */
1208 && !(stop_pc == step_range_start
1209 && FRAME_FP (get_current_frame ())
1210 && (read_sp () INNER_THAN step_sp
1211 || FRAME_FP (get_current_frame ()) != step_frame_address))
1212 #endif
1213 )
1214 {
1215 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
1216 So definately need to check for sigtramp here. */
1217 goto check_sigtramp2;
1218 }
1219
1220 /* We stepped out of the stepping range. */
1221
1222 /* If we are stepping at the source level and entered the runtime
1223 loader dynamic symbol resolution code, we keep on single stepping
1224 until we exit the run time loader code and reach the callee's
1225 address. */
1226 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
1227 goto keep_going;
1228
1229 /* We can't update step_sp every time through the loop, because
1230 reading the stack pointer would slow down stepping too much.
1231 But we can update it every time we leave the step range. */
1232 update_step_sp = 1;
1233
1234 /* Did we just take a signal? */
1235 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1236 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1237 && read_sp () INNER_THAN step_sp)
1238 {
1239 /* We've just taken a signal; go until we are back to
1240 the point where we took it and one more. */
1241
1242 /* This code is needed at least in the following case:
1243 The user types "next" and then a signal arrives (before
1244 the "next" is done). */
1245
1246 /* Note that if we are stopped at a breakpoint, then we need
1247 the step_resume breakpoint to override any breakpoints at
1248 the same location, so that we will still step over the
1249 breakpoint even though the signal happened. */
1250
1251 {
1252 struct symtab_and_line sr_sal;
1253
1254 INIT_SAL (&sr_sal); /* initialize to zeroes */
1255 sr_sal.pc = prev_pc;
1256 sr_sal.section = find_pc_overlay (sr_sal.pc);
1257 /* We could probably be setting the frame to
1258 step_frame_address; I don't think anyone thought to try it. */
1259 step_resume_breakpoint =
1260 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1261 if (breakpoints_inserted)
1262 insert_breakpoints ();
1263 }
1264
1265 /* If this is stepi or nexti, make sure that the stepping range
1266 gets us past that instruction. */
1267 if (step_range_end == 1)
1268 /* FIXME: Does this run afoul of the code below which, if
1269 we step into the middle of a line, resets the stepping
1270 range? */
1271 step_range_end = (step_range_start = prev_pc) + 1;
1272
1273 remove_breakpoints_on_following_step = 1;
1274 goto keep_going;
1275 }
1276
1277 #if 0
1278 /* I disabled this test because it was too complicated and slow. The
1279 SKIP_PROLOGUE was especially slow, because it caused unnecessary
1280 prologue examination on various architectures. The code in the #else
1281 clause has been tested on the Sparc, Mips, PA, and Power
1282 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */
1283
1284 /* See if we left the step range due to a subroutine call that
1285 we should proceed to the end of. */
1286
1287 if (stop_func_start)
1288 {
1289 struct symtab *s;
1290
1291 /* Do this after the IN_SIGTRAMP check; it might give
1292 an error. */
1293 prologue_pc = stop_func_start;
1294
1295 /* Don't skip the prologue if this is assembly source */
1296 s = find_pc_symtab (stop_pc);
1297 if (s && s->language != language_asm)
1298 SKIP_PROLOGUE (prologue_pc);
1299 }
1300
1301 if (!(step_sp INNER_THAN read_sp ()) /* don't mistake (sig)return as a call */
1302 && (/* Might be a non-recursive call. If the symbols are missing
1303 enough that stop_func_start == prev_func_start even though
1304 they are really two functions, we will treat some calls as
1305 jumps. */
1306 stop_func_start != prev_func_start
1307
1308 /* Might be a recursive call if either we have a prologue
1309 or the call instruction itself saves the PC on the stack. */
1310 || prologue_pc != stop_func_start
1311 || read_sp () != step_sp)
1312 && (/* PC is completely out of bounds of any known objfiles. Treat
1313 like a subroutine call. */
1314 ! stop_func_start
1315
1316 /* If we do a call, we will be at the start of a function... */
1317 || stop_pc == stop_func_start
1318
1319 /* ...except on the Alpha with -O (and also Irix 5 and
1320 perhaps others), in which we might call the address
1321 after the load of gp. Since prologues don't contain
1322 calls, we can't return to within one, and we don't
1323 jump back into them, so this check is OK. */
1324
1325 || stop_pc < prologue_pc
1326
1327 /* ...and if it is a leaf function, the prologue might
1328 consist of gp loading only, so the call transfers to
1329 the first instruction after the prologue. */
1330 || (stop_pc == prologue_pc
1331
1332 /* Distinguish this from the case where we jump back
1333 to the first instruction after the prologue,
1334 within a function. */
1335 && stop_func_start != prev_func_start)
1336
1337 /* If we end up in certain places, it means we did a subroutine
1338 call. I'm not completely sure this is necessary now that we
1339 have the above checks with stop_func_start (and now that
1340 find_pc_partial_function is pickier). */
1341 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1342
1343 /* If none of the above apply, it is a jump within a function,
1344 or a return from a subroutine. The other case is longjmp,
1345 which can no longer happen here as long as the
1346 handling_longjmp stuff is working. */
1347 ))
1348 #else
1349 /* This test is a much more streamlined, (but hopefully correct)
1350 replacement for the code above. It's been tested on the Sparc,
1351 Mips, PA, and Power architectures with good results. */
1352
1353 if (stop_pc == stop_func_start /* Quick test */
1354 || in_prologue (stop_pc, stop_func_start)
1355 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1356 || stop_func_start == 0)
1357 #endif
1358
1359 {
1360 /* It's a subroutine call. */
1361
1362 if (step_over_calls == 0)
1363 {
1364 /* I presume that step_over_calls is only 0 when we're
1365 supposed to be stepping at the assembly language level
1366 ("stepi"). Just stop. */
1367 stop_step = 1;
1368 break;
1369 }
1370
1371 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
1372 /* We're doing a "next". */
1373 goto step_over_function;
1374
1375 /* If we are in a function call trampoline (a stub between
1376 the calling routine and the real function), locate the real
1377 function. That's what tells us (a) whether we want to step
1378 into it at all, and (b) what prologue we want to run to
1379 the end of, if we do step into it. */
1380 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1381 if (tmp != 0)
1382 stop_func_start = tmp;
1383 else
1384 {
1385 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
1386 if (tmp)
1387 {
1388 struct symtab_and_line xxx;
1389 /* Why isn't this s_a_l called "sr_sal", like all of the
1390 other s_a_l's where this code is duplicated? */
1391 INIT_SAL (&xxx); /* initialize to zeroes */
1392 xxx.pc = tmp;
1393 xxx.section = find_pc_overlay (xxx.pc);
1394 step_resume_breakpoint =
1395 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
1396 insert_breakpoints ();
1397 goto keep_going;
1398 }
1399 }
1400
1401 /* If we have line number information for the function we
1402 are thinking of stepping into, step into it.
1403
1404 If there are several symtabs at that PC (e.g. with include
1405 files), just want to know whether *any* of them have line
1406 numbers. find_pc_line handles this. */
1407 {
1408 struct symtab_and_line tmp_sal;
1409
1410 tmp_sal = find_pc_line (stop_func_start, 0);
1411 if (tmp_sal.line != 0)
1412 goto step_into_function;
1413 }
1414
1415 step_over_function:
1416 /* A subroutine call has happened. */
1417 {
1418 /* Set a special breakpoint after the return */
1419 struct symtab_and_line sr_sal;
1420
1421 INIT_SAL (&sr_sal); /* initialize to zeroes */
1422 sr_sal.pc =
1423 ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
1424 sr_sal.section = find_pc_overlay (sr_sal.pc);
1425 step_resume_breakpoint =
1426 set_momentary_breakpoint (sr_sal, get_current_frame (),
1427 bp_step_resume);
1428 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
1429 step_resume_breakpoint->frame = step_frame_address;
1430 if (breakpoints_inserted)
1431 insert_breakpoints ();
1432 }
1433 goto keep_going;
1434
1435 step_into_function:
1436 /* Subroutine call with source code we should not step over.
1437 Do step to the first line of code in it. */
1438 {
1439 struct symtab *s;
1440
1441 s = find_pc_symtab (stop_pc);
1442 if (s && s->language != language_asm)
1443 SKIP_PROLOGUE (stop_func_start);
1444 }
1445 sal = find_pc_line (stop_func_start, 0);
1446 /* Use the step_resume_break to step until
1447 the end of the prologue, even if that involves jumps
1448 (as it seems to on the vax under 4.2). */
1449 /* If the prologue ends in the middle of a source line,
1450 continue to the end of that source line (if it is still
1451 within the function). Otherwise, just go to end of prologue. */
1452 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1453 /* no, don't either. It skips any code that's
1454 legitimately on the first line. */
1455 #else
1456 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
1457 stop_func_start = sal.end;
1458 #endif
1459
1460 if (stop_func_start == stop_pc)
1461 {
1462 /* We are already there: stop now. */
1463 stop_step = 1;
1464 break;
1465 }
1466 else
1467 /* Put the step-breakpoint there and go until there. */
1468 {
1469 struct symtab_and_line sr_sal;
1470
1471 INIT_SAL (&sr_sal); /* initialize to zeroes */
1472 sr_sal.pc = stop_func_start;
1473 sr_sal.section = find_pc_overlay (stop_func_start);
1474 /* Do not specify what the fp should be when we stop
1475 since on some machines the prologue
1476 is where the new fp value is established. */
1477 step_resume_breakpoint =
1478 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1479 if (breakpoints_inserted)
1480 insert_breakpoints ();
1481
1482 /* And make sure stepping stops right away then. */
1483 step_range_end = step_range_start;
1484 }
1485 goto keep_going;
1486 }
1487
1488 /* We've wandered out of the step range. */
1489
1490 sal = find_pc_line(stop_pc, 0);
1491
1492 if (step_range_end == 1)
1493 {
1494 /* It is stepi or nexti. We always want to stop stepping after
1495 one instruction. */
1496 stop_step = 1;
1497 break;
1498 }
1499
1500 /* If we're in the return path from a shared library trampoline,
1501 we want to proceed through the trampoline when stepping. */
1502 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
1503 {
1504 CORE_ADDR tmp;
1505
1506 /* Determine where this trampoline returns. */
1507 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1508
1509 /* Only proceed through if we know where it's going. */
1510 if (tmp)
1511 {
1512 /* And put the step-breakpoint there and go until there. */
1513 struct symtab_and_line sr_sal;
1514
1515 INIT_SAL (&sr_sal); /* initialize to zeroes */
1516 sr_sal.pc = tmp;
1517 sr_sal.section = find_pc_overlay (sr_sal.pc);
1518 /* Do not specify what the fp should be when we stop
1519 since on some machines the prologue
1520 is where the new fp value is established. */
1521 step_resume_breakpoint =
1522 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1523 if (breakpoints_inserted)
1524 insert_breakpoints ();
1525
1526 /* Restart without fiddling with the step ranges or
1527 other state. */
1528 goto keep_going;
1529 }
1530 }
1531
1532 if (sal.line == 0)
1533 {
1534 /* We have no line number information. That means to stop
1535 stepping (does this always happen right after one instruction,
1536 when we do "s" in a function with no line numbers,
1537 or can this happen as a result of a return or longjmp?). */
1538 stop_step = 1;
1539 break;
1540 }
1541
1542 if (stop_pc == sal.pc
1543 && (current_line != sal.line || current_symtab != sal.symtab))
1544 {
1545 /* We are at the start of a different line. So stop. Note that
1546 we don't stop if we step into the middle of a different line.
1547 That is said to make things like for (;;) statements work
1548 better. */
1549 stop_step = 1;
1550 break;
1551 }
1552
1553 /* We aren't done stepping.
1554
1555 Optimize by setting the stepping range to the line.
1556 (We might not be in the original line, but if we entered a
1557 new line in mid-statement, we continue stepping. This makes
1558 things like for(;;) statements work better.) */
1559
1560 if (stop_func_end && sal.end >= stop_func_end)
1561 {
1562 /* If this is the last line of the function, don't keep stepping
1563 (it would probably step us out of the function).
1564 This is particularly necessary for a one-line function,
1565 in which after skipping the prologue we better stop even though
1566 we will be in mid-line. */
1567 stop_step = 1;
1568 break;
1569 }
1570 step_range_start = sal.pc;
1571 step_range_end = sal.end;
1572 step_frame_address = FRAME_FP (get_current_frame ());
1573 current_line = sal.line;
1574 current_symtab = sal.symtab;
1575 goto keep_going;
1576
1577 check_sigtramp2:
1578 if (trap_expected
1579 && IN_SIGTRAMP (stop_pc, stop_func_name)
1580 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1581 && read_sp () INNER_THAN step_sp)
1582 {
1583 /* What has happened here is that we have just stepped the inferior
1584 with a signal (because it is a signal which shouldn't make
1585 us stop), thus stepping into sigtramp.
1586
1587 So we need to set a step_resume_break_address breakpoint
1588 and continue until we hit it, and then step. FIXME: This should
1589 be more enduring than a step_resume breakpoint; we should know
1590 that we will later need to keep going rather than re-hitting
1591 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1592 it says "exceedingly difficult"). */
1593 struct symtab_and_line sr_sal;
1594
1595 INIT_SAL (&sr_sal); /* initialize to zeroes */
1596 sr_sal.pc = prev_pc;
1597 sr_sal.section = find_pc_overlay (sr_sal.pc);
1598 /* We perhaps could set the frame if we kept track of what
1599 the frame corresponding to prev_pc was. But we don't,
1600 so don't. */
1601 through_sigtramp_breakpoint =
1602 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
1603 if (breakpoints_inserted)
1604 insert_breakpoints ();
1605
1606 remove_breakpoints_on_following_step = 1;
1607 another_trap = 1;
1608 }
1609
1610 keep_going:
1611 /* Come to this label when you need to resume the inferior.
1612 It's really much cleaner to do a goto than a maze of if-else
1613 conditions. */
1614
1615 /* Save the pc before execution, to compare with pc after stop. */
1616 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1617 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1618 BREAK is defined, the
1619 original pc would not have
1620 been at the start of a
1621 function. */
1622 prev_func_name = stop_func_name;
1623
1624 if (update_step_sp)
1625 step_sp = read_sp ();
1626 update_step_sp = 0;
1627
1628 /* If we did not do break;, it means we should keep
1629 running the inferior and not return to debugger. */
1630
1631 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
1632 {
1633 /* We took a signal (which we are supposed to pass through to
1634 the inferior, else we'd have done a break above) and we
1635 haven't yet gotten our trap. Simply continue. */
1636 resume (CURRENTLY_STEPPING (), stop_signal);
1637 }
1638 else
1639 {
1640 /* Either the trap was not expected, but we are continuing
1641 anyway (the user asked that this signal be passed to the
1642 child)
1643 -- or --
1644 The signal was SIGTRAP, e.g. it was our signal, but we
1645 decided we should resume from it.
1646
1647 We're going to run this baby now!
1648
1649 Insert breakpoints now, unless we are trying
1650 to one-proceed past a breakpoint. */
1651 /* If we've just finished a special step resume and we don't
1652 want to hit a breakpoint, pull em out. */
1653 if (step_resume_breakpoint == NULL
1654 && through_sigtramp_breakpoint == NULL
1655 && remove_breakpoints_on_following_step)
1656 {
1657 remove_breakpoints_on_following_step = 0;
1658 remove_breakpoints ();
1659 breakpoints_inserted = 0;
1660 }
1661 else if (!breakpoints_inserted &&
1662 (through_sigtramp_breakpoint != NULL || !another_trap))
1663 {
1664 breakpoints_failed = insert_breakpoints ();
1665 if (breakpoints_failed)
1666 break;
1667 breakpoints_inserted = 1;
1668 }
1669
1670 trap_expected = another_trap;
1671
1672 if (stop_signal == TARGET_SIGNAL_TRAP)
1673 stop_signal = TARGET_SIGNAL_0;
1674
1675 #ifdef SHIFT_INST_REGS
1676 /* I'm not sure when this following segment applies. I do know, now,
1677 that we shouldn't rewrite the regs when we were stopped by a
1678 random signal from the inferior process. */
1679 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1680 (this is only used on the 88k). */
1681
1682 if (!bpstat_explains_signal (stop_bpstat)
1683 && (stop_signal != TARGET_SIGNAL_CHLD)
1684 && !stopped_by_random_signal)
1685 SHIFT_INST_REGS();
1686 #endif /* SHIFT_INST_REGS */
1687
1688 resume (CURRENTLY_STEPPING (), stop_signal);
1689 }
1690 }
1691
1692 stop_stepping:
1693 if (target_has_execution)
1694 {
1695 /* Assuming the inferior still exists, set these up for next
1696 time, just like we did above if we didn't break out of the
1697 loop. */
1698 prev_pc = read_pc ();
1699 prev_func_start = stop_func_start;
1700 prev_func_name = stop_func_name;
1701 }
1702 do_cleanups (old_cleanups);
1703 }
1704 \f
1705 /* Here to return control to GDB when the inferior stops for real.
1706 Print appropriate messages, remove breakpoints, give terminal our modes.
1707
1708 STOP_PRINT_FRAME nonzero means print the executing frame
1709 (pc, function, args, file, line number and line text).
1710 BREAKPOINTS_FAILED nonzero means stop was due to error
1711 attempting to insert breakpoints. */
1712
1713 void
1714 normal_stop ()
1715 {
1716 /* Make sure that the current_frame's pc is correct. This
1717 is a correction for setting up the frame info before doing
1718 DECR_PC_AFTER_BREAK */
1719 if (target_has_execution && get_current_frame())
1720 (get_current_frame ())->pc = read_pc ();
1721
1722 if (breakpoints_failed)
1723 {
1724 target_terminal_ours_for_output ();
1725 print_sys_errmsg ("ptrace", breakpoints_failed);
1726 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1727 The same program may be running in another process.\n");
1728 }
1729
1730 if (target_has_execution && breakpoints_inserted)
1731 if (remove_breakpoints ())
1732 {
1733 target_terminal_ours_for_output ();
1734 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1735 It might be running in another process.\n\
1736 Further execution is probably impossible.\n");
1737 }
1738
1739 breakpoints_inserted = 0;
1740
1741 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1742 Delete any breakpoint that is to be deleted at the next stop. */
1743
1744 breakpoint_auto_delete (stop_bpstat);
1745
1746 /* If an auto-display called a function and that got a signal,
1747 delete that auto-display to avoid an infinite recursion. */
1748
1749 if (stopped_by_random_signal)
1750 disable_current_display ();
1751
1752 if (step_multi && stop_step)
1753 goto done;
1754
1755 target_terminal_ours ();
1756
1757 if (stop_bpstat
1758 && stop_bpstat->breakpoint_at
1759 && stop_bpstat->breakpoint_at->type == bp_shlib_event)
1760 printf_filtered ("Stopped due to shared library event\n");
1761
1762 /* Look up the hook_stop and run it if it exists. */
1763
1764 if (stop_command->hook)
1765 {
1766 catch_errors (hook_stop_stub, (char *)stop_command->hook,
1767 "Error while running hook_stop:\n", RETURN_MASK_ALL);
1768 }
1769
1770 if (!target_has_stack)
1771 goto done;
1772
1773 /* Select innermost stack frame except on return from a stack dummy routine,
1774 or if the program has exited. Print it without a level number if
1775 we have changed functions or hit a breakpoint. Print source line
1776 if we have one. */
1777 if (!stop_stack_dummy)
1778 {
1779 select_frame (get_current_frame (), 0);
1780
1781 if (stop_print_frame)
1782 {
1783 int source_only;
1784
1785 source_only = bpstat_print (stop_bpstat);
1786 source_only = source_only ||
1787 ( stop_step
1788 && step_frame_address == FRAME_FP (get_current_frame ())
1789 && step_start_function == find_pc_function (stop_pc));
1790
1791 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1792
1793 /* Display the auto-display expressions. */
1794 do_displays ();
1795 }
1796 }
1797
1798 /* Save the function value return registers, if we care.
1799 We might be about to restore their previous contents. */
1800 if (proceed_to_finish)
1801 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1802
1803 if (stop_stack_dummy)
1804 {
1805 /* Pop the empty frame that contains the stack dummy.
1806 POP_FRAME ends with a setting of the current frame, so we
1807 can use that next. */
1808 POP_FRAME;
1809 /* Set stop_pc to what it was before we called the function. Can't rely
1810 on restore_inferior_status because that only gets called if we don't
1811 stop in the called function. */
1812 stop_pc = read_pc();
1813 select_frame (get_current_frame (), 0);
1814 }
1815 done:
1816 annotate_stopped ();
1817 }
1818
1819 static int
1820 hook_stop_stub (cmd)
1821 char *cmd;
1822 {
1823 execute_user_command ((struct cmd_list_element *)cmd, 0);
1824 return (0);
1825 }
1826 \f
1827 int signal_stop_state (signo)
1828 int signo;
1829 {
1830 return signal_stop[signo];
1831 }
1832
1833 int signal_print_state (signo)
1834 int signo;
1835 {
1836 return signal_print[signo];
1837 }
1838
1839 int signal_pass_state (signo)
1840 int signo;
1841 {
1842 return signal_program[signo];
1843 }
1844
1845 static void
1846 sig_print_header ()
1847 {
1848 printf_filtered ("\
1849 Signal Stop\tPrint\tPass to program\tDescription\n");
1850 }
1851
1852 static void
1853 sig_print_info (oursig)
1854 enum target_signal oursig;
1855 {
1856 char *name = target_signal_to_name (oursig);
1857 int name_padding = 13 - strlen (name);
1858 if (name_padding <= 0)
1859 name_padding = 0;
1860
1861 printf_filtered ("%s", name);
1862 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
1863 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
1864 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
1865 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
1866 printf_filtered ("%s\n", target_signal_to_string (oursig));
1867 }
1868
1869 /* Specify how various signals in the inferior should be handled. */
1870
1871 static void
1872 handle_command (args, from_tty)
1873 char *args;
1874 int from_tty;
1875 {
1876 char **argv;
1877 int digits, wordlen;
1878 int sigfirst, signum, siglast;
1879 enum target_signal oursig;
1880 int allsigs;
1881 int nsigs;
1882 unsigned char *sigs;
1883 struct cleanup *old_chain;
1884
1885 if (args == NULL)
1886 {
1887 error_no_arg ("signal to handle");
1888 }
1889
1890 /* Allocate and zero an array of flags for which signals to handle. */
1891
1892 nsigs = (int)TARGET_SIGNAL_LAST;
1893 sigs = (unsigned char *) alloca (nsigs);
1894 memset (sigs, 0, nsigs);
1895
1896 /* Break the command line up into args. */
1897
1898 argv = buildargv (args);
1899 if (argv == NULL)
1900 {
1901 nomem (0);
1902 }
1903 old_chain = make_cleanup (freeargv, (char *) argv);
1904
1905 /* Walk through the args, looking for signal oursigs, signal names, and
1906 actions. Signal numbers and signal names may be interspersed with
1907 actions, with the actions being performed for all signals cumulatively
1908 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1909
1910 while (*argv != NULL)
1911 {
1912 wordlen = strlen (*argv);
1913 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1914 allsigs = 0;
1915 sigfirst = siglast = -1;
1916
1917 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1918 {
1919 /* Apply action to all signals except those used by the
1920 debugger. Silently skip those. */
1921 allsigs = 1;
1922 sigfirst = 0;
1923 siglast = nsigs - 1;
1924 }
1925 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1926 {
1927 SET_SIGS (nsigs, sigs, signal_stop);
1928 SET_SIGS (nsigs, sigs, signal_print);
1929 }
1930 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1931 {
1932 UNSET_SIGS (nsigs, sigs, signal_program);
1933 }
1934 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1935 {
1936 SET_SIGS (nsigs, sigs, signal_print);
1937 }
1938 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1939 {
1940 SET_SIGS (nsigs, sigs, signal_program);
1941 }
1942 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1943 {
1944 UNSET_SIGS (nsigs, sigs, signal_stop);
1945 }
1946 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1947 {
1948 SET_SIGS (nsigs, sigs, signal_program);
1949 }
1950 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1951 {
1952 UNSET_SIGS (nsigs, sigs, signal_print);
1953 UNSET_SIGS (nsigs, sigs, signal_stop);
1954 }
1955 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1956 {
1957 UNSET_SIGS (nsigs, sigs, signal_program);
1958 }
1959 else if (digits > 0)
1960 {
1961 /* It is numeric. The numeric signal refers to our own internal
1962 signal numbering from target.h, not to host/target signal number.
1963 This is a feature; users really should be using symbolic names
1964 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1965 will work right anyway. */
1966
1967 sigfirst = siglast = (int) target_signal_from_command (atoi (*argv));
1968 if ((*argv)[digits] == '-')
1969 {
1970 siglast =
1971 (int) target_signal_from_command (atoi ((*argv) + digits + 1));
1972 }
1973 if (sigfirst > siglast)
1974 {
1975 /* Bet he didn't figure we'd think of this case... */
1976 signum = sigfirst;
1977 sigfirst = siglast;
1978 siglast = signum;
1979 }
1980 }
1981 else
1982 {
1983 oursig = target_signal_from_name (*argv);
1984 if (oursig != TARGET_SIGNAL_UNKNOWN)
1985 {
1986 sigfirst = siglast = (int)oursig;
1987 }
1988 else
1989 {
1990 /* Not a number and not a recognized flag word => complain. */
1991 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
1992 }
1993 }
1994
1995 /* If any signal numbers or symbol names were found, set flags for
1996 which signals to apply actions to. */
1997
1998 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
1999 {
2000 switch ((enum target_signal)signum)
2001 {
2002 case TARGET_SIGNAL_TRAP:
2003 case TARGET_SIGNAL_INT:
2004 if (!allsigs && !sigs[signum])
2005 {
2006 if (query ("%s is used by the debugger.\n\
2007 Are you sure you want to change it? ",
2008 target_signal_to_name
2009 ((enum target_signal)signum)))
2010 {
2011 sigs[signum] = 1;
2012 }
2013 else
2014 {
2015 printf_unfiltered ("Not confirmed, unchanged.\n");
2016 gdb_flush (gdb_stdout);
2017 }
2018 }
2019 break;
2020 case TARGET_SIGNAL_0:
2021 case TARGET_SIGNAL_DEFAULT:
2022 case TARGET_SIGNAL_UNKNOWN:
2023 /* Make sure that "all" doesn't print these. */
2024 break;
2025 default:
2026 sigs[signum] = 1;
2027 break;
2028 }
2029 }
2030
2031 argv++;
2032 }
2033
2034 target_notice_signals(inferior_pid);
2035
2036 if (from_tty)
2037 {
2038 /* Show the results. */
2039 sig_print_header ();
2040 for (signum = 0; signum < nsigs; signum++)
2041 {
2042 if (sigs[signum])
2043 {
2044 sig_print_info (signum);
2045 }
2046 }
2047 }
2048
2049 do_cleanups (old_chain);
2050 }
2051
2052 /* Print current contents of the tables set by the handle command.
2053 It is possible we should just be printing signals actually used
2054 by the current target (but for things to work right when switching
2055 targets, all signals should be in the signal tables). */
2056
2057 static void
2058 signals_info (signum_exp, from_tty)
2059 char *signum_exp;
2060 int from_tty;
2061 {
2062 enum target_signal oursig;
2063 sig_print_header ();
2064
2065 if (signum_exp)
2066 {
2067 /* First see if this is a symbol name. */
2068 oursig = target_signal_from_name (signum_exp);
2069 if (oursig == TARGET_SIGNAL_UNKNOWN)
2070 {
2071 /* No, try numeric. */
2072 oursig =
2073 target_signal_from_command (parse_and_eval_address (signum_exp));
2074 }
2075 sig_print_info (oursig);
2076 return;
2077 }
2078
2079 printf_filtered ("\n");
2080 /* These ugly casts brought to you by the native VAX compiler. */
2081 for (oursig = TARGET_SIGNAL_FIRST;
2082 (int)oursig < (int)TARGET_SIGNAL_LAST;
2083 oursig = (enum target_signal)((int)oursig + 1))
2084 {
2085 QUIT;
2086
2087 if (oursig != TARGET_SIGNAL_UNKNOWN
2088 && oursig != TARGET_SIGNAL_DEFAULT
2089 && oursig != TARGET_SIGNAL_0)
2090 sig_print_info (oursig);
2091 }
2092
2093 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
2094 }
2095 \f
2096 /* Save all of the information associated with the inferior<==>gdb
2097 connection. INF_STATUS is a pointer to a "struct inferior_status"
2098 (defined in inferior.h). */
2099
2100 void
2101 save_inferior_status (inf_status, restore_stack_info)
2102 struct inferior_status *inf_status;
2103 int restore_stack_info;
2104 {
2105 inf_status->stop_signal = stop_signal;
2106 inf_status->stop_pc = stop_pc;
2107 inf_status->stop_step = stop_step;
2108 inf_status->stop_stack_dummy = stop_stack_dummy;
2109 inf_status->stopped_by_random_signal = stopped_by_random_signal;
2110 inf_status->trap_expected = trap_expected;
2111 inf_status->step_range_start = step_range_start;
2112 inf_status->step_range_end = step_range_end;
2113 inf_status->step_frame_address = step_frame_address;
2114 inf_status->step_over_calls = step_over_calls;
2115 inf_status->stop_after_trap = stop_after_trap;
2116 inf_status->stop_soon_quietly = stop_soon_quietly;
2117 /* Save original bpstat chain here; replace it with copy of chain.
2118 If caller's caller is walking the chain, they'll be happier if we
2119 hand them back the original chain when restore_i_s is called. */
2120 inf_status->stop_bpstat = stop_bpstat;
2121 stop_bpstat = bpstat_copy (stop_bpstat);
2122 inf_status->breakpoint_proceeded = breakpoint_proceeded;
2123 inf_status->restore_stack_info = restore_stack_info;
2124 inf_status->proceed_to_finish = proceed_to_finish;
2125
2126 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
2127
2128 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2129
2130 record_selected_frame (&(inf_status->selected_frame_address),
2131 &(inf_status->selected_level));
2132 return;
2133 }
2134
2135 struct restore_selected_frame_args {
2136 CORE_ADDR frame_address;
2137 int level;
2138 };
2139
2140 static int restore_selected_frame PARAMS ((char *));
2141
2142 /* Restore the selected frame. args is really a struct
2143 restore_selected_frame_args * (declared as char * for catch_errors)
2144 telling us what frame to restore. Returns 1 for success, or 0 for
2145 failure. An error message will have been printed on error. */
2146
2147 static int
2148 restore_selected_frame (args)
2149 char *args;
2150 {
2151 struct restore_selected_frame_args *fr =
2152 (struct restore_selected_frame_args *) args;
2153 struct frame_info *frame;
2154 int level = fr->level;
2155
2156 frame = find_relative_frame (get_current_frame (), &level);
2157
2158 /* If inf_status->selected_frame_address is NULL, there was no
2159 previously selected frame. */
2160 if (frame == NULL ||
2161 FRAME_FP (frame) != fr->frame_address ||
2162 level != 0)
2163 {
2164 warning ("Unable to restore previously selected frame.\n");
2165 return 0;
2166 }
2167 select_frame (frame, fr->level);
2168 return(1);
2169 }
2170
2171 void
2172 restore_inferior_status (inf_status)
2173 struct inferior_status *inf_status;
2174 {
2175 stop_signal = inf_status->stop_signal;
2176 stop_pc = inf_status->stop_pc;
2177 stop_step = inf_status->stop_step;
2178 stop_stack_dummy = inf_status->stop_stack_dummy;
2179 stopped_by_random_signal = inf_status->stopped_by_random_signal;
2180 trap_expected = inf_status->trap_expected;
2181 step_range_start = inf_status->step_range_start;
2182 step_range_end = inf_status->step_range_end;
2183 step_frame_address = inf_status->step_frame_address;
2184 step_over_calls = inf_status->step_over_calls;
2185 stop_after_trap = inf_status->stop_after_trap;
2186 stop_soon_quietly = inf_status->stop_soon_quietly;
2187 bpstat_clear (&stop_bpstat);
2188 stop_bpstat = inf_status->stop_bpstat;
2189 breakpoint_proceeded = inf_status->breakpoint_proceeded;
2190 proceed_to_finish = inf_status->proceed_to_finish;
2191
2192 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
2193
2194 /* The inferior can be gone if the user types "print exit(0)"
2195 (and perhaps other times). */
2196 if (target_has_execution)
2197 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2198
2199 /* The inferior can be gone if the user types "print exit(0)"
2200 (and perhaps other times). */
2201
2202 /* FIXME: If we are being called after stopping in a function which
2203 is called from gdb, we should not be trying to restore the
2204 selected frame; it just prints a spurious error message (The
2205 message is useful, however, in detecting bugs in gdb (like if gdb
2206 clobbers the stack)). In fact, should we be restoring the
2207 inferior status at all in that case? . */
2208
2209 if (target_has_stack && inf_status->restore_stack_info)
2210 {
2211 struct restore_selected_frame_args fr;
2212 fr.level = inf_status->selected_level;
2213 fr.frame_address = inf_status->selected_frame_address;
2214 /* The point of catch_errors is that if the stack is clobbered,
2215 walking the stack might encounter a garbage pointer and error()
2216 trying to dereference it. */
2217 if (catch_errors (restore_selected_frame, &fr,
2218 "Unable to restore previously selected frame:\n",
2219 RETURN_MASK_ERROR) == 0)
2220 /* Error in restoring the selected frame. Select the innermost
2221 frame. */
2222 select_frame (get_current_frame (), 0);
2223 }
2224 }
2225
2226 \f
2227 void
2228 _initialize_infrun ()
2229 {
2230 register int i;
2231 register int numsigs;
2232
2233 add_info ("signals", signals_info,
2234 "What debugger does when program gets various signals.\n\
2235 Specify a signal as argument to print info on that signal only.");
2236 add_info_alias ("handle", "signals", 0);
2237
2238 add_com ("handle", class_run, handle_command,
2239 concat ("Specify how to handle a signal.\n\
2240 Args are signals and actions to apply to those signals.\n\
2241 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
2242 from 1-15 are allowed for compatibility with old versions of GDB.\n\
2243 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
2244 The special arg \"all\" is recognized to mean all signals except those\n\
2245 used by the debugger, typically SIGTRAP and SIGINT.\n",
2246 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
2247 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
2248 Stop means reenter debugger if this signal happens (implies print).\n\
2249 Print means print a message if this signal happens.\n\
2250 Pass means let program see this signal; otherwise program doesn't know.\n\
2251 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
2252 Pass and Stop may be combined.", NULL));
2253
2254 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
2255 "There is no `stop' command, but you can set a hook on `stop'.\n\
2256 This allows you to set a list of commands to be run each time execution\n\
2257 of the program stops.", &cmdlist);
2258
2259 numsigs = (int)TARGET_SIGNAL_LAST;
2260 signal_stop = (unsigned char *)
2261 xmalloc (sizeof (signal_stop[0]) * numsigs);
2262 signal_print = (unsigned char *)
2263 xmalloc (sizeof (signal_print[0]) * numsigs);
2264 signal_program = (unsigned char *)
2265 xmalloc (sizeof (signal_program[0]) * numsigs);
2266 for (i = 0; i < numsigs; i++)
2267 {
2268 signal_stop[i] = 1;
2269 signal_print[i] = 1;
2270 signal_program[i] = 1;
2271 }
2272
2273 /* Signals caused by debugger's own actions
2274 should not be given to the program afterwards. */
2275 signal_program[TARGET_SIGNAL_TRAP] = 0;
2276 signal_program[TARGET_SIGNAL_INT] = 0;
2277
2278 /* Signals that are not errors should not normally enter the debugger. */
2279 signal_stop[TARGET_SIGNAL_ALRM] = 0;
2280 signal_print[TARGET_SIGNAL_ALRM] = 0;
2281 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
2282 signal_print[TARGET_SIGNAL_VTALRM] = 0;
2283 signal_stop[TARGET_SIGNAL_PROF] = 0;
2284 signal_print[TARGET_SIGNAL_PROF] = 0;
2285 signal_stop[TARGET_SIGNAL_CHLD] = 0;
2286 signal_print[TARGET_SIGNAL_CHLD] = 0;
2287 signal_stop[TARGET_SIGNAL_IO] = 0;
2288 signal_print[TARGET_SIGNAL_IO] = 0;
2289 signal_stop[TARGET_SIGNAL_POLL] = 0;
2290 signal_print[TARGET_SIGNAL_POLL] = 0;
2291 signal_stop[TARGET_SIGNAL_URG] = 0;
2292 signal_print[TARGET_SIGNAL_URG] = 0;
2293
2294 #ifdef SOLIB_ADD
2295 add_show_from_set
2296 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
2297 (char *) &stop_on_solib_events,
2298 "Set stopping for shared library events.\n\
2299 If nonzero, gdb will give control to the user when the dynamic linker\n\
2300 notifies gdb of shared library events. The most common event of interest\n\
2301 to the user would be loading/unloading of a new library.\n",
2302 &setlist),
2303 &showlist);
2304 #endif
2305 }
This page took 0.086653 seconds and 4 git commands to generate.