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