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