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