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