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