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