]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/infrun.c
* Makefile.in (VERSION): Bump to 4.7.4.
[thirdparty/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 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 /* Notes on the algorithm used in wait_for_inferior to determine if we
21 just did a subroutine call when stepping. We have the following
22 information at that point:
23
24 Current and previous (just before this step) pc.
25 Current and previous sp.
26 Current and previous start of current function.
27
28 If the starts of the functions don't match, then
29
30 a) We did a subroutine call.
31
32 In this case, the pc will be at the beginning of a function.
33
34 b) We did a subroutine return.
35
36 Otherwise.
37
38 c) We did a longjmp.
39
40 If we did a longjump, we were doing "nexti", since a next would
41 have attempted to skip over the assembly language routine in which
42 the longjmp is coded and would have simply been the equivalent of a
43 continue. I consider this ok behaivior. We'd like one of two
44 things to happen if we are doing a nexti through the longjmp()
45 routine: 1) It behaves as a stepi, or 2) It acts like a continue as
46 above. Given that this is a special case, and that anybody who
47 thinks that the concept of sub calls is meaningful in the context
48 of a longjmp, I'll take either one. Let's see what happens.
49
50 Acts like a subroutine return. I can handle that with no problem
51 at all.
52
53 -->So: If the current and previous beginnings of the current
54 function don't match, *and* the pc is at the start of a function,
55 we've done a subroutine call. If the pc is not at the start of a
56 function, we *didn't* do a subroutine call.
57
58 -->If the beginnings of the current and previous function do match,
59 either:
60
61 a) We just did a recursive call.
62
63 In this case, we would be at the very beginning of a
64 function and 1) it will have a prologue (don't jump to
65 before prologue, or 2) (we assume here that it doesn't have
66 a prologue) there will have been a change in the stack
67 pointer over the last instruction. (Ie. it's got to put
68 the saved pc somewhere. The stack is the usual place. In
69 a recursive call a register is only an option if there's a
70 prologue to do something with it. This is even true on
71 register window machines; the prologue sets up the new
72 window. It might not be true on a register window machine
73 where the call instruction moved the register window
74 itself. Hmmm. One would hope that the stack pointer would
75 also change. If it doesn't, somebody send me a note, and
76 I'll work out a more general theory.
77 bug-gdb@prep.ai.mit.edu). This is true (albeit slipperly
78 so) on all machines I'm aware of:
79
80 m68k: Call changes stack pointer. Regular jumps don't.
81
82 sparc: Recursive calls must have frames and therefor,
83 prologues.
84
85 vax: All calls have frames and hence change the
86 stack pointer.
87
88 b) We did a return from a recursive call. I don't see that we
89 have either the ability or the need to distinguish this
90 from an ordinary jump. The stack frame will be printed
91 when and if the frame pointer changes; if we are in a
92 function without a frame pointer, it's the users own
93 lookout.
94
95 c) We did a jump within a function. We assume that this is
96 true if we didn't do a recursive call.
97
98 d) We are in no-man's land ("I see no symbols here"). We
99 don't worry about this; it will make calls look like simple
100 jumps (and the stack frames will be printed when the frame
101 pointer moves), which is a reasonably non-violent response.
102 */
103
104 #include "defs.h"
105 #include <string.h>
106 #include <ctype.h>
107 #include "symtab.h"
108 #include "frame.h"
109 #include "inferior.h"
110 #include "breakpoint.h"
111 #include "wait.h"
112 #include "gdbcore.h"
113 #include "gdbcmd.h"
114 #include "target.h"
115
116 #include <signal.h>
117
118 /* unistd.h is needed to #define X_OK */
119 #ifdef USG
120 #include <unistd.h>
121 #else
122 #include <sys/file.h>
123 #endif
124
125 /* Prototypes for local functions */
126
127 static void
128 signals_info PARAMS ((char *, int));
129
130 static void
131 handle_command PARAMS ((char *, int));
132
133 static void
134 sig_print_info PARAMS ((int));
135
136 static void
137 sig_print_header PARAMS ((void));
138
139 static void
140 remove_step_breakpoint PARAMS ((void));
141
142 static void
143 insert_step_breakpoint PARAMS ((void));
144
145 static void
146 resume_cleanups PARAMS ((int));
147
148 static int
149 hook_stop_stub PARAMS ((char *));
150
151 /* Sigtramp is a routine that the kernel calls (which then calls the
152 signal handler). On most machines it is a library routine that
153 is linked into the executable.
154
155 This macro, given a program counter value and the name of the
156 function in which that PC resides (which can be null if the
157 name is not known), returns nonzero if the PC and name show
158 that we are in sigtramp.
159
160 On most machines just see if the name is sigtramp (and if we have
161 no name, assume we are not in sigtramp). */
162 #if !defined (IN_SIGTRAMP)
163 #define IN_SIGTRAMP(pc, name) \
164 (name && !strcmp ("_sigtramp", name))
165 #endif
166
167 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
168 program. It needs to examine the jmp_buf argument and extract the PC
169 from it. The return value is non-zero on success, zero otherwise. */
170 #ifndef GET_LONGJMP_TARGET
171 #define GET_LONGJMP_TARGET(PC_ADDR) 0
172 #endif
173
174
175 /* Some machines have trampoline code that sits between function callers
176 and the actual functions themselves. If this machine doesn't have
177 such things, disable their processing. */
178 #ifndef SKIP_TRAMPOLINE_CODE
179 #define SKIP_TRAMPOLINE_CODE(pc) 0
180 #endif
181
182 /* For SVR4 shared libraries, each call goes through a small piece of
183 trampoline code in the ".init" section. IN_SOLIB_TRAMPOLINE evaluates
184 to nonzero if we are current stopped in one of these. */
185 #ifndef IN_SOLIB_TRAMPOLINE
186 #define IN_SOLIB_TRAMPOLINE(pc,name) 0
187 #endif
188
189 #ifdef TDESC
190 #include "tdesc.h"
191 int safe_to_init_tdesc_context = 0;
192 extern dc_dcontext_t current_context;
193 #endif
194
195 /* Tables of how to react to signals; the user sets them. */
196
197 static unsigned char *signal_stop;
198 static unsigned char *signal_print;
199 static unsigned char *signal_program;
200
201 #define SET_SIGS(nsigs,sigs,flags) \
202 do { \
203 int signum = (nsigs); \
204 while (signum-- > 0) \
205 if ((sigs)[signum]) \
206 (flags)[signum] = 1; \
207 } while (0)
208
209 #define UNSET_SIGS(nsigs,sigs,flags) \
210 do { \
211 int signum = (nsigs); \
212 while (signum-- > 0) \
213 if ((sigs)[signum]) \
214 (flags)[signum] = 0; \
215 } while (0)
216
217
218 /* Command list pointer for the "stop" placeholder. */
219
220 static struct cmd_list_element *stop_command;
221
222 /* Nonzero if breakpoints are now inserted in the inferior. */
223
224 static int breakpoints_inserted;
225
226 /* Function inferior was in as of last step command. */
227
228 static struct symbol *step_start_function;
229
230 /* Nonzero => address for special breakpoint for resuming stepping. */
231
232 static CORE_ADDR step_resume_break_address;
233
234 /* Pointer to orig contents of the byte where the special breakpoint is. */
235
236 static char step_resume_break_shadow[BREAKPOINT_MAX];
237
238 /* Nonzero means the special breakpoint is a duplicate
239 so it has not itself been inserted. */
240
241 static int step_resume_break_duplicate;
242
243 /* Nonzero if we are expecting a trace trap and should proceed from it. */
244
245 static int trap_expected;
246
247 /* Nonzero if the next time we try to continue the inferior, it will
248 step one instruction and generate a spurious trace trap.
249 This is used to compensate for a bug in HP-UX. */
250
251 static int trap_expected_after_continue;
252
253 /* Nonzero means expecting a trace trap
254 and should stop the inferior and return silently when it happens. */
255
256 int stop_after_trap;
257
258 /* Nonzero means expecting a trap and caller will handle it themselves.
259 It is used after attach, due to attaching to a process;
260 when running in the shell before the child program has been exec'd;
261 and when running some kinds of remote stuff (FIXME?). */
262
263 int stop_soon_quietly;
264
265 /* Nonzero if pc has been changed by the debugger
266 since the inferior stopped. */
267
268 int pc_changed;
269
270 /* Nonzero if proceed is being used for a "finish" command or a similar
271 situation when stop_registers should be saved. */
272
273 int proceed_to_finish;
274
275 /* Save register contents here when about to pop a stack dummy frame,
276 if-and-only-if proceed_to_finish is set.
277 Thus this contains the return value from the called function (assuming
278 values are returned in a register). */
279
280 char stop_registers[REGISTER_BYTES];
281
282 /* Nonzero if program stopped due to error trying to insert breakpoints. */
283
284 static int breakpoints_failed;
285
286 /* Nonzero after stop if current stack frame should be printed. */
287
288 static int stop_print_frame;
289
290 #ifdef NO_SINGLE_STEP
291 extern int one_stepped; /* From machine dependent code */
292 extern void single_step (); /* Same. */
293 #endif /* NO_SINGLE_STEP */
294
295 \f
296 /* Things to clean up if we QUIT out of resume (). */
297 /* ARGSUSED */
298 static void
299 resume_cleanups (arg)
300 int arg;
301 {
302 normal_stop ();
303 }
304
305 /* Resume the inferior, but allow a QUIT. This is useful if the user
306 wants to interrupt some lengthy single-stepping operation
307 (for child processes, the SIGINT goes to the inferior, and so
308 we get a SIGINT random_signal, but for remote debugging and perhaps
309 other targets, that's not true).
310
311 STEP nonzero if we should step (zero to continue instead).
312 SIG is the signal to give the inferior (zero for none). */
313 void
314 resume (step, sig)
315 int step;
316 int sig;
317 {
318 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
319 QUIT;
320
321 #ifdef NO_SINGLE_STEP
322 if (step) {
323 single_step(sig); /* Do it the hard way, w/temp breakpoints */
324 step = 0; /* ...and don't ask hardware to do it. */
325 }
326 #endif
327
328 /* Handle any optimized stores to the inferior NOW... */
329 #ifdef DO_DEFERRED_STORES
330 DO_DEFERRED_STORES;
331 #endif
332
333 target_resume (step, sig);
334 discard_cleanups (old_cleanups);
335 }
336
337 \f
338 /* Clear out all variables saying what to do when inferior is continued.
339 First do this, then set the ones you want, then call `proceed'. */
340
341 void
342 clear_proceed_status ()
343 {
344 trap_expected = 0;
345 step_range_start = 0;
346 step_range_end = 0;
347 step_frame_address = 0;
348 step_over_calls = -1;
349 step_resume_break_address = 0;
350 stop_after_trap = 0;
351 stop_soon_quietly = 0;
352 proceed_to_finish = 0;
353 breakpoint_proceeded = 1; /* We're about to proceed... */
354
355 /* Discard any remaining commands or status from previous stop. */
356 bpstat_clear (&stop_bpstat);
357 }
358
359 /* Basic routine for continuing the program in various fashions.
360
361 ADDR is the address to resume at, or -1 for resume where stopped.
362 SIGGNAL is the signal to give it, or 0 for none,
363 or -1 for act according to how it stopped.
364 STEP is nonzero if should trap after one instruction.
365 -1 means return after that and print nothing.
366 You should probably set various step_... variables
367 before calling here, if you are stepping.
368
369 You should call clear_proceed_status before calling proceed. */
370
371 void
372 proceed (addr, siggnal, step)
373 CORE_ADDR addr;
374 int siggnal;
375 int step;
376 {
377 int oneproc = 0;
378
379 if (step > 0)
380 step_start_function = find_pc_function (read_pc ());
381 if (step < 0)
382 stop_after_trap = 1;
383
384 if (addr == (CORE_ADDR)-1)
385 {
386 /* If there is a breakpoint at the address we will resume at,
387 step one instruction before inserting breakpoints
388 so that we do not stop right away. */
389
390 if (!pc_changed && breakpoint_here_p (read_pc ()))
391 oneproc = 1;
392 }
393 else
394 {
395 write_register (PC_REGNUM, addr);
396 #ifdef NPC_REGNUM
397 write_register (NPC_REGNUM, addr + 4);
398 #ifdef NNPC_REGNUM
399 write_register (NNPC_REGNUM, addr + 8);
400 #endif
401 #endif
402 }
403
404 if (trap_expected_after_continue)
405 {
406 /* If (step == 0), a trap will be automatically generated after
407 the first instruction is executed. Force step one
408 instruction to clear this condition. This should not occur
409 if step is nonzero, but it is harmless in that case. */
410 oneproc = 1;
411 trap_expected_after_continue = 0;
412 }
413
414 if (oneproc)
415 /* We will get a trace trap after one instruction.
416 Continue it automatically and insert breakpoints then. */
417 trap_expected = 1;
418 else
419 {
420 int temp = insert_breakpoints ();
421 if (temp)
422 {
423 print_sys_errmsg ("ptrace", temp);
424 error ("Cannot insert breakpoints.\n\
425 The same program may be running in another process.");
426 }
427 breakpoints_inserted = 1;
428 }
429
430 /* Install inferior's terminal modes. */
431 target_terminal_inferior ();
432
433 if (siggnal >= 0)
434 stop_signal = siggnal;
435 /* If this signal should not be seen by program,
436 give it zero. Used for debugging signals. */
437 else if (stop_signal < NSIG && !signal_program[stop_signal])
438 stop_signal= 0;
439
440 /* Resume inferior. */
441 resume (oneproc || step || bpstat_should_step (), stop_signal);
442
443 /* Wait for it to stop (if not standalone)
444 and in any case decode why it stopped, and act accordingly. */
445
446 wait_for_inferior ();
447 normal_stop ();
448 }
449
450 /* Record the pc and sp of the program the last time it stopped.
451 These are just used internally by wait_for_inferior, but need
452 to be preserved over calls to it and cleared when the inferior
453 is started. */
454 static CORE_ADDR prev_pc;
455 static CORE_ADDR prev_sp;
456 static CORE_ADDR prev_func_start;
457 static char *prev_func_name;
458
459 \f
460 /* Start remote-debugging of a machine over a serial link. */
461
462 void
463 start_remote ()
464 {
465 init_wait_for_inferior ();
466 clear_proceed_status ();
467 stop_soon_quietly = 1;
468 trap_expected = 0;
469 wait_for_inferior ();
470 normal_stop ();
471 }
472
473 /* Initialize static vars when a new inferior begins. */
474
475 void
476 init_wait_for_inferior ()
477 {
478 /* These are meaningless until the first time through wait_for_inferior. */
479 prev_pc = 0;
480 prev_sp = 0;
481 prev_func_start = 0;
482 prev_func_name = NULL;
483
484 trap_expected_after_continue = 0;
485 breakpoints_inserted = 0;
486 mark_breakpoints_out ();
487 stop_signal = 0; /* Don't confuse first call to proceed(). */
488 }
489
490
491 \f
492 /* Wait for control to return from inferior to debugger.
493 If inferior gets a signal, we may decide to start it up again
494 instead of returning. That is why there is a loop in this function.
495 When this function actually returns it means the inferior
496 should be left stopped and GDB should read more commands. */
497
498 void
499 wait_for_inferior ()
500 {
501 WAITTYPE w;
502 int another_trap;
503 int random_signal;
504 CORE_ADDR stop_sp;
505 CORE_ADDR stop_func_start;
506 char *stop_func_name;
507 CORE_ADDR prologue_pc, tmp;
508 int stop_step_resume_break;
509 struct symtab_and_line sal;
510 int remove_breakpoints_on_following_step = 0;
511 int current_line;
512 int handling_longjmp = 0; /* FIXME */
513 struct symtab *symtab;
514
515 sal = find_pc_line(prev_pc, 0);
516 current_line = sal.line;
517
518 while (1)
519 {
520 /* Clean up saved state that will become invalid. */
521 pc_changed = 0;
522 flush_cached_frames ();
523 registers_changed ();
524
525 target_wait (&w);
526
527 #ifdef SIGTRAP_STOP_AFTER_LOAD
528
529 /* Somebody called load(2), and it gave us a "trap signal after load".
530 Ignore it gracefully. */
531
532 SIGTRAP_STOP_AFTER_LOAD (w);
533 #endif
534
535 /* See if the process still exists; clean up if it doesn't. */
536 if (WIFEXITED (w))
537 {
538 target_terminal_ours (); /* Must do this before mourn anyway */
539 if (WEXITSTATUS (w))
540 printf_filtered ("\nProgram exited with code 0%o.\n",
541 (unsigned int)WEXITSTATUS (w));
542 else
543 if (!batch_mode())
544 printf_filtered ("\nProgram exited normally.\n");
545 fflush (stdout);
546 target_mourn_inferior ();
547 #ifdef NO_SINGLE_STEP
548 one_stepped = 0;
549 #endif
550 stop_print_frame = 0;
551 break;
552 }
553 else if (!WIFSTOPPED (w))
554 {
555 stop_print_frame = 0;
556 stop_signal = WTERMSIG (w);
557 target_terminal_ours (); /* Must do this before mourn anyway */
558 target_kill (); /* kill mourns as well */
559 #ifdef PRINT_RANDOM_SIGNAL
560 printf_filtered ("\nProgram terminated: ");
561 PRINT_RANDOM_SIGNAL (stop_signal);
562 #else
563 printf_filtered ("\nProgram terminated with signal %d, %s\n",
564 stop_signal, safe_strsignal (stop_signal));
565 #endif
566 printf_filtered ("The inferior process no longer exists.\n");
567 fflush (stdout);
568 #ifdef NO_SINGLE_STEP
569 one_stepped = 0;
570 #endif
571 break;
572 }
573
574 #ifdef NO_SINGLE_STEP
575 if (one_stepped)
576 single_step (0); /* This actually cleans up the ss */
577 #endif /* NO_SINGLE_STEP */
578
579 stop_pc = read_pc ();
580 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
581 read_pc ()));
582
583 stop_frame_address = FRAME_FP (get_current_frame ());
584 stop_sp = read_register (SP_REGNUM);
585 stop_func_start = 0;
586 stop_func_name = 0;
587 /* Don't care about return value; stop_func_start and stop_func_name
588 will both be 0 if it doesn't work. */
589 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start);
590 stop_func_start += FUNCTION_START_OFFSET;
591 another_trap = 0;
592 bpstat_clear (&stop_bpstat);
593 stop_step = 0;
594 stop_stack_dummy = 0;
595 stop_print_frame = 1;
596 stop_step_resume_break = 0;
597 random_signal = 0;
598 stopped_by_random_signal = 0;
599 breakpoints_failed = 0;
600
601 /* Look at the cause of the stop, and decide what to do.
602 The alternatives are:
603 1) break; to really stop and return to the debugger,
604 2) drop through to start up again
605 (set another_trap to 1 to single step once)
606 3) set random_signal to 1, and the decision between 1 and 2
607 will be made according to the signal handling tables. */
608
609 stop_signal = WSTOPSIG (w);
610
611 /* First, distinguish signals caused by the debugger from signals
612 that have to do with the program's own actions.
613 Note that breakpoint insns may cause SIGTRAP or SIGILL
614 or SIGEMT, depending on the operating system version.
615 Here we detect when a SIGILL or SIGEMT is really a breakpoint
616 and change it to SIGTRAP. */
617
618 if (stop_signal == SIGTRAP
619 || (breakpoints_inserted &&
620 (stop_signal == SIGILL
621 #ifdef SIGEMT
622 || stop_signal == SIGEMT
623 #endif
624 ))
625 || stop_soon_quietly)
626 {
627 if (stop_signal == SIGTRAP && stop_after_trap)
628 {
629 stop_print_frame = 0;
630 break;
631 }
632 if (stop_soon_quietly)
633 break;
634
635 /* Don't even think about breakpoints
636 if just proceeded over a breakpoint.
637
638 However, if we are trying to proceed over a breakpoint
639 and end up in sigtramp, then step_resume_break_address
640 will be set and we should check whether we've hit the
641 step breakpoint. */
642 if (stop_signal == SIGTRAP && trap_expected
643 && step_resume_break_address == 0)
644 bpstat_clear (&stop_bpstat);
645 else
646 {
647 /* See if there is a breakpoint at the current PC. */
648 #if DECR_PC_AFTER_BREAK
649 /* Notice the case of stepping through a jump
650 that lands just after a breakpoint.
651 Don't confuse that with hitting the breakpoint.
652 What we check for is that 1) stepping is going on
653 and 2) the pc before the last insn does not match
654 the address of the breakpoint before the current pc. */
655 if (prev_pc == stop_pc - DECR_PC_AFTER_BREAK
656 || !step_range_end
657 || step_resume_break_address
658 || handling_longjmp /* FIXME */)
659 #endif /* DECR_PC_AFTER_BREAK not zero */
660 {
661 /* See if we stopped at the special breakpoint for
662 stepping over a subroutine call. If both are zero,
663 this wasn't the reason for the stop. */
664 if (step_resume_break_address
665 && stop_pc - DECR_PC_AFTER_BREAK
666 == step_resume_break_address)
667 {
668 stop_step_resume_break = 1;
669 if (DECR_PC_AFTER_BREAK)
670 {
671 stop_pc -= DECR_PC_AFTER_BREAK;
672 write_register (PC_REGNUM, stop_pc);
673 pc_changed = 0;
674 }
675 }
676 else
677 {
678 stop_bpstat =
679 bpstat_stop_status (&stop_pc, stop_frame_address);
680 /* Following in case break condition called a
681 function. */
682 stop_print_frame = 1;
683 }
684 }
685 }
686
687 if (stop_signal == SIGTRAP)
688 random_signal
689 = !(bpstat_explains_signal (stop_bpstat)
690 || trap_expected
691 || stop_step_resume_break
692 || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
693 || (step_range_end && !step_resume_break_address));
694 else
695 {
696 random_signal
697 = !(bpstat_explains_signal (stop_bpstat)
698 || stop_step_resume_break
699 /* End of a stack dummy. Some systems (e.g. Sony
700 news) give another signal besides SIGTRAP,
701 so check here as well as above. */
702 || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
703 );
704 if (!random_signal)
705 stop_signal = SIGTRAP;
706 }
707 }
708 else
709 random_signal = 1;
710
711 /* For the program's own signals, act according to
712 the signal handling tables. */
713
714 if (random_signal)
715 {
716 /* Signal not for debugging purposes. */
717 int printed = 0;
718
719 stopped_by_random_signal = 1;
720
721 if (stop_signal >= NSIG
722 || signal_print[stop_signal])
723 {
724 printed = 1;
725 target_terminal_ours_for_output ();
726 #ifdef PRINT_RANDOM_SIGNAL
727 PRINT_RANDOM_SIGNAL (stop_signal);
728 #else
729 printf_filtered ("\nProgram received signal %d, %s\n",
730 stop_signal, safe_strsignal (stop_signal));
731 #endif /* PRINT_RANDOM_SIGNAL */
732 fflush (stdout);
733 }
734 if (stop_signal >= NSIG
735 || signal_stop[stop_signal])
736 break;
737 /* If not going to stop, give terminal back
738 if we took it away. */
739 else if (printed)
740 target_terminal_inferior ();
741
742 /* Note that virtually all the code below does `if !random_signal'.
743 Perhaps this code should end with a goto or continue. At least
744 one (now fixed) bug was caused by this -- a !random_signal was
745 missing in one of the tests below. */
746 }
747
748 /* Handle cases caused by hitting a breakpoint. */
749
750 if (!random_signal)
751 if (bpstat_explains_signal (stop_bpstat))
752 {
753 CORE_ADDR jmp_buf_pc;
754
755 switch (stop_bpstat->breakpoint_at->type) /* FIXME */
756 {
757 /* If we hit the breakpoint at longjmp, disable it for the
758 duration of this command. Then, install a temporary
759 breakpoint at the target of the jmp_buf. */
760 case bp_longjmp:
761 disable_longjmp_breakpoint();
762 remove_breakpoints ();
763 breakpoints_inserted = 0;
764 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
765
766 /* Need to blow away step-resume breakpoint, as it
767 interferes with us */
768 remove_step_breakpoint ();
769 step_resume_break_address = 0;
770 stop_step_resume_break = 0;
771
772 #if 0 /* FIXME - Need to implement nested temporary breakpoints */
773 if (step_over_calls > 0)
774 set_longjmp_resume_breakpoint(jmp_buf_pc,
775 get_current_frame());
776 else
777 #endif /* 0 */
778 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
779 handling_longjmp = 1; /* FIXME */
780 goto keep_going;
781
782 case bp_longjmp_resume:
783 remove_breakpoints ();
784 breakpoints_inserted = 0;
785 #if 0 /* FIXME - Need to implement nested temporary breakpoints */
786 if (step_over_calls
787 && (stop_frame_address
788 INNER_THAN step_frame_address))
789 {
790 another_trap = 1;
791 goto keep_going;
792 }
793 #endif /* 0 */
794 disable_longjmp_breakpoint();
795 handling_longjmp = 0; /* FIXME */
796 break;
797
798 default:
799 fprintf(stderr, "Unknown breakpoint type %d\n",
800 stop_bpstat->breakpoint_at->type);
801 case bp_watchpoint:
802 case bp_breakpoint:
803 case bp_until:
804 case bp_finish:
805 /* Does a breakpoint want us to stop? */
806 if (bpstat_stop (stop_bpstat))
807 {
808 stop_print_frame = bpstat_should_print (stop_bpstat);
809 goto stop_stepping;
810 }
811 /* Otherwise, must remove breakpoints and single-step
812 to get us past the one we hit. */
813 else
814 {
815 remove_breakpoints ();
816 remove_step_breakpoint ();
817 breakpoints_inserted = 0;
818 another_trap = 1;
819 }
820 break;
821 }
822 }
823 else if (stop_step_resume_break)
824 {
825 /* But if we have hit the step-resumption breakpoint,
826 remove it. It has done its job getting us here.
827 The sp test is to make sure that we don't get hung
828 up in recursive calls in functions without frame
829 pointers. If the stack pointer isn't outside of
830 where the breakpoint was set (within a routine to be
831 stepped over), we're in the middle of a recursive
832 call. Not true for reg window machines (sparc)
833 because the must change frames to call things and
834 the stack pointer doesn't have to change if it
835 the bp was set in a routine without a frame (pc can
836 be stored in some other window).
837
838 The removal of the sp test is to allow calls to
839 alloca. Nasty things were happening. Oh, well,
840 gdb can only handle one level deep of lack of
841 frame pointer. */
842
843 /*
844 Disable test for step_frame_address match so that we always stop even if the
845 frames don't match. Reason: if we hit the step_resume_breakpoint, there is
846 no way to temporarily disable it so that we can step past it. If we leave
847 the breakpoint in, then we loop forever repeatedly hitting, but never
848 getting past the breakpoint. This change keeps nexting over recursive
849 function calls from hanging gdb.
850 */
851 #if 0
852 if (* step_frame_address == 0
853 || (step_frame_address == stop_frame_address))
854 #endif
855 {
856 remove_step_breakpoint ();
857 step_resume_break_address = 0;
858
859 /* If were waiting for a trap, hitting the step_resume_break
860 doesn't count as getting it. */
861 if (trap_expected)
862 another_trap = 1;
863 }
864 }
865
866 /* We come here if we hit a breakpoint but should not
867 stop for it. Possibly we also were stepping
868 and should stop for that. So fall through and
869 test for stepping. But, if not stepping,
870 do not stop. */
871
872 /* If this is the breakpoint at the end of a stack dummy,
873 just stop silently. */
874 if (!random_signal
875 && PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address))
876 {
877 stop_print_frame = 0;
878 stop_stack_dummy = 1;
879 #ifdef HP_OS_BUG
880 trap_expected_after_continue = 1;
881 #endif
882 break;
883 }
884
885 if (step_resume_break_address)
886 /* Having a step-resume breakpoint overrides anything
887 else having to do with stepping commands until
888 that breakpoint is reached. */
889 ;
890 /* If stepping through a line, keep going if still within it. */
891 else if (!random_signal
892 && step_range_end
893 && stop_pc >= step_range_start
894 && stop_pc < step_range_end
895 /* The step range might include the start of the
896 function, so if we are at the start of the
897 step range and either the stack or frame pointers
898 just changed, we've stepped outside */
899 && !(stop_pc == step_range_start
900 && stop_frame_address
901 && (stop_sp INNER_THAN prev_sp
902 || stop_frame_address != step_frame_address)))
903 {
904 ;
905 }
906
907 /* We stepped out of the stepping range. See if that was due
908 to a subroutine call that we should proceed to the end of. */
909 else if (!random_signal && step_range_end)
910 {
911 if (stop_func_start)
912 {
913 prologue_pc = stop_func_start;
914 SKIP_PROLOGUE (prologue_pc);
915 }
916
917 /* Did we just take a signal? */
918 if (IN_SIGTRAMP (stop_pc, stop_func_name)
919 && !IN_SIGTRAMP (prev_pc, prev_func_name))
920 {
921 /* This code is needed at least in the following case:
922 The user types "next" and then a signal arrives (before
923 the "next" is done). */
924 /* We've just taken a signal; go until we are back to
925 the point where we took it and one more. */
926 step_resume_break_address = prev_pc;
927 step_resume_break_duplicate =
928 breakpoint_here_p (step_resume_break_address);
929 if (breakpoints_inserted)
930 insert_step_breakpoint ();
931 /* Make sure that the stepping range gets us past
932 that instruction. */
933 if (step_range_end == 1)
934 step_range_end = (step_range_start = prev_pc) + 1;
935 remove_breakpoints_on_following_step = 1;
936 goto save_pc;
937 }
938
939 /* ==> See comments at top of file on this algorithm. <==*/
940
941 if ((stop_pc == stop_func_start
942 || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name))
943 && (stop_func_start != prev_func_start
944 || prologue_pc != stop_func_start
945 || stop_sp != prev_sp))
946 {
947 /* It's a subroutine call.
948 (0) If we are not stepping over any calls ("stepi"), we
949 just stop.
950 (1) If we're doing a "next", we want to continue through
951 the call ("step over the call").
952 (2) If we are in a function-call trampoline (a stub between
953 the calling routine and the real function), locate
954 the real function and change stop_func_start.
955 (3) If we're doing a "step", and there are no debug symbols
956 at the target of the call, we want to continue through
957 it ("step over the call").
958 (4) Otherwise, we want to stop soon, after the function
959 prologue ("step into the call"). */
960
961 if (step_over_calls == 0)
962 {
963 /* I presume that step_over_calls is only 0 when we're
964 supposed to be stepping at the assembly language level. */
965 stop_step = 1;
966 break;
967 }
968
969 if (step_over_calls > 0)
970 goto step_over_function;
971
972 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
973 if (tmp != 0)
974 stop_func_start = tmp;
975
976 symtab = find_pc_symtab (stop_pc);
977 if (symtab && LINETABLE (symtab))
978 goto step_into_function;
979
980 step_over_function:
981 /* A subroutine call has happened. */
982 /* Set a special breakpoint after the return */
983 step_resume_break_address =
984 ADDR_BITS_REMOVE
985 (SAVED_PC_AFTER_CALL (get_current_frame ()));
986 step_resume_break_duplicate
987 = breakpoint_here_p (step_resume_break_address);
988 if (breakpoints_inserted)
989 insert_step_breakpoint ();
990 goto save_pc;
991
992 step_into_function:
993 /* Subroutine call with source code we should not step over.
994 Do step to the first line of code in it. */
995 SKIP_PROLOGUE (stop_func_start);
996 sal = find_pc_line (stop_func_start, 0);
997 /* Use the step_resume_break to step until
998 the end of the prologue, even if that involves jumps
999 (as it seems to on the vax under 4.2). */
1000 /* If the prologue ends in the middle of a source line,
1001 continue to the end of that source line.
1002 Otherwise, just go to end of prologue. */
1003 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1004 /* no, don't either. It skips any code that's
1005 legitimately on the first line. */
1006 #else
1007 if (sal.end && sal.pc != stop_func_start)
1008 stop_func_start = sal.end;
1009 #endif
1010
1011 if (stop_func_start == stop_pc)
1012 {
1013 /* We are already there: stop now. */
1014 stop_step = 1;
1015 break;
1016 }
1017 else
1018 /* Put the step-breakpoint there and go until there. */
1019 {
1020 step_resume_break_address = stop_func_start;
1021
1022 step_resume_break_duplicate
1023 = breakpoint_here_p (step_resume_break_address);
1024 if (breakpoints_inserted)
1025 insert_step_breakpoint ();
1026 /* Do not specify what the fp should be when we stop
1027 since on some machines the prologue
1028 is where the new fp value is established. */
1029 step_frame_address = 0;
1030 /* And make sure stepping stops right away then. */
1031 step_range_end = step_range_start;
1032 }
1033 goto save_pc;
1034 }
1035
1036 /* We've wandered out of the step range (but haven't done a
1037 subroutine call or return). */
1038
1039 sal = find_pc_line(stop_pc, 0);
1040
1041 if (step_range_end == 1 || /* stepi or nexti */
1042 sal.line == 0 || /* ...or no line # info */
1043 (stop_pc == sal.pc /* ...or we're at the start */
1044 && current_line != sal.line)) { /* of a different line */
1045 /* Stop because we're done stepping. */
1046 stop_step = 1;
1047 break;
1048 } else {
1049 /* We aren't done stepping, and we have line number info for $pc.
1050 Optimize by setting the step_range for the line.
1051 (We might not be in the original line, but if we entered a
1052 new line in mid-statement, we continue stepping. This makes
1053 things like for(;;) statements work better.) */
1054 step_range_start = sal.pc;
1055 step_range_end = sal.end;
1056 goto save_pc;
1057 }
1058 /* We never fall through here */
1059 }
1060
1061 if (trap_expected
1062 && IN_SIGTRAMP (stop_pc, stop_func_name)
1063 && !IN_SIGTRAMP (prev_pc, prev_func_name))
1064 {
1065 /* What has happened here is that we have just stepped the inferior
1066 with a signal (because it is a signal which shouldn't make
1067 us stop), thus stepping into sigtramp.
1068
1069 So we need to set a step_resume_break_address breakpoint
1070 and continue until we hit it, and then step. */
1071 step_resume_break_address = prev_pc;
1072 /* Always 1, I think, but it's probably easier to have
1073 the step_resume_break as usual rather than trying to
1074 re-use the breakpoint which is already there. */
1075 step_resume_break_duplicate =
1076 breakpoint_here_p (step_resume_break_address);
1077 if (breakpoints_inserted)
1078 insert_step_breakpoint ();
1079 remove_breakpoints_on_following_step = 1;
1080 another_trap = 1;
1081 }
1082
1083 /* My apologies to the gods of structured programming. */
1084 /* Come to this label when you need to resume the inferior. It's really much
1085 cleaner at this time to do a goto than to try and figure out what the
1086 if-else chain ought to look like!! */
1087
1088 keep_going:
1089
1090 save_pc:
1091 /* Save the pc before execution, to compare with pc after stop. */
1092 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1093 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1094 BREAK is defined, the
1095 original pc would not have
1096 been at the start of a
1097 function. */
1098 prev_func_name = stop_func_name;
1099 prev_sp = stop_sp;
1100
1101 /* If we did not do break;, it means we should keep
1102 running the inferior and not return to debugger. */
1103
1104 if (trap_expected && stop_signal != SIGTRAP)
1105 {
1106 /* We took a signal (which we are supposed to pass through to
1107 the inferior, else we'd have done a break above) and we
1108 haven't yet gotten our trap. Simply continue. */
1109 resume ((step_range_end && !step_resume_break_address)
1110 || (trap_expected && !step_resume_break_address)
1111 || bpstat_should_step (),
1112 stop_signal);
1113 }
1114 else
1115 {
1116 /* Either the trap was not expected, but we are continuing
1117 anyway (the user asked that this signal be passed to the
1118 child)
1119 -- or --
1120 The signal was SIGTRAP, e.g. it was our signal, but we
1121 decided we should resume from it.
1122
1123 We're going to run this baby now!
1124
1125 Insert breakpoints now, unless we are trying
1126 to one-proceed past a breakpoint. */
1127 /* If we've just finished a special step resume and we don't
1128 want to hit a breakpoint, pull em out. */
1129 if (!step_resume_break_address &&
1130 remove_breakpoints_on_following_step)
1131 {
1132 remove_breakpoints_on_following_step = 0;
1133 remove_breakpoints ();
1134 breakpoints_inserted = 0;
1135 }
1136 else if (!breakpoints_inserted &&
1137 (step_resume_break_address != 0 || !another_trap))
1138 {
1139 insert_step_breakpoint ();
1140 breakpoints_failed = insert_breakpoints ();
1141 if (breakpoints_failed)
1142 break;
1143 breakpoints_inserted = 1;
1144 }
1145
1146 trap_expected = another_trap;
1147
1148 if (stop_signal == SIGTRAP)
1149 stop_signal = 0;
1150
1151 #ifdef SHIFT_INST_REGS
1152 /* I'm not sure when this following segment applies. I do know, now,
1153 that we shouldn't rewrite the regs when we were stopped by a
1154 random signal from the inferior process. */
1155
1156 if (!bpstat_explains_signal (stop_bpstat)
1157 && (stop_signal != SIGCLD)
1158 && !stopped_by_random_signal)
1159 {
1160 CORE_ADDR pc_contents = read_register (PC_REGNUM);
1161 CORE_ADDR npc_contents = read_register (NPC_REGNUM);
1162 if (pc_contents != npc_contents)
1163 {
1164 write_register (NNPC_REGNUM, npc_contents);
1165 write_register (NPC_REGNUM, pc_contents);
1166 }
1167 }
1168 #endif /* SHIFT_INST_REGS */
1169
1170 resume ((!step_resume_break_address
1171 && !handling_longjmp
1172 && (step_range_end
1173 || trap_expected))
1174 || bpstat_should_step (),
1175 stop_signal);
1176 }
1177 }
1178
1179 stop_stepping:
1180 if (target_has_execution)
1181 {
1182 /* Assuming the inferior still exists, set these up for next
1183 time, just like we did above if we didn't break out of the
1184 loop. */
1185 prev_pc = read_pc ();
1186 prev_func_start = stop_func_start;
1187 prev_func_name = stop_func_name;
1188 prev_sp = stop_sp;
1189 }
1190 }
1191 \f
1192 /* Here to return control to GDB when the inferior stops for real.
1193 Print appropriate messages, remove breakpoints, give terminal our modes.
1194
1195 STOP_PRINT_FRAME nonzero means print the executing frame
1196 (pc, function, args, file, line number and line text).
1197 BREAKPOINTS_FAILED nonzero means stop was due to error
1198 attempting to insert breakpoints. */
1199
1200 void
1201 normal_stop ()
1202 {
1203 /* Make sure that the current_frame's pc is correct. This
1204 is a correction for setting up the frame info before doing
1205 DECR_PC_AFTER_BREAK */
1206 if (target_has_execution)
1207 (get_current_frame ())->pc = read_pc ();
1208
1209 if (breakpoints_failed)
1210 {
1211 target_terminal_ours_for_output ();
1212 print_sys_errmsg ("ptrace", breakpoints_failed);
1213 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1214 The same program may be running in another process.\n");
1215 }
1216
1217 if (target_has_execution)
1218 remove_step_breakpoint ();
1219
1220 if (target_has_execution && breakpoints_inserted)
1221 if (remove_breakpoints ())
1222 {
1223 target_terminal_ours_for_output ();
1224 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1225 It might be running in another process.\n\
1226 Further execution is probably impossible.\n");
1227 }
1228
1229 breakpoints_inserted = 0;
1230
1231 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1232 Delete any breakpoint that is to be deleted at the next stop. */
1233
1234 breakpoint_auto_delete (stop_bpstat);
1235
1236 /* If an auto-display called a function and that got a signal,
1237 delete that auto-display to avoid an infinite recursion. */
1238
1239 if (stopped_by_random_signal)
1240 disable_current_display ();
1241
1242 if (step_multi && stop_step)
1243 return;
1244
1245 target_terminal_ours ();
1246
1247 /* Look up the hook_stop and run it if it exists. */
1248
1249 if (stop_command->hook)
1250 {
1251 catch_errors (hook_stop_stub, (char *)stop_command->hook,
1252 "Error while running hook_stop:\n");
1253 }
1254
1255 if (!target_has_stack)
1256 return;
1257
1258 /* Select innermost stack frame except on return from a stack dummy routine,
1259 or if the program has exited. Print it without a level number if
1260 we have changed functions or hit a breakpoint. Print source line
1261 if we have one. */
1262 if (!stop_stack_dummy)
1263 {
1264 select_frame (get_current_frame (), 0);
1265
1266 if (stop_print_frame)
1267 {
1268 int source_only;
1269
1270 source_only = bpstat_print (stop_bpstat);
1271 source_only = source_only ||
1272 ( stop_step
1273 && step_frame_address == stop_frame_address
1274 && step_start_function == find_pc_function (stop_pc));
1275
1276 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1277
1278 /* Display the auto-display expressions. */
1279 do_displays ();
1280 }
1281 }
1282
1283 /* Save the function value return registers, if we care.
1284 We might be about to restore their previous contents. */
1285 if (proceed_to_finish)
1286 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1287
1288 if (stop_stack_dummy)
1289 {
1290 /* Pop the empty frame that contains the stack dummy.
1291 POP_FRAME ends with a setting of the current frame, so we
1292 can use that next. */
1293 POP_FRAME;
1294 select_frame (get_current_frame (), 0);
1295 }
1296 }
1297
1298 static int
1299 hook_stop_stub (cmd)
1300 char *cmd;
1301 {
1302 execute_user_command ((struct cmd_list_element *)cmd, 0);
1303 return (0);
1304 }
1305
1306 \f
1307 static void
1308 insert_step_breakpoint ()
1309 {
1310 if (step_resume_break_address && !step_resume_break_duplicate)
1311 target_insert_breakpoint (step_resume_break_address,
1312 step_resume_break_shadow);
1313 }
1314
1315 static void
1316 remove_step_breakpoint ()
1317 {
1318 if (step_resume_break_address && !step_resume_break_duplicate)
1319 target_remove_breakpoint (step_resume_break_address,
1320 step_resume_break_shadow);
1321 }
1322 \f
1323 int signal_stop_state (signo)
1324 int signo;
1325 {
1326 return ((signo >= 0 && signo < NSIG) ? signal_stop[signo] : 0);
1327 }
1328
1329 int signal_print_state (signo)
1330 int signo;
1331 {
1332 return ((signo >= 0 && signo < NSIG) ? signal_print[signo] : 0);
1333 }
1334
1335 int signal_pass_state (signo)
1336 int signo;
1337 {
1338 return ((signo >= 0 && signo < NSIG) ? signal_program[signo] : 0);
1339 }
1340
1341 static void
1342 sig_print_header ()
1343 {
1344 printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n");
1345 }
1346
1347 static void
1348 sig_print_info (number)
1349 int number;
1350 {
1351 char *name;
1352
1353 if ((name = strsigno (number)) == NULL)
1354 printf_filtered ("%d\t\t", number);
1355 else
1356 printf_filtered ("%s (%d)\t", name, number);
1357 printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No");
1358 printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No");
1359 printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No");
1360 printf_filtered ("%s\n", safe_strsignal (number));
1361 }
1362
1363 /* Specify how various signals in the inferior should be handled. */
1364
1365 static void
1366 handle_command (args, from_tty)
1367 char *args;
1368 int from_tty;
1369 {
1370 char **argv;
1371 int digits, wordlen;
1372 int sigfirst, signum, siglast;
1373 int allsigs;
1374 int nsigs;
1375 unsigned char *sigs;
1376 struct cleanup *old_chain;
1377
1378 if (args == NULL)
1379 {
1380 error_no_arg ("signal to handle");
1381 }
1382
1383 /* Allocate and zero an array of flags for which signals to handle. */
1384
1385 nsigs = signo_max () + 1;
1386 sigs = (unsigned char *) alloca (nsigs);
1387 memset (sigs, 0, nsigs);
1388
1389 /* Break the command line up into args. */
1390
1391 argv = buildargv (args);
1392 if (argv == NULL)
1393 {
1394 nomem (0);
1395 }
1396 old_chain = make_cleanup (freeargv, (char *) argv);
1397
1398 /* Walk through the args, looking for signal numbers, signal names, and
1399 actions. Signal numbers and signal names may be interspersed with
1400 actions, with the actions being performed for all signals cumulatively
1401 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1402
1403 while (*argv != NULL)
1404 {
1405 wordlen = strlen (*argv);
1406 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1407 allsigs = 0;
1408 sigfirst = siglast = -1;
1409
1410 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1411 {
1412 /* Apply action to all signals except those used by the
1413 debugger. Silently skip those. */
1414 allsigs = 1;
1415 sigfirst = 0;
1416 siglast = nsigs - 1;
1417 }
1418 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1419 {
1420 SET_SIGS (nsigs, sigs, signal_stop);
1421 SET_SIGS (nsigs, sigs, signal_print);
1422 }
1423 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1424 {
1425 UNSET_SIGS (nsigs, sigs, signal_program);
1426 }
1427 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1428 {
1429 SET_SIGS (nsigs, sigs, signal_print);
1430 }
1431 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1432 {
1433 SET_SIGS (nsigs, sigs, signal_program);
1434 }
1435 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1436 {
1437 UNSET_SIGS (nsigs, sigs, signal_stop);
1438 }
1439 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1440 {
1441 SET_SIGS (nsigs, sigs, signal_program);
1442 }
1443 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1444 {
1445 UNSET_SIGS (nsigs, sigs, signal_print);
1446 UNSET_SIGS (nsigs, sigs, signal_stop);
1447 }
1448 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1449 {
1450 UNSET_SIGS (nsigs, sigs, signal_program);
1451 }
1452 else if (digits > 0)
1453 {
1454 sigfirst = siglast = atoi (*argv);
1455 if ((*argv)[digits] == '-')
1456 {
1457 siglast = atoi ((*argv) + digits + 1);
1458 }
1459 if (sigfirst > siglast)
1460 {
1461 /* Bet he didn't figure we'd think of this case... */
1462 signum = sigfirst;
1463 sigfirst = siglast;
1464 siglast = signum;
1465 }
1466 if (sigfirst < 0 || sigfirst >= nsigs)
1467 {
1468 error ("Signal %d not in range 0-%d", sigfirst, nsigs - 1);
1469 }
1470 if (siglast < 0 || siglast >= nsigs)
1471 {
1472 error ("Signal %d not in range 0-%d", siglast, nsigs - 1);
1473 }
1474 }
1475 else if ((signum = strtosigno (*argv)) != 0)
1476 {
1477 sigfirst = siglast = signum;
1478 }
1479 else
1480 {
1481 /* Not a number and not a recognized flag word => complain. */
1482 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
1483 }
1484
1485 /* If any signal numbers or symbol names were found, set flags for
1486 which signals to apply actions to. */
1487
1488 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
1489 {
1490 switch (signum)
1491 {
1492 case SIGTRAP:
1493 case SIGINT:
1494 if (!allsigs && !sigs[signum])
1495 {
1496 if (query ("%s is used by the debugger.\nAre you sure you want to change it? ", strsigno (signum)))
1497 {
1498 sigs[signum] = 1;
1499 }
1500 else
1501 {
1502 printf ("Not confirmed, unchanged.\n");
1503 fflush (stdout);
1504 }
1505 }
1506 break;
1507 default:
1508 sigs[signum] = 1;
1509 break;
1510 }
1511 }
1512
1513 argv++;
1514 }
1515
1516 target_notice_signals();
1517
1518 if (from_tty)
1519 {
1520 /* Show the results. */
1521 sig_print_header ();
1522 for (signum = 0; signum < nsigs; signum++)
1523 {
1524 if (sigs[signum])
1525 {
1526 sig_print_info (signum);
1527 }
1528 }
1529 }
1530
1531 do_cleanups (old_chain);
1532 }
1533
1534 /* Print current contents of the tables set by the handle command. */
1535
1536 static void
1537 signals_info (signum_exp, from_tty)
1538 char *signum_exp;
1539 int from_tty;
1540 {
1541 register int i;
1542 sig_print_header ();
1543
1544 if (signum_exp)
1545 {
1546 /* First see if this is a symbol name. */
1547 i = strtosigno (signum_exp);
1548 if (i == 0)
1549 {
1550 /* Nope, maybe it's an address which evaluates to a signal
1551 number. */
1552 i = parse_and_eval_address (signum_exp);
1553 if (i >= NSIG || i < 0)
1554 error ("Signal number out of bounds.");
1555 }
1556 sig_print_info (i);
1557 return;
1558 }
1559
1560 printf_filtered ("\n");
1561 for (i = 0; i < NSIG; i++)
1562 {
1563 QUIT;
1564
1565 sig_print_info (i);
1566 }
1567
1568 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1569 }
1570 \f
1571 /* Save all of the information associated with the inferior<==>gdb
1572 connection. INF_STATUS is a pointer to a "struct inferior_status"
1573 (defined in inferior.h). */
1574
1575 void
1576 save_inferior_status (inf_status, restore_stack_info)
1577 struct inferior_status *inf_status;
1578 int restore_stack_info;
1579 {
1580 inf_status->pc_changed = pc_changed;
1581 inf_status->stop_signal = stop_signal;
1582 inf_status->stop_pc = stop_pc;
1583 inf_status->stop_frame_address = stop_frame_address;
1584 inf_status->stop_step = stop_step;
1585 inf_status->stop_stack_dummy = stop_stack_dummy;
1586 inf_status->stopped_by_random_signal = stopped_by_random_signal;
1587 inf_status->trap_expected = trap_expected;
1588 inf_status->step_range_start = step_range_start;
1589 inf_status->step_range_end = step_range_end;
1590 inf_status->step_frame_address = step_frame_address;
1591 inf_status->step_over_calls = step_over_calls;
1592 inf_status->step_resume_break_address = step_resume_break_address;
1593 inf_status->stop_after_trap = stop_after_trap;
1594 inf_status->stop_soon_quietly = stop_soon_quietly;
1595 /* Save original bpstat chain here; replace it with copy of chain.
1596 If caller's caller is walking the chain, they'll be happier if we
1597 hand them back the original chain when restore_i_s is called. */
1598 inf_status->stop_bpstat = stop_bpstat;
1599 stop_bpstat = bpstat_copy (stop_bpstat);
1600 inf_status->breakpoint_proceeded = breakpoint_proceeded;
1601 inf_status->restore_stack_info = restore_stack_info;
1602 inf_status->proceed_to_finish = proceed_to_finish;
1603
1604 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
1605
1606 record_selected_frame (&(inf_status->selected_frame_address),
1607 &(inf_status->selected_level));
1608 return;
1609 }
1610
1611 void
1612 restore_inferior_status (inf_status)
1613 struct inferior_status *inf_status;
1614 {
1615 FRAME fid;
1616 int level = inf_status->selected_level;
1617
1618 pc_changed = inf_status->pc_changed;
1619 stop_signal = inf_status->stop_signal;
1620 stop_pc = inf_status->stop_pc;
1621 stop_frame_address = inf_status->stop_frame_address;
1622 stop_step = inf_status->stop_step;
1623 stop_stack_dummy = inf_status->stop_stack_dummy;
1624 stopped_by_random_signal = inf_status->stopped_by_random_signal;
1625 trap_expected = inf_status->trap_expected;
1626 step_range_start = inf_status->step_range_start;
1627 step_range_end = inf_status->step_range_end;
1628 step_frame_address = inf_status->step_frame_address;
1629 step_over_calls = inf_status->step_over_calls;
1630 step_resume_break_address = inf_status->step_resume_break_address;
1631 stop_after_trap = inf_status->stop_after_trap;
1632 stop_soon_quietly = inf_status->stop_soon_quietly;
1633 bpstat_clear (&stop_bpstat);
1634 stop_bpstat = inf_status->stop_bpstat;
1635 breakpoint_proceeded = inf_status->breakpoint_proceeded;
1636 proceed_to_finish = inf_status->proceed_to_finish;
1637
1638 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
1639
1640 /* The inferior can be gone if the user types "print exit(0)"
1641 (and perhaps other times). */
1642 if (target_has_stack && inf_status->restore_stack_info)
1643 {
1644 fid = find_relative_frame (get_current_frame (),
1645 &level);
1646
1647 /* If inf_status->selected_frame_address is NULL, there was no
1648 previously selected frame. */
1649 if (fid == 0 ||
1650 FRAME_FP (fid) != inf_status->selected_frame_address ||
1651 level != 0)
1652 {
1653 #if 1
1654 /* I'm not sure this error message is a good idea. I have
1655 only seen it occur after "Can't continue previously
1656 requested operation" (we get called from do_cleanups), in
1657 which case it just adds insult to injury (one confusing
1658 error message after another. Besides which, does the
1659 user really care if we can't restore the previously
1660 selected frame? */
1661 fprintf (stderr, "Unable to restore previously selected frame.\n");
1662 #endif
1663 select_frame (get_current_frame (), 0);
1664 return;
1665 }
1666
1667 select_frame (fid, inf_status->selected_level);
1668 }
1669 }
1670
1671 \f
1672 void
1673 _initialize_infrun ()
1674 {
1675 register int i;
1676 register int numsigs;
1677
1678 add_info ("signals", signals_info,
1679 "What debugger does when program gets various signals.\n\
1680 Specify a signal number as argument to print info on that signal only.");
1681 add_info_alias ("handle", "signals", 0);
1682
1683 add_com ("handle", class_run, handle_command,
1684 "Specify how to handle a signal.\n\
1685 Args are signal numbers and actions to apply to those signals.\n\
1686 Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
1687 Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
1688 The special arg \"all\" is recognized to mean all signals except those\n\
1689 used by the debugger, typically SIGTRAP and SIGINT.\n\
1690 Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
1691 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
1692 Stop means reenter debugger if this signal happens (implies print).\n\
1693 Print means print a message if this signal happens.\n\
1694 Pass means let program see this signal; otherwise program doesn't know.\n\
1695 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
1696 Pass and Stop may be combined.");
1697
1698 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
1699 "There is no `stop' command, but you can set a hook on `stop'.\n\
1700 This allows you to set a list of commands to be run each time execution\n\
1701 of the inferior program stops.", &cmdlist);
1702
1703 numsigs = signo_max () + 1;
1704 signal_stop = (unsigned char *)
1705 xmalloc (sizeof (signal_stop[0]) * numsigs);
1706 signal_print = (unsigned char *)
1707 xmalloc (sizeof (signal_print[0]) * numsigs);
1708 signal_program = (unsigned char *)
1709 xmalloc (sizeof (signal_program[0]) * numsigs);
1710 for (i = 0; i < numsigs; i++)
1711 {
1712 signal_stop[i] = 1;
1713 signal_print[i] = 1;
1714 signal_program[i] = 1;
1715 }
1716
1717 /* Signals caused by debugger's own actions
1718 should not be given to the program afterwards. */
1719 signal_program[SIGTRAP] = 0;
1720 signal_program[SIGINT] = 0;
1721
1722 /* Signals that are not errors should not normally enter the debugger. */
1723 #ifdef SIGALRM
1724 signal_stop[SIGALRM] = 0;
1725 signal_print[SIGALRM] = 0;
1726 #endif /* SIGALRM */
1727 #ifdef SIGVTALRM
1728 signal_stop[SIGVTALRM] = 0;
1729 signal_print[SIGVTALRM] = 0;
1730 #endif /* SIGVTALRM */
1731 #ifdef SIGPROF
1732 signal_stop[SIGPROF] = 0;
1733 signal_print[SIGPROF] = 0;
1734 #endif /* SIGPROF */
1735 #ifdef SIGCHLD
1736 signal_stop[SIGCHLD] = 0;
1737 signal_print[SIGCHLD] = 0;
1738 #endif /* SIGCHLD */
1739 #ifdef SIGCLD
1740 signal_stop[SIGCLD] = 0;
1741 signal_print[SIGCLD] = 0;
1742 #endif /* SIGCLD */
1743 #ifdef SIGIO
1744 signal_stop[SIGIO] = 0;
1745 signal_print[SIGIO] = 0;
1746 #endif /* SIGIO */
1747 #ifdef SIGURG
1748 signal_stop[SIGURG] = 0;
1749 signal_print[SIGURG] = 0;
1750 #endif /* SIGURG */
1751 }