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