gdb-3.5
[deliverable/binutils-gdb.git] / gdb / infrun.c
CommitLineData
7b4ac7e1 1/* Start and stop the inferior process, for GDB.
4187119d 2 Copyright (C) 1986, 1987, 1988, 1989 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. */
7b4ac7e1 19
e91b87a3 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 randy@wheaties.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
7a67dd45 119#include <stdio.h>
7b4ac7e1 120#include "defs.h"
7b4ac7e1 121#include "param.h"
122#include "symtab.h"
123#include "frame.h"
124#include "inferior.h"
125#include "wait.h"
126
7b4ac7e1 127#include <signal.h>
e91b87a3 128
129/* unistd.h is needed to #define X_OK */
130#ifdef USG
131#include <unistd.h>
132#else
133#include <sys/file.h>
134#endif
135
7b4ac7e1 136#ifdef UMAX_PTRACE
4187119d 137#include <aouthdr.h>
7b4ac7e1 138#include <sys/param.h>
139#include <sys/ptrace.h>
e91b87a3 140#endif /* UMAX_PTRACE */
7b4ac7e1 141
1c997a4a 142/* Required by <sys/user.h>. */
143#include <sys/types.h>
144/* Required by <sys/user.h>, at least on system V. */
145#include <sys/dir.h>
146/* Needed by IN_SIGTRAMP on some machines (e.g. vax). */
147#include <sys/param.h>
148/* Needed by IN_SIGTRAMP on some machines (e.g. vax). */
149#include <sys/user.h>
150
7b4ac7e1 151extern char *sys_siglist[];
152extern int errno;
153
1c997a4a 154/* Sigtramp is a routine that the kernel calls (which then calls the
155 signal handler). On most machines it is a library routine that
156 is linked into the executable.
157
158 This macro, given a program counter value and the name of the
159 function in which that PC resides (which can be null if the
160 name is not known), returns nonzero if the PC and name show
161 that we are in sigtramp.
162
163 On most machines just see if the name is sigtramp (and if we have
164 no name, assume we are not in sigtramp). */
165#if !defined (IN_SIGTRAMP)
166#define IN_SIGTRAMP(pc, name) \
167 name && !strcmp ("_sigtramp", name)
168#endif
169
7b4ac7e1 170/* Tables of how to react to signals; the user sets them. */
171
172static char signal_stop[NSIG];
173static char signal_print[NSIG];
174static char signal_program[NSIG];
175
176/* Nonzero if breakpoints are now inserted in the inferior. */
177
178static int breakpoints_inserted;
179
180/* Function inferior was in as of last step command. */
181
182static struct symbol *step_start_function;
183
184/* This is the sequence of bytes we insert for a breakpoint. */
185
186static char break_insn[] = BREAKPOINT;
187
e91b87a3 188/* Nonzero => address for special breakpoint for resuming stepping. */
7b4ac7e1 189
190static CORE_ADDR step_resume_break_address;
191
192/* Original contents of the byte where the special breakpoint is. */
193
194static char step_resume_break_shadow[sizeof break_insn];
195
196/* Nonzero means the special breakpoint is a duplicate
197 so it has not itself been inserted. */
198
199static int step_resume_break_duplicate;
200
201/* Nonzero if we are expecting a trace trap and should proceed from it.
202 2 means expecting 2 trace traps and should continue both times.
203 That occurs when we tell sh to exec the program: we will get
204 a trap after the exec of sh and a second when the program is exec'd. */
205
206static int trap_expected;
207
3bf57d21 208/* Nonzero if the next time we try to continue the inferior, it will
209 step one instruction and generate a spurious trace trap.
210 This is used to compensate for a bug in HP-UX. */
211
212static int trap_expected_after_continue;
213
7b4ac7e1 214/* Nonzero means expecting a trace trap
215 and should stop the inferior and return silently when it happens. */
216
e91b87a3 217int stop_after_trap;
7b4ac7e1 218
219/* Nonzero means expecting a trace trap due to attaching to a process. */
220
e91b87a3 221int stop_after_attach;
7b4ac7e1 222
223/* Nonzero if pc has been changed by the debugger
224 since the inferior stopped. */
225
226int pc_changed;
227
632ea0cc 228/* Nonzero if debugging a remote machine via a serial link or ethernet. */
229
230int remote_debugging;
231
7b4ac7e1 232/* Save register contents here when about to pop a stack dummy frame. */
233
234char stop_registers[REGISTER_BYTES];
235
236/* Nonzero if program stopped due to error trying to insert breakpoints. */
237
238static int breakpoints_failed;
239
240/* Nonzero if inferior is in sh before our program got exec'd. */
241
242static int running_in_shell;
243
244/* Nonzero after stop if current stack frame should be printed. */
245
246static int stop_print_frame;
247
bb7592f0 248#ifdef NO_SINGLE_STEP
e91b87a3 249extern int one_stepped; /* From machine dependent code */
250extern void single_step (); /* Same. */
bb7592f0 251#endif /* NO_SINGLE_STEP */
252
7b4ac7e1 253static void insert_step_breakpoint ();
254static void remove_step_breakpoint ();
255static void wait_for_inferior ();
256static void normal_stop ();
257
7b4ac7e1 258\f
259/* Clear out all variables saying what to do when inferior is continued.
260 First do this, then set the ones you want, then call `proceed'. */
261
262void
263clear_proceed_status ()
264{
265 trap_expected = 0;
266 step_range_start = 0;
267 step_range_end = 0;
e91b87a3 268 step_frame_address = 0;
7b4ac7e1 269 step_over_calls = -1;
270 step_resume_break_address = 0;
271 stop_after_trap = 0;
272 stop_after_attach = 0;
273
274 /* Discard any remaining commands left by breakpoint we had stopped at. */
275 clear_breakpoint_commands ();
276}
277
278/* Basic routine for continuing the program in various fashions.
279
280 ADDR is the address to resume at, or -1 for resume where stopped.
281 SIGNAL is the signal to give it, or 0 for none,
282 or -1 for act according to how it stopped.
283 STEP is nonzero if should trap after one instruction.
284 -1 means return after that and print nothing.
285 You should probably set various step_... variables
286 before calling here, if you are stepping.
287
288 You should call clear_proceed_status before calling proceed. */
289
290void
291proceed (addr, signal, step)
292 CORE_ADDR addr;
293 int signal;
294 int step;
295{
296 int oneproc = 0;
297
298 if (step > 0)
299 step_start_function = find_pc_function (read_pc ());
300 if (step < 0)
301 stop_after_trap = 1;
302
303 if (addr == -1)
304 {
305 /* If there is a breakpoint at the address we will resume at,
306 step one instruction before inserting breakpoints
307 so that we do not stop right away. */
308
309 if (!pc_changed && breakpoint_here_p (read_pc ()))
3bf57d21 310 oneproc = 1;
7b4ac7e1 311 }
312 else
bb7592f0 313 {
314 write_register (PC_REGNUM, addr);
315#ifdef NPC_REGNUM
e91b87a3 316 write_register (NPC_REGNUM, addr + 4);
bb7592f0 317#endif
318 }
7b4ac7e1 319
3bf57d21 320 if (trap_expected_after_continue)
321 {
322 /* If (step == 0), a trap will be automatically generated after
323 the first instruction is executed. Force step one
324 instruction to clear this condition. This should not occur
325 if step is nonzero, but it is harmless in that case. */
326 oneproc = 1;
327 trap_expected_after_continue = 0;
328 }
329
330 if (oneproc)
331 /* We will get a trace trap after one instruction.
332 Continue it automatically and insert breakpoints then. */
333 trap_expected = 1;
334 else
7b4ac7e1 335 {
336 int temp = insert_breakpoints ();
337 if (temp)
338 {
339 print_sys_errmsg ("ptrace", temp);
340 error ("Cannot insert breakpoints.\n\
341The same program may be running in another process.");
342 }
343 breakpoints_inserted = 1;
344 }
345
346 /* Install inferior's terminal modes. */
347 terminal_inferior ();
348
349 if (signal >= 0)
350 stop_signal = signal;
351 /* If this signal should not be seen by program,
352 give it zero. Used for debugging signals. */
353 else if (stop_signal < NSIG && !signal_program[stop_signal])
354 stop_signal= 0;
355
356 /* Resume inferior. */
357 resume (oneproc || step, stop_signal);
358
359 /* Wait for it to stop (if not standalone)
360 and in any case decode why it stopped, and act accordingly. */
361
362 wait_for_inferior ();
363 normal_stop ();
364}
365
366/* Writing the inferior pc as a register calls this function
367 to inform infrun that the pc has been set in the debugger. */
368
e91b87a3 369void
7b4ac7e1 370writing_pc (val)
371 CORE_ADDR val;
372{
373 stop_pc = val;
374 pc_changed = 1;
375}
376
377/* Start an inferior process for the first time.
378 Actually it was started by the fork that created it,
379 but it will have stopped one instruction after execing sh.
380 Here we must get it up to actual execution of the real program. */
381
e91b87a3 382void
7b4ac7e1 383start_inferior ()
384{
385 /* We will get a trace trap after one instruction.
386 Continue it automatically. Eventually (after shell does an exec)
387 it will get another trace trap. Then insert breakpoints and continue. */
e91b87a3 388
389#ifdef START_INFERIOR_TRAPS_EXPECTED
390 trap_expected = START_INFERIOR_TRAPS_EXPECTED;
391#else
7b4ac7e1 392 trap_expected = 2;
e91b87a3 393#endif
394
7b4ac7e1 395 running_in_shell = 0; /* Set to 1 at first SIGTRAP, 0 at second. */
3bf57d21 396 trap_expected_after_continue = 0;
7b4ac7e1 397 breakpoints_inserted = 0;
398 mark_breakpoints_out ();
399
400 /* Set up the "saved terminal modes" of the inferior
401 based on what modes we are starting it with. */
402 terminal_init_inferior ();
403
404 /* Install inferior's terminal modes. */
405 terminal_inferior ();
406
632ea0cc 407 if (remote_debugging)
408 {
409 trap_expected = 0;
410 fetch_inferior_registers();
e91b87a3 411 set_current_frame (create_new_frame (read_register (FP_REGNUM),
412 read_pc ()));
413 stop_frame_address = FRAME_FP (get_current_frame());
632ea0cc 414 inferior_pid = 3;
415 if (insert_breakpoints())
416 fatal("Can't insert breakpoints");
417 breakpoints_inserted = 1;
418 proceed(-1, -1, 0);
419 }
420 else
421 {
422 wait_for_inferior ();
423 normal_stop ();
424 }
425}
426
427/* Start remote-debugging of a machine over a serial link. */
428
429void
430start_remote ()
431{
432 clear_proceed_status ();
433 running_in_shell = 0;
434 trap_expected = 0;
435 inferior_pid = 3;
436 breakpoints_inserted = 0;
437 mark_breakpoints_out ();
7b4ac7e1 438 wait_for_inferior ();
632ea0cc 439 normal_stop();
7b4ac7e1 440}
441
442#ifdef ATTACH_DETACH
443
444/* Attach to process PID, then initialize for debugging it
445 and wait for the trace-trap that results from attaching. */
446
447void
448attach_program (pid)
449 int pid;
450{
451 attach (pid);
452 inferior_pid = pid;
453
454 mark_breakpoints_out ();
455 terminal_init_inferior ();
456 clear_proceed_status ();
457 stop_after_attach = 1;
458 /*proceed (-1, 0, -2);*/
4187119d 459 terminal_inferior ();
7b4ac7e1 460 wait_for_inferior ();
461 normal_stop ();
462}
463#endif /* ATTACH_DETACH */
464\f
465/* Wait for control to return from inferior to debugger.
466 If inferior gets a signal, we may decide to start it up again
467 instead of returning. That is why there is a loop in this function.
468 When this function actually returns it means the inferior
469 should be left stopped and GDB should read more commands. */
470
471static void
472wait_for_inferior ()
473{
474 register int pid;
475 WAITTYPE w;
476 CORE_ADDR pc;
477 int tem;
478 int another_trap;
479 int random_signal;
e91b87a3 480 CORE_ADDR stop_sp, prev_sp;
481 CORE_ADDR prev_func_start, stop_func_start;
4187119d 482 char *prev_func_name, *stop_func_name;
e91b87a3 483 CORE_ADDR prologue_pc;
7b4ac7e1 484 int stop_step_resume_break;
e91b87a3 485 CORE_ADDR step_resume_break_sp;
7b4ac7e1 486 int newmisc;
487 int newfun_pc;
7b4ac7e1 488 struct symtab_and_line sal;
489 int prev_pc;
e91b87a3 490 extern CORE_ADDR text_end;
4187119d 491 int remove_breakpoints_on_following_step = 0;
7b4ac7e1 492
3bf57d21 493 prev_pc = read_pc ();
4187119d 494 (void) find_pc_partial_function (prev_pc, &prev_func_name,
495 &prev_func_start);
496 prev_func_start += FUNCTION_START_OFFSET;
e91b87a3 497 prev_sp = read_register (SP_REGNUM);
3bf57d21 498
7b4ac7e1 499 while (1)
500 {
4187119d 501 /* Clean up saved state that will become invalid. */
e91b87a3 502 pc_changed = 0;
503 flush_cached_frames ();
504
632ea0cc 505 if (remote_debugging)
506 remote_wait (&w);
507 else
508 {
509 pid = wait (&w);
510 if (pid != inferior_pid)
511 continue;
512 }
513
4187119d 514 /* See if the process still exists; clean up if it doesn't. */
7b4ac7e1 515 if (WIFEXITED (w))
516 {
517 terminal_ours_for_output ();
518 if (WRETCODE (w))
519 printf ("\nProgram exited with code 0%o.\n", WRETCODE (w));
520 else
521 printf ("\nProgram exited normally.\n");
522 fflush (stdout);
523 inferior_died ();
e91b87a3 524#ifdef NO_SINGLE_STEP
4187119d 525 one_stepped = 0;
526#endif
7b4ac7e1 527 stop_print_frame = 0;
528 break;
529 }
530 else if (!WIFSTOPPED (w))
531 {
532 kill_inferior ();
533 stop_print_frame = 0;
534 stop_signal = WTERMSIG (w);
535 terminal_ours_for_output ();
536 printf ("\nProgram terminated with signal %d, %s\n",
537 stop_signal,
538 stop_signal < NSIG
539 ? sys_siglist[stop_signal]
540 : "(undocumented)");
541 printf ("The inferior process no longer exists.\n");
542 fflush (stdout);
e91b87a3 543#ifdef NO_SINGLE_STEP
4187119d 544 one_stepped = 0;
545#endif
7b4ac7e1 546 break;
547 }
4187119d 548
e91b87a3 549#ifdef NO_SINGLE_STEP
550 if (one_stepped)
551 single_step (0); /* This actually cleans up the ss */
552#endif /* NO_SINGLE_STEP */
4187119d 553
e91b87a3 554 fetch_inferior_registers ();
555 stop_pc = read_pc ();
556 set_current_frame ( create_new_frame (read_register (FP_REGNUM),
557 read_pc ()));
4187119d 558
e91b87a3 559 stop_frame_address = FRAME_FP (get_current_frame ());
560 stop_sp = read_register (SP_REGNUM);
4187119d 561 stop_func_start = 0;
1c997a4a 562 stop_func_name = 0;
563 /* Don't care about return value; stop_func_start and stop_func_name
564 will both be 0 if it doesn't work. */
4187119d 565 (void) find_pc_partial_function (stop_pc, &stop_func_name,
566 &stop_func_start);
567 stop_func_start += FUNCTION_START_OFFSET;
e91b87a3 568 another_trap = 0;
569 stop_breakpoint = 0;
570 stop_step = 0;
571 stop_stack_dummy = 0;
572 stop_print_frame = 1;
573 stop_step_resume_break = 0;
574 random_signal = 0;
575 stopped_by_random_signal = 0;
576 breakpoints_failed = 0;
4187119d 577
e91b87a3 578 /* Look at the cause of the stop, and decide what to do.
579 The alternatives are:
580 1) break; to really stop and return to the debugger,
581 2) drop through to start up again
4187119d 582 (set another_trap to 1 to single step once)
e91b87a3 583 3) set random_signal to 1, and the decision between 1 and 2
4187119d 584 will be made according to the signal handling tables. */
585
e91b87a3 586 stop_signal = WSTOPSIG (w);
4187119d 587
e91b87a3 588 /* First, distinguish signals caused by the debugger from signals
589 that have to do with the program's own actions.
590 Note that breakpoint insns may cause SIGTRAP or SIGILL
591 or SIGEMT, depending on the operating system version.
592 Here we detect when a SIGILL or SIGEMT is really a breakpoint
593 and change it to SIGTRAP. */
4187119d 594
e91b87a3 595 if (stop_signal == SIGTRAP
e91b87a3 596 || (breakpoints_inserted &&
597 (stop_signal == SIGILL
598 || stop_signal == SIGEMT))
e91b87a3 599 || stop_after_attach)
7b4ac7e1 600 {
e91b87a3 601 if (stop_signal == SIGTRAP && stop_after_trap)
7b4ac7e1 602 {
e91b87a3 603 stop_print_frame = 0;
604 break;
605 }
606 if (stop_after_attach)
607 break;
608 /* Don't even think about breakpoints
609 if still running the shell that will exec the program
610 or if just proceeded over a breakpoint. */
611 if (stop_signal == SIGTRAP && trap_expected)
612 stop_breakpoint = 0;
613 else
614 {
615 /* See if there is a breakpoint at the current PC. */
7b4ac7e1 616#if DECR_PC_AFTER_BREAK
e91b87a3 617 /* Notice the case of stepping through a jump
618 that leads just after a breakpoint.
619 Don't confuse that with hitting the breakpoint.
620 What we check for is that 1) stepping is going on
621 and 2) the pc before the last insn does not match
622 the address of the breakpoint before the current pc. */
623 if (!(prev_pc != stop_pc - DECR_PC_AFTER_BREAK
624 && step_range_end && !step_resume_break_address))
7b4ac7e1 625#endif /* DECR_PC_AFTER_BREAK not zero */
e91b87a3 626 {
4187119d 627 /* See if we stopped at the special breakpoint for
628 stepping over a subroutine call. */
629 if (stop_pc - DECR_PC_AFTER_BREAK
630 == step_resume_break_address)
e91b87a3 631 {
4187119d 632 stop_step_resume_break = 1;
633 if (DECR_PC_AFTER_BREAK)
634 {
635 stop_pc -= DECR_PC_AFTER_BREAK;
636 write_register (PC_REGNUM, stop_pc);
637 pc_changed = 0;
638 }
e91b87a3 639 }
4187119d 640 else
7b4ac7e1 641 {
4187119d 642 stop_breakpoint =
643 breakpoint_stop_status (stop_pc, stop_frame_address);
644 /* Following in case break condition called a
645 function. */
646 stop_print_frame = 1;
647 if (stop_breakpoint && DECR_PC_AFTER_BREAK)
648 {
649 stop_pc -= DECR_PC_AFTER_BREAK;
650 write_register (PC_REGNUM, stop_pc);
651#ifdef NPC_REGNUM
652 write_register (NPC_REGNUM, stop_pc + 4);
653#endif
654 pc_changed = 0;
655 }
7b4ac7e1 656 }
657 }
7b4ac7e1 658 }
4187119d 659
e91b87a3 660 if (stop_signal == SIGTRAP)
661 random_signal
662 = !(stop_breakpoint || trap_expected
663 || stop_step_resume_break
4187119d 664#ifndef CANNOT_EXECUTE_STACK
e91b87a3 665 || (stop_sp INNER_THAN stop_pc
666 && stop_pc INNER_THAN stop_frame_address)
667#else
668 || stop_pc == text_end - 2
669#endif
670 || (step_range_end && !step_resume_break_address));
7b4ac7e1 671 else
e91b87a3 672 {
673 random_signal
674 = !(stop_breakpoint
675 || stop_step_resume_break
4187119d 676#ifdef sony_news
e91b87a3 677 || (stop_sp INNER_THAN stop_pc
678 && stop_pc INNER_THAN stop_frame_address)
679#endif
4187119d 680
e91b87a3 681 );
682 if (!random_signal)
683 stop_signal = SIGTRAP;
684 }
685 }
686 else
687 random_signal = 1;
4187119d 688
e91b87a3 689 /* For the program's own signals, act according to
690 the signal handling tables. */
4187119d 691
e91b87a3 692 if (random_signal
693 && !(running_in_shell && stop_signal == SIGSEGV))
694 {
695 /* Signal not for debugging purposes. */
696 int printed = 0;
4187119d 697
e91b87a3 698 stopped_by_random_signal = 1;
4187119d 699
e91b87a3 700 if (stop_signal >= NSIG
701 || signal_print[stop_signal])
702 {
703 printed = 1;
704 terminal_ours_for_output ();
705 printf ("\nProgram received signal %d, %s\n",
706 stop_signal,
707 stop_signal < NSIG
4187119d 708 ? sys_siglist[stop_signal]
709 : "(undocumented)");
e91b87a3 710 fflush (stdout);
7b4ac7e1 711 }
e91b87a3 712 if (stop_signal >= NSIG
713 || signal_stop[stop_signal])
714 break;
715 /* If not going to stop, give terminal back
716 if we took it away. */
717 else if (printed)
718 terminal_inferior ();
719 }
4187119d 720
e91b87a3 721 /* Handle cases caused by hitting a breakpoint. */
4187119d 722
e91b87a3 723 if (!random_signal
724 && (stop_breakpoint || stop_step_resume_break))
725 {
726 /* Does a breakpoint want us to stop? */
727 if (stop_breakpoint && stop_breakpoint != -1
728 && stop_breakpoint != -0x1000001)
7b4ac7e1 729 {
e91b87a3 730 /* 0x1000000 is set in stop_breakpoint as returned by
731 breakpoint_stop_status to indicate a silent
732 breakpoint. */
733 if ((stop_breakpoint > 0 ? stop_breakpoint :
734 -stop_breakpoint)
735 & 0x1000000)
7b4ac7e1 736 {
e91b87a3 737 stop_print_frame = 0;
738 if (stop_breakpoint > 0)
739 stop_breakpoint -= 0x1000000;
740 else
741 stop_breakpoint += 0x1000000;
7b4ac7e1 742 }
e91b87a3 743 break;
7b4ac7e1 744 }
e91b87a3 745 /* But if we have hit the step-resumption breakpoint,
746 remove it. It has done its job getting us here.
747 The sp test is to make sure that we don't get hung
748 up in recursive calls in functions without frame
749 pointers. If the stack pointer isn't outside of
750 where the breakpoint was set (within a routine to be
751 stepped over), we're in the middle of a recursive
752 call. Not true for reg window machines (sparc)
753 because the must change frames to call things and
754 the stack pointer doesn't have to change if it
755 the bp was set in a routine without a frame (pc can
756 be stored in some other window).
4187119d 757
e91b87a3 758 The removal of the sp test is to allow calls to
759 alloca. Nasty things were happening. Oh, well,
760 gdb can only handle one level deep of lack of
761 frame pointer. */
762 if (stop_step_resume_break
763 && (step_frame_address == 0
4187119d 764 || (stop_frame_address == step_frame_address)))
7b4ac7e1 765 {
e91b87a3 766 remove_step_breakpoint ();
767 step_resume_break_address = 0;
768 }
769 /* Otherwise, must remove breakpoints and single-step
770 to get us past the one we hit. */
771 else
772 {
773 remove_breakpoints ();
774 remove_step_breakpoint ();
775 breakpoints_inserted = 0;
776 another_trap = 1;
777 }
4187119d 778
e91b87a3 779 /* We come here if we hit a breakpoint but should not
780 stop for it. Possibly we also were stepping
781 and should stop for that. So fall through and
782 test for stepping. But, if not stepping,
783 do not stop. */
784 }
4187119d 785
e91b87a3 786 /* If this is the breakpoint at the end of a stack dummy,
787 just stop silently. */
4187119d 788#ifndef CANNOT_EXECUTE_STACK
e91b87a3 789 if (stop_sp INNER_THAN stop_pc
790 && stop_pc INNER_THAN stop_frame_address)
791#else
4187119d 792 if (stop_pc == text_end - 2)
e91b87a3 793#endif
4187119d 794 {
795 stop_print_frame = 0;
796 stop_stack_dummy = 1;
797#ifdef HP_OS_BUG
798 trap_expected_after_continue = 1;
3bf57d21 799#endif
4187119d 800 break;
801 }
802
e91b87a3 803 if (step_resume_break_address)
804 /* Having a step-resume breakpoint overrides anything
805 else having to do with stepping commands until
806 that breakpoint is reached. */
807 ;
808 /* If stepping through a line, keep going if still within it. */
809 else if (!random_signal
810 && step_range_end
811 && stop_pc >= step_range_start
812 && stop_pc < step_range_end
813 /* The step range might include the start of the
814 function, so if we are at the start of the
815 step range and either the stack or frame pointers
816 just changed, we've stepped outside */
817 && !(stop_pc == step_range_start
818 && stop_frame_address
4187119d 819 && (stop_sp INNER_THAN prev_sp
e91b87a3 820 || stop_frame_address != step_frame_address)))
821 {
822 /* Don't step through the return from a function
823 unless that is the first instruction stepped through. */
824 if (ABOUT_TO_RETURN (stop_pc))
825 {
826 stop_step = 1;
7b4ac7e1 827 break;
828 }
e91b87a3 829 }
4187119d 830
e91b87a3 831 /* We stepped out of the stepping range. See if that was due
832 to a subroutine call that we should proceed to the end of. */
833 else if (!random_signal && step_range_end)
834 {
835 if (stop_func_start)
7b4ac7e1 836 {
e91b87a3 837 prologue_pc = stop_func_start;
838 SKIP_PROLOGUE (prologue_pc);
7b4ac7e1 839 }
840
4187119d 841 /* Did we just take a signal? */
1c997a4a 842 if (IN_SIGTRAMP (stop_pc, stop_func_name)
843 && !IN_SIGTRAMP (prev_pc, prev_func_name))
4187119d 844 {
7a67dd45 845 /* This code is needed at least in the following case:
846 The user types "next" and then a signal arrives (before
847 the "next" is done). */
4187119d 848 /* We've just taken a signal; go until we are back to
849 the point where we took it and one more. */
850 step_resume_break_address = prev_pc;
851 step_resume_break_duplicate =
852 breakpoint_here_p (step_resume_break_address);
853 step_resume_break_sp = stop_sp;
854 if (breakpoints_inserted)
855 insert_step_breakpoint ();
856 /* Make sure that the stepping range gets us past
857 that instruction. */
858 if (step_range_end == 1)
859 step_range_end = (step_range_start = prev_pc) + 1;
860 remove_breakpoints_on_following_step = 1;
861 }
e91b87a3 862
4187119d 863 /* ==> See comments at top of file on this algorithm. <==*/
864
865 else if (stop_pc == stop_func_start
e91b87a3 866 && (stop_func_start != prev_func_start
867 || prologue_pc != stop_func_start
868 || stop_sp != prev_sp))
7b4ac7e1 869 {
e91b87a3 870 /* It's a subroutine call */
4187119d 871 if (step_over_calls > 0
872 || (step_over_calls && find_pc_function (stop_pc) == 0))
7b4ac7e1 873 {
874 /* A subroutine call has happened. */
875 /* Set a special breakpoint after the return */
e91b87a3 876 step_resume_break_address =
877 SAVED_PC_AFTER_CALL (get_current_frame ());
7b4ac7e1 878 step_resume_break_duplicate
879 = breakpoint_here_p (step_resume_break_address);
e91b87a3 880 step_resume_break_sp = stop_sp;
7b4ac7e1 881 if (breakpoints_inserted)
882 insert_step_breakpoint ();
883 }
884 /* Subroutine call with source code we should not step over.
885 Do step to the first line of code in it. */
e91b87a3 886 else if (step_over_calls)
7b4ac7e1 887 {
e91b87a3 888 SKIP_PROLOGUE (stop_func_start);
889 sal = find_pc_line (stop_func_start, 0);
7b4ac7e1 890 /* Use the step_resume_break to step until
891 the end of the prologue, even if that involves jumps
892 (as it seems to on the vax under 4.2). */
893 /* If the prologue ends in the middle of a source line,
894 continue to the end of that source line.
895 Otherwise, just go to end of prologue. */
4187119d 896#ifdef PROLOGUE_FIRSTLINE_OVERLAP
e91b87a3 897 /* no, don't either. It skips any code that's
898 legitimately on the first line. */
899#else
900 if (sal.end && sal.pc != stop_func_start)
901 stop_func_start = sal.end;
902#endif
903
904 if (stop_func_start == stop_pc)
905 {
906 /* We are already there: stop now. */
907 stop_step = 1;
908 break;
909 }
3bf57d21 910 else
e91b87a3 911 /* Put the step-breakpoint there and go until there. */
3bf57d21 912 {
e91b87a3 913 step_resume_break_address = stop_func_start;
914 step_resume_break_sp = stop_sp;
915
3bf57d21 916 step_resume_break_duplicate
917 = breakpoint_here_p (step_resume_break_address);
918 if (breakpoints_inserted)
919 insert_step_breakpoint ();
920 /* Do not specify what the fp should be when we stop
921 since on some machines the prologue
922 is where the new fp value is established. */
e91b87a3 923 step_frame_address = 0;
3bf57d21 924 /* And make sure stepping stops right away then. */
925 step_range_end = step_range_start;
926 }
7b4ac7e1 927 }
7b4ac7e1 928 else
929 {
e91b87a3 930 /* We get here only if step_over_calls is 0 and we
931 just stepped into a subroutine. I presume
932 that step_over_calls is only 0 when we're
933 supposed to be stepping at the assembly
934 language level.*/
7b4ac7e1 935 stop_step = 1;
936 break;
937 }
938 }
e91b87a3 939 /* No subroutince call; stop now. */
940 else
941 {
942 stop_step = 1;
943 break;
944 }
7b4ac7e1 945 }
946
3bf57d21 947 /* Save the pc before execution, to compare with pc after stop. */
e91b87a3 948 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
949 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
950 BREAK is defined, the
951 original pc would not have
952 been at the start of a
953 function. */
4187119d 954 prev_func_name = stop_func_name;
e91b87a3 955 prev_sp = stop_sp;
3bf57d21 956
7b4ac7e1 957 /* If we did not do break;, it means we should keep
958 running the inferior and not return to debugger. */
959
960 /* If trap_expected is 2, it means continue once more
961 and insert breakpoints at the next trap.
962 If trap_expected is 1 and the signal was SIGSEGV, it means
963 the shell is doing some memory allocation--just resume it
964 with SIGSEGV.
965 Otherwise insert breakpoints now, and possibly single step. */
966
967 if (trap_expected > 1)
968 {
969 trap_expected--;
970 running_in_shell = 1;
971 resume (0, 0);
972 }
973 else if (running_in_shell && stop_signal == SIGSEGV)
974 {
975 resume (0, SIGSEGV);
976 }
4187119d 977 else if (trap_expected && stop_signal != SIGTRAP)
978 {
979 /* We took a signal which we are supposed to pass through to
980 the inferior and we haven't yet gotten our trap. Simply
981 continue. */
982 resume ((step_range_end && !step_resume_break_address)
983 || trap_expected,
984 stop_signal);
985 }
7b4ac7e1 986 else
987 {
988 /* Here, we are not awaiting another exec to get
989 the program we really want to debug.
990 Insert breakpoints now, unless we are trying
991 to one-proceed past a breakpoint. */
992 running_in_shell = 0;
4187119d 993 /* If we've just finished a special step resume and we don't
994 want to hit a breakpoint, pull em out. */
995 if (!step_resume_break_address &&
996 remove_breakpoints_on_following_step)
997 {
998 remove_breakpoints_on_following_step = 0;
999 remove_breakpoints ();
1000 breakpoints_inserted = 0;
1001 }
1002 else if (!breakpoints_inserted && !another_trap)
7b4ac7e1 1003 {
1004 insert_step_breakpoint ();
1005 breakpoints_failed = insert_breakpoints ();
1006 if (breakpoints_failed)
1007 break;
1008 breakpoints_inserted = 1;
1009 }
1010
1011 trap_expected = another_trap;
1012
1013 if (stop_signal == SIGTRAP)
1014 stop_signal = 0;
1015
1016 resume ((step_range_end && !step_resume_break_address)
1017 || trap_expected,
1018 stop_signal);
1019 }
1020 }
1021}
1022\f
1023/* Here to return control to GDB when the inferior stops for real.
1024 Print appropriate messages, remove breakpoints, give terminal our modes.
1025
1026 RUNNING_IN_SHELL nonzero means the shell got a signal before
1027 exec'ing the program we wanted to run.
1028 STOP_PRINT_FRAME nonzero means print the executing frame
1029 (pc, function, args, file, line number and line text).
1030 BREAKPOINTS_FAILED nonzero means stop was due to error
1031 attempting to insert breakpoints. */
1032
1033static void
1034normal_stop ()
1035{
e91b87a3 1036 /* Make sure that the current_frame's pc is correct. This
1037 is a correction for setting up the frame info before doing
1038 DECR_PC_AFTER_BREAK */
1039 if (inferior_pid)
1040 (get_current_frame ())->pc = read_pc ();
1041
7b4ac7e1 1042 if (breakpoints_failed)
1043 {
1044 terminal_ours_for_output ();
1045 print_sys_errmsg ("ptrace", breakpoints_failed);
1046 printf ("Stopped; cannot insert breakpoints.\n\
1047The same program may be running in another process.\n");
1048 }
1049
1050 if (inferior_pid)
1051 remove_step_breakpoint ();
1052
1053 if (inferior_pid && breakpoints_inserted)
1054 if (remove_breakpoints ())
1055 {
1056 terminal_ours_for_output ();
1057 printf ("Cannot remove breakpoints because program is no longer writable.\n\
1058It must be running in another process.\n\
1059Further execution is probably impossible.\n");
1060 }
1061
1062 breakpoints_inserted = 0;
1063
1064 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1065 Delete any breakpoint that is to be deleted at the next stop. */
1066
1067 breakpoint_auto_delete (stop_breakpoint);
1068
3bf57d21 1069 /* If an auto-display called a function and that got a signal,
1070 delete that auto-display to avoid an infinite recursion. */
1071
e91b87a3 1072 if (stopped_by_random_signal)
4187119d 1073 disable_current_display ();
3bf57d21 1074
7b4ac7e1 1075 if (step_multi && stop_step)
1076 return;
1077
1078 terminal_ours ();
1079
1080 if (running_in_shell)
1081 {
1082 if (stop_signal == SIGSEGV)
e91b87a3 1083 {
1084 char *exec_file = (char *) get_exec_file (1);
1085
1086 if (access (exec_file, X_OK) != 0)
1087 printf ("The file \"%s\" is not executable.\n", exec_file);
1088 else
7a67dd45 1089 /* I don't think we should ever get here.
1090 wait_for_inferior now ignores SIGSEGV's which happen in
1091 the shell (since the Bourne shell (/bin/sh) has some
1092 rather, er, uh, *unorthodox* memory management
1093 involving catching SIGSEGV). */
e91b87a3 1094 printf ("\
7b4ac7e1 1095You have just encountered a bug in \"sh\". GDB starts your program\n\
1096by running \"sh\" with a command to exec your program.\n\
1097This is so that \"sh\" will process wildcards and I/O redirection.\n\
1098This time, \"sh\" crashed.\n\
1099\n\
1100One known bug in \"sh\" bites when the environment takes up a lot of space.\n\
4187119d 1101Try \"info env\" to see the environment; then use \"delete env\" to kill\n\
7b4ac7e1 1102some variables whose values are large; then do \"run\" again.\n\
1103\n\
4187119d 1104If that works, you might want to put those \"delete env\" commands\n\
7b4ac7e1 1105into a \".gdbinit\" file in this directory so they will happen every time.\n");
e91b87a3 1106 }
7b4ac7e1 1107 /* Don't confuse user with his program's symbols on sh's data. */
1108 stop_print_frame = 0;
1109 }
1110
1111 if (inferior_pid == 0)
1112 return;
1113
1114 /* Select innermost stack frame except on return from a stack dummy routine,
1115 or if the program has exited. */
1116 if (!stop_stack_dummy)
1117 {
e91b87a3 1118 select_frame (get_current_frame (), 0);
7b4ac7e1 1119
1120 if (stop_print_frame)
1121 {
1122 if (stop_breakpoint > 0)
1123 printf ("\nBpt %d, ", stop_breakpoint);
1124 print_sel_frame (stop_step
e91b87a3 1125 && step_frame_address == stop_frame_address
7b4ac7e1 1126 && step_start_function == find_pc_function (stop_pc));
1127 /* Display the auto-display expressions. */
1128 do_displays ();
1129 }
1130 }
1131
1132 /* Save the function value return registers
1133 We might be about to restore their previous contents. */
1134 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1135
1136 if (stop_stack_dummy)
1137 {
e91b87a3 1138 /* Pop the empty frame that contains the stack dummy.
1139 POP_FRAME ends with a setting of the current frame, so we
1140 can use that next. */
7b4ac7e1 1141 POP_FRAME;
e91b87a3 1142 select_frame (get_current_frame (), 0);
7b4ac7e1 1143 }
1144}
1145\f
1146static void
1147insert_step_breakpoint ()
1148{
1149 if (step_resume_break_address && !step_resume_break_duplicate)
1150 {
1151 read_memory (step_resume_break_address,
1152 step_resume_break_shadow, sizeof break_insn);
1153 write_memory (step_resume_break_address,
1154 break_insn, sizeof break_insn);
1155 }
1156}
1157
1158static void
1159remove_step_breakpoint ()
1160{
1161 if (step_resume_break_address && !step_resume_break_duplicate)
1162 write_memory (step_resume_break_address, step_resume_break_shadow,
1163 sizeof break_insn);
1164}
1165\f
1166/* Specify how various signals in the inferior should be handled. */
1167
1168static void
1169handle_command (args, from_tty)
1170 char *args;
1171 int from_tty;
1172{
1173 register char *p = args;
e91b87a3 1174 int signum = 0;
7b4ac7e1 1175 register int digits, wordlen;
1176
1177 if (!args)
1178 error_no_arg ("signal to handle");
1179
1180 while (*p)
1181 {
1182 /* Find the end of the next word in the args. */
1183 for (wordlen = 0; p[wordlen] && p[wordlen] != ' ' && p[wordlen] != '\t';
1184 wordlen++);
1185 for (digits = 0; p[digits] >= '0' && p[digits] <= '9'; digits++);
1186
1187 /* If it is all digits, it is signal number to operate on. */
1188 if (digits == wordlen)
1189 {
1190 signum = atoi (p);
e91b87a3 1191 if (signum <= 0 || signum >= NSIG)
1192 {
1193 p[wordlen] = '\0';
1194 error ("Invalid signal %s given as argument to \"handle\".", p);
1195 }
7b4ac7e1 1196 if (signum == SIGTRAP || signum == SIGINT)
1197 {
1198 if (!query ("Signal %d is used by the debugger.\nAre you sure you want to change it? ", signum))
1199 error ("Not confirmed.");
1200 }
1201 }
1202 else if (signum == 0)
1203 error ("First argument is not a signal number.");
1204
1205 /* Else, if already got a signal number, look for flag words
1206 saying what to do for it. */
1207 else if (!strncmp (p, "stop", wordlen))
1208 {
1209 signal_stop[signum] = 1;
1210 signal_print[signum] = 1;
1211 }
1212 else if (wordlen >= 2 && !strncmp (p, "print", wordlen))
1213 signal_print[signum] = 1;
1214 else if (wordlen >= 2 && !strncmp (p, "pass", wordlen))
1215 signal_program[signum] = 1;
1216 else if (!strncmp (p, "ignore", wordlen))
1217 signal_program[signum] = 0;
1218 else if (wordlen >= 3 && !strncmp (p, "nostop", wordlen))
1219 signal_stop[signum] = 0;
1220 else if (wordlen >= 4 && !strncmp (p, "noprint", wordlen))
1221 {
1222 signal_print[signum] = 0;
1223 signal_stop[signum] = 0;
1224 }
1225 else if (wordlen >= 4 && !strncmp (p, "nopass", wordlen))
1226 signal_program[signum] = 0;
1227 else if (wordlen >= 3 && !strncmp (p, "noignore", wordlen))
1228 signal_program[signum] = 1;
1229 /* Not a number and not a recognized flag word => complain. */
1230 else
1231 {
1232 p[wordlen] = 0;
1233 error ("Unrecognized flag word: \"%s\".", p);
1234 }
1235
1236 /* Find start of next word. */
1237 p += wordlen;
1238 while (*p == ' ' || *p == '\t') p++;
1239 }
1240
1241 if (from_tty)
1242 {
1243 /* Show the results. */
1244 printf ("Number\tStop\tPrint\tPass to program\tDescription\n");
1245 printf ("%d\t", signum);
1246 printf ("%s\t", signal_stop[signum] ? "Yes" : "No");
1247 printf ("%s\t", signal_print[signum] ? "Yes" : "No");
1248 printf ("%s\t\t", signal_program[signum] ? "Yes" : "No");
1249 printf ("%s\n", sys_siglist[signum]);
1250 }
1251}
1252
1253/* Print current contents of the tables set by the handle command. */
1254
1255static void
1256signals_info (signum_exp)
1257 char *signum_exp;
1258{
1259 register int i;
4187119d 1260 printf_filtered ("Number\tStop\tPrint\tPass to program\tDescription\n");
7b4ac7e1 1261
1262 if (signum_exp)
1263 {
1264 i = parse_and_eval_address (signum_exp);
4187119d 1265 if (i >= NSIG || i < 0)
1266 error ("Signal number out of bounds.");
1267 printf_filtered ("%d\t", i);
1268 printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No");
1269 printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No");
1270 printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No");
1271 printf_filtered ("%s\n", sys_siglist[i]);
7b4ac7e1 1272 return;
1273 }
1274
4187119d 1275 printf_filtered ("\n");
7b4ac7e1 1276 for (i = 0; i < NSIG; i++)
1277 {
1278 QUIT;
4187119d 1279
1280 printf_filtered ("%d\t", i);
1281 printf_filtered ("%s\t", signal_stop[i] ? "Yes" : "No");
1282 printf_filtered ("%s\t", signal_print[i] ? "Yes" : "No");
1283 printf_filtered ("%s\t\t", signal_program[i] ? "Yes" : "No");
1284 printf_filtered ("%s\n", sys_siglist[i]);
7b4ac7e1 1285 }
1286
4187119d 1287 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
7b4ac7e1 1288}
1289\f
e91b87a3 1290/* Save all of the information associated with the inferior<==>gdb
1291 connection. INF_STATUS is a pointer to a "struct inferior_status"
1292 (defined in inferior.h). */
1293
1294struct command_line *get_breakpoint_commands ();
1295
1296void
1297save_inferior_status (inf_status, restore_stack_info)
1298 struct inferior_status *inf_status;
1299 int restore_stack_info;
1300{
1301 inf_status->pc_changed = pc_changed;
1302 inf_status->stop_signal = stop_signal;
1303 inf_status->stop_pc = stop_pc;
1304 inf_status->stop_frame_address = stop_frame_address;
1305 inf_status->stop_breakpoint = stop_breakpoint;
1306 inf_status->stop_step = stop_step;
1307 inf_status->stop_stack_dummy = stop_stack_dummy;
1308 inf_status->stopped_by_random_signal = stopped_by_random_signal;
1309 inf_status->trap_expected = trap_expected;
1310 inf_status->step_range_start = step_range_start;
1311 inf_status->step_range_end = step_range_end;
1312 inf_status->step_frame_address = step_frame_address;
1313 inf_status->step_over_calls = step_over_calls;
1314 inf_status->step_resume_break_address = step_resume_break_address;
1315 inf_status->stop_after_trap = stop_after_trap;
1316 inf_status->stop_after_attach = stop_after_attach;
1317 inf_status->breakpoint_commands = get_breakpoint_commands ();
1318 inf_status->restore_stack_info = restore_stack_info;
1319
1320 bcopy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
1321
1322 record_selected_frame (&(inf_status->selected_frame_address),
1323 &(inf_status->selected_level));
1324 return;
1325}
1326
1327void
1328restore_inferior_status (inf_status)
1329 struct inferior_status *inf_status;
1330{
1331 FRAME fid;
1332 int level = inf_status->selected_level;
1333
1334 pc_changed = inf_status->pc_changed;
1335 stop_signal = inf_status->stop_signal;
1336 stop_pc = inf_status->stop_pc;
1337 stop_frame_address = inf_status->stop_frame_address;
1338 stop_breakpoint = inf_status->stop_breakpoint;
1339 stop_step = inf_status->stop_step;
1340 stop_stack_dummy = inf_status->stop_stack_dummy;
1341 stopped_by_random_signal = inf_status->stopped_by_random_signal;
1342 trap_expected = inf_status->trap_expected;
1343 step_range_start = inf_status->step_range_start;
1344 step_range_end = inf_status->step_range_end;
1345 step_frame_address = inf_status->step_frame_address;
1346 step_over_calls = inf_status->step_over_calls;
1347 step_resume_break_address = inf_status->step_resume_break_address;
1348 stop_after_trap = inf_status->stop_after_trap;
1349 stop_after_attach = inf_status->stop_after_attach;
1350 set_breakpoint_commands (inf_status->breakpoint_commands);
1351
1352 bcopy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
1353
7a67dd45 1354 /* The inferior can be gone if the user types "print exit(0)"
1355 (and perhaps other times). */
1356 if (have_inferior_p() && inf_status->restore_stack_info)
e91b87a3 1357 {
1358 fid = find_relative_frame (get_current_frame (),
1359 &level);
7a67dd45 1360
1361 if (fid == 0 ||
1362 FRAME_FP (fid) != inf_status->selected_frame_address ||
e91b87a3 1363 level != 0)
1364 {
7a67dd45 1365 /* I'm not sure this error message is a good idea. I have
1366 only seen it occur after "Can't continue previously
1367 requested operation" (we get called from do_cleanups), in
1368 which case it just adds insult to injury (one confusing
1369 error message after another. Besides which, does the
1370 user really care if we can't restore the previously
1371 selected frame? */
e91b87a3 1372 fprintf (stderr, "Unable to restore previously selected frame.\n");
1373 select_frame (get_current_frame (), 0);
1374 return;
1375 }
1376
1377 select_frame (fid, inf_status->selected_level);
1378 }
1379 return;
1380}
1381
1382\f
1383void
1384_initialize_infrun ()
7b4ac7e1 1385{
1386 register int i;
1387
1388 add_info ("signals", signals_info,
1389 "What debugger does when program gets various signals.\n\
1390Specify a signal number as argument to print info on that signal only.");
1391
1392 add_com ("handle", class_run, handle_command,
1393 "Specify how to handle a signal.\n\
1394Args are signal number followed by flags.\n\
1395Flags allowed are \"stop\", \"print\", \"pass\",\n\
1396 \"nostop\", \"noprint\" or \"nopass\".\n\
1397Print means print a message if this signal happens.\n\
1398Stop means reenter debugger if this signal happens (implies print).\n\
1399Pass means let program see this signal; otherwise program doesn't know.\n\
1400Pass and Stop may be combined.");
1401
1402 for (i = 0; i < NSIG; i++)
1403 {
1404 signal_stop[i] = 1;
1405 signal_print[i] = 1;
1406 signal_program[i] = 1;
1407 }
1408
1409 /* Signals caused by debugger's own actions
1410 should not be given to the program afterwards. */
1411 signal_program[SIGTRAP] = 0;
1412 signal_program[SIGINT] = 0;
1413
1414 /* Signals that are not errors should not normally enter the debugger. */
1415#ifdef SIGALRM
1416 signal_stop[SIGALRM] = 0;
1417 signal_print[SIGALRM] = 0;
1418#endif /* SIGALRM */
1419#ifdef SIGVTALRM
1420 signal_stop[SIGVTALRM] = 0;
1421 signal_print[SIGVTALRM] = 0;
1422#endif /* SIGVTALRM */
1423#ifdef SIGPROF
1424 signal_stop[SIGPROF] = 0;
1425 signal_print[SIGPROF] = 0;
1426#endif /* SIGPROF */
1427#ifdef SIGCHLD
1428 signal_stop[SIGCHLD] = 0;
1429 signal_print[SIGCHLD] = 0;
1430#endif /* SIGCHLD */
1431#ifdef SIGCLD
1432 signal_stop[SIGCLD] = 0;
1433 signal_print[SIGCLD] = 0;
1434#endif /* SIGCLD */
1435#ifdef SIGIO
1436 signal_stop[SIGIO] = 0;
1437 signal_print[SIGIO] = 0;
1438#endif /* SIGIO */
1439#ifdef SIGURG
1440 signal_stop[SIGURG] = 0;
1441 signal_print[SIGURG] = 0;
1442#endif /* SIGURG */
1443}
1444
This page took 0.085794 seconds and 4 git commands to generate.