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