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