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