This commit was generated by cvs2svn to track changes on a CVS vendor
[deliverable/binutils-gdb.git] / gdb / infrun.c
1 /* Target-struct-independent code to start (run) and stop an inferior process.
2 Copyright 1986, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 1998
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "defs.h"
22 #include "gdb_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 "gdbthread.h"
33 #include "annotate.h"
34 #include "symfile.h" /* for overlay functions */
35
36 #include <signal.h>
37
38 /* Prototypes for local functions */
39
40 static void signals_info PARAMS ((char *, int));
41
42 static void handle_command PARAMS ((char *, int));
43
44 static void sig_print_info PARAMS ((enum target_signal));
45
46 static void sig_print_header PARAMS ((void));
47
48 static void resume_cleanups PARAMS ((int));
49
50 static int hook_stop_stub PARAMS ((char *));
51
52 static void delete_breakpoint_current_contents PARAMS ((PTR));
53
54 void _initialize_infrun PARAMS ((void));
55
56 /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the
57 program. It needs to examine the jmp_buf argument and extract the PC
58 from it. The return value is non-zero on success, zero otherwise. */
59
60 #ifndef GET_LONGJMP_TARGET
61 #define GET_LONGJMP_TARGET(PC_ADDR) 0
62 #endif
63
64
65 /* Some machines have trampoline code that sits between function callers
66 and the actual functions themselves. If this machine doesn't have
67 such things, disable their processing. */
68
69 #ifndef SKIP_TRAMPOLINE_CODE
70 #define SKIP_TRAMPOLINE_CODE(pc) 0
71 #endif
72
73 /* Dynamic function trampolines are similar to solib trampolines in that they
74 are between the caller and the callee. The difference is that when you
75 enter a dynamic trampoline, you can't determine the callee's address. Some
76 (usually complex) code needs to run in the dynamic trampoline to figure out
77 the callee's address. This macro is usually called twice. First, when we
78 enter the trampoline (looks like a normal function call at that point). It
79 should return the PC of a point within the trampoline where the callee's
80 address is known. Second, when we hit the breakpoint, this routine returns
81 the callee's address. At that point, things proceed as per a step resume
82 breakpoint. */
83
84 #ifndef DYNAMIC_TRAMPOLINE_NEXTPC
85 #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0
86 #endif
87
88 /* On SVR4 based systems, determining the callee's address is exceedingly
89 difficult and depends on the implementation of the run time loader.
90 If we are stepping at the source level, we single step until we exit
91 the run time loader code and reach the callee's address. */
92
93 #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE
94 #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0
95 #endif
96
97 /* For SVR4 shared libraries, each call goes through a small piece of
98 trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates
99 to nonzero if we are current stopped in one of these. */
100
101 #ifndef IN_SOLIB_CALL_TRAMPOLINE
102 #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0
103 #endif
104
105 /* In some shared library schemes, the return path from a shared library
106 call may need to go through a trampoline too. */
107
108 #ifndef IN_SOLIB_RETURN_TRAMPOLINE
109 #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0
110 #endif
111
112 /* On MIPS16, a function that returns a floating point value may call
113 a library helper function to copy the return value to a floating point
114 register. The IGNORE_HELPER_CALL macro returns non-zero if we
115 should ignore (i.e. step over) this function call. */
116 #ifndef IGNORE_HELPER_CALL
117 #define IGNORE_HELPER_CALL(pc) 0
118 #endif
119
120 /* On some systems, the PC may be left pointing at an instruction that won't
121 actually be executed. This is usually indicated by a bit in the PSW. If
122 we find ourselves in such a state, then we step the target beyond the
123 nullified instruction before returning control to the user so as to avoid
124 confusion. */
125
126 #ifndef INSTRUCTION_NULLIFIED
127 #define INSTRUCTION_NULLIFIED 0
128 #endif
129
130 /* Tables of how to react to signals; the user sets them. */
131
132 static unsigned char *signal_stop;
133 static unsigned char *signal_print;
134 static unsigned char *signal_program;
135
136 #define SET_SIGS(nsigs,sigs,flags) \
137 do { \
138 int signum = (nsigs); \
139 while (signum-- > 0) \
140 if ((sigs)[signum]) \
141 (flags)[signum] = 1; \
142 } while (0)
143
144 #define UNSET_SIGS(nsigs,sigs,flags) \
145 do { \
146 int signum = (nsigs); \
147 while (signum-- > 0) \
148 if ((sigs)[signum]) \
149 (flags)[signum] = 0; \
150 } while (0)
151
152
153 /* Command list pointer for the "stop" placeholder. */
154
155 static struct cmd_list_element *stop_command;
156
157 /* Nonzero if breakpoints are now inserted in the inferior. */
158
159 static int breakpoints_inserted;
160
161 /* Function inferior was in as of last step command. */
162
163 static struct symbol *step_start_function;
164
165 /* Nonzero if we are expecting a trace trap and should proceed from it. */
166
167 static int trap_expected;
168
169 #ifdef SOLIB_ADD
170 /* Nonzero if we want to give control to the user when we're notified
171 of shared library events by the dynamic linker. */
172 static int stop_on_solib_events;
173 #endif
174
175 #ifdef HP_OS_BUG
176 /* Nonzero if the next time we try to continue the inferior, it will
177 step one instruction and generate a spurious trace trap.
178 This is used to compensate for a bug in HP-UX. */
179
180 static int trap_expected_after_continue;
181 #endif
182
183 /* Nonzero means expecting a trace trap
184 and should stop the inferior and return silently when it happens. */
185
186 int stop_after_trap;
187
188 /* Nonzero means expecting a trap and caller will handle it themselves.
189 It is used after attach, due to attaching to a process;
190 when running in the shell before the child program has been exec'd;
191 and when running some kinds of remote stuff (FIXME?). */
192
193 int stop_soon_quietly;
194
195 /* Nonzero if proceed is being used for a "finish" command or a similar
196 situation when stop_registers should be saved. */
197
198 int proceed_to_finish;
199
200 /* Save register contents here when about to pop a stack dummy frame,
201 if-and-only-if proceed_to_finish is set.
202 Thus this contains the return value from the called function (assuming
203 values are returned in a register). */
204
205 char stop_registers[REGISTER_BYTES];
206
207 /* Nonzero if program stopped due to error trying to insert breakpoints. */
208
209 static int breakpoints_failed;
210
211 /* Nonzero after stop if current stack frame should be printed. */
212
213 static int stop_print_frame;
214
215 /* Non-zero if we just simulating a single-step. This is needed
216 because we cannot remove the breakpoints in the inferior process
217 until after the `wait' in `wait_for_inferior'. */
218 static int singlestep_breakpoints_inserted_p = 0;
219
220 \f
221 /* Things to clean up if we QUIT out of resume (). */
222 /* ARGSUSED */
223 static void
224 resume_cleanups (arg)
225 int arg;
226 {
227 normal_stop ();
228 }
229
230 /* Resume the inferior, but allow a QUIT. This is useful if the user
231 wants to interrupt some lengthy single-stepping operation
232 (for child processes, the SIGINT goes to the inferior, and so
233 we get a SIGINT random_signal, but for remote debugging and perhaps
234 other targets, that's not true).
235
236 STEP nonzero if we should step (zero to continue instead).
237 SIG is the signal to give the inferior (zero for none). */
238 void
239 resume (step, sig)
240 int step;
241 enum target_signal sig;
242 {
243 struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func)
244 resume_cleanups, 0);
245 QUIT;
246
247 #ifdef CANNOT_STEP_BREAKPOINT
248 /* Most targets can step a breakpoint instruction, thus executing it
249 normally. But if this one cannot, just continue and we will hit
250 it anyway. */
251 if (step && breakpoints_inserted && breakpoint_here_p (read_pc ()))
252 step = 0;
253 #endif
254
255 if (SOFTWARE_SINGLE_STEP_P && step)
256 {
257 /* Do it the hard way, w/temp breakpoints */
258 SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints*/);
259 /* ...and don't ask hardware to do it. */
260 step = 0;
261 /* and do not pull these breakpoints until after a `wait' in
262 `wait_for_inferior' */
263 singlestep_breakpoints_inserted_p = 1;
264 }
265
266 /* Handle any optimized stores to the inferior NOW... */
267 #ifdef DO_DEFERRED_STORES
268 DO_DEFERRED_STORES;
269 #endif
270
271 /* Install inferior's terminal modes. */
272 target_terminal_inferior ();
273
274 target_resume (-1, step, sig);
275 discard_cleanups (old_cleanups);
276 }
277
278 \f
279 /* Clear out all variables saying what to do when inferior is continued.
280 First do this, then set the ones you want, then call `proceed'. */
281
282 void
283 clear_proceed_status ()
284 {
285 trap_expected = 0;
286 step_range_start = 0;
287 step_range_end = 0;
288 step_frame_address = 0;
289 step_over_calls = -1;
290 stop_after_trap = 0;
291 stop_soon_quietly = 0;
292 proceed_to_finish = 0;
293 breakpoint_proceeded = 1; /* We're about to proceed... */
294
295 /* Discard any remaining commands or status from previous stop. */
296 bpstat_clear (&stop_bpstat);
297 }
298
299 /* Basic routine for continuing the program in various fashions.
300
301 ADDR is the address to resume at, or -1 for resume where stopped.
302 SIGGNAL is the signal to give it, or 0 for none,
303 or -1 for act according to how it stopped.
304 STEP is nonzero if should trap after one instruction.
305 -1 means return after that and print nothing.
306 You should probably set various step_... variables
307 before calling here, if you are stepping.
308
309 You should call clear_proceed_status before calling proceed. */
310
311 void
312 proceed (addr, siggnal, step)
313 CORE_ADDR addr;
314 enum target_signal siggnal;
315 int step;
316 {
317 int oneproc = 0;
318
319 if (step > 0)
320 step_start_function = find_pc_function (read_pc ());
321 if (step < 0)
322 stop_after_trap = 1;
323
324 if (addr == (CORE_ADDR)-1)
325 {
326 /* If there is a breakpoint at the address we will resume at,
327 step one instruction before inserting breakpoints
328 so that we do not stop right away. */
329
330 if (read_pc () == stop_pc && breakpoint_here_p (read_pc ()))
331 oneproc = 1;
332
333 #ifndef STEP_SKIPS_DELAY
334 #define STEP_SKIPS_DELAY(pc) (0)
335 #define STEP_SKIPS_DELAY_P (0)
336 #endif
337 /* Check breakpoint_here_p first, because breakpoint_here_p is fast
338 (it just checks internal GDB data structures) and STEP_SKIPS_DELAY
339 is slow (it needs to read memory from the target). */
340 if (STEP_SKIPS_DELAY_P
341 && breakpoint_here_p (read_pc () + 4)
342 && STEP_SKIPS_DELAY (read_pc ()))
343 oneproc = 1;
344 }
345 else
346 write_pc (addr);
347
348 #ifdef PREPARE_TO_PROCEED
349 /* In a multi-threaded task we may select another thread and then continue.
350
351 In this case the thread that stopped at a breakpoint will immediately
352 cause another stop, if it is not stepped over first. On the other hand,
353 if (ADDR != -1) we only want to single step over the breakpoint if we did
354 switch to another thread.
355
356 If we are single stepping, don't do any of the above.
357 (Note that in the current implementation single stepping another
358 thread after a breakpoint and then continuing will cause the original
359 breakpoint to be hit again, but you can always continue, so it's not
360 a big deal.) */
361
362 if (! step && PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ()))
363 oneproc = 1;
364 #endif /* PREPARE_TO_PROCEED */
365
366 #ifdef HP_OS_BUG
367 if (trap_expected_after_continue)
368 {
369 /* If (step == 0), a trap will be automatically generated after
370 the first instruction is executed. Force step one
371 instruction to clear this condition. This should not occur
372 if step is nonzero, but it is harmless in that case. */
373 oneproc = 1;
374 trap_expected_after_continue = 0;
375 }
376 #endif /* HP_OS_BUG */
377
378 if (oneproc)
379 /* We will get a trace trap after one instruction.
380 Continue it automatically and insert breakpoints then. */
381 trap_expected = 1;
382 else
383 {
384 int temp = insert_breakpoints ();
385 if (temp)
386 {
387 print_sys_errmsg ("ptrace", temp);
388 error ("Cannot insert breakpoints.\n\
389 The same program may be running in another process.");
390 }
391 breakpoints_inserted = 1;
392 }
393
394 if (siggnal != TARGET_SIGNAL_DEFAULT)
395 stop_signal = siggnal;
396 /* If this signal should not be seen by program,
397 give it zero. Used for debugging signals. */
398 else if (!signal_program[stop_signal])
399 stop_signal = TARGET_SIGNAL_0;
400
401 annotate_starting ();
402
403 /* Make sure that output from GDB appears before output from the
404 inferior. */
405 gdb_flush (gdb_stdout);
406
407 /* Resume inferior. */
408 resume (oneproc || step || bpstat_should_step (), stop_signal);
409
410 /* Wait for it to stop (if not standalone)
411 and in any case decode why it stopped, and act accordingly. */
412
413 wait_for_inferior ();
414 normal_stop ();
415 }
416
417 /* Record the pc and sp of the program the last time it stopped.
418 These are just used internally by wait_for_inferior, but need
419 to be preserved over calls to it and cleared when the inferior
420 is started. */
421 static CORE_ADDR prev_pc;
422 static CORE_ADDR prev_func_start;
423 static char *prev_func_name;
424
425 \f
426 /* Start remote-debugging of a machine over a serial link. */
427
428 void
429 start_remote ()
430 {
431 init_thread_list ();
432 init_wait_for_inferior ();
433 clear_proceed_status ();
434 stop_soon_quietly = 1;
435 trap_expected = 0;
436 wait_for_inferior ();
437 normal_stop ();
438 }
439
440 /* Initialize static vars when a new inferior begins. */
441
442 void
443 init_wait_for_inferior ()
444 {
445 /* These are meaningless until the first time through wait_for_inferior. */
446 prev_pc = 0;
447 prev_func_start = 0;
448 prev_func_name = NULL;
449
450 #ifdef HP_OS_BUG
451 trap_expected_after_continue = 0;
452 #endif
453 breakpoints_inserted = 0;
454 breakpoint_init_inferior ();
455
456 /* Don't confuse first call to proceed(). */
457 stop_signal = TARGET_SIGNAL_0;
458 }
459
460 static void
461 delete_breakpoint_current_contents (arg)
462 PTR arg;
463 {
464 struct breakpoint **breakpointp = (struct breakpoint **)arg;
465 if (*breakpointp != NULL)
466 delete_breakpoint (*breakpointp);
467 }
468 \f
469 /* Wait for control to return from inferior to debugger.
470 If inferior gets a signal, we may decide to start it up again
471 instead of returning. That is why there is a loop in this function.
472 When this function actually returns it means the inferior
473 should be left stopped and GDB should read more commands. */
474
475 void
476 wait_for_inferior ()
477 {
478 struct cleanup *old_cleanups;
479 struct target_waitstatus w;
480 int another_trap;
481 int random_signal = 0;
482 CORE_ADDR stop_func_start;
483 CORE_ADDR stop_func_end;
484 char *stop_func_name;
485 #if 0
486 CORE_ADDR prologue_pc = 0;
487 #endif
488 CORE_ADDR tmp;
489 struct symtab_and_line sal;
490 int remove_breakpoints_on_following_step = 0;
491 int current_line;
492 struct symtab *current_symtab;
493 int handling_longjmp = 0; /* FIXME */
494 struct breakpoint *step_resume_breakpoint = NULL;
495 struct breakpoint *through_sigtramp_breakpoint = NULL;
496 int pid;
497 int update_step_sp = 0;
498
499 old_cleanups = make_cleanup (delete_breakpoint_current_contents,
500 &step_resume_breakpoint);
501 make_cleanup (delete_breakpoint_current_contents,
502 &through_sigtramp_breakpoint);
503 sal = find_pc_line(prev_pc, 0);
504 current_line = sal.line;
505 current_symtab = sal.symtab;
506
507 /* Are we stepping? */
508 #define CURRENTLY_STEPPING() \
509 ((through_sigtramp_breakpoint == NULL \
510 && !handling_longjmp \
511 && ((step_range_end && step_resume_breakpoint == NULL) \
512 || trap_expected)) \
513 || bpstat_should_step ())
514
515 while (1)
516 {
517 extern int overlay_cache_invalid; /* declared in symfile.h */
518
519 overlay_cache_invalid = 1;
520
521 /* We have to invalidate the registers BEFORE calling target_wait because
522 they can be loaded from the target while in target_wait. This makes
523 remote debugging a bit more efficient for those targets that provide
524 critical registers as part of their normal status mechanism. */
525
526 registers_changed ();
527
528 if (target_wait_hook)
529 pid = target_wait_hook (-1, &w);
530 else
531 pid = target_wait (-1, &w);
532
533 /* Gross.
534
535 We goto this label from elsewhere in wait_for_inferior when we want
536 to continue the main loop without calling "wait" and trashing the
537 waitstatus contained in W. */
538 have_waited:
539
540 flush_cached_frames ();
541
542 /* If it's a new process, add it to the thread database */
543
544 if (w.kind != TARGET_WAITKIND_EXITED
545 && w.kind != TARGET_WAITKIND_SIGNALLED
546 && pid != inferior_pid
547 && !in_thread_list (pid))
548 {
549 add_thread (pid);
550 printf_filtered ("[New %s]\n", target_pid_to_str (pid));
551
552 /* We may want to consider not doing a resume here in order to give
553 the user a chance to play with the new thread. It might be good
554 to make that a user-settable option. */
555
556 /* At this point, all threads are stopped (happens automatically in
557 either the OS or the native code). Therefore we need to continue
558 all threads in order to make progress. */
559
560 target_resume (-1, 0, TARGET_SIGNAL_0);
561 continue;
562 }
563
564 switch (w.kind)
565 {
566 case TARGET_WAITKIND_LOADED:
567 /* Ignore gracefully during startup of the inferior, as it
568 might be the shell which has just loaded some objects,
569 otherwise add the symbols for the newly loaded objects. */
570 #ifdef SOLIB_ADD
571 if (!stop_soon_quietly)
572 {
573 extern int auto_solib_add;
574
575 /* Remove breakpoints, SOLIB_ADD might adjust
576 breakpoint addresses via breakpoint_re_set. */
577 if (breakpoints_inserted)
578 remove_breakpoints ();
579
580 /* Check for any newly added shared libraries if we're
581 supposed to be adding them automatically. */
582 if (auto_solib_add)
583 {
584 /* Switch terminal for any messages produced by
585 breakpoint_re_set. */
586 target_terminal_ours_for_output ();
587 SOLIB_ADD (NULL, 0, NULL);
588 target_terminal_inferior ();
589 }
590
591 /* Reinsert breakpoints and continue. */
592 if (breakpoints_inserted)
593 insert_breakpoints ();
594 }
595 #endif
596 resume (0, TARGET_SIGNAL_0);
597 continue;
598
599 case TARGET_WAITKIND_SPURIOUS:
600 resume (0, TARGET_SIGNAL_0);
601 continue;
602
603 case TARGET_WAITKIND_EXITED:
604 target_terminal_ours (); /* Must do this before mourn anyway */
605 annotate_exited (w.value.integer);
606 if (w.value.integer)
607 printf_filtered ("\nProgram exited with code 0%o.\n",
608 (unsigned int)w.value.integer);
609 else
610 printf_filtered ("\nProgram exited normally.\n");
611
612 /* Record the exit code in the convenience variable $_exitcode, so
613 that the user can inspect this again later. */
614 set_internalvar (lookup_internalvar ("_exitcode"),
615 value_from_longest (builtin_type_int,
616 (LONGEST) w.value.integer));
617 gdb_flush (gdb_stdout);
618 target_mourn_inferior ();
619 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
620 stop_print_frame = 0;
621 goto stop_stepping;
622
623 case TARGET_WAITKIND_SIGNALLED:
624 stop_print_frame = 0;
625 stop_signal = w.value.sig;
626 target_terminal_ours (); /* Must do this before mourn anyway */
627 annotate_signalled ();
628
629 /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED
630 mean it is already dead? This has been here since GDB 2.8, so
631 perhaps it means rms didn't understand unix waitstatuses?
632 For the moment I'm just kludging around this in remote.c
633 rather than trying to change it here --kingdon, 5 Dec 1994. */
634 target_kill (); /* kill mourns as well */
635
636 printf_filtered ("\nProgram terminated with signal ");
637 annotate_signal_name ();
638 printf_filtered ("%s", target_signal_to_name (stop_signal));
639 annotate_signal_name_end ();
640 printf_filtered (", ");
641 annotate_signal_string ();
642 printf_filtered ("%s", target_signal_to_string (stop_signal));
643 annotate_signal_string_end ();
644 printf_filtered (".\n");
645
646 printf_filtered ("The program no longer exists.\n");
647 gdb_flush (gdb_stdout);
648 singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P*/
649 goto stop_stepping;
650
651 case TARGET_WAITKIND_STOPPED:
652 /* This is the only case in which we keep going; the above cases
653 end in a continue or goto. */
654 break;
655 }
656
657 stop_signal = w.value.sig;
658
659 stop_pc = read_pc_pid (pid);
660
661 /* See if a thread hit a thread-specific breakpoint that was meant for
662 another thread. If so, then step that thread past the breakpoint,
663 and continue it. */
664
665 if (stop_signal == TARGET_SIGNAL_TRAP)
666 {
667 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
668 random_signal = 0;
669 else
670 if (breakpoints_inserted
671 && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK))
672 {
673 random_signal = 0;
674 if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, pid))
675 {
676 /* Saw a breakpoint, but it was hit by the wrong thread. Just continue. */
677 write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, pid);
678
679 remove_breakpoints ();
680 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
681 /* FIXME: What if a signal arrives instead of the single-step
682 happening? */
683
684 if (target_wait_hook)
685 target_wait_hook (pid, &w);
686 else
687 target_wait (pid, &w);
688 insert_breakpoints ();
689
690 /* We need to restart all the threads now. */
691 target_resume (-1, 0, TARGET_SIGNAL_0);
692 continue;
693 }
694 }
695 }
696 else
697 random_signal = 1;
698
699 /* See if something interesting happened to the non-current thread. If
700 so, then switch to that thread, and eventually give control back to
701 the user. */
702
703 if (pid != inferior_pid)
704 {
705 int printed = 0;
706
707 /* If it's a random signal for a non-current thread, notify user
708 if he's expressed an interest. */
709
710 if (random_signal
711 && signal_print[stop_signal])
712 {
713 printed = 1;
714 target_terminal_ours_for_output ();
715 printf_filtered ("\nProgram received signal %s, %s.\n",
716 target_signal_to_name (stop_signal),
717 target_signal_to_string (stop_signal));
718 gdb_flush (gdb_stdout);
719 }
720
721 /* If it's not SIGTRAP and not a signal we want to stop for, then
722 continue the thread. */
723
724 if (stop_signal != TARGET_SIGNAL_TRAP
725 && !signal_stop[stop_signal])
726 {
727 if (printed)
728 target_terminal_inferior ();
729
730 /* Clear the signal if it should not be passed. */
731 if (signal_program[stop_signal] == 0)
732 stop_signal = TARGET_SIGNAL_0;
733
734 target_resume (pid, 0, stop_signal);
735 continue;
736 }
737
738 /* It's a SIGTRAP or a signal we're interested in. Switch threads,
739 and fall into the rest of wait_for_inferior(). */
740
741 /* Save infrun state for the old thread. */
742 save_infrun_state (inferior_pid, prev_pc,
743 prev_func_start, prev_func_name,
744 trap_expected, step_resume_breakpoint,
745 through_sigtramp_breakpoint,
746 step_range_start, step_range_end,
747 step_frame_address, handling_longjmp,
748 another_trap);
749
750 inferior_pid = pid;
751
752 /* Load infrun state for the new thread. */
753 load_infrun_state (inferior_pid, &prev_pc,
754 &prev_func_start, &prev_func_name,
755 &trap_expected, &step_resume_breakpoint,
756 &through_sigtramp_breakpoint,
757 &step_range_start, &step_range_end,
758 &step_frame_address, &handling_longjmp,
759 &another_trap);
760
761 if (context_hook)
762 context_hook (pid_to_thread_id (pid));
763
764 printf_filtered ("[Switching to %s]\n", target_pid_to_str (pid));
765 flush_cached_frames ();
766 }
767
768 if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p)
769 {
770 /* Pull the single step breakpoints out of the target. */
771 SOFTWARE_SINGLE_STEP (0, 0);
772 singlestep_breakpoints_inserted_p = 0;
773 }
774
775 /* If PC is pointing at a nullified instruction, then step beyond
776 it so that the user won't be confused when GDB appears to be ready
777 to execute it. */
778
779 if (INSTRUCTION_NULLIFIED)
780 {
781 struct target_waitstatus tmpstatus;
782
783 registers_changed ();
784 target_resume (pid, 1, TARGET_SIGNAL_0);
785
786 /* We may have received a signal that we want to pass to
787 the inferior; therefore, we must not clobber the waitstatus
788 in W. So we call wait ourselves, then continue the loop
789 at the "have_waited" label. */
790 if (target_wait_hook)
791 target_wait_hook (pid, &tmpstatus);
792 else
793 target_wait (pid, &tmpstatus);
794
795
796 goto have_waited;
797 }
798
799 #ifdef HAVE_STEPPABLE_WATCHPOINT
800 /* It may not be necessary to disable the watchpoint to stop over
801 it. For example, the PA can (with some kernel cooperation)
802 single step over a watchpoint without disabling the watchpoint. */
803 if (STOPPED_BY_WATCHPOINT (w))
804 {
805 resume (1, 0);
806 continue;
807 }
808 #endif
809
810 #ifdef HAVE_NONSTEPPABLE_WATCHPOINT
811 /* It is far more common to need to disable a watchpoint
812 to step the inferior over it. FIXME. What else might
813 a debug register or page protection watchpoint scheme need
814 here? */
815 if (STOPPED_BY_WATCHPOINT (w))
816 {
817 /* At this point, we are stopped at an instruction which has attempted to write
818 to a piece of memory under control of a watchpoint. The instruction hasn't
819 actually executed yet. If we were to evaluate the watchpoint expression
820 now, we would get the old value, and therefore no change would seem to have
821 occurred.
822
823 In order to make watchpoints work `right', we really need to complete the
824 memory write, and then evaluate the watchpoint expression. The following
825 code does that by removing the watchpoint (actually, all watchpoints and
826 breakpoints), single-stepping the target, re-inserting watchpoints, and then
827 falling through to let normal single-step processing handle proceed. Since
828 this includes evaluating watchpoints, things will come to a stop in the
829 correct manner. */
830
831 write_pc (stop_pc - DECR_PC_AFTER_BREAK);
832
833 remove_breakpoints ();
834 registers_changed();
835 target_resume (pid, 1, TARGET_SIGNAL_0); /* Single step */
836
837 if (target_wait_hook)
838 target_wait_hook (pid, &w);
839 else
840 target_wait (pid, &w);
841 insert_breakpoints ();
842 /* FIXME-maybe: is this cleaner than setting a flag? Does it
843 handle things like signals arriving and other things happening
844 in combination correctly? */
845 goto have_waited;
846 }
847 #endif
848
849 #ifdef HAVE_CONTINUABLE_WATCHPOINT
850 /* It may be possible to simply continue after a watchpoint. */
851 STOPPED_BY_WATCHPOINT (w);
852 #endif
853
854 stop_func_start = 0;
855 stop_func_end = 0;
856 stop_func_name = 0;
857 /* Don't care about return value; stop_func_start and stop_func_name
858 will both be 0 if it doesn't work. */
859 find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start,
860 &stop_func_end);
861 stop_func_start += FUNCTION_START_OFFSET;
862 another_trap = 0;
863 bpstat_clear (&stop_bpstat);
864 stop_step = 0;
865 stop_stack_dummy = 0;
866 stop_print_frame = 1;
867 random_signal = 0;
868 stopped_by_random_signal = 0;
869 breakpoints_failed = 0;
870
871 /* Look at the cause of the stop, and decide what to do.
872 The alternatives are:
873 1) break; to really stop and return to the debugger,
874 2) drop through to start up again
875 (set another_trap to 1 to single step once)
876 3) set random_signal to 1, and the decision between 1 and 2
877 will be made according to the signal handling tables. */
878
879 /* First, distinguish signals caused by the debugger from signals
880 that have to do with the program's own actions.
881 Note that breakpoint insns may cause SIGTRAP or SIGILL
882 or SIGEMT, depending on the operating system version.
883 Here we detect when a SIGILL or SIGEMT is really a breakpoint
884 and change it to SIGTRAP. */
885
886 if (stop_signal == TARGET_SIGNAL_TRAP
887 || (breakpoints_inserted &&
888 (stop_signal == TARGET_SIGNAL_ILL
889 || stop_signal == TARGET_SIGNAL_EMT
890 ))
891 || stop_soon_quietly)
892 {
893 if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap)
894 {
895 stop_print_frame = 0;
896 break;
897 }
898 if (stop_soon_quietly)
899 break;
900
901 /* Don't even think about breakpoints
902 if just proceeded over a breakpoint.
903
904 However, if we are trying to proceed over a breakpoint
905 and end up in sigtramp, then through_sigtramp_breakpoint
906 will be set and we should check whether we've hit the
907 step breakpoint. */
908 if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected
909 && through_sigtramp_breakpoint == NULL)
910 bpstat_clear (&stop_bpstat);
911 else
912 {
913 /* See if there is a breakpoint at the current PC. */
914 stop_bpstat = bpstat_stop_status
915 (&stop_pc,
916 (DECR_PC_AFTER_BREAK ?
917 /* Notice the case of stepping through a jump
918 that lands just after a breakpoint.
919 Don't confuse that with hitting the breakpoint.
920 What we check for is that 1) stepping is going on
921 and 2) the pc before the last insn does not match
922 the address of the breakpoint before the current pc
923 and 3) we didn't hit a breakpoint in a signal handler
924 without an intervening stop in sigtramp, which is
925 detected by a new stack pointer value below
926 any usual function calling stack adjustments. */
927 (CURRENTLY_STEPPING ()
928 && prev_pc != stop_pc - DECR_PC_AFTER_BREAK
929 && !(step_range_end
930 && read_sp () INNER_THAN (step_sp - 16))) :
931 0)
932 );
933 /* Following in case break condition called a
934 function. */
935 stop_print_frame = 1;
936 }
937
938 if (stop_signal == TARGET_SIGNAL_TRAP)
939 random_signal
940 = !(bpstat_explains_signal (stop_bpstat)
941 || trap_expected
942 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
943 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
944 FRAME_FP (get_current_frame ()))
945 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
946 || (step_range_end && step_resume_breakpoint == NULL));
947 else
948 {
949 random_signal
950 = !(bpstat_explains_signal (stop_bpstat)
951 /* End of a stack dummy. Some systems (e.g. Sony
952 news) give another signal besides SIGTRAP,
953 so check here as well as above. */
954 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
955 || PC_IN_CALL_DUMMY (stop_pc, read_sp (),
956 FRAME_FP (get_current_frame ()))
957 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
958 );
959 if (!random_signal)
960 stop_signal = TARGET_SIGNAL_TRAP;
961 }
962 }
963 else
964 random_signal = 1;
965
966 /* For the program's own signals, act according to
967 the signal handling tables. */
968
969 if (random_signal)
970 {
971 /* Signal not for debugging purposes. */
972 int printed = 0;
973
974 stopped_by_random_signal = 1;
975
976 if (signal_print[stop_signal])
977 {
978 printed = 1;
979 target_terminal_ours_for_output ();
980 annotate_signal ();
981 printf_filtered ("\nProgram received signal ");
982 annotate_signal_name ();
983 printf_filtered ("%s", target_signal_to_name (stop_signal));
984 annotate_signal_name_end ();
985 printf_filtered (", ");
986 annotate_signal_string ();
987 printf_filtered ("%s", target_signal_to_string (stop_signal));
988 annotate_signal_string_end ();
989 printf_filtered (".\n");
990 gdb_flush (gdb_stdout);
991 }
992 if (signal_stop[stop_signal])
993 break;
994 /* If not going to stop, give terminal back
995 if we took it away. */
996 else if (printed)
997 target_terminal_inferior ();
998
999 /* Clear the signal if it should not be passed. */
1000 if (signal_program[stop_signal] == 0)
1001 stop_signal = TARGET_SIGNAL_0;
1002
1003 /* I'm not sure whether this needs to be check_sigtramp2 or
1004 whether it could/should be keep_going. */
1005 goto check_sigtramp2;
1006 }
1007
1008 /* Handle cases caused by hitting a breakpoint. */
1009 {
1010 CORE_ADDR jmp_buf_pc;
1011 struct bpstat_what what;
1012
1013 what = bpstat_what (stop_bpstat);
1014
1015 if (what.call_dummy)
1016 {
1017 stop_stack_dummy = 1;
1018 #ifdef HP_OS_BUG
1019 trap_expected_after_continue = 1;
1020 #endif
1021 }
1022
1023 switch (what.main_action)
1024 {
1025 case BPSTAT_WHAT_SET_LONGJMP_RESUME:
1026 /* If we hit the breakpoint at longjmp, disable it for the
1027 duration of this command. Then, install a temporary
1028 breakpoint at the target of the jmp_buf. */
1029 disable_longjmp_breakpoint();
1030 remove_breakpoints ();
1031 breakpoints_inserted = 0;
1032 if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going;
1033
1034 /* Need to blow away step-resume breakpoint, as it
1035 interferes with us */
1036 if (step_resume_breakpoint != NULL)
1037 {
1038 delete_breakpoint (step_resume_breakpoint);
1039 step_resume_breakpoint = NULL;
1040 }
1041 /* Not sure whether we need to blow this away too, but probably
1042 it is like the step-resume breakpoint. */
1043 if (through_sigtramp_breakpoint != NULL)
1044 {
1045 delete_breakpoint (through_sigtramp_breakpoint);
1046 through_sigtramp_breakpoint = NULL;
1047 }
1048
1049 #if 0
1050 /* FIXME - Need to implement nested temporary breakpoints */
1051 if (step_over_calls > 0)
1052 set_longjmp_resume_breakpoint(jmp_buf_pc,
1053 get_current_frame());
1054 else
1055 #endif /* 0 */
1056 set_longjmp_resume_breakpoint(jmp_buf_pc, NULL);
1057 handling_longjmp = 1; /* FIXME */
1058 goto keep_going;
1059
1060 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME:
1061 case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE:
1062 remove_breakpoints ();
1063 breakpoints_inserted = 0;
1064 #if 0
1065 /* FIXME - Need to implement nested temporary breakpoints */
1066 if (step_over_calls
1067 && (FRAME_FP (get_current_frame ())
1068 INNER_THAN step_frame_address))
1069 {
1070 another_trap = 1;
1071 goto keep_going;
1072 }
1073 #endif /* 0 */
1074 disable_longjmp_breakpoint();
1075 handling_longjmp = 0; /* FIXME */
1076 if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME)
1077 break;
1078 /* else fallthrough */
1079
1080 case BPSTAT_WHAT_SINGLE:
1081 if (breakpoints_inserted)
1082 remove_breakpoints ();
1083 breakpoints_inserted = 0;
1084 another_trap = 1;
1085 /* Still need to check other stuff, at least the case
1086 where we are stepping and step out of the right range. */
1087 break;
1088
1089 case BPSTAT_WHAT_STOP_NOISY:
1090 stop_print_frame = 1;
1091
1092 /* We are about to nuke the step_resume_breakpoint and
1093 through_sigtramp_breakpoint via the cleanup chain, so
1094 no need to worry about it here. */
1095
1096 goto stop_stepping;
1097
1098 case BPSTAT_WHAT_STOP_SILENT:
1099 stop_print_frame = 0;
1100
1101 /* We are about to nuke the step_resume_breakpoint and
1102 through_sigtramp_breakpoint via the cleanup chain, so
1103 no need to worry about it here. */
1104
1105 goto stop_stepping;
1106
1107 case BPSTAT_WHAT_STEP_RESUME:
1108 delete_breakpoint (step_resume_breakpoint);
1109 step_resume_breakpoint = NULL;
1110 break;
1111
1112 case BPSTAT_WHAT_THROUGH_SIGTRAMP:
1113 if (through_sigtramp_breakpoint)
1114 delete_breakpoint (through_sigtramp_breakpoint);
1115 through_sigtramp_breakpoint = NULL;
1116
1117 /* If were waiting for a trap, hitting the step_resume_break
1118 doesn't count as getting it. */
1119 if (trap_expected)
1120 another_trap = 1;
1121 break;
1122
1123 case BPSTAT_WHAT_CHECK_SHLIBS:
1124 #ifdef SOLIB_ADD
1125 {
1126 extern int auto_solib_add;
1127
1128 /* Remove breakpoints, we eventually want to step over the
1129 shlib event breakpoint, and SOLIB_ADD might adjust
1130 breakpoint addresses via breakpoint_re_set. */
1131 if (breakpoints_inserted)
1132 remove_breakpoints ();
1133 breakpoints_inserted = 0;
1134
1135 /* Check for any newly added shared libraries if we're
1136 supposed to be adding them automatically. */
1137 if (auto_solib_add)
1138 {
1139 /* Switch terminal for any messages produced by
1140 breakpoint_re_set. */
1141 target_terminal_ours_for_output ();
1142 SOLIB_ADD (NULL, 0, NULL);
1143 target_terminal_inferior ();
1144 }
1145
1146 /* Try to reenable shared library breakpoints, additional
1147 code segments in shared libraries might be mapped in now. */
1148 re_enable_breakpoints_in_shlibs ();
1149
1150 /* If requested, stop when the dynamic linker notifies
1151 gdb of events. This allows the user to get control
1152 and place breakpoints in initializer routines for
1153 dynamically loaded objects (among other things). */
1154 if (stop_on_solib_events)
1155 {
1156 stop_print_frame = 0;
1157 goto stop_stepping;
1158 }
1159 else
1160 {
1161 /* We want to step over this breakpoint, then keep going. */
1162 another_trap = 1;
1163 break;
1164 }
1165 }
1166 #endif
1167 break;
1168
1169 case BPSTAT_WHAT_LAST:
1170 /* Not a real code, but listed here to shut up gcc -Wall. */
1171
1172 case BPSTAT_WHAT_KEEP_CHECKING:
1173 break;
1174 }
1175 }
1176
1177 /* We come here if we hit a breakpoint but should not
1178 stop for it. Possibly we also were stepping
1179 and should stop for that. So fall through and
1180 test for stepping. But, if not stepping,
1181 do not stop. */
1182
1183 #ifndef CALL_DUMMY_BREAKPOINT_OFFSET
1184 /* This is the old way of detecting the end of the stack dummy.
1185 An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets
1186 handled above. As soon as we can test it on all of them, all
1187 architectures should define it. */
1188
1189 /* If this is the breakpoint at the end of a stack dummy,
1190 just stop silently, unless the user was doing an si/ni, in which
1191 case she'd better know what she's doing. */
1192
1193 if (PC_IN_CALL_DUMMY (stop_pc, read_sp (), FRAME_FP (get_current_frame ()))
1194 && !step_range_end)
1195 {
1196 stop_print_frame = 0;
1197 stop_stack_dummy = 1;
1198 #ifdef HP_OS_BUG
1199 trap_expected_after_continue = 1;
1200 #endif
1201 break;
1202 }
1203 #endif /* No CALL_DUMMY_BREAKPOINT_OFFSET. */
1204
1205 if (step_resume_breakpoint)
1206 /* Having a step-resume breakpoint overrides anything
1207 else having to do with stepping commands until
1208 that breakpoint is reached. */
1209 /* I'm not sure whether this needs to be check_sigtramp2 or
1210 whether it could/should be keep_going. */
1211 goto check_sigtramp2;
1212
1213 if (step_range_end == 0)
1214 /* Likewise if we aren't even stepping. */
1215 /* I'm not sure whether this needs to be check_sigtramp2 or
1216 whether it could/should be keep_going. */
1217 goto check_sigtramp2;
1218
1219 /* If stepping through a line, keep going if still within it. */
1220 if (stop_pc >= step_range_start
1221 && stop_pc < step_range_end
1222 #if 0
1223 /* I haven't a clue what might trigger this clause, and it seems wrong anyway,
1224 so I've disabled it until someone complains. -Stu 10/24/95 */
1225
1226 /* The step range might include the start of the
1227 function, so if we are at the start of the
1228 step range and either the stack or frame pointers
1229 just changed, we've stepped outside */
1230 && !(stop_pc == step_range_start
1231 && FRAME_FP (get_current_frame ())
1232 && (read_sp () INNER_THAN step_sp
1233 || FRAME_FP (get_current_frame ()) != step_frame_address))
1234 #endif
1235 )
1236 {
1237 /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal.
1238 So definately need to check for sigtramp here. */
1239 goto check_sigtramp2;
1240 }
1241
1242 /* We stepped out of the stepping range. */
1243
1244 /* If we are stepping at the source level and entered the runtime
1245 loader dynamic symbol resolution code, we keep on single stepping
1246 until we exit the run time loader code and reach the callee's
1247 address. */
1248 if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc))
1249 goto keep_going;
1250
1251 /* We can't update step_sp every time through the loop, because
1252 reading the stack pointer would slow down stepping too much.
1253 But we can update it every time we leave the step range. */
1254 update_step_sp = 1;
1255
1256 /* Did we just take a signal? */
1257 if (IN_SIGTRAMP (stop_pc, stop_func_name)
1258 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1259 && read_sp () INNER_THAN step_sp)
1260 {
1261 /* We've just taken a signal; go until we are back to
1262 the point where we took it and one more. */
1263
1264 /* This code is needed at least in the following case:
1265 The user types "next" and then a signal arrives (before
1266 the "next" is done). */
1267
1268 /* Note that if we are stopped at a breakpoint, then we need
1269 the step_resume breakpoint to override any breakpoints at
1270 the same location, so that we will still step over the
1271 breakpoint even though the signal happened. */
1272
1273 {
1274 struct symtab_and_line sr_sal;
1275
1276 INIT_SAL (&sr_sal); /* initialize to zeroes */
1277 sr_sal.pc = prev_pc;
1278 sr_sal.section = find_pc_overlay (sr_sal.pc);
1279 /* We could probably be setting the frame to
1280 step_frame_address; I don't think anyone thought to try it. */
1281 step_resume_breakpoint =
1282 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1283 if (breakpoints_inserted)
1284 insert_breakpoints ();
1285 }
1286
1287 /* If this is stepi or nexti, make sure that the stepping range
1288 gets us past that instruction. */
1289 if (step_range_end == 1)
1290 /* FIXME: Does this run afoul of the code below which, if
1291 we step into the middle of a line, resets the stepping
1292 range? */
1293 step_range_end = (step_range_start = prev_pc) + 1;
1294
1295 remove_breakpoints_on_following_step = 1;
1296 goto keep_going;
1297 }
1298
1299 #if 0
1300 /* I disabled this test because it was too complicated and slow. The
1301 SKIP_PROLOGUE was especially slow, because it caused unnecessary
1302 prologue examination on various architectures. The code in the #else
1303 clause has been tested on the Sparc, Mips, PA, and Power
1304 architectures, so it's pretty likely to be correct. -Stu 10/24/95 */
1305
1306 /* See if we left the step range due to a subroutine call that
1307 we should proceed to the end of. */
1308
1309 if (stop_func_start)
1310 {
1311 struct symtab *s;
1312
1313 /* Do this after the IN_SIGTRAMP check; it might give
1314 an error. */
1315 prologue_pc = stop_func_start;
1316
1317 /* Don't skip the prologue if this is assembly source */
1318 s = find_pc_symtab (stop_pc);
1319 if (s && s->language != language_asm)
1320 SKIP_PROLOGUE (prologue_pc);
1321 }
1322
1323 if (!(step_sp INNER_THAN read_sp ()) /* don't mistake (sig)return as a call */
1324 && (/* Might be a non-recursive call. If the symbols are missing
1325 enough that stop_func_start == prev_func_start even though
1326 they are really two functions, we will treat some calls as
1327 jumps. */
1328 stop_func_start != prev_func_start
1329
1330 /* Might be a recursive call if either we have a prologue
1331 or the call instruction itself saves the PC on the stack. */
1332 || prologue_pc != stop_func_start
1333 || read_sp () != step_sp)
1334 && (/* PC is completely out of bounds of any known objfiles. Treat
1335 like a subroutine call. */
1336 ! stop_func_start
1337
1338 /* If we do a call, we will be at the start of a function... */
1339 || stop_pc == stop_func_start
1340
1341 /* ...except on the Alpha with -O (and also Irix 5 and
1342 perhaps others), in which we might call the address
1343 after the load of gp. Since prologues don't contain
1344 calls, we can't return to within one, and we don't
1345 jump back into them, so this check is OK. */
1346
1347 || stop_pc < prologue_pc
1348
1349 /* ...and if it is a leaf function, the prologue might
1350 consist of gp loading only, so the call transfers to
1351 the first instruction after the prologue. */
1352 || (stop_pc == prologue_pc
1353
1354 /* Distinguish this from the case where we jump back
1355 to the first instruction after the prologue,
1356 within a function. */
1357 && stop_func_start != prev_func_start)
1358
1359 /* If we end up in certain places, it means we did a subroutine
1360 call. I'm not completely sure this is necessary now that we
1361 have the above checks with stop_func_start (and now that
1362 find_pc_partial_function is pickier). */
1363 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1364
1365 /* If none of the above apply, it is a jump within a function,
1366 or a return from a subroutine. The other case is longjmp,
1367 which can no longer happen here as long as the
1368 handling_longjmp stuff is working. */
1369 ))
1370 #else
1371 /* This test is a much more streamlined, (but hopefully correct)
1372 replacement for the code above. It's been tested on the Sparc,
1373 Mips, PA, and Power architectures with good results. */
1374
1375 if (stop_pc == stop_func_start /* Quick test */
1376 || in_prologue (stop_pc, stop_func_start)
1377 || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, stop_func_name)
1378 || stop_func_name == 0)
1379 #endif
1380
1381 {
1382 /* It's a subroutine call. */
1383
1384 if (step_over_calls == 0)
1385 {
1386 /* I presume that step_over_calls is only 0 when we're
1387 supposed to be stepping at the assembly language level
1388 ("stepi"). Just stop. */
1389 stop_step = 1;
1390 break;
1391 }
1392
1393 if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc))
1394 /* We're doing a "next". */
1395 goto step_over_function;
1396
1397 /* If we are in a function call trampoline (a stub between
1398 the calling routine and the real function), locate the real
1399 function. That's what tells us (a) whether we want to step
1400 into it at all, and (b) what prologue we want to run to
1401 the end of, if we do step into it. */
1402 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1403 if (tmp != 0)
1404 stop_func_start = tmp;
1405 else
1406 {
1407 tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc);
1408 if (tmp)
1409 {
1410 struct symtab_and_line xxx;
1411 /* Why isn't this s_a_l called "sr_sal", like all of the
1412 other s_a_l's where this code is duplicated? */
1413 INIT_SAL (&xxx); /* initialize to zeroes */
1414 xxx.pc = tmp;
1415 xxx.section = find_pc_overlay (xxx.pc);
1416 step_resume_breakpoint =
1417 set_momentary_breakpoint (xxx, NULL, bp_step_resume);
1418 insert_breakpoints ();
1419 goto keep_going;
1420 }
1421 }
1422
1423 /* If we have line number information for the function we
1424 are thinking of stepping into, step into it.
1425
1426 If there are several symtabs at that PC (e.g. with include
1427 files), just want to know whether *any* of them have line
1428 numbers. find_pc_line handles this. */
1429 {
1430 struct symtab_and_line tmp_sal;
1431
1432 tmp_sal = find_pc_line (stop_func_start, 0);
1433 if (tmp_sal.line != 0)
1434 goto step_into_function;
1435 }
1436
1437 step_over_function:
1438 /* A subroutine call has happened. */
1439 {
1440 /* Set a special breakpoint after the return */
1441 struct symtab_and_line sr_sal;
1442
1443 INIT_SAL (&sr_sal); /* initialize to zeroes */
1444 sr_sal.pc =
1445 ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ()));
1446 sr_sal.section = find_pc_overlay (sr_sal.pc);
1447 step_resume_breakpoint =
1448 set_momentary_breakpoint (sr_sal, get_current_frame (),
1449 bp_step_resume);
1450 if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc))
1451 step_resume_breakpoint->frame = step_frame_address;
1452 if (breakpoints_inserted)
1453 insert_breakpoints ();
1454 }
1455 goto keep_going;
1456
1457 step_into_function:
1458 /* Subroutine call with source code we should not step over.
1459 Do step to the first line of code in it. */
1460 {
1461 struct symtab *s;
1462
1463 s = find_pc_symtab (stop_pc);
1464 if (s && s->language != language_asm)
1465 SKIP_PROLOGUE (stop_func_start);
1466 }
1467 sal = find_pc_line (stop_func_start, 0);
1468 /* Use the step_resume_break to step until
1469 the end of the prologue, even if that involves jumps
1470 (as it seems to on the vax under 4.2). */
1471 /* If the prologue ends in the middle of a source line,
1472 continue to the end of that source line (if it is still
1473 within the function). Otherwise, just go to end of prologue. */
1474 #ifdef PROLOGUE_FIRSTLINE_OVERLAP
1475 /* no, don't either. It skips any code that's
1476 legitimately on the first line. */
1477 #else
1478 if (sal.end && sal.pc != stop_func_start && sal.end < stop_func_end)
1479 stop_func_start = sal.end;
1480 #endif
1481
1482 if (stop_func_start == stop_pc)
1483 {
1484 /* We are already there: stop now. */
1485 stop_step = 1;
1486 break;
1487 }
1488 else
1489 /* Put the step-breakpoint there and go until there. */
1490 {
1491 struct symtab_and_line sr_sal;
1492
1493 INIT_SAL (&sr_sal); /* initialize to zeroes */
1494 sr_sal.pc = stop_func_start;
1495 sr_sal.section = find_pc_overlay (stop_func_start);
1496 /* Do not specify what the fp should be when we stop
1497 since on some machines the prologue
1498 is where the new fp value is established. */
1499 step_resume_breakpoint =
1500 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1501 if (breakpoints_inserted)
1502 insert_breakpoints ();
1503
1504 /* And make sure stepping stops right away then. */
1505 step_range_end = step_range_start;
1506 }
1507 goto keep_going;
1508 }
1509
1510 /* We've wandered out of the step range. */
1511
1512 sal = find_pc_line(stop_pc, 0);
1513
1514 if (step_range_end == 1)
1515 {
1516 /* It is stepi or nexti. We always want to stop stepping after
1517 one instruction. */
1518 stop_step = 1;
1519 break;
1520 }
1521
1522 /* If we're in the return path from a shared library trampoline,
1523 we want to proceed through the trampoline when stepping. */
1524 if (IN_SOLIB_RETURN_TRAMPOLINE(stop_pc, stop_func_name))
1525 {
1526 CORE_ADDR tmp;
1527
1528 /* Determine where this trampoline returns. */
1529 tmp = SKIP_TRAMPOLINE_CODE (stop_pc);
1530
1531 /* Only proceed through if we know where it's going. */
1532 if (tmp)
1533 {
1534 /* And put the step-breakpoint there and go until there. */
1535 struct symtab_and_line sr_sal;
1536
1537 INIT_SAL (&sr_sal); /* initialize to zeroes */
1538 sr_sal.pc = tmp;
1539 sr_sal.section = find_pc_overlay (sr_sal.pc);
1540 /* Do not specify what the fp should be when we stop
1541 since on some machines the prologue
1542 is where the new fp value is established. */
1543 step_resume_breakpoint =
1544 set_momentary_breakpoint (sr_sal, NULL, bp_step_resume);
1545 if (breakpoints_inserted)
1546 insert_breakpoints ();
1547
1548 /* Restart without fiddling with the step ranges or
1549 other state. */
1550 goto keep_going;
1551 }
1552 }
1553
1554 if (sal.line == 0)
1555 {
1556 /* We have no line number information. That means to stop
1557 stepping (does this always happen right after one instruction,
1558 when we do "s" in a function with no line numbers,
1559 or can this happen as a result of a return or longjmp?). */
1560 stop_step = 1;
1561 break;
1562 }
1563
1564 if (stop_pc == sal.pc
1565 && (current_line != sal.line || current_symtab != sal.symtab))
1566 {
1567 /* We are at the start of a different line. So stop. Note that
1568 we don't stop if we step into the middle of a different line.
1569 That is said to make things like for (;;) statements work
1570 better. */
1571 stop_step = 1;
1572 break;
1573 }
1574
1575 /* We aren't done stepping.
1576
1577 Optimize by setting the stepping range to the line.
1578 (We might not be in the original line, but if we entered a
1579 new line in mid-statement, we continue stepping. This makes
1580 things like for(;;) statements work better.) */
1581
1582 if (stop_func_end && sal.end >= stop_func_end)
1583 {
1584 /* If this is the last line of the function, don't keep stepping
1585 (it would probably step us out of the function).
1586 This is particularly necessary for a one-line function,
1587 in which after skipping the prologue we better stop even though
1588 we will be in mid-line. */
1589 stop_step = 1;
1590 break;
1591 }
1592 step_range_start = sal.pc;
1593 step_range_end = sal.end;
1594 step_frame_address = FRAME_FP (get_current_frame ());
1595 current_line = sal.line;
1596 current_symtab = sal.symtab;
1597 goto keep_going;
1598
1599 check_sigtramp2:
1600 if (trap_expected
1601 && IN_SIGTRAMP (stop_pc, stop_func_name)
1602 && !IN_SIGTRAMP (prev_pc, prev_func_name)
1603 && read_sp () INNER_THAN step_sp)
1604 {
1605 /* What has happened here is that we have just stepped the inferior
1606 with a signal (because it is a signal which shouldn't make
1607 us stop), thus stepping into sigtramp.
1608
1609 So we need to set a step_resume_break_address breakpoint
1610 and continue until we hit it, and then step. FIXME: This should
1611 be more enduring than a step_resume breakpoint; we should know
1612 that we will later need to keep going rather than re-hitting
1613 the breakpoint here (see testsuite/gdb.t06/signals.exp where
1614 it says "exceedingly difficult"). */
1615 struct symtab_and_line sr_sal;
1616
1617 INIT_SAL (&sr_sal); /* initialize to zeroes */
1618 sr_sal.pc = prev_pc;
1619 sr_sal.section = find_pc_overlay (sr_sal.pc);
1620 /* We perhaps could set the frame if we kept track of what
1621 the frame corresponding to prev_pc was. But we don't,
1622 so don't. */
1623 through_sigtramp_breakpoint =
1624 set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp);
1625 if (breakpoints_inserted)
1626 insert_breakpoints ();
1627
1628 remove_breakpoints_on_following_step = 1;
1629 another_trap = 1;
1630 }
1631
1632 keep_going:
1633 /* Come to this label when you need to resume the inferior.
1634 It's really much cleaner to do a goto than a maze of if-else
1635 conditions. */
1636
1637 /* Save the pc before execution, to compare with pc after stop. */
1638 prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */
1639 prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER
1640 BREAK is defined, the
1641 original pc would not have
1642 been at the start of a
1643 function. */
1644 prev_func_name = stop_func_name;
1645
1646 if (update_step_sp)
1647 step_sp = read_sp ();
1648 update_step_sp = 0;
1649
1650 /* If we did not do break;, it means we should keep
1651 running the inferior and not return to debugger. */
1652
1653 if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP)
1654 {
1655 /* We took a signal (which we are supposed to pass through to
1656 the inferior, else we'd have done a break above) and we
1657 haven't yet gotten our trap. Simply continue. */
1658 resume (CURRENTLY_STEPPING (), stop_signal);
1659 }
1660 else
1661 {
1662 /* Either the trap was not expected, but we are continuing
1663 anyway (the user asked that this signal be passed to the
1664 child)
1665 -- or --
1666 The signal was SIGTRAP, e.g. it was our signal, but we
1667 decided we should resume from it.
1668
1669 We're going to run this baby now!
1670
1671 Insert breakpoints now, unless we are trying
1672 to one-proceed past a breakpoint. */
1673 /* If we've just finished a special step resume and we don't
1674 want to hit a breakpoint, pull em out. */
1675 if (step_resume_breakpoint == NULL
1676 && through_sigtramp_breakpoint == NULL
1677 && remove_breakpoints_on_following_step)
1678 {
1679 remove_breakpoints_on_following_step = 0;
1680 remove_breakpoints ();
1681 breakpoints_inserted = 0;
1682 }
1683 else if (!breakpoints_inserted &&
1684 (through_sigtramp_breakpoint != NULL || !another_trap))
1685 {
1686 breakpoints_failed = insert_breakpoints ();
1687 if (breakpoints_failed)
1688 break;
1689 breakpoints_inserted = 1;
1690 }
1691
1692 trap_expected = another_trap;
1693
1694 if (stop_signal == TARGET_SIGNAL_TRAP)
1695 stop_signal = TARGET_SIGNAL_0;
1696
1697 #ifdef SHIFT_INST_REGS
1698 /* I'm not sure when this following segment applies. I do know, now,
1699 that we shouldn't rewrite the regs when we were stopped by a
1700 random signal from the inferior process. */
1701 /* FIXME: Shouldn't this be based on the valid bit of the SXIP?
1702 (this is only used on the 88k). */
1703
1704 if (!bpstat_explains_signal (stop_bpstat)
1705 && (stop_signal != TARGET_SIGNAL_CHLD)
1706 && !stopped_by_random_signal)
1707 SHIFT_INST_REGS();
1708 #endif /* SHIFT_INST_REGS */
1709
1710 resume (CURRENTLY_STEPPING (), stop_signal);
1711 }
1712 }
1713
1714 stop_stepping:
1715 if (target_has_execution)
1716 {
1717 /* Assuming the inferior still exists, set these up for next
1718 time, just like we did above if we didn't break out of the
1719 loop. */
1720 prev_pc = read_pc ();
1721 prev_func_start = stop_func_start;
1722 prev_func_name = stop_func_name;
1723 }
1724 do_cleanups (old_cleanups);
1725 }
1726 \f
1727 /* Here to return control to GDB when the inferior stops for real.
1728 Print appropriate messages, remove breakpoints, give terminal our modes.
1729
1730 STOP_PRINT_FRAME nonzero means print the executing frame
1731 (pc, function, args, file, line number and line text).
1732 BREAKPOINTS_FAILED nonzero means stop was due to error
1733 attempting to insert breakpoints. */
1734
1735 void
1736 normal_stop ()
1737 {
1738 /* Make sure that the current_frame's pc is correct. This
1739 is a correction for setting up the frame info before doing
1740 DECR_PC_AFTER_BREAK */
1741 if (target_has_execution && get_current_frame())
1742 (get_current_frame ())->pc = read_pc ();
1743
1744 if (breakpoints_failed)
1745 {
1746 target_terminal_ours_for_output ();
1747 print_sys_errmsg ("ptrace", breakpoints_failed);
1748 printf_filtered ("Stopped; cannot insert breakpoints.\n\
1749 The same program may be running in another process.\n");
1750 }
1751
1752 if (target_has_execution && breakpoints_inserted)
1753 if (remove_breakpoints ())
1754 {
1755 target_terminal_ours_for_output ();
1756 printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\
1757 It might be running in another process.\n\
1758 Further execution is probably impossible.\n");
1759 }
1760
1761 breakpoints_inserted = 0;
1762
1763 /* Delete the breakpoint we stopped at, if it wants to be deleted.
1764 Delete any breakpoint that is to be deleted at the next stop. */
1765
1766 breakpoint_auto_delete (stop_bpstat);
1767
1768 /* If an auto-display called a function and that got a signal,
1769 delete that auto-display to avoid an infinite recursion. */
1770
1771 if (stopped_by_random_signal)
1772 disable_current_display ();
1773
1774 if (step_multi && stop_step)
1775 goto done;
1776
1777 target_terminal_ours ();
1778
1779 if (stop_bpstat
1780 && stop_bpstat->breakpoint_at
1781 && stop_bpstat->breakpoint_at->type == bp_shlib_event)
1782 printf_filtered ("Stopped due to shared library event\n");
1783
1784 /* Look up the hook_stop and run it if it exists. */
1785
1786 if (stop_command->hook)
1787 {
1788 catch_errors (hook_stop_stub, (char *)stop_command->hook,
1789 "Error while running hook_stop:\n", RETURN_MASK_ALL);
1790 }
1791
1792 if (!target_has_stack)
1793 goto done;
1794
1795 /* Select innermost stack frame except on return from a stack dummy routine,
1796 or if the program has exited. Print it without a level number if
1797 we have changed functions or hit a breakpoint. Print source line
1798 if we have one. */
1799 if (!stop_stack_dummy)
1800 {
1801 select_frame (get_current_frame (), 0);
1802
1803 if (stop_print_frame)
1804 {
1805 int source_only;
1806
1807 source_only = bpstat_print (stop_bpstat);
1808 source_only = source_only ||
1809 ( stop_step
1810 && step_frame_address == FRAME_FP (get_current_frame ())
1811 && step_start_function == find_pc_function (stop_pc));
1812
1813 print_stack_frame (selected_frame, -1, source_only? -1: 1);
1814
1815 /* Display the auto-display expressions. */
1816 do_displays ();
1817 }
1818 }
1819
1820 /* Save the function value return registers, if we care.
1821 We might be about to restore their previous contents. */
1822 if (proceed_to_finish)
1823 read_register_bytes (0, stop_registers, REGISTER_BYTES);
1824
1825 if (stop_stack_dummy)
1826 {
1827 /* Pop the empty frame that contains the stack dummy.
1828 POP_FRAME ends with a setting of the current frame, so we
1829 can use that next. */
1830 POP_FRAME;
1831 /* Set stop_pc to what it was before we called the function. Can't rely
1832 on restore_inferior_status because that only gets called if we don't
1833 stop in the called function. */
1834 stop_pc = read_pc();
1835 select_frame (get_current_frame (), 0);
1836 }
1837 done:
1838 annotate_stopped ();
1839 }
1840
1841 static int
1842 hook_stop_stub (cmd)
1843 char *cmd;
1844 {
1845 execute_user_command ((struct cmd_list_element *)cmd, 0);
1846 return (0);
1847 }
1848 \f
1849 int signal_stop_state (signo)
1850 int signo;
1851 {
1852 return signal_stop[signo];
1853 }
1854
1855 int signal_print_state (signo)
1856 int signo;
1857 {
1858 return signal_print[signo];
1859 }
1860
1861 int signal_pass_state (signo)
1862 int signo;
1863 {
1864 return signal_program[signo];
1865 }
1866
1867 static void
1868 sig_print_header ()
1869 {
1870 printf_filtered ("\
1871 Signal Stop\tPrint\tPass to program\tDescription\n");
1872 }
1873
1874 static void
1875 sig_print_info (oursig)
1876 enum target_signal oursig;
1877 {
1878 char *name = target_signal_to_name (oursig);
1879 int name_padding = 13 - strlen (name);
1880 if (name_padding <= 0)
1881 name_padding = 0;
1882
1883 printf_filtered ("%s", name);
1884 printf_filtered ("%*.*s ", name_padding, name_padding, " ");
1885 printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No");
1886 printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No");
1887 printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No");
1888 printf_filtered ("%s\n", target_signal_to_string (oursig));
1889 }
1890
1891 /* Specify how various signals in the inferior should be handled. */
1892
1893 static void
1894 handle_command (args, from_tty)
1895 char *args;
1896 int from_tty;
1897 {
1898 char **argv;
1899 int digits, wordlen;
1900 int sigfirst, signum, siglast;
1901 enum target_signal oursig;
1902 int allsigs;
1903 int nsigs;
1904 unsigned char *sigs;
1905 struct cleanup *old_chain;
1906
1907 if (args == NULL)
1908 {
1909 error_no_arg ("signal to handle");
1910 }
1911
1912 /* Allocate and zero an array of flags for which signals to handle. */
1913
1914 nsigs = (int)TARGET_SIGNAL_LAST;
1915 sigs = (unsigned char *) alloca (nsigs);
1916 memset (sigs, 0, nsigs);
1917
1918 /* Break the command line up into args. */
1919
1920 argv = buildargv (args);
1921 if (argv == NULL)
1922 {
1923 nomem (0);
1924 }
1925 old_chain = make_cleanup ((make_cleanup_func) freeargv, (char *) argv);
1926
1927 /* Walk through the args, looking for signal oursigs, signal names, and
1928 actions. Signal numbers and signal names may be interspersed with
1929 actions, with the actions being performed for all signals cumulatively
1930 specified. Signal ranges can be specified as <LOW>-<HIGH>. */
1931
1932 while (*argv != NULL)
1933 {
1934 wordlen = strlen (*argv);
1935 for (digits = 0; isdigit ((*argv)[digits]); digits++) {;}
1936 allsigs = 0;
1937 sigfirst = siglast = -1;
1938
1939 if (wordlen >= 1 && !strncmp (*argv, "all", wordlen))
1940 {
1941 /* Apply action to all signals except those used by the
1942 debugger. Silently skip those. */
1943 allsigs = 1;
1944 sigfirst = 0;
1945 siglast = nsigs - 1;
1946 }
1947 else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen))
1948 {
1949 SET_SIGS (nsigs, sigs, signal_stop);
1950 SET_SIGS (nsigs, sigs, signal_print);
1951 }
1952 else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen))
1953 {
1954 UNSET_SIGS (nsigs, sigs, signal_program);
1955 }
1956 else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen))
1957 {
1958 SET_SIGS (nsigs, sigs, signal_print);
1959 }
1960 else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen))
1961 {
1962 SET_SIGS (nsigs, sigs, signal_program);
1963 }
1964 else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen))
1965 {
1966 UNSET_SIGS (nsigs, sigs, signal_stop);
1967 }
1968 else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen))
1969 {
1970 SET_SIGS (nsigs, sigs, signal_program);
1971 }
1972 else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen))
1973 {
1974 UNSET_SIGS (nsigs, sigs, signal_print);
1975 UNSET_SIGS (nsigs, sigs, signal_stop);
1976 }
1977 else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen))
1978 {
1979 UNSET_SIGS (nsigs, sigs, signal_program);
1980 }
1981 else if (digits > 0)
1982 {
1983 /* It is numeric. The numeric signal refers to our own internal
1984 signal numbering from target.h, not to host/target signal number.
1985 This is a feature; users really should be using symbolic names
1986 anyway, and the common ones like SIGHUP, SIGINT, SIGALRM, etc.
1987 will work right anyway. */
1988
1989 sigfirst = siglast = (int) target_signal_from_command (atoi (*argv));
1990 if ((*argv)[digits] == '-')
1991 {
1992 siglast =
1993 (int) target_signal_from_command (atoi ((*argv) + digits + 1));
1994 }
1995 if (sigfirst > siglast)
1996 {
1997 /* Bet he didn't figure we'd think of this case... */
1998 signum = sigfirst;
1999 sigfirst = siglast;
2000 siglast = signum;
2001 }
2002 }
2003 else
2004 {
2005 oursig = target_signal_from_name (*argv);
2006 if (oursig != TARGET_SIGNAL_UNKNOWN)
2007 {
2008 sigfirst = siglast = (int)oursig;
2009 }
2010 else
2011 {
2012 /* Not a number and not a recognized flag word => complain. */
2013 error ("Unrecognized or ambiguous flag word: \"%s\".", *argv);
2014 }
2015 }
2016
2017 /* If any signal numbers or symbol names were found, set flags for
2018 which signals to apply actions to. */
2019
2020 for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++)
2021 {
2022 switch ((enum target_signal)signum)
2023 {
2024 case TARGET_SIGNAL_TRAP:
2025 case TARGET_SIGNAL_INT:
2026 if (!allsigs && !sigs[signum])
2027 {
2028 if (query ("%s is used by the debugger.\n\
2029 Are you sure you want to change it? ",
2030 target_signal_to_name
2031 ((enum target_signal)signum)))
2032 {
2033 sigs[signum] = 1;
2034 }
2035 else
2036 {
2037 printf_unfiltered ("Not confirmed, unchanged.\n");
2038 gdb_flush (gdb_stdout);
2039 }
2040 }
2041 break;
2042 case TARGET_SIGNAL_0:
2043 case TARGET_SIGNAL_DEFAULT:
2044 case TARGET_SIGNAL_UNKNOWN:
2045 /* Make sure that "all" doesn't print these. */
2046 break;
2047 default:
2048 sigs[signum] = 1;
2049 break;
2050 }
2051 }
2052
2053 argv++;
2054 }
2055
2056 target_notice_signals(inferior_pid);
2057
2058 if (from_tty)
2059 {
2060 /* Show the results. */
2061 sig_print_header ();
2062 for (signum = 0; signum < nsigs; signum++)
2063 {
2064 if (sigs[signum])
2065 {
2066 sig_print_info (signum);
2067 }
2068 }
2069 }
2070
2071 do_cleanups (old_chain);
2072 }
2073
2074 /* Print current contents of the tables set by the handle command.
2075 It is possible we should just be printing signals actually used
2076 by the current target (but for things to work right when switching
2077 targets, all signals should be in the signal tables). */
2078
2079 static void
2080 signals_info (signum_exp, from_tty)
2081 char *signum_exp;
2082 int from_tty;
2083 {
2084 enum target_signal oursig;
2085 sig_print_header ();
2086
2087 if (signum_exp)
2088 {
2089 /* First see if this is a symbol name. */
2090 oursig = target_signal_from_name (signum_exp);
2091 if (oursig == TARGET_SIGNAL_UNKNOWN)
2092 {
2093 /* No, try numeric. */
2094 oursig =
2095 target_signal_from_command (parse_and_eval_address (signum_exp));
2096 }
2097 sig_print_info (oursig);
2098 return;
2099 }
2100
2101 printf_filtered ("\n");
2102 /* These ugly casts brought to you by the native VAX compiler. */
2103 for (oursig = TARGET_SIGNAL_FIRST;
2104 (int)oursig < (int)TARGET_SIGNAL_LAST;
2105 oursig = (enum target_signal)((int)oursig + 1))
2106 {
2107 QUIT;
2108
2109 if (oursig != TARGET_SIGNAL_UNKNOWN
2110 && oursig != TARGET_SIGNAL_DEFAULT
2111 && oursig != TARGET_SIGNAL_0)
2112 sig_print_info (oursig);
2113 }
2114
2115 printf_filtered ("\nUse the \"handle\" command to change these tables.\n");
2116 }
2117 \f
2118 /* Save all of the information associated with the inferior<==>gdb
2119 connection. INF_STATUS is a pointer to a "struct inferior_status"
2120 (defined in inferior.h). */
2121
2122 void
2123 save_inferior_status (inf_status, restore_stack_info)
2124 struct inferior_status *inf_status;
2125 int restore_stack_info;
2126 {
2127 inf_status->stop_signal = stop_signal;
2128 inf_status->stop_pc = stop_pc;
2129 inf_status->stop_step = stop_step;
2130 inf_status->stop_stack_dummy = stop_stack_dummy;
2131 inf_status->stopped_by_random_signal = stopped_by_random_signal;
2132 inf_status->trap_expected = trap_expected;
2133 inf_status->step_range_start = step_range_start;
2134 inf_status->step_range_end = step_range_end;
2135 inf_status->step_frame_address = step_frame_address;
2136 inf_status->step_over_calls = step_over_calls;
2137 inf_status->stop_after_trap = stop_after_trap;
2138 inf_status->stop_soon_quietly = stop_soon_quietly;
2139 /* Save original bpstat chain here; replace it with copy of chain.
2140 If caller's caller is walking the chain, they'll be happier if we
2141 hand them back the original chain when restore_i_s is called. */
2142 inf_status->stop_bpstat = stop_bpstat;
2143 stop_bpstat = bpstat_copy (stop_bpstat);
2144 inf_status->breakpoint_proceeded = breakpoint_proceeded;
2145 inf_status->restore_stack_info = restore_stack_info;
2146 inf_status->proceed_to_finish = proceed_to_finish;
2147
2148 memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES);
2149
2150 read_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2151
2152 record_selected_frame (&(inf_status->selected_frame_address),
2153 &(inf_status->selected_level));
2154 return;
2155 }
2156
2157 struct restore_selected_frame_args {
2158 CORE_ADDR frame_address;
2159 int level;
2160 };
2161
2162 static int restore_selected_frame PARAMS ((char *));
2163
2164 /* Restore the selected frame. args is really a struct
2165 restore_selected_frame_args * (declared as char * for catch_errors)
2166 telling us what frame to restore. Returns 1 for success, or 0 for
2167 failure. An error message will have been printed on error. */
2168
2169 static int
2170 restore_selected_frame (args)
2171 char *args;
2172 {
2173 struct restore_selected_frame_args *fr =
2174 (struct restore_selected_frame_args *) args;
2175 struct frame_info *frame;
2176 int level = fr->level;
2177
2178 frame = find_relative_frame (get_current_frame (), &level);
2179
2180 /* If inf_status->selected_frame_address is NULL, there was no
2181 previously selected frame. */
2182 if (frame == NULL ||
2183 FRAME_FP (frame) != fr->frame_address ||
2184 level != 0)
2185 {
2186 warning ("Unable to restore previously selected frame.\n");
2187 return 0;
2188 }
2189 select_frame (frame, fr->level);
2190 return(1);
2191 }
2192
2193 void
2194 restore_inferior_status (inf_status)
2195 struct inferior_status *inf_status;
2196 {
2197 stop_signal = inf_status->stop_signal;
2198 stop_pc = inf_status->stop_pc;
2199 stop_step = inf_status->stop_step;
2200 stop_stack_dummy = inf_status->stop_stack_dummy;
2201 stopped_by_random_signal = inf_status->stopped_by_random_signal;
2202 trap_expected = inf_status->trap_expected;
2203 step_range_start = inf_status->step_range_start;
2204 step_range_end = inf_status->step_range_end;
2205 step_frame_address = inf_status->step_frame_address;
2206 step_over_calls = inf_status->step_over_calls;
2207 stop_after_trap = inf_status->stop_after_trap;
2208 stop_soon_quietly = inf_status->stop_soon_quietly;
2209 bpstat_clear (&stop_bpstat);
2210 stop_bpstat = inf_status->stop_bpstat;
2211 breakpoint_proceeded = inf_status->breakpoint_proceeded;
2212 proceed_to_finish = inf_status->proceed_to_finish;
2213
2214 memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES);
2215
2216 /* The inferior can be gone if the user types "print exit(0)"
2217 (and perhaps other times). */
2218 if (target_has_execution)
2219 write_register_bytes (0, inf_status->registers, REGISTER_BYTES);
2220
2221 /* The inferior can be gone if the user types "print exit(0)"
2222 (and perhaps other times). */
2223
2224 /* FIXME: If we are being called after stopping in a function which
2225 is called from gdb, we should not be trying to restore the
2226 selected frame; it just prints a spurious error message (The
2227 message is useful, however, in detecting bugs in gdb (like if gdb
2228 clobbers the stack)). In fact, should we be restoring the
2229 inferior status at all in that case? . */
2230
2231 if (target_has_stack && inf_status->restore_stack_info)
2232 {
2233 struct restore_selected_frame_args fr;
2234 fr.level = inf_status->selected_level;
2235 fr.frame_address = inf_status->selected_frame_address;
2236 /* The point of catch_errors is that if the stack is clobbered,
2237 walking the stack might encounter a garbage pointer and error()
2238 trying to dereference it. */
2239 if (catch_errors (restore_selected_frame, &fr,
2240 "Unable to restore previously selected frame:\n",
2241 RETURN_MASK_ERROR) == 0)
2242 /* Error in restoring the selected frame. Select the innermost
2243 frame. */
2244 select_frame (get_current_frame (), 0);
2245 }
2246 }
2247
2248 \f
2249 void
2250 _initialize_infrun ()
2251 {
2252 register int i;
2253 register int numsigs;
2254
2255 add_info ("signals", signals_info,
2256 "What debugger does when program gets various signals.\n\
2257 Specify a signal as argument to print info on that signal only.");
2258 add_info_alias ("handle", "signals", 0);
2259
2260 add_com ("handle", class_run, handle_command,
2261 concat ("Specify how to handle a signal.\n\
2262 Args are signals and actions to apply to those signals.\n\
2263 Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\
2264 from 1-15 are allowed for compatibility with old versions of GDB.\n\
2265 Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\
2266 The special arg \"all\" is recognized to mean all signals except those\n\
2267 used by the debugger, typically SIGTRAP and SIGINT.\n",
2268 "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\
2269 \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\
2270 Stop means reenter debugger if this signal happens (implies print).\n\
2271 Print means print a message if this signal happens.\n\
2272 Pass means let program see this signal; otherwise program doesn't know.\n\
2273 Ignore is a synonym for nopass and noignore is a synonym for pass.\n\
2274 Pass and Stop may be combined.", NULL));
2275
2276 stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command,
2277 "There is no `stop' command, but you can set a hook on `stop'.\n\
2278 This allows you to set a list of commands to be run each time execution\n\
2279 of the program stops.", &cmdlist);
2280
2281 numsigs = (int)TARGET_SIGNAL_LAST;
2282 signal_stop = (unsigned char *)
2283 xmalloc (sizeof (signal_stop[0]) * numsigs);
2284 signal_print = (unsigned char *)
2285 xmalloc (sizeof (signal_print[0]) * numsigs);
2286 signal_program = (unsigned char *)
2287 xmalloc (sizeof (signal_program[0]) * numsigs);
2288 for (i = 0; i < numsigs; i++)
2289 {
2290 signal_stop[i] = 1;
2291 signal_print[i] = 1;
2292 signal_program[i] = 1;
2293 }
2294
2295 /* Signals caused by debugger's own actions
2296 should not be given to the program afterwards. */
2297 signal_program[TARGET_SIGNAL_TRAP] = 0;
2298 signal_program[TARGET_SIGNAL_INT] = 0;
2299
2300 /* Signals that are not errors should not normally enter the debugger. */
2301 signal_stop[TARGET_SIGNAL_ALRM] = 0;
2302 signal_print[TARGET_SIGNAL_ALRM] = 0;
2303 signal_stop[TARGET_SIGNAL_VTALRM] = 0;
2304 signal_print[TARGET_SIGNAL_VTALRM] = 0;
2305 signal_stop[TARGET_SIGNAL_PROF] = 0;
2306 signal_print[TARGET_SIGNAL_PROF] = 0;
2307 signal_stop[TARGET_SIGNAL_CHLD] = 0;
2308 signal_print[TARGET_SIGNAL_CHLD] = 0;
2309 signal_stop[TARGET_SIGNAL_IO] = 0;
2310 signal_print[TARGET_SIGNAL_IO] = 0;
2311 signal_stop[TARGET_SIGNAL_POLL] = 0;
2312 signal_print[TARGET_SIGNAL_POLL] = 0;
2313 signal_stop[TARGET_SIGNAL_URG] = 0;
2314 signal_print[TARGET_SIGNAL_URG] = 0;
2315
2316 #ifdef SOLIB_ADD
2317 add_show_from_set
2318 (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger,
2319 (char *) &stop_on_solib_events,
2320 "Set stopping for shared library events.\n\
2321 If nonzero, gdb will give control to the user when the dynamic linker\n\
2322 notifies gdb of shared library events. The most common event of interest\n\
2323 to the user would be loading/unloading of a new library.\n",
2324 &setlist),
2325 &showlist);
2326 #endif
2327 }
This page took 0.074265 seconds and 5 git commands to generate.