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