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