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