]>
Commit | Line | Data |
---|---|---|
3aa6856a | 1 | /* Target-struct-independent code to start (run) and stop an inferior process. |
30875e1c | 2 | Copyright 1986, 1987, 1988, 1989, 1991, 1992 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
3b271cf4 | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
3b271cf4 JG |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
3b271cf4 | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
3b271cf4 JG |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 RP |
19 | |
20 | /* Notes on the algorithm used in wait_for_inferior to determine if we | |
21 | just did a subroutine call when stepping. We have the following | |
22 | information at that point: | |
23 | ||
24 | Current and previous (just before this step) pc. | |
25 | Current and previous sp. | |
26 | Current and previous start of current function. | |
27 | ||
e140f1da | 28 | If the starts of the functions don't match, then |
bd5635a1 RP |
29 | |
30 | a) We did a subroutine call. | |
31 | ||
32 | In this case, the pc will be at the beginning of a function. | |
33 | ||
34 | b) We did a subroutine return. | |
35 | ||
36 | Otherwise. | |
37 | ||
38 | c) We did a longjmp. | |
39 | ||
40 | If we did a longjump, we were doing "nexti", since a next would | |
41 | have attempted to skip over the assembly language routine in which | |
42 | the longjmp is coded and would have simply been the equivalent of a | |
43 | continue. I consider this ok behaivior. We'd like one of two | |
44 | things to happen if we are doing a nexti through the longjmp() | |
45 | routine: 1) It behaves as a stepi, or 2) It acts like a continue as | |
46 | above. Given that this is a special case, and that anybody who | |
47 | thinks that the concept of sub calls is meaningful in the context | |
48 | of a longjmp, I'll take either one. Let's see what happens. | |
49 | ||
50 | Acts like a subroutine return. I can handle that with no problem | |
51 | at all. | |
52 | ||
53 | -->So: If the current and previous beginnings of the current | |
54 | function don't match, *and* the pc is at the start of a function, | |
55 | we've done a subroutine call. If the pc is not at the start of a | |
56 | function, we *didn't* do a subroutine call. | |
57 | ||
58 | -->If the beginnings of the current and previous function do match, | |
59 | either: | |
60 | ||
61 | a) We just did a recursive call. | |
62 | ||
63 | In this case, we would be at the very beginning of a | |
64 | function and 1) it will have a prologue (don't jump to | |
65 | before prologue, or 2) (we assume here that it doesn't have | |
66 | a prologue) there will have been a change in the stack | |
67 | pointer over the last instruction. (Ie. it's got to put | |
68 | the saved pc somewhere. The stack is the usual place. In | |
69 | a recursive call a register is only an option if there's a | |
70 | prologue to do something with it. This is even true on | |
71 | register window machines; the prologue sets up the new | |
72 | window. It might not be true on a register window machine | |
73 | where the call instruction moved the register window | |
74 | itself. Hmmm. One would hope that the stack pointer would | |
75 | also change. If it doesn't, somebody send me a note, and | |
76 | I'll work out a more general theory. | |
77 | [email protected]). This is true (albeit slipperly | |
78 | so) on all machines I'm aware of: | |
79 | ||
80 | m68k: Call changes stack pointer. Regular jumps don't. | |
81 | ||
82 | sparc: Recursive calls must have frames and therefor, | |
83 | prologues. | |
84 | ||
85 | vax: All calls have frames and hence change the | |
86 | stack pointer. | |
87 | ||
88 | b) We did a return from a recursive call. I don't see that we | |
89 | have either the ability or the need to distinguish this | |
90 | from an ordinary jump. The stack frame will be printed | |
91 | when and if the frame pointer changes; if we are in a | |
92 | function without a frame pointer, it's the users own | |
93 | lookout. | |
94 | ||
95 | c) We did a jump within a function. We assume that this is | |
96 | true if we didn't do a recursive call. | |
97 | ||
98 | d) We are in no-man's land ("I see no symbols here"). We | |
99 | don't worry about this; it will make calls look like simple | |
100 | jumps (and the stack frames will be printed when the frame | |
101 | pointer moves), which is a reasonably non-violent response. | |
bd5635a1 | 102 | */ |
bd5635a1 | 103 | |
bd5635a1 | 104 | #include "defs.h" |
d747e0af | 105 | #include <string.h> |
a6b98cb9 | 106 | #include <ctype.h> |
bd5635a1 RP |
107 | #include "symtab.h" |
108 | #include "frame.h" | |
109 | #include "inferior.h" | |
110 | #include "breakpoint.h" | |
111 | #include "wait.h" | |
112 | #include "gdbcore.h" | |
3950a34e | 113 | #include "gdbcmd.h" |
bd5635a1 RP |
114 | #include "target.h" |
115 | ||
116 | #include <signal.h> | |
117 | ||
118 | /* unistd.h is needed to #define X_OK */ | |
119 | #ifdef USG | |
120 | #include <unistd.h> | |
121 | #else | |
122 | #include <sys/file.h> | |
123 | #endif | |
124 | ||
30875e1c | 125 | /* Prototypes for local functions */ |
bd5635a1 | 126 | |
30875e1c | 127 | static void |
e37a6e9c | 128 | signals_info PARAMS ((char *, int)); |
619fd145 | 129 | |
30875e1c SG |
130 | static void |
131 | handle_command PARAMS ((char *, int)); | |
132 | ||
133 | static void | |
134 | sig_print_info PARAMS ((int)); | |
135 | ||
136 | static void | |
137 | sig_print_header PARAMS ((void)); | |
138 | ||
139 | static void | |
140 | remove_step_breakpoint PARAMS ((void)); | |
bd5635a1 | 141 | |
30875e1c SG |
142 | static void |
143 | insert_step_breakpoint PARAMS ((void)); | |
144 | ||
30875e1c SG |
145 | static void |
146 | resume_cleanups PARAMS ((int)); | |
147 | ||
3950a34e RP |
148 | static int |
149 | hook_stop_stub PARAMS ((char *)); | |
150 | ||
bd5635a1 RP |
151 | /* Sigtramp is a routine that the kernel calls (which then calls the |
152 | signal handler). On most machines it is a library routine that | |
153 | is linked into the executable. | |
154 | ||
155 | This macro, given a program counter value and the name of the | |
156 | function in which that PC resides (which can be null if the | |
157 | name is not known), returns nonzero if the PC and name show | |
158 | that we are in sigtramp. | |
159 | ||
160 | On most machines just see if the name is sigtramp (and if we have | |
161 | no name, assume we are not in sigtramp). */ | |
162 | #if !defined (IN_SIGTRAMP) | |
163 | #define IN_SIGTRAMP(pc, name) \ | |
680c9dfa | 164 | (name && !strcmp ("_sigtramp", name)) |
bd5635a1 RP |
165 | #endif |
166 | ||
30875e1c SG |
167 | /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the |
168 | program. It needs to examine the jmp_buf argument and extract the PC | |
169 | from it. The return value is non-zero on success, zero otherwise. */ | |
170 | #ifndef GET_LONGJMP_TARGET | |
171 | #define GET_LONGJMP_TARGET(PC_ADDR) 0 | |
172 | #endif | |
173 | ||
d747e0af MT |
174 | |
175 | /* Some machines have trampoline code that sits between function callers | |
176 | and the actual functions themselves. If this machine doesn't have | |
177 | such things, disable their processing. */ | |
178 | #ifndef SKIP_TRAMPOLINE_CODE | |
179 | #define SKIP_TRAMPOLINE_CODE(pc) 0 | |
180 | #endif | |
181 | ||
1eeba686 PB |
182 | /* For SVR4 shared libraries, each call goes through a small piece of |
183 | trampoline code in the ".init" section. IN_SOLIB_TRAMPOLINE evaluates | |
184 | to nonzero if we are current stopped in one of these. */ | |
185 | #ifndef IN_SOLIB_TRAMPOLINE | |
186 | #define IN_SOLIB_TRAMPOLINE(pc,name) 0 | |
187 | #endif | |
d747e0af | 188 | |
9f739abd SG |
189 | /* On some systems, the PC may be left pointing at an instruction that won't |
190 | actually be executed. This is usually indicated by a bit in the PSW. If | |
191 | we find ourselves in such a state, then we step the target beyond the | |
192 | nullified instruction before returning control to the user so as to avoid | |
193 | confusion. */ | |
194 | ||
195 | #ifndef INSTRUCTION_NULLIFIED | |
196 | #define INSTRUCTION_NULLIFIED 0 | |
197 | #endif | |
198 | ||
d747e0af MT |
199 | #ifdef TDESC |
200 | #include "tdesc.h" | |
201 | int safe_to_init_tdesc_context = 0; | |
202 | extern dc_dcontext_t current_context; | |
203 | #endif | |
204 | ||
bd5635a1 RP |
205 | /* Tables of how to react to signals; the user sets them. */ |
206 | ||
072b552a JG |
207 | static unsigned char *signal_stop; |
208 | static unsigned char *signal_print; | |
209 | static unsigned char *signal_program; | |
210 | ||
211 | #define SET_SIGS(nsigs,sigs,flags) \ | |
212 | do { \ | |
213 | int signum = (nsigs); \ | |
214 | while (signum-- > 0) \ | |
215 | if ((sigs)[signum]) \ | |
216 | (flags)[signum] = 1; \ | |
217 | } while (0) | |
218 | ||
219 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
220 | do { \ | |
221 | int signum = (nsigs); \ | |
222 | while (signum-- > 0) \ | |
223 | if ((sigs)[signum]) \ | |
224 | (flags)[signum] = 0; \ | |
225 | } while (0) | |
bd5635a1 | 226 | |
3950a34e RP |
227 | |
228 | /* Command list pointer for the "stop" placeholder. */ | |
229 | ||
230 | static struct cmd_list_element *stop_command; | |
231 | ||
bd5635a1 | 232 | /* Nonzero if breakpoints are now inserted in the inferior. */ |
bd5635a1 | 233 | |
3950a34e | 234 | static int breakpoints_inserted; |
bd5635a1 RP |
235 | |
236 | /* Function inferior was in as of last step command. */ | |
237 | ||
238 | static struct symbol *step_start_function; | |
239 | ||
240 | /* Nonzero => address for special breakpoint for resuming stepping. */ | |
241 | ||
242 | static CORE_ADDR step_resume_break_address; | |
243 | ||
244 | /* Pointer to orig contents of the byte where the special breakpoint is. */ | |
245 | ||
246 | static char step_resume_break_shadow[BREAKPOINT_MAX]; | |
247 | ||
248 | /* Nonzero means the special breakpoint is a duplicate | |
249 | so it has not itself been inserted. */ | |
250 | ||
251 | static int step_resume_break_duplicate; | |
252 | ||
253 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ | |
254 | ||
255 | static int trap_expected; | |
256 | ||
257 | /* Nonzero if the next time we try to continue the inferior, it will | |
258 | step one instruction and generate a spurious trace trap. | |
259 | This is used to compensate for a bug in HP-UX. */ | |
260 | ||
261 | static int trap_expected_after_continue; | |
262 | ||
263 | /* Nonzero means expecting a trace trap | |
264 | and should stop the inferior and return silently when it happens. */ | |
265 | ||
266 | int stop_after_trap; | |
267 | ||
268 | /* Nonzero means expecting a trap and caller will handle it themselves. | |
269 | It is used after attach, due to attaching to a process; | |
270 | when running in the shell before the child program has been exec'd; | |
271 | and when running some kinds of remote stuff (FIXME?). */ | |
272 | ||
273 | int stop_soon_quietly; | |
274 | ||
275 | /* Nonzero if pc has been changed by the debugger | |
276 | since the inferior stopped. */ | |
277 | ||
278 | int pc_changed; | |
279 | ||
280 | /* Nonzero if proceed is being used for a "finish" command or a similar | |
281 | situation when stop_registers should be saved. */ | |
282 | ||
283 | int proceed_to_finish; | |
284 | ||
285 | /* Save register contents here when about to pop a stack dummy frame, | |
286 | if-and-only-if proceed_to_finish is set. | |
287 | Thus this contains the return value from the called function (assuming | |
288 | values are returned in a register). */ | |
289 | ||
290 | char stop_registers[REGISTER_BYTES]; | |
291 | ||
292 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ | |
293 | ||
294 | static int breakpoints_failed; | |
295 | ||
296 | /* Nonzero after stop if current stack frame should be printed. */ | |
297 | ||
298 | static int stop_print_frame; | |
299 | ||
300 | #ifdef NO_SINGLE_STEP | |
301 | extern int one_stepped; /* From machine dependent code */ | |
302 | extern void single_step (); /* Same. */ | |
303 | #endif /* NO_SINGLE_STEP */ | |
304 | ||
a71d17b1 JK |
305 | \f |
306 | /* Things to clean up if we QUIT out of resume (). */ | |
e1ce8aa5 | 307 | /* ARGSUSED */ |
a71d17b1 JK |
308 | static void |
309 | resume_cleanups (arg) | |
310 | int arg; | |
311 | { | |
312 | normal_stop (); | |
313 | } | |
314 | ||
315 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
316 | wants to interrupt some lengthy single-stepping operation | |
317 | (for child processes, the SIGINT goes to the inferior, and so | |
318 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
319 | other targets, that's not true). | |
320 | ||
321 | STEP nonzero if we should step (zero to continue instead). | |
322 | SIG is the signal to give the inferior (zero for none). */ | |
310cc570 | 323 | void |
a71d17b1 JK |
324 | resume (step, sig) |
325 | int step; | |
326 | int sig; | |
327 | { | |
328 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); | |
329 | QUIT; | |
d11c44f1 JG |
330 | |
331 | #ifdef NO_SINGLE_STEP | |
332 | if (step) { | |
818de002 | 333 | single_step(sig); /* Do it the hard way, w/temp breakpoints */ |
d11c44f1 JG |
334 | step = 0; /* ...and don't ask hardware to do it. */ |
335 | } | |
336 | #endif | |
337 | ||
bdbd5f50 JG |
338 | /* Handle any optimized stores to the inferior NOW... */ |
339 | #ifdef DO_DEFERRED_STORES | |
340 | DO_DEFERRED_STORES; | |
341 | #endif | |
342 | ||
a71d17b1 JK |
343 | target_resume (step, sig); |
344 | discard_cleanups (old_cleanups); | |
345 | } | |
346 | ||
bd5635a1 RP |
347 | \f |
348 | /* Clear out all variables saying what to do when inferior is continued. | |
349 | First do this, then set the ones you want, then call `proceed'. */ | |
350 | ||
351 | void | |
352 | clear_proceed_status () | |
353 | { | |
354 | trap_expected = 0; | |
355 | step_range_start = 0; | |
356 | step_range_end = 0; | |
357 | step_frame_address = 0; | |
358 | step_over_calls = -1; | |
359 | step_resume_break_address = 0; | |
360 | stop_after_trap = 0; | |
361 | stop_soon_quietly = 0; | |
362 | proceed_to_finish = 0; | |
363 | breakpoint_proceeded = 1; /* We're about to proceed... */ | |
364 | ||
365 | /* Discard any remaining commands or status from previous stop. */ | |
366 | bpstat_clear (&stop_bpstat); | |
367 | } | |
368 | ||
369 | /* Basic routine for continuing the program in various fashions. | |
370 | ||
371 | ADDR is the address to resume at, or -1 for resume where stopped. | |
372 | SIGGNAL is the signal to give it, or 0 for none, | |
373 | or -1 for act according to how it stopped. | |
374 | STEP is nonzero if should trap after one instruction. | |
375 | -1 means return after that and print nothing. | |
376 | You should probably set various step_... variables | |
377 | before calling here, if you are stepping. | |
378 | ||
379 | You should call clear_proceed_status before calling proceed. */ | |
380 | ||
381 | void | |
382 | proceed (addr, siggnal, step) | |
383 | CORE_ADDR addr; | |
384 | int siggnal; | |
385 | int step; | |
386 | { | |
387 | int oneproc = 0; | |
388 | ||
389 | if (step > 0) | |
390 | step_start_function = find_pc_function (read_pc ()); | |
391 | if (step < 0) | |
392 | stop_after_trap = 1; | |
393 | ||
bdbd5f50 | 394 | if (addr == (CORE_ADDR)-1) |
bd5635a1 RP |
395 | { |
396 | /* If there is a breakpoint at the address we will resume at, | |
397 | step one instruction before inserting breakpoints | |
398 | so that we do not stop right away. */ | |
399 | ||
400 | if (!pc_changed && breakpoint_here_p (read_pc ())) | |
401 | oneproc = 1; | |
402 | } | |
403 | else | |
404 | { | |
405 | write_register (PC_REGNUM, addr); | |
406 | #ifdef NPC_REGNUM | |
407 | write_register (NPC_REGNUM, addr + 4); | |
408 | #ifdef NNPC_REGNUM | |
409 | write_register (NNPC_REGNUM, addr + 8); | |
410 | #endif | |
411 | #endif | |
412 | } | |
413 | ||
414 | if (trap_expected_after_continue) | |
415 | { | |
416 | /* If (step == 0), a trap will be automatically generated after | |
417 | the first instruction is executed. Force step one | |
418 | instruction to clear this condition. This should not occur | |
419 | if step is nonzero, but it is harmless in that case. */ | |
420 | oneproc = 1; | |
421 | trap_expected_after_continue = 0; | |
422 | } | |
423 | ||
424 | if (oneproc) | |
425 | /* We will get a trace trap after one instruction. | |
426 | Continue it automatically and insert breakpoints then. */ | |
427 | trap_expected = 1; | |
428 | else | |
429 | { | |
430 | int temp = insert_breakpoints (); | |
431 | if (temp) | |
432 | { | |
433 | print_sys_errmsg ("ptrace", temp); | |
434 | error ("Cannot insert breakpoints.\n\ | |
435 | The same program may be running in another process."); | |
436 | } | |
437 | breakpoints_inserted = 1; | |
438 | } | |
439 | ||
440 | /* Install inferior's terminal modes. */ | |
441 | target_terminal_inferior (); | |
442 | ||
443 | if (siggnal >= 0) | |
444 | stop_signal = siggnal; | |
445 | /* If this signal should not be seen by program, | |
446 | give it zero. Used for debugging signals. */ | |
447 | else if (stop_signal < NSIG && !signal_program[stop_signal]) | |
448 | stop_signal= 0; | |
449 | ||
bd5635a1 | 450 | /* Resume inferior. */ |
a71d17b1 | 451 | resume (oneproc || step || bpstat_should_step (), stop_signal); |
bd5635a1 RP |
452 | |
453 | /* Wait for it to stop (if not standalone) | |
454 | and in any case decode why it stopped, and act accordingly. */ | |
455 | ||
456 | wait_for_inferior (); | |
457 | normal_stop (); | |
458 | } | |
459 | ||
bd5635a1 RP |
460 | /* Record the pc and sp of the program the last time it stopped. |
461 | These are just used internally by wait_for_inferior, but need | |
462 | to be preserved over calls to it and cleared when the inferior | |
463 | is started. */ | |
464 | static CORE_ADDR prev_pc; | |
465 | static CORE_ADDR prev_sp; | |
466 | static CORE_ADDR prev_func_start; | |
467 | static char *prev_func_name; | |
468 | ||
a71d17b1 | 469 | \f |
bd5635a1 RP |
470 | /* Start remote-debugging of a machine over a serial link. */ |
471 | ||
472 | void | |
473 | start_remote () | |
474 | { | |
475 | init_wait_for_inferior (); | |
476 | clear_proceed_status (); | |
477 | stop_soon_quietly = 1; | |
478 | trap_expected = 0; | |
98885d76 JK |
479 | wait_for_inferior (); |
480 | normal_stop (); | |
bd5635a1 RP |
481 | } |
482 | ||
483 | /* Initialize static vars when a new inferior begins. */ | |
484 | ||
485 | void | |
486 | init_wait_for_inferior () | |
487 | { | |
488 | /* These are meaningless until the first time through wait_for_inferior. */ | |
489 | prev_pc = 0; | |
490 | prev_sp = 0; | |
491 | prev_func_start = 0; | |
492 | prev_func_name = NULL; | |
493 | ||
494 | trap_expected_after_continue = 0; | |
495 | breakpoints_inserted = 0; | |
496 | mark_breakpoints_out (); | |
497 | stop_signal = 0; /* Don't confuse first call to proceed(). */ | |
498 | } | |
499 | ||
500 | ||
bd5635a1 RP |
501 | \f |
502 | /* Wait for control to return from inferior to debugger. | |
503 | If inferior gets a signal, we may decide to start it up again | |
504 | instead of returning. That is why there is a loop in this function. | |
505 | When this function actually returns it means the inferior | |
506 | should be left stopped and GDB should read more commands. */ | |
507 | ||
508 | void | |
509 | wait_for_inferior () | |
510 | { | |
511 | WAITTYPE w; | |
512 | int another_trap; | |
513 | int random_signal; | |
514 | CORE_ADDR stop_sp; | |
515 | CORE_ADDR stop_func_start; | |
516 | char *stop_func_name; | |
d747e0af | 517 | CORE_ADDR prologue_pc, tmp; |
bd5635a1 RP |
518 | int stop_step_resume_break; |
519 | struct symtab_and_line sal; | |
520 | int remove_breakpoints_on_following_step = 0; | |
b3b39c0c | 521 | int current_line; |
30875e1c | 522 | int handling_longjmp = 0; /* FIXME */ |
a8a69e63 | 523 | struct symtab *symtab; |
bd5635a1 | 524 | |
b3b39c0c SG |
525 | sal = find_pc_line(prev_pc, 0); |
526 | current_line = sal.line; | |
527 | ||
bd5635a1 RP |
528 | while (1) |
529 | { | |
530 | /* Clean up saved state that will become invalid. */ | |
531 | pc_changed = 0; | |
532 | flush_cached_frames (); | |
533 | registers_changed (); | |
534 | ||
535 | target_wait (&w); | |
536 | ||
1eeba686 PB |
537 | #ifdef SIGTRAP_STOP_AFTER_LOAD |
538 | ||
539 | /* Somebody called load(2), and it gave us a "trap signal after load". | |
540 | Ignore it gracefully. */ | |
541 | ||
542 | SIGTRAP_STOP_AFTER_LOAD (w); | |
543 | #endif | |
544 | ||
bd5635a1 RP |
545 | /* See if the process still exists; clean up if it doesn't. */ |
546 | if (WIFEXITED (w)) | |
547 | { | |
548 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
549 | if (WEXITSTATUS (w)) | |
e37a6e9c | 550 | printf_filtered ("\nProgram exited with code 0%o.\n", |
bd5635a1 RP |
551 | (unsigned int)WEXITSTATUS (w)); |
552 | else | |
553 | if (!batch_mode()) | |
e37a6e9c | 554 | printf_filtered ("\nProgram exited normally.\n"); |
bd5635a1 RP |
555 | fflush (stdout); |
556 | target_mourn_inferior (); | |
557 | #ifdef NO_SINGLE_STEP | |
558 | one_stepped = 0; | |
559 | #endif | |
560 | stop_print_frame = 0; | |
561 | break; | |
562 | } | |
563 | else if (!WIFSTOPPED (w)) | |
564 | { | |
565 | stop_print_frame = 0; | |
566 | stop_signal = WTERMSIG (w); | |
567 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
30875e1c | 568 | target_kill (); /* kill mourns as well */ |
bd5635a1 | 569 | #ifdef PRINT_RANDOM_SIGNAL |
e37a6e9c | 570 | printf_filtered ("\nProgram terminated: "); |
bd5635a1 RP |
571 | PRINT_RANDOM_SIGNAL (stop_signal); |
572 | #else | |
e37a6e9c PB |
573 | printf_filtered ("\nProgram terminated with signal %d, %s\n", |
574 | stop_signal, safe_strsignal (stop_signal)); | |
bd5635a1 | 575 | #endif |
e37a6e9c | 576 | printf_filtered ("The inferior process no longer exists.\n"); |
bd5635a1 RP |
577 | fflush (stdout); |
578 | #ifdef NO_SINGLE_STEP | |
579 | one_stepped = 0; | |
580 | #endif | |
581 | break; | |
582 | } | |
583 | ||
584 | #ifdef NO_SINGLE_STEP | |
585 | if (one_stepped) | |
586 | single_step (0); /* This actually cleans up the ss */ | |
587 | #endif /* NO_SINGLE_STEP */ | |
588 | ||
9f739abd SG |
589 | /* If PC is pointing at a nullified instruction, then step beyond it so that |
590 | the user won't be confused when GDB appears to be ready to execute it. */ | |
591 | ||
592 | if (INSTRUCTION_NULLIFIED) | |
593 | { | |
594 | resume (1, 0); | |
595 | continue; | |
596 | } | |
597 | ||
bd5635a1 RP |
598 | stop_pc = read_pc (); |
599 | set_current_frame ( create_new_frame (read_register (FP_REGNUM), | |
600 | read_pc ())); | |
601 | ||
602 | stop_frame_address = FRAME_FP (get_current_frame ()); | |
603 | stop_sp = read_register (SP_REGNUM); | |
604 | stop_func_start = 0; | |
605 | stop_func_name = 0; | |
606 | /* Don't care about return value; stop_func_start and stop_func_name | |
607 | will both be 0 if it doesn't work. */ | |
072b552a | 608 | find_pc_partial_function (stop_pc, &stop_func_name, &stop_func_start); |
bd5635a1 RP |
609 | stop_func_start += FUNCTION_START_OFFSET; |
610 | another_trap = 0; | |
611 | bpstat_clear (&stop_bpstat); | |
612 | stop_step = 0; | |
613 | stop_stack_dummy = 0; | |
614 | stop_print_frame = 1; | |
615 | stop_step_resume_break = 0; | |
616 | random_signal = 0; | |
617 | stopped_by_random_signal = 0; | |
618 | breakpoints_failed = 0; | |
619 | ||
620 | /* Look at the cause of the stop, and decide what to do. | |
621 | The alternatives are: | |
622 | 1) break; to really stop and return to the debugger, | |
623 | 2) drop through to start up again | |
624 | (set another_trap to 1 to single step once) | |
625 | 3) set random_signal to 1, and the decision between 1 and 2 | |
626 | will be made according to the signal handling tables. */ | |
627 | ||
628 | stop_signal = WSTOPSIG (w); | |
629 | ||
630 | /* First, distinguish signals caused by the debugger from signals | |
631 | that have to do with the program's own actions. | |
632 | Note that breakpoint insns may cause SIGTRAP or SIGILL | |
633 | or SIGEMT, depending on the operating system version. | |
634 | Here we detect when a SIGILL or SIGEMT is really a breakpoint | |
635 | and change it to SIGTRAP. */ | |
636 | ||
637 | if (stop_signal == SIGTRAP | |
638 | || (breakpoints_inserted && | |
639 | (stop_signal == SIGILL | |
e37a6e9c PB |
640 | #ifdef SIGEMT |
641 | || stop_signal == SIGEMT | |
642 | #endif | |
643 | )) | |
bd5635a1 RP |
644 | || stop_soon_quietly) |
645 | { | |
646 | if (stop_signal == SIGTRAP && stop_after_trap) | |
647 | { | |
648 | stop_print_frame = 0; | |
649 | break; | |
650 | } | |
651 | if (stop_soon_quietly) | |
652 | break; | |
653 | ||
654 | /* Don't even think about breakpoints | |
655 | if just proceeded over a breakpoint. | |
656 | ||
657 | However, if we are trying to proceed over a breakpoint | |
658 | and end up in sigtramp, then step_resume_break_address | |
659 | will be set and we should check whether we've hit the | |
660 | step breakpoint. */ | |
661 | if (stop_signal == SIGTRAP && trap_expected | |
818de002 | 662 | && step_resume_break_address == 0) |
bd5635a1 RP |
663 | bpstat_clear (&stop_bpstat); |
664 | else | |
665 | { | |
666 | /* See if there is a breakpoint at the current PC. */ | |
667 | #if DECR_PC_AFTER_BREAK | |
668 | /* Notice the case of stepping through a jump | |
30875e1c | 669 | that lands just after a breakpoint. |
bd5635a1 RP |
670 | Don't confuse that with hitting the breakpoint. |
671 | What we check for is that 1) stepping is going on | |
672 | and 2) the pc before the last insn does not match | |
673 | the address of the breakpoint before the current pc. */ | |
30875e1c SG |
674 | if (prev_pc == stop_pc - DECR_PC_AFTER_BREAK |
675 | || !step_range_end | |
676 | || step_resume_break_address | |
677 | || handling_longjmp /* FIXME */) | |
bd5635a1 RP |
678 | #endif /* DECR_PC_AFTER_BREAK not zero */ |
679 | { | |
680 | /* See if we stopped at the special breakpoint for | |
681 | stepping over a subroutine call. If both are zero, | |
682 | this wasn't the reason for the stop. */ | |
30875e1c SG |
683 | if (step_resume_break_address |
684 | && stop_pc - DECR_PC_AFTER_BREAK | |
685 | == step_resume_break_address) | |
bd5635a1 RP |
686 | { |
687 | stop_step_resume_break = 1; | |
688 | if (DECR_PC_AFTER_BREAK) | |
689 | { | |
690 | stop_pc -= DECR_PC_AFTER_BREAK; | |
691 | write_register (PC_REGNUM, stop_pc); | |
692 | pc_changed = 0; | |
693 | } | |
694 | } | |
695 | else | |
696 | { | |
697 | stop_bpstat = | |
698 | bpstat_stop_status (&stop_pc, stop_frame_address); | |
699 | /* Following in case break condition called a | |
700 | function. */ | |
701 | stop_print_frame = 1; | |
702 | } | |
703 | } | |
704 | } | |
705 | ||
706 | if (stop_signal == SIGTRAP) | |
707 | random_signal | |
708 | = !(bpstat_explains_signal (stop_bpstat) | |
709 | || trap_expected | |
710 | || stop_step_resume_break | |
711 | || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address) | |
712 | || (step_range_end && !step_resume_break_address)); | |
713 | else | |
714 | { | |
715 | random_signal | |
716 | = !(bpstat_explains_signal (stop_bpstat) | |
717 | || stop_step_resume_break | |
718 | /* End of a stack dummy. Some systems (e.g. Sony | |
719 | news) give another signal besides SIGTRAP, | |
720 | so check here as well as above. */ | |
d747e0af | 721 | || PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address) |
bd5635a1 RP |
722 | ); |
723 | if (!random_signal) | |
724 | stop_signal = SIGTRAP; | |
725 | } | |
726 | } | |
727 | else | |
728 | random_signal = 1; | |
729 | ||
730 | /* For the program's own signals, act according to | |
731 | the signal handling tables. */ | |
732 | ||
733 | if (random_signal) | |
734 | { | |
735 | /* Signal not for debugging purposes. */ | |
736 | int printed = 0; | |
737 | ||
738 | stopped_by_random_signal = 1; | |
739 | ||
740 | if (stop_signal >= NSIG | |
741 | || signal_print[stop_signal]) | |
742 | { | |
743 | printed = 1; | |
744 | target_terminal_ours_for_output (); | |
745 | #ifdef PRINT_RANDOM_SIGNAL | |
746 | PRINT_RANDOM_SIGNAL (stop_signal); | |
747 | #else | |
e37a6e9c PB |
748 | printf_filtered ("\nProgram received signal %d, %s\n", |
749 | stop_signal, safe_strsignal (stop_signal)); | |
bd5635a1 RP |
750 | #endif /* PRINT_RANDOM_SIGNAL */ |
751 | fflush (stdout); | |
752 | } | |
753 | if (stop_signal >= NSIG | |
754 | || signal_stop[stop_signal]) | |
755 | break; | |
756 | /* If not going to stop, give terminal back | |
757 | if we took it away. */ | |
758 | else if (printed) | |
759 | target_terminal_inferior (); | |
b7f81b57 JG |
760 | |
761 | /* Note that virtually all the code below does `if !random_signal'. | |
762 | Perhaps this code should end with a goto or continue. At least | |
763 | one (now fixed) bug was caused by this -- a !random_signal was | |
764 | missing in one of the tests below. */ | |
bd5635a1 | 765 | } |
30875e1c | 766 | |
bd5635a1 | 767 | /* Handle cases caused by hitting a breakpoint. */ |
bd5635a1 | 768 | |
30875e1c SG |
769 | if (!random_signal) |
770 | if (bpstat_explains_signal (stop_bpstat)) | |
771 | { | |
772 | CORE_ADDR jmp_buf_pc; | |
773 | ||
774 | switch (stop_bpstat->breakpoint_at->type) /* FIXME */ | |
775 | { | |
776 | /* If we hit the breakpoint at longjmp, disable it for the | |
777 | duration of this command. Then, install a temporary | |
778 | breakpoint at the target of the jmp_buf. */ | |
779 | case bp_longjmp: | |
780 | disable_longjmp_breakpoint(); | |
781 | remove_breakpoints (); | |
782 | breakpoints_inserted = 0; | |
783 | if (!GET_LONGJMP_TARGET(&jmp_buf_pc)) goto keep_going; | |
784 | ||
785 | /* Need to blow away step-resume breakpoint, as it | |
786 | interferes with us */ | |
787 | remove_step_breakpoint (); | |
818de002 | 788 | step_resume_break_address = 0; |
30875e1c SG |
789 | stop_step_resume_break = 0; |
790 | ||
791 | #if 0 /* FIXME - Need to implement nested temporary breakpoints */ | |
792 | if (step_over_calls > 0) | |
793 | set_longjmp_resume_breakpoint(jmp_buf_pc, | |
794 | get_current_frame()); | |
795 | else | |
796 | #endif /* 0 */ | |
797 | set_longjmp_resume_breakpoint(jmp_buf_pc, NULL); | |
798 | handling_longjmp = 1; /* FIXME */ | |
799 | goto keep_going; | |
800 | ||
801 | case bp_longjmp_resume: | |
802 | remove_breakpoints (); | |
803 | breakpoints_inserted = 0; | |
804 | #if 0 /* FIXME - Need to implement nested temporary breakpoints */ | |
805 | if (step_over_calls | |
806 | && (stop_frame_address | |
807 | INNER_THAN step_frame_address)) | |
808 | { | |
809 | another_trap = 1; | |
810 | goto keep_going; | |
811 | } | |
812 | #endif /* 0 */ | |
813 | disable_longjmp_breakpoint(); | |
814 | handling_longjmp = 0; /* FIXME */ | |
815 | break; | |
816 | ||
817 | default: | |
818 | fprintf(stderr, "Unknown breakpoint type %d\n", | |
819 | stop_bpstat->breakpoint_at->type); | |
820 | case bp_watchpoint: | |
821 | case bp_breakpoint: | |
822 | case bp_until: | |
823 | case bp_finish: | |
824 | /* Does a breakpoint want us to stop? */ | |
825 | if (bpstat_stop (stop_bpstat)) | |
826 | { | |
827 | stop_print_frame = bpstat_should_print (stop_bpstat); | |
828 | goto stop_stepping; | |
829 | } | |
830 | /* Otherwise, must remove breakpoints and single-step | |
831 | to get us past the one we hit. */ | |
832 | else | |
833 | { | |
834 | remove_breakpoints (); | |
835 | remove_step_breakpoint (); | |
836 | breakpoints_inserted = 0; | |
837 | another_trap = 1; | |
838 | } | |
839 | break; | |
840 | } | |
841 | } | |
842 | else if (stop_step_resume_break) | |
843 | { | |
844 | /* But if we have hit the step-resumption breakpoint, | |
845 | remove it. It has done its job getting us here. | |
846 | The sp test is to make sure that we don't get hung | |
847 | up in recursive calls in functions without frame | |
848 | pointers. If the stack pointer isn't outside of | |
849 | where the breakpoint was set (within a routine to be | |
850 | stepped over), we're in the middle of a recursive | |
851 | call. Not true for reg window machines (sparc) | |
852 | because the must change frames to call things and | |
853 | the stack pointer doesn't have to change if it | |
854 | the bp was set in a routine without a frame (pc can | |
855 | be stored in some other window). | |
856 | ||
857 | The removal of the sp test is to allow calls to | |
858 | alloca. Nasty things were happening. Oh, well, | |
859 | gdb can only handle one level deep of lack of | |
860 | frame pointer. */ | |
861 | ||
862 | /* | |
863 | Disable test for step_frame_address match so that we always stop even if the | |
864 | frames don't match. Reason: if we hit the step_resume_breakpoint, there is | |
865 | no way to temporarily disable it so that we can step past it. If we leave | |
866 | the breakpoint in, then we loop forever repeatedly hitting, but never | |
867 | getting past the breakpoint. This change keeps nexting over recursive | |
868 | function calls from hanging gdb. | |
869 | */ | |
870 | #if 0 | |
871 | if (* step_frame_address == 0 | |
872 | || (step_frame_address == stop_frame_address)) | |
cc221e76 | 873 | #endif |
30875e1c SG |
874 | { |
875 | remove_step_breakpoint (); | |
876 | step_resume_break_address = 0; | |
877 | ||
878 | /* If were waiting for a trap, hitting the step_resume_break | |
879 | doesn't count as getting it. */ | |
880 | if (trap_expected) | |
881 | another_trap = 1; | |
882 | } | |
883 | } | |
884 | ||
885 | /* We come here if we hit a breakpoint but should not | |
886 | stop for it. Possibly we also were stepping | |
887 | and should stop for that. So fall through and | |
888 | test for stepping. But, if not stepping, | |
889 | do not stop. */ | |
890 | ||
bd5635a1 RP |
891 | /* If this is the breakpoint at the end of a stack dummy, |
892 | just stop silently. */ | |
b7f81b57 JG |
893 | if (!random_signal |
894 | && PC_IN_CALL_DUMMY (stop_pc, stop_sp, stop_frame_address)) | |
bd5635a1 RP |
895 | { |
896 | stop_print_frame = 0; | |
897 | stop_stack_dummy = 1; | |
898 | #ifdef HP_OS_BUG | |
899 | trap_expected_after_continue = 1; | |
900 | #endif | |
901 | break; | |
902 | } | |
903 | ||
904 | if (step_resume_break_address) | |
905 | /* Having a step-resume breakpoint overrides anything | |
906 | else having to do with stepping commands until | |
907 | that breakpoint is reached. */ | |
908 | ; | |
909 | /* If stepping through a line, keep going if still within it. */ | |
910 | else if (!random_signal | |
911 | && step_range_end | |
912 | && stop_pc >= step_range_start | |
913 | && stop_pc < step_range_end | |
914 | /* The step range might include the start of the | |
915 | function, so if we are at the start of the | |
916 | step range and either the stack or frame pointers | |
917 | just changed, we've stepped outside */ | |
918 | && !(stop_pc == step_range_start | |
919 | && stop_frame_address | |
920 | && (stop_sp INNER_THAN prev_sp | |
921 | || stop_frame_address != step_frame_address))) | |
922 | { | |
d747e0af | 923 | ; |
bd5635a1 RP |
924 | } |
925 | ||
926 | /* We stepped out of the stepping range. See if that was due | |
927 | to a subroutine call that we should proceed to the end of. */ | |
928 | else if (!random_signal && step_range_end) | |
929 | { | |
930 | if (stop_func_start) | |
931 | { | |
932 | prologue_pc = stop_func_start; | |
933 | SKIP_PROLOGUE (prologue_pc); | |
934 | } | |
935 | ||
936 | /* Did we just take a signal? */ | |
937 | if (IN_SIGTRAMP (stop_pc, stop_func_name) | |
938 | && !IN_SIGTRAMP (prev_pc, prev_func_name)) | |
939 | { | |
940 | /* This code is needed at least in the following case: | |
941 | The user types "next" and then a signal arrives (before | |
942 | the "next" is done). */ | |
943 | /* We've just taken a signal; go until we are back to | |
944 | the point where we took it and one more. */ | |
945 | step_resume_break_address = prev_pc; | |
946 | step_resume_break_duplicate = | |
947 | breakpoint_here_p (step_resume_break_address); | |
948 | if (breakpoints_inserted) | |
949 | insert_step_breakpoint (); | |
950 | /* Make sure that the stepping range gets us past | |
951 | that instruction. */ | |
952 | if (step_range_end == 1) | |
953 | step_range_end = (step_range_start = prev_pc) + 1; | |
954 | remove_breakpoints_on_following_step = 1; | |
d747e0af | 955 | goto save_pc; |
bd5635a1 RP |
956 | } |
957 | ||
958 | /* ==> See comments at top of file on this algorithm. <==*/ | |
959 | ||
1eeba686 PB |
960 | if ((stop_pc == stop_func_start |
961 | || IN_SOLIB_TRAMPOLINE (stop_pc, stop_func_name)) | |
962 | && (stop_func_start != prev_func_start | |
963 | || prologue_pc != stop_func_start | |
964 | || stop_sp != prev_sp)) | |
bd5635a1 | 965 | { |
d747e0af MT |
966 | /* It's a subroutine call. |
967 | (0) If we are not stepping over any calls ("stepi"), we | |
968 | just stop. | |
969 | (1) If we're doing a "next", we want to continue through | |
970 | the call ("step over the call"). | |
971 | (2) If we are in a function-call trampoline (a stub between | |
972 | the calling routine and the real function), locate | |
973 | the real function and change stop_func_start. | |
974 | (3) If we're doing a "step", and there are no debug symbols | |
975 | at the target of the call, we want to continue through | |
976 | it ("step over the call"). | |
977 | (4) Otherwise, we want to stop soon, after the function | |
978 | prologue ("step into the call"). */ | |
979 | ||
980 | if (step_over_calls == 0) | |
bd5635a1 | 981 | { |
d747e0af MT |
982 | /* I presume that step_over_calls is only 0 when we're |
983 | supposed to be stepping at the assembly language level. */ | |
984 | stop_step = 1; | |
985 | break; | |
986 | } | |
30875e1c | 987 | |
d747e0af MT |
988 | if (step_over_calls > 0) |
989 | goto step_over_function; | |
30875e1c | 990 | |
d747e0af | 991 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); |
318bf84f | 992 | if (tmp != 0) |
d747e0af MT |
993 | stop_func_start = tmp; |
994 | ||
9f739abd | 995 | symtab = find_pc_symtab (stop_func_start); |
a8a69e63 FF |
996 | if (symtab && LINETABLE (symtab)) |
997 | goto step_into_function; | |
d747e0af MT |
998 | |
999 | step_over_function: | |
1000 | /* A subroutine call has happened. */ | |
1001 | /* Set a special breakpoint after the return */ | |
1002 | step_resume_break_address = | |
1003 | ADDR_BITS_REMOVE | |
1004 | (SAVED_PC_AFTER_CALL (get_current_frame ())); | |
1005 | step_resume_break_duplicate | |
1006 | = breakpoint_here_p (step_resume_break_address); | |
1007 | if (breakpoints_inserted) | |
1008 | insert_step_breakpoint (); | |
1009 | goto save_pc; | |
1010 | ||
1011 | step_into_function: | |
bd5635a1 RP |
1012 | /* Subroutine call with source code we should not step over. |
1013 | Do step to the first line of code in it. */ | |
d747e0af MT |
1014 | SKIP_PROLOGUE (stop_func_start); |
1015 | sal = find_pc_line (stop_func_start, 0); | |
1016 | /* Use the step_resume_break to step until | |
1017 | the end of the prologue, even if that involves jumps | |
1018 | (as it seems to on the vax under 4.2). */ | |
1019 | /* If the prologue ends in the middle of a source line, | |
1020 | continue to the end of that source line. | |
1021 | Otherwise, just go to end of prologue. */ | |
bd5635a1 | 1022 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP |
d747e0af MT |
1023 | /* no, don't either. It skips any code that's |
1024 | legitimately on the first line. */ | |
bd5635a1 | 1025 | #else |
d747e0af MT |
1026 | if (sal.end && sal.pc != stop_func_start) |
1027 | stop_func_start = sal.end; | |
bd5635a1 | 1028 | #endif |
d747e0af MT |
1029 | |
1030 | if (stop_func_start == stop_pc) | |
30875e1c | 1031 | { |
d747e0af | 1032 | /* We are already there: stop now. */ |
30875e1c SG |
1033 | stop_step = 1; |
1034 | break; | |
d747e0af MT |
1035 | } |
1036 | else | |
1037 | /* Put the step-breakpoint there and go until there. */ | |
30875e1c | 1038 | { |
d747e0af MT |
1039 | step_resume_break_address = stop_func_start; |
1040 | ||
1041 | step_resume_break_duplicate | |
1042 | = breakpoint_here_p (step_resume_break_address); | |
1043 | if (breakpoints_inserted) | |
1044 | insert_step_breakpoint (); | |
1045 | /* Do not specify what the fp should be when we stop | |
1046 | since on some machines the prologue | |
1047 | is where the new fp value is established. */ | |
1048 | step_frame_address = 0; | |
1049 | /* And make sure stepping stops right away then. */ | |
1050 | step_range_end = step_range_start; | |
30875e1c | 1051 | } |
d747e0af | 1052 | goto save_pc; |
bd5635a1 | 1053 | } |
d747e0af MT |
1054 | |
1055 | /* We've wandered out of the step range (but haven't done a | |
1056 | subroutine call or return). */ | |
1057 | ||
1058 | sal = find_pc_line(stop_pc, 0); | |
1059 | ||
1060 | if (step_range_end == 1 || /* stepi or nexti */ | |
1061 | sal.line == 0 || /* ...or no line # info */ | |
1062 | (stop_pc == sal.pc /* ...or we're at the start */ | |
1063 | && current_line != sal.line)) { /* of a different line */ | |
1064 | /* Stop because we're done stepping. */ | |
1065 | stop_step = 1; | |
1066 | break; | |
1067 | } else { | |
1068 | /* We aren't done stepping, and we have line number info for $pc. | |
1069 | Optimize by setting the step_range for the line. | |
1070 | (We might not be in the original line, but if we entered a | |
1071 | new line in mid-statement, we continue stepping. This makes | |
1072 | things like for(;;) statements work better.) */ | |
1073 | step_range_start = sal.pc; | |
1074 | step_range_end = sal.end; | |
1075 | goto save_pc; | |
1076 | } | |
318bf84f | 1077 | /* We never fall through here */ |
bd5635a1 RP |
1078 | } |
1079 | ||
d747e0af MT |
1080 | if (trap_expected |
1081 | && IN_SIGTRAMP (stop_pc, stop_func_name) | |
1082 | && !IN_SIGTRAMP (prev_pc, prev_func_name)) | |
bd5635a1 RP |
1083 | { |
1084 | /* What has happened here is that we have just stepped the inferior | |
1085 | with a signal (because it is a signal which shouldn't make | |
1086 | us stop), thus stepping into sigtramp. | |
1087 | ||
1088 | So we need to set a step_resume_break_address breakpoint | |
1089 | and continue until we hit it, and then step. */ | |
1090 | step_resume_break_address = prev_pc; | |
1091 | /* Always 1, I think, but it's probably easier to have | |
1092 | the step_resume_break as usual rather than trying to | |
1093 | re-use the breakpoint which is already there. */ | |
1094 | step_resume_break_duplicate = | |
1095 | breakpoint_here_p (step_resume_break_address); | |
1096 | if (breakpoints_inserted) | |
1097 | insert_step_breakpoint (); | |
1098 | remove_breakpoints_on_following_step = 1; | |
1099 | another_trap = 1; | |
1100 | } | |
1101 | ||
30875e1c SG |
1102 | /* My apologies to the gods of structured programming. */ |
1103 | /* Come to this label when you need to resume the inferior. It's really much | |
1104 | cleaner at this time to do a goto than to try and figure out what the | |
1105 | if-else chain ought to look like!! */ | |
1106 | ||
1107 | keep_going: | |
1108 | ||
d747e0af | 1109 | save_pc: |
bd5635a1 RP |
1110 | /* Save the pc before execution, to compare with pc after stop. */ |
1111 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ | |
1112 | prev_func_start = stop_func_start; /* Ok, since if DECR_PC_AFTER | |
1113 | BREAK is defined, the | |
1114 | original pc would not have | |
1115 | been at the start of a | |
1116 | function. */ | |
1117 | prev_func_name = stop_func_name; | |
1118 | prev_sp = stop_sp; | |
1119 | ||
1120 | /* If we did not do break;, it means we should keep | |
1121 | running the inferior and not return to debugger. */ | |
1122 | ||
1123 | if (trap_expected && stop_signal != SIGTRAP) | |
1124 | { | |
1125 | /* We took a signal (which we are supposed to pass through to | |
1126 | the inferior, else we'd have done a break above) and we | |
1127 | haven't yet gotten our trap. Simply continue. */ | |
a71d17b1 | 1128 | resume ((step_range_end && !step_resume_break_address) |
bd5635a1 RP |
1129 | || (trap_expected && !step_resume_break_address) |
1130 | || bpstat_should_step (), | |
1131 | stop_signal); | |
1132 | } | |
1133 | else | |
1134 | { | |
1135 | /* Either the trap was not expected, but we are continuing | |
1136 | anyway (the user asked that this signal be passed to the | |
1137 | child) | |
1138 | -- or -- | |
1139 | The signal was SIGTRAP, e.g. it was our signal, but we | |
1140 | decided we should resume from it. | |
1141 | ||
1142 | We're going to run this baby now! | |
1143 | ||
1144 | Insert breakpoints now, unless we are trying | |
1145 | to one-proceed past a breakpoint. */ | |
1146 | /* If we've just finished a special step resume and we don't | |
1147 | want to hit a breakpoint, pull em out. */ | |
1148 | if (!step_resume_break_address && | |
1149 | remove_breakpoints_on_following_step) | |
1150 | { | |
1151 | remove_breakpoints_on_following_step = 0; | |
1152 | remove_breakpoints (); | |
1153 | breakpoints_inserted = 0; | |
1154 | } | |
1155 | else if (!breakpoints_inserted && | |
818de002 | 1156 | (step_resume_break_address != 0 || !another_trap)) |
bd5635a1 RP |
1157 | { |
1158 | insert_step_breakpoint (); | |
1159 | breakpoints_failed = insert_breakpoints (); | |
1160 | if (breakpoints_failed) | |
1161 | break; | |
1162 | breakpoints_inserted = 1; | |
1163 | } | |
1164 | ||
1165 | trap_expected = another_trap; | |
1166 | ||
1167 | if (stop_signal == SIGTRAP) | |
1168 | stop_signal = 0; | |
1169 | ||
1170 | #ifdef SHIFT_INST_REGS | |
1171 | /* I'm not sure when this following segment applies. I do know, now, | |
1172 | that we shouldn't rewrite the regs when we were stopped by a | |
1173 | random signal from the inferior process. */ | |
1174 | ||
d11c44f1 JG |
1175 | if (!bpstat_explains_signal (stop_bpstat) |
1176 | && (stop_signal != SIGCLD) | |
bd5635a1 RP |
1177 | && !stopped_by_random_signal) |
1178 | { | |
1179 | CORE_ADDR pc_contents = read_register (PC_REGNUM); | |
1180 | CORE_ADDR npc_contents = read_register (NPC_REGNUM); | |
1181 | if (pc_contents != npc_contents) | |
1182 | { | |
1183 | write_register (NNPC_REGNUM, npc_contents); | |
1184 | write_register (NPC_REGNUM, pc_contents); | |
1185 | } | |
1186 | } | |
1187 | #endif /* SHIFT_INST_REGS */ | |
1188 | ||
30875e1c SG |
1189 | resume ((!step_resume_break_address |
1190 | && !handling_longjmp | |
1191 | && (step_range_end | |
1192 | || trap_expected)) | |
bd5635a1 RP |
1193 | || bpstat_should_step (), |
1194 | stop_signal); | |
1195 | } | |
1196 | } | |
30875e1c SG |
1197 | |
1198 | stop_stepping: | |
bd5635a1 RP |
1199 | if (target_has_execution) |
1200 | { | |
1201 | /* Assuming the inferior still exists, set these up for next | |
1202 | time, just like we did above if we didn't break out of the | |
1203 | loop. */ | |
1204 | prev_pc = read_pc (); | |
1205 | prev_func_start = stop_func_start; | |
1206 | prev_func_name = stop_func_name; | |
1207 | prev_sp = stop_sp; | |
1208 | } | |
1209 | } | |
1210 | \f | |
1211 | /* Here to return control to GDB when the inferior stops for real. | |
1212 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
1213 | ||
1214 | STOP_PRINT_FRAME nonzero means print the executing frame | |
1215 | (pc, function, args, file, line number and line text). | |
1216 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
1217 | attempting to insert breakpoints. */ | |
1218 | ||
1219 | void | |
1220 | normal_stop () | |
1221 | { | |
1222 | /* Make sure that the current_frame's pc is correct. This | |
1223 | is a correction for setting up the frame info before doing | |
1224 | DECR_PC_AFTER_BREAK */ | |
1225 | if (target_has_execution) | |
1226 | (get_current_frame ())->pc = read_pc (); | |
1227 | ||
1228 | if (breakpoints_failed) | |
1229 | { | |
1230 | target_terminal_ours_for_output (); | |
1231 | print_sys_errmsg ("ptrace", breakpoints_failed); | |
e37a6e9c | 1232 | printf_filtered ("Stopped; cannot insert breakpoints.\n\ |
bd5635a1 RP |
1233 | The same program may be running in another process.\n"); |
1234 | } | |
1235 | ||
1236 | if (target_has_execution) | |
1237 | remove_step_breakpoint (); | |
1238 | ||
1239 | if (target_has_execution && breakpoints_inserted) | |
1240 | if (remove_breakpoints ()) | |
1241 | { | |
1242 | target_terminal_ours_for_output (); | |
e37a6e9c | 1243 | printf_filtered ("Cannot remove breakpoints because program is no longer writable.\n\ |
bd5635a1 RP |
1244 | It might be running in another process.\n\ |
1245 | Further execution is probably impossible.\n"); | |
1246 | } | |
1247 | ||
1248 | breakpoints_inserted = 0; | |
1249 | ||
1250 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
1251 | Delete any breakpoint that is to be deleted at the next stop. */ | |
1252 | ||
1253 | breakpoint_auto_delete (stop_bpstat); | |
1254 | ||
1255 | /* If an auto-display called a function and that got a signal, | |
1256 | delete that auto-display to avoid an infinite recursion. */ | |
1257 | ||
1258 | if (stopped_by_random_signal) | |
1259 | disable_current_display (); | |
1260 | ||
1261 | if (step_multi && stop_step) | |
1262 | return; | |
1263 | ||
1264 | target_terminal_ours (); | |
1265 | ||
3950a34e RP |
1266 | /* Look up the hook_stop and run it if it exists. */ |
1267 | ||
1268 | if (stop_command->hook) | |
1269 | { | |
1270 | catch_errors (hook_stop_stub, (char *)stop_command->hook, | |
1271 | "Error while running hook_stop:\n"); | |
1272 | } | |
1273 | ||
bd5635a1 RP |
1274 | if (!target_has_stack) |
1275 | return; | |
1276 | ||
1277 | /* Select innermost stack frame except on return from a stack dummy routine, | |
1515ff18 JG |
1278 | or if the program has exited. Print it without a level number if |
1279 | we have changed functions or hit a breakpoint. Print source line | |
1280 | if we have one. */ | |
bd5635a1 RP |
1281 | if (!stop_stack_dummy) |
1282 | { | |
1283 | select_frame (get_current_frame (), 0); | |
1284 | ||
1285 | if (stop_print_frame) | |
1286 | { | |
1515ff18 JG |
1287 | int source_only; |
1288 | ||
1289 | source_only = bpstat_print (stop_bpstat); | |
1290 | source_only = source_only || | |
1291 | ( stop_step | |
bd5635a1 | 1292 | && step_frame_address == stop_frame_address |
1515ff18 JG |
1293 | && step_start_function == find_pc_function (stop_pc)); |
1294 | ||
1295 | print_stack_frame (selected_frame, -1, source_only? -1: 1); | |
bd5635a1 RP |
1296 | |
1297 | /* Display the auto-display expressions. */ | |
1298 | do_displays (); | |
1299 | } | |
1300 | } | |
1301 | ||
1302 | /* Save the function value return registers, if we care. | |
1303 | We might be about to restore their previous contents. */ | |
1304 | if (proceed_to_finish) | |
1305 | read_register_bytes (0, stop_registers, REGISTER_BYTES); | |
1306 | ||
1307 | if (stop_stack_dummy) | |
1308 | { | |
1309 | /* Pop the empty frame that contains the stack dummy. | |
1310 | POP_FRAME ends with a setting of the current frame, so we | |
1311 | can use that next. */ | |
1312 | POP_FRAME; | |
1313 | select_frame (get_current_frame (), 0); | |
1314 | } | |
1315 | } | |
3950a34e RP |
1316 | |
1317 | static int | |
1318 | hook_stop_stub (cmd) | |
1319 | char *cmd; | |
1320 | { | |
1321 | execute_user_command ((struct cmd_list_element *)cmd, 0); | |
a8a69e63 | 1322 | return (0); |
3950a34e RP |
1323 | } |
1324 | ||
bd5635a1 RP |
1325 | \f |
1326 | static void | |
1327 | insert_step_breakpoint () | |
1328 | { | |
1329 | if (step_resume_break_address && !step_resume_break_duplicate) | |
1330 | target_insert_breakpoint (step_resume_break_address, | |
1331 | step_resume_break_shadow); | |
1332 | } | |
1333 | ||
1334 | static void | |
1335 | remove_step_breakpoint () | |
1336 | { | |
1337 | if (step_resume_break_address && !step_resume_break_duplicate) | |
1338 | target_remove_breakpoint (step_resume_break_address, | |
1339 | step_resume_break_shadow); | |
1340 | } | |
1341 | \f | |
cc221e76 FF |
1342 | int signal_stop_state (signo) |
1343 | int signo; | |
1344 | { | |
1345 | return ((signo >= 0 && signo < NSIG) ? signal_stop[signo] : 0); | |
1346 | } | |
1347 | ||
1348 | int signal_print_state (signo) | |
1349 | int signo; | |
1350 | { | |
1351 | return ((signo >= 0 && signo < NSIG) ? signal_print[signo] : 0); | |
1352 | } | |
1353 | ||
1354 | int signal_pass_state (signo) | |
1355 | int signo; | |
1356 | { | |
1357 | return ((signo >= 0 && signo < NSIG) ? signal_program[signo] : 0); | |
1358 | } | |
1359 | ||
bd5635a1 RP |
1360 | static void |
1361 | sig_print_header () | |
1362 | { | |
1363 | printf_filtered ("Signal\t\tStop\tPrint\tPass to program\tDescription\n"); | |
1364 | } | |
1365 | ||
1366 | static void | |
1367 | sig_print_info (number) | |
1368 | int number; | |
1369 | { | |
e37a6e9c PB |
1370 | char *name; |
1371 | ||
1372 | if ((name = strsigno (number)) == NULL) | |
bd5635a1 RP |
1373 | printf_filtered ("%d\t\t", number); |
1374 | else | |
e37a6e9c | 1375 | printf_filtered ("%s (%d)\t", name, number); |
bd5635a1 RP |
1376 | printf_filtered ("%s\t", signal_stop[number] ? "Yes" : "No"); |
1377 | printf_filtered ("%s\t", signal_print[number] ? "Yes" : "No"); | |
1378 | printf_filtered ("%s\t\t", signal_program[number] ? "Yes" : "No"); | |
e37a6e9c | 1379 | printf_filtered ("%s\n", safe_strsignal (number)); |
bd5635a1 RP |
1380 | } |
1381 | ||
1382 | /* Specify how various signals in the inferior should be handled. */ | |
1383 | ||
1384 | static void | |
1385 | handle_command (args, from_tty) | |
1386 | char *args; | |
1387 | int from_tty; | |
1388 | { | |
072b552a JG |
1389 | char **argv; |
1390 | int digits, wordlen; | |
1391 | int sigfirst, signum, siglast; | |
1392 | int allsigs; | |
1393 | int nsigs; | |
1394 | unsigned char *sigs; | |
1395 | struct cleanup *old_chain; | |
1396 | ||
1397 | if (args == NULL) | |
1398 | { | |
1399 | error_no_arg ("signal to handle"); | |
1400 | } | |
bd5635a1 | 1401 | |
072b552a JG |
1402 | /* Allocate and zero an array of flags for which signals to handle. */ |
1403 | ||
1404 | nsigs = signo_max () + 1; | |
1405 | sigs = (unsigned char *) alloca (nsigs); | |
1406 | memset (sigs, 0, nsigs); | |
bd5635a1 | 1407 | |
072b552a JG |
1408 | /* Break the command line up into args. */ |
1409 | ||
1410 | argv = buildargv (args); | |
1411 | if (argv == NULL) | |
bd5635a1 | 1412 | { |
072b552a JG |
1413 | nomem (0); |
1414 | } | |
1415 | old_chain = make_cleanup (freeargv, (char *) argv); | |
bd5635a1 | 1416 | |
072b552a JG |
1417 | /* Walk through the args, looking for signal numbers, signal names, and |
1418 | actions. Signal numbers and signal names may be interspersed with | |
1419 | actions, with the actions being performed for all signals cumulatively | |
1420 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
bd5635a1 | 1421 | |
072b552a JG |
1422 | while (*argv != NULL) |
1423 | { | |
1424 | wordlen = strlen (*argv); | |
1425 | for (digits = 0; isdigit ((*argv)[digits]); digits++) {;} | |
1426 | allsigs = 0; | |
1427 | sigfirst = siglast = -1; | |
1428 | ||
1429 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
1430 | { | |
1431 | /* Apply action to all signals except those used by the | |
1432 | debugger. Silently skip those. */ | |
1433 | allsigs = 1; | |
1434 | sigfirst = 0; | |
1435 | siglast = nsigs - 1; | |
1436 | } | |
1437 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
1438 | { | |
1439 | SET_SIGS (nsigs, sigs, signal_stop); | |
1440 | SET_SIGS (nsigs, sigs, signal_print); | |
1441 | } | |
1442 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
1443 | { | |
1444 | UNSET_SIGS (nsigs, sigs, signal_program); | |
1445 | } | |
1446 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
1447 | { | |
1448 | SET_SIGS (nsigs, sigs, signal_print); | |
1449 | } | |
1450 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
1451 | { | |
1452 | SET_SIGS (nsigs, sigs, signal_program); | |
1453 | } | |
1454 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
1455 | { | |
1456 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
1457 | } | |
1458 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
1459 | { | |
1460 | SET_SIGS (nsigs, sigs, signal_program); | |
1461 | } | |
1462 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
1463 | { | |
1464 | UNSET_SIGS (nsigs, sigs, signal_print); | |
1465 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
1466 | } | |
1467 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
1468 | { | |
1469 | UNSET_SIGS (nsigs, sigs, signal_program); | |
1470 | } | |
1471 | else if (digits > 0) | |
bd5635a1 | 1472 | { |
072b552a JG |
1473 | sigfirst = siglast = atoi (*argv); |
1474 | if ((*argv)[digits] == '-') | |
bd5635a1 | 1475 | { |
072b552a | 1476 | siglast = atoi ((*argv) + digits + 1); |
bd5635a1 | 1477 | } |
072b552a | 1478 | if (sigfirst > siglast) |
bd5635a1 | 1479 | { |
072b552a JG |
1480 | /* Bet he didn't figure we'd think of this case... */ |
1481 | signum = sigfirst; | |
1482 | sigfirst = siglast; | |
1483 | siglast = signum; | |
bd5635a1 | 1484 | } |
072b552a JG |
1485 | if (sigfirst < 0 || sigfirst >= nsigs) |
1486 | { | |
1487 | error ("Signal %d not in range 0-%d", sigfirst, nsigs - 1); | |
1488 | } | |
1489 | if (siglast < 0 || siglast >= nsigs) | |
bd5635a1 | 1490 | { |
072b552a | 1491 | error ("Signal %d not in range 0-%d", siglast, nsigs - 1); |
bd5635a1 RP |
1492 | } |
1493 | } | |
072b552a | 1494 | else if ((signum = strtosigno (*argv)) != 0) |
bd5635a1 | 1495 | { |
072b552a | 1496 | sigfirst = siglast = signum; |
bd5635a1 | 1497 | } |
072b552a | 1498 | else |
bd5635a1 | 1499 | { |
072b552a JG |
1500 | /* Not a number and not a recognized flag word => complain. */ |
1501 | error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); | |
bd5635a1 | 1502 | } |
072b552a JG |
1503 | |
1504 | /* If any signal numbers or symbol names were found, set flags for | |
1505 | which signals to apply actions to. */ | |
1506 | ||
1507 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
bd5635a1 | 1508 | { |
072b552a JG |
1509 | switch (signum) |
1510 | { | |
1511 | case SIGTRAP: | |
1512 | case SIGINT: | |
1513 | if (!allsigs && !sigs[signum]) | |
1514 | { | |
1515 | if (query ("%s is used by the debugger.\nAre you sure you want to change it? ", strsigno (signum))) | |
1516 | { | |
1517 | sigs[signum] = 1; | |
1518 | } | |
1519 | else | |
1520 | { | |
1521 | printf ("Not confirmed, unchanged.\n"); | |
1522 | fflush (stdout); | |
1523 | } | |
1524 | } | |
1525 | break; | |
1526 | default: | |
1527 | sigs[signum] = 1; | |
1528 | break; | |
1529 | } | |
bd5635a1 RP |
1530 | } |
1531 | ||
072b552a | 1532 | argv++; |
bd5635a1 RP |
1533 | } |
1534 | ||
3950a34e | 1535 | target_notice_signals(); |
cc221e76 | 1536 | |
bd5635a1 RP |
1537 | if (from_tty) |
1538 | { | |
1539 | /* Show the results. */ | |
1540 | sig_print_header (); | |
072b552a JG |
1541 | for (signum = 0; signum < nsigs; signum++) |
1542 | { | |
1543 | if (sigs[signum]) | |
1544 | { | |
1545 | sig_print_info (signum); | |
1546 | } | |
1547 | } | |
bd5635a1 | 1548 | } |
072b552a JG |
1549 | |
1550 | do_cleanups (old_chain); | |
bd5635a1 RP |
1551 | } |
1552 | ||
1553 | /* Print current contents of the tables set by the handle command. */ | |
1554 | ||
1555 | static void | |
e37a6e9c | 1556 | signals_info (signum_exp, from_tty) |
bd5635a1 | 1557 | char *signum_exp; |
e37a6e9c | 1558 | int from_tty; |
bd5635a1 RP |
1559 | { |
1560 | register int i; | |
1561 | sig_print_header (); | |
1562 | ||
1563 | if (signum_exp) | |
1564 | { | |
1565 | /* First see if this is a symbol name. */ | |
e37a6e9c PB |
1566 | i = strtosigno (signum_exp); |
1567 | if (i == 0) | |
bd5635a1 RP |
1568 | { |
1569 | /* Nope, maybe it's an address which evaluates to a signal | |
1570 | number. */ | |
1571 | i = parse_and_eval_address (signum_exp); | |
1572 | if (i >= NSIG || i < 0) | |
1573 | error ("Signal number out of bounds."); | |
1574 | } | |
1575 | sig_print_info (i); | |
1576 | return; | |
1577 | } | |
1578 | ||
1579 | printf_filtered ("\n"); | |
1580 | for (i = 0; i < NSIG; i++) | |
1581 | { | |
1582 | QUIT; | |
1583 | ||
1584 | sig_print_info (i); | |
1585 | } | |
1586 | ||
1587 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); | |
1588 | } | |
1589 | \f | |
1590 | /* Save all of the information associated with the inferior<==>gdb | |
1591 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
1592 | (defined in inferior.h). */ | |
1593 | ||
1594 | void | |
1595 | save_inferior_status (inf_status, restore_stack_info) | |
1596 | struct inferior_status *inf_status; | |
1597 | int restore_stack_info; | |
1598 | { | |
1599 | inf_status->pc_changed = pc_changed; | |
1600 | inf_status->stop_signal = stop_signal; | |
1601 | inf_status->stop_pc = stop_pc; | |
1602 | inf_status->stop_frame_address = stop_frame_address; | |
1603 | inf_status->stop_step = stop_step; | |
1604 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
1605 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
1606 | inf_status->trap_expected = trap_expected; | |
1607 | inf_status->step_range_start = step_range_start; | |
1608 | inf_status->step_range_end = step_range_end; | |
1609 | inf_status->step_frame_address = step_frame_address; | |
1610 | inf_status->step_over_calls = step_over_calls; | |
1611 | inf_status->step_resume_break_address = step_resume_break_address; | |
1612 | inf_status->stop_after_trap = stop_after_trap; | |
1613 | inf_status->stop_soon_quietly = stop_soon_quietly; | |
1614 | /* Save original bpstat chain here; replace it with copy of chain. | |
1615 | If caller's caller is walking the chain, they'll be happier if we | |
1616 | hand them back the original chain when restore_i_s is called. */ | |
1617 | inf_status->stop_bpstat = stop_bpstat; | |
1618 | stop_bpstat = bpstat_copy (stop_bpstat); | |
1619 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
1620 | inf_status->restore_stack_info = restore_stack_info; | |
1621 | inf_status->proceed_to_finish = proceed_to_finish; | |
1622 | ||
072b552a | 1623 | memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); |
bd5635a1 RP |
1624 | |
1625 | record_selected_frame (&(inf_status->selected_frame_address), | |
1626 | &(inf_status->selected_level)); | |
1627 | return; | |
1628 | } | |
1629 | ||
1630 | void | |
1631 | restore_inferior_status (inf_status) | |
1632 | struct inferior_status *inf_status; | |
1633 | { | |
1634 | FRAME fid; | |
1635 | int level = inf_status->selected_level; | |
1636 | ||
1637 | pc_changed = inf_status->pc_changed; | |
1638 | stop_signal = inf_status->stop_signal; | |
1639 | stop_pc = inf_status->stop_pc; | |
1640 | stop_frame_address = inf_status->stop_frame_address; | |
1641 | stop_step = inf_status->stop_step; | |
1642 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
1643 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
1644 | trap_expected = inf_status->trap_expected; | |
1645 | step_range_start = inf_status->step_range_start; | |
1646 | step_range_end = inf_status->step_range_end; | |
1647 | step_frame_address = inf_status->step_frame_address; | |
1648 | step_over_calls = inf_status->step_over_calls; | |
1649 | step_resume_break_address = inf_status->step_resume_break_address; | |
1650 | stop_after_trap = inf_status->stop_after_trap; | |
1651 | stop_soon_quietly = inf_status->stop_soon_quietly; | |
1652 | bpstat_clear (&stop_bpstat); | |
1653 | stop_bpstat = inf_status->stop_bpstat; | |
1654 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
1655 | proceed_to_finish = inf_status->proceed_to_finish; | |
1656 | ||
072b552a | 1657 | memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); |
bd5635a1 RP |
1658 | |
1659 | /* The inferior can be gone if the user types "print exit(0)" | |
1660 | (and perhaps other times). */ | |
1661 | if (target_has_stack && inf_status->restore_stack_info) | |
1662 | { | |
1663 | fid = find_relative_frame (get_current_frame (), | |
1664 | &level); | |
1665 | ||
777bef06 JK |
1666 | /* If inf_status->selected_frame_address is NULL, there was no |
1667 | previously selected frame. */ | |
bd5635a1 RP |
1668 | if (fid == 0 || |
1669 | FRAME_FP (fid) != inf_status->selected_frame_address || | |
1670 | level != 0) | |
1671 | { | |
d747e0af | 1672 | #if 1 |
bd5635a1 RP |
1673 | /* I'm not sure this error message is a good idea. I have |
1674 | only seen it occur after "Can't continue previously | |
1675 | requested operation" (we get called from do_cleanups), in | |
1676 | which case it just adds insult to injury (one confusing | |
1677 | error message after another. Besides which, does the | |
1678 | user really care if we can't restore the previously | |
1679 | selected frame? */ | |
1680 | fprintf (stderr, "Unable to restore previously selected frame.\n"); | |
1681 | #endif | |
1682 | select_frame (get_current_frame (), 0); | |
1683 | return; | |
1684 | } | |
1685 | ||
1686 | select_frame (fid, inf_status->selected_level); | |
1687 | } | |
1688 | } | |
1689 | ||
1690 | \f | |
1691 | void | |
1692 | _initialize_infrun () | |
1693 | { | |
1694 | register int i; | |
e37a6e9c | 1695 | register int numsigs; |
bd5635a1 RP |
1696 | |
1697 | add_info ("signals", signals_info, | |
1698 | "What debugger does when program gets various signals.\n\ | |
1699 | Specify a signal number as argument to print info on that signal only."); | |
6b50c5c2 | 1700 | add_info_alias ("handle", "signals", 0); |
bd5635a1 RP |
1701 | |
1702 | add_com ("handle", class_run, handle_command, | |
1703 | "Specify how to handle a signal.\n\ | |
072b552a JG |
1704 | Args are signal numbers and actions to apply to those signals.\n\ |
1705 | Signal numbers may be numeric (ex. 11) or symbolic (ex. SIGSEGV).\n\ | |
1706 | Numeric ranges may be specified with the form LOW-HIGH (ex. 14-21).\n\ | |
1707 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1708 | used by the debugger, typically SIGTRAP and SIGINT.\n\ | |
1709 | Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
1710 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ | |
bd5635a1 | 1711 | Stop means reenter debugger if this signal happens (implies print).\n\ |
072b552a | 1712 | Print means print a message if this signal happens.\n\ |
bd5635a1 | 1713 | Pass means let program see this signal; otherwise program doesn't know.\n\ |
072b552a | 1714 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ |
bd5635a1 RP |
1715 | Pass and Stop may be combined."); |
1716 | ||
a8a69e63 | 1717 | stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command, |
3950a34e RP |
1718 | "There is no `stop' command, but you can set a hook on `stop'.\n\ |
1719 | This allows you to set a list of commands to be run each time execution\n\ | |
1720 | of the inferior program stops.", &cmdlist); | |
1721 | ||
e37a6e9c | 1722 | numsigs = signo_max () + 1; |
072b552a JG |
1723 | signal_stop = (unsigned char *) |
1724 | xmalloc (sizeof (signal_stop[0]) * numsigs); | |
1725 | signal_print = (unsigned char *) | |
1726 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
1727 | signal_program = (unsigned char *) | |
1728 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
e37a6e9c | 1729 | for (i = 0; i < numsigs; i++) |
bd5635a1 RP |
1730 | { |
1731 | signal_stop[i] = 1; | |
1732 | signal_print[i] = 1; | |
1733 | signal_program[i] = 1; | |
1734 | } | |
1735 | ||
1736 | /* Signals caused by debugger's own actions | |
1737 | should not be given to the program afterwards. */ | |
1738 | signal_program[SIGTRAP] = 0; | |
1739 | signal_program[SIGINT] = 0; | |
1740 | ||
1741 | /* Signals that are not errors should not normally enter the debugger. */ | |
1742 | #ifdef SIGALRM | |
1743 | signal_stop[SIGALRM] = 0; | |
1744 | signal_print[SIGALRM] = 0; | |
1745 | #endif /* SIGALRM */ | |
1746 | #ifdef SIGVTALRM | |
1747 | signal_stop[SIGVTALRM] = 0; | |
1748 | signal_print[SIGVTALRM] = 0; | |
1749 | #endif /* SIGVTALRM */ | |
1750 | #ifdef SIGPROF | |
1751 | signal_stop[SIGPROF] = 0; | |
1752 | signal_print[SIGPROF] = 0; | |
1753 | #endif /* SIGPROF */ | |
1754 | #ifdef SIGCHLD | |
1755 | signal_stop[SIGCHLD] = 0; | |
1756 | signal_print[SIGCHLD] = 0; | |
1757 | #endif /* SIGCHLD */ | |
1758 | #ifdef SIGCLD | |
1759 | signal_stop[SIGCLD] = 0; | |
1760 | signal_print[SIGCLD] = 0; | |
1761 | #endif /* SIGCLD */ | |
1762 | #ifdef SIGIO | |
1763 | signal_stop[SIGIO] = 0; | |
1764 | signal_print[SIGIO] = 0; | |
1765 | #endif /* SIGIO */ | |
1766 | #ifdef SIGURG | |
1767 | signal_stop[SIGURG] = 0; | |
1768 | signal_print[SIGURG] = 0; | |
1769 | #endif /* SIGURG */ | |
1770 | } |