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