start-sanitize-powerpc-netware
[deliverable/binutils-gdb.git] / gdb / infrun.c
CommitLineData
3aa6856a 1/* Target-struct-independent code to start (run) and stop an inferior process.
fcbc95a7 2 Copyright 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994
101b7f9c 3 Free Software Foundation, Inc.
bd5635a1
RP
4
5This file is part of GDB.
6
3b271cf4 7This program is free software; you can redistribute it and/or modify
bd5635a1 8it under the terms of the GNU General Public License as published by
3b271cf4
JG
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
bd5635a1 11
3b271cf4 12This program is distributed in the hope that it will be useful,
bd5635a1
RP
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
3b271cf4
JG
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 20
bd5635a1 21#include "defs.h"
d747e0af 22#include <string.h>
a6b98cb9 23#include <ctype.h>
bd5635a1
RP
24#include "symtab.h"
25#include "frame.h"
26#include "inferior.h"
27#include "breakpoint.h"
28#include "wait.h"
29#include "gdbcore.h"
3950a34e 30#include "gdbcmd.h"
bd5635a1 31#include "target.h"
100f92e2 32#include "thread.h"
bd5635a1
RP
33
34#include <signal.h>
35
36/* unistd.h is needed to #define X_OK */
37#ifdef USG
38#include <unistd.h>
39#else
40#include <sys/file.h>
41#endif
42
30875e1c 43/* Prototypes for local functions */
bd5635a1 44
30875e1c 45static void
e37a6e9c 46signals_info PARAMS ((char *, int));
619fd145 47
30875e1c
SG
48static void
49handle_command PARAMS ((char *, int));
50
67ac9759 51static void sig_print_info PARAMS ((enum target_signal));
30875e1c
SG
52
53static void
54sig_print_header PARAMS ((void));
55
30875e1c
SG
56static void
57resume_cleanups PARAMS ((int));
58
3950a34e
RP
59static int
60hook_stop_stub PARAMS ((char *));
61
30875e1c
SG
62/* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
63 program. It needs to examine the jmp_buf argument and extract the PC
64 from it. The return value is non-zero on success, zero otherwise. */
65#ifndef GET_LONGJMP_TARGET
66#define GET_LONGJMP_TARGET(PC_ADDR) 0
67#endif
68
d747e0af
MT
69
70/* Some machines have trampoline code that sits between function callers
71 and the actual functions themselves. If this machine doesn't have
72 such things, disable their processing. */
73#ifndef SKIP_TRAMPOLINE_CODE
74#define SKIP_TRAMPOLINE_CODE(pc) 0
75#endif
76
1eeba686 77/* For SVR4 shared libraries, each call goes through a small piece of
2fe3b329 78 trampoline code in the ".plt" section. IN_SOLIB_TRAMPOLINE evaluates
1eeba686
PB
79 to nonzero if we are current stopped in one of these. */
80#ifndef IN_SOLIB_TRAMPOLINE
81#define IN_SOLIB_TRAMPOLINE(pc,name) 0
82#endif
d747e0af 83
9f739abd
SG
84/* On some systems, the PC may be left pointing at an instruction that won't
85 actually be executed. This is usually indicated by a bit in the PSW. If
86 we find ourselves in such a state, then we step the target beyond the
87 nullified instruction before returning control to the user so as to avoid
88 confusion. */
89
90#ifndef INSTRUCTION_NULLIFIED
91#define INSTRUCTION_NULLIFIED 0
92#endif
93
bd5635a1
RP
94/* Tables of how to react to signals; the user sets them. */
95
072b552a
JG
96static unsigned char *signal_stop;
97static unsigned char *signal_print;
98static unsigned char *signal_program;
99
100#define SET_SIGS(nsigs,sigs,flags) \
101 do { \
102 int signum = (nsigs); \
103 while (signum-- > 0) \
104 if ((sigs)[signum]) \
105 (flags)[signum] = 1; \
106 } while (0)
107
108#define UNSET_SIGS(nsigs,sigs,flags) \
109 do { \
110 int signum = (nsigs); \
111 while (signum-- > 0) \
112 if ((sigs)[signum]) \
113 (flags)[signum] = 0; \
114 } while (0)
bd5635a1 115
3950a34e
RP
116
117/* Command list pointer for the "stop" placeholder. */
118
119static struct cmd_list_element *stop_command;
120
bd5635a1 121/* Nonzero if breakpoints are now inserted in the inferior. */
bd5635a1 122
3950a34e 123static int breakpoints_inserted;
bd5635a1
RP
124
125/* Function inferior was in as of last step command. */
126
127static struct symbol *step_start_function;
128
bd5635a1
RP
129/* Nonzero if we are expecting a trace trap and should proceed from it. */
130
131static int trap_expected;
132
133/* Nonzero if the next time we try to continue the inferior, it will
134 step one instruction and generate a spurious trace trap.
135 This is used to compensate for a bug in HP-UX. */
136
137static int trap_expected_after_continue;
138
139/* Nonzero means expecting a trace trap
140 and should stop the inferior and return silently when it happens. */
141
142int stop_after_trap;
143
144/* Nonzero means expecting a trap and caller will handle it themselves.
145 It is used after attach, due to attaching to a process;
146 when running in the shell before the child program has been exec'd;
147 and when running some kinds of remote stuff (FIXME?). */
148
149int stop_soon_quietly;
150
bd5635a1
RP
151/* Nonzero if proceed is being used for a "finish" command or a similar
152 situation when stop_registers should be saved. */
153
154int proceed_to_finish;
155
156/* Save register contents here when about to pop a stack dummy frame,
157 if-and-only-if proceed_to_finish is set.
158 Thus this contains the return value from the called function (assuming
159 values are returned in a register). */
160
161char stop_registers[REGISTER_BYTES];
162
163/* Nonzero if program stopped due to error trying to insert breakpoints. */
164
165static int breakpoints_failed;
166
167/* Nonzero after stop if current stack frame should be printed. */
168
169static int stop_print_frame;
170
171#ifdef NO_SINGLE_STEP
172extern int one_stepped; /* From machine dependent code */
173extern void single_step (); /* Same. */
174#endif /* NO_SINGLE_STEP */
175
a71d17b1
JK
176\f
177/* Things to clean up if we QUIT out of resume (). */
e1ce8aa5 178/* ARGSUSED */
a71d17b1
JK
179static void
180resume_cleanups (arg)
181 int arg;
182{
183 normal_stop ();
184}
185
186/* Resume the inferior, but allow a QUIT. This is useful if the user
187 wants to interrupt some lengthy single-stepping operation
188 (for child processes, the SIGINT goes to the inferior, and so
189 we get a SIGINT random_signal, but for remote debugging and perhaps
190 other targets, that's not true).
191
192 STEP nonzero if we should step (zero to continue instead).
193 SIG is the signal to give the inferior (zero for none). */
310cc570 194void
a71d17b1
JK
195resume (step, sig)
196 int step;
67ac9759 197 enum target_signal sig;
a71d17b1
JK
198{
199 struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0);
200 QUIT;
d11c44f1 201
cef4c2e7
PS
202#ifdef CANNOT_STEP_BREAKPOINT
203 /* Most targets can step a breakpoint instruction, thus executing it
204 normally. But if this one cannot, just continue and we will hit
205 it anyway. */
206 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
207 step = 0;
208#endif
209
d11c44f1
JG
210#ifdef NO_SINGLE_STEP
211 if (step) {
818de002 212 single_step(sig); /* Do it the hard way, w/temp breakpoints */
d11c44f1
JG
213 step = 0; /* ...and don't ask hardware to do it. */
214 }
215#endif
216
bdbd5f50
JG
217 /* Handle any optimized stores to the inferior NOW... */
218#ifdef DO_DEFERRED_STORES
219 DO_DEFERRED_STORES;
220#endif
221
2f1c7c3f
JK
222 /* Install inferior's terminal modes. */
223 target_terminal_inferior ();
224
de43d7d0 225 target_resume (-1, step, sig);
a71d17b1
JK
226 discard_cleanups (old_cleanups);
227}
228
bd5635a1
RP
229\f
230/* Clear out all variables saying what to do when inferior is continued.
231 First do this, then set the ones you want, then call `proceed'. */
232
233void
234clear_proceed_status ()
235{
236 trap_expected = 0;
237 step_range_start = 0;
238 step_range_end = 0;
239 step_frame_address = 0;
240 step_over_calls = -1;
bd5635a1
RP
241 stop_after_trap = 0;
242 stop_soon_quietly = 0;
243 proceed_to_finish = 0;
244 breakpoint_proceeded = 1; /* We're about to proceed... */
245
246 /* Discard any remaining commands or status from previous stop. */
247 bpstat_clear (&stop_bpstat);
248}
249
250/* Basic routine for continuing the program in various fashions.
251
252 ADDR is the address to resume at, or -1 for resume where stopped.
253 SIGGNAL is the signal to give it, or 0 for none,
254 or -1 for act according to how it stopped.
255 STEP is nonzero if should trap after one instruction.
256 -1 means return after that and print nothing.
257 You should probably set various step_... variables
258 before calling here, if you are stepping.
259
260 You should call clear_proceed_status before calling proceed. */
261
262void
263proceed (addr, siggnal, step)
264 CORE_ADDR addr;
67ac9759 265 enum target_signal siggnal;
bd5635a1
RP
266 int step;
267{
268 int oneproc = 0;
269
270 if (step > 0)
271 step_start_function = find_pc_function (read_pc ());
272 if (step < 0)
273 stop_after_trap = 1;
274
bdbd5f50 275 if (addr == (CORE_ADDR)-1)
bd5635a1
RP
276 {
277 /* If there is a breakpoint at the address we will resume at,
278 step one instruction before inserting breakpoints
279 so that we do not stop right away. */
280
37c99ddb 281 if (breakpoint_here_p (read_pc ()))
bd5635a1 282 oneproc = 1;
b5aff268
JK
283
284#ifdef STEP_SKIPS_DELAY
285 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
286 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
287 is slow (it needs to read memory from the target). */
288 if (breakpoint_here_p (read_pc () + 4)
289 && STEP_SKIPS_DELAY (read_pc ()))
290 oneproc = 1;
291#endif /* STEP_SKIPS_DELAY */
bd5635a1
RP
292 }
293 else
101b7f9c 294 write_pc (addr);
bd5635a1
RP
295
296 if (trap_expected_after_continue)
297 {
298 /* If (step == 0), a trap will be automatically generated after
299 the first instruction is executed. Force step one
300 instruction to clear this condition. This should not occur
301 if step is nonzero, but it is harmless in that case. */
302 oneproc = 1;
303 trap_expected_after_continue = 0;
304 }
305
306 if (oneproc)
307 /* We will get a trace trap after one instruction.
308 Continue it automatically and insert breakpoints then. */
309 trap_expected = 1;
310 else
311 {
312 int temp = insert_breakpoints ();
313 if (temp)
314 {
315 print_sys_errmsg ("ptrace", temp);
316 error ("Cannot insert breakpoints.\n\
317The same program may be running in another process.");
318 }
319 breakpoints_inserted = 1;
320 }
321
fcbc95a7 322 if (siggnal != TARGET_SIGNAL_DEFAULT)
bd5635a1
RP
323 stop_signal = siggnal;
324 /* If this signal should not be seen by program,
325 give it zero. Used for debugging signals. */
67ac9759 326 else if (!signal_program[stop_signal])
fcbc95a7 327 stop_signal = TARGET_SIGNAL_0;
bd5635a1 328
bd5635a1 329 /* Resume inferior. */
a71d17b1 330 resume (oneproc || step || bpstat_should_step (), stop_signal);
bd5635a1
RP
331
332 /* Wait for it to stop (if not standalone)
333 and in any case decode why it stopped, and act accordingly. */
334
335 wait_for_inferior ();
336 normal_stop ();
337}
338
bd5635a1
RP
339/* Record the pc and sp of the program the last time it stopped.
340 These are just used internally by wait_for_inferior, but need
341 to be preserved over calls to it and cleared when the inferior
342 is started. */
343static CORE_ADDR prev_pc;
344static CORE_ADDR prev_sp;
345static CORE_ADDR prev_func_start;
346static char *prev_func_name;
bcc37718 347static CORE_ADDR prev_frame_address;
bd5635a1 348
a71d17b1 349\f
bd5635a1
RP
350/* Start remote-debugging of a machine over a serial link. */
351
352void
353start_remote ()
354{
355 init_wait_for_inferior ();
356 clear_proceed_status ();
357 stop_soon_quietly = 1;
358 trap_expected = 0;
98885d76
JK
359 wait_for_inferior ();
360 normal_stop ();
bd5635a1
RP
361}
362
363/* Initialize static vars when a new inferior begins. */
364
365void
366init_wait_for_inferior ()
367{
368 /* These are meaningless until the first time through wait_for_inferior. */
369 prev_pc = 0;
370 prev_sp = 0;
371 prev_func_start = 0;
372 prev_func_name = NULL;
bcc37718 373 prev_frame_address = 0;
bd5635a1
RP
374
375 trap_expected_after_continue = 0;
376 breakpoints_inserted = 0;
cf3e377e 377 breakpoint_init_inferior ();
67ac9759
JK
378
379 /* Don't confuse first call to proceed(). */
380 stop_signal = TARGET_SIGNAL_0;
bd5635a1
RP
381}
382
fe675038
JK
383static void
384delete_breakpoint_current_contents (arg)
385 PTR arg;
386{
387 struct breakpoint **breakpointp = (struct breakpoint **)arg;
388 if (*breakpointp != NULL)
389 delete_breakpoint (*breakpointp);
390}
bd5635a1
RP
391\f
392/* Wait for control to return from inferior to debugger.
393 If inferior gets a signal, we may decide to start it up again
394 instead of returning. That is why there is a loop in this function.
395 When this function actually returns it means the inferior
396 should be left stopped and GDB should read more commands. */
397
398void
399wait_for_inferior ()
400{
fe675038 401 struct cleanup *old_cleanups;
67ac9759 402 struct target_waitstatus w;
bd5635a1
RP
403 int another_trap;
404 int random_signal;
37c99ddb 405 CORE_ADDR stop_sp = 0;
bd5635a1 406 CORE_ADDR stop_func_start;
67ac9759 407 CORE_ADDR stop_func_end;
bd5635a1 408 char *stop_func_name;
37c99ddb 409 CORE_ADDR prologue_pc = 0, tmp;
bd5635a1
RP
410 struct symtab_and_line sal;
411 int remove_breakpoints_on_following_step = 0;
b3b39c0c 412 int current_line;
b2f03c30 413 struct symtab *current_symtab;
30875e1c 414 int handling_longjmp = 0; /* FIXME */
fe675038 415 struct breakpoint *step_resume_breakpoint = NULL;
bcc37718 416 struct breakpoint *through_sigtramp_breakpoint = NULL;
37c99ddb 417 int pid;
bd5635a1 418
fe675038
JK
419 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
420 &step_resume_breakpoint);
bcc37718
JK
421 make_cleanup (delete_breakpoint_current_contents,
422 &through_sigtramp_breakpoint);
b3b39c0c
SG
423 sal = find_pc_line(prev_pc, 0);
424 current_line = sal.line;
b2f03c30 425 current_symtab = sal.symtab;
b3b39c0c 426
cb6b0202 427 /* Are we stepping? */
bcc37718
JK
428#define CURRENTLY_STEPPING() \
429 ((through_sigtramp_breakpoint == NULL \
430 && !handling_longjmp \
431 && ((step_range_end && step_resume_breakpoint == NULL) \
432 || trap_expected)) \
433 || bpstat_should_step ())
cb6b0202 434
bd5635a1
RP
435 while (1)
436 {
437 /* Clean up saved state that will become invalid. */
bd5635a1
RP
438 flush_cached_frames ();
439 registers_changed ();
440
de43d7d0 441 pid = target_wait (-1, &w);
bd5635a1 442
fcbc95a7
JK
443 switch (w.kind)
444 {
445 case TARGET_WAITKIND_LOADED:
446 /* Ignore it gracefully. */
447 if (breakpoints_inserted)
448 {
449 mark_breakpoints_out ();
450 insert_breakpoints ();
451 }
452 resume (0, TARGET_SIGNAL_0);
453 continue;
1eeba686 454
fcbc95a7
JK
455 case TARGET_WAITKIND_SPURIOUS:
456 resume (0, TARGET_SIGNAL_0);
457 continue;
1eeba686 458
fcbc95a7 459 case TARGET_WAITKIND_EXITED:
bd5635a1 460 target_terminal_ours (); /* Must do this before mourn anyway */
67ac9759 461 if (w.value.integer)
e37a6e9c 462 printf_filtered ("\nProgram exited with code 0%o.\n",
67ac9759 463 (unsigned int)w.value.integer);
bd5635a1
RP
464 else
465 if (!batch_mode())
e37a6e9c 466 printf_filtered ("\nProgram exited normally.\n");
199b2450 467 gdb_flush (gdb_stdout);
bd5635a1
RP
468 target_mourn_inferior ();
469#ifdef NO_SINGLE_STEP
470 one_stepped = 0;
471#endif
472 stop_print_frame = 0;
fcbc95a7 473 goto stop_stepping;
67ac9759 474
fcbc95a7 475 case TARGET_WAITKIND_SIGNALLED:
bd5635a1 476 stop_print_frame = 0;
67ac9759 477 stop_signal = w.value.sig;
bd5635a1 478 target_terminal_ours (); /* Must do this before mourn anyway */
30875e1c 479 target_kill (); /* kill mourns as well */
67ac9759
JK
480 printf_filtered ("\nProgram terminated with signal %s, %s.\n",
481 target_signal_to_name (stop_signal),
482 target_signal_to_string (stop_signal));
483
fee44494 484 printf_filtered ("The program no longer exists.\n");
199b2450 485 gdb_flush (gdb_stdout);
bd5635a1
RP
486#ifdef NO_SINGLE_STEP
487 one_stepped = 0;
488#endif
fcbc95a7
JK
489 goto stop_stepping;
490
491 case TARGET_WAITKIND_STOPPED:
492 /* This is the only case in which we keep going; the above cases
493 end in a continue or goto. */
bd5635a1
RP
494 break;
495 }
de43d7d0 496
67ac9759 497 stop_signal = w.value.sig;
de43d7d0
SG
498
499 if (pid != inferior_pid)
500 {
501 int save_pid = inferior_pid;
502
503 inferior_pid = pid; /* Setup for target memory/regs */
504 registers_changed ();
505 stop_pc = read_pc ();
506 inferior_pid = save_pid;
507 registers_changed ();
508 }
509 else
510 stop_pc = read_pc ();
511
67ac9759 512 if (stop_signal == TARGET_SIGNAL_TRAP
de43d7d0 513 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
b2f03c30
JK
514 {
515 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
516 {
517 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
518 if (breakpoints_inserted)
519 {
520 if (pid != inferior_pid)
521 {
522 int save_pid = inferior_pid;
523
524 inferior_pid = pid;
525 registers_changed ();
526 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
527 inferior_pid = save_pid;
528 registers_changed ();
529 }
530 else
531 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
532
533 remove_breakpoints ();
67ac9759 534 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
b2f03c30
JK
535 /* FIXME: What if a signal arrives instead of the single-step
536 happening? */
537 target_wait (pid, &w);
538 insert_breakpoints ();
539 }
67ac9759 540 target_resume (-1, 0, TARGET_SIGNAL_0);
b2f03c30
JK
541 continue;
542 }
543 else
544 if (pid != inferior_pid)
545 goto switch_thread;
546 }
de43d7d0 547
37c99ddb
JK
548 if (pid != inferior_pid)
549 {
550 int printed = 0;
551
552 if (!in_thread_list (pid))
553 {
199b2450 554 fprintf_unfiltered (gdb_stderr, "[New %s]\n", target_pid_to_str (pid));
37c99ddb
JK
555 add_thread (pid);
556
67ac9759 557 target_resume (-1, 0, TARGET_SIGNAL_0);
37c99ddb
JK
558 continue;
559 }
560 else
561 {
67ac9759 562 if (signal_print[stop_signal])
37c99ddb
JK
563 {
564 char *signame;
565
566 printed = 1;
567 target_terminal_ours_for_output ();
67ac9759
JK
568 printf_filtered ("\nProgram received signal %s, %s.\n",
569 target_signal_to_name (stop_signal),
570 target_signal_to_string (stop_signal));
199b2450 571 gdb_flush (gdb_stdout);
37c99ddb
JK
572 }
573
67ac9759 574 if (stop_signal == TARGET_SIGNAL_TRAP
de43d7d0 575 || signal_stop[stop_signal])
37c99ddb 576 {
de43d7d0 577switch_thread:
37c99ddb
JK
578 inferior_pid = pid;
579 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
580
581 flush_cached_frames ();
582 registers_changed ();
583 trap_expected = 0;
584 if (step_resume_breakpoint)
585 {
586 delete_breakpoint (step_resume_breakpoint);
587 step_resume_breakpoint = NULL;
588 }
bcc37718
JK
589
590 /* Not sure whether we need to blow this away too,
591 but probably it is like the step-resume
592 breakpoint. */
593 if (through_sigtramp_breakpoint)
594 {
595 delete_breakpoint (through_sigtramp_breakpoint);
596 through_sigtramp_breakpoint = NULL;
597 }
37c99ddb
JK
598 prev_pc = 0;
599 prev_sp = 0;
600 prev_func_name = NULL;
601 step_range_start = 0;
602 step_range_end = 0;
603 step_frame_address = 0;
604 handling_longjmp = 0;
605 another_trap = 0;
606 }
607 else
608 {
609 if (printed)
610 target_terminal_inferior ();
611
612 /* Clear the signal if it should not be passed. */
613 if (signal_program[stop_signal] == 0)
67ac9759 614 stop_signal = TARGET_SIGNAL_0;
37c99ddb 615
b2f03c30 616 target_resume (pid, 0, stop_signal);
37c99ddb
JK
617 continue;
618 }
619 }
620 }
621
bd5635a1
RP
622#ifdef NO_SINGLE_STEP
623 if (one_stepped)
624 single_step (0); /* This actually cleans up the ss */
625#endif /* NO_SINGLE_STEP */
626
999dd04b
JL
627 /* If PC is pointing at a nullified instruction, then step beyond
628 it so that the user won't be confused when GDB appears to be ready
629 to execute it. */
9f739abd
SG
630
631 if (INSTRUCTION_NULLIFIED)
632 {
633 resume (1, 0);
634 continue;
635 }
636
999dd04b
JL
637 set_current_frame (create_new_frame (read_fp (), stop_pc));
638 select_frame (get_current_frame (), 0);
639
640#ifdef HAVE_STEPPABLE_WATCHPOINT
641 /* It may not be necessary to disable the watchpoint to stop over
642 it. For example, the PA can (with some kernel cooperation)
643 single step over a watchpoint without disabling the watchpoint. */
644 if (STOPPED_BY_WATCHPOINT (w))
645 {
646 resume (1, 0);
647 continue;
648 }
649#endif
650
651#ifdef HAVE_NONSTEPPABLE_WATCHPOINT
652 /* It is far more common to need to disable a watchpoint
653 to step the inferior over it. FIXME. What else might
654 a debug register or page protection watchpoint scheme need
655 here? */
656 if (STOPPED_BY_WATCHPOINT (w))
657 {
658 remove_breakpoints ();
659 resume (1, 0);
660 insert_breakpoints ();
661 continue;
662 }
663#endif
fe675038 664
bd5635a1 665 stop_frame_address = FRAME_FP (get_current_frame ());
fee44494 666 stop_sp = read_sp ();
bd5635a1
RP
667 stop_func_start = 0;
668 stop_func_name = 0;
669 /* Don't care about return value; stop_func_start and stop_func_name
670 will both be 0 if it doesn't work. */
37c99ddb 671 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
67ac9759 672 &stop_func_end);
bd5635a1
RP
673 stop_func_start += FUNCTION_START_OFFSET;
674 another_trap = 0;
675 bpstat_clear (&stop_bpstat);
676 stop_step = 0;
677 stop_stack_dummy = 0;
678 stop_print_frame = 1;
bd5635a1
RP
679 random_signal = 0;
680 stopped_by_random_signal = 0;
681 breakpoints_failed = 0;
682
683 /* Look at the cause of the stop, and decide what to do.
684 The alternatives are:
685 1) break; to really stop and return to the debugger,
686 2) drop through to start up again
687 (set another_trap to 1 to single step once)
688 3) set random_signal to 1, and the decision between 1 and 2
689 will be made according to the signal handling tables. */
690
bd5635a1
RP
691 /* First, distinguish signals caused by the debugger from signals
692 that have to do with the program's own actions.
693 Note that breakpoint insns may cause SIGTRAP or SIGILL
694 or SIGEMT, depending on the operating system version.
695 Here we detect when a SIGILL or SIGEMT is really a breakpoint
696 and change it to SIGTRAP. */
697
67ac9759 698 if (stop_signal == TARGET_SIGNAL_TRAP
bd5635a1 699 || (breakpoints_inserted &&
67ac9759
JK
700 (stop_signal == TARGET_SIGNAL_ILL
701 || stop_signal == TARGET_SIGNAL_EMT
e37a6e9c 702 ))
bd5635a1
RP
703 || stop_soon_quietly)
704 {
67ac9759 705 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
bd5635a1
RP
706 {
707 stop_print_frame = 0;
708 break;
709 }
710 if (stop_soon_quietly)
711 break;
712
713 /* Don't even think about breakpoints
714 if just proceeded over a breakpoint.
715
716 However, if we are trying to proceed over a breakpoint
bcc37718 717 and end up in sigtramp, then through_sigtramp_breakpoint
bd5635a1
RP
718 will be set and we should check whether we've hit the
719 step breakpoint. */
67ac9759 720 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
bcc37718 721 && through_sigtramp_breakpoint == NULL)
bd5635a1
RP
722 bpstat_clear (&stop_bpstat);
723 else
724 {
725 /* See if there is a breakpoint at the current PC. */
cb6b0202
JK
726 stop_bpstat = bpstat_stop_status
727 (&stop_pc, stop_frame_address,
bd5635a1 728#if DECR_PC_AFTER_BREAK
cb6b0202
JK
729 /* Notice the case of stepping through a jump
730 that lands just after a breakpoint.
731 Don't confuse that with hitting the breakpoint.
732 What we check for is that 1) stepping is going on
733 and 2) the pc before the last insn does not match
734 the address of the breakpoint before the current pc. */
735 (prev_pc != stop_pc - DECR_PC_AFTER_BREAK
736 && CURRENTLY_STEPPING ())
737#else /* DECR_PC_AFTER_BREAK zero */
738 0
739#endif /* DECR_PC_AFTER_BREAK zero */
740 );
741 /* Following in case break condition called a
742 function. */
743 stop_print_frame = 1;
bd5635a1 744 }
fe675038 745
67ac9759 746 if (stop_signal == TARGET_SIGNAL_TRAP)
bd5635a1
RP
747 random_signal
748 = !(bpstat_explains_signal (stop_bpstat)
749 || trap_expected
84d59861 750#ifndef CALL_DUMMY_BREAKPOINT_OFFSET
bd5635a1 751 || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
84d59861 752#endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
fe675038 753 || (step_range_end && step_resume_breakpoint == NULL));
bd5635a1
RP
754 else
755 {
756 random_signal
757 = !(bpstat_explains_signal (stop_bpstat)
bd5635a1
RP
758 /* End of a stack dummy. Some systems (e.g. Sony
759 news) give another signal besides SIGTRAP,
760 so check here as well as above. */
84d59861 761#ifndef CALL_DUMMY_BREAKPOINT_OFFSET
d747e0af 762 || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
84d59861 763#endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
bd5635a1
RP
764 );
765 if (!random_signal)
67ac9759 766 stop_signal = TARGET_SIGNAL_TRAP;
bd5635a1
RP
767 }
768 }
769 else
770 random_signal = 1;
fe675038 771
bd5635a1
RP
772 /* For the program's own signals, act according to
773 the signal handling tables. */
fe675038 774
bd5635a1
RP
775 if (random_signal)
776 {
777 /* Signal not for debugging purposes. */
778 int printed = 0;
779
780 stopped_by_random_signal = 1;
781
67ac9759 782 if (signal_print[stop_signal])
bd5635a1 783 {
fee44494 784 char *signame;
bd5635a1
RP
785 printed = 1;
786 target_terminal_ours_for_output ();
67ac9759
JK
787 printf_filtered ("\nProgram received signal %s, %s.\n",
788 target_signal_to_name (stop_signal),
789 target_signal_to_string (stop_signal));
199b2450 790 gdb_flush (gdb_stdout);
bd5635a1 791 }
67ac9759 792 if (signal_stop[stop_signal])
bd5635a1
RP
793 break;
794 /* If not going to stop, give terminal back
795 if we took it away. */
796 else if (printed)
797 target_terminal_inferior ();
b7f81b57 798
101b7f9c
PS
799 /* Clear the signal if it should not be passed. */
800 if (signal_program[stop_signal] == 0)
67ac9759 801 stop_signal = TARGET_SIGNAL_0;
101b7f9c 802
fe675038
JK
803 /* I'm not sure whether this needs to be check_sigtramp2 or
804 whether it could/should be keep_going. */
805 goto check_sigtramp2;
bd5635a1 806 }
30875e1c 807
bd5635a1 808 /* Handle cases caused by hitting a breakpoint. */
fe675038
JK
809 {
810 CORE_ADDR jmp_buf_pc;
29c6dce2
JK
811 struct bpstat_what what;
812
813 what = bpstat_what (stop_bpstat);
bd5635a1 814
84d59861
JK
815 if (what.call_dummy)
816 {
817 stop_stack_dummy = 1;
818#ifdef HP_OS_BUG
819 trap_expected_after_continue = 1;
820#endif
821 }
822
fe675038
JK
823 switch (what.main_action)
824 {
825 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
826 /* If we hit the breakpoint at longjmp, disable it for the
827 duration of this command. Then, install a temporary
828 breakpoint at the target of the jmp_buf. */
829 disable_longjmp_breakpoint();
830 remove_breakpoints ();
831 breakpoints_inserted = 0;
832 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
833
834 /* Need to blow away step-resume breakpoint, as it
835 interferes with us */
836 if (step_resume_breakpoint != NULL)
837 {
838 delete_breakpoint (step_resume_breakpoint);
839 step_resume_breakpoint = NULL;
bcc37718
JK
840 }
841 /* Not sure whether we need to blow this away too, but probably
842 it is like the step-resume breakpoint. */
843 if (through_sigtramp_breakpoint != NULL)
844 {
845 delete_breakpoint (through_sigtramp_breakpoint);
846 through_sigtramp_breakpoint = NULL;
fe675038 847 }
30875e1c 848
101b7f9c 849#if 0
fe675038
JK
850 /* FIXME - Need to implement nested temporary breakpoints */
851 if (step_over_calls > 0)
852 set_longjmp_resume_breakpoint(jmp_buf_pc,
853 get_current_frame());
854 else
30875e1c 855#endif /* 0 */
fe675038
JK
856 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
857 handling_longjmp = 1; /* FIXME */
858 goto keep_going;
859
860 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
861 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
862 remove_breakpoints ();
863 breakpoints_inserted = 0;
101b7f9c 864#if 0
fe675038
JK
865 /* FIXME - Need to implement nested temporary breakpoints */
866 if (step_over_calls
867 && (stop_frame_address
868 INNER_THAN step_frame_address))
869 {
870 another_trap = 1;
871 goto keep_going;
872 }
30875e1c 873#endif /* 0 */
fe675038
JK
874 disable_longjmp_breakpoint();
875 handling_longjmp = 0; /* FIXME */
876 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
101b7f9c 877 break;
fe675038
JK
878 /* else fallthrough */
879
880 case BPSTAT_WHAT_SINGLE:
881 if (breakpoints_inserted)
882 remove_breakpoints ();
883 breakpoints_inserted = 0;
884 another_trap = 1;
885 /* Still need to check other stuff, at least the case
886 where we are stepping and step out of the right range. */
887 break;
888
889 case BPSTAT_WHAT_STOP_NOISY:
890 stop_print_frame = 1;
bcc37718
JK
891
892 /* We are about to nuke the step_resume_breakpoint and
893 through_sigtramp_breakpoint via the cleanup chain, so
894 no need to worry about it here. */
895
fe675038 896 goto stop_stepping;
101b7f9c 897
fe675038
JK
898 case BPSTAT_WHAT_STOP_SILENT:
899 stop_print_frame = 0;
fe675038 900
bcc37718
JK
901 /* We are about to nuke the step_resume_breakpoint and
902 through_sigtramp_breakpoint via the cleanup chain, so
903 no need to worry about it here. */
100f92e2 904
bcc37718 905 goto stop_stepping;
fe675038 906
bcc37718 907 case BPSTAT_WHAT_STEP_RESUME:
fe675038
JK
908 delete_breakpoint (step_resume_breakpoint);
909 step_resume_breakpoint = NULL;
bcc37718
JK
910 break;
911
912 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
913 delete_breakpoint (through_sigtramp_breakpoint);
914 through_sigtramp_breakpoint = NULL;
30875e1c 915
fe675038
JK
916 /* If were waiting for a trap, hitting the step_resume_break
917 doesn't count as getting it. */
918 if (trap_expected)
919 another_trap = 1;
bcc37718
JK
920 break;
921
922 case BPSTAT_WHAT_LAST:
923 /* Not a real code, but listed here to shut up gcc -Wall. */
924
925 case BPSTAT_WHAT_KEEP_CHECKING:
926 break;
30875e1c 927 }
fe675038 928 }
30875e1c
SG
929
930 /* We come here if we hit a breakpoint but should not
931 stop for it. Possibly we also were stepping
932 and should stop for that. So fall through and
933 test for stepping. But, if not stepping,
934 do not stop. */
935
84d59861
JK
936#ifndef CALL_DUMMY_BREAKPOINT_OFFSET
937 /* This is the old way of detecting the end of the stack dummy.
938 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
939 handled above. As soon as we can test it on all of them, all
940 architectures should define it. */
941
bd5635a1 942 /* If this is the breakpoint at the end of a stack dummy,
c9de302b
SG
943 just stop silently, unless the user was doing an si/ni, in which
944 case she'd better know what she's doing. */
945
946 if (PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)
947 && !step_range_end)
948 {
949 stop_print_frame = 0;
950 stop_stack_dummy = 1;
bd5635a1 951#ifdef HP_OS_BUG
c9de302b 952 trap_expected_after_continue = 1;
bd5635a1 953#endif
c9de302b
SG
954 break;
955 }
84d59861
JK
956#endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
957
fe675038 958 if (step_resume_breakpoint)
bd5635a1
RP
959 /* Having a step-resume breakpoint overrides anything
960 else having to do with stepping commands until
961 that breakpoint is reached. */
bcc37718
JK
962 /* I'm not sure whether this needs to be check_sigtramp2 or
963 whether it could/should be keep_going. */
fe675038
JK
964 goto check_sigtramp2;
965
966 if (step_range_end == 0)
967 /* Likewise if we aren't even stepping. */
968 /* I'm not sure whether this needs to be check_sigtramp2 or
969 whether it could/should be keep_going. */
970 goto check_sigtramp2;
971
bd5635a1 972 /* If stepping through a line, keep going if still within it. */
fe675038
JK
973 if (stop_pc >= step_range_start
974 && stop_pc < step_range_end
975 /* The step range might include the start of the
976 function, so if we are at the start of the
977 step range and either the stack or frame pointers
978 just changed, we've stepped outside */
979 && !(stop_pc == step_range_start
980 && stop_frame_address
981 && (stop_sp INNER_THAN prev_sp
982 || stop_frame_address != step_frame_address)))
bd5635a1 983 {
fe675038
JK
984 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
985 So definately need to check for sigtramp here. */
986 goto check_sigtramp2;
bd5635a1 987 }
fe675038 988
bd5635a1
RP
989 /* We stepped out of the stepping range. See if that was due
990 to a subroutine call that we should proceed to the end of. */
fe675038
JK
991
992 /* Did we just take a signal? */
993 if (IN_SIGTRAMP (stop_pc, stop_func_name)
994 && !IN_SIGTRAMP (prev_pc, prev_func_name))
bd5635a1 995 {
bcc37718
JK
996 /* We've just taken a signal; go until we are back to
997 the point where we took it and one more. */
998
fe675038
JK
999 /* This code is needed at least in the following case:
1000 The user types "next" and then a signal arrives (before
1001 the "next" is done). */
bcc37718
JK
1002
1003 /* Note that if we are stopped at a breakpoint, then we need
1004 the step_resume breakpoint to override any breakpoints at
1005 the same location, so that we will still step over the
1006 breakpoint even though the signal happened. */
1007
fe675038
JK
1008 {
1009 struct symtab_and_line sr_sal;
1010
1011 sr_sal.pc = prev_pc;
1012 sr_sal.symtab = NULL;
1013 sr_sal.line = 0;
d1c0c6cf
JK
1014 /* We could probably be setting the frame to
1015 prev_frame_address; the reason we don't is that it didn't used
1016 to exist. */
fe675038 1017 step_resume_breakpoint =
bcc37718 1018 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
fe675038
JK
1019 if (breakpoints_inserted)
1020 insert_breakpoints ();
1021 }
bd5635a1 1022
fe675038
JK
1023 /* If this is stepi or nexti, make sure that the stepping range
1024 gets us past that instruction. */
1025 if (step_range_end == 1)
1026 /* FIXME: Does this run afoul of the code below which, if
1027 we step into the middle of a line, resets the stepping
1028 range? */
1029 step_range_end = (step_range_start = prev_pc) + 1;
101b7f9c 1030
fe675038
JK
1031 remove_breakpoints_on_following_step = 1;
1032 goto keep_going;
1033 }
30875e1c 1034
fe675038
JK
1035 if (stop_func_start)
1036 {
1037 /* Do this after the IN_SIGTRAMP check; it might give
1038 an error. */
1039 prologue_pc = stop_func_start;
1040 SKIP_PROLOGUE (prologue_pc);
1041 }
30875e1c 1042
c0c14c1e
JK
1043 if ((/* Might be a non-recursive call. If the symbols are missing
1044 enough that stop_func_start == prev_func_start even though
1045 they are really two functions, we will treat some calls as
1046 jumps. */
1047 stop_func_start != prev_func_start
1048
1049 /* Might be a recursive call if either we have a prologue
1050 or the call instruction itself saves the PC on the stack. */
1051 || prologue_pc != stop_func_start
1052 || stop_sp != prev_sp)
199b2450
TL
1053 && (/* PC is completely out of bounds of any known objfiles. Treat
1054 like a subroutine call. */
1055 ! stop_func_start
c0c14c1e 1056
f1619234 1057 /* If we do a call, we will be at the start of a function... */
c0c14c1e 1058 || stop_pc == stop_func_start
f1619234
JK
1059
1060 /* ...except on the Alpha with -O (and also Irix 5 and
1061 perhaps others), in which we might call the address
1062 after the load of gp. Since prologues don't contain
1063 calls, we can't return to within one, and we don't
1064 jump back into them, so this check is OK. */
c0c14c1e 1065
c0c14c1e 1066 || stop_pc < prologue_pc
d747e0af 1067
c0c14c1e
JK
1068 /* If we end up in certain places, it means we did a subroutine
1069 call. I'm not completely sure this is necessary now that we
1070 have the above checks with stop_func_start (and now that
100f92e2 1071 find_pc_partial_function is pickier). */
c0c14c1e
JK
1072 || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name)
1073
1074 /* If none of the above apply, it is a jump within a function,
1075 or a return from a subroutine. The other case is longjmp,
1076 which can no longer happen here as long as the
1077 handling_longjmp stuff is working. */
1078 ))
fe675038
JK
1079 {
1080 /* It's a subroutine call. */
fee44494 1081
fe675038
JK
1082 if (step_over_calls == 0)
1083 {
1084 /* I presume that step_over_calls is only 0 when we're
1085 supposed to be stepping at the assembly language level
1086 ("stepi"). Just stop. */
1087 stop_step = 1;
1088 break;
1089 }
fee44494 1090
fe675038
JK
1091 if (step_over_calls > 0)
1092 /* We're doing a "next". */
1093 goto step_over_function;
1094
1095 /* If we are in a function call trampoline (a stub between
1096 the calling routine and the real function), locate the real
1097 function. That's what tells us (a) whether we want to step
1098 into it at all, and (b) what prologue we want to run to
1099 the end of, if we do step into it. */
1100 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1101 if (tmp != 0)
1102 stop_func_start = tmp;
1103
1104 /* If we have line number information for the function we
1105 are thinking of stepping into, step into it.
1106
1107 If there are several symtabs at that PC (e.g. with include
1108 files), just want to know whether *any* of them have line
1109 numbers. find_pc_line handles this. */
1110 {
1111 struct symtab_and_line tmp_sal;
1112
1113 tmp_sal = find_pc_line (stop_func_start, 0);
1114 if (tmp_sal.line != 0)
1115 goto step_into_function;
1116 }
d747e0af
MT
1117
1118step_over_function:
fe675038
JK
1119 /* A subroutine call has happened. */
1120 {
1121 /* Set a special breakpoint after the return */
1122 struct symtab_and_line sr_sal;
1123 sr_sal.pc =
1124 ADDR_BITS_REMOVE
1125 (SAVED_PC_AFTER_CALL (get_current_frame ()));
1126 sr_sal.symtab = NULL;
1127 sr_sal.line = 0;
1128 step_resume_breakpoint =
1129 set_momentary_breakpoint (sr_sal, get_current_frame (),
1130 bp_step_resume);
bcc37718 1131 step_resume_breakpoint->frame = prev_frame_address;
fe675038
JK
1132 if (breakpoints_inserted)
1133 insert_breakpoints ();
1134 }
1135 goto keep_going;
d747e0af
MT
1136
1137step_into_function:
fe675038
JK
1138 /* Subroutine call with source code we should not step over.
1139 Do step to the first line of code in it. */
1140 SKIP_PROLOGUE (stop_func_start);
1141 sal = find_pc_line (stop_func_start, 0);
1142 /* Use the step_resume_break to step until
1143 the end of the prologue, even if that involves jumps
1144 (as it seems to on the vax under 4.2). */
1145 /* If the prologue ends in the middle of a source line,
67ac9759
JK
1146 continue to the end of that source line (if it is still
1147 within the function). Otherwise, just go to end of prologue. */
bd5635a1 1148#ifdef PROLOGUE_FIRSTLINE_OVERLAP
fe675038
JK
1149 /* no, don't either. It skips any code that's
1150 legitimately on the first line. */
bd5635a1 1151#else
67ac9759 1152 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
fe675038 1153 stop_func_start = sal.end;
bd5635a1 1154#endif
d747e0af 1155
fe675038
JK
1156 if (stop_func_start == stop_pc)
1157 {
1158 /* We are already there: stop now. */
1159 stop_step = 1;
1160 break;
1161 }
1162 else
1163 /* Put the step-breakpoint there and go until there. */
1164 {
1165 struct symtab_and_line sr_sal;
1166
1167 sr_sal.pc = stop_func_start;
1168 sr_sal.symtab = NULL;
1169 sr_sal.line = 0;
1170 /* Do not specify what the fp should be when we stop
1171 since on some machines the prologue
1172 is where the new fp value is established. */
1173 step_resume_breakpoint =
84d59861 1174 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
fe675038
JK
1175 if (breakpoints_inserted)
1176 insert_breakpoints ();
1177
1178 /* And make sure stepping stops right away then. */
1179 step_range_end = step_range_start;
bd5635a1 1180 }
fe675038
JK
1181 goto keep_going;
1182 }
d747e0af 1183
b2f03c30 1184 /* We've wandered out of the step range. */
d747e0af 1185
fe675038
JK
1186 sal = find_pc_line(stop_pc, 0);
1187
1188 if (step_range_end == 1)
1189 {
1190 /* It is stepi or nexti. We always want to stop stepping after
1191 one instruction. */
1192 stop_step = 1;
1193 break;
1194 }
1195
1196 if (sal.line == 0)
1197 {
1198 /* We have no line number information. That means to stop
1199 stepping (does this always happen right after one instruction,
1200 when we do "s" in a function with no line numbers,
1201 or can this happen as a result of a return or longjmp?). */
1202 stop_step = 1;
1203 break;
1204 }
1205
b2f03c30
JK
1206 if (stop_pc == sal.pc
1207 && (current_line != sal.line || current_symtab != sal.symtab))
fe675038
JK
1208 {
1209 /* We are at the start of a different line. So stop. Note that
1210 we don't stop if we step into the middle of a different line.
1211 That is said to make things like for (;;) statements work
1212 better. */
1213 stop_step = 1;
1214 break;
bd5635a1
RP
1215 }
1216
fe675038
JK
1217 /* We aren't done stepping.
1218
1219 Optimize by setting the stepping range to the line.
1220 (We might not be in the original line, but if we entered a
1221 new line in mid-statement, we continue stepping. This makes
1222 things like for(;;) statements work better.) */
67ac9759
JK
1223
1224 if (stop_func_end && sal.end >= stop_func_end)
1225 {
1226 /* If this is the last line of the function, don't keep stepping
1227 (it would probably step us out of the function).
1228 This is particularly necessary for a one-line function,
1229 in which after skipping the prologue we better stop even though
1230 we will be in mid-line. */
1231 stop_step = 1;
1232 break;
1233 }
fe675038
JK
1234 step_range_start = sal.pc;
1235 step_range_end = sal.end;
1236 goto keep_going;
1237
1238 check_sigtramp2:
d747e0af
MT
1239 if (trap_expected
1240 && IN_SIGTRAMP (stop_pc, stop_func_name)
1241 && !IN_SIGTRAMP (prev_pc, prev_func_name))
bd5635a1
RP
1242 {
1243 /* What has happened here is that we have just stepped the inferior
1244 with a signal (because it is a signal which shouldn't make
1245 us stop), thus stepping into sigtramp.
1246
1247 So we need to set a step_resume_break_address breakpoint
fe675038
JK
1248 and continue until we hit it, and then step. FIXME: This should
1249 be more enduring than a step_resume breakpoint; we should know
1250 that we will later need to keep going rather than re-hitting
1251 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1252 it says "exceedingly difficult"). */
1253 struct symtab_and_line sr_sal;
1254
1255 sr_sal.pc = prev_pc;
1256 sr_sal.symtab = NULL;
1257 sr_sal.line = 0;
bcc37718
JK
1258 /* We perhaps could set the frame if we kept track of what
1259 the frame corresponding to prev_pc was. But we don't,
1260 so don't. */
1261 through_sigtramp_breakpoint =
1262 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
bd5635a1 1263 if (breakpoints_inserted)
fe675038
JK
1264 insert_breakpoints ();
1265
bd5635a1
RP
1266 remove_breakpoints_on_following_step = 1;
1267 another_trap = 1;
1268 }
1269
30875e1c 1270 keep_going:
fe675038
JK
1271 /* Come to this label when you need to resume the inferior.
1272 It's really much cleaner to do a goto than a maze of if-else
1273 conditions. */
30875e1c 1274
bd5635a1
RP
1275 /* Save the pc before execution, to compare with pc after stop. */
1276 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1277 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1278 BREAK is defined, the
1279 original pc would not have
1280 been at the start of a
1281 function. */
1282 prev_func_name = stop_func_name;
1283 prev_sp = stop_sp;
bcc37718 1284 prev_frame_address = stop_frame_address;
bd5635a1
RP
1285
1286 /* If we did not do break;, it means we should keep
1287 running the inferior and not return to debugger. */
1288
67ac9759 1289 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
bd5635a1
RP
1290 {
1291 /* We took a signal (which we are supposed to pass through to
1292 the inferior, else we'd have done a break above) and we
1293 haven't yet gotten our trap. Simply continue. */
cb6b0202 1294 resume (CURRENTLY_STEPPING (), stop_signal);
bd5635a1
RP
1295 }
1296 else
1297 {
1298 /* Either the trap was not expected, but we are continuing
1299 anyway (the user asked that this signal be passed to the
1300 child)
1301 -- or --
1302 The signal was SIGTRAP, e.g. it was our signal, but we
1303 decided we should resume from it.
1304
1305 We're going to run this baby now!
1306
1307 Insert breakpoints now, unless we are trying
1308 to one-proceed past a breakpoint. */
1309 /* If we've just finished a special step resume and we don't
1310 want to hit a breakpoint, pull em out. */
d1c0c6cf
JK
1311 if (step_resume_breakpoint == NULL
1312 && through_sigtramp_breakpoint == NULL
1313 && remove_breakpoints_on_following_step)
bd5635a1
RP
1314 {
1315 remove_breakpoints_on_following_step = 0;
1316 remove_breakpoints ();
1317 breakpoints_inserted = 0;
1318 }
1319 else if (!breakpoints_inserted &&
bcc37718 1320 (through_sigtramp_breakpoint != NULL || !another_trap))
bd5635a1 1321 {
bd5635a1
RP
1322 breakpoints_failed = insert_breakpoints ();
1323 if (breakpoints_failed)
1324 break;
1325 breakpoints_inserted = 1;
1326 }
1327
1328 trap_expected = another_trap;
1329
67ac9759
JK
1330 if (stop_signal == TARGET_SIGNAL_TRAP)
1331 stop_signal = TARGET_SIGNAL_0;
bd5635a1
RP
1332
1333#ifdef SHIFT_INST_REGS
1334 /* I'm not sure when this following segment applies. I do know, now,
1335 that we shouldn't rewrite the regs when we were stopped by a
1336 random signal from the inferior process. */
cef4c2e7
PS
1337 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1338 (this is only used on the 88k). */
bd5635a1 1339
d11c44f1 1340 if (!bpstat_explains_signal (stop_bpstat)
67ac9759 1341 && (stop_signal != TARGET_SIGNAL_CHLD)
bd5635a1 1342 && !stopped_by_random_signal)
07a5991a 1343 SHIFT_INST_REGS();
bd5635a1
RP
1344#endif /* SHIFT_INST_REGS */
1345
cb6b0202 1346 resume (CURRENTLY_STEPPING (), stop_signal);
bd5635a1
RP
1347 }
1348 }
30875e1c
SG
1349
1350 stop_stepping:
bd5635a1
RP
1351 if (target_has_execution)
1352 {
1353 /* Assuming the inferior still exists, set these up for next
1354 time, just like we did above if we didn't break out of the
1355 loop. */
1356 prev_pc = read_pc ();
1357 prev_func_start = stop_func_start;
1358 prev_func_name = stop_func_name;
1359 prev_sp = stop_sp;
bcc37718 1360 prev_frame_address = stop_frame_address;
bd5635a1 1361 }
fe675038 1362 do_cleanups (old_cleanups);
bd5635a1
RP
1363}
1364\f
1365/* Here to return control to GDB when the inferior stops for real.
1366 Print appropriate messages, remove breakpoints, give terminal our modes.
1367
1368 STOP_PRINT_FRAME nonzero means print the executing frame
1369 (pc, function, args, file, line number and line text).
1370 BREAKPOINTS_FAILED nonzero means stop was due to error
1371 attempting to insert breakpoints. */
1372
1373void
1374normal_stop ()
1375{
1376 /* Make sure that the current_frame's pc is correct. This
1377 is a correction for setting up the frame info before doing
1378 DECR_PC_AFTER_BREAK */
3f0184ac 1379 if (target_has_execution && get_current_frame())
bd5635a1
RP
1380 (get_current_frame ())->pc = read_pc ();
1381
1382 if (breakpoints_failed)
1383 {
1384 target_terminal_ours_for_output ();
1385 print_sys_errmsg ("ptrace", breakpoints_failed);
e37a6e9c 1386 printf_filtered ("Stopped; cannot insert breakpoints.\n\
bd5635a1
RP
1387The same program may be running in another process.\n");
1388 }
1389
bd5635a1
RP
1390 if (target_has_execution && breakpoints_inserted)
1391 if (remove_breakpoints ())
1392 {
1393 target_terminal_ours_for_output ();
e37a6e9c 1394 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
bd5635a1
RP
1395It might be running in another process.\n\
1396Further execution is probably impossible.\n");
1397 }
1398
1399 breakpoints_inserted = 0;
1400
1401 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1402 Delete any breakpoint that is to be deleted at the next stop. */
1403
1404 breakpoint_auto_delete (stop_bpstat);
1405
1406 /* If an auto-display called a function and that got a signal,
1407 delete that auto-display to avoid an infinite recursion. */
1408
1409 if (stopped_by_random_signal)
1410 disable_current_display ();
1411
1412 if (step_multi && stop_step)
1413 return;
1414
1415 target_terminal_ours ();
1416
3950a34e
RP
1417 /* Look up the hook_stop and run it if it exists. */
1418
1419 if (stop_command->hook)
1420 {
1421 catch_errors (hook_stop_stub, (char *)stop_command->hook,
fee44494 1422 "Error while running hook_stop:\n", RETURN_MASK_ALL);
3950a34e
RP
1423 }
1424
bd5635a1
RP
1425 if (!target_has_stack)
1426 return;
1427
1428 /* Select innermost stack frame except on return from a stack dummy routine,
1515ff18
JG
1429 or if the program has exited. Print it without a level number if
1430 we have changed functions or hit a breakpoint. Print source line
1431 if we have one. */
bd5635a1
RP
1432 if (!stop_stack_dummy)
1433 {
bd5635a1
RP
1434 if (stop_print_frame)
1435 {
1515ff18
JG
1436 int source_only;
1437
1438 source_only = bpstat_print (stop_bpstat);
1439 source_only = source_only ||
1440 ( stop_step
bd5635a1 1441 && step_frame_address == stop_frame_address
1515ff18
JG
1442 && step_start_function == find_pc_function (stop_pc));
1443
1444 print_stack_frame (selected_frame, -1, source_only? -1: 1);
bd5635a1
RP
1445
1446 /* Display the auto-display expressions. */
1447 do_displays ();
1448 }
1449 }
1450
1451 /* Save the function value return registers, if we care.
1452 We might be about to restore their previous contents. */
1453 if (proceed_to_finish)
1454 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1455
1456 if (stop_stack_dummy)
1457 {
1458 /* Pop the empty frame that contains the stack dummy.
1459 POP_FRAME ends with a setting of the current frame, so we
1460 can use that next. */
1461 POP_FRAME;
f1de67d3
PS
1462 /* Set stop_pc to what it was before we called the function. Can't rely
1463 on restore_inferior_status because that only gets called if we don't
1464 stop in the called function. */
1465 stop_pc = read_pc();
bd5635a1
RP
1466 select_frame (get_current_frame (), 0);
1467 }
1468}
3950a34e
RP
1469
1470static int
1471hook_stop_stub (cmd)
1472 char *cmd;
1473{
1474 execute_user_command ((struct cmd_list_element *)cmd, 0);
a8a69e63 1475 return (0);
3950a34e 1476}
bd5635a1 1477\f
cc221e76
FF
1478int signal_stop_state (signo)
1479 int signo;
1480{
67ac9759 1481 return signal_stop[signo];
cc221e76
FF
1482}
1483
1484int signal_print_state (signo)
1485 int signo;
1486{
67ac9759 1487 return signal_print[signo];
cc221e76
FF
1488}
1489
1490int signal_pass_state (signo)
1491 int signo;
1492{
67ac9759 1493 return signal_program[signo];
cc221e76
FF
1494}
1495
bd5635a1
RP
1496static void
1497sig_print_header ()
1498{
67ac9759
JK
1499 printf_filtered ("\
1500Signal Stop\tPrint\tPass to program\tDescription\n");
bd5635a1
RP
1501}
1502
1503static void
67ac9759
JK
1504sig_print_info (oursig)
1505 enum target_signal oursig;
bd5635a1 1506{
67ac9759
JK
1507 char *name = target_signal_to_name (oursig);
1508 printf_filtered ("%s", name);
1509 printf_filtered ("%*.*s ", 13 - strlen (name), 13 - strlen (name),
1510 " ");
1511 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
1512 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
1513 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
1514 printf_filtered ("%s\n", target_signal_to_string (oursig));
bd5635a1
RP
1515}
1516
1517/* Specify how various signals in the inferior should be handled. */
1518
1519static void
1520handle_command (args, from_tty)
1521 char *args;
1522 int from_tty;
1523{
072b552a
JG
1524 char **argv;
1525 int digits, wordlen;
1526 int sigfirst, signum, siglast;
67ac9759 1527 enum target_signal oursig;
072b552a
JG
1528 int allsigs;
1529 int nsigs;
1530 unsigned char *sigs;
1531 struct cleanup *old_chain;
1532
1533 if (args == NULL)
1534 {
1535 error_no_arg ("signal to handle");
1536 }
bd5635a1 1537
072b552a
JG
1538 /* Allocate and zero an array of flags for which signals to handle. */
1539
67ac9759 1540 nsigs = (int)TARGET_SIGNAL_LAST;
072b552a
JG
1541 sigs = (unsigned char *) alloca (nsigs);
1542 memset (sigs, 0, nsigs);
bd5635a1 1543
072b552a
JG
1544 /* Break the command line up into args. */
1545
1546 argv = buildargv (args);
1547 if (argv == NULL)
bd5635a1 1548 {
072b552a
JG
1549 nomem (0);
1550 }
1551 old_chain = make_cleanup (freeargv, (char *) argv);
bd5635a1 1552
67ac9759 1553 /* Walk through the args, looking for signal oursigs, signal names, and
072b552a
JG
1554 actions. Signal numbers and signal names may be interspersed with
1555 actions, with the actions being performed for all signals cumulatively
1556 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
bd5635a1 1557
072b552a
JG
1558 while (*argv != NULL)
1559 {
1560 wordlen = strlen (*argv);
1561 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1562 allsigs = 0;
1563 sigfirst = siglast = -1;
1564
1565 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1566 {
1567 /* Apply action to all signals except those used by the
1568 debugger. Silently skip those. */
1569 allsigs = 1;
1570 sigfirst = 0;
1571 siglast = nsigs - 1;
1572 }
1573 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1574 {
1575 SET_SIGS (nsigs, sigs, signal_stop);
1576 SET_SIGS (nsigs, sigs, signal_print);
1577 }
1578 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1579 {
1580 UNSET_SIGS (nsigs, sigs, signal_program);
1581 }
1582 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1583 {
1584 SET_SIGS (nsigs, sigs, signal_print);
1585 }
1586 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1587 {
1588 SET_SIGS (nsigs, sigs, signal_program);
1589 }
1590 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1591 {
1592 UNSET_SIGS (nsigs, sigs, signal_stop);
1593 }
1594 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1595 {
1596 SET_SIGS (nsigs, sigs, signal_program);
1597 }
1598 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1599 {
1600 UNSET_SIGS (nsigs, sigs, signal_print);
1601 UNSET_SIGS (nsigs, sigs, signal_stop);
1602 }
1603 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1604 {
1605 UNSET_SIGS (nsigs, sigs, signal_program);
1606 }
1607 else if (digits > 0)
bd5635a1 1608 {
67ac9759
JK
1609 /* It is numeric. The numeric signal refers to our own internal
1610 signal numbering from target.h, not to host/target signal number.
1611 This is a feature; users really should be using symbolic names
1612 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1613 will work right anyway. */
1614
072b552a
JG
1615 sigfirst = siglast = atoi (*argv);
1616 if ((*argv)[digits] == '-')
bd5635a1 1617 {
072b552a 1618 siglast = atoi ((*argv) + digits + 1);
bd5635a1 1619 }
072b552a 1620 if (sigfirst > siglast)
bd5635a1 1621 {
072b552a
JG
1622 /* Bet he didn't figure we'd think of this case... */
1623 signum = sigfirst;
1624 sigfirst = siglast;
1625 siglast = signum;
bd5635a1 1626 }
072b552a
JG
1627 if (sigfirst < 0 || sigfirst >= nsigs)
1628 {
1629 error ("Signal %d not in range 0-%d", sigfirst, nsigs - 1);
1630 }
1631 if (siglast < 0 || siglast >= nsigs)
bd5635a1 1632 {
072b552a 1633 error ("Signal %d not in range 0-%d", siglast, nsigs - 1);
bd5635a1
RP
1634 }
1635 }
072b552a 1636 else
bd5635a1 1637 {
fcbc95a7
JK
1638 oursig = target_signal_from_name (*argv);
1639 if (oursig != TARGET_SIGNAL_UNKNOWN)
1640 {
1641 sigfirst = siglast = (int)oursig;
1642 }
1643 else
1644 {
1645 /* Not a number and not a recognized flag word => complain. */
1646 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
1647 }
bd5635a1 1648 }
072b552a
JG
1649
1650 /* If any signal numbers or symbol names were found, set flags for
1651 which signals to apply actions to. */
1652
1653 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
bd5635a1 1654 {
67ac9759 1655 switch ((enum target_signal)signum)
072b552a 1656 {
67ac9759
JK
1657 case TARGET_SIGNAL_TRAP:
1658 case TARGET_SIGNAL_INT:
072b552a
JG
1659 if (!allsigs && !sigs[signum])
1660 {
67ac9759
JK
1661 if (query ("%s is used by the debugger.\n\
1662Are you sure you want to change it? ",
1663 target_signal_to_name
1664 ((enum target_signal)signum)))
072b552a
JG
1665 {
1666 sigs[signum] = 1;
1667 }
1668 else
1669 {
199b2450
TL
1670 printf_unfiltered ("Not confirmed, unchanged.\n");
1671 gdb_flush (gdb_stdout);
072b552a
JG
1672 }
1673 }
1674 break;
1675 default:
1676 sigs[signum] = 1;
1677 break;
1678 }
bd5635a1
RP
1679 }
1680
072b552a 1681 argv++;
bd5635a1
RP
1682 }
1683
de43d7d0 1684 target_notice_signals(inferior_pid);
cc221e76 1685
bd5635a1
RP
1686 if (from_tty)
1687 {
1688 /* Show the results. */
1689 sig_print_header ();
072b552a
JG
1690 for (signum = 0; signum < nsigs; signum++)
1691 {
1692 if (sigs[signum])
1693 {
1694 sig_print_info (signum);
1695 }
1696 }
bd5635a1 1697 }
072b552a
JG
1698
1699 do_cleanups (old_chain);
bd5635a1
RP
1700}
1701
67ac9759
JK
1702/* Print current contents of the tables set by the handle command.
1703 It is possible we should just be printing signals actually used
1704 by the current target (but for things to work right when switching
1705 targets, all signals should be in the signal tables). */
bd5635a1
RP
1706
1707static void
e37a6e9c 1708signals_info (signum_exp, from_tty)
bd5635a1 1709 char *signum_exp;
e37a6e9c 1710 int from_tty;
bd5635a1 1711{
67ac9759 1712 enum target_signal oursig;
bd5635a1
RP
1713 sig_print_header ();
1714
1715 if (signum_exp)
1716 {
1717 /* First see if this is a symbol name. */
67ac9759
JK
1718 oursig = target_signal_from_name (signum_exp);
1719 if (oursig == TARGET_SIGNAL_UNKNOWN)
bd5635a1
RP
1720 {
1721 /* Nope, maybe it's an address which evaluates to a signal
1722 number. */
67ac9759
JK
1723 /* The numeric signal refers to our own internal
1724 signal numbering from target.h, not to host/target signal number.
1725 This is a feature; users really should be using symbolic names
1726 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1727 will work right anyway. */
1728 int i = parse_and_eval_address (signum_exp);
1729 if (i >= (int)TARGET_SIGNAL_LAST
1730 || i < 0
fcbc95a7
JK
1731 || i == (int)TARGET_SIGNAL_UNKNOWN
1732 || i == (int)TARGET_SIGNAL_DEFAULT)
bd5635a1 1733 error ("Signal number out of bounds.");
67ac9759 1734 oursig = (enum target_signal)i;
bd5635a1 1735 }
67ac9759 1736 sig_print_info (oursig);
bd5635a1
RP
1737 return;
1738 }
1739
1740 printf_filtered ("\n");
db4340a6 1741 /* These ugly casts brought to you by the native VAX compiler. */
2fe3b329 1742 for (oursig = TARGET_SIGNAL_FIRST;
db4340a6
JK
1743 (int)oursig < (int)TARGET_SIGNAL_LAST;
1744 oursig = (enum target_signal)((int)oursig + 1))
bd5635a1
RP
1745 {
1746 QUIT;
1747
fcbc95a7
JK
1748 if (oursig != TARGET_SIGNAL_UNKNOWN
1749 && oursig != TARGET_SIGNAL_DEFAULT
1750 && oursig != TARGET_SIGNAL_0)
67ac9759 1751 sig_print_info (oursig);
bd5635a1
RP
1752 }
1753
1754 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
1755}
1756\f
1757/* Save all of the information associated with the inferior<==>gdb
1758 connection. INF_STATUS is a pointer to a "struct inferior_status"
1759 (defined in inferior.h). */
1760
1761void
1762save_inferior_status (inf_status, restore_stack_info)
1763 struct inferior_status *inf_status;
1764 int restore_stack_info;
1765{
bd5635a1
RP
1766 inf_status->stop_signal = stop_signal;
1767 inf_status->stop_pc = stop_pc;
1768 inf_status->stop_frame_address = stop_frame_address;
1769 inf_status->stop_step = stop_step;
1770 inf_status->stop_stack_dummy = stop_stack_dummy;
1771 inf_status->stopped_by_random_signal = stopped_by_random_signal;
1772 inf_status->trap_expected = trap_expected;
1773 inf_status->step_range_start = step_range_start;
1774 inf_status->step_range_end = step_range_end;
1775 inf_status->step_frame_address = step_frame_address;
1776 inf_status->step_over_calls = step_over_calls;
bd5635a1
RP
1777 inf_status->stop_after_trap = stop_after_trap;
1778 inf_status->stop_soon_quietly = stop_soon_quietly;
1779 /* Save original bpstat chain here; replace it with copy of chain.
1780 If caller's caller is walking the chain, they'll be happier if we
1781 hand them back the original chain when restore_i_s is called. */
1782 inf_status->stop_bpstat = stop_bpstat;
1783 stop_bpstat = bpstat_copy (stop_bpstat);
1784 inf_status->breakpoint_proceeded = breakpoint_proceeded;
1785 inf_status->restore_stack_info = restore_stack_info;
1786 inf_status->proceed_to_finish = proceed_to_finish;
1787
072b552a 1788 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
37c99ddb
JK
1789
1790 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
1791
bd5635a1
RP
1792 record_selected_frame (&(inf_status->selected_frame_address),
1793 &(inf_status->selected_level));
1794 return;
1795}
1796
37c99ddb
JK
1797struct restore_selected_frame_args {
1798 FRAME_ADDR frame_address;
1799 int level;
1800};
1801
1802static int restore_selected_frame PARAMS ((char *));
1803
1804/* Restore the selected frame. args is really a struct
1805 restore_selected_frame_args * (declared as char * for catch_errors)
1806 telling us what frame to restore. Returns 1 for success, or 0 for
1807 failure. An error message will have been printed on error. */
1808static int
1809restore_selected_frame (args)
1810 char *args;
1811{
1812 struct restore_selected_frame_args *fr =
1813 (struct restore_selected_frame_args *) args;
1814 FRAME fid;
1815 int level = fr->level;
1816
1817 fid = find_relative_frame (get_current_frame (), &level);
1818
1819 /* If inf_status->selected_frame_address is NULL, there was no
1820 previously selected frame. */
1821 if (fid == 0 ||
1822 FRAME_FP (fid) != fr->frame_address ||
1823 level != 0)
1824 {
1825 warning ("Unable to restore previously selected frame.\n");
1826 return 0;
1827 }
1828 select_frame (fid, fr->level);
1829 return(1);
1830}
1831
bd5635a1
RP
1832void
1833restore_inferior_status (inf_status)
1834 struct inferior_status *inf_status;
1835{
bd5635a1
RP
1836 stop_signal = inf_status->stop_signal;
1837 stop_pc = inf_status->stop_pc;
1838 stop_frame_address = inf_status->stop_frame_address;
1839 stop_step = inf_status->stop_step;
1840 stop_stack_dummy = inf_status->stop_stack_dummy;
1841 stopped_by_random_signal = inf_status->stopped_by_random_signal;
1842 trap_expected = inf_status->trap_expected;
1843 step_range_start = inf_status->step_range_start;
1844 step_range_end = inf_status->step_range_end;
1845 step_frame_address = inf_status->step_frame_address;
1846 step_over_calls = inf_status->step_over_calls;
bd5635a1
RP
1847 stop_after_trap = inf_status->stop_after_trap;
1848 stop_soon_quietly = inf_status->stop_soon_quietly;
1849 bpstat_clear (&stop_bpstat);
1850 stop_bpstat = inf_status->stop_bpstat;
1851 breakpoint_proceeded = inf_status->breakpoint_proceeded;
1852 proceed_to_finish = inf_status->proceed_to_finish;
1853
072b552a 1854 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
bd5635a1
RP
1855
1856 /* The inferior can be gone if the user types "print exit(0)"
1857 (and perhaps other times). */
37c99ddb
JK
1858 if (target_has_execution)
1859 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
1860
1861 /* The inferior can be gone if the user types "print exit(0)"
1862 (and perhaps other times). */
1863
1864 /* FIXME: If we are being called after stopping in a function which
1865 is called from gdb, we should not be trying to restore the
1866 selected frame; it just prints a spurious error message (The
1867 message is useful, however, in detecting bugs in gdb (like if gdb
1868 clobbers the stack)). In fact, should we be restoring the
1869 inferior status at all in that case? . */
1870
bd5635a1
RP
1871 if (target_has_stack && inf_status->restore_stack_info)
1872 {
37c99ddb
JK
1873 struct restore_selected_frame_args fr;
1874 fr.level = inf_status->selected_level;
1875 fr.frame_address = inf_status->selected_frame_address;
1876 /* The point of catch_errors is that if the stack is clobbered,
1877 walking the stack might encounter a garbage pointer and error()
1878 trying to dereference it. */
1879 if (catch_errors (restore_selected_frame, &fr,
1880 "Unable to restore previously selected frame:\n",
1881 RETURN_MASK_ERROR) == 0)
1882 /* Error in restoring the selected frame. Select the innermost
1883 frame. */
1884 select_frame (get_current_frame (), 0);
bd5635a1
RP
1885 }
1886}
1887
1888\f
1889void
1890_initialize_infrun ()
1891{
1892 register int i;
e37a6e9c 1893 register int numsigs;
bd5635a1
RP
1894
1895 add_info ("signals", signals_info,
1896 "What debugger does when program gets various signals.\n\
1897Specify a signal number as argument to print info on that signal only.");
6b50c5c2 1898 add_info_alias ("handle", "signals", 0);
bd5635a1
RP
1899
1900 add_com ("handle", class_run, handle_command,
1901 "Specify how to handle a signal.\n\
072b552a
JG
1902Args are signal numbers and actions to apply to those signals.\n\
1903Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\
1904Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\
1905The special arg \"all\" is recognized to mean all signals except those\n\
1906used by the debugger, typically SIGTRAP and SIGINT.\n\
1907Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
1908\"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
bd5635a1 1909Stop means reenter debugger if this signal happens (implies print).\n\
072b552a 1910Print means print a message if this signal happens.\n\
bd5635a1 1911Pass means let program see this signal; otherwise program doesn't know.\n\
072b552a 1912Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
bd5635a1
RP
1913Pass and Stop may be combined.");
1914
a8a69e63 1915 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
3950a34e
RP
1916 "There is no `stop' command, but you can set a hook on `stop'.\n\
1917This allows you to set a list of commands to be run each time execution\n\
fee44494 1918of the program stops.", &cmdlist);
3950a34e 1919
67ac9759
JK
1920 numsigs = (int)TARGET_SIGNAL_LAST;
1921 signal_stop = (unsigned char *)
1922 xmalloc (sizeof (signal_stop[0]) * numsigs);
1923 signal_print = (unsigned char *)
1924 xmalloc (sizeof (signal_print[0]) * numsigs);
072b552a 1925 signal_program = (unsigned char *)
67ac9759 1926 xmalloc (sizeof (signal_program[0]) * numsigs);
e37a6e9c 1927 for (i = 0; i < numsigs; i++)
bd5635a1
RP
1928 {
1929 signal_stop[i] = 1;
1930 signal_print[i] = 1;
1931 signal_program[i] = 1;
1932 }
1933
1934 /* Signals caused by debugger's own actions
1935 should not be given to the program afterwards. */
67ac9759
JK
1936 signal_program[TARGET_SIGNAL_TRAP] = 0;
1937 signal_program[TARGET_SIGNAL_INT] = 0;
bd5635a1
RP
1938
1939 /* Signals that are not errors should not normally enter the debugger. */
67ac9759
JK
1940 signal_stop[TARGET_SIGNAL_ALRM] = 0;
1941 signal_print[TARGET_SIGNAL_ALRM] = 0;
1942 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
1943 signal_print[TARGET_SIGNAL_VTALRM] = 0;
1944 signal_stop[TARGET_SIGNAL_PROF] = 0;
1945 signal_print[TARGET_SIGNAL_PROF] = 0;
1946 signal_stop[TARGET_SIGNAL_CHLD] = 0;
1947 signal_print[TARGET_SIGNAL_CHLD] = 0;
1948 signal_stop[TARGET_SIGNAL_IO] = 0;
1949 signal_print[TARGET_SIGNAL_IO] = 0;
4d4f2d50
JK
1950 signal_stop[TARGET_SIGNAL_POLL] = 0;
1951 signal_print[TARGET_SIGNAL_POLL] = 0;
67ac9759
JK
1952 signal_stop[TARGET_SIGNAL_URG] = 0;
1953 signal_print[TARGET_SIGNAL_URG] = 0;
bd5635a1 1954}
This page took 0.272964 seconds and 4 git commands to generate.