1 /* Start and stop the inferior process, for GDB.
2 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
22 #include "initialize.h"
34 #include <sys/param.h>
35 #include <sys/ptrace.h>
38 extern char *sys_siglist
[];
41 /* Tables of how to react to signals; the user sets them. */
43 static char signal_stop
[NSIG
];
44 static char signal_print
[NSIG
];
45 static char signal_program
[NSIG
];
47 /* Nonzero if breakpoints are now inserted in the inferior. */
49 static int breakpoints_inserted
;
51 /* Function inferior was in as of last step command. */
53 static struct symbol
*step_start_function
;
55 /* This is the sequence of bytes we insert for a breakpoint. */
57 static char break_insn
[] = BREAKPOINT
;
59 /* Nonzero => address for special breakpoint for resuming stepping. */
61 static CORE_ADDR step_resume_break_address
;
63 /* Original contents of the byte where the special breakpoint is. */
65 static char step_resume_break_shadow
[sizeof break_insn
];
67 /* Nonzero means the special breakpoint is a duplicate
68 so it has not itself been inserted. */
70 static int step_resume_break_duplicate
;
72 /* Nonzero if we are expecting a trace trap and should proceed from it.
73 2 means expecting 2 trace traps and should continue both times.
74 That occurs when we tell sh to exec the program: we will get
75 a trap after the exec of sh and a second when the program is exec'd. */
77 static int trap_expected
;
79 /* Nonzero if the next time we try to continue the inferior, it will
80 step one instruction and generate a spurious trace trap.
81 This is used to compensate for a bug in HP-UX. */
83 static int trap_expected_after_continue
;
85 /* Nonzero means expecting a trace trap
86 and should stop the inferior and return silently when it happens. */
88 static int stop_after_trap
;
90 /* Nonzero means expecting a trace trap due to attaching to a process. */
92 static int stop_after_attach
;
94 /* Nonzero if pc has been changed by the debugger
95 since the inferior stopped. */
99 /* Nonzero if debugging a remote machine via a serial link or ethernet. */
101 int remote_debugging
;
103 /* Save register contents here when about to pop a stack dummy frame. */
105 char stop_registers
[REGISTER_BYTES
];
107 /* Nonzero if program stopped due to error trying to insert breakpoints. */
109 static int breakpoints_failed
;
111 /* Nonzero if inferior is in sh before our program got exec'd. */
113 static int running_in_shell
;
115 /* Nonzero after stop if current stack frame should be printed. */
117 static int stop_print_frame
;
119 #ifdef NO_SINGLE_STEP
120 /* Non-zero if we just simulated a single-step ptrace call. This is
121 needed because we cannot remove the breakpoints in the inferior
122 process until after the `wait' in `wait_for_inferior'.
125 #endif /* NO_SINGLE_STEP */
127 static void insert_step_breakpoint ();
128 static void remove_step_breakpoint ();
129 static void wait_for_inferior ();
130 static void normal_stop ();
134 /* Clear out all variables saying what to do when inferior is continued.
135 First do this, then set the ones you want, then call `proceed'. */
138 clear_proceed_status ()
141 step_range_start
= 0;
144 step_over_calls
= -1;
145 step_resume_break_address
= 0;
147 stop_after_attach
= 0;
149 /* Discard any remaining commands left by breakpoint we had stopped at. */
150 clear_breakpoint_commands ();
153 /* Basic routine for continuing the program in various fashions.
155 ADDR is the address to resume at, or -1 for resume where stopped.
156 SIGNAL is the signal to give it, or 0 for none,
157 or -1 for act according to how it stopped.
158 STEP is nonzero if should trap after one instruction.
159 -1 means return after that and print nothing.
160 You should probably set various step_... variables
161 before calling here, if you are stepping.
163 You should call clear_proceed_status before calling proceed. */
166 proceed (addr
, signal
, step
)
174 step_start_function
= find_pc_function (read_pc ());
180 /* If there is a breakpoint at the address we will resume at,
181 step one instruction before inserting breakpoints
182 so that we do not stop right away. */
184 if (!pc_changed
&& breakpoint_here_p (read_pc ()))
189 write_register (PC_REGNUM
, addr
);
191 write_register (NPC_REGNUM
, addr
+4);
195 if (trap_expected_after_continue
)
197 /* If (step == 0), a trap will be automatically generated after
198 the first instruction is executed. Force step one
199 instruction to clear this condition. This should not occur
200 if step is nonzero, but it is harmless in that case. */
202 trap_expected_after_continue
= 0;
206 /* We will get a trace trap after one instruction.
207 Continue it automatically and insert breakpoints then. */
211 int temp
= insert_breakpoints ();
214 print_sys_errmsg ("ptrace", temp
);
215 error ("Cannot insert breakpoints.\n\
216 The same program may be running in another process.");
218 breakpoints_inserted
= 1;
221 /* Install inferior's terminal modes. */
222 terminal_inferior ();
225 stop_signal
= signal
;
226 /* If this signal should not be seen by program,
227 give it zero. Used for debugging signals. */
228 else if (stop_signal
< NSIG
&& !signal_program
[stop_signal
])
231 /* Resume inferior. */
232 resume (oneproc
|| step
, stop_signal
);
234 /* Wait for it to stop (if not standalone)
235 and in any case decode why it stopped, and act accordingly. */
237 wait_for_inferior ();
241 /* Writing the inferior pc as a register calls this function
242 to inform infrun that the pc has been set in the debugger. */
251 /* Start an inferior process for the first time.
252 Actually it was started by the fork that created it,
253 but it will have stopped one instruction after execing sh.
254 Here we must get it up to actual execution of the real program. */
258 /* We will get a trace trap after one instruction.
259 Continue it automatically. Eventually (after shell does an exec)
260 it will get another trace trap. Then insert breakpoints and continue. */
262 running_in_shell
= 0; /* Set to 1 at first SIGTRAP, 0 at second. */
263 trap_expected_after_continue
= 0;
264 breakpoints_inserted
= 0;
265 mark_breakpoints_out ();
267 /* Set up the "saved terminal modes" of the inferior
268 based on what modes we are starting it with. */
269 terminal_init_inferior ();
271 /* Install inferior's terminal modes. */
272 terminal_inferior ();
274 if (remote_debugging
)
277 fetch_inferior_registers();
278 set_current_frame (read_register(FP_REGNUM
));
279 stop_frame
= get_current_frame();
281 if (insert_breakpoints())
282 fatal("Can't insert breakpoints");
283 breakpoints_inserted
= 1;
288 wait_for_inferior ();
293 /* Start remote-debugging of a machine over a serial link. */
298 clear_proceed_status ();
299 running_in_shell
= 0;
302 breakpoints_inserted
= 0;
303 mark_breakpoints_out ();
304 wait_for_inferior ();
310 /* Attach to process PID, then initialize for debugging it
311 and wait for the trace-trap that results from attaching. */
320 mark_breakpoints_out ();
321 terminal_init_inferior ();
322 clear_proceed_status ();
323 stop_after_attach
= 1;
324 /*proceed (-1, 0, -2);*/
325 wait_for_inferior ();
328 #endif /* ATTACH_DETACH */
330 /* Wait for control to return from inferior to debugger.
331 If inferior gets a signal, we may decide to start it up again
332 instead of returning. That is why there is a loop in this function.
333 When this function actually returns it means the inferior
334 should be left stopped and GDB should read more commands. */
346 int stop_step_resume_break
;
349 struct symbol
*newfun
;
350 struct symtab_and_line sal
;
353 prev_pc
= read_pc ();
357 if (remote_debugging
)
362 if (pid
!= inferior_pid
)
366 #ifdef NO_SINGLE_STEP
371 #endif /* NO_SINGLE_STEP */
374 fetch_inferior_registers ();
375 stop_pc
= read_pc ();
376 set_current_frame (read_register (FP_REGNUM
));
377 stop_frame
= get_current_frame ();
378 stop_sp
= read_register (SP_REGNUM
);
382 stop_stack_dummy
= 0;
383 stop_print_frame
= 1;
384 stop_step_resume_break
= 0;
386 breakpoints_failed
= 0;
388 /* Look at the cause of the stop, and decide what to do.
389 The alternatives are:
390 1) break; to really stop and return to the debugger,
391 2) drop through to start up again
392 (set another_trap to 1 to single step once)
393 3) set random_signal to 1, and the decision between 1 and 2
394 will be made according to the signal handling tables. */
398 terminal_ours_for_output ();
400 printf ("\nProgram exited with code 0%o.\n", WRETCODE (w
));
402 printf ("\nProgram exited normally.\n");
405 stop_print_frame
= 0;
408 else if (!WIFSTOPPED (w
))
411 stop_print_frame
= 0;
412 stop_signal
= WTERMSIG (w
);
413 terminal_ours_for_output ();
414 printf ("\nProgram terminated with signal %d, %s\n",
417 ? sys_siglist
[stop_signal
]
419 printf ("The inferior process no longer exists.\n");
425 stop_signal
= WSTOPSIG (w
);
427 /* First, distinguish signals caused by the debugger from signals
428 that have to do with the program's own actions.
429 Note that breakpoint insns may cause SIGTRAP or SIGILL
430 or SIGEMT, depending on the operating system version.
431 Here we detect when a SIGILL or SIGEMT is really a breakpoint
432 and change it to SIGTRAP. */
434 if (stop_signal
== SIGTRAP
435 || (breakpoints_inserted
&&
436 (stop_signal
== SIGILL
437 || stop_signal
== SIGEMT
))
438 || stop_after_attach
)
440 if (stop_signal
== SIGTRAP
&& stop_after_trap
)
442 stop_print_frame
= 0;
445 if (stop_after_attach
)
447 /* Don't even think about breakpoints
448 if still running the shell that will exec the program
449 or if just proceeded over a breakpoint. */
450 if (stop_signal
== SIGTRAP
&& trap_expected
)
453 /* See if there is a breakpoint at the current PC. */
454 #if DECR_PC_AFTER_BREAK
455 /* Notice the case of stepping through a jump
456 that leads just after a breakpoint.
457 Don't confuse that with hitting the breakpoint.
458 What we check for is that 1) stepping is going on
459 and 2) the pc before the last insn does not match
460 the address of the breakpoint before the current pc. */
461 if (!(prev_pc
!= stop_pc
- DECR_PC_AFTER_BREAK
462 && step_range_end
&& !step_resume_break_address
))
463 #endif /* DECR_PC_AFTER_BREAK not zero */
465 select_frame (stop_frame
, 0); /* For condition exprs. */
466 stop_breakpoint
= breakpoint_stop_status (stop_pc
, stop_frame
);
467 /* Following in case break condition called a function. */
468 stop_print_frame
= 1;
469 if (stop_breakpoint
&& DECR_PC_AFTER_BREAK
)
471 stop_pc
-= DECR_PC_AFTER_BREAK
;
472 write_register (PC_REGNUM
, stop_pc
);
474 write_register (NPC_REGNUM
, stop_pc
+ 4);
479 /* See if we stopped at the special breakpoint for
480 stepping over a subroutine call. */
481 if (stop_pc
- DECR_PC_AFTER_BREAK
== step_resume_break_address
)
483 stop_step_resume_break
= 1;
484 if (DECR_PC_AFTER_BREAK
)
486 stop_pc
-= DECR_PC_AFTER_BREAK
;
487 write_register (PC_REGNUM
, stop_pc
);
489 write_register (PC_REGNUM
, stop_pc
+ 4);
495 if (stop_signal
== SIGTRAP
)
497 = !(stop_breakpoint
|| trap_expected
498 || stop_step_resume_break
499 || (stop_sp INNER_THAN stop_pc
&& stop_pc INNER_THAN stop_frame
)
500 || (step_range_end
&& !step_resume_break_address
));
504 = !(stop_breakpoint
|| stop_step_resume_break
);
506 stop_signal
= SIGTRAP
;
512 /* For the program's own signals, act according to
513 the signal handling tables. */
516 && !(running_in_shell
&& stop_signal
== SIGSEGV
))
518 /* Signal not for debugging purposes. */
521 if (stop_signal
>= NSIG
522 || signal_print
[stop_signal
])
525 terminal_ours_for_output ();
526 printf ("\nProgram received signal %d, %s\n",
529 ? sys_siglist
[stop_signal
]
533 if (stop_signal
>= NSIG
534 || signal_stop
[stop_signal
])
536 /* If not going to stop, give terminal back
537 if we took it away. */
539 terminal_inferior ();
542 /* Handle cases caused by hitting a breakpoint. */
545 && (stop_breakpoint
|| stop_step_resume_break
))
547 /* Does a breakpoint want us to stop? */
548 if (stop_breakpoint
&& stop_breakpoint
!= -1)
550 /* 0x1000000 is set in stop_breakpoint as returned by
551 breakpoint_status_p to indicate a silent breakpoint. */
552 if (stop_breakpoint
> 0 && stop_breakpoint
& 0x1000000)
554 stop_breakpoint
&= ~0x1000000;
555 stop_print_frame
= 0;
559 /* But if we have hit the step-resumption breakpoint,
560 remove it. It has done its job getting us here. */
561 if (stop_step_resume_break
562 && (step_frame
== 0 || stop_frame
== step_frame
))
564 remove_step_breakpoint ();
565 step_resume_break_address
= 0;
567 /* Otherwise, must remove breakpoints and single-step
568 to get us past the one we hit. */
571 remove_breakpoints ();
572 remove_step_breakpoint ();
573 breakpoints_inserted
= 0;
577 /* We come here if we hit a breakpoint but should not
578 stop for it. Possibly we also were stepping
579 and should stop for that. So fall through and
580 test for stepping. But, if not stepping,
584 /* If this is the breakpoint at the end of a stack dummy,
585 just stop silently. */
586 if (stop_sp INNER_THAN stop_pc
&& stop_pc INNER_THAN stop_frame
)
588 stop_print_frame
= 0;
589 stop_stack_dummy
= 1;
591 trap_expected_after_continue
= 1;
596 if (step_resume_break_address
)
597 /* Having a step-resume breakpoint overrides anything
598 else having to do with stepping commands until
599 that breakpoint is reached. */
601 /* If stepping through a line, keep going if still within it. */
602 else if (!random_signal
604 && stop_pc
>= step_range_start
605 && stop_pc
< step_range_end
)
607 /* Don't step through the return from a function
608 unless that is the first instruction stepped through. */
609 if (ABOUT_TO_RETURN (stop_pc
))
616 /* We stepped out of the stepping range. See if that was due
617 to a subroutine call that we should proceed to the end of. */
618 else if (!random_signal
&& step_range_end
)
620 newfun
= find_pc_function (stop_pc
);
624 newfun_pc
= BLOCK_START (SYMBOL_BLOCK_VALUE (newfun
))
625 + FUNCTION_START_OFFSET
;
629 newmisc
= find_pc_misc_function (stop_pc
);
631 newfun_pc
= misc_function_vector
[newmisc
].address
632 + FUNCTION_START_OFFSET
;
635 if (stop_pc
== newfun_pc
636 && (step_over_calls
> 0 || (step_over_calls
&& newfun
== 0)))
638 /* A subroutine call has happened. */
639 /* Set a special breakpoint after the return */
640 step_resume_break_address
= SAVED_PC_AFTER_CALL (stop_frame
);
641 step_resume_break_duplicate
642 = breakpoint_here_p (step_resume_break_address
);
643 if (breakpoints_inserted
)
644 insert_step_breakpoint ();
646 /* Subroutine call with source code we should not step over.
647 Do step to the first line of code in it. */
648 else if (stop_pc
== newfun_pc
&& step_over_calls
)
650 SKIP_PROLOGUE (newfun_pc
);
651 sal
= find_pc_line (newfun_pc
, 0);
652 /* Use the step_resume_break to step until
653 the end of the prologue, even if that involves jumps
654 (as it seems to on the vax under 4.2). */
655 /* If the prologue ends in the middle of a source line,
656 continue to the end of that source line.
657 Otherwise, just go to end of prologue. */
658 if (sal
.end
&& sal
.pc
!= newfun_pc
)
661 if (newfun_pc
== stop_pc
)
662 /* We are already there: stop now. */
665 /* Put the step-breakpoint there and go until there. */
667 step_resume_break_address
= newfun_pc
;
669 step_resume_break_duplicate
670 = breakpoint_here_p (step_resume_break_address
);
671 if (breakpoints_inserted
)
672 insert_step_breakpoint ();
673 /* Do not specify what the fp should be when we stop
674 since on some machines the prologue
675 is where the new fp value is established. */
677 /* And make sure stepping stops right away then. */
678 step_range_end
= step_range_start
;
681 /* No subroutince call; stop now. */
690 /* Save the pc before execution, to compare with pc after stop. */
691 prev_pc
= read_pc ();
693 /* If we did not do break;, it means we should keep
694 running the inferior and not return to debugger. */
696 /* If trap_expected is 2, it means continue once more
697 and insert breakpoints at the next trap.
698 If trap_expected is 1 and the signal was SIGSEGV, it means
699 the shell is doing some memory allocation--just resume it
701 Otherwise insert breakpoints now, and possibly single step. */
703 if (trap_expected
> 1)
706 running_in_shell
= 1;
709 else if (running_in_shell
&& stop_signal
== SIGSEGV
)
715 /* Here, we are not awaiting another exec to get
716 the program we really want to debug.
717 Insert breakpoints now, unless we are trying
718 to one-proceed past a breakpoint. */
719 running_in_shell
= 0;
720 if (!breakpoints_inserted
&& !another_trap
)
722 insert_step_breakpoint ();
723 breakpoints_failed
= insert_breakpoints ();
724 if (breakpoints_failed
)
726 breakpoints_inserted
= 1;
729 trap_expected
= another_trap
;
731 if (stop_signal
== SIGTRAP
)
734 resume ((step_range_end
&& !step_resume_break_address
)
741 /* Here to return control to GDB when the inferior stops for real.
742 Print appropriate messages, remove breakpoints, give terminal our modes.
744 RUNNING_IN_SHELL nonzero means the shell got a signal before
745 exec'ing the program we wanted to run.
746 STOP_PRINT_FRAME nonzero means print the executing frame
747 (pc, function, args, file, line number and line text).
748 BREAKPOINTS_FAILED nonzero means stop was due to error
749 attempting to insert breakpoints. */
754 if (breakpoints_failed
)
756 terminal_ours_for_output ();
757 print_sys_errmsg ("ptrace", breakpoints_failed
);
758 printf ("Stopped; cannot insert breakpoints.\n\
759 The same program may be running in another process.\n");
763 remove_step_breakpoint ();
765 if (inferior_pid
&& breakpoints_inserted
)
766 if (remove_breakpoints ())
768 terminal_ours_for_output ();
769 printf ("Cannot remove breakpoints because program is no longer writable.\n\
770 It must be running in another process.\n\
771 Further execution is probably impossible.\n");
774 breakpoints_inserted
= 0;
776 /* Delete the breakpoint we stopped at, if it wants to be deleted.
777 Delete any breakpoint that is to be deleted at the next stop. */
779 breakpoint_auto_delete (stop_breakpoint
);
781 /* If an auto-display called a function and that got a signal,
782 delete that auto-display to avoid an infinite recursion. */
784 delete_current_display ();
786 if (step_multi
&& stop_step
)
791 if (running_in_shell
)
793 if (stop_signal
== SIGSEGV
)
795 You have just encountered a bug in \"sh\". GDB starts your program\n\
796 by running \"sh\" with a command to exec your program.\n\
797 This is so that \"sh\" will process wildcards and I/O redirection.\n\
798 This time, \"sh\" crashed.\n\
800 One known bug in \"sh\" bites when the environment takes up a lot of space.\n\
801 Try \"info env\" to see the environment; then use \"unset-env\" to kill\n\
802 some variables whose values are large; then do \"run\" again.\n\
804 If that works, you might want to put those \"unset-env\" commands\n\
805 into a \".gdbinit\" file in this directory so they will happen every time.\n");
806 /* Don't confuse user with his program's symbols on sh's data. */
807 stop_print_frame
= 0;
810 if (inferior_pid
== 0)
813 /* Select innermost stack frame except on return from a stack dummy routine,
814 or if the program has exited. */
815 if (!stop_stack_dummy
)
817 select_frame (stop_frame
, 0);
819 if (stop_print_frame
)
821 if (stop_breakpoint
> 0)
822 printf ("\nBpt %d, ", stop_breakpoint
);
823 print_sel_frame (stop_step
824 && step_frame
== stop_frame
825 && step_start_function
== find_pc_function (stop_pc
));
826 /* Display the auto-display expressions. */
831 /* Save the function value return registers
832 We might be about to restore their previous contents. */
833 read_register_bytes (0, stop_registers
, REGISTER_BYTES
);
835 if (stop_stack_dummy
)
837 /* Pop the empty frame that contains the stack dummy. */
839 select_frame (read_register (FP_REGNUM
), 0);
844 insert_step_breakpoint ()
846 if (step_resume_break_address
&& !step_resume_break_duplicate
)
848 read_memory (step_resume_break_address
,
849 step_resume_break_shadow
, sizeof break_insn
);
850 write_memory (step_resume_break_address
,
851 break_insn
, sizeof break_insn
);
856 remove_step_breakpoint ()
858 if (step_resume_break_address
&& !step_resume_break_duplicate
)
859 write_memory (step_resume_break_address
, step_resume_break_shadow
,
863 /* Specify how various signals in the inferior should be handled. */
866 handle_command (args
, from_tty
)
870 register char *p
= args
;
872 register int digits
, wordlen
;
875 error_no_arg ("signal to handle");
879 /* Find the end of the next word in the args. */
880 for (wordlen
= 0; p
[wordlen
] && p
[wordlen
] != ' ' && p
[wordlen
] != '\t';
882 for (digits
= 0; p
[digits
] >= '0' && p
[digits
] <= '9'; digits
++);
884 /* If it is all digits, it is signal number to operate on. */
885 if (digits
== wordlen
)
888 if (signum
== SIGTRAP
|| signum
== SIGINT
)
890 if (!query ("Signal %d is used by the debugger.\nAre you sure you want to change it? ", signum
))
891 error ("Not confirmed.");
894 else if (signum
== 0)
895 error ("First argument is not a signal number.");
897 /* Else, if already got a signal number, look for flag words
898 saying what to do for it. */
899 else if (!strncmp (p
, "stop", wordlen
))
901 signal_stop
[signum
] = 1;
902 signal_print
[signum
] = 1;
904 else if (wordlen
>= 2 && !strncmp (p
, "print", wordlen
))
905 signal_print
[signum
] = 1;
906 else if (wordlen
>= 2 && !strncmp (p
, "pass", wordlen
))
907 signal_program
[signum
] = 1;
908 else if (!strncmp (p
, "ignore", wordlen
))
909 signal_program
[signum
] = 0;
910 else if (wordlen
>= 3 && !strncmp (p
, "nostop", wordlen
))
911 signal_stop
[signum
] = 0;
912 else if (wordlen
>= 4 && !strncmp (p
, "noprint", wordlen
))
914 signal_print
[signum
] = 0;
915 signal_stop
[signum
] = 0;
917 else if (wordlen
>= 4 && !strncmp (p
, "nopass", wordlen
))
918 signal_program
[signum
] = 0;
919 else if (wordlen
>= 3 && !strncmp (p
, "noignore", wordlen
))
920 signal_program
[signum
] = 1;
921 /* Not a number and not a recognized flag word => complain. */
925 error ("Unrecognized flag word: \"%s\".", p
);
928 /* Find start of next word. */
930 while (*p
== ' ' || *p
== '\t') p
++;
935 /* Show the results. */
936 printf ("Number\tStop\tPrint\tPass to program\tDescription\n");
937 printf ("%d\t", signum
);
938 printf ("%s\t", signal_stop
[signum
] ? "Yes" : "No");
939 printf ("%s\t", signal_print
[signum
] ? "Yes" : "No");
940 printf ("%s\t\t", signal_program
[signum
] ? "Yes" : "No");
941 printf ("%s\n", sys_siglist
[signum
]);
945 /* Print current contents of the tables set by the handle command. */
948 signals_info (signum_exp
)
952 printf ("Number\tStop\tPrint\tPass to program\tDescription\n");
956 i
= parse_and_eval_address (signum_exp
);
958 printf ("%s\t", signal_stop
[i
] ? "Yes" : "No");
959 printf ("%s\t", signal_print
[i
] ? "Yes" : "No");
960 printf ("%s\t\t", signal_program
[i
] ? "Yes" : "No");
961 printf ("%s\n", sys_siglist
[i
]);
966 for (i
= 0; i
< NSIG
; i
++)
969 if (i
> 0 && i
% 16 == 0)
971 printf ("[Type Return to see more]");
976 printf ("%s\t", signal_stop
[i
] ? "Yes" : "No");
977 printf ("%s\t", signal_print
[i
] ? "Yes" : "No");
978 printf ("%s\t\t", signal_program
[i
] ? "Yes" : "No");
979 printf ("%s\n", sys_siglist
[i
]);
982 printf ("\nUse the \"handle\" command to change these tables.\n");
990 add_info ("signals", signals_info
,
991 "What debugger does when program gets various signals.\n\
992 Specify a signal number as argument to print info on that signal only.");
994 add_com ("handle", class_run
, handle_command
,
995 "Specify how to handle a signal.\n\
996 Args are signal number followed by flags.\n\
997 Flags allowed are \"stop\", \"print\", \"pass\",\n\
998 \"nostop\", \"noprint\" or \"nopass\".\n\
999 Print means print a message if this signal happens.\n\
1000 Stop means reenter debugger if this signal happens (implies print).\n\
1001 Pass means let program see this signal; otherwise program doesn't know.\n\
1002 Pass and Stop may be combined.");
1004 for (i
= 0; i
< NSIG
; i
++)
1007 signal_print
[i
] = 1;
1008 signal_program
[i
] = 1;
1011 /* Signals caused by debugger's own actions
1012 should not be given to the program afterwards. */
1013 signal_program
[SIGTRAP
] = 0;
1014 signal_program
[SIGINT
] = 0;
1016 /* Signals that are not errors should not normally enter the debugger. */
1018 signal_stop
[SIGALRM
] = 0;
1019 signal_print
[SIGALRM
] = 0;
1020 #endif /* SIGALRM */
1022 signal_stop
[SIGVTALRM
] = 0;
1023 signal_print
[SIGVTALRM
] = 0;
1024 #endif /* SIGVTALRM */
1026 signal_stop
[SIGPROF
] = 0;
1027 signal_print
[SIGPROF
] = 0;
1028 #endif /* SIGPROF */
1030 signal_stop
[SIGCHLD
] = 0;
1031 signal_print
[SIGCHLD
] = 0;
1032 #endif /* SIGCHLD */
1034 signal_stop
[SIGCLD
] = 0;
1035 signal_print
[SIGCLD
] = 0;
1038 signal_stop
[SIGIO
] = 0;
1039 signal_print
[SIGIO
] = 0;
1042 signal_stop
[SIGURG
] = 0;
1043 signal_print
[SIGURG
] = 0;
1047 #ifdef NO_SINGLE_STEP
1048 /* This code was written by Gary Beihl (beihl@mcc.com).
1049 It was modified by Michael Tiemann (tiemann@corto.inria.fr). */
1051 /* Simulate single-step ptrace call for sun4. */
1055 b_error
, not_branch
, bicc
, bicca
, ba
, baa
, ticc
, ta
,
1058 static CORE_ADDR next_pc
, pc8
, target
;
1059 static int brkpc8
, brktrg
;
1060 typedef char binsn_quantum
[sizeof break_insn
];
1061 static binsn_quantum break_mem
[3];
1064 single_step (signal
)
1067 branch_type br
, isabranch();
1069 next_pc
= read_register (NPC_REGNUM
);
1070 pc8
= read_register (PC_REGNUM
) + 8; /* branch not taken */
1074 /* Always set breakpoint for NPC. */
1075 read_memory (next_pc
, break_mem
[0], sizeof break_insn
);
1076 write_memory (next_pc
, break_insn
, sizeof break_insn
);
1078 /* printf ("set break at %x\n",next_pc); */
1079 br
= isabranch (pc8
- 8, &target
);
1080 brkpc8
= brktrg
= 0;
1082 if (br
== bicca
&& pc8
!= next_pc
)
1084 /* Handle branches with care */
1086 read_memory (pc8
, break_mem
[1], sizeof break_insn
);
1087 write_memory (pc8
, break_insn
, sizeof break_insn
);
1089 else if (br
== baa
&& target
!= next_pc
)
1092 read_memory (target
, break_mem
[2], sizeof break_insn
);
1093 write_memory (target
, break_insn
, sizeof break_insn
);
1097 ptrace (7, inferior_pid
, 1, signal
);
1103 /* Remove breakpoints */
1104 write_memory (next_pc
, break_mem
[0], sizeof break_insn
);
1108 write_memory (pc8
, break_mem
[1], sizeof break_insn
);
1112 write_memory (target
, break_mem
[2], sizeof break_insn
);
1118 #endif /* NO_SINGLE_STEP */
1120 static int save_insn_opcodes
[] = { 0x03000000, 0x82007ee0, 0x9de38001, 0x03000000, 0x82007ee0, 0x91d02001, 0x01000000 };
1126 int g1
= read_register (1);
1127 CORE_ADDR sp
= read_register (SP_REGNUM
);
1128 CORE_ADDR pc
= read_register (PC_REGNUM
);
1130 CORE_ADDR npc
= read_register (NPC_REGNUM
);
1132 CORE_ADDR fake_pc
= sp
- sizeof (save_insn_opcodes
);
1133 save_insn_opcodes
[0] = 0x03000000 | ((-size
>> 12) & 0x3fffff);
1134 save_insn_opcodes
[1] = 0x82006000 | (-size
& 0x3ff);
1135 save_insn_opcodes
[3] = 0x03000000 | ((g1
>> 12) & 0x3fffff);
1136 save_insn_opcodes
[4] = 0x82006000 | (g1
& 0x3ff);
1137 write_memory (fake_pc
, save_insn_opcodes
, sizeof (save_insn_opcodes
));
1138 clear_proceed_status ();
1139 stop_after_trap
= 1;
1141 proceed (fake_pc
, 0, 0);
1143 write_register (PC_REGNUM
, pc
);
1145 write_register (NPC_REGNUM
, npc
);
1149 static int restore_insn_opcodes
[] = { 0x81e80000, 0x91d02001, 0x01000000 };
1152 do_restore_insn (raw_buffer
)
1155 CORE_ADDR pc
= read_memory_integer (*(int *)&raw_buffer
[REGISTER_BYTE (PC_REGNUM
)], 4);
1156 CORE_ADDR sp
= read_register (SP_REGNUM
);
1158 CORE_ADDR npc
= *(int *)&raw_buffer
[REGISTER_BYTE (NPC_REGNUM
)] != 0
1159 ? read_memory_integer (*(int *)&raw_buffer
[REGISTER_BYTE (NPC_REGNUM
)], 4) : pc
+ 4;
1161 CORE_ADDR fake_pc
= sp
- sizeof (restore_insn_opcodes
);
1162 int saved_stop_stack_dummy
= stop_stack_dummy
;
1164 if (*(int *)&raw_buffer
[REGISTER_BYTE (PC_REGNUM
)] == 0)
1167 write_memory (fake_pc
, restore_insn_opcodes
, sizeof (restore_insn_opcodes
));
1168 clear_proceed_status ();
1169 stop_after_trap
= 1;
1171 proceed (fake_pc
, 0, 0);
1173 stop_stack_dummy
= saved_stop_stack_dummy
;
1174 write_register (PC_REGNUM
, pc
);
1176 write_register (NPC_REGNUM
, npc
);
1179 /* Select innermost stack frame except on return from a stack dummy routine,
1180 or if the program has exited. */
1181 if (!stop_stack_dummy
)
1183 select_frame (stop_frame
, 0);
1187 select_frame (read_register (FP_REGNUM
), 0);