* configure.in: Check for working mmap, ansi headers, string.h,
[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 "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 "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 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
483 have_waited:
484 #endif
485
486 flush_cached_frames ();
487
488 /* If it's a new process, add it to the thread database */
489
490 if (pid != inferior_pid
491 && !in_thread_list (pid))
492 {
493 fprintf_unfiltered (gdb_stderr, "[New %s]\n", target_pid_to_str (pid));
494 add_thread (pid);
495
496 /* We may want to consider not doing a resume here in order to give
497 the user a chance to play with the new thread. It might be good
498 to make that a user-settable option. */
499
500 /* At this point, all threads are stopped (happens automatically in
501 either the OS or the native code). Therefore we need to continue
502 all threads in order to make progress. */
503
504 target_resume (-1, 0, TARGET_SIGNAL_0);
505 continue;
506 }
507
508 switch (w.kind)
509 {
510 case TARGET_WAITKIND_LOADED:
511 /* Ignore it gracefully. */
512 if (breakpoints_inserted)
513 {
514 mark_breakpoints_out ();
515 insert_breakpoints ();
516 }
517 resume (0, TARGET_SIGNAL_0);
518 continue;
519
520 case TARGET_WAITKIND_SPURIOUS:
521 resume (0, TARGET_SIGNAL_0);
522 continue;
523
524 case TARGET_WAITKIND_EXITED:
525 target_terminal_ours (); /* Must do this before mourn anyway */
526 annotate_exited (w.value.integer);
527 if (w.value.integer)
528 printf_filtered ("\nProgram exited with code 0%o.\n",
529 (unsigned int)w.value.integer);
530 else
531 printf_filtered ("\nProgram exited normally.\n");
532
533 /* Record the exit code in the convenience variable $_exitcode, so
534 that the user can inspect this again later. */
535 set_internalvar (lookup_internalvar ("_exitcode"),
536 value_from_longest (builtin_type_int,
537 (LONGEST) w.value.integer));
538 gdb_flush (gdb_stdout);
539 target_mourn_inferior ();
540 #ifdef NO_SINGLE_STEP
541 one_stepped = 0;
542 #endif
543 stop_print_frame = 0;
544 goto stop_stepping;
545
546 case TARGET_WAITKIND_SIGNALLED:
547 stop_print_frame = 0;
548 stop_signal = w.value.sig;
549 target_terminal_ours (); /* Must do this before mourn anyway */
550 annotate_signalled ();
551
552 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
553 mean it is already dead? This has been here since GDB 2.8, so
554 perhaps it means rms didn't understand unix waitstatuses?
555 For the moment I'm just kludging around this in remote.c
556 rather than trying to change it here --kingdon, 5 Dec 1994. */
557 target_kill (); /* kill mourns as well */
558
559 printf_filtered ("\nProgram terminated with signal ");
560 annotate_signal_name ();
561 printf_filtered ("%s", target_signal_to_name (stop_signal));
562 annotate_signal_name_end ();
563 printf_filtered (", ");
564 annotate_signal_string ();
565 printf_filtered ("%s", target_signal_to_string (stop_signal));
566 annotate_signal_string_end ();
567 printf_filtered (".\n");
568
569 printf_filtered ("The program no longer exists.\n");
570 gdb_flush (gdb_stdout);
571 #ifdef NO_SINGLE_STEP
572 one_stepped = 0;
573 #endif
574 goto stop_stepping;
575
576 case TARGET_WAITKIND_STOPPED:
577 /* This is the only case in which we keep going; the above cases
578 end in a continue or goto. */
579 break;
580 }
581
582 stop_signal = w.value.sig;
583
584 stop_pc = read_pc_pid (pid);
585
586 /* See if a thread hit a thread-specific breakpoint that was meant for
587 another thread. If so, then step that thread past the breakpoint,
588 and continue it. */
589
590 if (stop_signal == TARGET_SIGNAL_TRAP
591 && breakpoints_inserted
592 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
593 {
594 random_signal = 0;
595 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
596 {
597 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
598 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
599
600 remove_breakpoints ();
601 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
602 /* FIXME: What if a signal arrives instead of the single-step
603 happening? */
604
605 if (target_wait_hook)
606 target_wait_hook (pid, &w);
607 else
608 target_wait (pid, &w);
609 insert_breakpoints ();
610
611 /* We need to restart all the threads now. */
612 target_resume (-1, 0, TARGET_SIGNAL_0);
613 continue;
614 }
615 }
616 else
617 random_signal = 1;
618
619 /* See if something interesting happened to the non-current thread. If
620 so, then switch to that thread, and eventually give control back to
621 the user. */
622
623 if (pid != inferior_pid)
624 {
625 int printed = 0;
626
627 /* If it's a random signal for a non-current thread, notify user
628 if he's expressed an interest. */
629
630 if (random_signal
631 && signal_print[stop_signal])
632 {
633 printed = 1;
634 target_terminal_ours_for_output ();
635 printf_filtered ("\nProgram received signal %s, %s.\n",
636 target_signal_to_name (stop_signal),
637 target_signal_to_string (stop_signal));
638 gdb_flush (gdb_stdout);
639 }
640
641 /* If it's not SIGTRAP and not a signal we want to stop for, then
642 continue the thread. */
643
644 if (stop_signal != TARGET_SIGNAL_TRAP
645 && !signal_stop[stop_signal])
646 {
647 if (printed)
648 target_terminal_inferior ();
649
650 /* Clear the signal if it should not be passed. */
651 if (signal_program[stop_signal] == 0)
652 stop_signal = TARGET_SIGNAL_0;
653
654 target_resume (pid, 0, stop_signal);
655 continue;
656 }
657
658 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
659 and fall into the rest of wait_for_inferior(). */
660
661 /* Save infrun state for the old thread. */
662 save_infrun_state (inferior_pid, prev_pc,
663 prev_func_start, prev_func_name,
664 trap_expected, step_resume_breakpoint,
665 through_sigtramp_breakpoint,
666 step_range_start, step_range_end,
667 step_frame_address, handling_longjmp,
668 another_trap);
669
670 inferior_pid = pid;
671
672 /* Load infrun state for the new thread. */
673 load_infrun_state (inferior_pid, &prev_pc,
674 &prev_func_start, &prev_func_name,
675 &trap_expected, &step_resume_breakpoint,
676 &through_sigtramp_breakpoint,
677 &step_range_start, &step_range_end,
678 &step_frame_address, &handling_longjmp,
679 &another_trap);
680 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
681
682 flush_cached_frames ();
683 }
684
685 #ifdef NO_SINGLE_STEP
686 if (one_stepped)
687 single_step (0); /* This actually cleans up the ss */
688 #endif /* NO_SINGLE_STEP */
689
690 /* If PC is pointing at a nullified instruction, then step beyond
691 it so that the user won't be confused when GDB appears to be ready
692 to execute it. */
693
694 if (INSTRUCTION_NULLIFIED)
695 {
696 resume (1, 0);
697 continue;
698 }
699
700 #ifdef HAVE_STEPPABLE_WATCHPOINT
701 /* It may not be necessary to disable the watchpoint to stop over
702 it. For example, the PA can (with some kernel cooperation)
703 single step over a watchpoint without disabling the watchpoint. */
704 if (STOPPED_BY_WATCHPOINT (w))
705 {
706 resume (1, 0);
707 continue;
708 }
709 #endif
710
711 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
712 /* It is far more common to need to disable a watchpoint
713 to step the inferior over it. FIXME. What else might
714 a debug register or page protection watchpoint scheme need
715 here? */
716 if (STOPPED_BY_WATCHPOINT (w))
717 {
718 /* At this point, we are stopped at an instruction which has attempted to write
719 to a piece of memory under control of a watchpoint. The instruction hasn't
720 actually executed yet. If we were to evaluate the watchpoint expression
721 now, we would get the old value, and therefore no change would seem to have
722 occurred.
723
724 In order to make watchpoints work `right', we really need to complete the
725 memory write, and then evaluate the watchpoint expression. The following
726 code does that by removing the watchpoint (actually, all watchpoints and
727 breakpoints), single-stepping the target, re-inserting watchpoints, and then
728 falling through to let normal single-step processing handle proceed. Since
729 this includes evaluating watchpoints, things will come to a stop in the
730 correct manner. */
731
732 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
733
734 remove_breakpoints ();
735 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
736
737 if (target_wait_hook)
738 target_wait_hook (pid, &w);
739 else
740 target_wait (pid, &w);
741 insert_breakpoints ();
742 /* FIXME-maybe: is this cleaner than setting a flag? Does it
743 handle things like signals arriving and other things happening
744 in combination correctly? */
745 goto have_waited;
746 }
747 #endif
748
749 #ifdef HAVE_CONTINUABLE_WATCHPOINT
750 /* It may be possible to simply continue after a watchpoint. */
751 STOPPED_BY_WATCHPOINT (w);
752 #endif
753
754 stop_func_start = 0;
755 stop_func_name = 0;
756 /* Don't care about return value; stop_func_start and stop_func_name
757 will both be 0 if it doesn't work. */
758 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
759 &stop_func_end);
760 stop_func_start += FUNCTION_START_OFFSET;
761 another_trap = 0;
762 bpstat_clear (&stop_bpstat);
763 stop_step = 0;
764 stop_stack_dummy = 0;
765 stop_print_frame = 1;
766 random_signal = 0;
767 stopped_by_random_signal = 0;
768 breakpoints_failed = 0;
769
770 /* Look at the cause of the stop, and decide what to do.
771 The alternatives are:
772 1) break; to really stop and return to the debugger,
773 2) drop through to start up again
774 (set another_trap to 1 to single step once)
775 3) set random_signal to 1, and the decision between 1 and 2
776 will be made according to the signal handling tables. */
777
778 /* First, distinguish signals caused by the debugger from signals
779 that have to do with the program's own actions.
780 Note that breakpoint insns may cause SIGTRAP or SIGILL
781 or SIGEMT, depending on the operating system version.
782 Here we detect when a SIGILL or SIGEMT is really a breakpoint
783 and change it to SIGTRAP. */
784
785 if (stop_signal == TARGET_SIGNAL_TRAP
786 || (breakpoints_inserted &&
787 (stop_signal == TARGET_SIGNAL_ILL
788 || stop_signal == TARGET_SIGNAL_EMT
789 ))
790 || stop_soon_quietly)
791 {
792 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
793 {
794 stop_print_frame = 0;
795 break;
796 }
797 if (stop_soon_quietly)
798 break;
799
800 /* Don't even think about breakpoints
801 if just proceeded over a breakpoint.
802
803 However, if we are trying to proceed over a breakpoint
804 and end up in sigtramp, then through_sigtramp_breakpoint
805 will be set and we should check whether we've hit the
806 step breakpoint. */
807 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
808 && through_sigtramp_breakpoint == NULL)
809 bpstat_clear (&stop_bpstat);
810 else
811 {
812 /* See if there is a breakpoint at the current PC. */
813 stop_bpstat = bpstat_stop_status
814 (&stop_pc,
815 #if DECR_PC_AFTER_BREAK
816 /* Notice the case of stepping through a jump
817 that lands just after a breakpoint.
818 Don't confuse that with hitting the breakpoint.
819 What we check for is that 1) stepping is going on
820 and 2) the pc before the last insn does not match
821 the address of the breakpoint before the current pc. */
822 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
823 && CURRENTLY_STEPPING ())
824 #else /* DECR_PC_AFTER_BREAK zero */
825 0
826 #endif /* DECR_PC_AFTER_BREAK zero */
827 );
828 /* Following in case break condition called a
829 function. */
830 stop_print_frame = 1;
831 }
832
833 if (stop_signal == TARGET_SIGNAL_TRAP)
834 random_signal
835 = !(bpstat_explains_signal (stop_bpstat)
836 || trap_expected
837 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
838 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
839 FRAME_FP (get_current_frame ()))
840 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
841 || (step_range_end && step_resume_breakpoint == NULL));
842 else
843 {
844 random_signal
845 = !(bpstat_explains_signal (stop_bpstat)
846 /* End of a stack dummy. Some systems (e.g. Sony
847 news) give another signal besides SIGTRAP,
848 so check here as well as above. */
849 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
850 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
851 FRAME_FP (get_current_frame ()))
852 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
853 );
854 if (!random_signal)
855 stop_signal = TARGET_SIGNAL_TRAP;
856 }
857 }
858 else
859 random_signal = 1;
860
861 /* For the program's own signals, act according to
862 the signal handling tables. */
863
864 if (random_signal)
865 {
866 /* Signal not for debugging purposes. */
867 int printed = 0;
868
869 stopped_by_random_signal = 1;
870
871 if (signal_print[stop_signal])
872 {
873 printed = 1;
874 target_terminal_ours_for_output ();
875 annotate_signal ();
876 printf_filtered ("\nProgram received signal ");
877 annotate_signal_name ();
878 printf_filtered ("%s", target_signal_to_name (stop_signal));
879 annotate_signal_name_end ();
880 printf_filtered (", ");
881 annotate_signal_string ();
882 printf_filtered ("%s", target_signal_to_string (stop_signal));
883 annotate_signal_string_end ();
884 printf_filtered (".\n");
885 gdb_flush (gdb_stdout);
886 }
887 if (signal_stop[stop_signal])
888 break;
889 /* If not going to stop, give terminal back
890 if we took it away. */
891 else if (printed)
892 target_terminal_inferior ();
893
894 /* Clear the signal if it should not be passed. */
895 if (signal_program[stop_signal] == 0)
896 stop_signal = TARGET_SIGNAL_0;
897
898 /* I'm not sure whether this needs to be check_sigtramp2 or
899 whether it could/should be keep_going. */
900 goto check_sigtramp2;
901 }
902
903 /* Handle cases caused by hitting a breakpoint. */
904 {
905 CORE_ADDR jmp_buf_pc;
906 struct bpstat_what what;
907
908 what = bpstat_what (stop_bpstat);
909
910 if (what.call_dummy)
911 {
912 stop_stack_dummy = 1;
913 #ifdef HP_OS_BUG
914 trap_expected_after_continue = 1;
915 #endif
916 }
917
918 switch (what.main_action)
919 {
920 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
921 /* If we hit the breakpoint at longjmp, disable it for the
922 duration of this command. Then, install a temporary
923 breakpoint at the target of the jmp_buf. */
924 disable_longjmp_breakpoint();
925 remove_breakpoints ();
926 breakpoints_inserted = 0;
927 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
928
929 /* Need to blow away step-resume breakpoint, as it
930 interferes with us */
931 if (step_resume_breakpoint != NULL)
932 {
933 delete_breakpoint (step_resume_breakpoint);
934 step_resume_breakpoint = NULL;
935 }
936 /* Not sure whether we need to blow this away too, but probably
937 it is like the step-resume breakpoint. */
938 if (through_sigtramp_breakpoint != NULL)
939 {
940 delete_breakpoint (through_sigtramp_breakpoint);
941 through_sigtramp_breakpoint = NULL;
942 }
943
944 #if 0
945 /* FIXME - Need to implement nested temporary breakpoints */
946 if (step_over_calls > 0)
947 set_longjmp_resume_breakpoint(jmp_buf_pc,
948 get_current_frame());
949 else
950 #endif /* 0 */
951 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
952 handling_longjmp = 1; /* FIXME */
953 goto keep_going;
954
955 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
956 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
957 remove_breakpoints ();
958 breakpoints_inserted = 0;
959 #if 0
960 /* FIXME - Need to implement nested temporary breakpoints */
961 if (step_over_calls
962 && (FRAME_FP (get_current_frame ())
963 INNER_THAN step_frame_address))
964 {
965 another_trap = 1;
966 goto keep_going;
967 }
968 #endif /* 0 */
969 disable_longjmp_breakpoint();
970 handling_longjmp = 0; /* FIXME */
971 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
972 break;
973 /* else fallthrough */
974
975 case BPSTAT_WHAT_SINGLE:
976 if (breakpoints_inserted)
977 remove_breakpoints ();
978 breakpoints_inserted = 0;
979 another_trap = 1;
980 /* Still need to check other stuff, at least the case
981 where we are stepping and step out of the right range. */
982 break;
983
984 case BPSTAT_WHAT_STOP_NOISY:
985 stop_print_frame = 1;
986
987 /* We are about to nuke the step_resume_breakpoint and
988 through_sigtramp_breakpoint via the cleanup chain, so
989 no need to worry about it here. */
990
991 goto stop_stepping;
992
993 case BPSTAT_WHAT_STOP_SILENT:
994 stop_print_frame = 0;
995
996 /* We are about to nuke the step_resume_breakpoint and
997 through_sigtramp_breakpoint via the cleanup chain, so
998 no need to worry about it here. */
999
1000 goto stop_stepping;
1001
1002 case BPSTAT_WHAT_STEP_RESUME:
1003 delete_breakpoint (step_resume_breakpoint);
1004 step_resume_breakpoint = NULL;
1005 break;
1006
1007 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
1008 if (through_sigtramp_breakpoint)
1009 delete_breakpoint (through_sigtramp_breakpoint);
1010 through_sigtramp_breakpoint = NULL;
1011
1012 /* If were waiting for a trap, hitting the step_resume_break
1013 doesn't count as getting it. */
1014 if (trap_expected)
1015 another_trap = 1;
1016 break;
1017
1018 case BPSTAT_WHAT_LAST:
1019 /* Not a real code, but listed here to shut up gcc -Wall. */
1020
1021 case BPSTAT_WHAT_KEEP_CHECKING:
1022 break;
1023 }
1024 }
1025
1026 /* We come here if we hit a breakpoint but should not
1027 stop for it. Possibly we also were stepping
1028 and should stop for that. So fall through and
1029 test for stepping. But, if not stepping,
1030 do not stop. */
1031
1032 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1033 /* This is the old way of detecting the end of the stack dummy.
1034 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
1035 handled above. As soon as we can test it on all of them, all
1036 architectures should define it. */
1037
1038 /* If this is the breakpoint at the end of a stack dummy,
1039 just stop silently, unless the user was doing an si/ni, in which
1040 case she'd better know what she's doing. */
1041
1042 if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ()))
1043 && !step_range_end)
1044 {
1045 stop_print_frame = 0;
1046 stop_stack_dummy = 1;
1047 #ifdef HP_OS_BUG
1048 trap_expected_after_continue = 1;
1049 #endif
1050 break;
1051 }
1052 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1053
1054 if (step_resume_breakpoint)
1055 /* Having a step-resume breakpoint overrides anything
1056 else having to do with stepping commands until
1057 that breakpoint is reached. */
1058 /* I'm not sure whether this needs to be check_sigtramp2 or
1059 whether it could/should be keep_going. */
1060 goto check_sigtramp2;
1061
1062 if (step_range_end == 0)
1063 /* Likewise if we aren't even stepping. */
1064 /* I'm not sure whether this needs to be check_sigtramp2 or
1065 whether it could/should be keep_going. */
1066 goto check_sigtramp2;
1067
1068 /* If stepping through a line, keep going if still within it. */
1069 if (stop_pc >= step_range_start
1070 && stop_pc < step_range_end
1071 /* The step range might include the start of the
1072 function, so if we are at the start of the
1073 step range and either the stack or frame pointers
1074 just changed, we've stepped outside */
1075 && !(stop_pc == step_range_start
1076 && FRAME_FP (get_current_frame ())
1077 && (read_sp () INNER_THAN step_sp
1078 || FRAME_FP (get_current_frame ()) != step_frame_address)))
1079 {
1080 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
1081 So definately need to check for sigtramp here. */
1082 goto check_sigtramp2;
1083 }
1084
1085 /* We stepped out of the stepping range. */
1086
1087 /* We can't update step_sp every time through the loop, because
1088 reading the stack pointer would slow down stepping too much.
1089 But we can update it every time we leave the step range. */
1090 update_step_sp = 1;
1091
1092 /* Did we just take a signal? */
1093 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1094 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1095 {
1096 /* We've just taken a signal; go until we are back to
1097 the point where we took it and one more. */
1098
1099 /* This code is needed at least in the following case:
1100 The user types "next" and then a signal arrives (before
1101 the "next" is done). */
1102
1103 /* Note that if we are stopped at a breakpoint, then we need
1104 the step_resume breakpoint to override any breakpoints at
1105 the same location, so that we will still step over the
1106 breakpoint even though the signal happened. */
1107
1108 {
1109 struct symtab_and_line sr_sal;
1110
1111 sr_sal.pc = prev_pc;
1112 sr_sal.symtab = NULL;
1113 sr_sal.line = 0;
1114 /* We could probably be setting the frame to
1115 step_frame_address; I don't think anyone thought to try it. */
1116 step_resume_breakpoint =
1117 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1118 if (breakpoints_inserted)
1119 insert_breakpoints ();
1120 }
1121
1122 /* If this is stepi or nexti, make sure that the stepping range
1123 gets us past that instruction. */
1124 if (step_range_end == 1)
1125 /* FIXME: Does this run afoul of the code below which, if
1126 we step into the middle of a line, resets the stepping
1127 range? */
1128 step_range_end = (step_range_start = prev_pc) + 1;
1129
1130 remove_breakpoints_on_following_step = 1;
1131 goto keep_going;
1132 }
1133
1134 #if 1
1135 /* See if we left the step range due to a subroutine call that
1136 we should proceed to the end of. */
1137
1138 if (stop_func_start)
1139 {
1140 struct symtab *s;
1141
1142 /* Do this after the IN_SIGTRAMP check; it might give
1143 an error. */
1144 prologue_pc = stop_func_start;
1145
1146 /* Don't skip the prologue if this is assembly source */
1147 s = find_pc_symtab (stop_pc);
1148 if (s && s->language != language_asm)
1149 SKIP_PROLOGUE (prologue_pc);
1150 }
1151
1152 if ((/* Might be a non-recursive call. If the symbols are missing
1153 enough that stop_func_start == prev_func_start even though
1154 they are really two functions, we will treat some calls as
1155 jumps. */
1156 stop_func_start != prev_func_start
1157
1158 /* Might be a recursive call if either we have a prologue
1159 or the call instruction itself saves the PC on the stack. */
1160 || prologue_pc != stop_func_start
1161 || read_sp () != step_sp)
1162 && (/* PC is completely out of bounds of any known objfiles. Treat
1163 like a subroutine call. */
1164 ! stop_func_start
1165
1166 /* If we do a call, we will be at the start of a function... */
1167 || stop_pc == stop_func_start
1168
1169 /* ...except on the Alpha with -O (and also Irix 5 and
1170 perhaps others), in which we might call the address
1171 after the load of gp. Since prologues don't contain
1172 calls, we can't return to within one, and we don't
1173 jump back into them, so this check is OK. */
1174
1175 || stop_pc < prologue_pc
1176
1177 /* ...and if it is a leaf function, the prologue might
1178 consist of gp loading only, so the call transfers to
1179 the first instruction after the prologue. */
1180 || (stop_pc == prologue_pc
1181
1182 /* Distinguish this from the case where we jump back
1183 to the first instruction after the prologue,
1184 within a function. */
1185 && stop_func_start != prev_func_start)
1186
1187 /* If we end up in certain places, it means we did a subroutine
1188 call. I'm not completely sure this is necessary now that we
1189 have the above checks with stop_func_start (and now that
1190 find_pc_partial_function is pickier). */
1191 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1192
1193 /* If none of the above apply, it is a jump within a function,
1194 or a return from a subroutine. The other case is longjmp,
1195 which can no longer happen here as long as the
1196 handling_longjmp stuff is working. */
1197 ))
1198 #else
1199 /* This is experimental code which greatly simplifies the subroutine call
1200 test. I've actually tested on the Alpha, and it works great. -Stu */
1201
1202 if (in_prologue (stop_pc, NULL)
1203 || (prev_func_start != 0
1204 && stop_func_start == 0))
1205 #endif
1206 {
1207 /* It's a subroutine call. */
1208
1209 if (step_over_calls == 0)
1210 {
1211 /* I presume that step_over_calls is only 0 when we're
1212 supposed to be stepping at the assembly language level
1213 ("stepi"). Just stop. */
1214 stop_step = 1;
1215 break;
1216 }
1217
1218 if (step_over_calls > 0)
1219 /* We're doing a "next". */
1220 goto step_over_function;
1221
1222 /* If we are in a function call trampoline (a stub between
1223 the calling routine and the real function), locate the real
1224 function. That's what tells us (a) whether we want to step
1225 into it at all, and (b) what prologue we want to run to
1226 the end of, if we do step into it. */
1227 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1228 if (tmp != 0)
1229 stop_func_start = tmp;
1230
1231 /* If we have line number information for the function we
1232 are thinking of stepping into, step into it.
1233
1234 If there are several symtabs at that PC (e.g. with include
1235 files), just want to know whether *any* of them have line
1236 numbers. find_pc_line handles this. */
1237 {
1238 struct symtab_and_line tmp_sal;
1239
1240 tmp_sal = find_pc_line (stop_func_start, 0);
1241 if (tmp_sal.line != 0)
1242 goto step_into_function;
1243 }
1244
1245 step_over_function:
1246 /* A subroutine call has happened. */
1247 {
1248 /* Set a special breakpoint after the return */
1249 struct symtab_and_line sr_sal;
1250 sr_sal.pc =
1251 ADDR_BITS_REMOVE
1252 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1253 sr_sal.symtab = NULL;
1254 sr_sal.line = 0;
1255 step_resume_breakpoint =
1256 set_momentary_breakpoint (sr_sal, get_current_frame (),
1257 bp_step_resume);
1258 step_resume_breakpoint->frame = step_frame_address;
1259 if (breakpoints_inserted)
1260 insert_breakpoints ();
1261 }
1262 goto keep_going;
1263
1264 step_into_function:
1265 /* Subroutine call with source code we should not step over.
1266 Do step to the first line of code in it. */
1267 {
1268 struct symtab *s;
1269
1270 s = find_pc_symtab (stop_pc);
1271 if (s && s->language != language_asm)
1272 SKIP_PROLOGUE (stop_func_start);
1273 }
1274 sal = find_pc_line (stop_func_start, 0);
1275 /* Use the step_resume_break to step until
1276 the end of the prologue, even if that involves jumps
1277 (as it seems to on the vax under 4.2). */
1278 /* If the prologue ends in the middle of a source line,
1279 continue to the end of that source line (if it is still
1280 within the function). Otherwise, just go to end of prologue. */
1281 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1282 /* no, don't either. It skips any code that's
1283 legitimately on the first line. */
1284 #else
1285 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
1286 stop_func_start = sal.end;
1287 #endif
1288
1289 if (stop_func_start == stop_pc)
1290 {
1291 /* We are already there: stop now. */
1292 stop_step = 1;
1293 break;
1294 }
1295 else
1296 /* Put the step-breakpoint there and go until there. */
1297 {
1298 struct symtab_and_line sr_sal;
1299
1300 sr_sal.pc = stop_func_start;
1301 sr_sal.symtab = NULL;
1302 sr_sal.line = 0;
1303 /* Do not specify what the fp should be when we stop
1304 since on some machines the prologue
1305 is where the new fp value is established. */
1306 step_resume_breakpoint =
1307 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1308 if (breakpoints_inserted)
1309 insert_breakpoints ();
1310
1311 /* And make sure stepping stops right away then. */
1312 step_range_end = step_range_start;
1313 }
1314 goto keep_going;
1315 }
1316
1317 /* We've wandered out of the step range. */
1318
1319 sal = find_pc_line(stop_pc, 0);
1320
1321 if (step_range_end == 1)
1322 {
1323 /* It is stepi or nexti. We always want to stop stepping after
1324 one instruction. */
1325 stop_step = 1;
1326 break;
1327 }
1328
1329 /* If we're in the return path from a shared library trampoline,
1330 we want to proceed through the trampoline when stepping. */
1331 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
1332 {
1333 CORE_ADDR tmp;
1334
1335 /* Determine where this trampoline returns. */
1336 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1337
1338 /* Only proceed through if we know where it's going. */
1339 if (tmp)
1340 {
1341 /* And put the step-breakpoint there and go until there. */
1342 struct symtab_and_line sr_sal;
1343
1344 sr_sal.pc = tmp;
1345 sr_sal.symtab = NULL;
1346 sr_sal.line = 0;
1347 /* Do not specify what the fp should be when we stop
1348 since on some machines the prologue
1349 is where the new fp value is established. */
1350 step_resume_breakpoint =
1351 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1352 if (breakpoints_inserted)
1353 insert_breakpoints ();
1354
1355 /* Restart without fiddling with the step ranges or
1356 other state. */
1357 goto keep_going;
1358 }
1359 }
1360
1361 if (sal.line == 0)
1362 {
1363 /* We have no line number information. That means to stop
1364 stepping (does this always happen right after one instruction,
1365 when we do "s" in a function with no line numbers,
1366 or can this happen as a result of a return or longjmp?). */
1367 stop_step = 1;
1368 break;
1369 }
1370
1371 if (stop_pc == sal.pc
1372 && (current_line != sal.line || current_symtab != sal.symtab))
1373 {
1374 /* We are at the start of a different line. So stop. Note that
1375 we don't stop if we step into the middle of a different line.
1376 That is said to make things like for (;;) statements work
1377 better. */
1378 stop_step = 1;
1379 break;
1380 }
1381
1382 /* We aren't done stepping.
1383
1384 Optimize by setting the stepping range to the line.
1385 (We might not be in the original line, but if we entered a
1386 new line in mid-statement, we continue stepping. This makes
1387 things like for(;;) statements work better.) */
1388
1389 if (stop_func_end && sal.end >= stop_func_end)
1390 {
1391 /* If this is the last line of the function, don't keep stepping
1392 (it would probably step us out of the function).
1393 This is particularly necessary for a one-line function,
1394 in which after skipping the prologue we better stop even though
1395 we will be in mid-line. */
1396 stop_step = 1;
1397 break;
1398 }
1399 step_range_start = sal.pc;
1400 step_range_end = sal.end;
1401 goto keep_going;
1402
1403 check_sigtramp2:
1404 if (trap_expected
1405 && IN_SIGTRAMP (stop_pc, stop_func_name)
1406 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1407 {
1408 /* What has happened here is that we have just stepped the inferior
1409 with a signal (because it is a signal which shouldn't make
1410 us stop), thus stepping into sigtramp.
1411
1412 So we need to set a step_resume_break_address breakpoint
1413 and continue until we hit it, and then step. FIXME: This should
1414 be more enduring than a step_resume breakpoint; we should know
1415 that we will later need to keep going rather than re-hitting
1416 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1417 it says "exceedingly difficult"). */
1418 struct symtab_and_line sr_sal;
1419
1420 sr_sal.pc = prev_pc;
1421 sr_sal.symtab = NULL;
1422 sr_sal.line = 0;
1423 /* We perhaps could set the frame if we kept track of what
1424 the frame corresponding to prev_pc was. But we don't,
1425 so don't. */
1426 through_sigtramp_breakpoint =
1427 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
1428 if (breakpoints_inserted)
1429 insert_breakpoints ();
1430
1431 remove_breakpoints_on_following_step = 1;
1432 another_trap = 1;
1433 }
1434
1435 keep_going:
1436 /* Come to this label when you need to resume the inferior.
1437 It's really much cleaner to do a goto than a maze of if-else
1438 conditions. */
1439
1440 /* Save the pc before execution, to compare with pc after stop. */
1441 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1442 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1443 BREAK is defined, the
1444 original pc would not have
1445 been at the start of a
1446 function. */
1447 prev_func_name = stop_func_name;
1448
1449 if (update_step_sp)
1450 step_sp = read_sp ();
1451 update_step_sp = 0;
1452
1453 /* If we did not do break;, it means we should keep
1454 running the inferior and not return to debugger. */
1455
1456 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
1457 {
1458 /* We took a signal (which we are supposed to pass through to
1459 the inferior, else we'd have done a break above) and we
1460 haven't yet gotten our trap. Simply continue. */
1461 resume (CURRENTLY_STEPPING (), stop_signal);
1462 }
1463 else
1464 {
1465 /* Either the trap was not expected, but we are continuing
1466 anyway (the user asked that this signal be passed to the
1467 child)
1468 -- or --
1469 The signal was SIGTRAP, e.g. it was our signal, but we
1470 decided we should resume from it.
1471
1472 We're going to run this baby now!
1473
1474 Insert breakpoints now, unless we are trying
1475 to one-proceed past a breakpoint. */
1476 /* If we've just finished a special step resume and we don't
1477 want to hit a breakpoint, pull em out. */
1478 if (step_resume_breakpoint == NULL
1479 && through_sigtramp_breakpoint == NULL
1480 && remove_breakpoints_on_following_step)
1481 {
1482 remove_breakpoints_on_following_step = 0;
1483 remove_breakpoints ();
1484 breakpoints_inserted = 0;
1485 }
1486 else if (!breakpoints_inserted &&
1487 (through_sigtramp_breakpoint != NULL || !another_trap))
1488 {
1489 breakpoints_failed = insert_breakpoints ();
1490 if (breakpoints_failed)
1491 break;
1492 breakpoints_inserted = 1;
1493 }
1494
1495 trap_expected = another_trap;
1496
1497 if (stop_signal == TARGET_SIGNAL_TRAP)
1498 stop_signal = TARGET_SIGNAL_0;
1499
1500 #ifdef SHIFT_INST_REGS
1501 /* I'm not sure when this following segment applies. I do know, now,
1502 that we shouldn't rewrite the regs when we were stopped by a
1503 random signal from the inferior process. */
1504 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1505 (this is only used on the 88k). */
1506
1507 if (!bpstat_explains_signal (stop_bpstat)
1508 && (stop_signal != TARGET_SIGNAL_CHLD)
1509 && !stopped_by_random_signal)
1510 SHIFT_INST_REGS();
1511 #endif /* SHIFT_INST_REGS */
1512
1513 resume (CURRENTLY_STEPPING (), stop_signal);
1514 }
1515 }
1516
1517 stop_stepping:
1518 if (target_has_execution)
1519 {
1520 /* Assuming the inferior still exists, set these up for next
1521 time, just like we did above if we didn't break out of the
1522 loop. */
1523 prev_pc = read_pc ();
1524 prev_func_start = stop_func_start;
1525 prev_func_name = stop_func_name;
1526 }
1527 do_cleanups (old_cleanups);
1528 }
1529 \f
1530 /* Here to return control to GDB when the inferior stops for real.
1531 Print appropriate messages, remove breakpoints, give terminal our modes.
1532
1533 STOP_PRINT_FRAME nonzero means print the executing frame
1534 (pc, function, args, file, line number and line text).
1535 BREAKPOINTS_FAILED nonzero means stop was due to error
1536 attempting to insert breakpoints. */
1537
1538 void
1539 normal_stop ()
1540 {
1541 /* Make sure that the current_frame's pc is correct. This
1542 is a correction for setting up the frame info before doing
1543 DECR_PC_AFTER_BREAK */
1544 if (target_has_execution && get_current_frame())
1545 (get_current_frame ())->pc = read_pc ();
1546
1547 if (breakpoints_failed)
1548 {
1549 target_terminal_ours_for_output ();
1550 print_sys_errmsg ("ptrace", breakpoints_failed);
1551 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1552 The same program may be running in another process.\n");
1553 }
1554
1555 if (target_has_execution && breakpoints_inserted)
1556 if (remove_breakpoints ())
1557 {
1558 target_terminal_ours_for_output ();
1559 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1560 It might be running in another process.\n\
1561 Further execution is probably impossible.\n");
1562 }
1563
1564 breakpoints_inserted = 0;
1565
1566 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1567 Delete any breakpoint that is to be deleted at the next stop. */
1568
1569 breakpoint_auto_delete (stop_bpstat);
1570
1571 /* If an auto-display called a function and that got a signal,
1572 delete that auto-display to avoid an infinite recursion. */
1573
1574 if (stopped_by_random_signal)
1575 disable_current_display ();
1576
1577 if (step_multi && stop_step)
1578 goto done;
1579
1580 target_terminal_ours ();
1581
1582 /* Look up the hook_stop and run it if it exists. */
1583
1584 if (stop_command->hook)
1585 {
1586 catch_errors (hook_stop_stub, (char *)stop_command->hook,
1587 "Error while running hook_stop:\n", RETURN_MASK_ALL);
1588 }
1589
1590 if (!target_has_stack)
1591 goto done;
1592
1593 /* Select innermost stack frame except on return from a stack dummy routine,
1594 or if the program has exited. Print it without a level number if
1595 we have changed functions or hit a breakpoint. Print source line
1596 if we have one. */
1597 if (!stop_stack_dummy)
1598 {
1599 select_frame (get_current_frame (), 0);
1600
1601 if (stop_print_frame)
1602 {
1603 int source_only;
1604
1605 source_only = bpstat_print (stop_bpstat);
1606 source_only = source_only ||
1607 ( stop_step
1608 && step_frame_address == FRAME_FP (get_current_frame ())
1609 && step_start_function == find_pc_function (stop_pc));
1610
1611 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1612
1613 /* Display the auto-display expressions. */
1614 do_displays ();
1615 }
1616 }
1617
1618 /* Save the function value return registers, if we care.
1619 We might be about to restore their previous contents. */
1620 if (proceed_to_finish)
1621 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1622
1623 if (stop_stack_dummy)
1624 {
1625 /* Pop the empty frame that contains the stack dummy.
1626 POP_FRAME ends with a setting of the current frame, so we
1627 can use that next. */
1628 POP_FRAME;
1629 /* Set stop_pc to what it was before we called the function. Can't rely
1630 on restore_inferior_status because that only gets called if we don't
1631 stop in the called function. */
1632 stop_pc = read_pc();
1633 select_frame (get_current_frame (), 0);
1634 }
1635 done:
1636 annotate_stopped ();
1637 }
1638
1639 static int
1640 hook_stop_stub (cmd)
1641 char *cmd;
1642 {
1643 execute_user_command ((struct cmd_list_element *)cmd, 0);
1644 return (0);
1645 }
1646 \f
1647 int signal_stop_state (signo)
1648 int signo;
1649 {
1650 return signal_stop[signo];
1651 }
1652
1653 int signal_print_state (signo)
1654 int signo;
1655 {
1656 return signal_print[signo];
1657 }
1658
1659 int signal_pass_state (signo)
1660 int signo;
1661 {
1662 return signal_program[signo];
1663 }
1664
1665 static void
1666 sig_print_header ()
1667 {
1668 printf_filtered ("\
1669 Signal Stop\tPrint\tPass to program\tDescription\n");
1670 }
1671
1672 static void
1673 sig_print_info (oursig)
1674 enum target_signal oursig;
1675 {
1676 char *name = target_signal_to_name (oursig);
1677 printf_filtered ("%s", name);
1678 printf_filtered ("%*.*s ", 13 - strlen (name), 13 - strlen (name),
1679 " ");
1680 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
1681 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
1682 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
1683 printf_filtered ("%s\n", target_signal_to_string (oursig));
1684 }
1685
1686 /* Specify how various signals in the inferior should be handled. */
1687
1688 static void
1689 handle_command (args, from_tty)
1690 char *args;
1691 int from_tty;
1692 {
1693 char **argv;
1694 int digits, wordlen;
1695 int sigfirst, signum, siglast;
1696 enum target_signal oursig;
1697 int allsigs;
1698 int nsigs;
1699 unsigned char *sigs;
1700 struct cleanup *old_chain;
1701
1702 if (args == NULL)
1703 {
1704 error_no_arg ("signal to handle");
1705 }
1706
1707 /* Allocate and zero an array of flags for which signals to handle. */
1708
1709 nsigs = (int)TARGET_SIGNAL_LAST;
1710 sigs = (unsigned char *) alloca (nsigs);
1711 memset (sigs, 0, nsigs);
1712
1713 /* Break the command line up into args. */
1714
1715 argv = buildargv (args);
1716 if (argv == NULL)
1717 {
1718 nomem (0);
1719 }
1720 old_chain = make_cleanup (freeargv, (char *) argv);
1721
1722 /* Walk through the args, looking for signal oursigs, signal names, and
1723 actions. Signal numbers and signal names may be interspersed with
1724 actions, with the actions being performed for all signals cumulatively
1725 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1726
1727 while (*argv != NULL)
1728 {
1729 wordlen = strlen (*argv);
1730 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1731 allsigs = 0;
1732 sigfirst = siglast = -1;
1733
1734 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1735 {
1736 /* Apply action to all signals except those used by the
1737 debugger. Silently skip those. */
1738 allsigs = 1;
1739 sigfirst = 0;
1740 siglast = nsigs - 1;
1741 }
1742 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1743 {
1744 SET_SIGS (nsigs, sigs, signal_stop);
1745 SET_SIGS (nsigs, sigs, signal_print);
1746 }
1747 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1748 {
1749 UNSET_SIGS (nsigs, sigs, signal_program);
1750 }
1751 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1752 {
1753 SET_SIGS (nsigs, sigs, signal_print);
1754 }
1755 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1756 {
1757 SET_SIGS (nsigs, sigs, signal_program);
1758 }
1759 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1760 {
1761 UNSET_SIGS (nsigs, sigs, signal_stop);
1762 }
1763 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1764 {
1765 SET_SIGS (nsigs, sigs, signal_program);
1766 }
1767 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1768 {
1769 UNSET_SIGS (nsigs, sigs, signal_print);
1770 UNSET_SIGS (nsigs, sigs, signal_stop);
1771 }
1772 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1773 {
1774 UNSET_SIGS (nsigs, sigs, signal_program);
1775 }
1776 else if (digits > 0)
1777 {
1778 /* It is numeric. The numeric signal refers to our own internal
1779 signal numbering from target.h, not to host/target signal number.
1780 This is a feature; users really should be using symbolic names
1781 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1782 will work right anyway. */
1783
1784 sigfirst = siglast = (int) target_signal_from_command (atoi (*argv));
1785 if ((*argv)[digits] == '-')
1786 {
1787 siglast =
1788 (int) target_signal_from_command (atoi ((*argv) + digits + 1));
1789 }
1790 if (sigfirst > siglast)
1791 {
1792 /* Bet he didn't figure we'd think of this case... */
1793 signum = sigfirst;
1794 sigfirst = siglast;
1795 siglast = signum;
1796 }
1797 }
1798 else
1799 {
1800 oursig = target_signal_from_name (*argv);
1801 if (oursig != TARGET_SIGNAL_UNKNOWN)
1802 {
1803 sigfirst = siglast = (int)oursig;
1804 }
1805 else
1806 {
1807 /* Not a number and not a recognized flag word => complain. */
1808 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
1809 }
1810 }
1811
1812 /* If any signal numbers or symbol names were found, set flags for
1813 which signals to apply actions to. */
1814
1815 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
1816 {
1817 switch ((enum target_signal)signum)
1818 {
1819 case TARGET_SIGNAL_TRAP:
1820 case TARGET_SIGNAL_INT:
1821 if (!allsigs && !sigs[signum])
1822 {
1823 if (query ("%s is used by the debugger.\n\
1824 Are you sure you want to change it? ",
1825 target_signal_to_name
1826 ((enum target_signal)signum)))
1827 {
1828 sigs[signum] = 1;
1829 }
1830 else
1831 {
1832 printf_unfiltered ("Not confirmed, unchanged.\n");
1833 gdb_flush (gdb_stdout);
1834 }
1835 }
1836 break;
1837 case TARGET_SIGNAL_0:
1838 case TARGET_SIGNAL_DEFAULT:
1839 case TARGET_SIGNAL_UNKNOWN:
1840 /* Make sure that "all" doesn't print these. */
1841 break;
1842 default:
1843 sigs[signum] = 1;
1844 break;
1845 }
1846 }
1847
1848 argv++;
1849 }
1850
1851 target_notice_signals(inferior_pid);
1852
1853 if (from_tty)
1854 {
1855 /* Show the results. */
1856 sig_print_header ();
1857 for (signum = 0; signum < nsigs; signum++)
1858 {
1859 if (sigs[signum])
1860 {
1861 sig_print_info (signum);
1862 }
1863 }
1864 }
1865
1866 do_cleanups (old_chain);
1867 }
1868
1869 /* Print current contents of the tables set by the handle command.
1870 It is possible we should just be printing signals actually used
1871 by the current target (but for things to work right when switching
1872 targets, all signals should be in the signal tables). */
1873
1874 static void
1875 signals_info (signum_exp, from_tty)
1876 char *signum_exp;
1877 int from_tty;
1878 {
1879 enum target_signal oursig;
1880 sig_print_header ();
1881
1882 if (signum_exp)
1883 {
1884 /* First see if this is a symbol name. */
1885 oursig = target_signal_from_name (signum_exp);
1886 if (oursig == TARGET_SIGNAL_UNKNOWN)
1887 {
1888 /* No, try numeric. */
1889 oursig =
1890 target_signal_from_command (parse_and_eval_address (signum_exp));
1891 }
1892 sig_print_info (oursig);
1893 return;
1894 }
1895
1896 printf_filtered ("\n");
1897 /* These ugly casts brought to you by the native VAX compiler. */
1898 for (oursig = TARGET_SIGNAL_FIRST;
1899 (int)oursig < (int)TARGET_SIGNAL_LAST;
1900 oursig = (enum target_signal)((int)oursig + 1))
1901 {
1902 QUIT;
1903
1904 if (oursig != TARGET_SIGNAL_UNKNOWN
1905 && oursig != TARGET_SIGNAL_DEFAULT
1906 && oursig != TARGET_SIGNAL_0)
1907 sig_print_info (oursig);
1908 }
1909
1910 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1911 }
1912 \f
1913 /* Save all of the information associated with the inferior<==>gdb
1914 connection. INF_STATUS is a pointer to a "struct inferior_status"
1915 (defined in inferior.h). */
1916
1917 void
1918 save_inferior_status (inf_status, restore_stack_info)
1919 struct inferior_status *inf_status;
1920 int restore_stack_info;
1921 {
1922 inf_status->stop_signal = stop_signal;
1923 inf_status->stop_pc = stop_pc;
1924 inf_status->stop_step = stop_step;
1925 inf_status->stop_stack_dummy = stop_stack_dummy;
1926 inf_status->stopped_by_random_signal = stopped_by_random_signal;
1927 inf_status->trap_expected = trap_expected;
1928 inf_status->step_range_start = step_range_start;
1929 inf_status->step_range_end = step_range_end;
1930 inf_status->step_frame_address = step_frame_address;
1931 inf_status->step_over_calls = step_over_calls;
1932 inf_status->stop_after_trap = stop_after_trap;
1933 inf_status->stop_soon_quietly = stop_soon_quietly;
1934 /* Save original bpstat chain here; replace it with copy of chain.
1935 If caller's caller is walking the chain, they'll be happier if we
1936 hand them back the original chain when restore_i_s is called. */
1937 inf_status->stop_bpstat = stop_bpstat;
1938 stop_bpstat = bpstat_copy (stop_bpstat);
1939 inf_status->breakpoint_proceeded = breakpoint_proceeded;
1940 inf_status->restore_stack_info = restore_stack_info;
1941 inf_status->proceed_to_finish = proceed_to_finish;
1942
1943 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
1944
1945 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
1946
1947 record_selected_frame (&(inf_status->selected_frame_address),
1948 &(inf_status->selected_level));
1949 return;
1950 }
1951
1952 struct restore_selected_frame_args {
1953 CORE_ADDR frame_address;
1954 int level;
1955 };
1956
1957 static int restore_selected_frame PARAMS ((char *));
1958
1959 /* Restore the selected frame. args is really a struct
1960 restore_selected_frame_args * (declared as char * for catch_errors)
1961 telling us what frame to restore. Returns 1 for success, or 0 for
1962 failure. An error message will have been printed on error. */
1963
1964 static int
1965 restore_selected_frame (args)
1966 char *args;
1967 {
1968 struct restore_selected_frame_args *fr =
1969 (struct restore_selected_frame_args *) args;
1970 struct frame_info *frame;
1971 int level = fr->level;
1972
1973 frame = find_relative_frame (get_current_frame (), &level);
1974
1975 /* If inf_status->selected_frame_address is NULL, there was no
1976 previously selected frame. */
1977 if (frame == NULL ||
1978 FRAME_FP (frame) != fr->frame_address ||
1979 level != 0)
1980 {
1981 warning ("Unable to restore previously selected frame.\n");
1982 return 0;
1983 }
1984 select_frame (frame, fr->level);
1985 return(1);
1986 }
1987
1988 void
1989 restore_inferior_status (inf_status)
1990 struct inferior_status *inf_status;
1991 {
1992 stop_signal = inf_status->stop_signal;
1993 stop_pc = inf_status->stop_pc;
1994 stop_step = inf_status->stop_step;
1995 stop_stack_dummy = inf_status->stop_stack_dummy;
1996 stopped_by_random_signal = inf_status->stopped_by_random_signal;
1997 trap_expected = inf_status->trap_expected;
1998 step_range_start = inf_status->step_range_start;
1999 step_range_end = inf_status->step_range_end;
2000 step_frame_address = inf_status->step_frame_address;
2001 step_over_calls = inf_status->step_over_calls;
2002 stop_after_trap = inf_status->stop_after_trap;
2003 stop_soon_quietly = inf_status->stop_soon_quietly;
2004 bpstat_clear (&stop_bpstat);
2005 stop_bpstat = inf_status->stop_bpstat;
2006 breakpoint_proceeded = inf_status->breakpoint_proceeded;
2007 proceed_to_finish = inf_status->proceed_to_finish;
2008
2009 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
2010
2011 /* The inferior can be gone if the user types "print exit(0)"
2012 (and perhaps other times). */
2013 if (target_has_execution)
2014 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2015
2016 /* The inferior can be gone if the user types "print exit(0)"
2017 (and perhaps other times). */
2018
2019 /* FIXME: If we are being called after stopping in a function which
2020 is called from gdb, we should not be trying to restore the
2021 selected frame; it just prints a spurious error message (The
2022 message is useful, however, in detecting bugs in gdb (like if gdb
2023 clobbers the stack)). In fact, should we be restoring the
2024 inferior status at all in that case? . */
2025
2026 if (target_has_stack && inf_status->restore_stack_info)
2027 {
2028 struct restore_selected_frame_args fr;
2029 fr.level = inf_status->selected_level;
2030 fr.frame_address = inf_status->selected_frame_address;
2031 /* The point of catch_errors is that if the stack is clobbered,
2032 walking the stack might encounter a garbage pointer and error()
2033 trying to dereference it. */
2034 if (catch_errors (restore_selected_frame, &fr,
2035 "Unable to restore previously selected frame:\n",
2036 RETURN_MASK_ERROR) == 0)
2037 /* Error in restoring the selected frame. Select the innermost
2038 frame. */
2039 select_frame (get_current_frame (), 0);
2040 }
2041 }
2042
2043 \f
2044 void
2045 _initialize_infrun ()
2046 {
2047 register int i;
2048 register int numsigs;
2049
2050 add_info ("signals", signals_info,
2051 "What debugger does when program gets various signals.\n\
2052 Specify a signal as argument to print info on that signal only.");
2053 add_info_alias ("handle", "signals", 0);
2054
2055 add_com ("handle", class_run, handle_command,
2056 concat ("Specify how to handle a signal.\n\
2057 Args are signals and actions to apply to those signals.\n\
2058 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
2059 from 1-15 are allowed for compatibility with old versions of GDB.\n\
2060 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
2061 The special arg \"all\" is recognized to mean all signals except those\n\
2062 used by the debugger, typically SIGTRAP and SIGINT.\n",
2063 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
2064 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
2065 Stop means reenter debugger if this signal happens (implies print).\n\
2066 Print means print a message if this signal happens.\n\
2067 Pass means let program see this signal; otherwise program doesn't know.\n\
2068 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
2069 Pass and Stop may be combined.", NULL));
2070
2071 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
2072 "There is no `stop' command, but you can set a hook on `stop'.\n\
2073 This allows you to set a list of commands to be run each time execution\n\
2074 of the program stops.", &cmdlist);
2075
2076 numsigs = (int)TARGET_SIGNAL_LAST;
2077 signal_stop = (unsigned char *)
2078 xmalloc (sizeof (signal_stop[0]) * numsigs);
2079 signal_print = (unsigned char *)
2080 xmalloc (sizeof (signal_print[0]) * numsigs);
2081 signal_program = (unsigned char *)
2082 xmalloc (sizeof (signal_program[0]) * numsigs);
2083 for (i = 0; i < numsigs; i++)
2084 {
2085 signal_stop[i] = 1;
2086 signal_print[i] = 1;
2087 signal_program[i] = 1;
2088 }
2089
2090 /* Signals caused by debugger's own actions
2091 should not be given to the program afterwards. */
2092 signal_program[TARGET_SIGNAL_TRAP] = 0;
2093 signal_program[TARGET_SIGNAL_INT] = 0;
2094
2095 /* Signals that are not errors should not normally enter the debugger. */
2096 signal_stop[TARGET_SIGNAL_ALRM] = 0;
2097 signal_print[TARGET_SIGNAL_ALRM] = 0;
2098 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
2099 signal_print[TARGET_SIGNAL_VTALRM] = 0;
2100 signal_stop[TARGET_SIGNAL_PROF] = 0;
2101 signal_print[TARGET_SIGNAL_PROF] = 0;
2102 signal_stop[TARGET_SIGNAL_CHLD] = 0;
2103 signal_print[TARGET_SIGNAL_CHLD] = 0;
2104 signal_stop[TARGET_SIGNAL_IO] = 0;
2105 signal_print[TARGET_SIGNAL_IO] = 0;
2106 signal_stop[TARGET_SIGNAL_POLL] = 0;
2107 signal_print[TARGET_SIGNAL_POLL] = 0;
2108 signal_stop[TARGET_SIGNAL_URG] = 0;
2109 signal_print[TARGET_SIGNAL_URG] = 0;
2110 }