Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Target-struct-independent code to start (run) and stop an inferior process. |
7a292a7a | 2 | Copyright 1986-1989, 1991-1999 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
c906108c | 10 | |
c5aa993b JM |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
c906108c | 15 | |
c5aa993b JM |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "gdb_string.h" | |
23 | #include <ctype.h> | |
24 | #include "symtab.h" | |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
27 | #include "breakpoint.h" | |
28 | #include "wait.h" | |
29 | #include "gdbcore.h" | |
30 | #include "gdbcmd.h" | |
31 | #include "target.h" | |
32 | #include "gdbthread.h" | |
33 | #include "annotate.h" | |
34 | #include "symfile.h" /* for overlay functions */ | |
7a292a7a | 35 | #include "top.h" |
c906108c | 36 | #include <signal.h> |
43ff13b4 | 37 | #include "event-loop.h" |
c906108c SS |
38 | |
39 | /* Prototypes for local functions */ | |
40 | ||
41 | static void signals_info PARAMS ((char *, int)); | |
42 | ||
43 | static void handle_command PARAMS ((char *, int)); | |
44 | ||
45 | static void sig_print_info PARAMS ((enum target_signal)); | |
46 | ||
47 | static void sig_print_header PARAMS ((void)); | |
48 | ||
49 | static void resume_cleanups PARAMS ((int)); | |
50 | ||
51 | static int hook_stop_stub PARAMS ((PTR)); | |
52 | ||
53 | static void delete_breakpoint_current_contents PARAMS ((PTR)); | |
54 | ||
c5aa993b | 55 | static void set_follow_fork_mode_command PARAMS ((char *arg, int from_tty, struct cmd_list_element * c)); |
7a292a7a | 56 | |
43ff13b4 JM |
57 | static void complete_execution PARAMS ((void)); |
58 | ||
c906108c SS |
59 | int inferior_ignoring_startup_exec_events = 0; |
60 | int inferior_ignoring_leading_exec_events = 0; | |
61 | ||
43ff13b4 JM |
62 | /* In asynchronous mode, but simulating synchronous execution. */ |
63 | int sync_execution = 0; | |
64 | ||
c906108c SS |
65 | /* wait_for_inferior and normal_stop use this to notify the user |
66 | when the inferior stopped in a different thread than it had been | |
67 | running in. */ | |
68 | static int switched_from_inferior_pid; | |
7a292a7a SS |
69 | |
70 | /* This will be true for configurations that may actually report an | |
71 | inferior pid different from the original. At present this is only | |
72 | true for HP-UX native. */ | |
73 | ||
74 | #ifndef MAY_SWITCH_FROM_INFERIOR_PID | |
75 | #define MAY_SWITCH_FROM_INFERIOR_PID (0) | |
76 | #endif | |
77 | ||
78 | static int may_switch_from_inferior_pid = MAY_SWITCH_FROM_INFERIOR_PID; | |
79 | ||
80 | /* This is true for configurations that may follow through execl() and | |
81 | similar functions. At present this is only true for HP-UX native. */ | |
82 | ||
83 | #ifndef MAY_FOLLOW_EXEC | |
84 | #define MAY_FOLLOW_EXEC (0) | |
c906108c SS |
85 | #endif |
86 | ||
7a292a7a SS |
87 | static int may_follow_exec = MAY_FOLLOW_EXEC; |
88 | ||
c906108c SS |
89 | /* resume and wait_for_inferior use this to ensure that when |
90 | stepping over a hit breakpoint in a threaded application | |
91 | only the thread that hit the breakpoint is stepped and the | |
92 | other threads don't continue. This prevents having another | |
93 | thread run past the breakpoint while it is temporarily | |
94 | removed. | |
95 | ||
96 | This is not thread-specific, so it isn't saved as part of | |
97 | the infrun state. | |
98 | ||
99 | Versions of gdb which don't use the "step == this thread steps | |
100 | and others continue" model but instead use the "step == this | |
101 | thread steps and others wait" shouldn't do this. */ | |
102 | static int thread_step_needed = 0; | |
103 | ||
7a292a7a SS |
104 | /* This is true if thread_step_needed should actually be used. At |
105 | present this is only true for HP-UX native. */ | |
106 | ||
107 | #ifndef USE_THREAD_STEP_NEEDED | |
108 | #define USE_THREAD_STEP_NEEDED (0) | |
109 | #endif | |
110 | ||
111 | static int use_thread_step_needed = USE_THREAD_STEP_NEEDED; | |
112 | ||
392a587b JM |
113 | static void follow_inferior_fork PARAMS ((int parent_pid, |
114 | int child_pid, | |
115 | int has_forked, | |
116 | int has_vforked)); | |
117 | ||
118 | static void follow_fork PARAMS ((int parent_pid, int child_pid)); | |
119 | ||
120 | static void follow_vfork PARAMS ((int parent_pid, int child_pid)); | |
121 | ||
122 | static void set_schedlock_func PARAMS ((char *args, int from_tty, | |
c5aa993b | 123 | struct cmd_list_element * c)); |
392a587b | 124 | |
c5aa993b | 125 | static int is_internal_shlib_eventpoint PARAMS ((struct breakpoint * ep)); |
392a587b JM |
126 | |
127 | static int stopped_for_internal_shlib_event PARAMS ((bpstat bs)); | |
128 | ||
129 | static int stopped_for_shlib_catchpoint PARAMS ((bpstat bs, | |
c5aa993b | 130 | struct breakpoint ** cp_p)); |
392a587b JM |
131 | |
132 | #if __STDC__ | |
133 | struct execution_control_state; | |
134 | #endif | |
c5aa993b | 135 | static int currently_stepping PARAMS ((struct execution_control_state * ecs)); |
392a587b JM |
136 | |
137 | static void xdb_handle_command PARAMS ((char *args, int from_tty)); | |
138 | ||
c906108c SS |
139 | void _initialize_infrun PARAMS ((void)); |
140 | ||
141 | /* GET_LONGJMP_TARGET returns the PC at which longjmp() will resume the | |
142 | program. It needs to examine the jmp_buf argument and extract the PC | |
143 | from it. The return value is non-zero on success, zero otherwise. */ | |
144 | ||
145 | #ifndef GET_LONGJMP_TARGET | |
146 | #define GET_LONGJMP_TARGET(PC_ADDR) 0 | |
147 | #endif | |
148 | ||
149 | ||
150 | /* Some machines have trampoline code that sits between function callers | |
151 | and the actual functions themselves. If this machine doesn't have | |
152 | such things, disable their processing. */ | |
153 | ||
154 | #ifndef SKIP_TRAMPOLINE_CODE | |
155 | #define SKIP_TRAMPOLINE_CODE(pc) 0 | |
156 | #endif | |
157 | ||
158 | /* Dynamic function trampolines are similar to solib trampolines in that they | |
159 | are between the caller and the callee. The difference is that when you | |
160 | enter a dynamic trampoline, you can't determine the callee's address. Some | |
161 | (usually complex) code needs to run in the dynamic trampoline to figure out | |
162 | the callee's address. This macro is usually called twice. First, when we | |
163 | enter the trampoline (looks like a normal function call at that point). It | |
164 | should return the PC of a point within the trampoline where the callee's | |
165 | address is known. Second, when we hit the breakpoint, this routine returns | |
166 | the callee's address. At that point, things proceed as per a step resume | |
167 | breakpoint. */ | |
168 | ||
169 | #ifndef DYNAMIC_TRAMPOLINE_NEXTPC | |
170 | #define DYNAMIC_TRAMPOLINE_NEXTPC(pc) 0 | |
171 | #endif | |
172 | ||
173 | /* On SVR4 based systems, determining the callee's address is exceedingly | |
174 | difficult and depends on the implementation of the run time loader. | |
175 | If we are stepping at the source level, we single step until we exit | |
176 | the run time loader code and reach the callee's address. */ | |
177 | ||
178 | #ifndef IN_SOLIB_DYNSYM_RESOLVE_CODE | |
179 | #define IN_SOLIB_DYNSYM_RESOLVE_CODE(pc) 0 | |
180 | #endif | |
181 | ||
182 | /* For SVR4 shared libraries, each call goes through a small piece of | |
183 | trampoline code in the ".plt" section. IN_SOLIB_CALL_TRAMPOLINE evaluates | |
184 | to nonzero if we are current stopped in one of these. */ | |
185 | ||
186 | #ifndef IN_SOLIB_CALL_TRAMPOLINE | |
187 | #define IN_SOLIB_CALL_TRAMPOLINE(pc,name) 0 | |
188 | #endif | |
189 | ||
190 | /* In some shared library schemes, the return path from a shared library | |
191 | call may need to go through a trampoline too. */ | |
192 | ||
193 | #ifndef IN_SOLIB_RETURN_TRAMPOLINE | |
194 | #define IN_SOLIB_RETURN_TRAMPOLINE(pc,name) 0 | |
195 | #endif | |
196 | ||
197 | /* This function returns TRUE if pc is the address of an instruction | |
198 | that lies within the dynamic linker (such as the event hook, or the | |
199 | dld itself). | |
200 | ||
201 | This function must be used only when a dynamic linker event has | |
202 | been caught, and the inferior is being stepped out of the hook, or | |
203 | undefined results are guaranteed. */ | |
204 | ||
205 | #ifndef SOLIB_IN_DYNAMIC_LINKER | |
206 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 | |
207 | #endif | |
208 | ||
209 | /* On MIPS16, a function that returns a floating point value may call | |
210 | a library helper function to copy the return value to a floating point | |
211 | register. The IGNORE_HELPER_CALL macro returns non-zero if we | |
212 | should ignore (i.e. step over) this function call. */ | |
213 | #ifndef IGNORE_HELPER_CALL | |
214 | #define IGNORE_HELPER_CALL(pc) 0 | |
215 | #endif | |
216 | ||
217 | /* On some systems, the PC may be left pointing at an instruction that won't | |
218 | actually be executed. This is usually indicated by a bit in the PSW. If | |
219 | we find ourselves in such a state, then we step the target beyond the | |
220 | nullified instruction before returning control to the user so as to avoid | |
221 | confusion. */ | |
222 | ||
223 | #ifndef INSTRUCTION_NULLIFIED | |
224 | #define INSTRUCTION_NULLIFIED 0 | |
225 | #endif | |
226 | ||
7a292a7a SS |
227 | /* Convert the #defines into values. This is temporary until wfi control |
228 | flow is completely sorted out. */ | |
229 | ||
230 | #ifndef HAVE_STEPPABLE_WATCHPOINT | |
231 | #define HAVE_STEPPABLE_WATCHPOINT 0 | |
232 | #else | |
233 | #undef HAVE_STEPPABLE_WATCHPOINT | |
234 | #define HAVE_STEPPABLE_WATCHPOINT 1 | |
235 | #endif | |
236 | ||
237 | #ifndef HAVE_NONSTEPPABLE_WATCHPOINT | |
238 | #define HAVE_NONSTEPPABLE_WATCHPOINT 0 | |
239 | #else | |
240 | #undef HAVE_NONSTEPPABLE_WATCHPOINT | |
241 | #define HAVE_NONSTEPPABLE_WATCHPOINT 1 | |
242 | #endif | |
243 | ||
244 | #ifndef HAVE_CONTINUABLE_WATCHPOINT | |
245 | #define HAVE_CONTINUABLE_WATCHPOINT 0 | |
246 | #else | |
247 | #undef HAVE_CONTINUABLE_WATCHPOINT | |
248 | #define HAVE_CONTINUABLE_WATCHPOINT 1 | |
249 | #endif | |
250 | ||
c906108c SS |
251 | /* Tables of how to react to signals; the user sets them. */ |
252 | ||
253 | static unsigned char *signal_stop; | |
254 | static unsigned char *signal_print; | |
255 | static unsigned char *signal_program; | |
256 | ||
257 | #define SET_SIGS(nsigs,sigs,flags) \ | |
258 | do { \ | |
259 | int signum = (nsigs); \ | |
260 | while (signum-- > 0) \ | |
261 | if ((sigs)[signum]) \ | |
262 | (flags)[signum] = 1; \ | |
263 | } while (0) | |
264 | ||
265 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
266 | do { \ | |
267 | int signum = (nsigs); \ | |
268 | while (signum-- > 0) \ | |
269 | if ((sigs)[signum]) \ | |
270 | (flags)[signum] = 0; \ | |
271 | } while (0) | |
272 | ||
273 | ||
274 | /* Command list pointer for the "stop" placeholder. */ | |
275 | ||
276 | static struct cmd_list_element *stop_command; | |
277 | ||
278 | /* Nonzero if breakpoints are now inserted in the inferior. */ | |
279 | ||
280 | static int breakpoints_inserted; | |
281 | ||
282 | /* Function inferior was in as of last step command. */ | |
283 | ||
284 | static struct symbol *step_start_function; | |
285 | ||
286 | /* Nonzero if we are expecting a trace trap and should proceed from it. */ | |
287 | ||
288 | static int trap_expected; | |
289 | ||
290 | #ifdef SOLIB_ADD | |
291 | /* Nonzero if we want to give control to the user when we're notified | |
292 | of shared library events by the dynamic linker. */ | |
293 | static int stop_on_solib_events; | |
294 | #endif | |
295 | ||
296 | #ifdef HP_OS_BUG | |
297 | /* Nonzero if the next time we try to continue the inferior, it will | |
298 | step one instruction and generate a spurious trace trap. | |
299 | This is used to compensate for a bug in HP-UX. */ | |
300 | ||
301 | static int trap_expected_after_continue; | |
302 | #endif | |
303 | ||
304 | /* Nonzero means expecting a trace trap | |
305 | and should stop the inferior and return silently when it happens. */ | |
306 | ||
307 | int stop_after_trap; | |
308 | ||
309 | /* Nonzero means expecting a trap and caller will handle it themselves. | |
310 | It is used after attach, due to attaching to a process; | |
311 | when running in the shell before the child program has been exec'd; | |
312 | and when running some kinds of remote stuff (FIXME?). */ | |
313 | ||
314 | int stop_soon_quietly; | |
315 | ||
316 | /* Nonzero if proceed is being used for a "finish" command or a similar | |
317 | situation when stop_registers should be saved. */ | |
318 | ||
319 | int proceed_to_finish; | |
320 | ||
321 | /* Save register contents here when about to pop a stack dummy frame, | |
322 | if-and-only-if proceed_to_finish is set. | |
323 | Thus this contains the return value from the called function (assuming | |
324 | values are returned in a register). */ | |
325 | ||
7a292a7a | 326 | char *stop_registers; |
c906108c SS |
327 | |
328 | /* Nonzero if program stopped due to error trying to insert breakpoints. */ | |
329 | ||
330 | static int breakpoints_failed; | |
331 | ||
332 | /* Nonzero after stop if current stack frame should be printed. */ | |
333 | ||
334 | static int stop_print_frame; | |
335 | ||
336 | static struct breakpoint *step_resume_breakpoint = NULL; | |
337 | static struct breakpoint *through_sigtramp_breakpoint = NULL; | |
338 | ||
339 | /* On some platforms (e.g., HP-UX), hardware watchpoints have bad | |
340 | interactions with an inferior that is running a kernel function | |
341 | (aka, a system call or "syscall"). wait_for_inferior therefore | |
342 | may have a need to know when the inferior is in a syscall. This | |
343 | is a count of the number of inferior threads which are known to | |
344 | currently be running in a syscall. */ | |
345 | static int number_of_threads_in_syscalls; | |
346 | ||
347 | /* This is used to remember when a fork, vfork or exec event | |
348 | was caught by a catchpoint, and thus the event is to be | |
349 | followed at the next resume of the inferior, and not | |
350 | immediately. */ | |
351 | static struct | |
352 | { | |
353 | enum target_waitkind kind; | |
354 | struct | |
355 | { | |
356 | int parent_pid; | |
357 | int saw_parent_fork; | |
358 | int child_pid; | |
359 | int saw_child_fork; | |
360 | int saw_child_exec; | |
361 | } | |
362 | fork_event; | |
363 | char *execd_pathname; | |
364 | } | |
365 | pending_follow; | |
366 | ||
367 | /* Some platforms don't allow us to do anything meaningful with a | |
368 | vforked child until it has exec'd. Vforked processes on such | |
369 | platforms can only be followed after they've exec'd. | |
370 | ||
371 | When this is set to 0, a vfork can be immediately followed, | |
372 | and an exec can be followed merely as an exec. When this is | |
373 | set to 1, a vfork event has been seen, but cannot be followed | |
374 | until the exec is seen. | |
375 | ||
376 | (In the latter case, inferior_pid is still the parent of the | |
377 | vfork, and pending_follow.fork_event.child_pid is the child. The | |
378 | appropriate process is followed, according to the setting of | |
379 | follow-fork-mode.) */ | |
380 | static int follow_vfork_when_exec; | |
381 | ||
382 | static char *follow_fork_mode_kind_names[] = | |
383 | { | |
384 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 | |
385 | kernel problem. It's also not terribly useful without a GUI to | |
386 | help the user drive two debuggers. So for now, I'm disabling | |
387 | the "both" option. | |
c5aa993b JM |
388 | "parent", "child", "both", "ask" }; |
389 | */ | |
c906108c SS |
390 | "parent", "child", "ask"}; |
391 | ||
392 | static char *follow_fork_mode_string = NULL; | |
393 | \f | |
394 | ||
c906108c SS |
395 | static void |
396 | follow_inferior_fork (parent_pid, child_pid, has_forked, has_vforked) | |
397 | int parent_pid; | |
398 | int child_pid; | |
399 | int has_forked; | |
400 | int has_vforked; | |
401 | { | |
402 | int followed_parent = 0; | |
403 | int followed_child = 0; | |
404 | int ima_clone = 0; | |
405 | ||
406 | /* Which process did the user want us to follow? */ | |
407 | char *follow_mode = | |
408 | savestring (follow_fork_mode_string, strlen (follow_fork_mode_string)); | |
409 | ||
410 | /* Or, did the user not know, and want us to ask? */ | |
411 | if (STREQ (follow_fork_mode_string, "ask")) | |
412 | { | |
413 | char requested_mode[100]; | |
414 | ||
415 | free (follow_mode); | |
416 | error ("\"ask\" mode NYI"); | |
417 | follow_mode = savestring (requested_mode, strlen (requested_mode)); | |
418 | } | |
419 | ||
420 | /* If we're to be following the parent, then detach from child_pid. | |
421 | We're already following the parent, so need do nothing explicit | |
422 | for it. */ | |
423 | if (STREQ (follow_mode, "parent")) | |
424 | { | |
425 | followed_parent = 1; | |
426 | ||
427 | /* We're already attached to the parent, by default. */ | |
428 | ||
429 | /* Before detaching from the child, remove all breakpoints from | |
430 | it. (This won't actually modify the breakpoint list, but will | |
431 | physically remove the breakpoints from the child.) */ | |
432 | if (!has_vforked || !follow_vfork_when_exec) | |
433 | { | |
434 | detach_breakpoints (child_pid); | |
7a292a7a | 435 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
c906108c | 436 | SOLIB_REMOVE_INFERIOR_HOOK (child_pid); |
7a292a7a | 437 | #endif |
c906108c SS |
438 | } |
439 | ||
440 | /* Detach from the child. */ | |
441 | dont_repeat (); | |
442 | ||
443 | target_require_detach (child_pid, "", 1); | |
444 | } | |
445 | ||
446 | /* If we're to be following the child, then attach to it, detach | |
447 | from inferior_pid, and set inferior_pid to child_pid. */ | |
448 | else if (STREQ (follow_mode, "child")) | |
449 | { | |
450 | char child_pid_spelling[100]; /* Arbitrary length. */ | |
451 | ||
452 | followed_child = 1; | |
453 | ||
454 | /* Before detaching from the parent, detach all breakpoints from | |
455 | the child. But only if we're forking, or if we follow vforks | |
456 | as soon as they happen. (If we're following vforks only when | |
457 | the child has exec'd, then it's very wrong to try to write | |
458 | back the "shadow contents" of inserted breakpoints now -- they | |
459 | belong to the child's pre-exec'd a.out.) */ | |
460 | if (!has_vforked || !follow_vfork_when_exec) | |
461 | { | |
462 | detach_breakpoints (child_pid); | |
463 | } | |
464 | ||
465 | /* Before detaching from the parent, remove all breakpoints from it. */ | |
466 | remove_breakpoints (); | |
467 | ||
468 | /* Also reset the solib inferior hook from the parent. */ | |
7a292a7a | 469 | #ifdef SOLIB_REMOVE_INFERIOR_HOOK |
c906108c | 470 | SOLIB_REMOVE_INFERIOR_HOOK (inferior_pid); |
7a292a7a | 471 | #endif |
c906108c SS |
472 | |
473 | /* Detach from the parent. */ | |
474 | dont_repeat (); | |
475 | target_detach (NULL, 1); | |
476 | ||
477 | /* Attach to the child. */ | |
478 | inferior_pid = child_pid; | |
479 | sprintf (child_pid_spelling, "%d", child_pid); | |
480 | dont_repeat (); | |
481 | ||
482 | target_require_attach (child_pid_spelling, 1); | |
483 | ||
484 | /* Was there a step_resume breakpoint? (There was if the user | |
485 | did a "next" at the fork() call.) If so, explicitly reset its | |
486 | thread number. | |
487 | ||
488 | step_resumes are a form of bp that are made to be per-thread. | |
489 | Since we created the step_resume bp when the parent process | |
490 | was being debugged, and now are switching to the child process, | |
491 | from the breakpoint package's viewpoint, that's a switch of | |
492 | "threads". We must update the bp's notion of which thread | |
493 | it is for, or it'll be ignored when it triggers... */ | |
494 | if (step_resume_breakpoint && | |
495 | (!has_vforked || !follow_vfork_when_exec)) | |
496 | breakpoint_re_set_thread (step_resume_breakpoint); | |
497 | ||
498 | /* Reinsert all breakpoints in the child. (The user may've set | |
499 | breakpoints after catching the fork, in which case those | |
500 | actually didn't get set in the child, but only in the parent.) */ | |
501 | if (!has_vforked || !follow_vfork_when_exec) | |
502 | { | |
503 | breakpoint_re_set (); | |
504 | insert_breakpoints (); | |
505 | } | |
506 | } | |
507 | ||
508 | /* If we're to be following both parent and child, then fork ourselves, | |
509 | and attach the debugger clone to the child. */ | |
510 | else if (STREQ (follow_mode, "both")) | |
511 | { | |
512 | char pid_suffix[100]; /* Arbitrary length. */ | |
513 | ||
514 | /* Clone ourselves to follow the child. This is the end of our | |
c5aa993b | 515 | involvement with child_pid; our clone will take it from here... */ |
c906108c SS |
516 | dont_repeat (); |
517 | target_clone_and_follow_inferior (child_pid, &followed_child); | |
518 | followed_parent = !followed_child; | |
519 | ||
520 | /* We continue to follow the parent. To help distinguish the two | |
521 | debuggers, though, both we and our clone will reset our prompts. */ | |
522 | sprintf (pid_suffix, "[%d] ", inferior_pid); | |
523 | set_prompt (strcat (get_prompt (), pid_suffix)); | |
524 | } | |
525 | ||
526 | /* The parent and child of a vfork share the same address space. | |
527 | Also, on some targets the order in which vfork and exec events | |
528 | are received for parent in child requires some delicate handling | |
529 | of the events. | |
530 | ||
531 | For instance, on ptrace-based HPUX we receive the child's vfork | |
532 | event first, at which time the parent has been suspended by the | |
533 | OS and is essentially untouchable until the child's exit or second | |
534 | exec event arrives. At that time, the parent's vfork event is | |
535 | delivered to us, and that's when we see and decide how to follow | |
536 | the vfork. But to get to that point, we must continue the child | |
537 | until it execs or exits. To do that smoothly, all breakpoints | |
538 | must be removed from the child, in case there are any set between | |
539 | the vfork() and exec() calls. But removing them from the child | |
540 | also removes them from the parent, due to the shared-address-space | |
541 | nature of a vfork'd parent and child. On HPUX, therefore, we must | |
542 | take care to restore the bp's to the parent before we continue it. | |
543 | Else, it's likely that we may not stop in the expected place. (The | |
544 | worst scenario is when the user tries to step over a vfork() call; | |
545 | the step-resume bp must be restored for the step to properly stop | |
546 | in the parent after the call completes!) | |
547 | ||
548 | Sequence of events, as reported to gdb from HPUX: | |
549 | ||
c5aa993b JM |
550 | Parent Child Action for gdb to take |
551 | ------------------------------------------------------- | |
552 | 1 VFORK Continue child | |
553 | 2 EXEC | |
554 | 3 EXEC or EXIT | |
555 | 4 VFORK */ | |
c906108c SS |
556 | if (has_vforked) |
557 | { | |
558 | target_post_follow_vfork (parent_pid, | |
559 | followed_parent, | |
560 | child_pid, | |
561 | followed_child); | |
562 | } | |
563 | ||
564 | pending_follow.fork_event.saw_parent_fork = 0; | |
565 | pending_follow.fork_event.saw_child_fork = 0; | |
566 | ||
567 | free (follow_mode); | |
568 | } | |
569 | ||
570 | static void | |
571 | follow_fork (parent_pid, child_pid) | |
572 | int parent_pid; | |
573 | int child_pid; | |
574 | { | |
575 | follow_inferior_fork (parent_pid, child_pid, 1, 0); | |
576 | } | |
577 | ||
578 | ||
579 | /* Forward declaration. */ | |
580 | static void follow_exec PARAMS ((int, char *)); | |
581 | ||
582 | static void | |
583 | follow_vfork (parent_pid, child_pid) | |
584 | int parent_pid; | |
585 | int child_pid; | |
586 | { | |
587 | follow_inferior_fork (parent_pid, child_pid, 0, 1); | |
588 | ||
589 | /* Did we follow the child? Had it exec'd before we saw the parent vfork? */ | |
590 | if (pending_follow.fork_event.saw_child_exec && (inferior_pid == child_pid)) | |
591 | { | |
592 | pending_follow.fork_event.saw_child_exec = 0; | |
593 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
594 | follow_exec (inferior_pid, pending_follow.execd_pathname); | |
595 | free (pending_follow.execd_pathname); | |
596 | } | |
597 | } | |
c906108c SS |
598 | |
599 | static void | |
600 | follow_exec (pid, execd_pathname) | |
601 | int pid; | |
602 | char *execd_pathname; | |
603 | { | |
c906108c | 604 | int saved_pid = pid; |
7a292a7a SS |
605 | struct target_ops *tgt; |
606 | ||
607 | if (!may_follow_exec) | |
608 | return; | |
c906108c SS |
609 | |
610 | /* Did this exec() follow a vfork()? If so, we must follow the | |
611 | vfork now too. Do it before following the exec. */ | |
612 | if (follow_vfork_when_exec && | |
613 | (pending_follow.kind == TARGET_WAITKIND_VFORKED)) | |
614 | { | |
615 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
616 | follow_vfork (inferior_pid, pending_follow.fork_event.child_pid); | |
617 | follow_vfork_when_exec = 0; | |
618 | saved_pid = inferior_pid; | |
619 | ||
620 | /* Did we follow the parent? If so, we're done. If we followed | |
621 | the child then we must also follow its exec(). */ | |
622 | if (inferior_pid == pending_follow.fork_event.parent_pid) | |
623 | return; | |
624 | } | |
625 | ||
626 | /* This is an exec event that we actually wish to pay attention to. | |
627 | Refresh our symbol table to the newly exec'd program, remove any | |
628 | momentary bp's, etc. | |
629 | ||
630 | If there are breakpoints, they aren't really inserted now, | |
631 | since the exec() transformed our inferior into a fresh set | |
632 | of instructions. | |
633 | ||
634 | We want to preserve symbolic breakpoints on the list, since | |
635 | we have hopes that they can be reset after the new a.out's | |
636 | symbol table is read. | |
637 | ||
638 | However, any "raw" breakpoints must be removed from the list | |
639 | (e.g., the solib bp's), since their address is probably invalid | |
640 | now. | |
641 | ||
642 | And, we DON'T want to call delete_breakpoints() here, since | |
643 | that may write the bp's "shadow contents" (the instruction | |
644 | value that was overwritten witha TRAP instruction). Since | |
645 | we now have a new a.out, those shadow contents aren't valid. */ | |
646 | update_breakpoints_after_exec (); | |
647 | ||
648 | /* If there was one, it's gone now. We cannot truly step-to-next | |
649 | statement through an exec(). */ | |
650 | step_resume_breakpoint = NULL; | |
651 | step_range_start = 0; | |
652 | step_range_end = 0; | |
653 | ||
654 | /* If there was one, it's gone now. */ | |
655 | through_sigtramp_breakpoint = NULL; | |
656 | ||
657 | /* What is this a.out's name? */ | |
658 | printf_unfiltered ("Executing new program: %s\n", execd_pathname); | |
659 | ||
660 | /* We've followed the inferior through an exec. Therefore, the | |
661 | inferior has essentially been killed & reborn. */ | |
7a292a7a SS |
662 | |
663 | /* First collect the run target in effect. */ | |
664 | tgt = find_run_target (); | |
665 | /* If we can't find one, things are in a very strange state... */ | |
666 | if (tgt == NULL) | |
667 | error ("Could find run target to save before following exec"); | |
668 | ||
c906108c SS |
669 | gdb_flush (gdb_stdout); |
670 | target_mourn_inferior (); | |
c5aa993b | 671 | inferior_pid = saved_pid; /* Because mourn_inferior resets inferior_pid. */ |
7a292a7a | 672 | push_target (tgt); |
c906108c SS |
673 | |
674 | /* That a.out is now the one to use. */ | |
675 | exec_file_attach (execd_pathname, 0); | |
676 | ||
677 | /* And also is where symbols can be found. */ | |
678 | symbol_file_command (execd_pathname, 0); | |
679 | ||
680 | /* Reset the shared library package. This ensures that we get | |
681 | a shlib event when the child reaches "_start", at which point | |
682 | the dld will have had a chance to initialize the child. */ | |
7a292a7a | 683 | #if defined(SOLIB_RESTART) |
c906108c | 684 | SOLIB_RESTART (); |
7a292a7a SS |
685 | #endif |
686 | #ifdef SOLIB_CREATE_INFERIOR_HOOK | |
c906108c | 687 | SOLIB_CREATE_INFERIOR_HOOK (inferior_pid); |
7a292a7a | 688 | #endif |
c906108c SS |
689 | |
690 | /* Reinsert all breakpoints. (Those which were symbolic have | |
691 | been reset to the proper address in the new a.out, thanks | |
692 | to symbol_file_command...) */ | |
693 | insert_breakpoints (); | |
694 | ||
695 | /* The next resume of this inferior should bring it to the shlib | |
696 | startup breakpoints. (If the user had also set bp's on | |
697 | "main" from the old (parent) process, then they'll auto- | |
698 | matically get reset there in the new process.) */ | |
c906108c SS |
699 | } |
700 | ||
701 | /* Non-zero if we just simulating a single-step. This is needed | |
702 | because we cannot remove the breakpoints in the inferior process | |
703 | until after the `wait' in `wait_for_inferior'. */ | |
704 | static int singlestep_breakpoints_inserted_p = 0; | |
705 | \f | |
706 | ||
707 | /* Things to clean up if we QUIT out of resume (). */ | |
708 | /* ARGSUSED */ | |
709 | static void | |
710 | resume_cleanups (arg) | |
711 | int arg; | |
712 | { | |
713 | normal_stop (); | |
714 | } | |
715 | ||
716 | static char schedlock_off[] = "off"; | |
717 | static char schedlock_on[] = "on"; | |
718 | static char schedlock_step[] = "step"; | |
719 | static char *scheduler_mode = schedlock_off; | |
720 | static char *scheduler_enums[] = | |
721 | {schedlock_off, schedlock_on, schedlock_step}; | |
722 | ||
723 | static void | |
724 | set_schedlock_func (args, from_tty, c) | |
725 | char *args; | |
726 | int from_tty; | |
727 | struct cmd_list_element *c; | |
728 | { | |
729 | if (c->type == set_cmd) | |
730 | if (!target_can_lock_scheduler) | |
731 | { | |
732 | scheduler_mode = schedlock_off; | |
733 | error ("Target '%s' cannot support this command.", | |
734 | target_shortname); | |
735 | } | |
736 | } | |
737 | ||
738 | ||
739 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
740 | wants to interrupt some lengthy single-stepping operation | |
741 | (for child processes, the SIGINT goes to the inferior, and so | |
742 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
743 | other targets, that's not true). | |
744 | ||
745 | STEP nonzero if we should step (zero to continue instead). | |
746 | SIG is the signal to give the inferior (zero for none). */ | |
747 | void | |
748 | resume (step, sig) | |
749 | int step; | |
750 | enum target_signal sig; | |
751 | { | |
752 | int should_resume = 1; | |
753 | struct cleanup *old_cleanups = make_cleanup ((make_cleanup_func) | |
754 | resume_cleanups, 0); | |
755 | QUIT; | |
756 | ||
757 | #ifdef CANNOT_STEP_BREAKPOINT | |
758 | /* Most targets can step a breakpoint instruction, thus executing it | |
759 | normally. But if this one cannot, just continue and we will hit | |
760 | it anyway. */ | |
761 | if (step && breakpoints_inserted && breakpoint_here_p (read_pc ())) | |
762 | step = 0; | |
763 | #endif | |
764 | ||
765 | if (SOFTWARE_SINGLE_STEP_P && step) | |
766 | { | |
767 | /* Do it the hard way, w/temp breakpoints */ | |
c5aa993b | 768 | SOFTWARE_SINGLE_STEP (sig, 1 /*insert-breakpoints */ ); |
c906108c SS |
769 | /* ...and don't ask hardware to do it. */ |
770 | step = 0; | |
771 | /* and do not pull these breakpoints until after a `wait' in | |
772 | `wait_for_inferior' */ | |
773 | singlestep_breakpoints_inserted_p = 1; | |
774 | } | |
775 | ||
776 | /* Handle any optimized stores to the inferior NOW... */ | |
777 | #ifdef DO_DEFERRED_STORES | |
778 | DO_DEFERRED_STORES; | |
779 | #endif | |
780 | ||
c906108c SS |
781 | /* If there were any forks/vforks/execs that were caught and are |
782 | now to be followed, then do so. */ | |
783 | switch (pending_follow.kind) | |
784 | { | |
785 | case (TARGET_WAITKIND_FORKED): | |
786 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
787 | follow_fork (inferior_pid, pending_follow.fork_event.child_pid); | |
788 | break; | |
789 | ||
790 | case (TARGET_WAITKIND_VFORKED): | |
791 | { | |
792 | int saw_child_exec = pending_follow.fork_event.saw_child_exec; | |
793 | ||
794 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
795 | follow_vfork (inferior_pid, pending_follow.fork_event.child_pid); | |
796 | ||
797 | /* Did we follow the child, but not yet see the child's exec event? | |
c5aa993b JM |
798 | If so, then it actually ought to be waiting for us; we respond to |
799 | parent vfork events. We don't actually want to resume the child | |
800 | in this situation; we want to just get its exec event. */ | |
c906108c SS |
801 | if (!saw_child_exec && |
802 | (inferior_pid == pending_follow.fork_event.child_pid)) | |
803 | should_resume = 0; | |
804 | } | |
805 | break; | |
806 | ||
807 | case (TARGET_WAITKIND_EXECD): | |
808 | /* If we saw a vfork event but couldn't follow it until we saw | |
c5aa993b | 809 | an exec, then now might be the time! */ |
c906108c SS |
810 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; |
811 | /* follow_exec is called as soon as the exec event is seen. */ | |
812 | break; | |
813 | ||
814 | default: | |
815 | break; | |
816 | } | |
c906108c SS |
817 | |
818 | /* Install inferior's terminal modes. */ | |
819 | target_terminal_inferior (); | |
820 | ||
821 | if (should_resume) | |
822 | { | |
7a292a7a | 823 | if (use_thread_step_needed && thread_step_needed) |
c906108c SS |
824 | { |
825 | /* We stopped on a BPT instruction; | |
826 | don't continue other threads and | |
827 | just step this thread. */ | |
828 | thread_step_needed = 0; | |
829 | ||
830 | if (!breakpoint_here_p (read_pc ())) | |
831 | { | |
832 | /* Breakpoint deleted: ok to do regular resume | |
c5aa993b | 833 | where all the threads either step or continue. */ |
c906108c SS |
834 | target_resume (-1, step, sig); |
835 | } | |
836 | else | |
837 | { | |
838 | if (!step) | |
839 | { | |
840 | warning ("Internal error, changing continue to step."); | |
841 | remove_breakpoints (); | |
842 | breakpoints_inserted = 0; | |
843 | trap_expected = 1; | |
844 | step = 1; | |
845 | } | |
846 | ||
847 | target_resume (inferior_pid, step, sig); | |
848 | } | |
849 | } | |
850 | else | |
c906108c SS |
851 | { |
852 | /* Vanilla resume. */ | |
853 | ||
854 | if ((scheduler_mode == schedlock_on) || | |
855 | (scheduler_mode == schedlock_step && step != 0)) | |
856 | target_resume (inferior_pid, step, sig); | |
857 | else | |
858 | target_resume (-1, step, sig); | |
859 | } | |
860 | } | |
861 | ||
862 | discard_cleanups (old_cleanups); | |
863 | } | |
864 | \f | |
865 | ||
866 | /* Clear out all variables saying what to do when inferior is continued. | |
867 | First do this, then set the ones you want, then call `proceed'. */ | |
868 | ||
869 | void | |
870 | clear_proceed_status () | |
871 | { | |
872 | trap_expected = 0; | |
873 | step_range_start = 0; | |
874 | step_range_end = 0; | |
875 | step_frame_address = 0; | |
876 | step_over_calls = -1; | |
877 | stop_after_trap = 0; | |
878 | stop_soon_quietly = 0; | |
879 | proceed_to_finish = 0; | |
880 | breakpoint_proceeded = 1; /* We're about to proceed... */ | |
881 | ||
882 | /* Discard any remaining commands or status from previous stop. */ | |
883 | bpstat_clear (&stop_bpstat); | |
884 | } | |
885 | ||
886 | /* Basic routine for continuing the program in various fashions. | |
887 | ||
888 | ADDR is the address to resume at, or -1 for resume where stopped. | |
889 | SIGGNAL is the signal to give it, or 0 for none, | |
c5aa993b | 890 | or -1 for act according to how it stopped. |
c906108c | 891 | STEP is nonzero if should trap after one instruction. |
c5aa993b JM |
892 | -1 means return after that and print nothing. |
893 | You should probably set various step_... variables | |
894 | before calling here, if you are stepping. | |
c906108c SS |
895 | |
896 | You should call clear_proceed_status before calling proceed. */ | |
897 | ||
898 | void | |
899 | proceed (addr, siggnal, step) | |
900 | CORE_ADDR addr; | |
901 | enum target_signal siggnal; | |
902 | int step; | |
903 | { | |
904 | int oneproc = 0; | |
905 | ||
906 | if (step > 0) | |
907 | step_start_function = find_pc_function (read_pc ()); | |
908 | if (step < 0) | |
909 | stop_after_trap = 1; | |
910 | ||
911 | if (addr == (CORE_ADDR) - 1) | |
912 | { | |
913 | /* If there is a breakpoint at the address we will resume at, | |
c5aa993b JM |
914 | step one instruction before inserting breakpoints |
915 | so that we do not stop right away (and report a second | |
c906108c SS |
916 | hit at this breakpoint). */ |
917 | ||
918 | if (read_pc () == stop_pc && breakpoint_here_p (read_pc ())) | |
919 | oneproc = 1; | |
920 | ||
921 | #ifndef STEP_SKIPS_DELAY | |
922 | #define STEP_SKIPS_DELAY(pc) (0) | |
923 | #define STEP_SKIPS_DELAY_P (0) | |
924 | #endif | |
925 | /* Check breakpoint_here_p first, because breakpoint_here_p is fast | |
c5aa993b JM |
926 | (it just checks internal GDB data structures) and STEP_SKIPS_DELAY |
927 | is slow (it needs to read memory from the target). */ | |
c906108c SS |
928 | if (STEP_SKIPS_DELAY_P |
929 | && breakpoint_here_p (read_pc () + 4) | |
930 | && STEP_SKIPS_DELAY (read_pc ())) | |
931 | oneproc = 1; | |
932 | } | |
933 | else | |
934 | { | |
935 | write_pc (addr); | |
936 | ||
937 | /* New address; we don't need to single-step a thread | |
c5aa993b JM |
938 | over a breakpoint we just hit, 'cause we aren't |
939 | continuing from there. | |
c906108c | 940 | |
c5aa993b JM |
941 | It's not worth worrying about the case where a user |
942 | asks for a "jump" at the current PC--if they get the | |
943 | hiccup of re-hiting a hit breakpoint, what else do | |
944 | they expect? */ | |
c906108c SS |
945 | thread_step_needed = 0; |
946 | } | |
947 | ||
948 | #ifdef PREPARE_TO_PROCEED | |
949 | /* In a multi-threaded task we may select another thread | |
950 | and then continue or step. | |
951 | ||
952 | But if the old thread was stopped at a breakpoint, it | |
953 | will immediately cause another breakpoint stop without | |
954 | any execution (i.e. it will report a breakpoint hit | |
955 | incorrectly). So we must step over it first. | |
956 | ||
957 | PREPARE_TO_PROCEED checks the current thread against the thread | |
958 | that reported the most recent event. If a step-over is required | |
959 | it returns TRUE and sets the current thread to the old thread. */ | |
9e086581 | 960 | if (PREPARE_TO_PROCEED (1) && breakpoint_here_p (read_pc ())) |
c906108c SS |
961 | { |
962 | oneproc = 1; | |
963 | thread_step_needed = 1; | |
964 | } | |
965 | ||
966 | #endif /* PREPARE_TO_PROCEED */ | |
967 | ||
968 | #ifdef HP_OS_BUG | |
969 | if (trap_expected_after_continue) | |
970 | { | |
971 | /* If (step == 0), a trap will be automatically generated after | |
c5aa993b JM |
972 | the first instruction is executed. Force step one |
973 | instruction to clear this condition. This should not occur | |
974 | if step is nonzero, but it is harmless in that case. */ | |
c906108c SS |
975 | oneproc = 1; |
976 | trap_expected_after_continue = 0; | |
977 | } | |
978 | #endif /* HP_OS_BUG */ | |
979 | ||
980 | if (oneproc) | |
981 | /* We will get a trace trap after one instruction. | |
982 | Continue it automatically and insert breakpoints then. */ | |
983 | trap_expected = 1; | |
984 | else | |
985 | { | |
986 | int temp = insert_breakpoints (); | |
987 | if (temp) | |
988 | { | |
989 | print_sys_errmsg ("ptrace", temp); | |
990 | error ("Cannot insert breakpoints.\n\ | |
991 | The same program may be running in another process."); | |
992 | } | |
993 | ||
994 | breakpoints_inserted = 1; | |
995 | } | |
996 | ||
997 | if (siggnal != TARGET_SIGNAL_DEFAULT) | |
998 | stop_signal = siggnal; | |
999 | /* If this signal should not be seen by program, | |
1000 | give it zero. Used for debugging signals. */ | |
1001 | else if (!signal_program[stop_signal]) | |
1002 | stop_signal = TARGET_SIGNAL_0; | |
1003 | ||
1004 | annotate_starting (); | |
1005 | ||
1006 | /* Make sure that output from GDB appears before output from the | |
1007 | inferior. */ | |
1008 | gdb_flush (gdb_stdout); | |
1009 | ||
1010 | /* Resume inferior. */ | |
1011 | resume (oneproc || step || bpstat_should_step (), stop_signal); | |
1012 | ||
1013 | /* Wait for it to stop (if not standalone) | |
1014 | and in any case decode why it stopped, and act accordingly. */ | |
43ff13b4 JM |
1015 | /* Do this only if we are not using the event loop, or if the target |
1016 | does not support asynchronous execution. */ | |
1017 | if (!async_p || !target_has_async) | |
1018 | { | |
1019 | wait_for_inferior (); | |
1020 | normal_stop (); | |
1021 | } | |
c906108c SS |
1022 | } |
1023 | ||
1024 | /* Record the pc and sp of the program the last time it stopped. | |
1025 | These are just used internally by wait_for_inferior, but need | |
1026 | to be preserved over calls to it and cleared when the inferior | |
1027 | is started. */ | |
1028 | static CORE_ADDR prev_pc; | |
1029 | static CORE_ADDR prev_func_start; | |
1030 | static char *prev_func_name; | |
1031 | \f | |
1032 | ||
1033 | /* Start remote-debugging of a machine over a serial link. */ | |
c906108c SS |
1034 | void |
1035 | start_remote () | |
1036 | { | |
1037 | init_thread_list (); | |
1038 | init_wait_for_inferior (); | |
1039 | stop_soon_quietly = 1; | |
1040 | trap_expected = 0; | |
43ff13b4 JM |
1041 | |
1042 | /* Go on waiting only in case gdb is not started in async mode, or | |
1043 | in case the target doesn't support async execution. */ | |
1044 | if (!async_p || !target_has_async) | |
1045 | { | |
1046 | wait_for_inferior (); | |
1047 | normal_stop (); | |
1048 | } | |
1049 | else | |
1050 | { | |
1051 | /* The 'tar rem' command should always look synchronous, | |
c5aa993b JM |
1052 | i.e. display the prompt only once it has connected and |
1053 | started the target. */ | |
43ff13b4 JM |
1054 | sync_execution = 1; |
1055 | push_prompt ("", "", ""); | |
1056 | delete_file_handler (input_fd); | |
1057 | target_executing = 1; | |
1058 | } | |
c906108c SS |
1059 | } |
1060 | ||
1061 | /* Initialize static vars when a new inferior begins. */ | |
1062 | ||
1063 | void | |
1064 | init_wait_for_inferior () | |
1065 | { | |
1066 | /* These are meaningless until the first time through wait_for_inferior. */ | |
1067 | prev_pc = 0; | |
1068 | prev_func_start = 0; | |
1069 | prev_func_name = NULL; | |
1070 | ||
1071 | #ifdef HP_OS_BUG | |
1072 | trap_expected_after_continue = 0; | |
1073 | #endif | |
1074 | breakpoints_inserted = 0; | |
1075 | breakpoint_init_inferior (inf_starting); | |
1076 | ||
1077 | /* Don't confuse first call to proceed(). */ | |
1078 | stop_signal = TARGET_SIGNAL_0; | |
1079 | ||
1080 | /* The first resume is not following a fork/vfork/exec. */ | |
1081 | pending_follow.kind = TARGET_WAITKIND_SPURIOUS; /* I.e., none. */ | |
1082 | pending_follow.fork_event.saw_parent_fork = 0; | |
1083 | pending_follow.fork_event.saw_child_fork = 0; | |
1084 | pending_follow.fork_event.saw_child_exec = 0; | |
1085 | ||
1086 | /* See wait_for_inferior's handling of SYSCALL_ENTRY/RETURN events. */ | |
1087 | number_of_threads_in_syscalls = 0; | |
1088 | ||
1089 | clear_proceed_status (); | |
1090 | } | |
1091 | ||
1092 | static void | |
1093 | delete_breakpoint_current_contents (arg) | |
1094 | PTR arg; | |
1095 | { | |
1096 | struct breakpoint **breakpointp = (struct breakpoint **) arg; | |
1097 | if (*breakpointp != NULL) | |
1098 | { | |
1099 | delete_breakpoint (*breakpointp); | |
1100 | *breakpointp = NULL; | |
1101 | } | |
1102 | } | |
1103 | \f | |
b83266a0 SS |
1104 | /* This enum encodes possible reasons for doing a target_wait, so that |
1105 | wfi can call target_wait in one place. (Ultimately the call will be | |
1106 | moved out of the infinite loop entirely.) */ | |
1107 | ||
c5aa993b JM |
1108 | enum infwait_states |
1109 | { | |
cd0fc7c3 SS |
1110 | infwait_normal_state, |
1111 | infwait_thread_hop_state, | |
1112 | infwait_nullified_state, | |
1113 | infwait_nonstep_watch_state | |
b83266a0 SS |
1114 | }; |
1115 | ||
cd0fc7c3 SS |
1116 | /* This structure contains what used to be local variables in |
1117 | wait_for_inferior. Probably many of them can return to being | |
1118 | locals in handle_inferior_event. */ | |
1119 | ||
c5aa993b JM |
1120 | struct execution_control_state |
1121 | { | |
1122 | struct target_waitstatus ws; | |
1123 | struct target_waitstatus *wp; | |
1124 | int another_trap; | |
1125 | int random_signal; | |
1126 | CORE_ADDR stop_func_start; | |
1127 | CORE_ADDR stop_func_end; | |
1128 | char *stop_func_name; | |
1129 | struct symtab_and_line sal; | |
1130 | int remove_breakpoints_on_following_step; | |
1131 | int current_line; | |
1132 | struct symtab *current_symtab; | |
1133 | int handling_longjmp; /* FIXME */ | |
1134 | int pid; | |
1135 | int saved_inferior_pid; | |
1136 | int update_step_sp; | |
1137 | int stepping_through_solib_after_catch; | |
1138 | bpstat stepping_through_solib_catchpoints; | |
1139 | int enable_hw_watchpoints_after_wait; | |
1140 | int stepping_through_sigtramp; | |
1141 | int new_thread_event; | |
1142 | struct target_waitstatus tmpstatus; | |
1143 | enum infwait_states infwait_state; | |
1144 | int waiton_pid; | |
1145 | int wait_some_more; | |
1146 | }; | |
1147 | ||
1148 | void init_execution_control_state PARAMS ((struct execution_control_state * ecs)); | |
1149 | ||
1150 | void handle_inferior_event PARAMS ((struct execution_control_state * ecs)); | |
cd0fc7c3 SS |
1151 | |
1152 | /* Wait for control to return from inferior to debugger. | |
1153 | If inferior gets a signal, we may decide to start it up again | |
1154 | instead of returning. That is why there is a loop in this function. | |
1155 | When this function actually returns it means the inferior | |
1156 | should be left stopped and GDB should read more commands. */ | |
1157 | ||
1158 | void | |
1159 | wait_for_inferior () | |
1160 | { | |
1161 | struct cleanup *old_cleanups; | |
1162 | struct execution_control_state ecss; | |
1163 | struct execution_control_state *ecs; | |
c906108c SS |
1164 | |
1165 | old_cleanups = make_cleanup (delete_breakpoint_current_contents, | |
1166 | &step_resume_breakpoint); | |
1167 | make_cleanup (delete_breakpoint_current_contents, | |
1168 | &through_sigtramp_breakpoint); | |
cd0fc7c3 SS |
1169 | |
1170 | /* wfi still stays in a loop, so it's OK just to take the address of | |
1171 | a local to get the ecs pointer. */ | |
1172 | ecs = &ecss; | |
1173 | ||
1174 | /* Fill in with reasonable starting values. */ | |
1175 | init_execution_control_state (ecs); | |
1176 | ||
c906108c SS |
1177 | thread_step_needed = 0; |
1178 | ||
c906108c | 1179 | /* We'll update this if & when we switch to a new thread. */ |
7a292a7a SS |
1180 | if (may_switch_from_inferior_pid) |
1181 | switched_from_inferior_pid = inferior_pid; | |
c906108c | 1182 | |
cd0fc7c3 SS |
1183 | overlay_cache_invalid = 1; |
1184 | ||
1185 | /* We have to invalidate the registers BEFORE calling target_wait | |
1186 | because they can be loaded from the target while in target_wait. | |
1187 | This makes remote debugging a bit more efficient for those | |
1188 | targets that provide critical registers as part of their normal | |
1189 | status mechanism. */ | |
1190 | ||
1191 | registers_changed (); | |
b83266a0 | 1192 | |
c906108c SS |
1193 | while (1) |
1194 | { | |
cd0fc7c3 SS |
1195 | if (target_wait_hook) |
1196 | ecs->pid = target_wait_hook (ecs->waiton_pid, ecs->wp); | |
1197 | else | |
1198 | ecs->pid = target_wait (ecs->waiton_pid, ecs->wp); | |
c906108c | 1199 | |
cd0fc7c3 SS |
1200 | /* Now figure out what to do with the result of the result. */ |
1201 | handle_inferior_event (ecs); | |
c906108c | 1202 | |
cd0fc7c3 SS |
1203 | if (!ecs->wait_some_more) |
1204 | break; | |
1205 | } | |
1206 | do_cleanups (old_cleanups); | |
1207 | } | |
c906108c | 1208 | |
43ff13b4 JM |
1209 | /* Asynchronous version of wait_for_inferior. It is called by the |
1210 | event loop whenever a change of state is detected on the file | |
1211 | descriptor corresponding to the target. It can be called more than | |
1212 | once to complete a single execution command. In such cases we need | |
1213 | to keep the state in a global variable ASYNC_ECSS. If it is the | |
1214 | last time that this function is called for a single execution | |
1215 | command, then report to the user that the inferior has stopped, and | |
1216 | do the necessary cleanups. */ | |
1217 | ||
1218 | struct execution_control_state async_ecss; | |
1219 | struct execution_control_state *async_ecs; | |
1220 | ||
1221 | void | |
1222 | fetch_inferior_event () | |
1223 | { | |
1224 | static struct cleanup *old_cleanups; | |
1225 | ||
c5aa993b | 1226 | async_ecs = &async_ecss; |
43ff13b4 JM |
1227 | |
1228 | if (!async_ecs->wait_some_more) | |
1229 | { | |
1230 | old_cleanups = make_exec_cleanup (delete_breakpoint_current_contents, | |
c5aa993b | 1231 | &step_resume_breakpoint); |
43ff13b4 | 1232 | make_exec_cleanup (delete_breakpoint_current_contents, |
c5aa993b | 1233 | &through_sigtramp_breakpoint); |
43ff13b4 JM |
1234 | |
1235 | /* Fill in with reasonable starting values. */ | |
1236 | init_execution_control_state (async_ecs); | |
1237 | ||
1238 | thread_step_needed = 0; | |
1239 | ||
1240 | /* We'll update this if & when we switch to a new thread. */ | |
1241 | if (may_switch_from_inferior_pid) | |
1242 | switched_from_inferior_pid = inferior_pid; | |
1243 | ||
1244 | overlay_cache_invalid = 1; | |
1245 | ||
1246 | /* We have to invalidate the registers BEFORE calling target_wait | |
c5aa993b JM |
1247 | because they can be loaded from the target while in target_wait. |
1248 | This makes remote debugging a bit more efficient for those | |
1249 | targets that provide critical registers as part of their normal | |
1250 | status mechanism. */ | |
43ff13b4 JM |
1251 | |
1252 | registers_changed (); | |
1253 | } | |
1254 | ||
1255 | if (target_wait_hook) | |
1256 | async_ecs->pid = target_wait_hook (async_ecs->waiton_pid, async_ecs->wp); | |
1257 | else | |
1258 | async_ecs->pid = target_wait (async_ecs->waiton_pid, async_ecs->wp); | |
1259 | ||
1260 | /* Now figure out what to do with the result of the result. */ | |
1261 | handle_inferior_event (async_ecs); | |
1262 | ||
1263 | if (!async_ecs->wait_some_more) | |
1264 | { | |
adf40b2e JM |
1265 | /* Do only the cleanups that have been added by this |
1266 | function. Let the continuations for the commands do the rest, | |
1267 | if there are any. */ | |
43ff13b4 JM |
1268 | do_exec_cleanups (old_cleanups); |
1269 | normal_stop (); | |
1270 | /* Is there anything left to do for the command issued to | |
1271 | complete? */ | |
1272 | do_all_continuations (); | |
1273 | /* Reset things after target has stopped for the async commands. */ | |
1274 | complete_execution (); | |
1275 | } | |
1276 | } | |
1277 | ||
cd0fc7c3 SS |
1278 | /* Prepare an execution control state for looping through a |
1279 | wait_for_inferior-type loop. */ | |
1280 | ||
1281 | void | |
1282 | init_execution_control_state (ecs) | |
1283 | struct execution_control_state *ecs; | |
1284 | { | |
1285 | ecs->random_signal = 0; | |
1286 | ecs->remove_breakpoints_on_following_step = 0; | |
1287 | ecs->handling_longjmp = 0; /* FIXME */ | |
1288 | ecs->update_step_sp = 0; | |
1289 | ecs->stepping_through_solib_after_catch = 0; | |
1290 | ecs->stepping_through_solib_catchpoints = NULL; | |
1291 | ecs->enable_hw_watchpoints_after_wait = 0; | |
1292 | ecs->stepping_through_sigtramp = 0; | |
1293 | ecs->sal = find_pc_line (prev_pc, 0); | |
1294 | ecs->current_line = ecs->sal.line; | |
1295 | ecs->current_symtab = ecs->sal.symtab; | |
1296 | ecs->infwait_state = infwait_normal_state; | |
1297 | ecs->waiton_pid = -1; | |
1298 | ecs->wp = &(ecs->ws); | |
1299 | } | |
1300 | ||
a0b3c4fd JM |
1301 | /* Call this function before setting step_resume_breakpoint, as a |
1302 | sanity check. We should never be setting a new | |
1303 | step_resume_breakpoint when we have an old one active. */ | |
1304 | static void | |
1305 | check_for_old_step_resume_breakpoint () | |
1306 | { | |
1307 | if (step_resume_breakpoint) | |
1308 | warning ("GDB bug: infrun.c (wait_for_inferior): dropping old step_resume breakpoint"); | |
1309 | } | |
1310 | ||
cd0fc7c3 SS |
1311 | /* Given an execution control state that has been freshly filled in |
1312 | by an event from the inferior, figure out what it means and take | |
1313 | appropriate action. */ | |
c906108c | 1314 | |
cd0fc7c3 SS |
1315 | void |
1316 | handle_inferior_event (ecs) | |
1317 | struct execution_control_state *ecs; | |
1318 | { | |
1319 | CORE_ADDR tmp; | |
1320 | int stepped_after_stopped_by_watchpoint; | |
1321 | ||
1322 | /* Keep this extra brace for now, minimizes diffs. */ | |
1323 | { | |
c5aa993b JM |
1324 | switch (ecs->infwait_state) |
1325 | { | |
1326 | case infwait_normal_state: | |
1327 | /* Since we've done a wait, we have a new event. Don't | |
1328 | carry over any expectations about needing to step over a | |
1329 | breakpoint. */ | |
1330 | thread_step_needed = 0; | |
1331 | ||
1332 | /* See comments where a TARGET_WAITKIND_SYSCALL_RETURN event | |
1333 | is serviced in this loop, below. */ | |
1334 | if (ecs->enable_hw_watchpoints_after_wait) | |
1335 | { | |
1336 | TARGET_ENABLE_HW_WATCHPOINTS (inferior_pid); | |
1337 | ecs->enable_hw_watchpoints_after_wait = 0; | |
1338 | } | |
1339 | stepped_after_stopped_by_watchpoint = 0; | |
1340 | break; | |
b83266a0 | 1341 | |
c5aa993b JM |
1342 | case infwait_thread_hop_state: |
1343 | insert_breakpoints (); | |
c906108c | 1344 | |
c5aa993b JM |
1345 | /* We need to restart all the threads now, |
1346 | * unles we're running in scheduler-locked mode. | |
1347 | * FIXME: shouldn't we look at currently_stepping ()? | |
1348 | */ | |
1349 | if (scheduler_mode == schedlock_on) | |
1350 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); | |
1351 | else | |
1352 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
1353 | ecs->infwait_state = infwait_normal_state; | |
1354 | goto wfi_continue; | |
c906108c | 1355 | |
c5aa993b JM |
1356 | case infwait_nullified_state: |
1357 | break; | |
b83266a0 | 1358 | |
c5aa993b JM |
1359 | case infwait_nonstep_watch_state: |
1360 | insert_breakpoints (); | |
b83266a0 | 1361 | |
c5aa993b JM |
1362 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
1363 | handle things like signals arriving and other things happening | |
1364 | in combination correctly? */ | |
1365 | stepped_after_stopped_by_watchpoint = 1; | |
1366 | break; | |
1367 | } | |
1368 | ecs->infwait_state = infwait_normal_state; | |
c906108c | 1369 | |
c5aa993b | 1370 | flush_cached_frames (); |
c906108c | 1371 | |
c5aa993b | 1372 | /* If it's a new process, add it to the thread database */ |
c906108c | 1373 | |
c5aa993b | 1374 | ecs->new_thread_event = ((ecs->pid != inferior_pid) && !in_thread_list (ecs->pid)); |
c906108c | 1375 | |
c5aa993b JM |
1376 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
1377 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
1378 | && ecs->new_thread_event) | |
1379 | { | |
1380 | add_thread (ecs->pid); | |
c906108c | 1381 | |
c5aa993b | 1382 | printf_filtered ("[New %s]\n", target_pid_or_tid_to_str (ecs->pid)); |
c906108c SS |
1383 | |
1384 | #if 0 | |
c5aa993b JM |
1385 | /* NOTE: This block is ONLY meant to be invoked in case of a |
1386 | "thread creation event"! If it is invoked for any other | |
1387 | sort of event (such as a new thread landing on a breakpoint), | |
1388 | the event will be discarded, which is almost certainly | |
1389 | a bad thing! | |
1390 | ||
1391 | To avoid this, the low-level module (eg. target_wait) | |
1392 | should call in_thread_list and add_thread, so that the | |
1393 | new thread is known by the time we get here. */ | |
1394 | ||
1395 | /* We may want to consider not doing a resume here in order | |
1396 | to give the user a chance to play with the new thread. | |
1397 | It might be good to make that a user-settable option. */ | |
1398 | ||
1399 | /* At this point, all threads are stopped (happens | |
1400 | automatically in either the OS or the native code). | |
1401 | Therefore we need to continue all threads in order to | |
1402 | make progress. */ | |
1403 | ||
1404 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
1405 | goto wfi_continue; | |
c906108c | 1406 | #endif |
c5aa993b | 1407 | } |
c906108c | 1408 | |
c5aa993b JM |
1409 | switch (ecs->ws.kind) |
1410 | { | |
1411 | case TARGET_WAITKIND_LOADED: | |
1412 | /* Ignore gracefully during startup of the inferior, as it | |
1413 | might be the shell which has just loaded some objects, | |
1414 | otherwise add the symbols for the newly loaded objects. */ | |
c906108c | 1415 | #ifdef SOLIB_ADD |
c5aa993b JM |
1416 | if (!stop_soon_quietly) |
1417 | { | |
1418 | /* Remove breakpoints, SOLIB_ADD might adjust | |
1419 | breakpoint addresses via breakpoint_re_set. */ | |
1420 | if (breakpoints_inserted) | |
1421 | remove_breakpoints (); | |
c906108c | 1422 | |
c5aa993b JM |
1423 | /* Check for any newly added shared libraries if we're |
1424 | supposed to be adding them automatically. */ | |
1425 | if (auto_solib_add) | |
1426 | { | |
1427 | /* Switch terminal for any messages produced by | |
1428 | breakpoint_re_set. */ | |
1429 | target_terminal_ours_for_output (); | |
1430 | SOLIB_ADD (NULL, 0, NULL); | |
1431 | target_terminal_inferior (); | |
1432 | } | |
c906108c | 1433 | |
c5aa993b JM |
1434 | /* Reinsert breakpoints and continue. */ |
1435 | if (breakpoints_inserted) | |
1436 | insert_breakpoints (); | |
1437 | } | |
c906108c | 1438 | #endif |
c5aa993b JM |
1439 | resume (0, TARGET_SIGNAL_0); |
1440 | goto wfi_continue; | |
1441 | ||
1442 | case TARGET_WAITKIND_SPURIOUS: | |
1443 | resume (0, TARGET_SIGNAL_0); | |
1444 | goto wfi_continue; | |
1445 | ||
1446 | case TARGET_WAITKIND_EXITED: | |
1447 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
1448 | annotate_exited (ecs->ws.value.integer); | |
1449 | if (ecs->ws.value.integer) | |
1450 | printf_filtered ("\nProgram exited with code 0%o.\n", | |
1451 | (unsigned int) ecs->ws.value.integer); | |
1452 | else | |
1453 | printf_filtered ("\nProgram exited normally.\n"); | |
1454 | ||
1455 | /* Record the exit code in the convenience variable $_exitcode, so | |
1456 | that the user can inspect this again later. */ | |
1457 | set_internalvar (lookup_internalvar ("_exitcode"), | |
1458 | value_from_longest (builtin_type_int, | |
1459 | (LONGEST) ecs->ws.value.integer)); | |
1460 | gdb_flush (gdb_stdout); | |
1461 | target_mourn_inferior (); | |
1462 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */ | |
1463 | stop_print_frame = 0; | |
1464 | goto stop_stepping; | |
1465 | ||
1466 | case TARGET_WAITKIND_SIGNALLED: | |
1467 | stop_print_frame = 0; | |
1468 | stop_signal = ecs->ws.value.sig; | |
1469 | target_terminal_ours (); /* Must do this before mourn anyway */ | |
1470 | annotate_signalled (); | |
1471 | ||
1472 | /* This looks pretty bogus to me. Doesn't TARGET_WAITKIND_SIGNALLED | |
1473 | mean it is already dead? This has been here since GDB 2.8, so | |
1474 | perhaps it means rms didn't understand unix waitstatuses? | |
1475 | For the moment I'm just kludging around this in remote.c | |
1476 | rather than trying to change it here --kingdon, 5 Dec 1994. */ | |
1477 | target_kill (); /* kill mourns as well */ | |
1478 | ||
1479 | printf_filtered ("\nProgram terminated with signal "); | |
1480 | annotate_signal_name (); | |
1481 | printf_filtered ("%s", target_signal_to_name (stop_signal)); | |
1482 | annotate_signal_name_end (); | |
1483 | printf_filtered (", "); | |
1484 | annotate_signal_string (); | |
1485 | printf_filtered ("%s", target_signal_to_string (stop_signal)); | |
1486 | annotate_signal_string_end (); | |
1487 | printf_filtered (".\n"); | |
1488 | ||
1489 | printf_filtered ("The program no longer exists.\n"); | |
1490 | gdb_flush (gdb_stdout); | |
1491 | singlestep_breakpoints_inserted_p = 0; /*SOFTWARE_SINGLE_STEP_P */ | |
1492 | goto stop_stepping; | |
1493 | ||
1494 | /* The following are the only cases in which we keep going; | |
1495 | the above cases end in a continue or goto. */ | |
1496 | case TARGET_WAITKIND_FORKED: | |
1497 | stop_signal = TARGET_SIGNAL_TRAP; | |
1498 | pending_follow.kind = ecs->ws.kind; | |
1499 | ||
1500 | /* Ignore fork events reported for the parent; we're only | |
1501 | interested in reacting to forks of the child. Note that | |
1502 | we expect the child's fork event to be available if we | |
1503 | waited for it now. */ | |
1504 | if (inferior_pid == ecs->pid) | |
1505 | { | |
1506 | pending_follow.fork_event.saw_parent_fork = 1; | |
1507 | pending_follow.fork_event.parent_pid = ecs->pid; | |
1508 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; | |
1509 | goto wfi_continue; | |
1510 | } | |
1511 | else | |
1512 | { | |
1513 | pending_follow.fork_event.saw_child_fork = 1; | |
1514 | pending_follow.fork_event.child_pid = ecs->pid; | |
1515 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; | |
1516 | } | |
c906108c | 1517 | |
c5aa993b JM |
1518 | stop_pc = read_pc_pid (ecs->pid); |
1519 | ecs->saved_inferior_pid = inferior_pid; | |
1520 | inferior_pid = ecs->pid; | |
1521 | stop_bpstat = bpstat_stop_status | |
1522 | (&stop_pc, | |
1523 | (DECR_PC_AFTER_BREAK ? | |
1524 | (prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
1525 | && currently_stepping (ecs)) | |
1526 | : 0) | |
1527 | ); | |
1528 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); | |
1529 | inferior_pid = ecs->saved_inferior_pid; | |
1530 | goto process_event_stop_test; | |
1531 | ||
1532 | /* If this a platform which doesn't allow a debugger to touch a | |
1533 | vfork'd inferior until after it exec's, then we'd best keep | |
1534 | our fingers entirely off the inferior, other than continuing | |
1535 | it. This has the unfortunate side-effect that catchpoints | |
1536 | of vforks will be ignored. But since the platform doesn't | |
1537 | allow the inferior be touched at vfork time, there's really | |
1538 | little choice. */ | |
1539 | case TARGET_WAITKIND_VFORKED: | |
1540 | stop_signal = TARGET_SIGNAL_TRAP; | |
1541 | pending_follow.kind = ecs->ws.kind; | |
1542 | ||
1543 | /* Is this a vfork of the parent? If so, then give any | |
1544 | vfork catchpoints a chance to trigger now. (It's | |
1545 | dangerous to do so if the child canot be touched until | |
1546 | it execs, and the child has not yet exec'd. We probably | |
1547 | should warn the user to that effect when the catchpoint | |
1548 | triggers...) */ | |
1549 | if (ecs->pid == inferior_pid) | |
1550 | { | |
1551 | pending_follow.fork_event.saw_parent_fork = 1; | |
1552 | pending_follow.fork_event.parent_pid = ecs->pid; | |
1553 | pending_follow.fork_event.child_pid = ecs->ws.value.related_pid; | |
1554 | } | |
c906108c | 1555 | |
c5aa993b JM |
1556 | /* If we've seen the child's vfork event but cannot really touch |
1557 | the child until it execs, then we must continue the child now. | |
1558 | Else, give any vfork catchpoints a chance to trigger now. */ | |
1559 | else | |
1560 | { | |
1561 | pending_follow.fork_event.saw_child_fork = 1; | |
1562 | pending_follow.fork_event.child_pid = ecs->pid; | |
1563 | pending_follow.fork_event.parent_pid = ecs->ws.value.related_pid; | |
1564 | target_post_startup_inferior (pending_follow.fork_event.child_pid); | |
1565 | follow_vfork_when_exec = !target_can_follow_vfork_prior_to_exec (); | |
1566 | if (follow_vfork_when_exec) | |
1567 | { | |
1568 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); | |
1569 | goto wfi_continue; | |
1570 | } | |
1571 | } | |
c906108c | 1572 | |
c5aa993b JM |
1573 | stop_pc = read_pc (); |
1574 | stop_bpstat = bpstat_stop_status | |
1575 | (&stop_pc, | |
1576 | (DECR_PC_AFTER_BREAK ? | |
1577 | (prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
1578 | && currently_stepping (ecs)) | |
1579 | : 0) | |
1580 | ); | |
1581 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); | |
1582 | goto process_event_stop_test; | |
1583 | ||
1584 | case TARGET_WAITKIND_EXECD: | |
1585 | stop_signal = TARGET_SIGNAL_TRAP; | |
1586 | ||
1587 | /* Is this a target which reports multiple exec events per actual | |
1588 | call to exec()? (HP-UX using ptrace does, for example.) If so, | |
1589 | ignore all but the last one. Just resume the exec'r, and wait | |
1590 | for the next exec event. */ | |
1591 | if (inferior_ignoring_leading_exec_events) | |
1592 | { | |
1593 | inferior_ignoring_leading_exec_events--; | |
1594 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
1595 | ENSURE_VFORKING_PARENT_REMAINS_STOPPED (pending_follow.fork_event.parent_pid); | |
1596 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); | |
1597 | goto wfi_continue; | |
1598 | } | |
1599 | inferior_ignoring_leading_exec_events = | |
1600 | target_reported_exec_events_per_exec_call () - 1; | |
c906108c | 1601 | |
c5aa993b JM |
1602 | pending_follow.execd_pathname = savestring (ecs->ws.value.execd_pathname, |
1603 | strlen (ecs->ws.value.execd_pathname)); | |
c906108c | 1604 | |
c5aa993b JM |
1605 | /* Did inferior_pid exec, or did a (possibly not-yet-followed) |
1606 | child of a vfork exec? | |
c906108c | 1607 | |
c5aa993b JM |
1608 | ??rehrauer: This is unabashedly an HP-UX specific thing. On |
1609 | HP-UX, events associated with a vforking inferior come in | |
1610 | threes: a vfork event for the child (always first), followed | |
1611 | a vfork event for the parent and an exec event for the child. | |
1612 | The latter two can come in either order. | |
c906108c | 1613 | |
c5aa993b JM |
1614 | If we get the parent vfork event first, life's good: We follow |
1615 | either the parent or child, and then the child's exec event is | |
1616 | a "don't care". | |
c906108c | 1617 | |
c5aa993b JM |
1618 | But if we get the child's exec event first, then we delay |
1619 | responding to it until we handle the parent's vfork. Because, | |
1620 | otherwise we can't satisfy a "catch vfork". */ | |
1621 | if (pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
1622 | { | |
1623 | pending_follow.fork_event.saw_child_exec = 1; | |
1624 | ||
1625 | /* On some targets, the child must be resumed before | |
1626 | the parent vfork event is delivered. A single-step | |
1627 | suffices. */ | |
1628 | if (RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK ()) | |
1629 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); | |
1630 | /* We expect the parent vfork event to be available now. */ | |
1631 | goto wfi_continue; | |
1632 | } | |
c906108c | 1633 | |
c5aa993b JM |
1634 | /* This causes the eventpoints and symbol table to be reset. Must |
1635 | do this now, before trying to determine whether to stop. */ | |
1636 | follow_exec (inferior_pid, pending_follow.execd_pathname); | |
1637 | free (pending_follow.execd_pathname); | |
1638 | ||
1639 | stop_pc = read_pc_pid (ecs->pid); | |
1640 | ecs->saved_inferior_pid = inferior_pid; | |
1641 | inferior_pid = ecs->pid; | |
1642 | stop_bpstat = bpstat_stop_status | |
1643 | (&stop_pc, | |
1644 | (DECR_PC_AFTER_BREAK ? | |
1645 | (prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
1646 | && currently_stepping (ecs)) | |
1647 | : 0) | |
1648 | ); | |
1649 | ecs->random_signal = !bpstat_explains_signal (stop_bpstat); | |
1650 | inferior_pid = ecs->saved_inferior_pid; | |
1651 | goto process_event_stop_test; | |
1652 | ||
1653 | /* These syscall events are returned on HP-UX, as part of its | |
1654 | implementation of page-protection-based "hardware" watchpoints. | |
1655 | HP-UX has unfortunate interactions between page-protections and | |
1656 | some system calls. Our solution is to disable hardware watches | |
1657 | when a system call is entered, and reenable them when the syscall | |
1658 | completes. The downside of this is that we may miss the precise | |
1659 | point at which a watched piece of memory is modified. "Oh well." | |
1660 | ||
1661 | Note that we may have multiple threads running, which may each | |
1662 | enter syscalls at roughly the same time. Since we don't have a | |
1663 | good notion currently of whether a watched piece of memory is | |
1664 | thread-private, we'd best not have any page-protections active | |
1665 | when any thread is in a syscall. Thus, we only want to reenable | |
1666 | hardware watches when no threads are in a syscall. | |
1667 | ||
1668 | Also, be careful not to try to gather much state about a thread | |
1669 | that's in a syscall. It's frequently a losing proposition. */ | |
1670 | case TARGET_WAITKIND_SYSCALL_ENTRY: | |
1671 | number_of_threads_in_syscalls++; | |
1672 | if (number_of_threads_in_syscalls == 1) | |
1673 | { | |
1674 | TARGET_DISABLE_HW_WATCHPOINTS (inferior_pid); | |
1675 | } | |
1676 | resume (0, TARGET_SIGNAL_0); | |
1677 | goto wfi_continue; | |
c906108c | 1678 | |
c5aa993b | 1679 | /* Before examining the threads further, step this thread to |
c906108c SS |
1680 | get it entirely out of the syscall. (We get notice of the |
1681 | event when the thread is just on the verge of exiting a | |
1682 | syscall. Stepping one instruction seems to get it back | |
1683 | into user code.) | |
1684 | ||
1685 | Note that although the logical place to reenable h/w watches | |
1686 | is here, we cannot. We cannot reenable them before stepping | |
1687 | the thread (this causes the next wait on the thread to hang). | |
1688 | ||
1689 | Nor can we enable them after stepping until we've done a wait. | |
cd0fc7c3 | 1690 | Thus, we simply set the flag ecs->enable_hw_watchpoints_after_wait |
c906108c SS |
1691 | here, which will be serviced immediately after the target |
1692 | is waited on. */ | |
c5aa993b JM |
1693 | case TARGET_WAITKIND_SYSCALL_RETURN: |
1694 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); | |
c906108c | 1695 | |
c5aa993b JM |
1696 | if (number_of_threads_in_syscalls > 0) |
1697 | { | |
1698 | number_of_threads_in_syscalls--; | |
1699 | ecs->enable_hw_watchpoints_after_wait = | |
1700 | (number_of_threads_in_syscalls == 0); | |
1701 | } | |
1702 | goto wfi_continue; | |
c906108c | 1703 | |
c5aa993b JM |
1704 | case TARGET_WAITKIND_STOPPED: |
1705 | stop_signal = ecs->ws.value.sig; | |
1706 | break; | |
1707 | } | |
c906108c | 1708 | |
c5aa993b JM |
1709 | /* We may want to consider not doing a resume here in order to give |
1710 | the user a chance to play with the new thread. It might be good | |
1711 | to make that a user-settable option. */ | |
c906108c | 1712 | |
c5aa993b JM |
1713 | /* At this point, all threads are stopped (happens automatically in |
1714 | either the OS or the native code). Therefore we need to continue | |
1715 | all threads in order to make progress. */ | |
1716 | if (ecs->new_thread_event) | |
1717 | { | |
1718 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
1719 | goto wfi_continue; | |
1720 | } | |
c906108c | 1721 | |
c5aa993b | 1722 | stop_pc = read_pc_pid (ecs->pid); |
c906108c | 1723 | |
c5aa993b JM |
1724 | /* See if a thread hit a thread-specific breakpoint that was meant for |
1725 | another thread. If so, then step that thread past the breakpoint, | |
1726 | and continue it. */ | |
c906108c | 1727 | |
c5aa993b JM |
1728 | if (stop_signal == TARGET_SIGNAL_TRAP) |
1729 | { | |
1730 | if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p) | |
1731 | ecs->random_signal = 0; | |
1732 | else if (breakpoints_inserted | |
1733 | && breakpoint_here_p (stop_pc - DECR_PC_AFTER_BREAK)) | |
1734 | { | |
cd0fc7c3 | 1735 | ecs->random_signal = 0; |
c5aa993b JM |
1736 | if (!breakpoint_thread_match (stop_pc - DECR_PC_AFTER_BREAK, |
1737 | ecs->pid)) | |
1738 | { | |
1739 | int remove_status; | |
1740 | ||
1741 | /* Saw a breakpoint, but it was hit by the wrong thread. | |
1742 | Just continue. */ | |
1743 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK, ecs->pid); | |
1744 | ||
1745 | remove_status = remove_breakpoints (); | |
1746 | /* Did we fail to remove breakpoints? If so, try | |
1747 | to set the PC past the bp. (There's at least | |
1748 | one situation in which we can fail to remove | |
1749 | the bp's: On HP-UX's that use ttrace, we can't | |
1750 | change the address space of a vforking child | |
1751 | process until the child exits (well, okay, not | |
1752 | then either :-) or execs. */ | |
1753 | if (remove_status != 0) | |
1754 | { | |
1755 | write_pc_pid (stop_pc - DECR_PC_AFTER_BREAK + 4, ecs->pid); | |
1756 | } | |
1757 | else | |
1758 | { /* Single step */ | |
1759 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); | |
1760 | /* FIXME: What if a signal arrives instead of the | |
1761 | single-step happening? */ | |
1762 | ||
1763 | ecs->waiton_pid = ecs->pid; | |
1764 | ecs->wp = &(ecs->ws); | |
1765 | ecs->infwait_state = infwait_thread_hop_state; | |
cd0fc7c3 | 1766 | goto wfi_continue; |
c5aa993b | 1767 | } |
c906108c | 1768 | |
c5aa993b JM |
1769 | /* We need to restart all the threads now, |
1770 | * unles we're running in scheduler-locked mode. | |
1771 | * FIXME: shouldn't we look at currently_stepping ()? | |
1772 | */ | |
1773 | if (scheduler_mode == schedlock_on) | |
1774 | target_resume (ecs->pid, 0, TARGET_SIGNAL_0); | |
1775 | else | |
1776 | target_resume (-1, 0, TARGET_SIGNAL_0); | |
1777 | goto wfi_continue; | |
1778 | } | |
1779 | else | |
1780 | { | |
1781 | /* This breakpoint matches--either it is the right | |
1782 | thread or it's a generic breakpoint for all threads. | |
1783 | Remember that we'll need to step just _this_ thread | |
1784 | on any following user continuation! */ | |
1785 | thread_step_needed = 1; | |
1786 | } | |
1787 | } | |
1788 | } | |
1789 | else | |
1790 | ecs->random_signal = 1; | |
1791 | ||
1792 | /* See if something interesting happened to the non-current thread. If | |
1793 | so, then switch to that thread, and eventually give control back to | |
1794 | the user. | |
1795 | ||
1796 | Note that if there's any kind of pending follow (i.e., of a fork, | |
1797 | vfork or exec), we don't want to do this now. Rather, we'll let | |
1798 | the next resume handle it. */ | |
1799 | if ((ecs->pid != inferior_pid) && | |
1800 | (pending_follow.kind == TARGET_WAITKIND_SPURIOUS)) | |
1801 | { | |
1802 | int printed = 0; | |
c906108c | 1803 | |
c5aa993b JM |
1804 | /* If it's a random signal for a non-current thread, notify user |
1805 | if he's expressed an interest. */ | |
1806 | if (ecs->random_signal | |
1807 | && signal_print[stop_signal]) | |
1808 | { | |
c906108c SS |
1809 | /* ??rehrauer: I don't understand the rationale for this code. If the |
1810 | inferior will stop as a result of this signal, then the act of handling | |
1811 | the stop ought to print a message that's couches the stoppage in user | |
1812 | terms, e.g., "Stopped for breakpoint/watchpoint". If the inferior | |
1813 | won't stop as a result of the signal -- i.e., if the signal is merely | |
1814 | a side-effect of something GDB's doing "under the covers" for the | |
1815 | user, such as stepping threads over a breakpoint they shouldn't stop | |
1816 | for -- then the message seems to be a serious annoyance at best. | |
1817 | ||
1818 | For now, remove the message altogether. */ | |
1819 | #if 0 | |
c5aa993b JM |
1820 | printed = 1; |
1821 | target_terminal_ours_for_output (); | |
1822 | printf_filtered ("\nProgram received signal %s, %s.\n", | |
1823 | target_signal_to_name (stop_signal), | |
1824 | target_signal_to_string (stop_signal)); | |
1825 | gdb_flush (gdb_stdout); | |
c906108c | 1826 | #endif |
c5aa993b | 1827 | } |
c906108c | 1828 | |
c5aa993b JM |
1829 | /* If it's not SIGTRAP and not a signal we want to stop for, then |
1830 | continue the thread. */ | |
c906108c | 1831 | |
c5aa993b JM |
1832 | if (stop_signal != TARGET_SIGNAL_TRAP |
1833 | && !signal_stop[stop_signal]) | |
1834 | { | |
1835 | if (printed) | |
1836 | target_terminal_inferior (); | |
c906108c | 1837 | |
c5aa993b JM |
1838 | /* Clear the signal if it should not be passed. */ |
1839 | if (signal_program[stop_signal] == 0) | |
1840 | stop_signal = TARGET_SIGNAL_0; | |
c906108c | 1841 | |
c5aa993b JM |
1842 | target_resume (ecs->pid, 0, stop_signal); |
1843 | goto wfi_continue; | |
1844 | } | |
c906108c | 1845 | |
c5aa993b JM |
1846 | /* It's a SIGTRAP or a signal we're interested in. Switch threads, |
1847 | and fall into the rest of wait_for_inferior(). */ | |
1848 | ||
1849 | /* Save infrun state for the old thread. */ | |
1850 | save_infrun_state (inferior_pid, prev_pc, | |
1851 | prev_func_start, prev_func_name, | |
1852 | trap_expected, step_resume_breakpoint, | |
1853 | through_sigtramp_breakpoint, | |
1854 | step_range_start, step_range_end, | |
1855 | step_frame_address, ecs->handling_longjmp, | |
1856 | ecs->another_trap, | |
1857 | ecs->stepping_through_solib_after_catch, | |
1858 | ecs->stepping_through_solib_catchpoints, | |
1859 | ecs->stepping_through_sigtramp); | |
1860 | ||
1861 | if (may_switch_from_inferior_pid) | |
1862 | switched_from_inferior_pid = inferior_pid; | |
1863 | ||
1864 | inferior_pid = ecs->pid; | |
1865 | ||
1866 | /* Load infrun state for the new thread. */ | |
1867 | load_infrun_state (inferior_pid, &prev_pc, | |
1868 | &prev_func_start, &prev_func_name, | |
1869 | &trap_expected, &step_resume_breakpoint, | |
1870 | &through_sigtramp_breakpoint, | |
1871 | &step_range_start, &step_range_end, | |
1872 | &step_frame_address, &ecs->handling_longjmp, | |
1873 | &ecs->another_trap, | |
1874 | &ecs->stepping_through_solib_after_catch, | |
1875 | &ecs->stepping_through_solib_catchpoints, | |
1876 | &ecs->stepping_through_sigtramp); | |
1877 | ||
1878 | if (context_hook) | |
1879 | context_hook (pid_to_thread_id (ecs->pid)); | |
1880 | ||
1881 | printf_filtered ("[Switching to %s]\n", target_pid_to_str (ecs->pid)); | |
1882 | flush_cached_frames (); | |
1883 | } | |
c906108c | 1884 | |
c5aa993b JM |
1885 | if (SOFTWARE_SINGLE_STEP_P && singlestep_breakpoints_inserted_p) |
1886 | { | |
1887 | /* Pull the single step breakpoints out of the target. */ | |
1888 | SOFTWARE_SINGLE_STEP (0, 0); | |
1889 | singlestep_breakpoints_inserted_p = 0; | |
1890 | } | |
c906108c | 1891 | |
c5aa993b JM |
1892 | /* If PC is pointing at a nullified instruction, then step beyond |
1893 | it so that the user won't be confused when GDB appears to be ready | |
1894 | to execute it. */ | |
c906108c | 1895 | |
c5aa993b JM |
1896 | /* if (INSTRUCTION_NULLIFIED && currently_stepping (ecs)) */ |
1897 | if (INSTRUCTION_NULLIFIED) | |
1898 | { | |
1899 | registers_changed (); | |
1900 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); | |
c906108c | 1901 | |
c5aa993b JM |
1902 | /* We may have received a signal that we want to pass to |
1903 | the inferior; therefore, we must not clobber the waitstatus | |
1904 | in WS. */ | |
c906108c | 1905 | |
c5aa993b JM |
1906 | ecs->infwait_state = infwait_nullified_state; |
1907 | ecs->waiton_pid = ecs->pid; | |
1908 | ecs->wp = &(ecs->tmpstatus); | |
1909 | goto wfi_continue; | |
1910 | } | |
c906108c | 1911 | |
c5aa993b JM |
1912 | /* It may not be necessary to disable the watchpoint to stop over |
1913 | it. For example, the PA can (with some kernel cooperation) | |
1914 | single step over a watchpoint without disabling the watchpoint. */ | |
1915 | if (HAVE_STEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) | |
1916 | { | |
1917 | resume (1, 0); | |
1918 | goto wfi_continue; | |
1919 | } | |
c906108c | 1920 | |
c5aa993b JM |
1921 | /* It is far more common to need to disable a watchpoint to step |
1922 | the inferior over it. FIXME. What else might a debug | |
1923 | register or page protection watchpoint scheme need here? */ | |
1924 | if (HAVE_NONSTEPPABLE_WATCHPOINT && STOPPED_BY_WATCHPOINT (ecs->ws)) | |
1925 | { | |
1926 | /* At this point, we are stopped at an instruction which has | |
1927 | attempted to write to a piece of memory under control of | |
1928 | a watchpoint. The instruction hasn't actually executed | |
1929 | yet. If we were to evaluate the watchpoint expression | |
1930 | now, we would get the old value, and therefore no change | |
1931 | would seem to have occurred. | |
1932 | ||
1933 | In order to make watchpoints work `right', we really need | |
1934 | to complete the memory write, and then evaluate the | |
1935 | watchpoint expression. The following code does that by | |
1936 | removing the watchpoint (actually, all watchpoints and | |
1937 | breakpoints), single-stepping the target, re-inserting | |
1938 | watchpoints, and then falling through to let normal | |
1939 | single-step processing handle proceed. Since this | |
1940 | includes evaluating watchpoints, things will come to a | |
1941 | stop in the correct manner. */ | |
1942 | ||
1943 | write_pc (stop_pc - DECR_PC_AFTER_BREAK); | |
1944 | ||
1945 | remove_breakpoints (); | |
1946 | registers_changed (); | |
1947 | target_resume (ecs->pid, 1, TARGET_SIGNAL_0); /* Single step */ | |
1948 | ||
1949 | ecs->waiton_pid = ecs->pid; | |
1950 | ecs->wp = &(ecs->ws); | |
1951 | ecs->infwait_state = infwait_nonstep_watch_state; | |
1952 | goto wfi_continue; | |
1953 | } | |
c906108c | 1954 | |
c5aa993b JM |
1955 | /* It may be possible to simply continue after a watchpoint. */ |
1956 | if (HAVE_CONTINUABLE_WATCHPOINT) | |
1957 | STOPPED_BY_WATCHPOINT (ecs->ws); | |
1958 | ||
1959 | ecs->stop_func_start = 0; | |
1960 | ecs->stop_func_end = 0; | |
1961 | ecs->stop_func_name = 0; | |
1962 | /* Don't care about return value; stop_func_start and stop_func_name | |
1963 | will both be 0 if it doesn't work. */ | |
1964 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
1965 | &ecs->stop_func_start, &ecs->stop_func_end); | |
1966 | ecs->stop_func_start += FUNCTION_START_OFFSET; | |
1967 | ecs->another_trap = 0; | |
1968 | bpstat_clear (&stop_bpstat); | |
1969 | stop_step = 0; | |
1970 | stop_stack_dummy = 0; | |
1971 | stop_print_frame = 1; | |
1972 | ecs->random_signal = 0; | |
1973 | stopped_by_random_signal = 0; | |
1974 | breakpoints_failed = 0; | |
1975 | ||
1976 | /* Look at the cause of the stop, and decide what to do. | |
1977 | The alternatives are: | |
1978 | 1) break; to really stop and return to the debugger, | |
1979 | 2) drop through to start up again | |
1980 | (set ecs->another_trap to 1 to single step once) | |
1981 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 | |
1982 | will be made according to the signal handling tables. */ | |
1983 | ||
1984 | /* First, distinguish signals caused by the debugger from signals | |
1985 | that have to do with the program's own actions. | |
1986 | Note that breakpoint insns may cause SIGTRAP or SIGILL | |
1987 | or SIGEMT, depending on the operating system version. | |
1988 | Here we detect when a SIGILL or SIGEMT is really a breakpoint | |
1989 | and change it to SIGTRAP. */ | |
1990 | ||
1991 | if (stop_signal == TARGET_SIGNAL_TRAP | |
1992 | || (breakpoints_inserted && | |
1993 | (stop_signal == TARGET_SIGNAL_ILL | |
1994 | || stop_signal == TARGET_SIGNAL_EMT | |
1995 | )) | |
1996 | || stop_soon_quietly) | |
1997 | { | |
1998 | if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) | |
1999 | { | |
2000 | stop_print_frame = 0; | |
cd0fc7c3 | 2001 | goto wfi_break; |
c5aa993b JM |
2002 | } |
2003 | if (stop_soon_quietly) | |
2004 | goto wfi_break; | |
c906108c | 2005 | |
c5aa993b JM |
2006 | /* Don't even think about breakpoints |
2007 | if just proceeded over a breakpoint. | |
c906108c | 2008 | |
c5aa993b JM |
2009 | However, if we are trying to proceed over a breakpoint |
2010 | and end up in sigtramp, then through_sigtramp_breakpoint | |
2011 | will be set and we should check whether we've hit the | |
2012 | step breakpoint. */ | |
2013 | if (stop_signal == TARGET_SIGNAL_TRAP && trap_expected | |
2014 | && through_sigtramp_breakpoint == NULL) | |
2015 | bpstat_clear (&stop_bpstat); | |
2016 | else | |
2017 | { | |
2018 | /* See if there is a breakpoint at the current PC. */ | |
2019 | stop_bpstat = bpstat_stop_status | |
2020 | (&stop_pc, | |
2021 | (DECR_PC_AFTER_BREAK ? | |
2022 | /* Notice the case of stepping through a jump | |
2023 | that lands just after a breakpoint. | |
2024 | Don't confuse that with hitting the breakpoint. | |
2025 | What we check for is that 1) stepping is going on | |
2026 | and 2) the pc before the last insn does not match | |
2027 | the address of the breakpoint before the current pc | |
2028 | and 3) we didn't hit a breakpoint in a signal handler | |
2029 | without an intervening stop in sigtramp, which is | |
2030 | detected by a new stack pointer value below | |
2031 | any usual function calling stack adjustments. */ | |
2032 | (currently_stepping (ecs) | |
2033 | && prev_pc != stop_pc - DECR_PC_AFTER_BREAK | |
2034 | && !(step_range_end | |
2035 | && INNER_THAN (read_sp (), (step_sp - 16)))) : | |
2036 | 0) | |
2037 | ); | |
2038 | /* Following in case break condition called a | |
2039 | function. */ | |
2040 | stop_print_frame = 1; | |
2041 | } | |
c906108c | 2042 | |
c5aa993b JM |
2043 | if (stop_signal == TARGET_SIGNAL_TRAP) |
2044 | ecs->random_signal | |
2045 | = !(bpstat_explains_signal (stop_bpstat) | |
2046 | || trap_expected | |
2047 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P | |
2048 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), | |
2049 | FRAME_FP (get_current_frame ()))) | |
2050 | || (step_range_end && step_resume_breakpoint == NULL)); | |
2051 | ||
2052 | else | |
2053 | { | |
cd0fc7c3 | 2054 | ecs->random_signal |
c906108c | 2055 | = !(bpstat_explains_signal (stop_bpstat) |
c5aa993b JM |
2056 | /* End of a stack dummy. Some systems (e.g. Sony |
2057 | news) give another signal besides SIGTRAP, so | |
2058 | check here as well as above. */ | |
7a292a7a SS |
2059 | || (!CALL_DUMMY_BREAKPOINT_OFFSET_P |
2060 | && PC_IN_CALL_DUMMY (stop_pc, read_sp (), | |
2061 | FRAME_FP (get_current_frame ()))) | |
c5aa993b JM |
2062 | ); |
2063 | if (!ecs->random_signal) | |
2064 | stop_signal = TARGET_SIGNAL_TRAP; | |
2065 | } | |
2066 | } | |
c906108c | 2067 | |
c5aa993b JM |
2068 | /* When we reach this point, we've pretty much decided |
2069 | that the reason for stopping must've been a random | |
2070 | (unexpected) signal. */ | |
2071 | ||
2072 | else | |
2073 | ecs->random_signal = 1; | |
2074 | /* If a fork, vfork or exec event was seen, then there are two | |
2075 | possible responses we can make: | |
2076 | ||
2077 | 1. If a catchpoint triggers for the event (ecs->random_signal == 0), | |
2078 | then we must stop now and issue a prompt. We will resume | |
2079 | the inferior when the user tells us to. | |
2080 | 2. If no catchpoint triggers for the event (ecs->random_signal == 1), | |
2081 | then we must resume the inferior now and keep checking. | |
2082 | ||
2083 | In either case, we must take appropriate steps to "follow" the | |
2084 | the fork/vfork/exec when the inferior is resumed. For example, | |
2085 | if follow-fork-mode is "child", then we must detach from the | |
2086 | parent inferior and follow the new child inferior. | |
2087 | ||
2088 | In either case, setting pending_follow causes the next resume() | |
2089 | to take the appropriate following action. */ | |
2090 | process_event_stop_test: | |
2091 | if (ecs->ws.kind == TARGET_WAITKIND_FORKED) | |
2092 | { | |
2093 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ | |
2094 | { | |
2095 | trap_expected = 1; | |
2096 | stop_signal = TARGET_SIGNAL_0; | |
2097 | goto keep_going; | |
2098 | } | |
2099 | } | |
2100 | else if (ecs->ws.kind == TARGET_WAITKIND_VFORKED) | |
2101 | { | |
2102 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ | |
2103 | { | |
2104 | stop_signal = TARGET_SIGNAL_0; | |
2105 | goto keep_going; | |
2106 | } | |
2107 | } | |
2108 | else if (ecs->ws.kind == TARGET_WAITKIND_EXECD) | |
2109 | { | |
2110 | pending_follow.kind = ecs->ws.kind; | |
2111 | if (ecs->random_signal) /* I.e., no catchpoint triggered for this. */ | |
2112 | { | |
2113 | trap_expected = 1; | |
2114 | stop_signal = TARGET_SIGNAL_0; | |
2115 | goto keep_going; | |
2116 | } | |
2117 | } | |
c906108c | 2118 | |
c5aa993b JM |
2119 | /* For the program's own signals, act according to |
2120 | the signal handling tables. */ | |
c906108c | 2121 | |
c5aa993b JM |
2122 | if (ecs->random_signal) |
2123 | { | |
2124 | /* Signal not for debugging purposes. */ | |
2125 | int printed = 0; | |
2126 | ||
2127 | stopped_by_random_signal = 1; | |
2128 | ||
2129 | if (signal_print[stop_signal]) | |
2130 | { | |
2131 | printed = 1; | |
2132 | target_terminal_ours_for_output (); | |
2133 | annotate_signal (); | |
2134 | printf_filtered ("\nProgram received signal "); | |
2135 | annotate_signal_name (); | |
2136 | printf_filtered ("%s", target_signal_to_name (stop_signal)); | |
2137 | annotate_signal_name_end (); | |
2138 | printf_filtered (", "); | |
2139 | annotate_signal_string (); | |
2140 | printf_filtered ("%s", target_signal_to_string (stop_signal)); | |
2141 | annotate_signal_string_end (); | |
2142 | printf_filtered (".\n"); | |
2143 | gdb_flush (gdb_stdout); | |
2144 | } | |
2145 | if (signal_stop[stop_signal]) | |
2146 | goto wfi_break; | |
2147 | /* If not going to stop, give terminal back | |
2148 | if we took it away. */ | |
2149 | else if (printed) | |
2150 | target_terminal_inferior (); | |
2151 | ||
2152 | /* Clear the signal if it should not be passed. */ | |
2153 | if (signal_program[stop_signal] == 0) | |
2154 | stop_signal = TARGET_SIGNAL_0; | |
2155 | ||
a0b3c4fd JM |
2156 | /* I'm not sure whether this needs to be check_sigtramp2 or |
2157 | whether it could/should be keep_going. | |
2158 | ||
2159 | This used to jump to step_over_function if we are stepping, | |
2160 | which is wrong. | |
2161 | ||
2162 | Suppose the user does a `next' over a function call, and while | |
2163 | that call is in progress, the inferior receives a signal for | |
2164 | which GDB does not stop (i.e., signal_stop[SIG] is false). In | |
2165 | that case, when we reach this point, there is already a | |
2166 | step-resume breakpoint established, right where it should be: | |
2167 | immediately after the function call the user is "next"-ing | |
2168 | over. If we jump to step_over_function now, two bad things | |
2169 | happen: | |
2170 | ||
2171 | - we'll create a new breakpoint, at wherever the current | |
2172 | frame's return address happens to be. That could be | |
2173 | anywhere, depending on what function call happens to be on | |
2174 | the top of the stack at that point. Point is, it's probably | |
2175 | not where we need it. | |
2176 | ||
2177 | - the existing step-resume breakpoint (which is at the correct | |
2178 | address) will get orphaned: step_resume_breakpoint will point | |
2179 | to the new breakpoint, and the old step-resume breakpoint | |
2180 | will never be cleaned up. | |
2181 | ||
2182 | The old behavior was meant to help HP-UX single-step out of | |
2183 | sigtramps. It would place the new breakpoint at prev_pc, which | |
2184 | was certainly wrong. I don't know the details there, so fixing | |
2185 | this probably breaks that. As with anything else, it's up to | |
2186 | the HP-UX maintainer to furnish a fix that doesn't break other | |
2187 | platforms. --JimB, 20 May 1999 */ | |
2188 | goto check_sigtramp2; | |
c5aa993b JM |
2189 | } |
2190 | ||
2191 | /* Handle cases caused by hitting a breakpoint. */ | |
2192 | { | |
2193 | CORE_ADDR jmp_buf_pc; | |
2194 | struct bpstat_what what; | |
2195 | ||
2196 | what = bpstat_what (stop_bpstat); | |
2197 | ||
2198 | if (what.call_dummy) | |
c906108c | 2199 | { |
c5aa993b JM |
2200 | stop_stack_dummy = 1; |
2201 | #ifdef HP_OS_BUG | |
2202 | trap_expected_after_continue = 1; | |
2203 | #endif | |
c906108c | 2204 | } |
c5aa993b JM |
2205 | |
2206 | switch (what.main_action) | |
c906108c | 2207 | { |
c5aa993b JM |
2208 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
2209 | /* If we hit the breakpoint at longjmp, disable it for the | |
2210 | duration of this command. Then, install a temporary | |
2211 | breakpoint at the target of the jmp_buf. */ | |
2212 | disable_longjmp_breakpoint (); | |
2213 | remove_breakpoints (); | |
2214 | breakpoints_inserted = 0; | |
2215 | if (!GET_LONGJMP_TARGET (&jmp_buf_pc)) | |
2216 | goto keep_going; | |
2217 | ||
2218 | /* Need to blow away step-resume breakpoint, as it | |
2219 | interferes with us */ | |
2220 | if (step_resume_breakpoint != NULL) | |
c906108c | 2221 | { |
c5aa993b JM |
2222 | delete_breakpoint (step_resume_breakpoint); |
2223 | step_resume_breakpoint = NULL; | |
c906108c | 2224 | } |
c5aa993b JM |
2225 | /* Not sure whether we need to blow this away too, but probably |
2226 | it is like the step-resume breakpoint. */ | |
2227 | if (through_sigtramp_breakpoint != NULL) | |
c906108c | 2228 | { |
c5aa993b JM |
2229 | delete_breakpoint (through_sigtramp_breakpoint); |
2230 | through_sigtramp_breakpoint = NULL; | |
c906108c | 2231 | } |
c906108c | 2232 | |
c5aa993b JM |
2233 | #if 0 |
2234 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2235 | if (step_over_calls > 0) | |
2236 | set_longjmp_resume_breakpoint (jmp_buf_pc, | |
2237 | get_current_frame ()); | |
2238 | else | |
2239 | #endif /* 0 */ | |
2240 | set_longjmp_resume_breakpoint (jmp_buf_pc, NULL); | |
2241 | ecs->handling_longjmp = 1; /* FIXME */ | |
2242 | goto keep_going; | |
c906108c | 2243 | |
c5aa993b JM |
2244 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
2245 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE: | |
2246 | remove_breakpoints (); | |
2247 | breakpoints_inserted = 0; | |
2248 | #if 0 | |
2249 | /* FIXME - Need to implement nested temporary breakpoints */ | |
2250 | if (step_over_calls | |
2251 | && (INNER_THAN (FRAME_FP (get_current_frame ()), | |
2252 | step_frame_address))) | |
2253 | { | |
2254 | ecs->another_trap = 1; | |
2255 | goto keep_going; | |
2256 | } | |
2257 | #endif /* 0 */ | |
2258 | disable_longjmp_breakpoint (); | |
2259 | ecs->handling_longjmp = 0; /* FIXME */ | |
2260 | if (what.main_action == BPSTAT_WHAT_CLEAR_LONGJMP_RESUME) | |
2261 | break; | |
2262 | /* else fallthrough */ | |
c906108c | 2263 | |
c5aa993b JM |
2264 | case BPSTAT_WHAT_SINGLE: |
2265 | if (breakpoints_inserted) | |
c906108c | 2266 | { |
c5aa993b JM |
2267 | thread_step_needed = 1; |
2268 | remove_breakpoints (); | |
c906108c | 2269 | } |
c5aa993b JM |
2270 | breakpoints_inserted = 0; |
2271 | ecs->another_trap = 1; | |
2272 | /* Still need to check other stuff, at least the case | |
2273 | where we are stepping and step out of the right range. */ | |
2274 | break; | |
c906108c | 2275 | |
c5aa993b JM |
2276 | case BPSTAT_WHAT_STOP_NOISY: |
2277 | stop_print_frame = 1; | |
c906108c | 2278 | |
c5aa993b JM |
2279 | /* We are about to nuke the step_resume_breakpoint and |
2280 | through_sigtramp_breakpoint via the cleanup chain, so | |
2281 | no need to worry about it here. */ | |
c906108c | 2282 | |
c5aa993b | 2283 | goto stop_stepping; |
c906108c | 2284 | |
c5aa993b JM |
2285 | case BPSTAT_WHAT_STOP_SILENT: |
2286 | stop_print_frame = 0; | |
c906108c | 2287 | |
c5aa993b JM |
2288 | /* We are about to nuke the step_resume_breakpoint and |
2289 | through_sigtramp_breakpoint via the cleanup chain, so | |
2290 | no need to worry about it here. */ | |
c906108c | 2291 | |
c5aa993b | 2292 | goto stop_stepping; |
c906108c | 2293 | |
c5aa993b JM |
2294 | case BPSTAT_WHAT_STEP_RESUME: |
2295 | /* This proably demands a more elegant solution, but, yeah | |
2296 | right... | |
2297 | ||
2298 | This function's use of the simple variable | |
2299 | step_resume_breakpoint doesn't seem to accomodate | |
2300 | simultaneously active step-resume bp's, although the | |
2301 | breakpoint list certainly can. | |
2302 | ||
2303 | If we reach here and step_resume_breakpoint is already | |
2304 | NULL, then apparently we have multiple active | |
2305 | step-resume bp's. We'll just delete the breakpoint we | |
2306 | stopped at, and carry on. */ | |
2307 | if (step_resume_breakpoint == NULL) | |
2308 | { | |
2309 | step_resume_breakpoint = | |
2310 | bpstat_find_step_resume_breakpoint (stop_bpstat); | |
2311 | } | |
2312 | delete_breakpoint (step_resume_breakpoint); | |
2313 | step_resume_breakpoint = NULL; | |
2314 | break; | |
2315 | ||
2316 | case BPSTAT_WHAT_THROUGH_SIGTRAMP: | |
2317 | if (through_sigtramp_breakpoint) | |
2318 | delete_breakpoint (through_sigtramp_breakpoint); | |
2319 | through_sigtramp_breakpoint = NULL; | |
2320 | ||
2321 | /* If were waiting for a trap, hitting the step_resume_break | |
2322 | doesn't count as getting it. */ | |
2323 | if (trap_expected) | |
2324 | ecs->another_trap = 1; | |
2325 | break; | |
c906108c | 2326 | |
c5aa993b JM |
2327 | case BPSTAT_WHAT_CHECK_SHLIBS: |
2328 | case BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK: | |
2329 | #ifdef SOLIB_ADD | |
c906108c | 2330 | { |
c5aa993b JM |
2331 | /* Remove breakpoints, we eventually want to step over the |
2332 | shlib event breakpoint, and SOLIB_ADD might adjust | |
2333 | breakpoint addresses via breakpoint_re_set. */ | |
2334 | if (breakpoints_inserted) | |
2335 | remove_breakpoints (); | |
c906108c | 2336 | breakpoints_inserted = 0; |
c906108c | 2337 | |
c5aa993b JM |
2338 | /* Check for any newly added shared libraries if we're |
2339 | supposed to be adding them automatically. */ | |
2340 | if (auto_solib_add) | |
c906108c | 2341 | { |
c5aa993b JM |
2342 | /* Switch terminal for any messages produced by |
2343 | breakpoint_re_set. */ | |
2344 | target_terminal_ours_for_output (); | |
2345 | SOLIB_ADD (NULL, 0, NULL); | |
2346 | target_terminal_inferior (); | |
c906108c | 2347 | } |
c5aa993b JM |
2348 | |
2349 | /* Try to reenable shared library breakpoints, additional | |
2350 | code segments in shared libraries might be mapped in now. */ | |
2351 | re_enable_breakpoints_in_shlibs (); | |
2352 | ||
2353 | /* If requested, stop when the dynamic linker notifies | |
2354 | gdb of events. This allows the user to get control | |
2355 | and place breakpoints in initializer routines for | |
2356 | dynamically loaded objects (among other things). */ | |
2357 | if (stop_on_solib_events) | |
c906108c | 2358 | { |
c5aa993b JM |
2359 | stop_print_frame = 0; |
2360 | goto stop_stepping; | |
c906108c SS |
2361 | } |
2362 | ||
c5aa993b JM |
2363 | /* If we stopped due to an explicit catchpoint, then the |
2364 | (see above) call to SOLIB_ADD pulled in any symbols | |
2365 | from a newly-loaded library, if appropriate. | |
2366 | ||
2367 | We do want the inferior to stop, but not where it is | |
2368 | now, which is in the dynamic linker callback. Rather, | |
2369 | we would like it stop in the user's program, just after | |
2370 | the call that caused this catchpoint to trigger. That | |
2371 | gives the user a more useful vantage from which to | |
2372 | examine their program's state. */ | |
2373 | else if (what.main_action == BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK) | |
2374 | { | |
2375 | /* ??rehrauer: If I could figure out how to get the | |
2376 | right return PC from here, we could just set a temp | |
2377 | breakpoint and resume. I'm not sure we can without | |
2378 | cracking open the dld's shared libraries and sniffing | |
2379 | their unwind tables and text/data ranges, and that's | |
2380 | not a terribly portable notion. | |
2381 | ||
2382 | Until that time, we must step the inferior out of the | |
2383 | dld callback, and also out of the dld itself (and any | |
2384 | code or stubs in libdld.sl, such as "shl_load" and | |
2385 | friends) until we reach non-dld code. At that point, | |
2386 | we can stop stepping. */ | |
2387 | bpstat_get_triggered_catchpoints (stop_bpstat, | |
2388 | &ecs->stepping_through_solib_catchpoints); | |
2389 | ecs->stepping_through_solib_after_catch = 1; | |
2390 | ||
2391 | /* Be sure to lift all breakpoints, so the inferior does | |
2392 | actually step past this point... */ | |
2393 | ecs->another_trap = 1; | |
2394 | break; | |
2395 | } | |
2396 | else | |
c906108c | 2397 | { |
c5aa993b | 2398 | /* We want to step over this breakpoint, then keep going. */ |
cd0fc7c3 | 2399 | ecs->another_trap = 1; |
c5aa993b | 2400 | break; |
c906108c | 2401 | } |
c5aa993b JM |
2402 | } |
2403 | #endif | |
2404 | break; | |
c906108c | 2405 | |
c5aa993b JM |
2406 | case BPSTAT_WHAT_LAST: |
2407 | /* Not a real code, but listed here to shut up gcc -Wall. */ | |
c906108c | 2408 | |
c5aa993b JM |
2409 | case BPSTAT_WHAT_KEEP_CHECKING: |
2410 | break; | |
2411 | } | |
2412 | } | |
c906108c | 2413 | |
c5aa993b JM |
2414 | /* We come here if we hit a breakpoint but should not |
2415 | stop for it. Possibly we also were stepping | |
2416 | and should stop for that. So fall through and | |
2417 | test for stepping. But, if not stepping, | |
2418 | do not stop. */ | |
c906108c | 2419 | |
c5aa993b JM |
2420 | /* Are we stepping to get the inferior out of the dynamic |
2421 | linker's hook (and possibly the dld itself) after catching | |
2422 | a shlib event? */ | |
2423 | if (ecs->stepping_through_solib_after_catch) | |
2424 | { | |
2425 | #if defined(SOLIB_ADD) | |
2426 | /* Have we reached our destination? If not, keep going. */ | |
2427 | if (SOLIB_IN_DYNAMIC_LINKER (ecs->pid, stop_pc)) | |
2428 | { | |
2429 | ecs->another_trap = 1; | |
2430 | goto keep_going; | |
2431 | } | |
2432 | #endif | |
2433 | /* Else, stop and report the catchpoint(s) whose triggering | |
2434 | caused us to begin stepping. */ | |
2435 | ecs->stepping_through_solib_after_catch = 0; | |
2436 | bpstat_clear (&stop_bpstat); | |
2437 | stop_bpstat = bpstat_copy (ecs->stepping_through_solib_catchpoints); | |
2438 | bpstat_clear (&ecs->stepping_through_solib_catchpoints); | |
2439 | stop_print_frame = 1; | |
2440 | goto stop_stepping; | |
2441 | } | |
c906108c | 2442 | |
c5aa993b JM |
2443 | if (!CALL_DUMMY_BREAKPOINT_OFFSET_P) |
2444 | { | |
2445 | /* This is the old way of detecting the end of the stack dummy. | |
2446 | An architecture which defines CALL_DUMMY_BREAKPOINT_OFFSET gets | |
2447 | handled above. As soon as we can test it on all of them, all | |
2448 | architectures should define it. */ | |
2449 | ||
2450 | /* If this is the breakpoint at the end of a stack dummy, | |
2451 | just stop silently, unless the user was doing an si/ni, in which | |
2452 | case she'd better know what she's doing. */ | |
2453 | ||
2454 | if (CALL_DUMMY_HAS_COMPLETED (stop_pc, read_sp (), | |
2455 | FRAME_FP (get_current_frame ())) | |
2456 | && !step_range_end) | |
2457 | { | |
c906108c | 2458 | stop_print_frame = 0; |
c5aa993b JM |
2459 | stop_stack_dummy = 1; |
2460 | #ifdef HP_OS_BUG | |
2461 | trap_expected_after_continue = 1; | |
2462 | #endif | |
2463 | goto wfi_break; | |
2464 | } | |
2465 | } | |
c906108c | 2466 | |
c5aa993b JM |
2467 | if (step_resume_breakpoint) |
2468 | /* Having a step-resume breakpoint overrides anything | |
2469 | else having to do with stepping commands until | |
2470 | that breakpoint is reached. */ | |
2471 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2472 | whether it could/should be keep_going. */ | |
2473 | goto check_sigtramp2; | |
2474 | ||
2475 | if (step_range_end == 0) | |
2476 | /* Likewise if we aren't even stepping. */ | |
2477 | /* I'm not sure whether this needs to be check_sigtramp2 or | |
2478 | whether it could/should be keep_going. */ | |
2479 | goto check_sigtramp2; | |
2480 | ||
2481 | /* If stepping through a line, keep going if still within it. | |
2482 | ||
2483 | Note that step_range_end is the address of the first instruction | |
2484 | beyond the step range, and NOT the address of the last instruction | |
2485 | within it! */ | |
2486 | if (stop_pc >= step_range_start | |
2487 | && stop_pc < step_range_end) | |
2488 | { | |
2489 | /* We might be doing a BPSTAT_WHAT_SINGLE and getting a signal. | |
2490 | So definately need to check for sigtramp here. */ | |
2491 | goto check_sigtramp2; | |
2492 | } | |
c906108c | 2493 | |
c5aa993b | 2494 | /* We stepped out of the stepping range. */ |
c906108c | 2495 | |
c5aa993b JM |
2496 | /* If we are stepping at the source level and entered the runtime |
2497 | loader dynamic symbol resolution code, we keep on single stepping | |
2498 | until we exit the run time loader code and reach the callee's | |
2499 | address. */ | |
2500 | if (step_over_calls < 0 && IN_SOLIB_DYNSYM_RESOLVE_CODE (stop_pc)) | |
2501 | goto keep_going; | |
c906108c | 2502 | |
c5aa993b JM |
2503 | /* We can't update step_sp every time through the loop, because |
2504 | reading the stack pointer would slow down stepping too much. | |
2505 | But we can update it every time we leave the step range. */ | |
2506 | ecs->update_step_sp = 1; | |
c906108c | 2507 | |
c5aa993b JM |
2508 | /* Did we just take a signal? */ |
2509 | if (IN_SIGTRAMP (stop_pc, ecs->stop_func_name) | |
2510 | && !IN_SIGTRAMP (prev_pc, prev_func_name) | |
2511 | && INNER_THAN (read_sp (), step_sp)) | |
2512 | { | |
2513 | /* We've just taken a signal; go until we are back to | |
2514 | the point where we took it and one more. */ | |
c906108c | 2515 | |
c5aa993b JM |
2516 | /* Note: The test above succeeds not only when we stepped |
2517 | into a signal handler, but also when we step past the last | |
2518 | statement of a signal handler and end up in the return stub | |
2519 | of the signal handler trampoline. To distinguish between | |
2520 | these two cases, check that the frame is INNER_THAN the | |
2521 | previous one below. pai/1997-09-11 */ | |
c906108c | 2522 | |
c906108c | 2523 | |
c5aa993b JM |
2524 | { |
2525 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); | |
c906108c | 2526 | |
c5aa993b JM |
2527 | if (INNER_THAN (current_frame, step_frame_address)) |
2528 | { | |
2529 | /* We have just taken a signal; go until we are back to | |
2530 | the point where we took it and one more. */ | |
c906108c | 2531 | |
c5aa993b JM |
2532 | /* This code is needed at least in the following case: |
2533 | The user types "next" and then a signal arrives (before | |
2534 | the "next" is done). */ | |
c906108c | 2535 | |
c5aa993b JM |
2536 | /* Note that if we are stopped at a breakpoint, then we need |
2537 | the step_resume breakpoint to override any breakpoints at | |
2538 | the same location, so that we will still step over the | |
2539 | breakpoint even though the signal happened. */ | |
2540 | struct symtab_and_line sr_sal; | |
c906108c | 2541 | |
c5aa993b JM |
2542 | INIT_SAL (&sr_sal); |
2543 | sr_sal.symtab = NULL; | |
2544 | sr_sal.line = 0; | |
2545 | sr_sal.pc = prev_pc; | |
2546 | /* We could probably be setting the frame to | |
2547 | step_frame_address; I don't think anyone thought to | |
2548 | try it. */ | |
a0b3c4fd | 2549 | check_for_old_step_resume_breakpoint (); |
c5aa993b JM |
2550 | step_resume_breakpoint = |
2551 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2552 | if (breakpoints_inserted) | |
2553 | insert_breakpoints (); | |
c906108c | 2554 | } |
c5aa993b | 2555 | else |
c906108c | 2556 | { |
c5aa993b JM |
2557 | /* We just stepped out of a signal handler and into |
2558 | its calling trampoline. | |
2559 | ||
2560 | Normally, we'd jump to step_over_function from | |
2561 | here, but for some reason GDB can't unwind the | |
2562 | stack correctly to find the real PC for the point | |
2563 | user code where the signal trampoline will return | |
2564 | -- FRAME_SAVED_PC fails, at least on HP-UX 10.20. | |
2565 | But signal trampolines are pretty small stubs of | |
2566 | code, anyway, so it's OK instead to just | |
2567 | single-step out. Note: assuming such trampolines | |
2568 | don't exhibit recursion on any platform... */ | |
2569 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
2570 | &ecs->stop_func_start, | |
2571 | &ecs->stop_func_end); | |
2572 | /* Readjust stepping range */ | |
2573 | step_range_start = ecs->stop_func_start; | |
2574 | step_range_end = ecs->stop_func_end; | |
2575 | ecs->stepping_through_sigtramp = 1; | |
c906108c | 2576 | } |
c906108c SS |
2577 | } |
2578 | ||
c906108c | 2579 | |
c5aa993b JM |
2580 | /* If this is stepi or nexti, make sure that the stepping range |
2581 | gets us past that instruction. */ | |
2582 | if (step_range_end == 1) | |
2583 | /* FIXME: Does this run afoul of the code below which, if | |
2584 | we step into the middle of a line, resets the stepping | |
2585 | range? */ | |
2586 | step_range_end = (step_range_start = prev_pc) + 1; | |
c906108c | 2587 | |
c5aa993b | 2588 | ecs->remove_breakpoints_on_following_step = 1; |
c906108c | 2589 | goto keep_going; |
c5aa993b | 2590 | } |
c906108c | 2591 | |
c5aa993b JM |
2592 | if (stop_pc == ecs->stop_func_start /* Quick test */ |
2593 | || (in_prologue (stop_pc, ecs->stop_func_start) && | |
2594 | !IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) | |
2595 | || IN_SOLIB_CALL_TRAMPOLINE (stop_pc, ecs->stop_func_name) | |
2596 | || ecs->stop_func_name == 0) | |
2597 | { | |
2598 | /* It's a subroutine call. */ | |
c906108c | 2599 | |
c5aa993b | 2600 | if (step_over_calls == 0) |
c906108c | 2601 | { |
c5aa993b JM |
2602 | /* I presume that step_over_calls is only 0 when we're |
2603 | supposed to be stepping at the assembly language level | |
2604 | ("stepi"). Just stop. */ | |
2605 | stop_step = 1; | |
2606 | goto wfi_break; | |
2607 | } | |
c906108c | 2608 | |
c5aa993b JM |
2609 | if (step_over_calls > 0 || IGNORE_HELPER_CALL (stop_pc)) |
2610 | /* We're doing a "next". */ | |
2611 | goto step_over_function; | |
2612 | ||
2613 | /* If we are in a function call trampoline (a stub between | |
2614 | the calling routine and the real function), locate the real | |
2615 | function. That's what tells us (a) whether we want to step | |
2616 | into it at all, and (b) what prologue we want to run to | |
2617 | the end of, if we do step into it. */ | |
2618 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); | |
2619 | if (tmp != 0) | |
2620 | ecs->stop_func_start = tmp; | |
2621 | else | |
2622 | { | |
2623 | tmp = DYNAMIC_TRAMPOLINE_NEXTPC (stop_pc); | |
2624 | if (tmp) | |
c906108c | 2625 | { |
c5aa993b JM |
2626 | struct symtab_and_line xxx; |
2627 | /* Why isn't this s_a_l called "sr_sal", like all of the | |
2628 | other s_a_l's where this code is duplicated? */ | |
2629 | INIT_SAL (&xxx); /* initialize to zeroes */ | |
2630 | xxx.pc = tmp; | |
2631 | xxx.section = find_pc_overlay (xxx.pc); | |
a0b3c4fd | 2632 | check_for_old_step_resume_breakpoint (); |
c906108c | 2633 | step_resume_breakpoint = |
c5aa993b JM |
2634 | set_momentary_breakpoint (xxx, NULL, bp_step_resume); |
2635 | insert_breakpoints (); | |
2636 | goto keep_going; | |
c906108c SS |
2637 | } |
2638 | } | |
2639 | ||
c5aa993b JM |
2640 | /* If we have line number information for the function we |
2641 | are thinking of stepping into, step into it. | |
c906108c | 2642 | |
c5aa993b JM |
2643 | If there are several symtabs at that PC (e.g. with include |
2644 | files), just want to know whether *any* of them have line | |
2645 | numbers. find_pc_line handles this. */ | |
2646 | { | |
2647 | struct symtab_and_line tmp_sal; | |
c906108c | 2648 | |
c5aa993b JM |
2649 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
2650 | if (tmp_sal.line != 0) | |
2651 | goto step_into_function; | |
c906108c SS |
2652 | } |
2653 | ||
c5aa993b JM |
2654 | step_over_function: |
2655 | /* A subroutine call has happened. */ | |
c906108c | 2656 | { |
a0b3c4fd JM |
2657 | /* We've just entered a callee, and we wish to resume until it |
2658 | returns to the caller. Setting a step_resume breakpoint on | |
2659 | the return address will catch a return from the callee. | |
2660 | ||
2661 | However, if the callee is recursing, we want to be careful | |
2662 | not to catch returns of those recursive calls, but only of | |
2663 | THIS instance of the call. | |
c906108c | 2664 | |
a0b3c4fd JM |
2665 | To do this, we set the step_resume bp's frame to our current |
2666 | caller's frame (step_frame_address, which is set by the "next" | |
2667 | or "until" command, before execution begins). */ | |
2668 | struct symtab_and_line sr_sal; | |
c5aa993b | 2669 | |
a0b3c4fd JM |
2670 | INIT_SAL (&sr_sal); /* initialize to zeros */ |
2671 | sr_sal.pc = | |
2672 | ADDR_BITS_REMOVE (SAVED_PC_AFTER_CALL (get_current_frame ())); | |
2673 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
c5aa993b | 2674 | |
a0b3c4fd | 2675 | check_for_old_step_resume_breakpoint (); |
c5aa993b | 2676 | step_resume_breakpoint = |
a0b3c4fd | 2677 | set_momentary_breakpoint (sr_sal, get_current_frame (), |
c5aa993b JM |
2678 | bp_step_resume); |
2679 | ||
a0b3c4fd | 2680 | if (!IN_SOLIB_DYNSYM_RESOLVE_CODE (sr_sal.pc)) |
c5aa993b | 2681 | step_resume_breakpoint->frame = step_frame_address; |
c906108c | 2682 | |
c5aa993b JM |
2683 | if (breakpoints_inserted) |
2684 | insert_breakpoints (); | |
2685 | } | |
2686 | goto keep_going; | |
c906108c | 2687 | |
c5aa993b JM |
2688 | step_into_function: |
2689 | /* Subroutine call with source code we should not step over. | |
2690 | Do step to the first line of code in it. */ | |
2691 | { | |
2692 | struct symtab *s; | |
c906108c | 2693 | |
c5aa993b JM |
2694 | s = find_pc_symtab (stop_pc); |
2695 | if (s && s->language != language_asm) | |
2696 | ecs->stop_func_start = SKIP_PROLOGUE (ecs->stop_func_start); | |
2697 | } | |
2698 | ecs->sal = find_pc_line (ecs->stop_func_start, 0); | |
2699 | /* Use the step_resume_break to step until | |
2700 | the end of the prologue, even if that involves jumps | |
2701 | (as it seems to on the vax under 4.2). */ | |
2702 | /* If the prologue ends in the middle of a source line, | |
2703 | continue to the end of that source line (if it is still | |
2704 | within the function). Otherwise, just go to end of prologue. */ | |
2705 | #ifdef PROLOGUE_FIRSTLINE_OVERLAP | |
2706 | /* no, don't either. It skips any code that's | |
2707 | legitimately on the first line. */ | |
2708 | #else | |
2709 | if (ecs->sal.end && ecs->sal.pc != ecs->stop_func_start && ecs->sal.end < ecs->stop_func_end) | |
2710 | ecs->stop_func_start = ecs->sal.end; | |
2711 | #endif | |
c906108c | 2712 | |
c5aa993b JM |
2713 | if (ecs->stop_func_start == stop_pc) |
2714 | { | |
2715 | /* We are already there: stop now. */ | |
2716 | stop_step = 1; | |
2717 | goto wfi_break; | |
c906108c | 2718 | } |
c5aa993b JM |
2719 | else |
2720 | /* Put the step-breakpoint there and go until there. */ | |
c906108c | 2721 | { |
c906108c SS |
2722 | struct symtab_and_line sr_sal; |
2723 | ||
c5aa993b JM |
2724 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
2725 | sr_sal.pc = ecs->stop_func_start; | |
2726 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
2727 | /* Do not specify what the fp should be when we stop | |
2728 | since on some machines the prologue | |
2729 | is where the new fp value is established. */ | |
a0b3c4fd | 2730 | check_for_old_step_resume_breakpoint (); |
c906108c | 2731 | step_resume_breakpoint = |
c5aa993b | 2732 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); |
c906108c SS |
2733 | if (breakpoints_inserted) |
2734 | insert_breakpoints (); | |
c906108c | 2735 | |
c5aa993b JM |
2736 | /* And make sure stepping stops right away then. */ |
2737 | step_range_end = step_range_start; | |
c906108c | 2738 | } |
c5aa993b JM |
2739 | goto keep_going; |
2740 | } | |
c906108c | 2741 | |
c5aa993b | 2742 | /* We've wandered out of the step range. */ |
c906108c | 2743 | |
c5aa993b | 2744 | ecs->sal = find_pc_line (stop_pc, 0); |
c906108c | 2745 | |
c5aa993b JM |
2746 | if (step_range_end == 1) |
2747 | { | |
2748 | /* It is stepi or nexti. We always want to stop stepping after | |
2749 | one instruction. */ | |
2750 | stop_step = 1; | |
2751 | goto wfi_break; | |
2752 | } | |
c906108c | 2753 | |
c5aa993b JM |
2754 | /* If we're in the return path from a shared library trampoline, |
2755 | we want to proceed through the trampoline when stepping. */ | |
2756 | if (IN_SOLIB_RETURN_TRAMPOLINE (stop_pc, ecs->stop_func_name)) | |
2757 | { | |
2758 | CORE_ADDR tmp; | |
c906108c | 2759 | |
c5aa993b JM |
2760 | /* Determine where this trampoline returns. */ |
2761 | tmp = SKIP_TRAMPOLINE_CODE (stop_pc); | |
c906108c | 2762 | |
c5aa993b JM |
2763 | /* Only proceed through if we know where it's going. */ |
2764 | if (tmp) | |
2765 | { | |
2766 | /* And put the step-breakpoint there and go until there. */ | |
2767 | struct symtab_and_line sr_sal; | |
c906108c | 2768 | |
c5aa993b JM |
2769 | INIT_SAL (&sr_sal); /* initialize to zeroes */ |
2770 | sr_sal.pc = tmp; | |
2771 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
2772 | /* Do not specify what the fp should be when we stop | |
2773 | since on some machines the prologue | |
2774 | is where the new fp value is established. */ | |
a0b3c4fd | 2775 | check_for_old_step_resume_breakpoint (); |
c5aa993b JM |
2776 | step_resume_breakpoint = |
2777 | set_momentary_breakpoint (sr_sal, NULL, bp_step_resume); | |
2778 | if (breakpoints_inserted) | |
2779 | insert_breakpoints (); | |
c906108c | 2780 | |
c5aa993b JM |
2781 | /* Restart without fiddling with the step ranges or |
2782 | other state. */ | |
2783 | goto keep_going; | |
2784 | } | |
2785 | } | |
c906108c | 2786 | |
c5aa993b | 2787 | if (ecs->sal.line == 0) |
c906108c | 2788 | { |
c5aa993b JM |
2789 | /* We have no line number information. That means to stop |
2790 | stepping (does this always happen right after one instruction, | |
2791 | when we do "s" in a function with no line numbers, | |
2792 | or can this happen as a result of a return or longjmp?). */ | |
2793 | stop_step = 1; | |
2794 | goto wfi_break; | |
c906108c SS |
2795 | } |
2796 | ||
c5aa993b JM |
2797 | if ((stop_pc == ecs->sal.pc) |
2798 | && (ecs->current_line != ecs->sal.line || ecs->current_symtab != ecs->sal.symtab)) | |
2799 | { | |
2800 | /* We are at the start of a different line. So stop. Note that | |
2801 | we don't stop if we step into the middle of a different line. | |
2802 | That is said to make things like for (;;) statements work | |
2803 | better. */ | |
2804 | stop_step = 1; | |
2805 | goto wfi_break; | |
2806 | } | |
c906108c | 2807 | |
c5aa993b | 2808 | /* We aren't done stepping. |
c906108c | 2809 | |
c5aa993b JM |
2810 | Optimize by setting the stepping range to the line. |
2811 | (We might not be in the original line, but if we entered a | |
2812 | new line in mid-statement, we continue stepping. This makes | |
2813 | things like for(;;) statements work better.) */ | |
c906108c | 2814 | |
c5aa993b JM |
2815 | if (ecs->stop_func_end && ecs->sal.end >= ecs->stop_func_end) |
2816 | { | |
2817 | /* If this is the last line of the function, don't keep stepping | |
2818 | (it would probably step us out of the function). | |
2819 | This is particularly necessary for a one-line function, | |
2820 | in which after skipping the prologue we better stop even though | |
2821 | we will be in mid-line. */ | |
2822 | stop_step = 1; | |
2823 | goto wfi_break; | |
2824 | } | |
2825 | step_range_start = ecs->sal.pc; | |
2826 | step_range_end = ecs->sal.end; | |
2827 | step_frame_address = FRAME_FP (get_current_frame ()); | |
2828 | ecs->current_line = ecs->sal.line; | |
2829 | ecs->current_symtab = ecs->sal.symtab; | |
2830 | ||
2831 | /* In the case where we just stepped out of a function into the middle | |
2832 | of a line of the caller, continue stepping, but step_frame_address | |
2833 | must be modified to current frame */ | |
2834 | { | |
2835 | CORE_ADDR current_frame = FRAME_FP (get_current_frame ()); | |
2836 | if (!(INNER_THAN (current_frame, step_frame_address))) | |
2837 | step_frame_address = current_frame; | |
2838 | } | |
c906108c | 2839 | |
c906108c | 2840 | |
c5aa993b | 2841 | goto keep_going; |
c906108c | 2842 | |
c5aa993b JM |
2843 | check_sigtramp2: |
2844 | if (trap_expected | |
2845 | && IN_SIGTRAMP (stop_pc, ecs->stop_func_name) | |
2846 | && !IN_SIGTRAMP (prev_pc, prev_func_name) | |
2847 | && INNER_THAN (read_sp (), step_sp)) | |
2848 | { | |
2849 | /* What has happened here is that we have just stepped the inferior | |
2850 | with a signal (because it is a signal which shouldn't make | |
2851 | us stop), thus stepping into sigtramp. | |
2852 | ||
2853 | So we need to set a step_resume_break_address breakpoint | |
2854 | and continue until we hit it, and then step. FIXME: This should | |
2855 | be more enduring than a step_resume breakpoint; we should know | |
2856 | that we will later need to keep going rather than re-hitting | |
2857 | the breakpoint here (see testsuite/gdb.t06/signals.exp where | |
2858 | it says "exceedingly difficult"). */ | |
2859 | struct symtab_and_line sr_sal; | |
2860 | ||
2861 | INIT_SAL (&sr_sal); /* initialize to zeroes */ | |
2862 | sr_sal.pc = prev_pc; | |
2863 | sr_sal.section = find_pc_overlay (sr_sal.pc); | |
2864 | /* We perhaps could set the frame if we kept track of what | |
2865 | the frame corresponding to prev_pc was. But we don't, | |
2866 | so don't. */ | |
2867 | through_sigtramp_breakpoint = | |
2868 | set_momentary_breakpoint (sr_sal, NULL, bp_through_sigtramp); | |
2869 | if (breakpoints_inserted) | |
2870 | insert_breakpoints (); | |
c906108c | 2871 | |
c5aa993b JM |
2872 | ecs->remove_breakpoints_on_following_step = 1; |
2873 | ecs->another_trap = 1; | |
2874 | } | |
c906108c | 2875 | |
c5aa993b JM |
2876 | keep_going: |
2877 | /* Come to this label when you need to resume the inferior. | |
2878 | It's really much cleaner to do a goto than a maze of if-else | |
2879 | conditions. */ | |
2880 | ||
2881 | /* ??rehrauer: ttrace on HP-UX theoretically allows one to debug | |
2882 | a vforked child beetween its creation and subsequent exit or | |
2883 | call to exec(). However, I had big problems in this rather | |
2884 | creaky exec engine, getting that to work. The fundamental | |
2885 | problem is that I'm trying to debug two processes via an | |
2886 | engine that only understands a single process with possibly | |
2887 | multiple threads. | |
2888 | ||
2889 | Hence, this spot is known to have problems when | |
2890 | target_can_follow_vfork_prior_to_exec returns 1. */ | |
2891 | ||
2892 | /* Save the pc before execution, to compare with pc after stop. */ | |
2893 | prev_pc = read_pc (); /* Might have been DECR_AFTER_BREAK */ | |
2894 | prev_func_start = ecs->stop_func_start; /* Ok, since if DECR_PC_AFTER | |
2895 | BREAK is defined, the | |
2896 | original pc would not have | |
2897 | been at the start of a | |
2898 | function. */ | |
2899 | prev_func_name = ecs->stop_func_name; | |
2900 | ||
2901 | if (ecs->update_step_sp) | |
2902 | step_sp = read_sp (); | |
2903 | ecs->update_step_sp = 0; | |
2904 | ||
2905 | /* If we did not do break;, it means we should keep | |
2906 | running the inferior and not return to debugger. */ | |
2907 | ||
2908 | if (trap_expected && stop_signal != TARGET_SIGNAL_TRAP) | |
2909 | { | |
2910 | /* We took a signal (which we are supposed to pass through to | |
2911 | the inferior, else we'd have done a break above) and we | |
2912 | haven't yet gotten our trap. Simply continue. */ | |
2913 | resume (currently_stepping (ecs), stop_signal); | |
2914 | } | |
2915 | else | |
2916 | { | |
2917 | /* Either the trap was not expected, but we are continuing | |
2918 | anyway (the user asked that this signal be passed to the | |
2919 | child) | |
2920 | -- or -- | |
2921 | The signal was SIGTRAP, e.g. it was our signal, but we | |
2922 | decided we should resume from it. | |
2923 | ||
2924 | We're going to run this baby now! | |
2925 | ||
2926 | Insert breakpoints now, unless we are trying | |
2927 | to one-proceed past a breakpoint. */ | |
2928 | /* If we've just finished a special step resume and we don't | |
2929 | want to hit a breakpoint, pull em out. */ | |
2930 | if (step_resume_breakpoint == NULL | |
2931 | && through_sigtramp_breakpoint == NULL | |
2932 | && ecs->remove_breakpoints_on_following_step) | |
2933 | { | |
2934 | ecs->remove_breakpoints_on_following_step = 0; | |
2935 | remove_breakpoints (); | |
2936 | breakpoints_inserted = 0; | |
2937 | } | |
2938 | else if (!breakpoints_inserted && | |
2939 | (through_sigtramp_breakpoint != NULL || !ecs->another_trap)) | |
2940 | { | |
2941 | breakpoints_failed = insert_breakpoints (); | |
2942 | if (breakpoints_failed) | |
2943 | goto wfi_break; | |
2944 | breakpoints_inserted = 1; | |
2945 | } | |
c906108c | 2946 | |
c5aa993b | 2947 | trap_expected = ecs->another_trap; |
c906108c | 2948 | |
c5aa993b JM |
2949 | /* Do not deliver SIGNAL_TRAP (except when the user |
2950 | explicitly specifies that such a signal should be | |
2951 | delivered to the target program). | |
c906108c | 2952 | |
c5aa993b JM |
2953 | Typically, this would occure when a user is debugging a |
2954 | target monitor on a simulator: the target monitor sets a | |
2955 | breakpoint; the simulator encounters this break-point and | |
2956 | halts the simulation handing control to GDB; GDB, noteing | |
2957 | that the break-point isn't valid, returns control back to | |
2958 | the simulator; the simulator then delivers the hardware | |
2959 | equivalent of a SIGNAL_TRAP to the program being | |
2960 | debugged. */ | |
c906108c | 2961 | |
c5aa993b JM |
2962 | if (stop_signal == TARGET_SIGNAL_TRAP |
2963 | && !signal_program[stop_signal]) | |
2964 | stop_signal = TARGET_SIGNAL_0; | |
c906108c SS |
2965 | |
2966 | #ifdef SHIFT_INST_REGS | |
c5aa993b JM |
2967 | /* I'm not sure when this following segment applies. I do know, |
2968 | now, that we shouldn't rewrite the regs when we were stopped | |
2969 | by a random signal from the inferior process. */ | |
2970 | /* FIXME: Shouldn't this be based on the valid bit of the SXIP? | |
2971 | (this is only used on the 88k). */ | |
2972 | ||
2973 | if (!bpstat_explains_signal (stop_bpstat) | |
2974 | && (stop_signal != TARGET_SIGNAL_CHLD) | |
2975 | && !stopped_by_random_signal) | |
2976 | SHIFT_INST_REGS (); | |
c906108c SS |
2977 | #endif /* SHIFT_INST_REGS */ |
2978 | ||
c5aa993b JM |
2979 | resume (currently_stepping (ecs), stop_signal); |
2980 | } | |
cd0fc7c3 | 2981 | |
c5aa993b JM |
2982 | /* Former continues in the main loop goto here. */ |
2983 | wfi_continue: | |
2984 | /* This used to be at the top of the loop. */ | |
2985 | if (ecs->infwait_state == infwait_normal_state) | |
2986 | { | |
2987 | overlay_cache_invalid = 1; | |
cd0fc7c3 | 2988 | |
c5aa993b JM |
2989 | /* We have to invalidate the registers BEFORE calling |
2990 | target_wait because they can be loaded from the target | |
2991 | while in target_wait. This makes remote debugging a bit | |
2992 | more efficient for those targets that provide critical | |
2993 | registers as part of their normal status mechanism. */ | |
cd0fc7c3 | 2994 | |
c5aa993b JM |
2995 | registers_changed (); |
2996 | ecs->waiton_pid = -1; | |
2997 | ecs->wp = &(ecs->ws); | |
2998 | } | |
2999 | /* This is the old end of the while loop. Let everybody know | |
3000 | we want to wait for the inferior some more and get called | |
3001 | again soon. */ | |
3002 | ecs->wait_some_more = 1; | |
3003 | return; | |
3004 | } | |
c906108c | 3005 | |
cd0fc7c3 SS |
3006 | /* Former breaks in the main loop goto here. */ |
3007 | wfi_break: | |
3008 | ||
c906108c SS |
3009 | stop_stepping: |
3010 | if (target_has_execution) | |
3011 | { | |
3012 | /* Are we stopping for a vfork event? We only stop when we see | |
3013 | the child's event. However, we may not yet have seen the | |
3014 | parent's event. And, inferior_pid is still set to the parent's | |
3015 | pid, until we resume again and follow either the parent or child. | |
3016 | ||
3017 | To ensure that we can really touch inferior_pid (aka, the | |
3018 | parent process) -- which calls to functions like read_pc | |
3019 | implicitly do -- wait on the parent if necessary. */ | |
3020 | if ((pending_follow.kind == TARGET_WAITKIND_VFORKED) | |
3021 | && !pending_follow.fork_event.saw_parent_fork) | |
3022 | { | |
3023 | int parent_pid; | |
3024 | ||
3025 | do | |
3026 | { | |
3027 | if (target_wait_hook) | |
cd0fc7c3 | 3028 | parent_pid = target_wait_hook (-1, &(ecs->ws)); |
c906108c | 3029 | else |
cd0fc7c3 | 3030 | parent_pid = target_wait (-1, &(ecs->ws)); |
c906108c SS |
3031 | } |
3032 | while (parent_pid != inferior_pid); | |
3033 | } | |
3034 | ||
c906108c | 3035 | /* Assuming the inferior still exists, set these up for next |
c5aa993b JM |
3036 | time, just like we did above if we didn't break out of the |
3037 | loop. */ | |
c906108c | 3038 | prev_pc = read_pc (); |
cd0fc7c3 SS |
3039 | prev_func_start = ecs->stop_func_start; |
3040 | prev_func_name = ecs->stop_func_name; | |
c906108c | 3041 | } |
cd0fc7c3 SS |
3042 | /* Let callers know we don't want to wait for the inferior anymore. */ |
3043 | ecs->wait_some_more = 0; | |
3044 | } | |
3045 | ||
3046 | /* Are we in the middle of stepping? */ | |
3047 | ||
392a587b | 3048 | static int |
cd0fc7c3 SS |
3049 | currently_stepping (ecs) |
3050 | struct execution_control_state *ecs; | |
3051 | { | |
3052 | return ((through_sigtramp_breakpoint == NULL | |
3053 | && !ecs->handling_longjmp | |
3054 | && ((step_range_end && step_resume_breakpoint == NULL) | |
3055 | || trap_expected)) | |
3056 | || ecs->stepping_through_solib_after_catch | |
3057 | || bpstat_should_step ()); | |
c906108c SS |
3058 | } |
3059 | ||
3060 | /* This function returns TRUE if ep is an internal breakpoint | |
3061 | set to catch generic shared library (aka dynamically-linked | |
3062 | library) events. (This is *NOT* the same as a catchpoint for a | |
3063 | shlib event. The latter is something a user can set; this is | |
3064 | something gdb sets for its own use, and isn't ever shown to a | |
3065 | user.) */ | |
3066 | static int | |
3067 | is_internal_shlib_eventpoint (ep) | |
3068 | struct breakpoint *ep; | |
3069 | { | |
3070 | return | |
3071 | (ep->type == bp_shlib_event) | |
3072 | ; | |
3073 | } | |
3074 | ||
3075 | /* This function returns TRUE if bs indicates that the inferior | |
3076 | stopped due to a shared library (aka dynamically-linked library) | |
3077 | event. */ | |
3078 | static int | |
3079 | stopped_for_internal_shlib_event (bs) | |
3080 | bpstat bs; | |
3081 | { | |
3082 | /* Note that multiple eventpoints may've caused the stop. Any | |
3083 | that are associated with shlib events will be accepted. */ | |
3084 | for (; bs != NULL; bs = bs->next) | |
3085 | { | |
3086 | if ((bs->breakpoint_at != NULL) | |
3087 | && is_internal_shlib_eventpoint (bs->breakpoint_at)) | |
3088 | return 1; | |
3089 | } | |
3090 | ||
3091 | /* If we get here, then no candidate was found. */ | |
3092 | return 0; | |
3093 | } | |
3094 | ||
3095 | /* This function returns TRUE if bs indicates that the inferior | |
3096 | stopped due to a shared library (aka dynamically-linked library) | |
3097 | event caught by a catchpoint. | |
3098 | ||
3099 | If TRUE, cp_p is set to point to the catchpoint. | |
3100 | ||
3101 | Else, the value of cp_p is undefined. */ | |
3102 | static int | |
3103 | stopped_for_shlib_catchpoint (bs, cp_p) | |
3104 | bpstat bs; | |
3105 | struct breakpoint **cp_p; | |
3106 | { | |
3107 | /* Note that multiple eventpoints may've caused the stop. Any | |
3108 | that are associated with shlib events will be accepted. */ | |
3109 | *cp_p = NULL; | |
3110 | ||
3111 | for (; bs != NULL; bs = bs->next) | |
3112 | { | |
3113 | if ((bs->breakpoint_at != NULL) | |
3114 | && ep_is_shlib_catchpoint (bs->breakpoint_at)) | |
3115 | { | |
3116 | *cp_p = bs->breakpoint_at; | |
3117 | return 1; | |
3118 | } | |
3119 | } | |
3120 | ||
3121 | /* If we get here, then no candidate was found. */ | |
3122 | return 0; | |
3123 | } | |
3124 | \f | |
3125 | ||
43ff13b4 JM |
3126 | /* Reset proper settings after an asynchronous command has finished. |
3127 | If the execution command was in synchronous mode, register stdin | |
3128 | with the event loop, and reset the prompt. */ | |
3129 | static void | |
3130 | complete_execution () | |
3131 | { | |
c5aa993b | 3132 | extern cleanup_sigint_signal_handler PARAMS ((void)); |
43ff13b4 | 3133 | |
adf40b2e | 3134 | target_executing = 0; |
43ff13b4 JM |
3135 | if (sync_execution) |
3136 | { | |
3137 | add_file_handler (input_fd, (file_handler_func *) call_readline, 0); | |
3138 | pop_prompt (); | |
3139 | sync_execution = 0; | |
3140 | cleanup_sigint_signal_handler (); | |
3141 | display_gdb_prompt (0); | |
3142 | } | |
43ff13b4 JM |
3143 | } |
3144 | ||
c906108c SS |
3145 | /* Here to return control to GDB when the inferior stops for real. |
3146 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
3147 | ||
3148 | STOP_PRINT_FRAME nonzero means print the executing frame | |
3149 | (pc, function, args, file, line number and line text). | |
3150 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
3151 | attempting to insert breakpoints. */ | |
3152 | ||
3153 | void | |
3154 | normal_stop () | |
3155 | { | |
c906108c SS |
3156 | /* As with the notification of thread events, we want to delay |
3157 | notifying the user that we've switched thread context until | |
3158 | the inferior actually stops. | |
3159 | ||
3160 | (Note that there's no point in saying anything if the inferior | |
3161 | has exited!) */ | |
7a292a7a SS |
3162 | if (may_switch_from_inferior_pid |
3163 | && (switched_from_inferior_pid != inferior_pid) | |
3164 | && target_has_execution) | |
c906108c SS |
3165 | { |
3166 | target_terminal_ours_for_output (); | |
3167 | printf_filtered ("[Switched to %s]\n", | |
3168 | target_pid_or_tid_to_str (inferior_pid)); | |
3169 | switched_from_inferior_pid = inferior_pid; | |
3170 | } | |
c906108c SS |
3171 | |
3172 | /* Make sure that the current_frame's pc is correct. This | |
3173 | is a correction for setting up the frame info before doing | |
3174 | DECR_PC_AFTER_BREAK */ | |
3175 | if (target_has_execution && get_current_frame ()) | |
3176 | (get_current_frame ())->pc = read_pc (); | |
3177 | ||
3178 | if (breakpoints_failed) | |
3179 | { | |
3180 | target_terminal_ours_for_output (); | |
3181 | print_sys_errmsg ("ptrace", breakpoints_failed); | |
3182 | printf_filtered ("Stopped; cannot insert breakpoints.\n\ | |
3183 | The same program may be running in another process.\n"); | |
3184 | } | |
3185 | ||
3186 | if (target_has_execution && breakpoints_inserted) | |
3187 | { | |
3188 | if (remove_breakpoints ()) | |
3189 | { | |
3190 | target_terminal_ours_for_output (); | |
3191 | printf_filtered ("Cannot remove breakpoints because "); | |
3192 | printf_filtered ("program is no longer writable.\n"); | |
3193 | printf_filtered ("It might be running in another process.\n"); | |
3194 | printf_filtered ("Further execution is probably impossible.\n"); | |
3195 | } | |
3196 | } | |
3197 | breakpoints_inserted = 0; | |
3198 | ||
3199 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
3200 | Delete any breakpoint that is to be deleted at the next stop. */ | |
3201 | ||
3202 | breakpoint_auto_delete (stop_bpstat); | |
3203 | ||
3204 | /* If an auto-display called a function and that got a signal, | |
3205 | delete that auto-display to avoid an infinite recursion. */ | |
3206 | ||
3207 | if (stopped_by_random_signal) | |
3208 | disable_current_display (); | |
3209 | ||
3210 | /* Don't print a message if in the middle of doing a "step n" | |
3211 | operation for n > 1 */ | |
3212 | if (step_multi && stop_step) | |
3213 | goto done; | |
3214 | ||
3215 | target_terminal_ours (); | |
3216 | ||
3217 | /* Did we stop because the user set the stop_on_solib_events | |
3218 | variable? (If so, we report this as a generic, "Stopped due | |
3219 | to shlib event" message.) */ | |
3220 | if (stopped_for_internal_shlib_event (stop_bpstat)) | |
3221 | { | |
3222 | printf_filtered ("Stopped due to shared library event\n"); | |
3223 | } | |
3224 | ||
3225 | /* Look up the hook_stop and run it if it exists. */ | |
3226 | ||
3227 | if (stop_command && stop_command->hook) | |
3228 | { | |
3229 | catch_errors (hook_stop_stub, stop_command->hook, | |
3230 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
3231 | } | |
3232 | ||
3233 | if (!target_has_stack) | |
3234 | { | |
3235 | ||
3236 | goto done; | |
3237 | } | |
3238 | ||
3239 | /* Select innermost stack frame - i.e., current frame is frame 0, | |
3240 | and current location is based on that. | |
3241 | Don't do this on return from a stack dummy routine, | |
3242 | or if the program has exited. */ | |
3243 | ||
3244 | if (!stop_stack_dummy) | |
3245 | { | |
3246 | select_frame (get_current_frame (), 0); | |
3247 | ||
3248 | /* Print current location without a level number, if | |
c5aa993b JM |
3249 | we have changed functions or hit a breakpoint. |
3250 | Print source line if we have one. | |
3251 | bpstat_print() contains the logic deciding in detail | |
3252 | what to print, based on the event(s) that just occurred. */ | |
c906108c SS |
3253 | |
3254 | if (stop_print_frame) | |
3255 | { | |
3256 | int bpstat_ret; | |
3257 | int source_flag; | |
3258 | ||
3259 | bpstat_ret = bpstat_print (stop_bpstat); | |
3260 | /* bpstat_print() returned one of: | |
c5aa993b JM |
3261 | -1: Didn't print anything |
3262 | 0: Printed preliminary "Breakpoint n, " message, desires | |
3263 | location tacked on | |
3264 | 1: Printed something, don't tack on location */ | |
c906108c SS |
3265 | |
3266 | if (bpstat_ret == -1) | |
3267 | if (stop_step | |
3268 | && step_frame_address == FRAME_FP (get_current_frame ()) | |
3269 | && step_start_function == find_pc_function (stop_pc)) | |
3270 | source_flag = -1; /* finished step, just print source line */ | |
3271 | else | |
3272 | source_flag = 1; /* print location and source line */ | |
3273 | else if (bpstat_ret == 0) /* hit bpt, desire location */ | |
3274 | source_flag = 1; /* print location and source line */ | |
3275 | else /* bpstat_ret == 1, hit bpt, do not desire location */ | |
3276 | source_flag = -1; /* just print source line */ | |
3277 | ||
3278 | /* The behavior of this routine with respect to the source | |
3279 | flag is: | |
3280 | -1: Print only source line | |
3281 | 0: Print only location | |
3282 | 1: Print location and source line */ | |
3283 | show_and_print_stack_frame (selected_frame, -1, source_flag); | |
3284 | ||
3285 | /* Display the auto-display expressions. */ | |
3286 | do_displays (); | |
3287 | } | |
3288 | } | |
3289 | ||
3290 | /* Save the function value return registers, if we care. | |
3291 | We might be about to restore their previous contents. */ | |
3292 | if (proceed_to_finish) | |
3293 | read_register_bytes (0, stop_registers, REGISTER_BYTES); | |
3294 | ||
3295 | if (stop_stack_dummy) | |
3296 | { | |
3297 | /* Pop the empty frame that contains the stack dummy. | |
3298 | POP_FRAME ends with a setting of the current frame, so we | |
c5aa993b | 3299 | can use that next. */ |
c906108c SS |
3300 | POP_FRAME; |
3301 | /* Set stop_pc to what it was before we called the function. | |
c5aa993b JM |
3302 | Can't rely on restore_inferior_status because that only gets |
3303 | called if we don't stop in the called function. */ | |
c906108c SS |
3304 | stop_pc = read_pc (); |
3305 | select_frame (get_current_frame (), 0); | |
3306 | } | |
3307 | ||
3308 | ||
3309 | TUIDO (((TuiOpaqueFuncPtr) tui_vCheckDataValues, selected_frame)); | |
3310 | ||
3311 | done: | |
3312 | annotate_stopped (); | |
3313 | } | |
3314 | ||
3315 | static int | |
3316 | hook_stop_stub (cmd) | |
3317 | PTR cmd; | |
3318 | { | |
3319 | execute_user_command ((struct cmd_list_element *) cmd, 0); | |
3320 | return (0); | |
3321 | } | |
3322 | \f | |
c5aa993b | 3323 | int |
c906108c SS |
3324 | signal_stop_state (signo) |
3325 | int signo; | |
3326 | { | |
3327 | return signal_stop[signo]; | |
3328 | } | |
3329 | ||
c5aa993b | 3330 | int |
c906108c SS |
3331 | signal_print_state (signo) |
3332 | int signo; | |
3333 | { | |
3334 | return signal_print[signo]; | |
3335 | } | |
3336 | ||
c5aa993b | 3337 | int |
c906108c SS |
3338 | signal_pass_state (signo) |
3339 | int signo; | |
3340 | { | |
3341 | return signal_program[signo]; | |
3342 | } | |
3343 | ||
3344 | static void | |
3345 | sig_print_header () | |
3346 | { | |
3347 | printf_filtered ("\ | |
3348 | Signal Stop\tPrint\tPass to program\tDescription\n"); | |
3349 | } | |
3350 | ||
3351 | static void | |
3352 | sig_print_info (oursig) | |
3353 | enum target_signal oursig; | |
3354 | { | |
3355 | char *name = target_signal_to_name (oursig); | |
3356 | int name_padding = 13 - strlen (name); | |
3357 | if (name_padding <= 0) | |
3358 | name_padding = 0; | |
3359 | ||
3360 | printf_filtered ("%s", name); | |
3361 | printf_filtered ("%*.*s ", name_padding, name_padding, | |
3362 | " "); | |
3363 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); | |
3364 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
3365 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
3366 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
3367 | } | |
3368 | ||
3369 | /* Specify how various signals in the inferior should be handled. */ | |
3370 | ||
3371 | static void | |
3372 | handle_command (args, from_tty) | |
3373 | char *args; | |
3374 | int from_tty; | |
3375 | { | |
3376 | char **argv; | |
3377 | int digits, wordlen; | |
3378 | int sigfirst, signum, siglast; | |
3379 | enum target_signal oursig; | |
3380 | int allsigs; | |
3381 | int nsigs; | |
3382 | unsigned char *sigs; | |
3383 | struct cleanup *old_chain; | |
3384 | ||
3385 | if (args == NULL) | |
3386 | { | |
3387 | error_no_arg ("signal to handle"); | |
3388 | } | |
3389 | ||
3390 | /* Allocate and zero an array of flags for which signals to handle. */ | |
3391 | ||
3392 | nsigs = (int) TARGET_SIGNAL_LAST; | |
3393 | sigs = (unsigned char *) alloca (nsigs); | |
3394 | memset (sigs, 0, nsigs); | |
3395 | ||
3396 | /* Break the command line up into args. */ | |
3397 | ||
3398 | argv = buildargv (args); | |
3399 | if (argv == NULL) | |
3400 | { | |
3401 | nomem (0); | |
3402 | } | |
7a292a7a | 3403 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3404 | |
3405 | /* Walk through the args, looking for signal oursigs, signal names, and | |
3406 | actions. Signal numbers and signal names may be interspersed with | |
3407 | actions, with the actions being performed for all signals cumulatively | |
3408 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ | |
3409 | ||
3410 | while (*argv != NULL) | |
3411 | { | |
3412 | wordlen = strlen (*argv); | |
3413 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
3414 | {; | |
3415 | } | |
3416 | allsigs = 0; | |
3417 | sigfirst = siglast = -1; | |
3418 | ||
3419 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
3420 | { | |
3421 | /* Apply action to all signals except those used by the | |
3422 | debugger. Silently skip those. */ | |
3423 | allsigs = 1; | |
3424 | sigfirst = 0; | |
3425 | siglast = nsigs - 1; | |
3426 | } | |
3427 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
3428 | { | |
3429 | SET_SIGS (nsigs, sigs, signal_stop); | |
3430 | SET_SIGS (nsigs, sigs, signal_print); | |
3431 | } | |
3432 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
3433 | { | |
3434 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3435 | } | |
3436 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
3437 | { | |
3438 | SET_SIGS (nsigs, sigs, signal_print); | |
3439 | } | |
3440 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
3441 | { | |
3442 | SET_SIGS (nsigs, sigs, signal_program); | |
3443 | } | |
3444 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
3445 | { | |
3446 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3447 | } | |
3448 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
3449 | { | |
3450 | SET_SIGS (nsigs, sigs, signal_program); | |
3451 | } | |
3452 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
3453 | { | |
3454 | UNSET_SIGS (nsigs, sigs, signal_print); | |
3455 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
3456 | } | |
3457 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
3458 | { | |
3459 | UNSET_SIGS (nsigs, sigs, signal_program); | |
3460 | } | |
3461 | else if (digits > 0) | |
3462 | { | |
3463 | /* It is numeric. The numeric signal refers to our own | |
3464 | internal signal numbering from target.h, not to host/target | |
3465 | signal number. This is a feature; users really should be | |
3466 | using symbolic names anyway, and the common ones like | |
3467 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
3468 | ||
3469 | sigfirst = siglast = (int) | |
3470 | target_signal_from_command (atoi (*argv)); | |
3471 | if ((*argv)[digits] == '-') | |
3472 | { | |
3473 | siglast = (int) | |
3474 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
3475 | } | |
3476 | if (sigfirst > siglast) | |
3477 | { | |
3478 | /* Bet he didn't figure we'd think of this case... */ | |
3479 | signum = sigfirst; | |
3480 | sigfirst = siglast; | |
3481 | siglast = signum; | |
3482 | } | |
3483 | } | |
3484 | else | |
3485 | { | |
3486 | oursig = target_signal_from_name (*argv); | |
3487 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
3488 | { | |
3489 | sigfirst = siglast = (int) oursig; | |
3490 | } | |
3491 | else | |
3492 | { | |
3493 | /* Not a number and not a recognized flag word => complain. */ | |
3494 | error ("Unrecognized or ambiguous flag word: \"%s\".", *argv); | |
3495 | } | |
3496 | } | |
3497 | ||
3498 | /* If any signal numbers or symbol names were found, set flags for | |
c5aa993b | 3499 | which signals to apply actions to. */ |
c906108c SS |
3500 | |
3501 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
3502 | { | |
3503 | switch ((enum target_signal) signum) | |
3504 | { | |
3505 | case TARGET_SIGNAL_TRAP: | |
3506 | case TARGET_SIGNAL_INT: | |
3507 | if (!allsigs && !sigs[signum]) | |
3508 | { | |
3509 | if (query ("%s is used by the debugger.\n\ | |
3510 | Are you sure you want to change it? ", | |
3511 | target_signal_to_name | |
3512 | ((enum target_signal) signum))) | |
3513 | { | |
3514 | sigs[signum] = 1; | |
3515 | } | |
3516 | else | |
3517 | { | |
3518 | printf_unfiltered ("Not confirmed, unchanged.\n"); | |
3519 | gdb_flush (gdb_stdout); | |
3520 | } | |
3521 | } | |
3522 | break; | |
3523 | case TARGET_SIGNAL_0: | |
3524 | case TARGET_SIGNAL_DEFAULT: | |
3525 | case TARGET_SIGNAL_UNKNOWN: | |
3526 | /* Make sure that "all" doesn't print these. */ | |
3527 | break; | |
3528 | default: | |
3529 | sigs[signum] = 1; | |
3530 | break; | |
3531 | } | |
3532 | } | |
3533 | ||
3534 | argv++; | |
3535 | } | |
3536 | ||
3537 | target_notice_signals (inferior_pid); | |
3538 | ||
3539 | if (from_tty) | |
3540 | { | |
3541 | /* Show the results. */ | |
3542 | sig_print_header (); | |
3543 | for (signum = 0; signum < nsigs; signum++) | |
3544 | { | |
3545 | if (sigs[signum]) | |
3546 | { | |
3547 | sig_print_info (signum); | |
3548 | } | |
3549 | } | |
3550 | } | |
3551 | ||
3552 | do_cleanups (old_chain); | |
3553 | } | |
3554 | ||
3555 | static void | |
3556 | xdb_handle_command (args, from_tty) | |
3557 | char *args; | |
3558 | int from_tty; | |
3559 | { | |
3560 | char **argv; | |
3561 | struct cleanup *old_chain; | |
3562 | ||
3563 | /* Break the command line up into args. */ | |
3564 | ||
3565 | argv = buildargv (args); | |
3566 | if (argv == NULL) | |
3567 | { | |
3568 | nomem (0); | |
3569 | } | |
7a292a7a | 3570 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
3571 | if (argv[1] != (char *) NULL) |
3572 | { | |
3573 | char *argBuf; | |
3574 | int bufLen; | |
3575 | ||
3576 | bufLen = strlen (argv[0]) + 20; | |
3577 | argBuf = (char *) xmalloc (bufLen); | |
3578 | if (argBuf) | |
3579 | { | |
3580 | int validFlag = 1; | |
3581 | enum target_signal oursig; | |
3582 | ||
3583 | oursig = target_signal_from_name (argv[0]); | |
3584 | memset (argBuf, 0, bufLen); | |
3585 | if (strcmp (argv[1], "Q") == 0) | |
3586 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3587 | else | |
3588 | { | |
3589 | if (strcmp (argv[1], "s") == 0) | |
3590 | { | |
3591 | if (!signal_stop[oursig]) | |
3592 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
3593 | else | |
3594 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
3595 | } | |
3596 | else if (strcmp (argv[1], "i") == 0) | |
3597 | { | |
3598 | if (!signal_program[oursig]) | |
3599 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
3600 | else | |
3601 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
3602 | } | |
3603 | else if (strcmp (argv[1], "r") == 0) | |
3604 | { | |
3605 | if (!signal_print[oursig]) | |
3606 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
3607 | else | |
3608 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
3609 | } | |
3610 | else | |
3611 | validFlag = 0; | |
3612 | } | |
3613 | if (validFlag) | |
3614 | handle_command (argBuf, from_tty); | |
3615 | else | |
3616 | printf_filtered ("Invalid signal handling flag.\n"); | |
3617 | if (argBuf) | |
3618 | free (argBuf); | |
3619 | } | |
3620 | } | |
3621 | do_cleanups (old_chain); | |
3622 | } | |
3623 | ||
3624 | /* Print current contents of the tables set by the handle command. | |
3625 | It is possible we should just be printing signals actually used | |
3626 | by the current target (but for things to work right when switching | |
3627 | targets, all signals should be in the signal tables). */ | |
3628 | ||
3629 | static void | |
3630 | signals_info (signum_exp, from_tty) | |
3631 | char *signum_exp; | |
3632 | int from_tty; | |
3633 | { | |
3634 | enum target_signal oursig; | |
3635 | sig_print_header (); | |
3636 | ||
3637 | if (signum_exp) | |
3638 | { | |
3639 | /* First see if this is a symbol name. */ | |
3640 | oursig = target_signal_from_name (signum_exp); | |
3641 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
3642 | { | |
3643 | /* No, try numeric. */ | |
3644 | oursig = | |
3645 | target_signal_from_command (parse_and_eval_address (signum_exp)); | |
3646 | } | |
3647 | sig_print_info (oursig); | |
3648 | return; | |
3649 | } | |
3650 | ||
3651 | printf_filtered ("\n"); | |
3652 | /* These ugly casts brought to you by the native VAX compiler. */ | |
3653 | for (oursig = TARGET_SIGNAL_FIRST; | |
3654 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
3655 | oursig = (enum target_signal) ((int) oursig + 1)) | |
3656 | { | |
3657 | QUIT; | |
3658 | ||
3659 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
3660 | && oursig != TARGET_SIGNAL_DEFAULT | |
3661 | && oursig != TARGET_SIGNAL_0) | |
3662 | sig_print_info (oursig); | |
3663 | } | |
3664 | ||
3665 | printf_filtered ("\nUse the \"handle\" command to change these tables.\n"); | |
3666 | } | |
3667 | \f | |
7a292a7a SS |
3668 | struct inferior_status |
3669 | { | |
3670 | enum target_signal stop_signal; | |
3671 | CORE_ADDR stop_pc; | |
3672 | bpstat stop_bpstat; | |
3673 | int stop_step; | |
3674 | int stop_stack_dummy; | |
3675 | int stopped_by_random_signal; | |
3676 | int trap_expected; | |
3677 | CORE_ADDR step_range_start; | |
3678 | CORE_ADDR step_range_end; | |
3679 | CORE_ADDR step_frame_address; | |
3680 | int step_over_calls; | |
3681 | CORE_ADDR step_resume_break_address; | |
3682 | int stop_after_trap; | |
3683 | int stop_soon_quietly; | |
3684 | CORE_ADDR selected_frame_address; | |
3685 | char *stop_registers; | |
3686 | ||
3687 | /* These are here because if call_function_by_hand has written some | |
3688 | registers and then decides to call error(), we better not have changed | |
3689 | any registers. */ | |
3690 | char *registers; | |
3691 | ||
3692 | int selected_level; | |
3693 | int breakpoint_proceeded; | |
3694 | int restore_stack_info; | |
3695 | int proceed_to_finish; | |
3696 | }; | |
3697 | ||
3698 | ||
3699 | static struct inferior_status *xmalloc_inferior_status PARAMS ((void)); | |
3700 | static struct inferior_status * | |
3701 | xmalloc_inferior_status () | |
3702 | { | |
3703 | struct inferior_status *inf_status; | |
3704 | inf_status = xmalloc (sizeof (struct inferior_status)); | |
3705 | inf_status->stop_registers = xmalloc (REGISTER_BYTES); | |
3706 | inf_status->registers = xmalloc (REGISTER_BYTES); | |
3707 | return inf_status; | |
3708 | } | |
3709 | ||
3710 | static void free_inferior_status PARAMS ((struct inferior_status *)); | |
3711 | static void | |
3712 | free_inferior_status (inf_status) | |
3713 | struct inferior_status *inf_status; | |
3714 | { | |
3715 | free (inf_status->registers); | |
3716 | free (inf_status->stop_registers); | |
3717 | free (inf_status); | |
3718 | } | |
3719 | ||
3720 | void | |
3721 | write_inferior_status_register (inf_status, regno, val) | |
3722 | struct inferior_status *inf_status; | |
3723 | int regno; | |
3724 | LONGEST val; | |
3725 | { | |
c5aa993b | 3726 | int size = REGISTER_RAW_SIZE (regno); |
7a292a7a SS |
3727 | void *buf = alloca (size); |
3728 | store_signed_integer (buf, size, val); | |
3729 | memcpy (&inf_status->registers[REGISTER_BYTE (regno)], buf, size); | |
3730 | } | |
3731 | ||
3732 | ||
3733 | ||
c906108c SS |
3734 | /* Save all of the information associated with the inferior<==>gdb |
3735 | connection. INF_STATUS is a pointer to a "struct inferior_status" | |
3736 | (defined in inferior.h). */ | |
3737 | ||
7a292a7a SS |
3738 | struct inferior_status * |
3739 | save_inferior_status (restore_stack_info) | |
c906108c SS |
3740 | int restore_stack_info; |
3741 | { | |
7a292a7a SS |
3742 | struct inferior_status *inf_status = xmalloc_inferior_status (); |
3743 | ||
c906108c SS |
3744 | inf_status->stop_signal = stop_signal; |
3745 | inf_status->stop_pc = stop_pc; | |
3746 | inf_status->stop_step = stop_step; | |
3747 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
3748 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
3749 | inf_status->trap_expected = trap_expected; | |
3750 | inf_status->step_range_start = step_range_start; | |
3751 | inf_status->step_range_end = step_range_end; | |
3752 | inf_status->step_frame_address = step_frame_address; | |
3753 | inf_status->step_over_calls = step_over_calls; | |
3754 | inf_status->stop_after_trap = stop_after_trap; | |
3755 | inf_status->stop_soon_quietly = stop_soon_quietly; | |
3756 | /* Save original bpstat chain here; replace it with copy of chain. | |
3757 | If caller's caller is walking the chain, they'll be happier if we | |
7a292a7a SS |
3758 | hand them back the original chain when restore_inferior_status is |
3759 | called. */ | |
c906108c SS |
3760 | inf_status->stop_bpstat = stop_bpstat; |
3761 | stop_bpstat = bpstat_copy (stop_bpstat); | |
3762 | inf_status->breakpoint_proceeded = breakpoint_proceeded; | |
3763 | inf_status->restore_stack_info = restore_stack_info; | |
3764 | inf_status->proceed_to_finish = proceed_to_finish; | |
c5aa993b | 3765 | |
c906108c SS |
3766 | memcpy (inf_status->stop_registers, stop_registers, REGISTER_BYTES); |
3767 | ||
3768 | read_register_bytes (0, inf_status->registers, REGISTER_BYTES); | |
3769 | ||
3770 | record_selected_frame (&(inf_status->selected_frame_address), | |
3771 | &(inf_status->selected_level)); | |
7a292a7a | 3772 | return inf_status; |
c906108c SS |
3773 | } |
3774 | ||
3775 | struct restore_selected_frame_args | |
3776 | { | |
3777 | CORE_ADDR frame_address; | |
3778 | int level; | |
3779 | }; | |
3780 | ||
3781 | static int restore_selected_frame PARAMS ((PTR)); | |
3782 | ||
c906108c SS |
3783 | static int |
3784 | restore_selected_frame (args) | |
3785 | PTR args; | |
3786 | { | |
3787 | struct restore_selected_frame_args *fr = | |
3788 | (struct restore_selected_frame_args *) args; | |
3789 | struct frame_info *frame; | |
3790 | int level = fr->level; | |
3791 | ||
3792 | frame = find_relative_frame (get_current_frame (), &level); | |
3793 | ||
3794 | /* If inf_status->selected_frame_address is NULL, there was no | |
3795 | previously selected frame. */ | |
3796 | if (frame == NULL || | |
3797 | /* FRAME_FP (frame) != fr->frame_address || */ | |
3798 | /* elz: deleted this check as a quick fix to the problem that | |
c5aa993b JM |
3799 | for function called by hand gdb creates no internal frame |
3800 | structure and the real stack and gdb's idea of stack are | |
3801 | different if nested calls by hands are made. | |
c906108c | 3802 | |
c5aa993b | 3803 | mvs: this worries me. */ |
c906108c SS |
3804 | level != 0) |
3805 | { | |
3806 | warning ("Unable to restore previously selected frame.\n"); | |
3807 | return 0; | |
3808 | } | |
3809 | ||
3810 | select_frame (frame, fr->level); | |
3811 | ||
3812 | return (1); | |
3813 | } | |
3814 | ||
3815 | void | |
3816 | restore_inferior_status (inf_status) | |
3817 | struct inferior_status *inf_status; | |
3818 | { | |
3819 | stop_signal = inf_status->stop_signal; | |
3820 | stop_pc = inf_status->stop_pc; | |
3821 | stop_step = inf_status->stop_step; | |
3822 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
3823 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
3824 | trap_expected = inf_status->trap_expected; | |
3825 | step_range_start = inf_status->step_range_start; | |
3826 | step_range_end = inf_status->step_range_end; | |
3827 | step_frame_address = inf_status->step_frame_address; | |
3828 | step_over_calls = inf_status->step_over_calls; | |
3829 | stop_after_trap = inf_status->stop_after_trap; | |
3830 | stop_soon_quietly = inf_status->stop_soon_quietly; | |
3831 | bpstat_clear (&stop_bpstat); | |
3832 | stop_bpstat = inf_status->stop_bpstat; | |
3833 | breakpoint_proceeded = inf_status->breakpoint_proceeded; | |
3834 | proceed_to_finish = inf_status->proceed_to_finish; | |
3835 | ||
7a292a7a | 3836 | /* FIXME: Is the restore of stop_registers always needed */ |
c906108c SS |
3837 | memcpy (stop_registers, inf_status->stop_registers, REGISTER_BYTES); |
3838 | ||
3839 | /* The inferior can be gone if the user types "print exit(0)" | |
3840 | (and perhaps other times). */ | |
3841 | if (target_has_execution) | |
3842 | write_register_bytes (0, inf_status->registers, REGISTER_BYTES); | |
3843 | ||
c906108c SS |
3844 | /* FIXME: If we are being called after stopping in a function which |
3845 | is called from gdb, we should not be trying to restore the | |
3846 | selected frame; it just prints a spurious error message (The | |
3847 | message is useful, however, in detecting bugs in gdb (like if gdb | |
3848 | clobbers the stack)). In fact, should we be restoring the | |
3849 | inferior status at all in that case? . */ | |
3850 | ||
3851 | if (target_has_stack && inf_status->restore_stack_info) | |
3852 | { | |
3853 | struct restore_selected_frame_args fr; | |
3854 | fr.level = inf_status->selected_level; | |
3855 | fr.frame_address = inf_status->selected_frame_address; | |
3856 | /* The point of catch_errors is that if the stack is clobbered, | |
c5aa993b JM |
3857 | walking the stack might encounter a garbage pointer and error() |
3858 | trying to dereference it. */ | |
c906108c SS |
3859 | if (catch_errors (restore_selected_frame, &fr, |
3860 | "Unable to restore previously selected frame:\n", | |
3861 | RETURN_MASK_ERROR) == 0) | |
3862 | /* Error in restoring the selected frame. Select the innermost | |
3863 | frame. */ | |
3864 | ||
3865 | ||
3866 | select_frame (get_current_frame (), 0); | |
3867 | ||
3868 | } | |
c906108c | 3869 | |
7a292a7a SS |
3870 | free_inferior_status (inf_status); |
3871 | } | |
c906108c SS |
3872 | |
3873 | void | |
7a292a7a SS |
3874 | discard_inferior_status (inf_status) |
3875 | struct inferior_status *inf_status; | |
3876 | { | |
3877 | /* See save_inferior_status for info on stop_bpstat. */ | |
3878 | bpstat_clear (&inf_status->stop_bpstat); | |
3879 | free_inferior_status (inf_status); | |
3880 | } | |
3881 | ||
3882 | static void | |
c906108c SS |
3883 | set_follow_fork_mode_command (arg, from_tty, c) |
3884 | char *arg; | |
3885 | int from_tty; | |
3886 | struct cmd_list_element *c; | |
3887 | { | |
3888 | if (!STREQ (arg, "parent") && | |
3889 | !STREQ (arg, "child") && | |
3890 | !STREQ (arg, "both") && | |
3891 | !STREQ (arg, "ask")) | |
3892 | error ("follow-fork-mode must be one of \"parent\", \"child\", \"both\" or \"ask\"."); | |
3893 | ||
3894 | if (follow_fork_mode_string != NULL) | |
3895 | free (follow_fork_mode_string); | |
3896 | follow_fork_mode_string = savestring (arg, strlen (arg)); | |
3897 | } | |
c5aa993b | 3898 | \f |
7a292a7a SS |
3899 | |
3900 | ||
7a292a7a SS |
3901 | static void build_infrun PARAMS ((void)); |
3902 | static void | |
3903 | build_infrun () | |
3904 | { | |
3905 | stop_registers = xmalloc (REGISTER_BYTES); | |
3906 | } | |
c906108c SS |
3907 | |
3908 | ||
3909 | void | |
3910 | _initialize_infrun () | |
3911 | { | |
3912 | register int i; | |
3913 | register int numsigs; | |
3914 | struct cmd_list_element *c; | |
3915 | ||
7a292a7a SS |
3916 | build_infrun (); |
3917 | ||
0f71a2f6 JM |
3918 | register_gdbarch_swap (&stop_registers, sizeof (stop_registers), NULL); |
3919 | register_gdbarch_swap (NULL, 0, build_infrun); | |
3920 | ||
c906108c SS |
3921 | add_info ("signals", signals_info, |
3922 | "What debugger does when program gets various signals.\n\ | |
3923 | Specify a signal as argument to print info on that signal only."); | |
3924 | add_info_alias ("handle", "signals", 0); | |
3925 | ||
3926 | add_com ("handle", class_run, handle_command, | |
3927 | concat ("Specify how to handle a signal.\n\ | |
3928 | Args are signals and actions to apply to those signals.\n\ | |
3929 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
3930 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
3931 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
3932 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
3933 | used by the debugger, typically SIGTRAP and SIGINT.\n", | |
3934 | "Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
3935 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ | |
3936 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
3937 | Print means print a message if this signal happens.\n\ | |
3938 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
3939 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
3940 | Pass and Stop may be combined.", NULL)); | |
3941 | if (xdb_commands) | |
3942 | { | |
3943 | add_com ("lz", class_info, signals_info, | |
3944 | "What debugger does when program gets various signals.\n\ | |
3945 | Specify a signal as argument to print info on that signal only."); | |
3946 | add_com ("z", class_run, xdb_handle_command, | |
3947 | concat ("Specify how to handle a signal.\n\ | |
3948 | Args are signals and actions to apply to those signals.\n\ | |
3949 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
3950 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
3951 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
3952 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
3953 | used by the debugger, typically SIGTRAP and SIGINT.\n", | |
3954 | "Recognized actions include \"s\" (toggles between stop and nostop), \n\ | |
3955 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ | |
3956 | nopass), \"Q\" (noprint)\n\ | |
3957 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
3958 | Print means print a message if this signal happens.\n\ | |
3959 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
3960 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
3961 | Pass and Stop may be combined.", NULL)); | |
3962 | } | |
3963 | ||
3964 | if (!dbx_commands) | |
3965 | stop_command = add_cmd ("stop", class_obscure, not_just_help_class_command, | |
3966 | "There is no `stop' command, but you can set a hook on `stop'.\n\ | |
3967 | This allows you to set a list of commands to be run each time execution\n\ | |
3968 | of the program stops.", &cmdlist); | |
3969 | ||
3970 | numsigs = (int) TARGET_SIGNAL_LAST; | |
3971 | signal_stop = (unsigned char *) | |
3972 | xmalloc (sizeof (signal_stop[0]) * numsigs); | |
3973 | signal_print = (unsigned char *) | |
3974 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
3975 | signal_program = (unsigned char *) | |
3976 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
3977 | for (i = 0; i < numsigs; i++) | |
3978 | { | |
3979 | signal_stop[i] = 1; | |
3980 | signal_print[i] = 1; | |
3981 | signal_program[i] = 1; | |
3982 | } | |
3983 | ||
3984 | /* Signals caused by debugger's own actions | |
3985 | should not be given to the program afterwards. */ | |
3986 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
3987 | signal_program[TARGET_SIGNAL_INT] = 0; | |
3988 | ||
3989 | /* Signals that are not errors should not normally enter the debugger. */ | |
3990 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
3991 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
3992 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
3993 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
3994 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
3995 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
3996 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
3997 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
3998 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
3999 | signal_print[TARGET_SIGNAL_IO] = 0; | |
4000 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
4001 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
4002 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
4003 | signal_print[TARGET_SIGNAL_URG] = 0; | |
4004 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
4005 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
4006 | ||
cd0fc7c3 SS |
4007 | /* These signals are used internally by user-level thread |
4008 | implementations. (See signal(5) on Solaris.) Like the above | |
4009 | signals, a healthy program receives and handles them as part of | |
4010 | its normal operation. */ | |
4011 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
4012 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
4013 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
4014 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
4015 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
4016 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
4017 | ||
c906108c SS |
4018 | #ifdef SOLIB_ADD |
4019 | add_show_from_set | |
4020 | (add_set_cmd ("stop-on-solib-events", class_support, var_zinteger, | |
4021 | (char *) &stop_on_solib_events, | |
4022 | "Set stopping for shared library events.\n\ | |
4023 | If nonzero, gdb will give control to the user when the dynamic linker\n\ | |
4024 | notifies gdb of shared library events. The most common event of interest\n\ | |
4025 | to the user would be loading/unloading of a new library.\n", | |
4026 | &setlist), | |
4027 | &showlist); | |
4028 | #endif | |
4029 | ||
4030 | c = add_set_enum_cmd ("follow-fork-mode", | |
4031 | class_run, | |
4032 | follow_fork_mode_kind_names, | |
4033 | (char *) &follow_fork_mode_string, | |
4034 | /* ??rehrauer: The "both" option is broken, by what may be a 10.20 | |
4035 | kernel problem. It's also not terribly useful without a GUI to | |
4036 | help the user drive two debuggers. So for now, I'm disabling | |
4037 | the "both" option. */ | |
c5aa993b JM |
4038 | /* "Set debugger response to a program call of fork \ |
4039 | or vfork.\n\ | |
4040 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
4041 | parent - the original process is debugged after a fork\n\ | |
4042 | child - the new process is debugged after a fork\n\ | |
4043 | both - both the parent and child are debugged after a fork\n\ | |
4044 | ask - the debugger will ask for one of the above choices\n\ | |
4045 | For \"both\", another copy of the debugger will be started to follow\n\ | |
4046 | the new child process. The original debugger will continue to follow\n\ | |
4047 | the original parent process. To distinguish their prompts, the\n\ | |
4048 | debugger copy's prompt will be changed.\n\ | |
4049 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
4050 | By default, the debugger will follow the parent process.", | |
4051 | */ | |
c906108c SS |
4052 | "Set debugger response to a program call of fork \ |
4053 | or vfork.\n\ | |
4054 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ | |
4055 | parent - the original process is debugged after a fork\n\ | |
4056 | child - the new process is debugged after a fork\n\ | |
4057 | ask - the debugger will ask for one of the above choices\n\ | |
4058 | For \"parent\" or \"child\", the unfollowed process will run free.\n\ | |
4059 | By default, the debugger will follow the parent process.", | |
4060 | &setlist); | |
c5aa993b | 4061 | /* c->function.sfunc = ; */ |
c906108c SS |
4062 | add_show_from_set (c, &showlist); |
4063 | ||
4064 | set_follow_fork_mode_command ("parent", 0, NULL); | |
4065 | ||
4066 | c = add_set_enum_cmd ("scheduler-locking", class_run, | |
4067 | scheduler_enums, /* array of string names */ | |
4068 | (char *) &scheduler_mode, /* current mode */ | |
4069 | "Set mode for locking scheduler during execution.\n\ | |
4070 | off == no locking (threads may preempt at any time)\n\ | |
4071 | on == full locking (no thread except the current thread may run)\n\ | |
4072 | step == scheduler locked during every single-step operation.\n\ | |
4073 | In this mode, no other thread may run during a step command.\n\ | |
4074 | Other threads may run while stepping over a function call ('next').", | |
4075 | &setlist); | |
4076 | ||
4077 | c->function.sfunc = set_schedlock_func; /* traps on target vector */ | |
4078 | add_show_from_set (c, &showlist); | |
4079 | } |