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