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