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