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