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