Commit | Line | Data |
---|---|---|
ca557f44 AC |
1 | /* Target-struct-independent code to start (run) and stop an inferior |
2 | process. | |
8926118c | 3 | |
6aba47ca | 4 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 5 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
7b6bb8da | 6 | 2008, 2009, 2010, 2011 Free Software 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 | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 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 | 20 | You should have received a copy of the GNU General Public License |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
22 | |
23 | #include "defs.h" | |
24 | #include "gdb_string.h" | |
25 | #include <ctype.h> | |
26 | #include "symtab.h" | |
27 | #include "frame.h" | |
28 | #include "inferior.h" | |
60250e8b | 29 | #include "exceptions.h" |
c906108c | 30 | #include "breakpoint.h" |
03f2053f | 31 | #include "gdb_wait.h" |
c906108c SS |
32 | #include "gdbcore.h" |
33 | #include "gdbcmd.h" | |
210661e7 | 34 | #include "cli/cli-script.h" |
c906108c SS |
35 | #include "target.h" |
36 | #include "gdbthread.h" | |
37 | #include "annotate.h" | |
1adeb98a | 38 | #include "symfile.h" |
7a292a7a | 39 | #include "top.h" |
c906108c | 40 | #include <signal.h> |
2acceee2 | 41 | #include "inf-loop.h" |
4e052eda | 42 | #include "regcache.h" |
fd0407d6 | 43 | #include "value.h" |
06600e06 | 44 | #include "observer.h" |
f636b87d | 45 | #include "language.h" |
a77053c2 | 46 | #include "solib.h" |
f17517ea | 47 | #include "main.h" |
186c406b TT |
48 | #include "dictionary.h" |
49 | #include "block.h" | |
9f976b41 | 50 | #include "gdb_assert.h" |
034dad6f | 51 | #include "mi/mi-common.h" |
4f8d22e3 | 52 | #include "event-top.h" |
96429cc8 | 53 | #include "record.h" |
edb3359d | 54 | #include "inline-frame.h" |
4efc6507 | 55 | #include "jit.h" |
06cd862c | 56 | #include "tracepoint.h" |
c906108c SS |
57 | |
58 | /* Prototypes for local functions */ | |
59 | ||
96baa820 | 60 | static void signals_info (char *, int); |
c906108c | 61 | |
96baa820 | 62 | static void handle_command (char *, int); |
c906108c | 63 | |
96baa820 | 64 | static void sig_print_info (enum target_signal); |
c906108c | 65 | |
96baa820 | 66 | static void sig_print_header (void); |
c906108c | 67 | |
74b7792f | 68 | static void resume_cleanups (void *); |
c906108c | 69 | |
96baa820 | 70 | static int hook_stop_stub (void *); |
c906108c | 71 | |
96baa820 JM |
72 | static int restore_selected_frame (void *); |
73 | ||
4ef3f3be | 74 | static int follow_fork (void); |
96baa820 JM |
75 | |
76 | static void set_schedlock_func (char *args, int from_tty, | |
488f131b | 77 | struct cmd_list_element *c); |
96baa820 | 78 | |
a289b8f6 JK |
79 | static int currently_stepping (struct thread_info *tp); |
80 | ||
b3444185 PA |
81 | static int currently_stepping_or_nexting_callback (struct thread_info *tp, |
82 | void *data); | |
a7212384 | 83 | |
96baa820 JM |
84 | static void xdb_handle_command (char *args, int from_tty); |
85 | ||
6a6b96b9 | 86 | static int prepare_to_proceed (int); |
ea67f13b | 87 | |
33d62d64 JK |
88 | static void print_exited_reason (int exitstatus); |
89 | ||
90 | static void print_signal_exited_reason (enum target_signal siggnal); | |
91 | ||
92 | static void print_no_history_reason (void); | |
93 | ||
94 | static void print_signal_received_reason (enum target_signal siggnal); | |
95 | ||
96 | static void print_end_stepping_range_reason (void); | |
97 | ||
96baa820 | 98 | void _initialize_infrun (void); |
43ff13b4 | 99 | |
e58b0e63 PA |
100 | void nullify_last_target_wait_ptid (void); |
101 | ||
5fbbeb29 CF |
102 | /* When set, stop the 'step' command if we enter a function which has |
103 | no line number information. The normal behavior is that we step | |
104 | over such function. */ | |
105 | int step_stop_if_no_debug = 0; | |
920d2a44 AC |
106 | static void |
107 | show_step_stop_if_no_debug (struct ui_file *file, int from_tty, | |
108 | struct cmd_list_element *c, const char *value) | |
109 | { | |
110 | fprintf_filtered (file, _("Mode of the step operation is %s.\n"), value); | |
111 | } | |
5fbbeb29 | 112 | |
1777feb0 | 113 | /* In asynchronous mode, but simulating synchronous execution. */ |
96baa820 | 114 | |
43ff13b4 JM |
115 | int sync_execution = 0; |
116 | ||
c906108c SS |
117 | /* wait_for_inferior and normal_stop use this to notify the user |
118 | when the inferior stopped in a different thread than it had been | |
96baa820 JM |
119 | running in. */ |
120 | ||
39f77062 | 121 | static ptid_t previous_inferior_ptid; |
7a292a7a | 122 | |
6c95b8df PA |
123 | /* Default behavior is to detach newly forked processes (legacy). */ |
124 | int detach_fork = 1; | |
125 | ||
237fc4c9 PA |
126 | int debug_displaced = 0; |
127 | static void | |
128 | show_debug_displaced (struct ui_file *file, int from_tty, | |
129 | struct cmd_list_element *c, const char *value) | |
130 | { | |
131 | fprintf_filtered (file, _("Displace stepping debugging is %s.\n"), value); | |
132 | } | |
133 | ||
628fe4e4 | 134 | int debug_infrun = 0; |
920d2a44 AC |
135 | static void |
136 | show_debug_infrun (struct ui_file *file, int from_tty, | |
137 | struct cmd_list_element *c, const char *value) | |
138 | { | |
139 | fprintf_filtered (file, _("Inferior debugging is %s.\n"), value); | |
140 | } | |
527159b7 | 141 | |
d4f3574e SS |
142 | /* If the program uses ELF-style shared libraries, then calls to |
143 | functions in shared libraries go through stubs, which live in a | |
144 | table called the PLT (Procedure Linkage Table). The first time the | |
145 | function is called, the stub sends control to the dynamic linker, | |
146 | which looks up the function's real address, patches the stub so | |
147 | that future calls will go directly to the function, and then passes | |
148 | control to the function. | |
149 | ||
150 | If we are stepping at the source level, we don't want to see any of | |
151 | this --- we just want to skip over the stub and the dynamic linker. | |
152 | The simple approach is to single-step until control leaves the | |
153 | dynamic linker. | |
154 | ||
ca557f44 AC |
155 | However, on some systems (e.g., Red Hat's 5.2 distribution) the |
156 | dynamic linker calls functions in the shared C library, so you | |
157 | can't tell from the PC alone whether the dynamic linker is still | |
158 | running. In this case, we use a step-resume breakpoint to get us | |
159 | past the dynamic linker, as if we were using "next" to step over a | |
160 | function call. | |
d4f3574e | 161 | |
cfd8ab24 | 162 | in_solib_dynsym_resolve_code() says whether we're in the dynamic |
d4f3574e SS |
163 | linker code or not. Normally, this means we single-step. However, |
164 | if SKIP_SOLIB_RESOLVER then returns non-zero, then its value is an | |
165 | address where we can place a step-resume breakpoint to get past the | |
166 | linker's symbol resolution function. | |
167 | ||
cfd8ab24 | 168 | in_solib_dynsym_resolve_code() can generally be implemented in a |
d4f3574e SS |
169 | pretty portable way, by comparing the PC against the address ranges |
170 | of the dynamic linker's sections. | |
171 | ||
172 | SKIP_SOLIB_RESOLVER is generally going to be system-specific, since | |
173 | it depends on internal details of the dynamic linker. It's usually | |
174 | not too hard to figure out where to put a breakpoint, but it | |
175 | certainly isn't portable. SKIP_SOLIB_RESOLVER should do plenty of | |
176 | sanity checking. If it can't figure things out, returning zero and | |
177 | getting the (possibly confusing) stepping behavior is better than | |
178 | signalling an error, which will obscure the change in the | |
179 | inferior's state. */ | |
c906108c | 180 | |
c906108c SS |
181 | /* This function returns TRUE if pc is the address of an instruction |
182 | that lies within the dynamic linker (such as the event hook, or the | |
183 | dld itself). | |
184 | ||
185 | This function must be used only when a dynamic linker event has | |
186 | been caught, and the inferior is being stepped out of the hook, or | |
187 | undefined results are guaranteed. */ | |
188 | ||
189 | #ifndef SOLIB_IN_DYNAMIC_LINKER | |
190 | #define SOLIB_IN_DYNAMIC_LINKER(pid,pc) 0 | |
191 | #endif | |
192 | ||
d914c394 SS |
193 | /* "Observer mode" is somewhat like a more extreme version of |
194 | non-stop, in which all GDB operations that might affect the | |
195 | target's execution have been disabled. */ | |
196 | ||
197 | static int non_stop_1 = 0; | |
198 | ||
199 | int observer_mode = 0; | |
200 | static int observer_mode_1 = 0; | |
201 | ||
202 | static void | |
203 | set_observer_mode (char *args, int from_tty, | |
204 | struct cmd_list_element *c) | |
205 | { | |
206 | extern int pagination_enabled; | |
207 | ||
208 | if (target_has_execution) | |
209 | { | |
210 | observer_mode_1 = observer_mode; | |
211 | error (_("Cannot change this setting while the inferior is running.")); | |
212 | } | |
213 | ||
214 | observer_mode = observer_mode_1; | |
215 | ||
216 | may_write_registers = !observer_mode; | |
217 | may_write_memory = !observer_mode; | |
218 | may_insert_breakpoints = !observer_mode; | |
219 | may_insert_tracepoints = !observer_mode; | |
220 | /* We can insert fast tracepoints in or out of observer mode, | |
221 | but enable them if we're going into this mode. */ | |
222 | if (observer_mode) | |
223 | may_insert_fast_tracepoints = 1; | |
224 | may_stop = !observer_mode; | |
225 | update_target_permissions (); | |
226 | ||
227 | /* Going *into* observer mode we must force non-stop, then | |
228 | going out we leave it that way. */ | |
229 | if (observer_mode) | |
230 | { | |
231 | target_async_permitted = 1; | |
232 | pagination_enabled = 0; | |
233 | non_stop = non_stop_1 = 1; | |
234 | } | |
235 | ||
236 | if (from_tty) | |
237 | printf_filtered (_("Observer mode is now %s.\n"), | |
238 | (observer_mode ? "on" : "off")); | |
239 | } | |
240 | ||
241 | static void | |
242 | show_observer_mode (struct ui_file *file, int from_tty, | |
243 | struct cmd_list_element *c, const char *value) | |
244 | { | |
245 | fprintf_filtered (file, _("Observer mode is %s.\n"), value); | |
246 | } | |
247 | ||
248 | /* This updates the value of observer mode based on changes in | |
249 | permissions. Note that we are deliberately ignoring the values of | |
250 | may-write-registers and may-write-memory, since the user may have | |
251 | reason to enable these during a session, for instance to turn on a | |
252 | debugging-related global. */ | |
253 | ||
254 | void | |
255 | update_observer_mode (void) | |
256 | { | |
257 | int newval; | |
258 | ||
259 | newval = (!may_insert_breakpoints | |
260 | && !may_insert_tracepoints | |
261 | && may_insert_fast_tracepoints | |
262 | && !may_stop | |
263 | && non_stop); | |
264 | ||
265 | /* Let the user know if things change. */ | |
266 | if (newval != observer_mode) | |
267 | printf_filtered (_("Observer mode is now %s.\n"), | |
268 | (newval ? "on" : "off")); | |
269 | ||
270 | observer_mode = observer_mode_1 = newval; | |
271 | } | |
c2c6d25f | 272 | |
c906108c SS |
273 | /* Tables of how to react to signals; the user sets them. */ |
274 | ||
275 | static unsigned char *signal_stop; | |
276 | static unsigned char *signal_print; | |
277 | static unsigned char *signal_program; | |
278 | ||
279 | #define SET_SIGS(nsigs,sigs,flags) \ | |
280 | do { \ | |
281 | int signum = (nsigs); \ | |
282 | while (signum-- > 0) \ | |
283 | if ((sigs)[signum]) \ | |
284 | (flags)[signum] = 1; \ | |
285 | } while (0) | |
286 | ||
287 | #define UNSET_SIGS(nsigs,sigs,flags) \ | |
288 | do { \ | |
289 | int signum = (nsigs); \ | |
290 | while (signum-- > 0) \ | |
291 | if ((sigs)[signum]) \ | |
292 | (flags)[signum] = 0; \ | |
293 | } while (0) | |
294 | ||
1777feb0 | 295 | /* Value to pass to target_resume() to cause all threads to resume. */ |
39f77062 | 296 | |
edb3359d | 297 | #define RESUME_ALL minus_one_ptid |
c906108c SS |
298 | |
299 | /* Command list pointer for the "stop" placeholder. */ | |
300 | ||
301 | static struct cmd_list_element *stop_command; | |
302 | ||
c906108c SS |
303 | /* Function inferior was in as of last step command. */ |
304 | ||
305 | static struct symbol *step_start_function; | |
306 | ||
c906108c SS |
307 | /* Nonzero if we want to give control to the user when we're notified |
308 | of shared library events by the dynamic linker. */ | |
628fe4e4 | 309 | int stop_on_solib_events; |
920d2a44 AC |
310 | static void |
311 | show_stop_on_solib_events (struct ui_file *file, int from_tty, | |
312 | struct cmd_list_element *c, const char *value) | |
313 | { | |
314 | fprintf_filtered (file, _("Stopping for shared library events is %s.\n"), | |
315 | value); | |
316 | } | |
c906108c | 317 | |
c906108c SS |
318 | /* Nonzero means expecting a trace trap |
319 | and should stop the inferior and return silently when it happens. */ | |
320 | ||
321 | int stop_after_trap; | |
322 | ||
642fd101 DE |
323 | /* Save register contents here when executing a "finish" command or are |
324 | about to pop a stack dummy frame, if-and-only-if proceed_to_finish is set. | |
c906108c SS |
325 | Thus this contains the return value from the called function (assuming |
326 | values are returned in a register). */ | |
327 | ||
72cec141 | 328 | struct regcache *stop_registers; |
c906108c | 329 | |
c906108c SS |
330 | /* Nonzero after stop if current stack frame should be printed. */ |
331 | ||
332 | static int stop_print_frame; | |
333 | ||
e02bc4cc | 334 | /* This is a cached copy of the pid/waitstatus of the last event |
9a4105ab AC |
335 | returned by target_wait()/deprecated_target_wait_hook(). This |
336 | information is returned by get_last_target_status(). */ | |
39f77062 | 337 | static ptid_t target_last_wait_ptid; |
e02bc4cc DS |
338 | static struct target_waitstatus target_last_waitstatus; |
339 | ||
0d1e5fa7 PA |
340 | static void context_switch (ptid_t ptid); |
341 | ||
4e1c45ea | 342 | void init_thread_stepping_state (struct thread_info *tss); |
0d1e5fa7 PA |
343 | |
344 | void init_infwait_state (void); | |
a474d7c2 | 345 | |
53904c9e AC |
346 | static const char follow_fork_mode_child[] = "child"; |
347 | static const char follow_fork_mode_parent[] = "parent"; | |
348 | ||
488f131b | 349 | static const char *follow_fork_mode_kind_names[] = { |
53904c9e AC |
350 | follow_fork_mode_child, |
351 | follow_fork_mode_parent, | |
352 | NULL | |
ef346e04 | 353 | }; |
c906108c | 354 | |
53904c9e | 355 | static const char *follow_fork_mode_string = follow_fork_mode_parent; |
920d2a44 AC |
356 | static void |
357 | show_follow_fork_mode_string (struct ui_file *file, int from_tty, | |
358 | struct cmd_list_element *c, const char *value) | |
359 | { | |
3e43a32a MS |
360 | fprintf_filtered (file, |
361 | _("Debugger response to a program " | |
362 | "call of fork or vfork is \"%s\".\n"), | |
920d2a44 AC |
363 | value); |
364 | } | |
c906108c SS |
365 | \f |
366 | ||
e58b0e63 PA |
367 | /* Tell the target to follow the fork we're stopped at. Returns true |
368 | if the inferior should be resumed; false, if the target for some | |
369 | reason decided it's best not to resume. */ | |
370 | ||
6604731b | 371 | static int |
4ef3f3be | 372 | follow_fork (void) |
c906108c | 373 | { |
ea1dd7bc | 374 | int follow_child = (follow_fork_mode_string == follow_fork_mode_child); |
e58b0e63 PA |
375 | int should_resume = 1; |
376 | struct thread_info *tp; | |
377 | ||
378 | /* Copy user stepping state to the new inferior thread. FIXME: the | |
379 | followed fork child thread should have a copy of most of the | |
4e3990f4 DE |
380 | parent thread structure's run control related fields, not just these. |
381 | Initialized to avoid "may be used uninitialized" warnings from gcc. */ | |
382 | struct breakpoint *step_resume_breakpoint = NULL; | |
186c406b | 383 | struct breakpoint *exception_resume_breakpoint = NULL; |
4e3990f4 DE |
384 | CORE_ADDR step_range_start = 0; |
385 | CORE_ADDR step_range_end = 0; | |
386 | struct frame_id step_frame_id = { 0 }; | |
e58b0e63 PA |
387 | |
388 | if (!non_stop) | |
389 | { | |
390 | ptid_t wait_ptid; | |
391 | struct target_waitstatus wait_status; | |
392 | ||
393 | /* Get the last target status returned by target_wait(). */ | |
394 | get_last_target_status (&wait_ptid, &wait_status); | |
395 | ||
396 | /* If not stopped at a fork event, then there's nothing else to | |
397 | do. */ | |
398 | if (wait_status.kind != TARGET_WAITKIND_FORKED | |
399 | && wait_status.kind != TARGET_WAITKIND_VFORKED) | |
400 | return 1; | |
401 | ||
402 | /* Check if we switched over from WAIT_PTID, since the event was | |
403 | reported. */ | |
404 | if (!ptid_equal (wait_ptid, minus_one_ptid) | |
405 | && !ptid_equal (inferior_ptid, wait_ptid)) | |
406 | { | |
407 | /* We did. Switch back to WAIT_PTID thread, to tell the | |
408 | target to follow it (in either direction). We'll | |
409 | afterwards refuse to resume, and inform the user what | |
410 | happened. */ | |
411 | switch_to_thread (wait_ptid); | |
412 | should_resume = 0; | |
413 | } | |
414 | } | |
415 | ||
416 | tp = inferior_thread (); | |
417 | ||
418 | /* If there were any forks/vforks that were caught and are now to be | |
419 | followed, then do so now. */ | |
420 | switch (tp->pending_follow.kind) | |
421 | { | |
422 | case TARGET_WAITKIND_FORKED: | |
423 | case TARGET_WAITKIND_VFORKED: | |
424 | { | |
425 | ptid_t parent, child; | |
426 | ||
427 | /* If the user did a next/step, etc, over a fork call, | |
428 | preserve the stepping state in the fork child. */ | |
429 | if (follow_child && should_resume) | |
430 | { | |
8358c15c JK |
431 | step_resume_breakpoint = clone_momentary_breakpoint |
432 | (tp->control.step_resume_breakpoint); | |
16c381f0 JK |
433 | step_range_start = tp->control.step_range_start; |
434 | step_range_end = tp->control.step_range_end; | |
435 | step_frame_id = tp->control.step_frame_id; | |
186c406b TT |
436 | exception_resume_breakpoint |
437 | = clone_momentary_breakpoint (tp->control.exception_resume_breakpoint); | |
e58b0e63 PA |
438 | |
439 | /* For now, delete the parent's sr breakpoint, otherwise, | |
440 | parent/child sr breakpoints are considered duplicates, | |
441 | and the child version will not be installed. Remove | |
442 | this when the breakpoints module becomes aware of | |
443 | inferiors and address spaces. */ | |
444 | delete_step_resume_breakpoint (tp); | |
16c381f0 JK |
445 | tp->control.step_range_start = 0; |
446 | tp->control.step_range_end = 0; | |
447 | tp->control.step_frame_id = null_frame_id; | |
186c406b | 448 | delete_exception_resume_breakpoint (tp); |
e58b0e63 PA |
449 | } |
450 | ||
451 | parent = inferior_ptid; | |
452 | child = tp->pending_follow.value.related_pid; | |
453 | ||
454 | /* Tell the target to do whatever is necessary to follow | |
455 | either parent or child. */ | |
456 | if (target_follow_fork (follow_child)) | |
457 | { | |
458 | /* Target refused to follow, or there's some other reason | |
459 | we shouldn't resume. */ | |
460 | should_resume = 0; | |
461 | } | |
462 | else | |
463 | { | |
464 | /* This pending follow fork event is now handled, one way | |
465 | or another. The previous selected thread may be gone | |
466 | from the lists by now, but if it is still around, need | |
467 | to clear the pending follow request. */ | |
e09875d4 | 468 | tp = find_thread_ptid (parent); |
e58b0e63 PA |
469 | if (tp) |
470 | tp->pending_follow.kind = TARGET_WAITKIND_SPURIOUS; | |
471 | ||
472 | /* This makes sure we don't try to apply the "Switched | |
473 | over from WAIT_PID" logic above. */ | |
474 | nullify_last_target_wait_ptid (); | |
475 | ||
1777feb0 | 476 | /* If we followed the child, switch to it... */ |
e58b0e63 PA |
477 | if (follow_child) |
478 | { | |
479 | switch_to_thread (child); | |
480 | ||
481 | /* ... and preserve the stepping state, in case the | |
482 | user was stepping over the fork call. */ | |
483 | if (should_resume) | |
484 | { | |
485 | tp = inferior_thread (); | |
8358c15c JK |
486 | tp->control.step_resume_breakpoint |
487 | = step_resume_breakpoint; | |
16c381f0 JK |
488 | tp->control.step_range_start = step_range_start; |
489 | tp->control.step_range_end = step_range_end; | |
490 | tp->control.step_frame_id = step_frame_id; | |
186c406b TT |
491 | tp->control.exception_resume_breakpoint |
492 | = exception_resume_breakpoint; | |
e58b0e63 PA |
493 | } |
494 | else | |
495 | { | |
496 | /* If we get here, it was because we're trying to | |
497 | resume from a fork catchpoint, but, the user | |
498 | has switched threads away from the thread that | |
499 | forked. In that case, the resume command | |
500 | issued is most likely not applicable to the | |
501 | child, so just warn, and refuse to resume. */ | |
3e43a32a MS |
502 | warning (_("Not resuming: switched threads " |
503 | "before following fork child.\n")); | |
e58b0e63 PA |
504 | } |
505 | ||
506 | /* Reset breakpoints in the child as appropriate. */ | |
507 | follow_inferior_reset_breakpoints (); | |
508 | } | |
509 | else | |
510 | switch_to_thread (parent); | |
511 | } | |
512 | } | |
513 | break; | |
514 | case TARGET_WAITKIND_SPURIOUS: | |
515 | /* Nothing to follow. */ | |
516 | break; | |
517 | default: | |
518 | internal_error (__FILE__, __LINE__, | |
519 | "Unexpected pending_follow.kind %d\n", | |
520 | tp->pending_follow.kind); | |
521 | break; | |
522 | } | |
c906108c | 523 | |
e58b0e63 | 524 | return should_resume; |
c906108c SS |
525 | } |
526 | ||
6604731b DJ |
527 | void |
528 | follow_inferior_reset_breakpoints (void) | |
c906108c | 529 | { |
4e1c45ea PA |
530 | struct thread_info *tp = inferior_thread (); |
531 | ||
6604731b DJ |
532 | /* Was there a step_resume breakpoint? (There was if the user |
533 | did a "next" at the fork() call.) If so, explicitly reset its | |
534 | thread number. | |
535 | ||
536 | step_resumes are a form of bp that are made to be per-thread. | |
537 | Since we created the step_resume bp when the parent process | |
538 | was being debugged, and now are switching to the child process, | |
539 | from the breakpoint package's viewpoint, that's a switch of | |
540 | "threads". We must update the bp's notion of which thread | |
541 | it is for, or it'll be ignored when it triggers. */ | |
542 | ||
8358c15c JK |
543 | if (tp->control.step_resume_breakpoint) |
544 | breakpoint_re_set_thread (tp->control.step_resume_breakpoint); | |
6604731b | 545 | |
186c406b TT |
546 | if (tp->control.exception_resume_breakpoint) |
547 | breakpoint_re_set_thread (tp->control.exception_resume_breakpoint); | |
548 | ||
6604731b DJ |
549 | /* Reinsert all breakpoints in the child. The user may have set |
550 | breakpoints after catching the fork, in which case those | |
551 | were never set in the child, but only in the parent. This makes | |
552 | sure the inserted breakpoints match the breakpoint list. */ | |
553 | ||
554 | breakpoint_re_set (); | |
555 | insert_breakpoints (); | |
c906108c | 556 | } |
c906108c | 557 | |
6c95b8df PA |
558 | /* The child has exited or execed: resume threads of the parent the |
559 | user wanted to be executing. */ | |
560 | ||
561 | static int | |
562 | proceed_after_vfork_done (struct thread_info *thread, | |
563 | void *arg) | |
564 | { | |
565 | int pid = * (int *) arg; | |
566 | ||
567 | if (ptid_get_pid (thread->ptid) == pid | |
568 | && is_running (thread->ptid) | |
569 | && !is_executing (thread->ptid) | |
570 | && !thread->stop_requested | |
16c381f0 | 571 | && thread->suspend.stop_signal == TARGET_SIGNAL_0) |
6c95b8df PA |
572 | { |
573 | if (debug_infrun) | |
574 | fprintf_unfiltered (gdb_stdlog, | |
575 | "infrun: resuming vfork parent thread %s\n", | |
576 | target_pid_to_str (thread->ptid)); | |
577 | ||
578 | switch_to_thread (thread->ptid); | |
579 | clear_proceed_status (); | |
580 | proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0); | |
581 | } | |
582 | ||
583 | return 0; | |
584 | } | |
585 | ||
586 | /* Called whenever we notice an exec or exit event, to handle | |
587 | detaching or resuming a vfork parent. */ | |
588 | ||
589 | static void | |
590 | handle_vfork_child_exec_or_exit (int exec) | |
591 | { | |
592 | struct inferior *inf = current_inferior (); | |
593 | ||
594 | if (inf->vfork_parent) | |
595 | { | |
596 | int resume_parent = -1; | |
597 | ||
598 | /* This exec or exit marks the end of the shared memory region | |
599 | between the parent and the child. If the user wanted to | |
600 | detach from the parent, now is the time. */ | |
601 | ||
602 | if (inf->vfork_parent->pending_detach) | |
603 | { | |
604 | struct thread_info *tp; | |
605 | struct cleanup *old_chain; | |
606 | struct program_space *pspace; | |
607 | struct address_space *aspace; | |
608 | ||
1777feb0 | 609 | /* follow-fork child, detach-on-fork on. */ |
6c95b8df PA |
610 | |
611 | old_chain = make_cleanup_restore_current_thread (); | |
612 | ||
613 | /* We're letting loose of the parent. */ | |
614 | tp = any_live_thread_of_process (inf->vfork_parent->pid); | |
615 | switch_to_thread (tp->ptid); | |
616 | ||
617 | /* We're about to detach from the parent, which implicitly | |
618 | removes breakpoints from its address space. There's a | |
619 | catch here: we want to reuse the spaces for the child, | |
620 | but, parent/child are still sharing the pspace at this | |
621 | point, although the exec in reality makes the kernel give | |
622 | the child a fresh set of new pages. The problem here is | |
623 | that the breakpoints module being unaware of this, would | |
624 | likely chose the child process to write to the parent | |
625 | address space. Swapping the child temporarily away from | |
626 | the spaces has the desired effect. Yes, this is "sort | |
627 | of" a hack. */ | |
628 | ||
629 | pspace = inf->pspace; | |
630 | aspace = inf->aspace; | |
631 | inf->aspace = NULL; | |
632 | inf->pspace = NULL; | |
633 | ||
634 | if (debug_infrun || info_verbose) | |
635 | { | |
636 | target_terminal_ours (); | |
637 | ||
638 | if (exec) | |
639 | fprintf_filtered (gdb_stdlog, | |
3e43a32a MS |
640 | "Detaching vfork parent process " |
641 | "%d after child exec.\n", | |
6c95b8df PA |
642 | inf->vfork_parent->pid); |
643 | else | |
644 | fprintf_filtered (gdb_stdlog, | |
3e43a32a MS |
645 | "Detaching vfork parent process " |
646 | "%d after child exit.\n", | |
6c95b8df PA |
647 | inf->vfork_parent->pid); |
648 | } | |
649 | ||
650 | target_detach (NULL, 0); | |
651 | ||
652 | /* Put it back. */ | |
653 | inf->pspace = pspace; | |
654 | inf->aspace = aspace; | |
655 | ||
656 | do_cleanups (old_chain); | |
657 | } | |
658 | else if (exec) | |
659 | { | |
660 | /* We're staying attached to the parent, so, really give the | |
661 | child a new address space. */ | |
662 | inf->pspace = add_program_space (maybe_new_address_space ()); | |
663 | inf->aspace = inf->pspace->aspace; | |
664 | inf->removable = 1; | |
665 | set_current_program_space (inf->pspace); | |
666 | ||
667 | resume_parent = inf->vfork_parent->pid; | |
668 | ||
669 | /* Break the bonds. */ | |
670 | inf->vfork_parent->vfork_child = NULL; | |
671 | } | |
672 | else | |
673 | { | |
674 | struct cleanup *old_chain; | |
675 | struct program_space *pspace; | |
676 | ||
677 | /* If this is a vfork child exiting, then the pspace and | |
678 | aspaces were shared with the parent. Since we're | |
679 | reporting the process exit, we'll be mourning all that is | |
680 | found in the address space, and switching to null_ptid, | |
681 | preparing to start a new inferior. But, since we don't | |
682 | want to clobber the parent's address/program spaces, we | |
683 | go ahead and create a new one for this exiting | |
684 | inferior. */ | |
685 | ||
686 | /* Switch to null_ptid, so that clone_program_space doesn't want | |
687 | to read the selected frame of a dead process. */ | |
688 | old_chain = save_inferior_ptid (); | |
689 | inferior_ptid = null_ptid; | |
690 | ||
691 | /* This inferior is dead, so avoid giving the breakpoints | |
692 | module the option to write through to it (cloning a | |
693 | program space resets breakpoints). */ | |
694 | inf->aspace = NULL; | |
695 | inf->pspace = NULL; | |
696 | pspace = add_program_space (maybe_new_address_space ()); | |
697 | set_current_program_space (pspace); | |
698 | inf->removable = 1; | |
699 | clone_program_space (pspace, inf->vfork_parent->pspace); | |
700 | inf->pspace = pspace; | |
701 | inf->aspace = pspace->aspace; | |
702 | ||
703 | /* Put back inferior_ptid. We'll continue mourning this | |
1777feb0 | 704 | inferior. */ |
6c95b8df PA |
705 | do_cleanups (old_chain); |
706 | ||
707 | resume_parent = inf->vfork_parent->pid; | |
708 | /* Break the bonds. */ | |
709 | inf->vfork_parent->vfork_child = NULL; | |
710 | } | |
711 | ||
712 | inf->vfork_parent = NULL; | |
713 | ||
714 | gdb_assert (current_program_space == inf->pspace); | |
715 | ||
716 | if (non_stop && resume_parent != -1) | |
717 | { | |
718 | /* If the user wanted the parent to be running, let it go | |
719 | free now. */ | |
720 | struct cleanup *old_chain = make_cleanup_restore_current_thread (); | |
721 | ||
722 | if (debug_infrun) | |
3e43a32a MS |
723 | fprintf_unfiltered (gdb_stdlog, |
724 | "infrun: resuming vfork parent process %d\n", | |
6c95b8df PA |
725 | resume_parent); |
726 | ||
727 | iterate_over_threads (proceed_after_vfork_done, &resume_parent); | |
728 | ||
729 | do_cleanups (old_chain); | |
730 | } | |
731 | } | |
732 | } | |
733 | ||
734 | /* Enum strings for "set|show displaced-stepping". */ | |
735 | ||
736 | static const char follow_exec_mode_new[] = "new"; | |
737 | static const char follow_exec_mode_same[] = "same"; | |
738 | static const char *follow_exec_mode_names[] = | |
739 | { | |
740 | follow_exec_mode_new, | |
741 | follow_exec_mode_same, | |
742 | NULL, | |
743 | }; | |
744 | ||
745 | static const char *follow_exec_mode_string = follow_exec_mode_same; | |
746 | static void | |
747 | show_follow_exec_mode_string (struct ui_file *file, int from_tty, | |
748 | struct cmd_list_element *c, const char *value) | |
749 | { | |
750 | fprintf_filtered (file, _("Follow exec mode is \"%s\".\n"), value); | |
751 | } | |
752 | ||
1777feb0 | 753 | /* EXECD_PATHNAME is assumed to be non-NULL. */ |
1adeb98a | 754 | |
c906108c | 755 | static void |
3a3e9ee3 | 756 | follow_exec (ptid_t pid, char *execd_pathname) |
c906108c | 757 | { |
4e1c45ea | 758 | struct thread_info *th = inferior_thread (); |
6c95b8df | 759 | struct inferior *inf = current_inferior (); |
7a292a7a | 760 | |
c906108c SS |
761 | /* This is an exec event that we actually wish to pay attention to. |
762 | Refresh our symbol table to the newly exec'd program, remove any | |
763 | momentary bp's, etc. | |
764 | ||
765 | If there are breakpoints, they aren't really inserted now, | |
766 | since the exec() transformed our inferior into a fresh set | |
767 | of instructions. | |
768 | ||
769 | We want to preserve symbolic breakpoints on the list, since | |
770 | we have hopes that they can be reset after the new a.out's | |
771 | symbol table is read. | |
772 | ||
773 | However, any "raw" breakpoints must be removed from the list | |
774 | (e.g., the solib bp's), since their address is probably invalid | |
775 | now. | |
776 | ||
777 | And, we DON'T want to call delete_breakpoints() here, since | |
778 | that may write the bp's "shadow contents" (the instruction | |
779 | value that was overwritten witha TRAP instruction). Since | |
1777feb0 | 780 | we now have a new a.out, those shadow contents aren't valid. */ |
6c95b8df PA |
781 | |
782 | mark_breakpoints_out (); | |
783 | ||
c906108c SS |
784 | update_breakpoints_after_exec (); |
785 | ||
786 | /* If there was one, it's gone now. We cannot truly step-to-next | |
1777feb0 | 787 | statement through an exec(). */ |
8358c15c | 788 | th->control.step_resume_breakpoint = NULL; |
186c406b | 789 | th->control.exception_resume_breakpoint = NULL; |
16c381f0 JK |
790 | th->control.step_range_start = 0; |
791 | th->control.step_range_end = 0; | |
c906108c | 792 | |
a75724bc PA |
793 | /* The target reports the exec event to the main thread, even if |
794 | some other thread does the exec, and even if the main thread was | |
795 | already stopped --- if debugging in non-stop mode, it's possible | |
796 | the user had the main thread held stopped in the previous image | |
797 | --- release it now. This is the same behavior as step-over-exec | |
798 | with scheduler-locking on in all-stop mode. */ | |
799 | th->stop_requested = 0; | |
800 | ||
1777feb0 | 801 | /* What is this a.out's name? */ |
6c95b8df PA |
802 | printf_unfiltered (_("%s is executing new program: %s\n"), |
803 | target_pid_to_str (inferior_ptid), | |
804 | execd_pathname); | |
c906108c SS |
805 | |
806 | /* We've followed the inferior through an exec. Therefore, the | |
1777feb0 | 807 | inferior has essentially been killed & reborn. */ |
7a292a7a | 808 | |
c906108c | 809 | gdb_flush (gdb_stdout); |
6ca15a4b PA |
810 | |
811 | breakpoint_init_inferior (inf_execd); | |
e85a822c DJ |
812 | |
813 | if (gdb_sysroot && *gdb_sysroot) | |
814 | { | |
815 | char *name = alloca (strlen (gdb_sysroot) | |
816 | + strlen (execd_pathname) | |
817 | + 1); | |
abbb1732 | 818 | |
e85a822c DJ |
819 | strcpy (name, gdb_sysroot); |
820 | strcat (name, execd_pathname); | |
821 | execd_pathname = name; | |
822 | } | |
c906108c | 823 | |
cce9b6bf PA |
824 | /* Reset the shared library package. This ensures that we get a |
825 | shlib event when the child reaches "_start", at which point the | |
826 | dld will have had a chance to initialize the child. */ | |
827 | /* Also, loading a symbol file below may trigger symbol lookups, and | |
828 | we don't want those to be satisfied by the libraries of the | |
829 | previous incarnation of this process. */ | |
830 | no_shared_libraries (NULL, 0); | |
831 | ||
6c95b8df PA |
832 | if (follow_exec_mode_string == follow_exec_mode_new) |
833 | { | |
834 | struct program_space *pspace; | |
6c95b8df PA |
835 | |
836 | /* The user wants to keep the old inferior and program spaces | |
837 | around. Create a new fresh one, and switch to it. */ | |
838 | ||
839 | inf = add_inferior (current_inferior ()->pid); | |
840 | pspace = add_program_space (maybe_new_address_space ()); | |
841 | inf->pspace = pspace; | |
842 | inf->aspace = pspace->aspace; | |
843 | ||
844 | exit_inferior_num_silent (current_inferior ()->num); | |
845 | ||
846 | set_current_inferior (inf); | |
847 | set_current_program_space (pspace); | |
848 | } | |
849 | ||
850 | gdb_assert (current_program_space == inf->pspace); | |
851 | ||
1777feb0 | 852 | /* That a.out is now the one to use. */ |
6c95b8df PA |
853 | exec_file_attach (execd_pathname, 0); |
854 | ||
c1e56572 JK |
855 | /* SYMFILE_DEFER_BP_RESET is used as the proper displacement for PIE |
856 | (Position Independent Executable) main symbol file will get applied by | |
857 | solib_create_inferior_hook below. breakpoint_re_set would fail to insert | |
858 | the breakpoints with the zero displacement. */ | |
859 | ||
860 | symbol_file_add (execd_pathname, SYMFILE_MAINLINE | SYMFILE_DEFER_BP_RESET, | |
861 | NULL, 0); | |
862 | ||
863 | set_initial_language (); | |
c906108c | 864 | |
7a292a7a | 865 | #ifdef SOLIB_CREATE_INFERIOR_HOOK |
39f77062 | 866 | SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid)); |
a77053c2 | 867 | #else |
268a4a75 | 868 | solib_create_inferior_hook (0); |
7a292a7a | 869 | #endif |
c906108c | 870 | |
4efc6507 DE |
871 | jit_inferior_created_hook (); |
872 | ||
c1e56572 JK |
873 | breakpoint_re_set (); |
874 | ||
c906108c SS |
875 | /* Reinsert all breakpoints. (Those which were symbolic have |
876 | been reset to the proper address in the new a.out, thanks | |
1777feb0 | 877 | to symbol_file_command...). */ |
c906108c SS |
878 | insert_breakpoints (); |
879 | ||
880 | /* The next resume of this inferior should bring it to the shlib | |
881 | startup breakpoints. (If the user had also set bp's on | |
882 | "main" from the old (parent) process, then they'll auto- | |
1777feb0 | 883 | matically get reset there in the new process.). */ |
c906108c SS |
884 | } |
885 | ||
886 | /* Non-zero if we just simulating a single-step. This is needed | |
887 | because we cannot remove the breakpoints in the inferior process | |
888 | until after the `wait' in `wait_for_inferior'. */ | |
889 | static int singlestep_breakpoints_inserted_p = 0; | |
9f976b41 DJ |
890 | |
891 | /* The thread we inserted single-step breakpoints for. */ | |
892 | static ptid_t singlestep_ptid; | |
893 | ||
fd48f117 DJ |
894 | /* PC when we started this single-step. */ |
895 | static CORE_ADDR singlestep_pc; | |
896 | ||
9f976b41 DJ |
897 | /* If another thread hit the singlestep breakpoint, we save the original |
898 | thread here so that we can resume single-stepping it later. */ | |
899 | static ptid_t saved_singlestep_ptid; | |
900 | static int stepping_past_singlestep_breakpoint; | |
6a6b96b9 | 901 | |
ca67fcb8 VP |
902 | /* If not equal to null_ptid, this means that after stepping over breakpoint |
903 | is finished, we need to switch to deferred_step_ptid, and step it. | |
904 | ||
905 | The use case is when one thread has hit a breakpoint, and then the user | |
1777feb0 | 906 | has switched to another thread and issued 'step'. We need to step over |
ca67fcb8 VP |
907 | breakpoint in the thread which hit the breakpoint, but then continue |
908 | stepping the thread user has selected. */ | |
909 | static ptid_t deferred_step_ptid; | |
c906108c | 910 | \f |
237fc4c9 PA |
911 | /* Displaced stepping. */ |
912 | ||
913 | /* In non-stop debugging mode, we must take special care to manage | |
914 | breakpoints properly; in particular, the traditional strategy for | |
915 | stepping a thread past a breakpoint it has hit is unsuitable. | |
916 | 'Displaced stepping' is a tactic for stepping one thread past a | |
917 | breakpoint it has hit while ensuring that other threads running | |
918 | concurrently will hit the breakpoint as they should. | |
919 | ||
920 | The traditional way to step a thread T off a breakpoint in a | |
921 | multi-threaded program in all-stop mode is as follows: | |
922 | ||
923 | a0) Initially, all threads are stopped, and breakpoints are not | |
924 | inserted. | |
925 | a1) We single-step T, leaving breakpoints uninserted. | |
926 | a2) We insert breakpoints, and resume all threads. | |
927 | ||
928 | In non-stop debugging, however, this strategy is unsuitable: we | |
929 | don't want to have to stop all threads in the system in order to | |
930 | continue or step T past a breakpoint. Instead, we use displaced | |
931 | stepping: | |
932 | ||
933 | n0) Initially, T is stopped, other threads are running, and | |
934 | breakpoints are inserted. | |
935 | n1) We copy the instruction "under" the breakpoint to a separate | |
936 | location, outside the main code stream, making any adjustments | |
937 | to the instruction, register, and memory state as directed by | |
938 | T's architecture. | |
939 | n2) We single-step T over the instruction at its new location. | |
940 | n3) We adjust the resulting register and memory state as directed | |
941 | by T's architecture. This includes resetting T's PC to point | |
942 | back into the main instruction stream. | |
943 | n4) We resume T. | |
944 | ||
945 | This approach depends on the following gdbarch methods: | |
946 | ||
947 | - gdbarch_max_insn_length and gdbarch_displaced_step_location | |
948 | indicate where to copy the instruction, and how much space must | |
949 | be reserved there. We use these in step n1. | |
950 | ||
951 | - gdbarch_displaced_step_copy_insn copies a instruction to a new | |
952 | address, and makes any necessary adjustments to the instruction, | |
953 | register contents, and memory. We use this in step n1. | |
954 | ||
955 | - gdbarch_displaced_step_fixup adjusts registers and memory after | |
956 | we have successfuly single-stepped the instruction, to yield the | |
957 | same effect the instruction would have had if we had executed it | |
958 | at its original address. We use this in step n3. | |
959 | ||
960 | - gdbarch_displaced_step_free_closure provides cleanup. | |
961 | ||
962 | The gdbarch_displaced_step_copy_insn and | |
963 | gdbarch_displaced_step_fixup functions must be written so that | |
964 | copying an instruction with gdbarch_displaced_step_copy_insn, | |
965 | single-stepping across the copied instruction, and then applying | |
966 | gdbarch_displaced_insn_fixup should have the same effects on the | |
967 | thread's memory and registers as stepping the instruction in place | |
968 | would have. Exactly which responsibilities fall to the copy and | |
969 | which fall to the fixup is up to the author of those functions. | |
970 | ||
971 | See the comments in gdbarch.sh for details. | |
972 | ||
973 | Note that displaced stepping and software single-step cannot | |
974 | currently be used in combination, although with some care I think | |
975 | they could be made to. Software single-step works by placing | |
976 | breakpoints on all possible subsequent instructions; if the | |
977 | displaced instruction is a PC-relative jump, those breakpoints | |
978 | could fall in very strange places --- on pages that aren't | |
979 | executable, or at addresses that are not proper instruction | |
980 | boundaries. (We do generally let other threads run while we wait | |
981 | to hit the software single-step breakpoint, and they might | |
982 | encounter such a corrupted instruction.) One way to work around | |
983 | this would be to have gdbarch_displaced_step_copy_insn fully | |
984 | simulate the effect of PC-relative instructions (and return NULL) | |
985 | on architectures that use software single-stepping. | |
986 | ||
987 | In non-stop mode, we can have independent and simultaneous step | |
988 | requests, so more than one thread may need to simultaneously step | |
989 | over a breakpoint. The current implementation assumes there is | |
990 | only one scratch space per process. In this case, we have to | |
991 | serialize access to the scratch space. If thread A wants to step | |
992 | over a breakpoint, but we are currently waiting for some other | |
993 | thread to complete a displaced step, we leave thread A stopped and | |
994 | place it in the displaced_step_request_queue. Whenever a displaced | |
995 | step finishes, we pick the next thread in the queue and start a new | |
996 | displaced step operation on it. See displaced_step_prepare and | |
997 | displaced_step_fixup for details. */ | |
998 | ||
237fc4c9 PA |
999 | struct displaced_step_request |
1000 | { | |
1001 | ptid_t ptid; | |
1002 | struct displaced_step_request *next; | |
1003 | }; | |
1004 | ||
fc1cf338 PA |
1005 | /* Per-inferior displaced stepping state. */ |
1006 | struct displaced_step_inferior_state | |
1007 | { | |
1008 | /* Pointer to next in linked list. */ | |
1009 | struct displaced_step_inferior_state *next; | |
1010 | ||
1011 | /* The process this displaced step state refers to. */ | |
1012 | int pid; | |
1013 | ||
1014 | /* A queue of pending displaced stepping requests. One entry per | |
1015 | thread that needs to do a displaced step. */ | |
1016 | struct displaced_step_request *step_request_queue; | |
1017 | ||
1018 | /* If this is not null_ptid, this is the thread carrying out a | |
1019 | displaced single-step in process PID. This thread's state will | |
1020 | require fixing up once it has completed its step. */ | |
1021 | ptid_t step_ptid; | |
1022 | ||
1023 | /* The architecture the thread had when we stepped it. */ | |
1024 | struct gdbarch *step_gdbarch; | |
1025 | ||
1026 | /* The closure provided gdbarch_displaced_step_copy_insn, to be used | |
1027 | for post-step cleanup. */ | |
1028 | struct displaced_step_closure *step_closure; | |
1029 | ||
1030 | /* The address of the original instruction, and the copy we | |
1031 | made. */ | |
1032 | CORE_ADDR step_original, step_copy; | |
1033 | ||
1034 | /* Saved contents of copy area. */ | |
1035 | gdb_byte *step_saved_copy; | |
1036 | }; | |
1037 | ||
1038 | /* The list of states of processes involved in displaced stepping | |
1039 | presently. */ | |
1040 | static struct displaced_step_inferior_state *displaced_step_inferior_states; | |
1041 | ||
1042 | /* Get the displaced stepping state of process PID. */ | |
1043 | ||
1044 | static struct displaced_step_inferior_state * | |
1045 | get_displaced_stepping_state (int pid) | |
1046 | { | |
1047 | struct displaced_step_inferior_state *state; | |
1048 | ||
1049 | for (state = displaced_step_inferior_states; | |
1050 | state != NULL; | |
1051 | state = state->next) | |
1052 | if (state->pid == pid) | |
1053 | return state; | |
1054 | ||
1055 | return NULL; | |
1056 | } | |
1057 | ||
1058 | /* Add a new displaced stepping state for process PID to the displaced | |
1059 | stepping state list, or return a pointer to an already existing | |
1060 | entry, if it already exists. Never returns NULL. */ | |
1061 | ||
1062 | static struct displaced_step_inferior_state * | |
1063 | add_displaced_stepping_state (int pid) | |
1064 | { | |
1065 | struct displaced_step_inferior_state *state; | |
1066 | ||
1067 | for (state = displaced_step_inferior_states; | |
1068 | state != NULL; | |
1069 | state = state->next) | |
1070 | if (state->pid == pid) | |
1071 | return state; | |
237fc4c9 | 1072 | |
fc1cf338 PA |
1073 | state = xcalloc (1, sizeof (*state)); |
1074 | state->pid = pid; | |
1075 | state->next = displaced_step_inferior_states; | |
1076 | displaced_step_inferior_states = state; | |
237fc4c9 | 1077 | |
fc1cf338 PA |
1078 | return state; |
1079 | } | |
1080 | ||
a42244db YQ |
1081 | /* If inferior is in displaced stepping, and ADDR equals to starting address |
1082 | of copy area, return corresponding displaced_step_closure. Otherwise, | |
1083 | return NULL. */ | |
1084 | ||
1085 | struct displaced_step_closure* | |
1086 | get_displaced_step_closure_by_addr (CORE_ADDR addr) | |
1087 | { | |
1088 | struct displaced_step_inferior_state *displaced | |
1089 | = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); | |
1090 | ||
1091 | /* If checking the mode of displaced instruction in copy area. */ | |
1092 | if (displaced && !ptid_equal (displaced->step_ptid, null_ptid) | |
1093 | && (displaced->step_copy == addr)) | |
1094 | return displaced->step_closure; | |
1095 | ||
1096 | return NULL; | |
1097 | } | |
1098 | ||
fc1cf338 | 1099 | /* Remove the displaced stepping state of process PID. */ |
237fc4c9 | 1100 | |
fc1cf338 PA |
1101 | static void |
1102 | remove_displaced_stepping_state (int pid) | |
1103 | { | |
1104 | struct displaced_step_inferior_state *it, **prev_next_p; | |
237fc4c9 | 1105 | |
fc1cf338 PA |
1106 | gdb_assert (pid != 0); |
1107 | ||
1108 | it = displaced_step_inferior_states; | |
1109 | prev_next_p = &displaced_step_inferior_states; | |
1110 | while (it) | |
1111 | { | |
1112 | if (it->pid == pid) | |
1113 | { | |
1114 | *prev_next_p = it->next; | |
1115 | xfree (it); | |
1116 | return; | |
1117 | } | |
1118 | ||
1119 | prev_next_p = &it->next; | |
1120 | it = *prev_next_p; | |
1121 | } | |
1122 | } | |
1123 | ||
1124 | static void | |
1125 | infrun_inferior_exit (struct inferior *inf) | |
1126 | { | |
1127 | remove_displaced_stepping_state (inf->pid); | |
1128 | } | |
237fc4c9 | 1129 | |
fff08868 HZ |
1130 | /* Enum strings for "set|show displaced-stepping". */ |
1131 | ||
1132 | static const char can_use_displaced_stepping_auto[] = "auto"; | |
1133 | static const char can_use_displaced_stepping_on[] = "on"; | |
1134 | static const char can_use_displaced_stepping_off[] = "off"; | |
1135 | static const char *can_use_displaced_stepping_enum[] = | |
1136 | { | |
1137 | can_use_displaced_stepping_auto, | |
1138 | can_use_displaced_stepping_on, | |
1139 | can_use_displaced_stepping_off, | |
1140 | NULL, | |
1141 | }; | |
1142 | ||
1143 | /* If ON, and the architecture supports it, GDB will use displaced | |
1144 | stepping to step over breakpoints. If OFF, or if the architecture | |
1145 | doesn't support it, GDB will instead use the traditional | |
1146 | hold-and-step approach. If AUTO (which is the default), GDB will | |
1147 | decide which technique to use to step over breakpoints depending on | |
1148 | which of all-stop or non-stop mode is active --- displaced stepping | |
1149 | in non-stop mode; hold-and-step in all-stop mode. */ | |
1150 | ||
1151 | static const char *can_use_displaced_stepping = | |
1152 | can_use_displaced_stepping_auto; | |
1153 | ||
237fc4c9 PA |
1154 | static void |
1155 | show_can_use_displaced_stepping (struct ui_file *file, int from_tty, | |
1156 | struct cmd_list_element *c, | |
1157 | const char *value) | |
1158 | { | |
fff08868 | 1159 | if (can_use_displaced_stepping == can_use_displaced_stepping_auto) |
3e43a32a MS |
1160 | fprintf_filtered (file, |
1161 | _("Debugger's willingness to use displaced stepping " | |
1162 | "to step over breakpoints is %s (currently %s).\n"), | |
fff08868 HZ |
1163 | value, non_stop ? "on" : "off"); |
1164 | else | |
3e43a32a MS |
1165 | fprintf_filtered (file, |
1166 | _("Debugger's willingness to use displaced stepping " | |
1167 | "to step over breakpoints is %s.\n"), value); | |
237fc4c9 PA |
1168 | } |
1169 | ||
fff08868 HZ |
1170 | /* Return non-zero if displaced stepping can/should be used to step |
1171 | over breakpoints. */ | |
1172 | ||
237fc4c9 PA |
1173 | static int |
1174 | use_displaced_stepping (struct gdbarch *gdbarch) | |
1175 | { | |
fff08868 HZ |
1176 | return (((can_use_displaced_stepping == can_use_displaced_stepping_auto |
1177 | && non_stop) | |
1178 | || can_use_displaced_stepping == can_use_displaced_stepping_on) | |
96429cc8 HZ |
1179 | && gdbarch_displaced_step_copy_insn_p (gdbarch) |
1180 | && !RECORD_IS_USED); | |
237fc4c9 PA |
1181 | } |
1182 | ||
1183 | /* Clean out any stray displaced stepping state. */ | |
1184 | static void | |
fc1cf338 | 1185 | displaced_step_clear (struct displaced_step_inferior_state *displaced) |
237fc4c9 PA |
1186 | { |
1187 | /* Indicate that there is no cleanup pending. */ | |
fc1cf338 | 1188 | displaced->step_ptid = null_ptid; |
237fc4c9 | 1189 | |
fc1cf338 | 1190 | if (displaced->step_closure) |
237fc4c9 | 1191 | { |
fc1cf338 PA |
1192 | gdbarch_displaced_step_free_closure (displaced->step_gdbarch, |
1193 | displaced->step_closure); | |
1194 | displaced->step_closure = NULL; | |
237fc4c9 PA |
1195 | } |
1196 | } | |
1197 | ||
1198 | static void | |
fc1cf338 | 1199 | displaced_step_clear_cleanup (void *arg) |
237fc4c9 | 1200 | { |
fc1cf338 PA |
1201 | struct displaced_step_inferior_state *state = arg; |
1202 | ||
1203 | displaced_step_clear (state); | |
237fc4c9 PA |
1204 | } |
1205 | ||
1206 | /* Dump LEN bytes at BUF in hex to FILE, followed by a newline. */ | |
1207 | void | |
1208 | displaced_step_dump_bytes (struct ui_file *file, | |
1209 | const gdb_byte *buf, | |
1210 | size_t len) | |
1211 | { | |
1212 | int i; | |
1213 | ||
1214 | for (i = 0; i < len; i++) | |
1215 | fprintf_unfiltered (file, "%02x ", buf[i]); | |
1216 | fputs_unfiltered ("\n", file); | |
1217 | } | |
1218 | ||
1219 | /* Prepare to single-step, using displaced stepping. | |
1220 | ||
1221 | Note that we cannot use displaced stepping when we have a signal to | |
1222 | deliver. If we have a signal to deliver and an instruction to step | |
1223 | over, then after the step, there will be no indication from the | |
1224 | target whether the thread entered a signal handler or ignored the | |
1225 | signal and stepped over the instruction successfully --- both cases | |
1226 | result in a simple SIGTRAP. In the first case we mustn't do a | |
1227 | fixup, and in the second case we must --- but we can't tell which. | |
1228 | Comments in the code for 'random signals' in handle_inferior_event | |
1229 | explain how we handle this case instead. | |
1230 | ||
1231 | Returns 1 if preparing was successful -- this thread is going to be | |
1232 | stepped now; or 0 if displaced stepping this thread got queued. */ | |
1233 | static int | |
1234 | displaced_step_prepare (ptid_t ptid) | |
1235 | { | |
ad53cd71 | 1236 | struct cleanup *old_cleanups, *ignore_cleanups; |
237fc4c9 PA |
1237 | struct regcache *regcache = get_thread_regcache (ptid); |
1238 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
1239 | CORE_ADDR original, copy; | |
1240 | ULONGEST len; | |
1241 | struct displaced_step_closure *closure; | |
fc1cf338 | 1242 | struct displaced_step_inferior_state *displaced; |
237fc4c9 PA |
1243 | |
1244 | /* We should never reach this function if the architecture does not | |
1245 | support displaced stepping. */ | |
1246 | gdb_assert (gdbarch_displaced_step_copy_insn_p (gdbarch)); | |
1247 | ||
fc1cf338 PA |
1248 | /* We have to displaced step one thread at a time, as we only have |
1249 | access to a single scratch space per inferior. */ | |
237fc4c9 | 1250 | |
fc1cf338 PA |
1251 | displaced = add_displaced_stepping_state (ptid_get_pid (ptid)); |
1252 | ||
1253 | if (!ptid_equal (displaced->step_ptid, null_ptid)) | |
237fc4c9 PA |
1254 | { |
1255 | /* Already waiting for a displaced step to finish. Defer this | |
1256 | request and place in queue. */ | |
1257 | struct displaced_step_request *req, *new_req; | |
1258 | ||
1259 | if (debug_displaced) | |
1260 | fprintf_unfiltered (gdb_stdlog, | |
1261 | "displaced: defering step of %s\n", | |
1262 | target_pid_to_str (ptid)); | |
1263 | ||
1264 | new_req = xmalloc (sizeof (*new_req)); | |
1265 | new_req->ptid = ptid; | |
1266 | new_req->next = NULL; | |
1267 | ||
fc1cf338 | 1268 | if (displaced->step_request_queue) |
237fc4c9 | 1269 | { |
fc1cf338 | 1270 | for (req = displaced->step_request_queue; |
237fc4c9 PA |
1271 | req && req->next; |
1272 | req = req->next) | |
1273 | ; | |
1274 | req->next = new_req; | |
1275 | } | |
1276 | else | |
fc1cf338 | 1277 | displaced->step_request_queue = new_req; |
237fc4c9 PA |
1278 | |
1279 | return 0; | |
1280 | } | |
1281 | else | |
1282 | { | |
1283 | if (debug_displaced) | |
1284 | fprintf_unfiltered (gdb_stdlog, | |
1285 | "displaced: stepping %s now\n", | |
1286 | target_pid_to_str (ptid)); | |
1287 | } | |
1288 | ||
fc1cf338 | 1289 | displaced_step_clear (displaced); |
237fc4c9 | 1290 | |
ad53cd71 PA |
1291 | old_cleanups = save_inferior_ptid (); |
1292 | inferior_ptid = ptid; | |
1293 | ||
515630c5 | 1294 | original = regcache_read_pc (regcache); |
237fc4c9 PA |
1295 | |
1296 | copy = gdbarch_displaced_step_location (gdbarch); | |
1297 | len = gdbarch_max_insn_length (gdbarch); | |
1298 | ||
1299 | /* Save the original contents of the copy area. */ | |
fc1cf338 | 1300 | displaced->step_saved_copy = xmalloc (len); |
ad53cd71 | 1301 | ignore_cleanups = make_cleanup (free_current_contents, |
fc1cf338 PA |
1302 | &displaced->step_saved_copy); |
1303 | read_memory (copy, displaced->step_saved_copy, len); | |
237fc4c9 PA |
1304 | if (debug_displaced) |
1305 | { | |
5af949e3 UW |
1306 | fprintf_unfiltered (gdb_stdlog, "displaced: saved %s: ", |
1307 | paddress (gdbarch, copy)); | |
fc1cf338 PA |
1308 | displaced_step_dump_bytes (gdb_stdlog, |
1309 | displaced->step_saved_copy, | |
1310 | len); | |
237fc4c9 PA |
1311 | }; |
1312 | ||
1313 | closure = gdbarch_displaced_step_copy_insn (gdbarch, | |
ad53cd71 | 1314 | original, copy, regcache); |
237fc4c9 PA |
1315 | |
1316 | /* We don't support the fully-simulated case at present. */ | |
1317 | gdb_assert (closure); | |
1318 | ||
9f5a595d UW |
1319 | /* Save the information we need to fix things up if the step |
1320 | succeeds. */ | |
fc1cf338 PA |
1321 | displaced->step_ptid = ptid; |
1322 | displaced->step_gdbarch = gdbarch; | |
1323 | displaced->step_closure = closure; | |
1324 | displaced->step_original = original; | |
1325 | displaced->step_copy = copy; | |
9f5a595d | 1326 | |
fc1cf338 | 1327 | make_cleanup (displaced_step_clear_cleanup, displaced); |
237fc4c9 PA |
1328 | |
1329 | /* Resume execution at the copy. */ | |
515630c5 | 1330 | regcache_write_pc (regcache, copy); |
237fc4c9 | 1331 | |
ad53cd71 PA |
1332 | discard_cleanups (ignore_cleanups); |
1333 | ||
1334 | do_cleanups (old_cleanups); | |
237fc4c9 PA |
1335 | |
1336 | if (debug_displaced) | |
5af949e3 UW |
1337 | fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n", |
1338 | paddress (gdbarch, copy)); | |
237fc4c9 | 1339 | |
237fc4c9 PA |
1340 | return 1; |
1341 | } | |
1342 | ||
237fc4c9 | 1343 | static void |
3e43a32a MS |
1344 | write_memory_ptid (ptid_t ptid, CORE_ADDR memaddr, |
1345 | const gdb_byte *myaddr, int len) | |
237fc4c9 PA |
1346 | { |
1347 | struct cleanup *ptid_cleanup = save_inferior_ptid (); | |
abbb1732 | 1348 | |
237fc4c9 PA |
1349 | inferior_ptid = ptid; |
1350 | write_memory (memaddr, myaddr, len); | |
1351 | do_cleanups (ptid_cleanup); | |
1352 | } | |
1353 | ||
1354 | static void | |
1355 | displaced_step_fixup (ptid_t event_ptid, enum target_signal signal) | |
1356 | { | |
1357 | struct cleanup *old_cleanups; | |
fc1cf338 PA |
1358 | struct displaced_step_inferior_state *displaced |
1359 | = get_displaced_stepping_state (ptid_get_pid (event_ptid)); | |
1360 | ||
1361 | /* Was any thread of this process doing a displaced step? */ | |
1362 | if (displaced == NULL) | |
1363 | return; | |
237fc4c9 PA |
1364 | |
1365 | /* Was this event for the pid we displaced? */ | |
fc1cf338 PA |
1366 | if (ptid_equal (displaced->step_ptid, null_ptid) |
1367 | || ! ptid_equal (displaced->step_ptid, event_ptid)) | |
237fc4c9 PA |
1368 | return; |
1369 | ||
fc1cf338 | 1370 | old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced); |
237fc4c9 PA |
1371 | |
1372 | /* Restore the contents of the copy area. */ | |
1373 | { | |
fc1cf338 | 1374 | ULONGEST len = gdbarch_max_insn_length (displaced->step_gdbarch); |
abbb1732 | 1375 | |
fc1cf338 PA |
1376 | write_memory_ptid (displaced->step_ptid, displaced->step_copy, |
1377 | displaced->step_saved_copy, len); | |
237fc4c9 | 1378 | if (debug_displaced) |
5af949e3 | 1379 | fprintf_unfiltered (gdb_stdlog, "displaced: restored %s\n", |
fc1cf338 PA |
1380 | paddress (displaced->step_gdbarch, |
1381 | displaced->step_copy)); | |
237fc4c9 PA |
1382 | } |
1383 | ||
1384 | /* Did the instruction complete successfully? */ | |
1385 | if (signal == TARGET_SIGNAL_TRAP) | |
1386 | { | |
1387 | /* Fix up the resulting state. */ | |
fc1cf338 PA |
1388 | gdbarch_displaced_step_fixup (displaced->step_gdbarch, |
1389 | displaced->step_closure, | |
1390 | displaced->step_original, | |
1391 | displaced->step_copy, | |
1392 | get_thread_regcache (displaced->step_ptid)); | |
237fc4c9 PA |
1393 | } |
1394 | else | |
1395 | { | |
1396 | /* Since the instruction didn't complete, all we can do is | |
1397 | relocate the PC. */ | |
515630c5 UW |
1398 | struct regcache *regcache = get_thread_regcache (event_ptid); |
1399 | CORE_ADDR pc = regcache_read_pc (regcache); | |
abbb1732 | 1400 | |
fc1cf338 | 1401 | pc = displaced->step_original + (pc - displaced->step_copy); |
515630c5 | 1402 | regcache_write_pc (regcache, pc); |
237fc4c9 PA |
1403 | } |
1404 | ||
1405 | do_cleanups (old_cleanups); | |
1406 | ||
fc1cf338 | 1407 | displaced->step_ptid = null_ptid; |
1c5cfe86 | 1408 | |
237fc4c9 | 1409 | /* Are there any pending displaced stepping requests? If so, run |
fc1cf338 PA |
1410 | one now. Leave the state object around, since we're likely to |
1411 | need it again soon. */ | |
1412 | while (displaced->step_request_queue) | |
237fc4c9 PA |
1413 | { |
1414 | struct displaced_step_request *head; | |
1415 | ptid_t ptid; | |
5af949e3 | 1416 | struct regcache *regcache; |
929dfd4f | 1417 | struct gdbarch *gdbarch; |
1c5cfe86 | 1418 | CORE_ADDR actual_pc; |
6c95b8df | 1419 | struct address_space *aspace; |
237fc4c9 | 1420 | |
fc1cf338 | 1421 | head = displaced->step_request_queue; |
237fc4c9 | 1422 | ptid = head->ptid; |
fc1cf338 | 1423 | displaced->step_request_queue = head->next; |
237fc4c9 PA |
1424 | xfree (head); |
1425 | ||
ad53cd71 PA |
1426 | context_switch (ptid); |
1427 | ||
5af949e3 UW |
1428 | regcache = get_thread_regcache (ptid); |
1429 | actual_pc = regcache_read_pc (regcache); | |
6c95b8df | 1430 | aspace = get_regcache_aspace (regcache); |
1c5cfe86 | 1431 | |
6c95b8df | 1432 | if (breakpoint_here_p (aspace, actual_pc)) |
ad53cd71 | 1433 | { |
1c5cfe86 PA |
1434 | if (debug_displaced) |
1435 | fprintf_unfiltered (gdb_stdlog, | |
1436 | "displaced: stepping queued %s now\n", | |
1437 | target_pid_to_str (ptid)); | |
1438 | ||
1439 | displaced_step_prepare (ptid); | |
1440 | ||
929dfd4f JB |
1441 | gdbarch = get_regcache_arch (regcache); |
1442 | ||
1c5cfe86 PA |
1443 | if (debug_displaced) |
1444 | { | |
929dfd4f | 1445 | CORE_ADDR actual_pc = regcache_read_pc (regcache); |
1c5cfe86 PA |
1446 | gdb_byte buf[4]; |
1447 | ||
5af949e3 UW |
1448 | fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", |
1449 | paddress (gdbarch, actual_pc)); | |
1c5cfe86 PA |
1450 | read_memory (actual_pc, buf, sizeof (buf)); |
1451 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); | |
1452 | } | |
1453 | ||
fc1cf338 PA |
1454 | if (gdbarch_displaced_step_hw_singlestep (gdbarch, |
1455 | displaced->step_closure)) | |
929dfd4f | 1456 | target_resume (ptid, 1, TARGET_SIGNAL_0); |
99e40580 UW |
1457 | else |
1458 | target_resume (ptid, 0, TARGET_SIGNAL_0); | |
1c5cfe86 PA |
1459 | |
1460 | /* Done, we're stepping a thread. */ | |
1461 | break; | |
ad53cd71 | 1462 | } |
1c5cfe86 PA |
1463 | else |
1464 | { | |
1465 | int step; | |
1466 | struct thread_info *tp = inferior_thread (); | |
1467 | ||
1468 | /* The breakpoint we were sitting under has since been | |
1469 | removed. */ | |
16c381f0 | 1470 | tp->control.trap_expected = 0; |
1c5cfe86 PA |
1471 | |
1472 | /* Go back to what we were trying to do. */ | |
1473 | step = currently_stepping (tp); | |
ad53cd71 | 1474 | |
1c5cfe86 | 1475 | if (debug_displaced) |
3e43a32a MS |
1476 | fprintf_unfiltered (gdb_stdlog, |
1477 | "breakpoint is gone %s: step(%d)\n", | |
1c5cfe86 PA |
1478 | target_pid_to_str (tp->ptid), step); |
1479 | ||
1480 | target_resume (ptid, step, TARGET_SIGNAL_0); | |
16c381f0 | 1481 | tp->suspend.stop_signal = TARGET_SIGNAL_0; |
1c5cfe86 PA |
1482 | |
1483 | /* This request was discarded. See if there's any other | |
1484 | thread waiting for its turn. */ | |
1485 | } | |
237fc4c9 PA |
1486 | } |
1487 | } | |
1488 | ||
5231c1fd PA |
1489 | /* Update global variables holding ptids to hold NEW_PTID if they were |
1490 | holding OLD_PTID. */ | |
1491 | static void | |
1492 | infrun_thread_ptid_changed (ptid_t old_ptid, ptid_t new_ptid) | |
1493 | { | |
1494 | struct displaced_step_request *it; | |
fc1cf338 | 1495 | struct displaced_step_inferior_state *displaced; |
5231c1fd PA |
1496 | |
1497 | if (ptid_equal (inferior_ptid, old_ptid)) | |
1498 | inferior_ptid = new_ptid; | |
1499 | ||
1500 | if (ptid_equal (singlestep_ptid, old_ptid)) | |
1501 | singlestep_ptid = new_ptid; | |
1502 | ||
5231c1fd PA |
1503 | if (ptid_equal (deferred_step_ptid, old_ptid)) |
1504 | deferred_step_ptid = new_ptid; | |
1505 | ||
fc1cf338 PA |
1506 | for (displaced = displaced_step_inferior_states; |
1507 | displaced; | |
1508 | displaced = displaced->next) | |
1509 | { | |
1510 | if (ptid_equal (displaced->step_ptid, old_ptid)) | |
1511 | displaced->step_ptid = new_ptid; | |
1512 | ||
1513 | for (it = displaced->step_request_queue; it; it = it->next) | |
1514 | if (ptid_equal (it->ptid, old_ptid)) | |
1515 | it->ptid = new_ptid; | |
1516 | } | |
5231c1fd PA |
1517 | } |
1518 | ||
237fc4c9 PA |
1519 | \f |
1520 | /* Resuming. */ | |
c906108c SS |
1521 | |
1522 | /* Things to clean up if we QUIT out of resume (). */ | |
c906108c | 1523 | static void |
74b7792f | 1524 | resume_cleanups (void *ignore) |
c906108c SS |
1525 | { |
1526 | normal_stop (); | |
1527 | } | |
1528 | ||
53904c9e AC |
1529 | static const char schedlock_off[] = "off"; |
1530 | static const char schedlock_on[] = "on"; | |
1531 | static const char schedlock_step[] = "step"; | |
488f131b | 1532 | static const char *scheduler_enums[] = { |
ef346e04 AC |
1533 | schedlock_off, |
1534 | schedlock_on, | |
1535 | schedlock_step, | |
1536 | NULL | |
1537 | }; | |
920d2a44 AC |
1538 | static const char *scheduler_mode = schedlock_off; |
1539 | static void | |
1540 | show_scheduler_mode (struct ui_file *file, int from_tty, | |
1541 | struct cmd_list_element *c, const char *value) | |
1542 | { | |
3e43a32a MS |
1543 | fprintf_filtered (file, |
1544 | _("Mode for locking scheduler " | |
1545 | "during execution is \"%s\".\n"), | |
920d2a44 AC |
1546 | value); |
1547 | } | |
c906108c SS |
1548 | |
1549 | static void | |
96baa820 | 1550 | set_schedlock_func (char *args, int from_tty, struct cmd_list_element *c) |
c906108c | 1551 | { |
eefe576e AC |
1552 | if (!target_can_lock_scheduler) |
1553 | { | |
1554 | scheduler_mode = schedlock_off; | |
1555 | error (_("Target '%s' cannot support this command."), target_shortname); | |
1556 | } | |
c906108c SS |
1557 | } |
1558 | ||
d4db2f36 PA |
1559 | /* True if execution commands resume all threads of all processes by |
1560 | default; otherwise, resume only threads of the current inferior | |
1561 | process. */ | |
1562 | int sched_multi = 0; | |
1563 | ||
2facfe5c DD |
1564 | /* Try to setup for software single stepping over the specified location. |
1565 | Return 1 if target_resume() should use hardware single step. | |
1566 | ||
1567 | GDBARCH the current gdbarch. | |
1568 | PC the location to step over. */ | |
1569 | ||
1570 | static int | |
1571 | maybe_software_singlestep (struct gdbarch *gdbarch, CORE_ADDR pc) | |
1572 | { | |
1573 | int hw_step = 1; | |
1574 | ||
f02253f1 HZ |
1575 | if (execution_direction == EXEC_FORWARD |
1576 | && gdbarch_software_single_step_p (gdbarch) | |
99e40580 | 1577 | && gdbarch_software_single_step (gdbarch, get_current_frame ())) |
2facfe5c | 1578 | { |
99e40580 UW |
1579 | hw_step = 0; |
1580 | /* Do not pull these breakpoints until after a `wait' in | |
1777feb0 | 1581 | `wait_for_inferior'. */ |
99e40580 UW |
1582 | singlestep_breakpoints_inserted_p = 1; |
1583 | singlestep_ptid = inferior_ptid; | |
1584 | singlestep_pc = pc; | |
2facfe5c DD |
1585 | } |
1586 | return hw_step; | |
1587 | } | |
c906108c SS |
1588 | |
1589 | /* Resume the inferior, but allow a QUIT. This is useful if the user | |
1590 | wants to interrupt some lengthy single-stepping operation | |
1591 | (for child processes, the SIGINT goes to the inferior, and so | |
1592 | we get a SIGINT random_signal, but for remote debugging and perhaps | |
1593 | other targets, that's not true). | |
1594 | ||
1595 | STEP nonzero if we should step (zero to continue instead). | |
1596 | SIG is the signal to give the inferior (zero for none). */ | |
1597 | void | |
96baa820 | 1598 | resume (int step, enum target_signal sig) |
c906108c SS |
1599 | { |
1600 | int should_resume = 1; | |
74b7792f | 1601 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); |
515630c5 UW |
1602 | struct regcache *regcache = get_current_regcache (); |
1603 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
4e1c45ea | 1604 | struct thread_info *tp = inferior_thread (); |
515630c5 | 1605 | CORE_ADDR pc = regcache_read_pc (regcache); |
6c95b8df | 1606 | struct address_space *aspace = get_regcache_aspace (regcache); |
c7e8a53c | 1607 | |
c906108c SS |
1608 | QUIT; |
1609 | ||
74609e71 YQ |
1610 | if (current_inferior ()->waiting_for_vfork_done) |
1611 | { | |
48f9886d PA |
1612 | /* Don't try to single-step a vfork parent that is waiting for |
1613 | the child to get out of the shared memory region (by exec'ing | |
1614 | or exiting). This is particularly important on software | |
1615 | single-step archs, as the child process would trip on the | |
1616 | software single step breakpoint inserted for the parent | |
1617 | process. Since the parent will not actually execute any | |
1618 | instruction until the child is out of the shared region (such | |
1619 | are vfork's semantics), it is safe to simply continue it. | |
1620 | Eventually, we'll see a TARGET_WAITKIND_VFORK_DONE event for | |
1621 | the parent, and tell it to `keep_going', which automatically | |
1622 | re-sets it stepping. */ | |
74609e71 YQ |
1623 | if (debug_infrun) |
1624 | fprintf_unfiltered (gdb_stdlog, | |
1625 | "infrun: resume : clear step\n"); | |
1626 | step = 0; | |
1627 | } | |
1628 | ||
527159b7 | 1629 | if (debug_infrun) |
237fc4c9 PA |
1630 | fprintf_unfiltered (gdb_stdlog, |
1631 | "infrun: resume (step=%d, signal=%d), " | |
4e1c45ea | 1632 | "trap_expected=%d\n", |
16c381f0 | 1633 | step, sig, tp->control.trap_expected); |
c906108c | 1634 | |
c2c6d25f JM |
1635 | /* Normally, by the time we reach `resume', the breakpoints are either |
1636 | removed or inserted, as appropriate. The exception is if we're sitting | |
1637 | at a permanent breakpoint; we need to step over it, but permanent | |
1638 | breakpoints can't be removed. So we have to test for it here. */ | |
6c95b8df | 1639 | if (breakpoint_here_p (aspace, pc) == permanent_breakpoint_here) |
6d350bb5 | 1640 | { |
515630c5 UW |
1641 | if (gdbarch_skip_permanent_breakpoint_p (gdbarch)) |
1642 | gdbarch_skip_permanent_breakpoint (gdbarch, regcache); | |
6d350bb5 | 1643 | else |
ac74f770 MS |
1644 | error (_("\ |
1645 | The program is stopped at a permanent breakpoint, but GDB does not know\n\ | |
1646 | how to step past a permanent breakpoint on this architecture. Try using\n\ | |
1647 | a command like `return' or `jump' to continue execution.")); | |
6d350bb5 | 1648 | } |
c2c6d25f | 1649 | |
237fc4c9 PA |
1650 | /* If enabled, step over breakpoints by executing a copy of the |
1651 | instruction at a different address. | |
1652 | ||
1653 | We can't use displaced stepping when we have a signal to deliver; | |
1654 | the comments for displaced_step_prepare explain why. The | |
1655 | comments in the handle_inferior event for dealing with 'random | |
74609e71 YQ |
1656 | signals' explain what we do instead. |
1657 | ||
1658 | We can't use displaced stepping when we are waiting for vfork_done | |
1659 | event, displaced stepping breaks the vfork child similarly as single | |
1660 | step software breakpoint. */ | |
515630c5 | 1661 | if (use_displaced_stepping (gdbarch) |
16c381f0 | 1662 | && (tp->control.trap_expected |
929dfd4f | 1663 | || (step && gdbarch_software_single_step_p (gdbarch))) |
74609e71 YQ |
1664 | && sig == TARGET_SIGNAL_0 |
1665 | && !current_inferior ()->waiting_for_vfork_done) | |
237fc4c9 | 1666 | { |
fc1cf338 PA |
1667 | struct displaced_step_inferior_state *displaced; |
1668 | ||
237fc4c9 | 1669 | if (!displaced_step_prepare (inferior_ptid)) |
d56b7306 VP |
1670 | { |
1671 | /* Got placed in displaced stepping queue. Will be resumed | |
1672 | later when all the currently queued displaced stepping | |
7f7efbd9 VP |
1673 | requests finish. The thread is not executing at this point, |
1674 | and the call to set_executing will be made later. But we | |
1675 | need to call set_running here, since from frontend point of view, | |
1676 | the thread is running. */ | |
1677 | set_running (inferior_ptid, 1); | |
d56b7306 VP |
1678 | discard_cleanups (old_cleanups); |
1679 | return; | |
1680 | } | |
99e40580 | 1681 | |
fc1cf338 PA |
1682 | displaced = get_displaced_stepping_state (ptid_get_pid (inferior_ptid)); |
1683 | step = gdbarch_displaced_step_hw_singlestep (gdbarch, | |
1684 | displaced->step_closure); | |
237fc4c9 PA |
1685 | } |
1686 | ||
2facfe5c | 1687 | /* Do we need to do it the hard way, w/temp breakpoints? */ |
99e40580 | 1688 | else if (step) |
2facfe5c | 1689 | step = maybe_software_singlestep (gdbarch, pc); |
c906108c | 1690 | |
c906108c SS |
1691 | if (should_resume) |
1692 | { | |
39f77062 | 1693 | ptid_t resume_ptid; |
dfcd3bfb | 1694 | |
cd76b0b7 VP |
1695 | /* If STEP is set, it's a request to use hardware stepping |
1696 | facilities. But in that case, we should never | |
1697 | use singlestep breakpoint. */ | |
1698 | gdb_assert (!(singlestep_breakpoints_inserted_p && step)); | |
1699 | ||
d4db2f36 PA |
1700 | /* Decide the set of threads to ask the target to resume. Start |
1701 | by assuming everything will be resumed, than narrow the set | |
1702 | by applying increasingly restricting conditions. */ | |
1703 | ||
1704 | /* By default, resume all threads of all processes. */ | |
1705 | resume_ptid = RESUME_ALL; | |
1706 | ||
1707 | /* Maybe resume only all threads of the current process. */ | |
1708 | if (!sched_multi && target_supports_multi_process ()) | |
1709 | { | |
1710 | resume_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid)); | |
1711 | } | |
1712 | ||
1713 | /* Maybe resume a single thread after all. */ | |
cd76b0b7 VP |
1714 | if (singlestep_breakpoints_inserted_p |
1715 | && stepping_past_singlestep_breakpoint) | |
c906108c | 1716 | { |
cd76b0b7 VP |
1717 | /* The situation here is as follows. In thread T1 we wanted to |
1718 | single-step. Lacking hardware single-stepping we've | |
1719 | set breakpoint at the PC of the next instruction -- call it | |
1720 | P. After resuming, we've hit that breakpoint in thread T2. | |
1721 | Now we've removed original breakpoint, inserted breakpoint | |
1722 | at P+1, and try to step to advance T2 past breakpoint. | |
1723 | We need to step only T2, as if T1 is allowed to freely run, | |
1724 | it can run past P, and if other threads are allowed to run, | |
1725 | they can hit breakpoint at P+1, and nested hits of single-step | |
1726 | breakpoints is not something we'd want -- that's complicated | |
1727 | to support, and has no value. */ | |
1728 | resume_ptid = inferior_ptid; | |
1729 | } | |
d4db2f36 | 1730 | else if ((step || singlestep_breakpoints_inserted_p) |
16c381f0 | 1731 | && tp->control.trap_expected) |
cd76b0b7 | 1732 | { |
74960c60 VP |
1733 | /* We're allowing a thread to run past a breakpoint it has |
1734 | hit, by single-stepping the thread with the breakpoint | |
1735 | removed. In which case, we need to single-step only this | |
1736 | thread, and keep others stopped, as they can miss this | |
1737 | breakpoint if allowed to run. | |
1738 | ||
1739 | The current code actually removes all breakpoints when | |
1740 | doing this, not just the one being stepped over, so if we | |
1741 | let other threads run, we can actually miss any | |
1742 | breakpoint, not just the one at PC. */ | |
ef5cf84e | 1743 | resume_ptid = inferior_ptid; |
c906108c | 1744 | } |
d4db2f36 | 1745 | else if (non_stop) |
94cc34af PA |
1746 | { |
1747 | /* With non-stop mode on, threads are always handled | |
1748 | individually. */ | |
1749 | resume_ptid = inferior_ptid; | |
1750 | } | |
1751 | else if ((scheduler_mode == schedlock_on) | |
1752 | || (scheduler_mode == schedlock_step | |
1753 | && (step || singlestep_breakpoints_inserted_p))) | |
c906108c | 1754 | { |
1777feb0 | 1755 | /* User-settable 'scheduler' mode requires solo thread resume. */ |
488f131b | 1756 | resume_ptid = inferior_ptid; |
c906108c | 1757 | } |
ef5cf84e | 1758 | |
515630c5 | 1759 | if (gdbarch_cannot_step_breakpoint (gdbarch)) |
c4ed33b9 AC |
1760 | { |
1761 | /* Most targets can step a breakpoint instruction, thus | |
1762 | executing it normally. But if this one cannot, just | |
1763 | continue and we will hit it anyway. */ | |
6c95b8df | 1764 | if (step && breakpoint_inserted_here_p (aspace, pc)) |
c4ed33b9 AC |
1765 | step = 0; |
1766 | } | |
237fc4c9 PA |
1767 | |
1768 | if (debug_displaced | |
515630c5 | 1769 | && use_displaced_stepping (gdbarch) |
16c381f0 | 1770 | && tp->control.trap_expected) |
237fc4c9 | 1771 | { |
515630c5 | 1772 | struct regcache *resume_regcache = get_thread_regcache (resume_ptid); |
5af949e3 | 1773 | struct gdbarch *resume_gdbarch = get_regcache_arch (resume_regcache); |
515630c5 | 1774 | CORE_ADDR actual_pc = regcache_read_pc (resume_regcache); |
237fc4c9 PA |
1775 | gdb_byte buf[4]; |
1776 | ||
5af949e3 UW |
1777 | fprintf_unfiltered (gdb_stdlog, "displaced: run %s: ", |
1778 | paddress (resume_gdbarch, actual_pc)); | |
237fc4c9 PA |
1779 | read_memory (actual_pc, buf, sizeof (buf)); |
1780 | displaced_step_dump_bytes (gdb_stdlog, buf, sizeof (buf)); | |
1781 | } | |
1782 | ||
e58b0e63 PA |
1783 | /* Install inferior's terminal modes. */ |
1784 | target_terminal_inferior (); | |
1785 | ||
2020b7ab PA |
1786 | /* Avoid confusing the next resume, if the next stop/resume |
1787 | happens to apply to another thread. */ | |
16c381f0 | 1788 | tp->suspend.stop_signal = TARGET_SIGNAL_0; |
607cecd2 PA |
1789 | |
1790 | target_resume (resume_ptid, step, sig); | |
c906108c SS |
1791 | } |
1792 | ||
1793 | discard_cleanups (old_cleanups); | |
1794 | } | |
1795 | \f | |
237fc4c9 | 1796 | /* Proceeding. */ |
c906108c SS |
1797 | |
1798 | /* Clear out all variables saying what to do when inferior is continued. | |
1799 | First do this, then set the ones you want, then call `proceed'. */ | |
1800 | ||
a7212384 UW |
1801 | static void |
1802 | clear_proceed_status_thread (struct thread_info *tp) | |
c906108c | 1803 | { |
a7212384 UW |
1804 | if (debug_infrun) |
1805 | fprintf_unfiltered (gdb_stdlog, | |
1806 | "infrun: clear_proceed_status_thread (%s)\n", | |
1807 | target_pid_to_str (tp->ptid)); | |
d6b48e9c | 1808 | |
16c381f0 JK |
1809 | tp->control.trap_expected = 0; |
1810 | tp->control.step_range_start = 0; | |
1811 | tp->control.step_range_end = 0; | |
1812 | tp->control.step_frame_id = null_frame_id; | |
1813 | tp->control.step_stack_frame_id = null_frame_id; | |
1814 | tp->control.step_over_calls = STEP_OVER_UNDEBUGGABLE; | |
a7212384 | 1815 | tp->stop_requested = 0; |
4e1c45ea | 1816 | |
16c381f0 | 1817 | tp->control.stop_step = 0; |
32400beb | 1818 | |
16c381f0 | 1819 | tp->control.proceed_to_finish = 0; |
414c69f7 | 1820 | |
a7212384 | 1821 | /* Discard any remaining commands or status from previous stop. */ |
16c381f0 | 1822 | bpstat_clear (&tp->control.stop_bpstat); |
a7212384 | 1823 | } |
32400beb | 1824 | |
a7212384 UW |
1825 | static int |
1826 | clear_proceed_status_callback (struct thread_info *tp, void *data) | |
1827 | { | |
1828 | if (is_exited (tp->ptid)) | |
1829 | return 0; | |
d6b48e9c | 1830 | |
a7212384 UW |
1831 | clear_proceed_status_thread (tp); |
1832 | return 0; | |
1833 | } | |
1834 | ||
1835 | void | |
1836 | clear_proceed_status (void) | |
1837 | { | |
6c95b8df PA |
1838 | if (!non_stop) |
1839 | { | |
1840 | /* In all-stop mode, delete the per-thread status of all | |
1841 | threads, even if inferior_ptid is null_ptid, there may be | |
1842 | threads on the list. E.g., we may be launching a new | |
1843 | process, while selecting the executable. */ | |
1844 | iterate_over_threads (clear_proceed_status_callback, NULL); | |
1845 | } | |
1846 | ||
a7212384 UW |
1847 | if (!ptid_equal (inferior_ptid, null_ptid)) |
1848 | { | |
1849 | struct inferior *inferior; | |
1850 | ||
1851 | if (non_stop) | |
1852 | { | |
6c95b8df PA |
1853 | /* If in non-stop mode, only delete the per-thread status of |
1854 | the current thread. */ | |
a7212384 UW |
1855 | clear_proceed_status_thread (inferior_thread ()); |
1856 | } | |
6c95b8df | 1857 | |
d6b48e9c | 1858 | inferior = current_inferior (); |
16c381f0 | 1859 | inferior->control.stop_soon = NO_STOP_QUIETLY; |
4e1c45ea PA |
1860 | } |
1861 | ||
c906108c | 1862 | stop_after_trap = 0; |
f3b1572e PA |
1863 | |
1864 | observer_notify_about_to_proceed (); | |
c906108c | 1865 | |
d5c31457 UW |
1866 | if (stop_registers) |
1867 | { | |
1868 | regcache_xfree (stop_registers); | |
1869 | stop_registers = NULL; | |
1870 | } | |
c906108c SS |
1871 | } |
1872 | ||
5a437975 DE |
1873 | /* Check the current thread against the thread that reported the most recent |
1874 | event. If a step-over is required return TRUE and set the current thread | |
1875 | to the old thread. Otherwise return FALSE. | |
1876 | ||
1777feb0 | 1877 | This should be suitable for any targets that support threads. */ |
ea67f13b DJ |
1878 | |
1879 | static int | |
6a6b96b9 | 1880 | prepare_to_proceed (int step) |
ea67f13b DJ |
1881 | { |
1882 | ptid_t wait_ptid; | |
1883 | struct target_waitstatus wait_status; | |
5a437975 DE |
1884 | int schedlock_enabled; |
1885 | ||
1886 | /* With non-stop mode on, threads are always handled individually. */ | |
1887 | gdb_assert (! non_stop); | |
ea67f13b DJ |
1888 | |
1889 | /* Get the last target status returned by target_wait(). */ | |
1890 | get_last_target_status (&wait_ptid, &wait_status); | |
1891 | ||
6a6b96b9 | 1892 | /* Make sure we were stopped at a breakpoint. */ |
ea67f13b | 1893 | if (wait_status.kind != TARGET_WAITKIND_STOPPED |
2b009048 DJ |
1894 | || (wait_status.value.sig != TARGET_SIGNAL_TRAP |
1895 | && wait_status.value.sig != TARGET_SIGNAL_ILL | |
1896 | && wait_status.value.sig != TARGET_SIGNAL_SEGV | |
1897 | && wait_status.value.sig != TARGET_SIGNAL_EMT)) | |
ea67f13b DJ |
1898 | { |
1899 | return 0; | |
1900 | } | |
1901 | ||
5a437975 DE |
1902 | schedlock_enabled = (scheduler_mode == schedlock_on |
1903 | || (scheduler_mode == schedlock_step | |
1904 | && step)); | |
1905 | ||
d4db2f36 PA |
1906 | /* Don't switch over to WAIT_PTID if scheduler locking is on. */ |
1907 | if (schedlock_enabled) | |
1908 | return 0; | |
1909 | ||
1910 | /* Don't switch over if we're about to resume some other process | |
1911 | other than WAIT_PTID's, and schedule-multiple is off. */ | |
1912 | if (!sched_multi | |
1913 | && ptid_get_pid (wait_ptid) != ptid_get_pid (inferior_ptid)) | |
1914 | return 0; | |
1915 | ||
6a6b96b9 | 1916 | /* Switched over from WAIT_PID. */ |
ea67f13b | 1917 | if (!ptid_equal (wait_ptid, minus_one_ptid) |
d4db2f36 | 1918 | && !ptid_equal (inferior_ptid, wait_ptid)) |
ea67f13b | 1919 | { |
515630c5 UW |
1920 | struct regcache *regcache = get_thread_regcache (wait_ptid); |
1921 | ||
6c95b8df PA |
1922 | if (breakpoint_here_p (get_regcache_aspace (regcache), |
1923 | regcache_read_pc (regcache))) | |
ea67f13b | 1924 | { |
515630c5 UW |
1925 | /* If stepping, remember current thread to switch back to. */ |
1926 | if (step) | |
1927 | deferred_step_ptid = inferior_ptid; | |
ea67f13b | 1928 | |
515630c5 UW |
1929 | /* Switch back to WAIT_PID thread. */ |
1930 | switch_to_thread (wait_ptid); | |
6a6b96b9 | 1931 | |
515630c5 UW |
1932 | /* We return 1 to indicate that there is a breakpoint here, |
1933 | so we need to step over it before continuing to avoid | |
1777feb0 | 1934 | hitting it straight away. */ |
515630c5 UW |
1935 | return 1; |
1936 | } | |
ea67f13b DJ |
1937 | } |
1938 | ||
1939 | return 0; | |
ea67f13b | 1940 | } |
e4846b08 | 1941 | |
c906108c SS |
1942 | /* Basic routine for continuing the program in various fashions. |
1943 | ||
1944 | ADDR is the address to resume at, or -1 for resume where stopped. | |
1945 | SIGGNAL is the signal to give it, or 0 for none, | |
c5aa993b | 1946 | or -1 for act according to how it stopped. |
c906108c | 1947 | STEP is nonzero if should trap after one instruction. |
c5aa993b JM |
1948 | -1 means return after that and print nothing. |
1949 | You should probably set various step_... variables | |
1950 | before calling here, if you are stepping. | |
c906108c SS |
1951 | |
1952 | You should call clear_proceed_status before calling proceed. */ | |
1953 | ||
1954 | void | |
96baa820 | 1955 | proceed (CORE_ADDR addr, enum target_signal siggnal, int step) |
c906108c | 1956 | { |
e58b0e63 PA |
1957 | struct regcache *regcache; |
1958 | struct gdbarch *gdbarch; | |
4e1c45ea | 1959 | struct thread_info *tp; |
e58b0e63 | 1960 | CORE_ADDR pc; |
6c95b8df | 1961 | struct address_space *aspace; |
c906108c SS |
1962 | int oneproc = 0; |
1963 | ||
e58b0e63 PA |
1964 | /* If we're stopped at a fork/vfork, follow the branch set by the |
1965 | "set follow-fork-mode" command; otherwise, we'll just proceed | |
1966 | resuming the current thread. */ | |
1967 | if (!follow_fork ()) | |
1968 | { | |
1969 | /* The target for some reason decided not to resume. */ | |
1970 | normal_stop (); | |
1971 | return; | |
1972 | } | |
1973 | ||
1974 | regcache = get_current_regcache (); | |
1975 | gdbarch = get_regcache_arch (regcache); | |
6c95b8df | 1976 | aspace = get_regcache_aspace (regcache); |
e58b0e63 PA |
1977 | pc = regcache_read_pc (regcache); |
1978 | ||
c906108c | 1979 | if (step > 0) |
515630c5 | 1980 | step_start_function = find_pc_function (pc); |
c906108c SS |
1981 | if (step < 0) |
1982 | stop_after_trap = 1; | |
1983 | ||
2acceee2 | 1984 | if (addr == (CORE_ADDR) -1) |
c906108c | 1985 | { |
6c95b8df | 1986 | if (pc == stop_pc && breakpoint_here_p (aspace, pc) |
b2175913 | 1987 | && execution_direction != EXEC_REVERSE) |
3352ef37 AC |
1988 | /* There is a breakpoint at the address we will resume at, |
1989 | step one instruction before inserting breakpoints so that | |
1990 | we do not stop right away (and report a second hit at this | |
b2175913 MS |
1991 | breakpoint). |
1992 | ||
1993 | Note, we don't do this in reverse, because we won't | |
1994 | actually be executing the breakpoint insn anyway. | |
1995 | We'll be (un-)executing the previous instruction. */ | |
1996 | ||
c906108c | 1997 | oneproc = 1; |
515630c5 UW |
1998 | else if (gdbarch_single_step_through_delay_p (gdbarch) |
1999 | && gdbarch_single_step_through_delay (gdbarch, | |
2000 | get_current_frame ())) | |
3352ef37 AC |
2001 | /* We stepped onto an instruction that needs to be stepped |
2002 | again before re-inserting the breakpoint, do so. */ | |
c906108c SS |
2003 | oneproc = 1; |
2004 | } | |
2005 | else | |
2006 | { | |
515630c5 | 2007 | regcache_write_pc (regcache, addr); |
c906108c SS |
2008 | } |
2009 | ||
527159b7 | 2010 | if (debug_infrun) |
8a9de0e4 | 2011 | fprintf_unfiltered (gdb_stdlog, |
5af949e3 UW |
2012 | "infrun: proceed (addr=%s, signal=%d, step=%d)\n", |
2013 | paddress (gdbarch, addr), siggnal, step); | |
527159b7 | 2014 | |
94cc34af PA |
2015 | if (non_stop) |
2016 | /* In non-stop, each thread is handled individually. The context | |
2017 | must already be set to the right thread here. */ | |
2018 | ; | |
2019 | else | |
2020 | { | |
2021 | /* In a multi-threaded task we may select another thread and | |
2022 | then continue or step. | |
c906108c | 2023 | |
94cc34af PA |
2024 | But if the old thread was stopped at a breakpoint, it will |
2025 | immediately cause another breakpoint stop without any | |
2026 | execution (i.e. it will report a breakpoint hit incorrectly). | |
2027 | So we must step over it first. | |
c906108c | 2028 | |
94cc34af PA |
2029 | prepare_to_proceed checks the current thread against the |
2030 | thread that reported the most recent event. If a step-over | |
2031 | is required it returns TRUE and sets the current thread to | |
1777feb0 | 2032 | the old thread. */ |
94cc34af PA |
2033 | if (prepare_to_proceed (step)) |
2034 | oneproc = 1; | |
2035 | } | |
c906108c | 2036 | |
4e1c45ea PA |
2037 | /* prepare_to_proceed may change the current thread. */ |
2038 | tp = inferior_thread (); | |
2039 | ||
c906108c | 2040 | if (oneproc) |
74960c60 | 2041 | { |
16c381f0 | 2042 | tp->control.trap_expected = 1; |
237fc4c9 PA |
2043 | /* If displaced stepping is enabled, we can step over the |
2044 | breakpoint without hitting it, so leave all breakpoints | |
2045 | inserted. Otherwise we need to disable all breakpoints, step | |
2046 | one instruction, and then re-add them when that step is | |
2047 | finished. */ | |
515630c5 | 2048 | if (!use_displaced_stepping (gdbarch)) |
237fc4c9 | 2049 | remove_breakpoints (); |
74960c60 | 2050 | } |
237fc4c9 PA |
2051 | |
2052 | /* We can insert breakpoints if we're not trying to step over one, | |
2053 | or if we are stepping over one but we're using displaced stepping | |
2054 | to do so. */ | |
16c381f0 | 2055 | if (! tp->control.trap_expected || use_displaced_stepping (gdbarch)) |
c36b740a | 2056 | insert_breakpoints (); |
c906108c | 2057 | |
2020b7ab PA |
2058 | if (!non_stop) |
2059 | { | |
2060 | /* Pass the last stop signal to the thread we're resuming, | |
2061 | irrespective of whether the current thread is the thread that | |
2062 | got the last event or not. This was historically GDB's | |
2063 | behaviour before keeping a stop_signal per thread. */ | |
2064 | ||
2065 | struct thread_info *last_thread; | |
2066 | ptid_t last_ptid; | |
2067 | struct target_waitstatus last_status; | |
2068 | ||
2069 | get_last_target_status (&last_ptid, &last_status); | |
2070 | if (!ptid_equal (inferior_ptid, last_ptid) | |
2071 | && !ptid_equal (last_ptid, null_ptid) | |
2072 | && !ptid_equal (last_ptid, minus_one_ptid)) | |
2073 | { | |
e09875d4 | 2074 | last_thread = find_thread_ptid (last_ptid); |
2020b7ab PA |
2075 | if (last_thread) |
2076 | { | |
16c381f0 JK |
2077 | tp->suspend.stop_signal = last_thread->suspend.stop_signal; |
2078 | last_thread->suspend.stop_signal = TARGET_SIGNAL_0; | |
2020b7ab PA |
2079 | } |
2080 | } | |
2081 | } | |
2082 | ||
c906108c | 2083 | if (siggnal != TARGET_SIGNAL_DEFAULT) |
16c381f0 | 2084 | tp->suspend.stop_signal = siggnal; |
c906108c SS |
2085 | /* If this signal should not be seen by program, |
2086 | give it zero. Used for debugging signals. */ | |
16c381f0 JK |
2087 | else if (!signal_program[tp->suspend.stop_signal]) |
2088 | tp->suspend.stop_signal = TARGET_SIGNAL_0; | |
c906108c SS |
2089 | |
2090 | annotate_starting (); | |
2091 | ||
2092 | /* Make sure that output from GDB appears before output from the | |
2093 | inferior. */ | |
2094 | gdb_flush (gdb_stdout); | |
2095 | ||
e4846b08 JJ |
2096 | /* Refresh prev_pc value just prior to resuming. This used to be |
2097 | done in stop_stepping, however, setting prev_pc there did not handle | |
2098 | scenarios such as inferior function calls or returning from | |
2099 | a function via the return command. In those cases, the prev_pc | |
2100 | value was not set properly for subsequent commands. The prev_pc value | |
2101 | is used to initialize the starting line number in the ecs. With an | |
2102 | invalid value, the gdb next command ends up stopping at the position | |
2103 | represented by the next line table entry past our start position. | |
2104 | On platforms that generate one line table entry per line, this | |
2105 | is not a problem. However, on the ia64, the compiler generates | |
2106 | extraneous line table entries that do not increase the line number. | |
2107 | When we issue the gdb next command on the ia64 after an inferior call | |
2108 | or a return command, we often end up a few instructions forward, still | |
2109 | within the original line we started. | |
2110 | ||
d5cd6034 JB |
2111 | An attempt was made to refresh the prev_pc at the same time the |
2112 | execution_control_state is initialized (for instance, just before | |
2113 | waiting for an inferior event). But this approach did not work | |
2114 | because of platforms that use ptrace, where the pc register cannot | |
2115 | be read unless the inferior is stopped. At that point, we are not | |
2116 | guaranteed the inferior is stopped and so the regcache_read_pc() call | |
2117 | can fail. Setting the prev_pc value here ensures the value is updated | |
2118 | correctly when the inferior is stopped. */ | |
4e1c45ea | 2119 | tp->prev_pc = regcache_read_pc (get_current_regcache ()); |
e4846b08 | 2120 | |
59f0d5d9 | 2121 | /* Fill in with reasonable starting values. */ |
4e1c45ea | 2122 | init_thread_stepping_state (tp); |
59f0d5d9 | 2123 | |
59f0d5d9 PA |
2124 | /* Reset to normal state. */ |
2125 | init_infwait_state (); | |
2126 | ||
c906108c | 2127 | /* Resume inferior. */ |
16c381f0 | 2128 | resume (oneproc || step || bpstat_should_step (), tp->suspend.stop_signal); |
c906108c SS |
2129 | |
2130 | /* Wait for it to stop (if not standalone) | |
2131 | and in any case decode why it stopped, and act accordingly. */ | |
43ff13b4 | 2132 | /* Do this only if we are not using the event loop, or if the target |
1777feb0 | 2133 | does not support asynchronous execution. */ |
362646f5 | 2134 | if (!target_can_async_p ()) |
43ff13b4 | 2135 | { |
ae123ec6 | 2136 | wait_for_inferior (0); |
43ff13b4 JM |
2137 | normal_stop (); |
2138 | } | |
c906108c | 2139 | } |
c906108c SS |
2140 | \f |
2141 | ||
2142 | /* Start remote-debugging of a machine over a serial link. */ | |
96baa820 | 2143 | |
c906108c | 2144 | void |
8621d6a9 | 2145 | start_remote (int from_tty) |
c906108c | 2146 | { |
d6b48e9c | 2147 | struct inferior *inferior; |
d6b48e9c | 2148 | |
abbb1732 | 2149 | init_wait_for_inferior (); |
d6b48e9c | 2150 | inferior = current_inferior (); |
16c381f0 | 2151 | inferior->control.stop_soon = STOP_QUIETLY_REMOTE; |
43ff13b4 | 2152 | |
1777feb0 | 2153 | /* Always go on waiting for the target, regardless of the mode. */ |
6426a772 | 2154 | /* FIXME: cagney/1999-09-23: At present it isn't possible to |
7e73cedf | 2155 | indicate to wait_for_inferior that a target should timeout if |
6426a772 JM |
2156 | nothing is returned (instead of just blocking). Because of this, |
2157 | targets expecting an immediate response need to, internally, set | |
2158 | things up so that the target_wait() is forced to eventually | |
1777feb0 | 2159 | timeout. */ |
6426a772 JM |
2160 | /* FIXME: cagney/1999-09-24: It isn't possible for target_open() to |
2161 | differentiate to its caller what the state of the target is after | |
2162 | the initial open has been performed. Here we're assuming that | |
2163 | the target has stopped. It should be possible to eventually have | |
2164 | target_open() return to the caller an indication that the target | |
2165 | is currently running and GDB state should be set to the same as | |
1777feb0 | 2166 | for an async run. */ |
ae123ec6 | 2167 | wait_for_inferior (0); |
8621d6a9 DJ |
2168 | |
2169 | /* Now that the inferior has stopped, do any bookkeeping like | |
2170 | loading shared libraries. We want to do this before normal_stop, | |
2171 | so that the displayed frame is up to date. */ | |
2172 | post_create_inferior (¤t_target, from_tty); | |
2173 | ||
6426a772 | 2174 | normal_stop (); |
c906108c SS |
2175 | } |
2176 | ||
2177 | /* Initialize static vars when a new inferior begins. */ | |
2178 | ||
2179 | void | |
96baa820 | 2180 | init_wait_for_inferior (void) |
c906108c SS |
2181 | { |
2182 | /* These are meaningless until the first time through wait_for_inferior. */ | |
c906108c | 2183 | |
c906108c SS |
2184 | breakpoint_init_inferior (inf_starting); |
2185 | ||
c906108c | 2186 | clear_proceed_status (); |
9f976b41 DJ |
2187 | |
2188 | stepping_past_singlestep_breakpoint = 0; | |
ca67fcb8 | 2189 | deferred_step_ptid = null_ptid; |
ca005067 DJ |
2190 | |
2191 | target_last_wait_ptid = minus_one_ptid; | |
237fc4c9 | 2192 | |
0d1e5fa7 PA |
2193 | previous_inferior_ptid = null_ptid; |
2194 | init_infwait_state (); | |
2195 | ||
edb3359d DJ |
2196 | /* Discard any skipped inlined frames. */ |
2197 | clear_inline_frame_state (minus_one_ptid); | |
c906108c | 2198 | } |
237fc4c9 | 2199 | |
c906108c | 2200 | \f |
b83266a0 SS |
2201 | /* This enum encodes possible reasons for doing a target_wait, so that |
2202 | wfi can call target_wait in one place. (Ultimately the call will be | |
2203 | moved out of the infinite loop entirely.) */ | |
2204 | ||
c5aa993b JM |
2205 | enum infwait_states |
2206 | { | |
cd0fc7c3 SS |
2207 | infwait_normal_state, |
2208 | infwait_thread_hop_state, | |
d983da9c | 2209 | infwait_step_watch_state, |
cd0fc7c3 | 2210 | infwait_nonstep_watch_state |
b83266a0 SS |
2211 | }; |
2212 | ||
0d1e5fa7 PA |
2213 | /* The PTID we'll do a target_wait on.*/ |
2214 | ptid_t waiton_ptid; | |
2215 | ||
2216 | /* Current inferior wait state. */ | |
2217 | enum infwait_states infwait_state; | |
cd0fc7c3 | 2218 | |
0d1e5fa7 PA |
2219 | /* Data to be passed around while handling an event. This data is |
2220 | discarded between events. */ | |
c5aa993b | 2221 | struct execution_control_state |
488f131b | 2222 | { |
0d1e5fa7 | 2223 | ptid_t ptid; |
4e1c45ea PA |
2224 | /* The thread that got the event, if this was a thread event; NULL |
2225 | otherwise. */ | |
2226 | struct thread_info *event_thread; | |
2227 | ||
488f131b | 2228 | struct target_waitstatus ws; |
488f131b JB |
2229 | int random_signal; |
2230 | CORE_ADDR stop_func_start; | |
2231 | CORE_ADDR stop_func_end; | |
2232 | char *stop_func_name; | |
488f131b | 2233 | int new_thread_event; |
488f131b JB |
2234 | int wait_some_more; |
2235 | }; | |
2236 | ||
ec9499be | 2237 | static void handle_inferior_event (struct execution_control_state *ecs); |
cd0fc7c3 | 2238 | |
568d6575 UW |
2239 | static void handle_step_into_function (struct gdbarch *gdbarch, |
2240 | struct execution_control_state *ecs); | |
2241 | static void handle_step_into_function_backward (struct gdbarch *gdbarch, | |
2242 | struct execution_control_state *ecs); | |
3e43a32a | 2243 | static void insert_step_resume_breakpoint_at_frame (struct frame_info *); |
14e60db5 | 2244 | static void insert_step_resume_breakpoint_at_caller (struct frame_info *); |
3e43a32a MS |
2245 | static void insert_step_resume_breakpoint_at_sal (struct gdbarch *, |
2246 | struct symtab_and_line , | |
2247 | struct frame_id); | |
a6d9a66e | 2248 | static void insert_longjmp_resume_breakpoint (struct gdbarch *, CORE_ADDR); |
186c406b TT |
2249 | static void check_exception_resume (struct execution_control_state *, |
2250 | struct frame_info *, struct symbol *); | |
611c83ae | 2251 | |
104c1213 JM |
2252 | static void stop_stepping (struct execution_control_state *ecs); |
2253 | static void prepare_to_wait (struct execution_control_state *ecs); | |
d4f3574e | 2254 | static void keep_going (struct execution_control_state *ecs); |
104c1213 | 2255 | |
252fbfc8 PA |
2256 | /* Callback for iterate over threads. If the thread is stopped, but |
2257 | the user/frontend doesn't know about that yet, go through | |
2258 | normal_stop, as if the thread had just stopped now. ARG points at | |
2259 | a ptid. If PTID is MINUS_ONE_PTID, applies to all threads. If | |
2260 | ptid_is_pid(PTID) is true, applies to all threads of the process | |
2261 | pointed at by PTID. Otherwise, apply only to the thread pointed by | |
2262 | PTID. */ | |
2263 | ||
2264 | static int | |
2265 | infrun_thread_stop_requested_callback (struct thread_info *info, void *arg) | |
2266 | { | |
2267 | ptid_t ptid = * (ptid_t *) arg; | |
2268 | ||
2269 | if ((ptid_equal (info->ptid, ptid) | |
2270 | || ptid_equal (minus_one_ptid, ptid) | |
2271 | || (ptid_is_pid (ptid) | |
2272 | && ptid_get_pid (ptid) == ptid_get_pid (info->ptid))) | |
2273 | && is_running (info->ptid) | |
2274 | && !is_executing (info->ptid)) | |
2275 | { | |
2276 | struct cleanup *old_chain; | |
2277 | struct execution_control_state ecss; | |
2278 | struct execution_control_state *ecs = &ecss; | |
2279 | ||
2280 | memset (ecs, 0, sizeof (*ecs)); | |
2281 | ||
2282 | old_chain = make_cleanup_restore_current_thread (); | |
2283 | ||
2284 | switch_to_thread (info->ptid); | |
2285 | ||
2286 | /* Go through handle_inferior_event/normal_stop, so we always | |
2287 | have consistent output as if the stop event had been | |
2288 | reported. */ | |
2289 | ecs->ptid = info->ptid; | |
e09875d4 | 2290 | ecs->event_thread = find_thread_ptid (info->ptid); |
252fbfc8 PA |
2291 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; |
2292 | ecs->ws.value.sig = TARGET_SIGNAL_0; | |
2293 | ||
2294 | handle_inferior_event (ecs); | |
2295 | ||
2296 | if (!ecs->wait_some_more) | |
2297 | { | |
2298 | struct thread_info *tp; | |
2299 | ||
2300 | normal_stop (); | |
2301 | ||
2302 | /* Finish off the continuations. The continations | |
2303 | themselves are responsible for realising the thread | |
2304 | didn't finish what it was supposed to do. */ | |
2305 | tp = inferior_thread (); | |
2306 | do_all_intermediate_continuations_thread (tp); | |
2307 | do_all_continuations_thread (tp); | |
2308 | } | |
2309 | ||
2310 | do_cleanups (old_chain); | |
2311 | } | |
2312 | ||
2313 | return 0; | |
2314 | } | |
2315 | ||
2316 | /* This function is attached as a "thread_stop_requested" observer. | |
2317 | Cleanup local state that assumed the PTID was to be resumed, and | |
2318 | report the stop to the frontend. */ | |
2319 | ||
2c0b251b | 2320 | static void |
252fbfc8 PA |
2321 | infrun_thread_stop_requested (ptid_t ptid) |
2322 | { | |
fc1cf338 | 2323 | struct displaced_step_inferior_state *displaced; |
252fbfc8 PA |
2324 | |
2325 | /* PTID was requested to stop. Remove it from the displaced | |
2326 | stepping queue, so we don't try to resume it automatically. */ | |
fc1cf338 PA |
2327 | |
2328 | for (displaced = displaced_step_inferior_states; | |
2329 | displaced; | |
2330 | displaced = displaced->next) | |
252fbfc8 | 2331 | { |
fc1cf338 | 2332 | struct displaced_step_request *it, **prev_next_p; |
252fbfc8 | 2333 | |
fc1cf338 PA |
2334 | it = displaced->step_request_queue; |
2335 | prev_next_p = &displaced->step_request_queue; | |
2336 | while (it) | |
252fbfc8 | 2337 | { |
fc1cf338 PA |
2338 | if (ptid_match (it->ptid, ptid)) |
2339 | { | |
2340 | *prev_next_p = it->next; | |
2341 | it->next = NULL; | |
2342 | xfree (it); | |
2343 | } | |
252fbfc8 | 2344 | else |
fc1cf338 PA |
2345 | { |
2346 | prev_next_p = &it->next; | |
2347 | } | |
252fbfc8 | 2348 | |
fc1cf338 | 2349 | it = *prev_next_p; |
252fbfc8 | 2350 | } |
252fbfc8 PA |
2351 | } |
2352 | ||
2353 | iterate_over_threads (infrun_thread_stop_requested_callback, &ptid); | |
2354 | } | |
2355 | ||
a07daef3 PA |
2356 | static void |
2357 | infrun_thread_thread_exit (struct thread_info *tp, int silent) | |
2358 | { | |
2359 | if (ptid_equal (target_last_wait_ptid, tp->ptid)) | |
2360 | nullify_last_target_wait_ptid (); | |
2361 | } | |
2362 | ||
4e1c45ea PA |
2363 | /* Callback for iterate_over_threads. */ |
2364 | ||
2365 | static int | |
2366 | delete_step_resume_breakpoint_callback (struct thread_info *info, void *data) | |
2367 | { | |
2368 | if (is_exited (info->ptid)) | |
2369 | return 0; | |
2370 | ||
2371 | delete_step_resume_breakpoint (info); | |
186c406b | 2372 | delete_exception_resume_breakpoint (info); |
4e1c45ea PA |
2373 | return 0; |
2374 | } | |
2375 | ||
2376 | /* In all-stop, delete the step resume breakpoint of any thread that | |
2377 | had one. In non-stop, delete the step resume breakpoint of the | |
2378 | thread that just stopped. */ | |
2379 | ||
2380 | static void | |
2381 | delete_step_thread_step_resume_breakpoint (void) | |
2382 | { | |
2383 | if (!target_has_execution | |
2384 | || ptid_equal (inferior_ptid, null_ptid)) | |
2385 | /* If the inferior has exited, we have already deleted the step | |
2386 | resume breakpoints out of GDB's lists. */ | |
2387 | return; | |
2388 | ||
2389 | if (non_stop) | |
2390 | { | |
2391 | /* If in non-stop mode, only delete the step-resume or | |
2392 | longjmp-resume breakpoint of the thread that just stopped | |
2393 | stepping. */ | |
2394 | struct thread_info *tp = inferior_thread (); | |
abbb1732 | 2395 | |
4e1c45ea | 2396 | delete_step_resume_breakpoint (tp); |
186c406b | 2397 | delete_exception_resume_breakpoint (tp); |
4e1c45ea PA |
2398 | } |
2399 | else | |
2400 | /* In all-stop mode, delete all step-resume and longjmp-resume | |
2401 | breakpoints of any thread that had them. */ | |
2402 | iterate_over_threads (delete_step_resume_breakpoint_callback, NULL); | |
2403 | } | |
2404 | ||
1777feb0 | 2405 | /* A cleanup wrapper. */ |
4e1c45ea PA |
2406 | |
2407 | static void | |
2408 | delete_step_thread_step_resume_breakpoint_cleanup (void *arg) | |
2409 | { | |
2410 | delete_step_thread_step_resume_breakpoint (); | |
2411 | } | |
2412 | ||
223698f8 DE |
2413 | /* Pretty print the results of target_wait, for debugging purposes. */ |
2414 | ||
2415 | static void | |
2416 | print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, | |
2417 | const struct target_waitstatus *ws) | |
2418 | { | |
2419 | char *status_string = target_waitstatus_to_string (ws); | |
2420 | struct ui_file *tmp_stream = mem_fileopen (); | |
2421 | char *text; | |
223698f8 DE |
2422 | |
2423 | /* The text is split over several lines because it was getting too long. | |
2424 | Call fprintf_unfiltered (gdb_stdlog) once so that the text is still | |
2425 | output as a unit; we want only one timestamp printed if debug_timestamp | |
2426 | is set. */ | |
2427 | ||
2428 | fprintf_unfiltered (tmp_stream, | |
2429 | "infrun: target_wait (%d", PIDGET (waiton_ptid)); | |
2430 | if (PIDGET (waiton_ptid) != -1) | |
2431 | fprintf_unfiltered (tmp_stream, | |
2432 | " [%s]", target_pid_to_str (waiton_ptid)); | |
2433 | fprintf_unfiltered (tmp_stream, ", status) =\n"); | |
2434 | fprintf_unfiltered (tmp_stream, | |
2435 | "infrun: %d [%s],\n", | |
2436 | PIDGET (result_ptid), target_pid_to_str (result_ptid)); | |
2437 | fprintf_unfiltered (tmp_stream, | |
2438 | "infrun: %s\n", | |
2439 | status_string); | |
2440 | ||
759ef836 | 2441 | text = ui_file_xstrdup (tmp_stream, NULL); |
223698f8 DE |
2442 | |
2443 | /* This uses %s in part to handle %'s in the text, but also to avoid | |
2444 | a gcc error: the format attribute requires a string literal. */ | |
2445 | fprintf_unfiltered (gdb_stdlog, "%s", text); | |
2446 | ||
2447 | xfree (status_string); | |
2448 | xfree (text); | |
2449 | ui_file_delete (tmp_stream); | |
2450 | } | |
2451 | ||
24291992 PA |
2452 | /* Prepare and stabilize the inferior for detaching it. E.g., |
2453 | detaching while a thread is displaced stepping is a recipe for | |
2454 | crashing it, as nothing would readjust the PC out of the scratch | |
2455 | pad. */ | |
2456 | ||
2457 | void | |
2458 | prepare_for_detach (void) | |
2459 | { | |
2460 | struct inferior *inf = current_inferior (); | |
2461 | ptid_t pid_ptid = pid_to_ptid (inf->pid); | |
2462 | struct cleanup *old_chain_1; | |
2463 | struct displaced_step_inferior_state *displaced; | |
2464 | ||
2465 | displaced = get_displaced_stepping_state (inf->pid); | |
2466 | ||
2467 | /* Is any thread of this process displaced stepping? If not, | |
2468 | there's nothing else to do. */ | |
2469 | if (displaced == NULL || ptid_equal (displaced->step_ptid, null_ptid)) | |
2470 | return; | |
2471 | ||
2472 | if (debug_infrun) | |
2473 | fprintf_unfiltered (gdb_stdlog, | |
2474 | "displaced-stepping in-process while detaching"); | |
2475 | ||
2476 | old_chain_1 = make_cleanup_restore_integer (&inf->detaching); | |
2477 | inf->detaching = 1; | |
2478 | ||
2479 | while (!ptid_equal (displaced->step_ptid, null_ptid)) | |
2480 | { | |
2481 | struct cleanup *old_chain_2; | |
2482 | struct execution_control_state ecss; | |
2483 | struct execution_control_state *ecs; | |
2484 | ||
2485 | ecs = &ecss; | |
2486 | memset (ecs, 0, sizeof (*ecs)); | |
2487 | ||
2488 | overlay_cache_invalid = 1; | |
2489 | ||
2490 | /* We have to invalidate the registers BEFORE calling | |
2491 | target_wait because they can be loaded from the target while | |
2492 | in target_wait. This makes remote debugging a bit more | |
2493 | efficient for those targets that provide critical registers | |
1777feb0 | 2494 | as part of their normal status mechanism. */ |
24291992 PA |
2495 | |
2496 | registers_changed (); | |
2497 | ||
2498 | if (deprecated_target_wait_hook) | |
2499 | ecs->ptid = deprecated_target_wait_hook (pid_ptid, &ecs->ws, 0); | |
2500 | else | |
2501 | ecs->ptid = target_wait (pid_ptid, &ecs->ws, 0); | |
2502 | ||
2503 | if (debug_infrun) | |
2504 | print_target_wait_results (pid_ptid, ecs->ptid, &ecs->ws); | |
2505 | ||
2506 | /* If an error happens while handling the event, propagate GDB's | |
2507 | knowledge of the executing state to the frontend/user running | |
2508 | state. */ | |
3e43a32a MS |
2509 | old_chain_2 = make_cleanup (finish_thread_state_cleanup, |
2510 | &minus_one_ptid); | |
24291992 | 2511 | |
4d533103 PA |
2512 | /* In non-stop mode, each thread is handled individually. |
2513 | Switch early, so the global state is set correctly for this | |
2514 | thread. */ | |
2515 | if (non_stop | |
2516 | && ecs->ws.kind != TARGET_WAITKIND_EXITED | |
2517 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) | |
2518 | context_switch (ecs->ptid); | |
2519 | ||
24291992 PA |
2520 | /* Now figure out what to do with the result of the result. */ |
2521 | handle_inferior_event (ecs); | |
2522 | ||
2523 | /* No error, don't finish the state yet. */ | |
2524 | discard_cleanups (old_chain_2); | |
2525 | ||
2526 | /* Breakpoints and watchpoints are not installed on the target | |
2527 | at this point, and signals are passed directly to the | |
2528 | inferior, so this must mean the process is gone. */ | |
2529 | if (!ecs->wait_some_more) | |
2530 | { | |
2531 | discard_cleanups (old_chain_1); | |
2532 | error (_("Program exited while detaching")); | |
2533 | } | |
2534 | } | |
2535 | ||
2536 | discard_cleanups (old_chain_1); | |
2537 | } | |
2538 | ||
cd0fc7c3 | 2539 | /* Wait for control to return from inferior to debugger. |
ae123ec6 JB |
2540 | |
2541 | If TREAT_EXEC_AS_SIGTRAP is non-zero, then handle EXEC signals | |
2542 | as if they were SIGTRAP signals. This can be useful during | |
2543 | the startup sequence on some targets such as HP/UX, where | |
2544 | we receive an EXEC event instead of the expected SIGTRAP. | |
2545 | ||
cd0fc7c3 SS |
2546 | If inferior gets a signal, we may decide to start it up again |
2547 | instead of returning. That is why there is a loop in this function. | |
2548 | When this function actually returns it means the inferior | |
2549 | should be left stopped and GDB should read more commands. */ | |
2550 | ||
2551 | void | |
ae123ec6 | 2552 | wait_for_inferior (int treat_exec_as_sigtrap) |
cd0fc7c3 SS |
2553 | { |
2554 | struct cleanup *old_cleanups; | |
0d1e5fa7 | 2555 | struct execution_control_state ecss; |
cd0fc7c3 | 2556 | struct execution_control_state *ecs; |
c906108c | 2557 | |
527159b7 | 2558 | if (debug_infrun) |
ae123ec6 JB |
2559 | fprintf_unfiltered |
2560 | (gdb_stdlog, "infrun: wait_for_inferior (treat_exec_as_sigtrap=%d)\n", | |
2561 | treat_exec_as_sigtrap); | |
527159b7 | 2562 | |
4e1c45ea PA |
2563 | old_cleanups = |
2564 | make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL); | |
cd0fc7c3 | 2565 | |
cd0fc7c3 | 2566 | ecs = &ecss; |
0d1e5fa7 PA |
2567 | memset (ecs, 0, sizeof (*ecs)); |
2568 | ||
e0bb1c1c PA |
2569 | /* We'll update this if & when we switch to a new thread. */ |
2570 | previous_inferior_ptid = inferior_ptid; | |
2571 | ||
c906108c SS |
2572 | while (1) |
2573 | { | |
29f49a6a PA |
2574 | struct cleanup *old_chain; |
2575 | ||
ec9499be UW |
2576 | /* We have to invalidate the registers BEFORE calling target_wait |
2577 | because they can be loaded from the target while in target_wait. | |
2578 | This makes remote debugging a bit more efficient for those | |
2579 | targets that provide critical registers as part of their normal | |
1777feb0 | 2580 | status mechanism. */ |
ec9499be UW |
2581 | |
2582 | overlay_cache_invalid = 1; | |
2583 | registers_changed (); | |
2584 | ||
9a4105ab | 2585 | if (deprecated_target_wait_hook) |
47608cb1 | 2586 | ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws, 0); |
cd0fc7c3 | 2587 | else |
47608cb1 | 2588 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, 0); |
c906108c | 2589 | |
f00150c9 | 2590 | if (debug_infrun) |
223698f8 | 2591 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
f00150c9 | 2592 | |
ae123ec6 JB |
2593 | if (treat_exec_as_sigtrap && ecs->ws.kind == TARGET_WAITKIND_EXECD) |
2594 | { | |
2595 | xfree (ecs->ws.value.execd_pathname); | |
2596 | ecs->ws.kind = TARGET_WAITKIND_STOPPED; | |
2597 | ecs->ws.value.sig = TARGET_SIGNAL_TRAP; | |
2598 | } | |
2599 | ||
29f49a6a PA |
2600 | /* If an error happens while handling the event, propagate GDB's |
2601 | knowledge of the executing state to the frontend/user running | |
2602 | state. */ | |
2603 | old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
2604 | ||
a96d9b2e SDJ |
2605 | if (ecs->ws.kind == TARGET_WAITKIND_SYSCALL_ENTRY |
2606 | || ecs->ws.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
2607 | ecs->ws.value.syscall_number = UNKNOWN_SYSCALL; | |
2608 | ||
cd0fc7c3 SS |
2609 | /* Now figure out what to do with the result of the result. */ |
2610 | handle_inferior_event (ecs); | |
c906108c | 2611 | |
29f49a6a PA |
2612 | /* No error, don't finish the state yet. */ |
2613 | discard_cleanups (old_chain); | |
2614 | ||
cd0fc7c3 SS |
2615 | if (!ecs->wait_some_more) |
2616 | break; | |
2617 | } | |
4e1c45ea | 2618 | |
cd0fc7c3 SS |
2619 | do_cleanups (old_cleanups); |
2620 | } | |
c906108c | 2621 | |
1777feb0 | 2622 | /* Asynchronous version of wait_for_inferior. It is called by the |
43ff13b4 | 2623 | event loop whenever a change of state is detected on the file |
1777feb0 MS |
2624 | descriptor corresponding to the target. It can be called more than |
2625 | once to complete a single execution command. In such cases we need | |
2626 | to keep the state in a global variable ECSS. If it is the last time | |
a474d7c2 PA |
2627 | that this function is called for a single execution command, then |
2628 | report to the user that the inferior has stopped, and do the | |
1777feb0 | 2629 | necessary cleanups. */ |
43ff13b4 JM |
2630 | |
2631 | void | |
fba45db2 | 2632 | fetch_inferior_event (void *client_data) |
43ff13b4 | 2633 | { |
0d1e5fa7 | 2634 | struct execution_control_state ecss; |
a474d7c2 | 2635 | struct execution_control_state *ecs = &ecss; |
4f8d22e3 | 2636 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
29f49a6a | 2637 | struct cleanup *ts_old_chain; |
4f8d22e3 | 2638 | int was_sync = sync_execution; |
43ff13b4 | 2639 | |
0d1e5fa7 PA |
2640 | memset (ecs, 0, sizeof (*ecs)); |
2641 | ||
ec9499be UW |
2642 | /* We'll update this if & when we switch to a new thread. */ |
2643 | previous_inferior_ptid = inferior_ptid; | |
e0bb1c1c | 2644 | |
c5187ac6 PA |
2645 | /* We're handling a live event, so make sure we're doing live |
2646 | debugging. If we're looking at traceframes while the target is | |
2647 | running, we're going to need to get back to that mode after | |
2648 | handling the event. */ | |
2649 | if (non_stop) | |
2650 | { | |
2651 | make_cleanup_restore_current_traceframe (); | |
e6e4e701 | 2652 | set_current_traceframe (-1); |
c5187ac6 PA |
2653 | } |
2654 | ||
4f8d22e3 PA |
2655 | if (non_stop) |
2656 | /* In non-stop mode, the user/frontend should not notice a thread | |
2657 | switch due to internal events. Make sure we reverse to the | |
2658 | user selected thread and frame after handling the event and | |
2659 | running any breakpoint commands. */ | |
2660 | make_cleanup_restore_current_thread (); | |
2661 | ||
59f0d5d9 PA |
2662 | /* We have to invalidate the registers BEFORE calling target_wait |
2663 | because they can be loaded from the target while in target_wait. | |
2664 | This makes remote debugging a bit more efficient for those | |
2665 | targets that provide critical registers as part of their normal | |
1777feb0 | 2666 | status mechanism. */ |
43ff13b4 | 2667 | |
ec9499be | 2668 | overlay_cache_invalid = 1; |
59f0d5d9 | 2669 | registers_changed (); |
43ff13b4 | 2670 | |
9a4105ab | 2671 | if (deprecated_target_wait_hook) |
a474d7c2 | 2672 | ecs->ptid = |
47608cb1 | 2673 | deprecated_target_wait_hook (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
43ff13b4 | 2674 | else |
47608cb1 | 2675 | ecs->ptid = target_wait (waiton_ptid, &ecs->ws, TARGET_WNOHANG); |
43ff13b4 | 2676 | |
f00150c9 | 2677 | if (debug_infrun) |
223698f8 | 2678 | print_target_wait_results (waiton_ptid, ecs->ptid, &ecs->ws); |
f00150c9 | 2679 | |
94cc34af PA |
2680 | if (non_stop |
2681 | && ecs->ws.kind != TARGET_WAITKIND_IGNORE | |
2682 | && ecs->ws.kind != TARGET_WAITKIND_EXITED | |
2683 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) | |
2684 | /* In non-stop mode, each thread is handled individually. Switch | |
2685 | early, so the global state is set correctly for this | |
2686 | thread. */ | |
2687 | context_switch (ecs->ptid); | |
2688 | ||
29f49a6a PA |
2689 | /* If an error happens while handling the event, propagate GDB's |
2690 | knowledge of the executing state to the frontend/user running | |
2691 | state. */ | |
2692 | if (!non_stop) | |
2693 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
2694 | else | |
2695 | ts_old_chain = make_cleanup (finish_thread_state_cleanup, &ecs->ptid); | |
2696 | ||
43ff13b4 | 2697 | /* Now figure out what to do with the result of the result. */ |
a474d7c2 | 2698 | handle_inferior_event (ecs); |
43ff13b4 | 2699 | |
a474d7c2 | 2700 | if (!ecs->wait_some_more) |
43ff13b4 | 2701 | { |
d6b48e9c PA |
2702 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); |
2703 | ||
4e1c45ea | 2704 | delete_step_thread_step_resume_breakpoint (); |
f107f563 | 2705 | |
d6b48e9c | 2706 | /* We may not find an inferior if this was a process exit. */ |
16c381f0 | 2707 | if (inf == NULL || inf->control.stop_soon == NO_STOP_QUIETLY) |
83c265ab PA |
2708 | normal_stop (); |
2709 | ||
af679fd0 PA |
2710 | if (target_has_execution |
2711 | && ecs->ws.kind != TARGET_WAITKIND_EXITED | |
2712 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
2713 | && ecs->event_thread->step_multi | |
16c381f0 | 2714 | && ecs->event_thread->control.stop_step) |
c2d11a7d JM |
2715 | inferior_event_handler (INF_EXEC_CONTINUE, NULL); |
2716 | else | |
2717 | inferior_event_handler (INF_EXEC_COMPLETE, NULL); | |
43ff13b4 | 2718 | } |
4f8d22e3 | 2719 | |
29f49a6a PA |
2720 | /* No error, don't finish the thread states yet. */ |
2721 | discard_cleanups (ts_old_chain); | |
2722 | ||
4f8d22e3 PA |
2723 | /* Revert thread and frame. */ |
2724 | do_cleanups (old_chain); | |
2725 | ||
2726 | /* If the inferior was in sync execution mode, and now isn't, | |
2727 | restore the prompt. */ | |
2728 | if (was_sync && !sync_execution) | |
2729 | display_gdb_prompt (0); | |
43ff13b4 JM |
2730 | } |
2731 | ||
edb3359d DJ |
2732 | /* Record the frame and location we're currently stepping through. */ |
2733 | void | |
2734 | set_step_info (struct frame_info *frame, struct symtab_and_line sal) | |
2735 | { | |
2736 | struct thread_info *tp = inferior_thread (); | |
2737 | ||
16c381f0 JK |
2738 | tp->control.step_frame_id = get_frame_id (frame); |
2739 | tp->control.step_stack_frame_id = get_stack_frame_id (frame); | |
edb3359d DJ |
2740 | |
2741 | tp->current_symtab = sal.symtab; | |
2742 | tp->current_line = sal.line; | |
2743 | } | |
2744 | ||
0d1e5fa7 PA |
2745 | /* Clear context switchable stepping state. */ |
2746 | ||
2747 | void | |
4e1c45ea | 2748 | init_thread_stepping_state (struct thread_info *tss) |
0d1e5fa7 PA |
2749 | { |
2750 | tss->stepping_over_breakpoint = 0; | |
2751 | tss->step_after_step_resume_breakpoint = 0; | |
2752 | tss->stepping_through_solib_after_catch = 0; | |
2753 | tss->stepping_through_solib_catchpoints = NULL; | |
cd0fc7c3 SS |
2754 | } |
2755 | ||
e02bc4cc | 2756 | /* Return the cached copy of the last pid/waitstatus returned by |
9a4105ab AC |
2757 | target_wait()/deprecated_target_wait_hook(). The data is actually |
2758 | cached by handle_inferior_event(), which gets called immediately | |
2759 | after target_wait()/deprecated_target_wait_hook(). */ | |
e02bc4cc DS |
2760 | |
2761 | void | |
488f131b | 2762 | get_last_target_status (ptid_t *ptidp, struct target_waitstatus *status) |
e02bc4cc | 2763 | { |
39f77062 | 2764 | *ptidp = target_last_wait_ptid; |
e02bc4cc DS |
2765 | *status = target_last_waitstatus; |
2766 | } | |
2767 | ||
ac264b3b MS |
2768 | void |
2769 | nullify_last_target_wait_ptid (void) | |
2770 | { | |
2771 | target_last_wait_ptid = minus_one_ptid; | |
2772 | } | |
2773 | ||
dcf4fbde | 2774 | /* Switch thread contexts. */ |
dd80620e MS |
2775 | |
2776 | static void | |
0d1e5fa7 | 2777 | context_switch (ptid_t ptid) |
dd80620e | 2778 | { |
fd48f117 DJ |
2779 | if (debug_infrun) |
2780 | { | |
2781 | fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", | |
2782 | target_pid_to_str (inferior_ptid)); | |
2783 | fprintf_unfiltered (gdb_stdlog, "to %s\n", | |
0d1e5fa7 | 2784 | target_pid_to_str (ptid)); |
fd48f117 DJ |
2785 | } |
2786 | ||
0d1e5fa7 | 2787 | switch_to_thread (ptid); |
dd80620e MS |
2788 | } |
2789 | ||
4fa8626c DJ |
2790 | static void |
2791 | adjust_pc_after_break (struct execution_control_state *ecs) | |
2792 | { | |
24a73cce UW |
2793 | struct regcache *regcache; |
2794 | struct gdbarch *gdbarch; | |
6c95b8df | 2795 | struct address_space *aspace; |
8aad930b | 2796 | CORE_ADDR breakpoint_pc; |
4fa8626c | 2797 | |
4fa8626c DJ |
2798 | /* If we've hit a breakpoint, we'll normally be stopped with SIGTRAP. If |
2799 | we aren't, just return. | |
9709f61c DJ |
2800 | |
2801 | We assume that waitkinds other than TARGET_WAITKIND_STOPPED are not | |
b798847d UW |
2802 | affected by gdbarch_decr_pc_after_break. Other waitkinds which are |
2803 | implemented by software breakpoints should be handled through the normal | |
2804 | breakpoint layer. | |
8fb3e588 | 2805 | |
4fa8626c DJ |
2806 | NOTE drow/2004-01-31: On some targets, breakpoints may generate |
2807 | different signals (SIGILL or SIGEMT for instance), but it is less | |
2808 | clear where the PC is pointing afterwards. It may not match | |
b798847d UW |
2809 | gdbarch_decr_pc_after_break. I don't know any specific target that |
2810 | generates these signals at breakpoints (the code has been in GDB since at | |
2811 | least 1992) so I can not guess how to handle them here. | |
8fb3e588 | 2812 | |
e6cf7916 UW |
2813 | In earlier versions of GDB, a target with |
2814 | gdbarch_have_nonsteppable_watchpoint would have the PC after hitting a | |
b798847d UW |
2815 | watchpoint affected by gdbarch_decr_pc_after_break. I haven't found any |
2816 | target with both of these set in GDB history, and it seems unlikely to be | |
2817 | correct, so gdbarch_have_nonsteppable_watchpoint is not checked here. */ | |
4fa8626c DJ |
2818 | |
2819 | if (ecs->ws.kind != TARGET_WAITKIND_STOPPED) | |
2820 | return; | |
2821 | ||
2822 | if (ecs->ws.value.sig != TARGET_SIGNAL_TRAP) | |
2823 | return; | |
2824 | ||
4058b839 PA |
2825 | /* In reverse execution, when a breakpoint is hit, the instruction |
2826 | under it has already been de-executed. The reported PC always | |
2827 | points at the breakpoint address, so adjusting it further would | |
2828 | be wrong. E.g., consider this case on a decr_pc_after_break == 1 | |
2829 | architecture: | |
2830 | ||
2831 | B1 0x08000000 : INSN1 | |
2832 | B2 0x08000001 : INSN2 | |
2833 | 0x08000002 : INSN3 | |
2834 | PC -> 0x08000003 : INSN4 | |
2835 | ||
2836 | Say you're stopped at 0x08000003 as above. Reverse continuing | |
2837 | from that point should hit B2 as below. Reading the PC when the | |
2838 | SIGTRAP is reported should read 0x08000001 and INSN2 should have | |
2839 | been de-executed already. | |
2840 | ||
2841 | B1 0x08000000 : INSN1 | |
2842 | B2 PC -> 0x08000001 : INSN2 | |
2843 | 0x08000002 : INSN3 | |
2844 | 0x08000003 : INSN4 | |
2845 | ||
2846 | We can't apply the same logic as for forward execution, because | |
2847 | we would wrongly adjust the PC to 0x08000000, since there's a | |
2848 | breakpoint at PC - 1. We'd then report a hit on B1, although | |
2849 | INSN1 hadn't been de-executed yet. Doing nothing is the correct | |
2850 | behaviour. */ | |
2851 | if (execution_direction == EXEC_REVERSE) | |
2852 | return; | |
2853 | ||
24a73cce UW |
2854 | /* If this target does not decrement the PC after breakpoints, then |
2855 | we have nothing to do. */ | |
2856 | regcache = get_thread_regcache (ecs->ptid); | |
2857 | gdbarch = get_regcache_arch (regcache); | |
2858 | if (gdbarch_decr_pc_after_break (gdbarch) == 0) | |
2859 | return; | |
2860 | ||
6c95b8df PA |
2861 | aspace = get_regcache_aspace (regcache); |
2862 | ||
8aad930b AC |
2863 | /* Find the location where (if we've hit a breakpoint) the |
2864 | breakpoint would be. */ | |
515630c5 UW |
2865 | breakpoint_pc = regcache_read_pc (regcache) |
2866 | - gdbarch_decr_pc_after_break (gdbarch); | |
8aad930b | 2867 | |
1c5cfe86 PA |
2868 | /* Check whether there actually is a software breakpoint inserted at |
2869 | that location. | |
2870 | ||
2871 | If in non-stop mode, a race condition is possible where we've | |
2872 | removed a breakpoint, but stop events for that breakpoint were | |
2873 | already queued and arrive later. To suppress those spurious | |
2874 | SIGTRAPs, we keep a list of such breakpoint locations for a bit, | |
2875 | and retire them after a number of stop events are reported. */ | |
6c95b8df PA |
2876 | if (software_breakpoint_inserted_here_p (aspace, breakpoint_pc) |
2877 | || (non_stop && moribund_breakpoint_here_p (aspace, breakpoint_pc))) | |
8aad930b | 2878 | { |
96429cc8 | 2879 | struct cleanup *old_cleanups = NULL; |
abbb1732 | 2880 | |
96429cc8 HZ |
2881 | if (RECORD_IS_USED) |
2882 | old_cleanups = record_gdb_operation_disable_set (); | |
2883 | ||
1c0fdd0e UW |
2884 | /* When using hardware single-step, a SIGTRAP is reported for both |
2885 | a completed single-step and a software breakpoint. Need to | |
2886 | differentiate between the two, as the latter needs adjusting | |
2887 | but the former does not. | |
2888 | ||
2889 | The SIGTRAP can be due to a completed hardware single-step only if | |
2890 | - we didn't insert software single-step breakpoints | |
2891 | - the thread to be examined is still the current thread | |
2892 | - this thread is currently being stepped | |
2893 | ||
2894 | If any of these events did not occur, we must have stopped due | |
2895 | to hitting a software breakpoint, and have to back up to the | |
2896 | breakpoint address. | |
2897 | ||
2898 | As a special case, we could have hardware single-stepped a | |
2899 | software breakpoint. In this case (prev_pc == breakpoint_pc), | |
2900 | we also need to back up to the breakpoint address. */ | |
2901 | ||
2902 | if (singlestep_breakpoints_inserted_p | |
2903 | || !ptid_equal (ecs->ptid, inferior_ptid) | |
4e1c45ea PA |
2904 | || !currently_stepping (ecs->event_thread) |
2905 | || ecs->event_thread->prev_pc == breakpoint_pc) | |
515630c5 | 2906 | regcache_write_pc (regcache, breakpoint_pc); |
96429cc8 HZ |
2907 | |
2908 | if (RECORD_IS_USED) | |
2909 | do_cleanups (old_cleanups); | |
8aad930b | 2910 | } |
4fa8626c DJ |
2911 | } |
2912 | ||
0d1e5fa7 PA |
2913 | void |
2914 | init_infwait_state (void) | |
2915 | { | |
2916 | waiton_ptid = pid_to_ptid (-1); | |
2917 | infwait_state = infwait_normal_state; | |
2918 | } | |
2919 | ||
94cc34af PA |
2920 | void |
2921 | error_is_running (void) | |
2922 | { | |
3e43a32a MS |
2923 | error (_("Cannot execute this command while " |
2924 | "the selected thread is running.")); | |
94cc34af PA |
2925 | } |
2926 | ||
2927 | void | |
2928 | ensure_not_running (void) | |
2929 | { | |
2930 | if (is_running (inferior_ptid)) | |
2931 | error_is_running (); | |
2932 | } | |
2933 | ||
edb3359d DJ |
2934 | static int |
2935 | stepped_in_from (struct frame_info *frame, struct frame_id step_frame_id) | |
2936 | { | |
2937 | for (frame = get_prev_frame (frame); | |
2938 | frame != NULL; | |
2939 | frame = get_prev_frame (frame)) | |
2940 | { | |
2941 | if (frame_id_eq (get_frame_id (frame), step_frame_id)) | |
2942 | return 1; | |
2943 | if (get_frame_type (frame) != INLINE_FRAME) | |
2944 | break; | |
2945 | } | |
2946 | ||
2947 | return 0; | |
2948 | } | |
2949 | ||
a96d9b2e SDJ |
2950 | /* Auxiliary function that handles syscall entry/return events. |
2951 | It returns 1 if the inferior should keep going (and GDB | |
2952 | should ignore the event), or 0 if the event deserves to be | |
2953 | processed. */ | |
ca2163eb | 2954 | |
a96d9b2e | 2955 | static int |
ca2163eb | 2956 | handle_syscall_event (struct execution_control_state *ecs) |
a96d9b2e | 2957 | { |
ca2163eb PA |
2958 | struct regcache *regcache; |
2959 | struct gdbarch *gdbarch; | |
2960 | int syscall_number; | |
2961 | ||
2962 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
2963 | context_switch (ecs->ptid); | |
2964 | ||
2965 | regcache = get_thread_regcache (ecs->ptid); | |
2966 | gdbarch = get_regcache_arch (regcache); | |
2967 | syscall_number = gdbarch_get_syscall_number (gdbarch, ecs->ptid); | |
2968 | stop_pc = regcache_read_pc (regcache); | |
2969 | ||
a96d9b2e SDJ |
2970 | target_last_waitstatus.value.syscall_number = syscall_number; |
2971 | ||
2972 | if (catch_syscall_enabled () > 0 | |
2973 | && catching_syscall_number (syscall_number) > 0) | |
2974 | { | |
2975 | if (debug_infrun) | |
2976 | fprintf_unfiltered (gdb_stdlog, "infrun: syscall number = '%d'\n", | |
2977 | syscall_number); | |
a96d9b2e | 2978 | |
16c381f0 | 2979 | ecs->event_thread->control.stop_bpstat |
6c95b8df PA |
2980 | = bpstat_stop_status (get_regcache_aspace (regcache), |
2981 | stop_pc, ecs->ptid); | |
16c381f0 JK |
2982 | ecs->random_signal |
2983 | = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat); | |
a96d9b2e | 2984 | |
ca2163eb PA |
2985 | if (!ecs->random_signal) |
2986 | { | |
2987 | /* Catchpoint hit. */ | |
16c381f0 | 2988 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
ca2163eb PA |
2989 | return 0; |
2990 | } | |
a96d9b2e | 2991 | } |
ca2163eb PA |
2992 | |
2993 | /* If no catchpoint triggered for this, then keep going. */ | |
16c381f0 | 2994 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
ca2163eb PA |
2995 | keep_going (ecs); |
2996 | return 1; | |
a96d9b2e SDJ |
2997 | } |
2998 | ||
cd0fc7c3 SS |
2999 | /* Given an execution control state that has been freshly filled in |
3000 | by an event from the inferior, figure out what it means and take | |
3001 | appropriate action. */ | |
c906108c | 3002 | |
ec9499be | 3003 | static void |
96baa820 | 3004 | handle_inferior_event (struct execution_control_state *ecs) |
cd0fc7c3 | 3005 | { |
568d6575 UW |
3006 | struct frame_info *frame; |
3007 | struct gdbarch *gdbarch; | |
c8edd8b4 | 3008 | int sw_single_step_trap_p = 0; |
d983da9c DJ |
3009 | int stopped_by_watchpoint; |
3010 | int stepped_after_stopped_by_watchpoint = 0; | |
2afb61aa | 3011 | struct symtab_and_line stop_pc_sal; |
d6b48e9c PA |
3012 | enum stop_kind stop_soon; |
3013 | ||
28736962 PA |
3014 | if (ecs->ws.kind == TARGET_WAITKIND_IGNORE) |
3015 | { | |
3016 | /* We had an event in the inferior, but we are not interested in | |
3017 | handling it at this level. The lower layers have already | |
3018 | done what needs to be done, if anything. | |
3019 | ||
3020 | One of the possible circumstances for this is when the | |
3021 | inferior produces output for the console. The inferior has | |
3022 | not stopped, and we are ignoring the event. Another possible | |
3023 | circumstance is any event which the lower level knows will be | |
3024 | reported multiple times without an intervening resume. */ | |
3025 | if (debug_infrun) | |
3026 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IGNORE\n"); | |
3027 | prepare_to_wait (ecs); | |
3028 | return; | |
3029 | } | |
3030 | ||
d6b48e9c | 3031 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED |
28736962 | 3032 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED) |
d6b48e9c PA |
3033 | { |
3034 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); | |
abbb1732 | 3035 | |
d6b48e9c | 3036 | gdb_assert (inf); |
16c381f0 | 3037 | stop_soon = inf->control.stop_soon; |
d6b48e9c PA |
3038 | } |
3039 | else | |
3040 | stop_soon = NO_STOP_QUIETLY; | |
cd0fc7c3 | 3041 | |
1777feb0 | 3042 | /* Cache the last pid/waitstatus. */ |
39f77062 | 3043 | target_last_wait_ptid = ecs->ptid; |
0d1e5fa7 | 3044 | target_last_waitstatus = ecs->ws; |
e02bc4cc | 3045 | |
ca005067 | 3046 | /* Always clear state belonging to the previous time we stopped. */ |
aa7d318d | 3047 | stop_stack_dummy = STOP_NONE; |
ca005067 | 3048 | |
1777feb0 | 3049 | /* If it's a new process, add it to the thread database. */ |
8c90c137 LM |
3050 | |
3051 | ecs->new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid) | |
3052 | && !ptid_equal (ecs->ptid, minus_one_ptid) | |
3053 | && !in_thread_list (ecs->ptid)); | |
3054 | ||
3055 | if (ecs->ws.kind != TARGET_WAITKIND_EXITED | |
3056 | && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && ecs->new_thread_event) | |
3057 | add_thread (ecs->ptid); | |
3058 | ||
e09875d4 | 3059 | ecs->event_thread = find_thread_ptid (ecs->ptid); |
88ed393a JK |
3060 | |
3061 | /* Dependent on valid ECS->EVENT_THREAD. */ | |
3062 | adjust_pc_after_break (ecs); | |
3063 | ||
3064 | /* Dependent on the current PC value modified by adjust_pc_after_break. */ | |
3065 | reinit_frame_cache (); | |
3066 | ||
28736962 PA |
3067 | breakpoint_retire_moribund (); |
3068 | ||
2b009048 DJ |
3069 | /* First, distinguish signals caused by the debugger from signals |
3070 | that have to do with the program's own actions. Note that | |
3071 | breakpoint insns may cause SIGTRAP or SIGILL or SIGEMT, depending | |
3072 | on the operating system version. Here we detect when a SIGILL or | |
3073 | SIGEMT is really a breakpoint and change it to SIGTRAP. We do | |
3074 | something similar for SIGSEGV, since a SIGSEGV will be generated | |
3075 | when we're trying to execute a breakpoint instruction on a | |
3076 | non-executable stack. This happens for call dummy breakpoints | |
3077 | for architectures like SPARC that place call dummies on the | |
3078 | stack. */ | |
2b009048 DJ |
3079 | if (ecs->ws.kind == TARGET_WAITKIND_STOPPED |
3080 | && (ecs->ws.value.sig == TARGET_SIGNAL_ILL | |
3081 | || ecs->ws.value.sig == TARGET_SIGNAL_SEGV | |
de0a0249 | 3082 | || ecs->ws.value.sig == TARGET_SIGNAL_EMT)) |
2b009048 | 3083 | { |
de0a0249 UW |
3084 | struct regcache *regcache = get_thread_regcache (ecs->ptid); |
3085 | ||
3086 | if (breakpoint_inserted_here_p (get_regcache_aspace (regcache), | |
3087 | regcache_read_pc (regcache))) | |
3088 | { | |
3089 | if (debug_infrun) | |
3090 | fprintf_unfiltered (gdb_stdlog, | |
3091 | "infrun: Treating signal as SIGTRAP\n"); | |
3092 | ecs->ws.value.sig = TARGET_SIGNAL_TRAP; | |
3093 | } | |
2b009048 DJ |
3094 | } |
3095 | ||
28736962 PA |
3096 | /* Mark the non-executing threads accordingly. In all-stop, all |
3097 | threads of all processes are stopped when we get any event | |
3098 | reported. In non-stop mode, only the event thread stops. If | |
3099 | we're handling a process exit in non-stop mode, there's nothing | |
3100 | to do, as threads of the dead process are gone, and threads of | |
3101 | any other process were left running. */ | |
3102 | if (!non_stop) | |
3103 | set_executing (minus_one_ptid, 0); | |
3104 | else if (ecs->ws.kind != TARGET_WAITKIND_SIGNALLED | |
3105 | && ecs->ws.kind != TARGET_WAITKIND_EXITED) | |
3106 | set_executing (inferior_ptid, 0); | |
8c90c137 | 3107 | |
0d1e5fa7 | 3108 | switch (infwait_state) |
488f131b JB |
3109 | { |
3110 | case infwait_thread_hop_state: | |
527159b7 | 3111 | if (debug_infrun) |
8a9de0e4 | 3112 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n"); |
65e82032 | 3113 | break; |
b83266a0 | 3114 | |
488f131b | 3115 | case infwait_normal_state: |
527159b7 | 3116 | if (debug_infrun) |
8a9de0e4 | 3117 | fprintf_unfiltered (gdb_stdlog, "infrun: infwait_normal_state\n"); |
d983da9c DJ |
3118 | break; |
3119 | ||
3120 | case infwait_step_watch_state: | |
3121 | if (debug_infrun) | |
3122 | fprintf_unfiltered (gdb_stdlog, | |
3123 | "infrun: infwait_step_watch_state\n"); | |
3124 | ||
3125 | stepped_after_stopped_by_watchpoint = 1; | |
488f131b | 3126 | break; |
b83266a0 | 3127 | |
488f131b | 3128 | case infwait_nonstep_watch_state: |
527159b7 | 3129 | if (debug_infrun) |
8a9de0e4 AC |
3130 | fprintf_unfiltered (gdb_stdlog, |
3131 | "infrun: infwait_nonstep_watch_state\n"); | |
488f131b | 3132 | insert_breakpoints (); |
c906108c | 3133 | |
488f131b JB |
3134 | /* FIXME-maybe: is this cleaner than setting a flag? Does it |
3135 | handle things like signals arriving and other things happening | |
3136 | in combination correctly? */ | |
3137 | stepped_after_stopped_by_watchpoint = 1; | |
3138 | break; | |
65e82032 AC |
3139 | |
3140 | default: | |
e2e0b3e5 | 3141 | internal_error (__FILE__, __LINE__, _("bad switch")); |
488f131b | 3142 | } |
ec9499be | 3143 | |
0d1e5fa7 | 3144 | infwait_state = infwait_normal_state; |
ec9499be | 3145 | waiton_ptid = pid_to_ptid (-1); |
c906108c | 3146 | |
488f131b JB |
3147 | switch (ecs->ws.kind) |
3148 | { | |
3149 | case TARGET_WAITKIND_LOADED: | |
527159b7 | 3150 | if (debug_infrun) |
8a9de0e4 | 3151 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); |
b0f4b84b DJ |
3152 | /* Ignore gracefully during startup of the inferior, as it might |
3153 | be the shell which has just loaded some objects, otherwise | |
3154 | add the symbols for the newly loaded objects. Also ignore at | |
3155 | the beginning of an attach or remote session; we will query | |
3156 | the full list of libraries once the connection is | |
3157 | established. */ | |
c0236d92 | 3158 | if (stop_soon == NO_STOP_QUIETLY) |
488f131b | 3159 | { |
488f131b JB |
3160 | /* Check for any newly added shared libraries if we're |
3161 | supposed to be adding them automatically. Switch | |
3162 | terminal for any messages produced by | |
3163 | breakpoint_re_set. */ | |
3164 | target_terminal_ours_for_output (); | |
aff6338a | 3165 | /* NOTE: cagney/2003-11-25: Make certain that the target |
8fb3e588 AC |
3166 | stack's section table is kept up-to-date. Architectures, |
3167 | (e.g., PPC64), use the section table to perform | |
3168 | operations such as address => section name and hence | |
3169 | require the table to contain all sections (including | |
3170 | those found in shared libraries). */ | |
b0f4b84b | 3171 | #ifdef SOLIB_ADD |
aff6338a | 3172 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); |
b0f4b84b DJ |
3173 | #else |
3174 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
3175 | #endif | |
488f131b JB |
3176 | target_terminal_inferior (); |
3177 | ||
b0f4b84b DJ |
3178 | /* If requested, stop when the dynamic linker notifies |
3179 | gdb of events. This allows the user to get control | |
3180 | and place breakpoints in initializer routines for | |
3181 | dynamically loaded objects (among other things). */ | |
3182 | if (stop_on_solib_events) | |
3183 | { | |
55409f9d DJ |
3184 | /* Make sure we print "Stopped due to solib-event" in |
3185 | normal_stop. */ | |
3186 | stop_print_frame = 1; | |
3187 | ||
b0f4b84b DJ |
3188 | stop_stepping (ecs); |
3189 | return; | |
3190 | } | |
3191 | ||
3192 | /* NOTE drow/2007-05-11: This might be a good place to check | |
3193 | for "catch load". */ | |
488f131b | 3194 | } |
b0f4b84b DJ |
3195 | |
3196 | /* If we are skipping through a shell, or through shared library | |
3197 | loading that we aren't interested in, resume the program. If | |
3198 | we're running the program normally, also resume. But stop if | |
3199 | we're attaching or setting up a remote connection. */ | |
3200 | if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) | |
3201 | { | |
74960c60 VP |
3202 | /* Loading of shared libraries might have changed breakpoint |
3203 | addresses. Make sure new breakpoints are inserted. */ | |
0b02b92d UW |
3204 | if (stop_soon == NO_STOP_QUIETLY |
3205 | && !breakpoints_always_inserted_mode ()) | |
74960c60 | 3206 | insert_breakpoints (); |
b0f4b84b DJ |
3207 | resume (0, TARGET_SIGNAL_0); |
3208 | prepare_to_wait (ecs); | |
3209 | return; | |
3210 | } | |
3211 | ||
3212 | break; | |
c5aa993b | 3213 | |
488f131b | 3214 | case TARGET_WAITKIND_SPURIOUS: |
527159b7 | 3215 | if (debug_infrun) |
8a9de0e4 | 3216 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SPURIOUS\n"); |
488f131b JB |
3217 | resume (0, TARGET_SIGNAL_0); |
3218 | prepare_to_wait (ecs); | |
3219 | return; | |
c5aa993b | 3220 | |
488f131b | 3221 | case TARGET_WAITKIND_EXITED: |
527159b7 | 3222 | if (debug_infrun) |
8a9de0e4 | 3223 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n"); |
fb66883a | 3224 | inferior_ptid = ecs->ptid; |
6c95b8df PA |
3225 | set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid))); |
3226 | set_current_program_space (current_inferior ()->pspace); | |
3227 | handle_vfork_child_exec_or_exit (0); | |
1777feb0 | 3228 | target_terminal_ours (); /* Must do this before mourn anyway. */ |
33d62d64 | 3229 | print_exited_reason (ecs->ws.value.integer); |
488f131b JB |
3230 | |
3231 | /* Record the exit code in the convenience variable $_exitcode, so | |
3232 | that the user can inspect this again later. */ | |
4fa62494 UW |
3233 | set_internalvar_integer (lookup_internalvar ("_exitcode"), |
3234 | (LONGEST) ecs->ws.value.integer); | |
488f131b JB |
3235 | gdb_flush (gdb_stdout); |
3236 | target_mourn_inferior (); | |
1c0fdd0e | 3237 | singlestep_breakpoints_inserted_p = 0; |
d03285ec | 3238 | cancel_single_step_breakpoints (); |
488f131b JB |
3239 | stop_print_frame = 0; |
3240 | stop_stepping (ecs); | |
3241 | return; | |
c5aa993b | 3242 | |
488f131b | 3243 | case TARGET_WAITKIND_SIGNALLED: |
527159b7 | 3244 | if (debug_infrun) |
8a9de0e4 | 3245 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SIGNALLED\n"); |
fb66883a | 3246 | inferior_ptid = ecs->ptid; |
6c95b8df PA |
3247 | set_current_inferior (find_inferior_pid (ptid_get_pid (ecs->ptid))); |
3248 | set_current_program_space (current_inferior ()->pspace); | |
3249 | handle_vfork_child_exec_or_exit (0); | |
488f131b | 3250 | stop_print_frame = 0; |
1777feb0 | 3251 | target_terminal_ours (); /* Must do this before mourn anyway. */ |
c5aa993b | 3252 | |
488f131b JB |
3253 | /* Note: By definition of TARGET_WAITKIND_SIGNALLED, we shouldn't |
3254 | reach here unless the inferior is dead. However, for years | |
3255 | target_kill() was called here, which hints that fatal signals aren't | |
3256 | really fatal on some systems. If that's true, then some changes | |
1777feb0 | 3257 | may be needed. */ |
488f131b | 3258 | target_mourn_inferior (); |
c906108c | 3259 | |
33d62d64 | 3260 | print_signal_exited_reason (ecs->ws.value.sig); |
1c0fdd0e | 3261 | singlestep_breakpoints_inserted_p = 0; |
d03285ec | 3262 | cancel_single_step_breakpoints (); |
488f131b JB |
3263 | stop_stepping (ecs); |
3264 | return; | |
c906108c | 3265 | |
488f131b | 3266 | /* The following are the only cases in which we keep going; |
1777feb0 | 3267 | the above cases end in a continue or goto. */ |
488f131b | 3268 | case TARGET_WAITKIND_FORKED: |
deb3b17b | 3269 | case TARGET_WAITKIND_VFORKED: |
527159b7 | 3270 | if (debug_infrun) |
8a9de0e4 | 3271 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n"); |
c906108c | 3272 | |
5a2901d9 DJ |
3273 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
3274 | { | |
0d1e5fa7 | 3275 | context_switch (ecs->ptid); |
35f196d9 | 3276 | reinit_frame_cache (); |
5a2901d9 DJ |
3277 | } |
3278 | ||
b242c3c2 PA |
3279 | /* Immediately detach breakpoints from the child before there's |
3280 | any chance of letting the user delete breakpoints from the | |
3281 | breakpoint lists. If we don't do this early, it's easy to | |
3282 | leave left over traps in the child, vis: "break foo; catch | |
3283 | fork; c; <fork>; del; c; <child calls foo>". We only follow | |
3284 | the fork on the last `continue', and by that time the | |
3285 | breakpoint at "foo" is long gone from the breakpoint table. | |
3286 | If we vforked, then we don't need to unpatch here, since both | |
3287 | parent and child are sharing the same memory pages; we'll | |
3288 | need to unpatch at follow/detach time instead to be certain | |
3289 | that new breakpoints added between catchpoint hit time and | |
3290 | vfork follow are detached. */ | |
3291 | if (ecs->ws.kind != TARGET_WAITKIND_VFORKED) | |
3292 | { | |
3293 | int child_pid = ptid_get_pid (ecs->ws.value.related_pid); | |
3294 | ||
3295 | /* This won't actually modify the breakpoint list, but will | |
3296 | physically remove the breakpoints from the child. */ | |
3297 | detach_breakpoints (child_pid); | |
3298 | } | |
3299 | ||
d03285ec UW |
3300 | if (singlestep_breakpoints_inserted_p) |
3301 | { | |
1777feb0 | 3302 | /* Pull the single step breakpoints out of the target. */ |
d03285ec UW |
3303 | remove_single_step_breakpoints (); |
3304 | singlestep_breakpoints_inserted_p = 0; | |
3305 | } | |
3306 | ||
e58b0e63 PA |
3307 | /* In case the event is caught by a catchpoint, remember that |
3308 | the event is to be followed at the next resume of the thread, | |
3309 | and not immediately. */ | |
3310 | ecs->event_thread->pending_follow = ecs->ws; | |
3311 | ||
fb14de7b | 3312 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
675bf4cb | 3313 | |
16c381f0 | 3314 | ecs->event_thread->control.stop_bpstat |
6c95b8df PA |
3315 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
3316 | stop_pc, ecs->ptid); | |
675bf4cb | 3317 | |
67822962 PA |
3318 | /* Note that we're interested in knowing the bpstat actually |
3319 | causes a stop, not just if it may explain the signal. | |
3320 | Software watchpoints, for example, always appear in the | |
3321 | bpstat. */ | |
16c381f0 JK |
3322 | ecs->random_signal |
3323 | = !bpstat_causes_stop (ecs->event_thread->control.stop_bpstat); | |
04e68871 DJ |
3324 | |
3325 | /* If no catchpoint triggered for this, then keep going. */ | |
3326 | if (ecs->random_signal) | |
3327 | { | |
6c95b8df PA |
3328 | ptid_t parent; |
3329 | ptid_t child; | |
e58b0e63 | 3330 | int should_resume; |
3e43a32a MS |
3331 | int follow_child |
3332 | = (follow_fork_mode_string == follow_fork_mode_child); | |
e58b0e63 | 3333 | |
16c381f0 | 3334 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
e58b0e63 PA |
3335 | |
3336 | should_resume = follow_fork (); | |
3337 | ||
6c95b8df PA |
3338 | parent = ecs->ptid; |
3339 | child = ecs->ws.value.related_pid; | |
3340 | ||
3341 | /* In non-stop mode, also resume the other branch. */ | |
3342 | if (non_stop && !detach_fork) | |
3343 | { | |
3344 | if (follow_child) | |
3345 | switch_to_thread (parent); | |
3346 | else | |
3347 | switch_to_thread (child); | |
3348 | ||
3349 | ecs->event_thread = inferior_thread (); | |
3350 | ecs->ptid = inferior_ptid; | |
3351 | keep_going (ecs); | |
3352 | } | |
3353 | ||
3354 | if (follow_child) | |
3355 | switch_to_thread (child); | |
3356 | else | |
3357 | switch_to_thread (parent); | |
3358 | ||
e58b0e63 PA |
3359 | ecs->event_thread = inferior_thread (); |
3360 | ecs->ptid = inferior_ptid; | |
3361 | ||
3362 | if (should_resume) | |
3363 | keep_going (ecs); | |
3364 | else | |
3365 | stop_stepping (ecs); | |
04e68871 DJ |
3366 | return; |
3367 | } | |
16c381f0 | 3368 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
488f131b JB |
3369 | goto process_event_stop_test; |
3370 | ||
6c95b8df PA |
3371 | case TARGET_WAITKIND_VFORK_DONE: |
3372 | /* Done with the shared memory region. Re-insert breakpoints in | |
3373 | the parent, and keep going. */ | |
3374 | ||
3375 | if (debug_infrun) | |
3e43a32a MS |
3376 | fprintf_unfiltered (gdb_stdlog, |
3377 | "infrun: TARGET_WAITKIND_VFORK_DONE\n"); | |
6c95b8df PA |
3378 | |
3379 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
3380 | context_switch (ecs->ptid); | |
3381 | ||
3382 | current_inferior ()->waiting_for_vfork_done = 0; | |
56710373 | 3383 | current_inferior ()->pspace->breakpoints_not_allowed = 0; |
6c95b8df PA |
3384 | /* This also takes care of reinserting breakpoints in the |
3385 | previously locked inferior. */ | |
3386 | keep_going (ecs); | |
3387 | return; | |
3388 | ||
488f131b | 3389 | case TARGET_WAITKIND_EXECD: |
527159b7 | 3390 | if (debug_infrun) |
fc5261f2 | 3391 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n"); |
488f131b | 3392 | |
5a2901d9 DJ |
3393 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
3394 | { | |
0d1e5fa7 | 3395 | context_switch (ecs->ptid); |
35f196d9 | 3396 | reinit_frame_cache (); |
5a2901d9 DJ |
3397 | } |
3398 | ||
d03285ec UW |
3399 | singlestep_breakpoints_inserted_p = 0; |
3400 | cancel_single_step_breakpoints (); | |
3401 | ||
fb14de7b | 3402 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
795e548f | 3403 | |
6c95b8df PA |
3404 | /* Do whatever is necessary to the parent branch of the vfork. */ |
3405 | handle_vfork_child_exec_or_exit (1); | |
3406 | ||
795e548f PA |
3407 | /* This causes the eventpoints and symbol table to be reset. |
3408 | Must do this now, before trying to determine whether to | |
3409 | stop. */ | |
71b43ef8 | 3410 | follow_exec (inferior_ptid, ecs->ws.value.execd_pathname); |
795e548f | 3411 | |
16c381f0 | 3412 | ecs->event_thread->control.stop_bpstat |
6c95b8df PA |
3413 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
3414 | stop_pc, ecs->ptid); | |
16c381f0 JK |
3415 | ecs->random_signal |
3416 | = !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat); | |
795e548f | 3417 | |
71b43ef8 PA |
3418 | /* Note that this may be referenced from inside |
3419 | bpstat_stop_status above, through inferior_has_execd. */ | |
3420 | xfree (ecs->ws.value.execd_pathname); | |
3421 | ecs->ws.value.execd_pathname = NULL; | |
3422 | ||
04e68871 DJ |
3423 | /* If no catchpoint triggered for this, then keep going. */ |
3424 | if (ecs->random_signal) | |
3425 | { | |
16c381f0 | 3426 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
04e68871 DJ |
3427 | keep_going (ecs); |
3428 | return; | |
3429 | } | |
16c381f0 | 3430 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
488f131b JB |
3431 | goto process_event_stop_test; |
3432 | ||
b4dc5ffa MK |
3433 | /* Be careful not to try to gather much state about a thread |
3434 | that's in a syscall. It's frequently a losing proposition. */ | |
488f131b | 3435 | case TARGET_WAITKIND_SYSCALL_ENTRY: |
527159b7 | 3436 | if (debug_infrun) |
3e43a32a MS |
3437 | fprintf_unfiltered (gdb_stdlog, |
3438 | "infrun: TARGET_WAITKIND_SYSCALL_ENTRY\n"); | |
1777feb0 | 3439 | /* Getting the current syscall number. */ |
ca2163eb | 3440 | if (handle_syscall_event (ecs) != 0) |
a96d9b2e SDJ |
3441 | return; |
3442 | goto process_event_stop_test; | |
c906108c | 3443 | |
488f131b JB |
3444 | /* Before examining the threads further, step this thread to |
3445 | get it entirely out of the syscall. (We get notice of the | |
3446 | event when the thread is just on the verge of exiting a | |
3447 | syscall. Stepping one instruction seems to get it back | |
b4dc5ffa | 3448 | into user code.) */ |
488f131b | 3449 | case TARGET_WAITKIND_SYSCALL_RETURN: |
527159b7 | 3450 | if (debug_infrun) |
3e43a32a MS |
3451 | fprintf_unfiltered (gdb_stdlog, |
3452 | "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n"); | |
ca2163eb | 3453 | if (handle_syscall_event (ecs) != 0) |
a96d9b2e SDJ |
3454 | return; |
3455 | goto process_event_stop_test; | |
c906108c | 3456 | |
488f131b | 3457 | case TARGET_WAITKIND_STOPPED: |
527159b7 | 3458 | if (debug_infrun) |
8a9de0e4 | 3459 | fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n"); |
16c381f0 | 3460 | ecs->event_thread->suspend.stop_signal = ecs->ws.value.sig; |
488f131b | 3461 | break; |
c906108c | 3462 | |
b2175913 MS |
3463 | case TARGET_WAITKIND_NO_HISTORY: |
3464 | /* Reverse execution: target ran out of history info. */ | |
fb14de7b | 3465 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
33d62d64 | 3466 | print_no_history_reason (); |
b2175913 MS |
3467 | stop_stepping (ecs); |
3468 | return; | |
488f131b | 3469 | } |
c906108c | 3470 | |
488f131b JB |
3471 | if (ecs->new_thread_event) |
3472 | { | |
94cc34af PA |
3473 | if (non_stop) |
3474 | /* Non-stop assumes that the target handles adding new threads | |
3475 | to the thread list. */ | |
3e43a32a MS |
3476 | internal_error (__FILE__, __LINE__, |
3477 | "targets should add new threads to the thread " | |
3478 | "list themselves in non-stop mode."); | |
94cc34af PA |
3479 | |
3480 | /* We may want to consider not doing a resume here in order to | |
3481 | give the user a chance to play with the new thread. It might | |
3482 | be good to make that a user-settable option. */ | |
3483 | ||
3484 | /* At this point, all threads are stopped (happens automatically | |
3485 | in either the OS or the native code). Therefore we need to | |
3486 | continue all threads in order to make progress. */ | |
3487 | ||
173853dc PA |
3488 | if (!ptid_equal (ecs->ptid, inferior_ptid)) |
3489 | context_switch (ecs->ptid); | |
488f131b JB |
3490 | target_resume (RESUME_ALL, 0, TARGET_SIGNAL_0); |
3491 | prepare_to_wait (ecs); | |
3492 | return; | |
3493 | } | |
c906108c | 3494 | |
2020b7ab | 3495 | if (ecs->ws.kind == TARGET_WAITKIND_STOPPED) |
252fbfc8 PA |
3496 | { |
3497 | /* Do we need to clean up the state of a thread that has | |
3498 | completed a displaced single-step? (Doing so usually affects | |
3499 | the PC, so do it here, before we set stop_pc.) */ | |
16c381f0 JK |
3500 | displaced_step_fixup (ecs->ptid, |
3501 | ecs->event_thread->suspend.stop_signal); | |
252fbfc8 PA |
3502 | |
3503 | /* If we either finished a single-step or hit a breakpoint, but | |
3504 | the user wanted this thread to be stopped, pretend we got a | |
3505 | SIG0 (generic unsignaled stop). */ | |
3506 | ||
3507 | if (ecs->event_thread->stop_requested | |
16c381f0 JK |
3508 | && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
3509 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; | |
252fbfc8 | 3510 | } |
237fc4c9 | 3511 | |
515630c5 | 3512 | stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid)); |
488f131b | 3513 | |
527159b7 | 3514 | if (debug_infrun) |
237fc4c9 | 3515 | { |
5af949e3 UW |
3516 | struct regcache *regcache = get_thread_regcache (ecs->ptid); |
3517 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
7f82dfc7 JK |
3518 | struct cleanup *old_chain = save_inferior_ptid (); |
3519 | ||
3520 | inferior_ptid = ecs->ptid; | |
5af949e3 UW |
3521 | |
3522 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = %s\n", | |
3523 | paddress (gdbarch, stop_pc)); | |
d92524f1 | 3524 | if (target_stopped_by_watchpoint ()) |
237fc4c9 PA |
3525 | { |
3526 | CORE_ADDR addr; | |
abbb1732 | 3527 | |
237fc4c9 PA |
3528 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n"); |
3529 | ||
3530 | if (target_stopped_data_address (¤t_target, &addr)) | |
3531 | fprintf_unfiltered (gdb_stdlog, | |
5af949e3 UW |
3532 | "infrun: stopped data address = %s\n", |
3533 | paddress (gdbarch, addr)); | |
237fc4c9 PA |
3534 | else |
3535 | fprintf_unfiltered (gdb_stdlog, | |
3536 | "infrun: (no data address available)\n"); | |
3537 | } | |
7f82dfc7 JK |
3538 | |
3539 | do_cleanups (old_chain); | |
237fc4c9 | 3540 | } |
527159b7 | 3541 | |
9f976b41 DJ |
3542 | if (stepping_past_singlestep_breakpoint) |
3543 | { | |
1c0fdd0e | 3544 | gdb_assert (singlestep_breakpoints_inserted_p); |
9f976b41 DJ |
3545 | gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid)); |
3546 | gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid)); | |
3547 | ||
3548 | stepping_past_singlestep_breakpoint = 0; | |
3549 | ||
3550 | /* We've either finished single-stepping past the single-step | |
8fb3e588 AC |
3551 | breakpoint, or stopped for some other reason. It would be nice if |
3552 | we could tell, but we can't reliably. */ | |
16c381f0 | 3553 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
8fb3e588 | 3554 | { |
527159b7 | 3555 | if (debug_infrun) |
3e43a32a MS |
3556 | fprintf_unfiltered (gdb_stdlog, |
3557 | "infrun: stepping_past_" | |
3558 | "singlestep_breakpoint\n"); | |
9f976b41 | 3559 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 3560 | remove_single_step_breakpoints (); |
9f976b41 DJ |
3561 | singlestep_breakpoints_inserted_p = 0; |
3562 | ||
3563 | ecs->random_signal = 0; | |
16c381f0 | 3564 | ecs->event_thread->control.trap_expected = 0; |
9f976b41 | 3565 | |
0d1e5fa7 | 3566 | context_switch (saved_singlestep_ptid); |
9a4105ab AC |
3567 | if (deprecated_context_hook) |
3568 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
9f976b41 DJ |
3569 | |
3570 | resume (1, TARGET_SIGNAL_0); | |
3571 | prepare_to_wait (ecs); | |
3572 | return; | |
3573 | } | |
3574 | } | |
3575 | ||
ca67fcb8 | 3576 | if (!ptid_equal (deferred_step_ptid, null_ptid)) |
6a6b96b9 | 3577 | { |
94cc34af PA |
3578 | /* In non-stop mode, there's never a deferred_step_ptid set. */ |
3579 | gdb_assert (!non_stop); | |
3580 | ||
6a6b96b9 UW |
3581 | /* If we stopped for some other reason than single-stepping, ignore |
3582 | the fact that we were supposed to switch back. */ | |
16c381f0 | 3583 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
6a6b96b9 UW |
3584 | { |
3585 | if (debug_infrun) | |
3586 | fprintf_unfiltered (gdb_stdlog, | |
ca67fcb8 | 3587 | "infrun: handling deferred step\n"); |
6a6b96b9 UW |
3588 | |
3589 | /* Pull the single step breakpoints out of the target. */ | |
3590 | if (singlestep_breakpoints_inserted_p) | |
3591 | { | |
3592 | remove_single_step_breakpoints (); | |
3593 | singlestep_breakpoints_inserted_p = 0; | |
3594 | } | |
3595 | ||
3596 | /* Note: We do not call context_switch at this point, as the | |
3597 | context is already set up for stepping the original thread. */ | |
ca67fcb8 VP |
3598 | switch_to_thread (deferred_step_ptid); |
3599 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
3600 | /* Suppress spurious "Switching to ..." message. */ |
3601 | previous_inferior_ptid = inferior_ptid; | |
3602 | ||
3603 | resume (1, TARGET_SIGNAL_0); | |
3604 | prepare_to_wait (ecs); | |
3605 | return; | |
3606 | } | |
ca67fcb8 VP |
3607 | |
3608 | deferred_step_ptid = null_ptid; | |
6a6b96b9 UW |
3609 | } |
3610 | ||
488f131b JB |
3611 | /* See if a thread hit a thread-specific breakpoint that was meant for |
3612 | another thread. If so, then step that thread past the breakpoint, | |
3613 | and continue it. */ | |
3614 | ||
16c381f0 | 3615 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
488f131b | 3616 | { |
9f976b41 | 3617 | int thread_hop_needed = 0; |
cf00dfa7 VP |
3618 | struct address_space *aspace = |
3619 | get_regcache_aspace (get_thread_regcache (ecs->ptid)); | |
9f976b41 | 3620 | |
f8d40ec8 | 3621 | /* Check if a regular breakpoint has been hit before checking |
1777feb0 | 3622 | for a potential single step breakpoint. Otherwise, GDB will |
f8d40ec8 | 3623 | not see this breakpoint hit when stepping onto breakpoints. */ |
6c95b8df | 3624 | if (regular_breakpoint_inserted_here_p (aspace, stop_pc)) |
488f131b | 3625 | { |
c5aa993b | 3626 | ecs->random_signal = 0; |
6c95b8df | 3627 | if (!breakpoint_thread_match (aspace, stop_pc, ecs->ptid)) |
9f976b41 DJ |
3628 | thread_hop_needed = 1; |
3629 | } | |
1c0fdd0e | 3630 | else if (singlestep_breakpoints_inserted_p) |
9f976b41 | 3631 | { |
fd48f117 DJ |
3632 | /* We have not context switched yet, so this should be true |
3633 | no matter which thread hit the singlestep breakpoint. */ | |
3634 | gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid)); | |
3635 | if (debug_infrun) | |
3636 | fprintf_unfiltered (gdb_stdlog, "infrun: software single step " | |
3637 | "trap for %s\n", | |
3638 | target_pid_to_str (ecs->ptid)); | |
3639 | ||
9f976b41 DJ |
3640 | ecs->random_signal = 0; |
3641 | /* The call to in_thread_list is necessary because PTIDs sometimes | |
3642 | change when we go from single-threaded to multi-threaded. If | |
3643 | the singlestep_ptid is still in the list, assume that it is | |
3644 | really different from ecs->ptid. */ | |
3645 | if (!ptid_equal (singlestep_ptid, ecs->ptid) | |
3646 | && in_thread_list (singlestep_ptid)) | |
3647 | { | |
fd48f117 DJ |
3648 | /* If the PC of the thread we were trying to single-step |
3649 | has changed, discard this event (which we were going | |
3650 | to ignore anyway), and pretend we saw that thread | |
3651 | trap. This prevents us continuously moving the | |
3652 | single-step breakpoint forward, one instruction at a | |
3653 | time. If the PC has changed, then the thread we were | |
3654 | trying to single-step has trapped or been signalled, | |
3655 | but the event has not been reported to GDB yet. | |
3656 | ||
3657 | There might be some cases where this loses signal | |
3658 | information, if a signal has arrived at exactly the | |
3659 | same time that the PC changed, but this is the best | |
3660 | we can do with the information available. Perhaps we | |
3661 | should arrange to report all events for all threads | |
3662 | when they stop, or to re-poll the remote looking for | |
3663 | this particular thread (i.e. temporarily enable | |
3664 | schedlock). */ | |
515630c5 UW |
3665 | |
3666 | CORE_ADDR new_singlestep_pc | |
3667 | = regcache_read_pc (get_thread_regcache (singlestep_ptid)); | |
3668 | ||
3669 | if (new_singlestep_pc != singlestep_pc) | |
fd48f117 | 3670 | { |
2020b7ab PA |
3671 | enum target_signal stop_signal; |
3672 | ||
fd48f117 DJ |
3673 | if (debug_infrun) |
3674 | fprintf_unfiltered (gdb_stdlog, "infrun: unexpected thread," | |
3675 | " but expected thread advanced also\n"); | |
3676 | ||
3677 | /* The current context still belongs to | |
3678 | singlestep_ptid. Don't swap here, since that's | |
3679 | the context we want to use. Just fudge our | |
3680 | state and continue. */ | |
16c381f0 JK |
3681 | stop_signal = ecs->event_thread->suspend.stop_signal; |
3682 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; | |
fd48f117 | 3683 | ecs->ptid = singlestep_ptid; |
e09875d4 | 3684 | ecs->event_thread = find_thread_ptid (ecs->ptid); |
16c381f0 | 3685 | ecs->event_thread->suspend.stop_signal = stop_signal; |
515630c5 | 3686 | stop_pc = new_singlestep_pc; |
fd48f117 DJ |
3687 | } |
3688 | else | |
3689 | { | |
3690 | if (debug_infrun) | |
3691 | fprintf_unfiltered (gdb_stdlog, | |
3692 | "infrun: unexpected thread\n"); | |
3693 | ||
3694 | thread_hop_needed = 1; | |
3695 | stepping_past_singlestep_breakpoint = 1; | |
3696 | saved_singlestep_ptid = singlestep_ptid; | |
3697 | } | |
9f976b41 DJ |
3698 | } |
3699 | } | |
3700 | ||
3701 | if (thread_hop_needed) | |
8fb3e588 | 3702 | { |
9f5a595d | 3703 | struct regcache *thread_regcache; |
237fc4c9 | 3704 | int remove_status = 0; |
8fb3e588 | 3705 | |
527159b7 | 3706 | if (debug_infrun) |
8a9de0e4 | 3707 | fprintf_unfiltered (gdb_stdlog, "infrun: thread_hop_needed\n"); |
527159b7 | 3708 | |
b3444185 PA |
3709 | /* Switch context before touching inferior memory, the |
3710 | previous thread may have exited. */ | |
3711 | if (!ptid_equal (inferior_ptid, ecs->ptid)) | |
3712 | context_switch (ecs->ptid); | |
3713 | ||
8fb3e588 | 3714 | /* Saw a breakpoint, but it was hit by the wrong thread. |
1777feb0 | 3715 | Just continue. */ |
8fb3e588 | 3716 | |
1c0fdd0e | 3717 | if (singlestep_breakpoints_inserted_p) |
488f131b | 3718 | { |
1777feb0 | 3719 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 3720 | remove_single_step_breakpoints (); |
8fb3e588 AC |
3721 | singlestep_breakpoints_inserted_p = 0; |
3722 | } | |
3723 | ||
237fc4c9 PA |
3724 | /* If the arch can displace step, don't remove the |
3725 | breakpoints. */ | |
9f5a595d UW |
3726 | thread_regcache = get_thread_regcache (ecs->ptid); |
3727 | if (!use_displaced_stepping (get_regcache_arch (thread_regcache))) | |
237fc4c9 PA |
3728 | remove_status = remove_breakpoints (); |
3729 | ||
8fb3e588 AC |
3730 | /* Did we fail to remove breakpoints? If so, try |
3731 | to set the PC past the bp. (There's at least | |
3732 | one situation in which we can fail to remove | |
3733 | the bp's: On HP-UX's that use ttrace, we can't | |
3734 | change the address space of a vforking child | |
3735 | process until the child exits (well, okay, not | |
1777feb0 | 3736 | then either :-) or execs. */ |
8fb3e588 | 3737 | if (remove_status != 0) |
9d9cd7ac | 3738 | error (_("Cannot step over breakpoint hit in wrong thread")); |
8fb3e588 AC |
3739 | else |
3740 | { /* Single step */ | |
94cc34af PA |
3741 | if (!non_stop) |
3742 | { | |
3743 | /* Only need to require the next event from this | |
3744 | thread in all-stop mode. */ | |
3745 | waiton_ptid = ecs->ptid; | |
3746 | infwait_state = infwait_thread_hop_state; | |
3747 | } | |
8fb3e588 | 3748 | |
4e1c45ea | 3749 | ecs->event_thread->stepping_over_breakpoint = 1; |
8fb3e588 | 3750 | keep_going (ecs); |
8fb3e588 AC |
3751 | return; |
3752 | } | |
488f131b | 3753 | } |
1c0fdd0e | 3754 | else if (singlestep_breakpoints_inserted_p) |
8fb3e588 AC |
3755 | { |
3756 | sw_single_step_trap_p = 1; | |
3757 | ecs->random_signal = 0; | |
3758 | } | |
488f131b JB |
3759 | } |
3760 | else | |
3761 | ecs->random_signal = 1; | |
c906108c | 3762 | |
488f131b | 3763 | /* See if something interesting happened to the non-current thread. If |
b40c7d58 DJ |
3764 | so, then switch to that thread. */ |
3765 | if (!ptid_equal (ecs->ptid, inferior_ptid)) | |
488f131b | 3766 | { |
527159b7 | 3767 | if (debug_infrun) |
8a9de0e4 | 3768 | fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n"); |
527159b7 | 3769 | |
0d1e5fa7 | 3770 | context_switch (ecs->ptid); |
c5aa993b | 3771 | |
9a4105ab AC |
3772 | if (deprecated_context_hook) |
3773 | deprecated_context_hook (pid_to_thread_id (ecs->ptid)); | |
488f131b | 3774 | } |
c906108c | 3775 | |
568d6575 UW |
3776 | /* At this point, get hold of the now-current thread's frame. */ |
3777 | frame = get_current_frame (); | |
3778 | gdbarch = get_frame_arch (frame); | |
3779 | ||
1c0fdd0e | 3780 | if (singlestep_breakpoints_inserted_p) |
488f131b | 3781 | { |
1777feb0 | 3782 | /* Pull the single step breakpoints out of the target. */ |
e0cd558a | 3783 | remove_single_step_breakpoints (); |
488f131b JB |
3784 | singlestep_breakpoints_inserted_p = 0; |
3785 | } | |
c906108c | 3786 | |
d983da9c DJ |
3787 | if (stepped_after_stopped_by_watchpoint) |
3788 | stopped_by_watchpoint = 0; | |
3789 | else | |
3790 | stopped_by_watchpoint = watchpoints_triggered (&ecs->ws); | |
3791 | ||
3792 | /* If necessary, step over this watchpoint. We'll be back to display | |
3793 | it in a moment. */ | |
3794 | if (stopped_by_watchpoint | |
d92524f1 | 3795 | && (target_have_steppable_watchpoint |
568d6575 | 3796 | || gdbarch_have_nonsteppable_watchpoint (gdbarch))) |
488f131b | 3797 | { |
488f131b JB |
3798 | /* At this point, we are stopped at an instruction which has |
3799 | attempted to write to a piece of memory under control of | |
3800 | a watchpoint. The instruction hasn't actually executed | |
3801 | yet. If we were to evaluate the watchpoint expression | |
3802 | now, we would get the old value, and therefore no change | |
3803 | would seem to have occurred. | |
3804 | ||
3805 | In order to make watchpoints work `right', we really need | |
3806 | to complete the memory write, and then evaluate the | |
d983da9c DJ |
3807 | watchpoint expression. We do this by single-stepping the |
3808 | target. | |
3809 | ||
3810 | It may not be necessary to disable the watchpoint to stop over | |
3811 | it. For example, the PA can (with some kernel cooperation) | |
3812 | single step over a watchpoint without disabling the watchpoint. | |
3813 | ||
3814 | It is far more common to need to disable a watchpoint to step | |
3815 | the inferior over it. If we have non-steppable watchpoints, | |
3816 | we must disable the current watchpoint; it's simplest to | |
3817 | disable all watchpoints and breakpoints. */ | |
2facfe5c DD |
3818 | int hw_step = 1; |
3819 | ||
d92524f1 | 3820 | if (!target_have_steppable_watchpoint) |
d983da9c | 3821 | remove_breakpoints (); |
2facfe5c | 3822 | /* Single step */ |
568d6575 | 3823 | hw_step = maybe_software_singlestep (gdbarch, stop_pc); |
2facfe5c | 3824 | target_resume (ecs->ptid, hw_step, TARGET_SIGNAL_0); |
0d1e5fa7 | 3825 | waiton_ptid = ecs->ptid; |
d92524f1 | 3826 | if (target_have_steppable_watchpoint) |
0d1e5fa7 | 3827 | infwait_state = infwait_step_watch_state; |
d983da9c | 3828 | else |
0d1e5fa7 | 3829 | infwait_state = infwait_nonstep_watch_state; |
488f131b JB |
3830 | prepare_to_wait (ecs); |
3831 | return; | |
3832 | } | |
3833 | ||
488f131b JB |
3834 | ecs->stop_func_start = 0; |
3835 | ecs->stop_func_end = 0; | |
3836 | ecs->stop_func_name = 0; | |
3837 | /* Don't care about return value; stop_func_start and stop_func_name | |
3838 | will both be 0 if it doesn't work. */ | |
3839 | find_pc_partial_function (stop_pc, &ecs->stop_func_name, | |
3840 | &ecs->stop_func_start, &ecs->stop_func_end); | |
cbf3b44a | 3841 | ecs->stop_func_start |
568d6575 | 3842 | += gdbarch_deprecated_function_start_offset (gdbarch); |
4e1c45ea | 3843 | ecs->event_thread->stepping_over_breakpoint = 0; |
16c381f0 JK |
3844 | bpstat_clear (&ecs->event_thread->control.stop_bpstat); |
3845 | ecs->event_thread->control.stop_step = 0; | |
488f131b JB |
3846 | stop_print_frame = 1; |
3847 | ecs->random_signal = 0; | |
3848 | stopped_by_random_signal = 0; | |
488f131b | 3849 | |
edb3359d DJ |
3850 | /* Hide inlined functions starting here, unless we just performed stepi or |
3851 | nexti. After stepi and nexti, always show the innermost frame (not any | |
3852 | inline function call sites). */ | |
16c381f0 | 3853 | if (ecs->event_thread->control.step_range_end != 1) |
edb3359d DJ |
3854 | skip_inline_frames (ecs->ptid); |
3855 | ||
16c381f0 JK |
3856 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
3857 | && ecs->event_thread->control.trap_expected | |
568d6575 | 3858 | && gdbarch_single_step_through_delay_p (gdbarch) |
4e1c45ea | 3859 | && currently_stepping (ecs->event_thread)) |
3352ef37 | 3860 | { |
b50d7442 | 3861 | /* We're trying to step off a breakpoint. Turns out that we're |
3352ef37 | 3862 | also on an instruction that needs to be stepped multiple |
1777feb0 | 3863 | times before it's been fully executing. E.g., architectures |
3352ef37 AC |
3864 | with a delay slot. It needs to be stepped twice, once for |
3865 | the instruction and once for the delay slot. */ | |
3866 | int step_through_delay | |
568d6575 | 3867 | = gdbarch_single_step_through_delay (gdbarch, frame); |
abbb1732 | 3868 | |
527159b7 | 3869 | if (debug_infrun && step_through_delay) |
8a9de0e4 | 3870 | fprintf_unfiltered (gdb_stdlog, "infrun: step through delay\n"); |
16c381f0 JK |
3871 | if (ecs->event_thread->control.step_range_end == 0 |
3872 | && step_through_delay) | |
3352ef37 AC |
3873 | { |
3874 | /* The user issued a continue when stopped at a breakpoint. | |
3875 | Set up for another trap and get out of here. */ | |
4e1c45ea | 3876 | ecs->event_thread->stepping_over_breakpoint = 1; |
3352ef37 AC |
3877 | keep_going (ecs); |
3878 | return; | |
3879 | } | |
3880 | else if (step_through_delay) | |
3881 | { | |
3882 | /* The user issued a step when stopped at a breakpoint. | |
3883 | Maybe we should stop, maybe we should not - the delay | |
3884 | slot *might* correspond to a line of source. In any | |
ca67fcb8 VP |
3885 | case, don't decide that here, just set |
3886 | ecs->stepping_over_breakpoint, making sure we | |
3887 | single-step again before breakpoints are re-inserted. */ | |
4e1c45ea | 3888 | ecs->event_thread->stepping_over_breakpoint = 1; |
3352ef37 AC |
3889 | } |
3890 | } | |
3891 | ||
488f131b JB |
3892 | /* Look at the cause of the stop, and decide what to do. |
3893 | The alternatives are: | |
0d1e5fa7 PA |
3894 | 1) stop_stepping and return; to really stop and return to the debugger, |
3895 | 2) keep_going and return to start up again | |
4e1c45ea | 3896 | (set ecs->event_thread->stepping_over_breakpoint to 1 to single step once) |
488f131b JB |
3897 | 3) set ecs->random_signal to 1, and the decision between 1 and 2 |
3898 | will be made according to the signal handling tables. */ | |
3899 | ||
16c381f0 | 3900 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
b0f4b84b DJ |
3901 | || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP |
3902 | || stop_soon == STOP_QUIETLY_REMOTE) | |
488f131b | 3903 | { |
16c381f0 JK |
3904 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
3905 | && stop_after_trap) | |
488f131b | 3906 | { |
527159b7 | 3907 | if (debug_infrun) |
8a9de0e4 | 3908 | fprintf_unfiltered (gdb_stdlog, "infrun: stopped\n"); |
488f131b JB |
3909 | stop_print_frame = 0; |
3910 | stop_stepping (ecs); | |
3911 | return; | |
3912 | } | |
c54cfec8 EZ |
3913 | |
3914 | /* This is originated from start_remote(), start_inferior() and | |
3915 | shared libraries hook functions. */ | |
b0f4b84b | 3916 | if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) |
488f131b | 3917 | { |
527159b7 | 3918 | if (debug_infrun) |
8a9de0e4 | 3919 | fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); |
488f131b JB |
3920 | stop_stepping (ecs); |
3921 | return; | |
3922 | } | |
3923 | ||
c54cfec8 | 3924 | /* This originates from attach_command(). We need to overwrite |
a0d21d28 PA |
3925 | the stop_signal here, because some kernels don't ignore a |
3926 | SIGSTOP in a subsequent ptrace(PTRACE_CONT,SIGSTOP) call. | |
3927 | See more comments in inferior.h. On the other hand, if we | |
a0ef4274 | 3928 | get a non-SIGSTOP, report it to the user - assume the backend |
a0d21d28 PA |
3929 | will handle the SIGSTOP if it should show up later. |
3930 | ||
3931 | Also consider that the attach is complete when we see a | |
3932 | SIGTRAP. Some systems (e.g. Windows), and stubs supporting | |
3933 | target extended-remote report it instead of a SIGSTOP | |
3934 | (e.g. gdbserver). We already rely on SIGTRAP being our | |
e0ba6746 PA |
3935 | signal, so this is no exception. |
3936 | ||
3937 | Also consider that the attach is complete when we see a | |
3938 | TARGET_SIGNAL_0. In non-stop mode, GDB will explicitly tell | |
3939 | the target to stop all threads of the inferior, in case the | |
3940 | low level attach operation doesn't stop them implicitly. If | |
3941 | they weren't stopped implicitly, then the stub will report a | |
3942 | TARGET_SIGNAL_0, meaning: stopped for no particular reason | |
3943 | other than GDB's request. */ | |
a0ef4274 | 3944 | if (stop_soon == STOP_QUIETLY_NO_SIGSTOP |
16c381f0 JK |
3945 | && (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_STOP |
3946 | || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP | |
3947 | || ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_0)) | |
c54cfec8 EZ |
3948 | { |
3949 | stop_stepping (ecs); | |
16c381f0 | 3950 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; |
c54cfec8 EZ |
3951 | return; |
3952 | } | |
3953 | ||
fba57f8f | 3954 | /* See if there is a breakpoint at the current PC. */ |
16c381f0 | 3955 | ecs->event_thread->control.stop_bpstat |
6c95b8df PA |
3956 | = bpstat_stop_status (get_regcache_aspace (get_current_regcache ()), |
3957 | stop_pc, ecs->ptid); | |
3958 | ||
fba57f8f VP |
3959 | /* Following in case break condition called a |
3960 | function. */ | |
3961 | stop_print_frame = 1; | |
488f131b | 3962 | |
db82e815 PA |
3963 | /* This is where we handle "moribund" watchpoints. Unlike |
3964 | software breakpoints traps, hardware watchpoint traps are | |
3965 | always distinguishable from random traps. If no high-level | |
3966 | watchpoint is associated with the reported stop data address | |
3967 | anymore, then the bpstat does not explain the signal --- | |
3968 | simply make sure to ignore it if `stopped_by_watchpoint' is | |
3969 | set. */ | |
3970 | ||
3971 | if (debug_infrun | |
16c381f0 JK |
3972 | && ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
3973 | && !bpstat_explains_signal (ecs->event_thread->control.stop_bpstat) | |
db82e815 | 3974 | && stopped_by_watchpoint) |
3e43a32a MS |
3975 | fprintf_unfiltered (gdb_stdlog, |
3976 | "infrun: no user watchpoint explains " | |
3977 | "watchpoint SIGTRAP, ignoring\n"); | |
db82e815 | 3978 | |
73dd234f | 3979 | /* NOTE: cagney/2003-03-29: These two checks for a random signal |
8fb3e588 AC |
3980 | at one stage in the past included checks for an inferior |
3981 | function call's call dummy's return breakpoint. The original | |
3982 | comment, that went with the test, read: | |
73dd234f | 3983 | |
8fb3e588 AC |
3984 | ``End of a stack dummy. Some systems (e.g. Sony news) give |
3985 | another signal besides SIGTRAP, so check here as well as | |
3986 | above.'' | |
73dd234f | 3987 | |
8002d778 | 3988 | If someone ever tries to get call dummys on a |
73dd234f | 3989 | non-executable stack to work (where the target would stop |
03cebad2 MK |
3990 | with something like a SIGSEGV), then those tests might need |
3991 | to be re-instated. Given, however, that the tests were only | |
73dd234f | 3992 | enabled when momentary breakpoints were not being used, I |
03cebad2 MK |
3993 | suspect that it won't be the case. |
3994 | ||
8fb3e588 AC |
3995 | NOTE: kettenis/2004-02-05: Indeed such checks don't seem to |
3996 | be necessary for call dummies on a non-executable stack on | |
3997 | SPARC. */ | |
73dd234f | 3998 | |
16c381f0 | 3999 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP) |
488f131b | 4000 | ecs->random_signal |
16c381f0 | 4001 | = !(bpstat_explains_signal (ecs->event_thread->control.stop_bpstat) |
db82e815 | 4002 | || stopped_by_watchpoint |
16c381f0 JK |
4003 | || ecs->event_thread->control.trap_expected |
4004 | || (ecs->event_thread->control.step_range_end | |
8358c15c JK |
4005 | && (ecs->event_thread->control.step_resume_breakpoint |
4006 | == NULL))); | |
488f131b JB |
4007 | else |
4008 | { | |
16c381f0 JK |
4009 | ecs->random_signal = !bpstat_explains_signal |
4010 | (ecs->event_thread->control.stop_bpstat); | |
488f131b | 4011 | if (!ecs->random_signal) |
16c381f0 | 4012 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_TRAP; |
488f131b JB |
4013 | } |
4014 | } | |
4015 | ||
4016 | /* When we reach this point, we've pretty much decided | |
4017 | that the reason for stopping must've been a random | |
1777feb0 | 4018 | (unexpected) signal. */ |
488f131b JB |
4019 | |
4020 | else | |
4021 | ecs->random_signal = 1; | |
488f131b | 4022 | |
04e68871 | 4023 | process_event_stop_test: |
568d6575 UW |
4024 | |
4025 | /* Re-fetch current thread's frame in case we did a | |
4026 | "goto process_event_stop_test" above. */ | |
4027 | frame = get_current_frame (); | |
4028 | gdbarch = get_frame_arch (frame); | |
4029 | ||
488f131b JB |
4030 | /* For the program's own signals, act according to |
4031 | the signal handling tables. */ | |
4032 | ||
4033 | if (ecs->random_signal) | |
4034 | { | |
4035 | /* Signal not for debugging purposes. */ | |
4036 | int printed = 0; | |
24291992 | 4037 | struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid)); |
488f131b | 4038 | |
527159b7 | 4039 | if (debug_infrun) |
2020b7ab | 4040 | fprintf_unfiltered (gdb_stdlog, "infrun: random signal %d\n", |
16c381f0 | 4041 | ecs->event_thread->suspend.stop_signal); |
527159b7 | 4042 | |
488f131b JB |
4043 | stopped_by_random_signal = 1; |
4044 | ||
16c381f0 | 4045 | if (signal_print[ecs->event_thread->suspend.stop_signal]) |
488f131b JB |
4046 | { |
4047 | printed = 1; | |
4048 | target_terminal_ours_for_output (); | |
16c381f0 JK |
4049 | print_signal_received_reason |
4050 | (ecs->event_thread->suspend.stop_signal); | |
488f131b | 4051 | } |
252fbfc8 PA |
4052 | /* Always stop on signals if we're either just gaining control |
4053 | of the program, or the user explicitly requested this thread | |
4054 | to remain stopped. */ | |
d6b48e9c | 4055 | if (stop_soon != NO_STOP_QUIETLY |
252fbfc8 | 4056 | || ecs->event_thread->stop_requested |
24291992 | 4057 | || (!inf->detaching |
16c381f0 | 4058 | && signal_stop_state (ecs->event_thread->suspend.stop_signal))) |
488f131b JB |
4059 | { |
4060 | stop_stepping (ecs); | |
4061 | return; | |
4062 | } | |
4063 | /* If not going to stop, give terminal back | |
4064 | if we took it away. */ | |
4065 | else if (printed) | |
4066 | target_terminal_inferior (); | |
4067 | ||
4068 | /* Clear the signal if it should not be passed. */ | |
16c381f0 JK |
4069 | if (signal_program[ecs->event_thread->suspend.stop_signal] == 0) |
4070 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; | |
488f131b | 4071 | |
fb14de7b | 4072 | if (ecs->event_thread->prev_pc == stop_pc |
16c381f0 | 4073 | && ecs->event_thread->control.trap_expected |
8358c15c | 4074 | && ecs->event_thread->control.step_resume_breakpoint == NULL) |
68f53502 AC |
4075 | { |
4076 | /* We were just starting a new sequence, attempting to | |
4077 | single-step off of a breakpoint and expecting a SIGTRAP. | |
237fc4c9 | 4078 | Instead this signal arrives. This signal will take us out |
68f53502 AC |
4079 | of the stepping range so GDB needs to remember to, when |
4080 | the signal handler returns, resume stepping off that | |
4081 | breakpoint. */ | |
4082 | /* To simplify things, "continue" is forced to use the same | |
4083 | code paths as single-step - set a breakpoint at the | |
4084 | signal return address and then, once hit, step off that | |
4085 | breakpoint. */ | |
237fc4c9 PA |
4086 | if (debug_infrun) |
4087 | fprintf_unfiltered (gdb_stdlog, | |
4088 | "infrun: signal arrived while stepping over " | |
4089 | "breakpoint\n"); | |
d3169d93 | 4090 | |
568d6575 | 4091 | insert_step_resume_breakpoint_at_frame (frame); |
4e1c45ea | 4092 | ecs->event_thread->step_after_step_resume_breakpoint = 1; |
9d799f85 AC |
4093 | keep_going (ecs); |
4094 | return; | |
68f53502 | 4095 | } |
9d799f85 | 4096 | |
16c381f0 JK |
4097 | if (ecs->event_thread->control.step_range_end != 0 |
4098 | && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_0 | |
4099 | && (ecs->event_thread->control.step_range_start <= stop_pc | |
4100 | && stop_pc < ecs->event_thread->control.step_range_end) | |
edb3359d | 4101 | && frame_id_eq (get_stack_frame_id (frame), |
16c381f0 | 4102 | ecs->event_thread->control.step_stack_frame_id) |
8358c15c | 4103 | && ecs->event_thread->control.step_resume_breakpoint == NULL) |
d303a6c7 AC |
4104 | { |
4105 | /* The inferior is about to take a signal that will take it | |
4106 | out of the single step range. Set a breakpoint at the | |
4107 | current PC (which is presumably where the signal handler | |
4108 | will eventually return) and then allow the inferior to | |
4109 | run free. | |
4110 | ||
4111 | Note that this is only needed for a signal delivered | |
4112 | while in the single-step range. Nested signals aren't a | |
4113 | problem as they eventually all return. */ | |
237fc4c9 PA |
4114 | if (debug_infrun) |
4115 | fprintf_unfiltered (gdb_stdlog, | |
4116 | "infrun: signal may take us out of " | |
4117 | "single-step range\n"); | |
4118 | ||
568d6575 | 4119 | insert_step_resume_breakpoint_at_frame (frame); |
9d799f85 AC |
4120 | keep_going (ecs); |
4121 | return; | |
d303a6c7 | 4122 | } |
9d799f85 AC |
4123 | |
4124 | /* Note: step_resume_breakpoint may be non-NULL. This occures | |
4125 | when either there's a nested signal, or when there's a | |
4126 | pending signal enabled just as the signal handler returns | |
4127 | (leaving the inferior at the step-resume-breakpoint without | |
4128 | actually executing it). Either way continue until the | |
4129 | breakpoint is really hit. */ | |
488f131b JB |
4130 | keep_going (ecs); |
4131 | return; | |
4132 | } | |
4133 | ||
4134 | /* Handle cases caused by hitting a breakpoint. */ | |
4135 | { | |
4136 | CORE_ADDR jmp_buf_pc; | |
4137 | struct bpstat_what what; | |
4138 | ||
16c381f0 | 4139 | what = bpstat_what (ecs->event_thread->control.stop_bpstat); |
488f131b JB |
4140 | |
4141 | if (what.call_dummy) | |
4142 | { | |
aa7d318d | 4143 | stop_stack_dummy = what.call_dummy; |
c5aa993b | 4144 | } |
c906108c | 4145 | |
628fe4e4 JK |
4146 | /* If we hit an internal event that triggers symbol changes, the |
4147 | current frame will be invalidated within bpstat_what (e.g., if | |
4148 | we hit an internal solib event). Re-fetch it. */ | |
4149 | frame = get_current_frame (); | |
4150 | gdbarch = get_frame_arch (frame); | |
4151 | ||
488f131b | 4152 | switch (what.main_action) |
c5aa993b | 4153 | { |
488f131b | 4154 | case BPSTAT_WHAT_SET_LONGJMP_RESUME: |
611c83ae PA |
4155 | /* If we hit the breakpoint at longjmp while stepping, we |
4156 | install a momentary breakpoint at the target of the | |
4157 | jmp_buf. */ | |
4158 | ||
4159 | if (debug_infrun) | |
4160 | fprintf_unfiltered (gdb_stdlog, | |
4161 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME\n"); | |
4162 | ||
4e1c45ea | 4163 | ecs->event_thread->stepping_over_breakpoint = 1; |
611c83ae | 4164 | |
186c406b | 4165 | if (what.is_longjmp) |
c5aa993b | 4166 | { |
186c406b TT |
4167 | if (!gdbarch_get_longjmp_target_p (gdbarch) |
4168 | || !gdbarch_get_longjmp_target (gdbarch, | |
4169 | frame, &jmp_buf_pc)) | |
4170 | { | |
4171 | if (debug_infrun) | |
3e43a32a MS |
4172 | fprintf_unfiltered (gdb_stdlog, |
4173 | "infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME " | |
4174 | "(!gdbarch_get_longjmp_target)\n"); | |
186c406b TT |
4175 | keep_going (ecs); |
4176 | return; | |
4177 | } | |
488f131b | 4178 | |
186c406b TT |
4179 | /* We're going to replace the current step-resume breakpoint |
4180 | with a longjmp-resume breakpoint. */ | |
4181 | delete_step_resume_breakpoint (ecs->event_thread); | |
611c83ae | 4182 | |
186c406b TT |
4183 | /* Insert a breakpoint at resume address. */ |
4184 | insert_longjmp_resume_breakpoint (gdbarch, jmp_buf_pc); | |
4185 | } | |
4186 | else | |
4187 | { | |
4188 | struct symbol *func = get_frame_function (frame); | |
c906108c | 4189 | |
186c406b TT |
4190 | if (func) |
4191 | check_exception_resume (ecs, frame, func); | |
4192 | } | |
488f131b JB |
4193 | keep_going (ecs); |
4194 | return; | |
c906108c | 4195 | |
488f131b | 4196 | case BPSTAT_WHAT_CLEAR_LONGJMP_RESUME: |
527159b7 | 4197 | if (debug_infrun) |
611c83ae PA |
4198 | fprintf_unfiltered (gdb_stdlog, |
4199 | "infrun: BPSTAT_WHAT_CLEAR_LONGJMP_RESUME\n"); | |
4200 | ||
186c406b TT |
4201 | if (what.is_longjmp) |
4202 | { | |
4203 | gdb_assert (ecs->event_thread->control.step_resume_breakpoint | |
4204 | != NULL); | |
4205 | delete_step_resume_breakpoint (ecs->event_thread); | |
4206 | } | |
4207 | else | |
4208 | { | |
4209 | /* There are several cases to consider. | |
4210 | ||
4211 | 1. The initiating frame no longer exists. In this case | |
4212 | we must stop, because the exception has gone too far. | |
4213 | ||
4214 | 2. The initiating frame exists, and is the same as the | |
4215 | current frame. We stop, because the exception has been | |
4216 | caught. | |
4217 | ||
4218 | 3. The initiating frame exists and is different from | |
4219 | the current frame. This means the exception has been | |
4220 | caught beneath the initiating frame, so keep going. */ | |
4221 | struct frame_info *init_frame | |
4222 | = frame_find_by_id (ecs->event_thread->initiating_frame); | |
4223 | ||
4224 | gdb_assert (ecs->event_thread->control.exception_resume_breakpoint | |
4225 | != NULL); | |
4226 | delete_exception_resume_breakpoint (ecs->event_thread); | |
4227 | ||
4228 | if (init_frame) | |
4229 | { | |
4230 | struct frame_id current_id | |
4231 | = get_frame_id (get_current_frame ()); | |
4232 | if (frame_id_eq (current_id, | |
4233 | ecs->event_thread->initiating_frame)) | |
4234 | { | |
4235 | /* Case 2. Fall through. */ | |
4236 | } | |
4237 | else | |
4238 | { | |
4239 | /* Case 3. */ | |
4240 | keep_going (ecs); | |
4241 | return; | |
4242 | } | |
4243 | } | |
4244 | ||
4245 | /* For Cases 1 and 2, remove the step-resume breakpoint, | |
4246 | if it exists. */ | |
4247 | delete_step_resume_breakpoint (ecs->event_thread); | |
4248 | } | |
611c83ae | 4249 | |
16c381f0 | 4250 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4251 | print_end_stepping_range_reason (); |
611c83ae PA |
4252 | stop_stepping (ecs); |
4253 | return; | |
488f131b JB |
4254 | |
4255 | case BPSTAT_WHAT_SINGLE: | |
527159b7 | 4256 | if (debug_infrun) |
8802d8ed | 4257 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_SINGLE\n"); |
4e1c45ea | 4258 | ecs->event_thread->stepping_over_breakpoint = 1; |
488f131b JB |
4259 | /* Still need to check other stuff, at least the case |
4260 | where we are stepping and step out of the right range. */ | |
4261 | break; | |
c906108c | 4262 | |
488f131b | 4263 | case BPSTAT_WHAT_STOP_NOISY: |
527159b7 | 4264 | if (debug_infrun) |
8802d8ed | 4265 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_NOISY\n"); |
488f131b | 4266 | stop_print_frame = 1; |
c906108c | 4267 | |
d303a6c7 AC |
4268 | /* We are about to nuke the step_resume_breakpointt via the |
4269 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 4270 | |
488f131b JB |
4271 | stop_stepping (ecs); |
4272 | return; | |
c5aa993b | 4273 | |
488f131b | 4274 | case BPSTAT_WHAT_STOP_SILENT: |
527159b7 | 4275 | if (debug_infrun) |
8802d8ed | 4276 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STOP_SILENT\n"); |
488f131b | 4277 | stop_print_frame = 0; |
c5aa993b | 4278 | |
d303a6c7 AC |
4279 | /* We are about to nuke the step_resume_breakpoin via the |
4280 | cleanup chain, so no need to worry about it here. */ | |
c5aa993b | 4281 | |
488f131b | 4282 | stop_stepping (ecs); |
e441088d | 4283 | return; |
c5aa993b | 4284 | |
488f131b | 4285 | case BPSTAT_WHAT_STEP_RESUME: |
527159b7 | 4286 | if (debug_infrun) |
8802d8ed | 4287 | fprintf_unfiltered (gdb_stdlog, "infrun: BPSTAT_WHAT_STEP_RESUME\n"); |
527159b7 | 4288 | |
4e1c45ea PA |
4289 | delete_step_resume_breakpoint (ecs->event_thread); |
4290 | if (ecs->event_thread->step_after_step_resume_breakpoint) | |
68f53502 AC |
4291 | { |
4292 | /* Back when the step-resume breakpoint was inserted, we | |
4293 | were trying to single-step off a breakpoint. Go back | |
4294 | to doing that. */ | |
4e1c45ea PA |
4295 | ecs->event_thread->step_after_step_resume_breakpoint = 0; |
4296 | ecs->event_thread->stepping_over_breakpoint = 1; | |
68f53502 AC |
4297 | keep_going (ecs); |
4298 | return; | |
4299 | } | |
b2175913 MS |
4300 | if (stop_pc == ecs->stop_func_start |
4301 | && execution_direction == EXEC_REVERSE) | |
4302 | { | |
4303 | /* We are stepping over a function call in reverse, and | |
4304 | just hit the step-resume breakpoint at the start | |
4305 | address of the function. Go back to single-stepping, | |
4306 | which should take us back to the function call. */ | |
4307 | ecs->event_thread->stepping_over_breakpoint = 1; | |
4308 | keep_going (ecs); | |
4309 | return; | |
4310 | } | |
488f131b JB |
4311 | break; |
4312 | ||
488f131b JB |
4313 | case BPSTAT_WHAT_KEEP_CHECKING: |
4314 | break; | |
4315 | } | |
4316 | } | |
c906108c | 4317 | |
488f131b JB |
4318 | /* We come here if we hit a breakpoint but should not |
4319 | stop for it. Possibly we also were stepping | |
4320 | and should stop for that. So fall through and | |
4321 | test for stepping. But, if not stepping, | |
4322 | do not stop. */ | |
c906108c | 4323 | |
a7212384 UW |
4324 | /* In all-stop mode, if we're currently stepping but have stopped in |
4325 | some other thread, we need to switch back to the stepped thread. */ | |
4326 | if (!non_stop) | |
4327 | { | |
4328 | struct thread_info *tp; | |
abbb1732 | 4329 | |
b3444185 | 4330 | tp = iterate_over_threads (currently_stepping_or_nexting_callback, |
a7212384 UW |
4331 | ecs->event_thread); |
4332 | if (tp) | |
4333 | { | |
4334 | /* However, if the current thread is blocked on some internal | |
4335 | breakpoint, and we simply need to step over that breakpoint | |
4336 | to get it going again, do that first. */ | |
16c381f0 JK |
4337 | if ((ecs->event_thread->control.trap_expected |
4338 | && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP) | |
a7212384 UW |
4339 | || ecs->event_thread->stepping_over_breakpoint) |
4340 | { | |
4341 | keep_going (ecs); | |
4342 | return; | |
4343 | } | |
4344 | ||
66852e9c PA |
4345 | /* If the stepping thread exited, then don't try to switch |
4346 | back and resume it, which could fail in several different | |
4347 | ways depending on the target. Instead, just keep going. | |
4348 | ||
4349 | We can find a stepping dead thread in the thread list in | |
4350 | two cases: | |
4351 | ||
4352 | - The target supports thread exit events, and when the | |
4353 | target tries to delete the thread from the thread list, | |
4354 | inferior_ptid pointed at the exiting thread. In such | |
4355 | case, calling delete_thread does not really remove the | |
4356 | thread from the list; instead, the thread is left listed, | |
4357 | with 'exited' state. | |
4358 | ||
4359 | - The target's debug interface does not support thread | |
4360 | exit events, and so we have no idea whatsoever if the | |
4361 | previously stepping thread is still alive. For that | |
4362 | reason, we need to synchronously query the target | |
4363 | now. */ | |
b3444185 PA |
4364 | if (is_exited (tp->ptid) |
4365 | || !target_thread_alive (tp->ptid)) | |
4366 | { | |
4367 | if (debug_infrun) | |
3e43a32a MS |
4368 | fprintf_unfiltered (gdb_stdlog, |
4369 | "infrun: not switching back to " | |
4370 | "stepped thread, it has vanished\n"); | |
b3444185 PA |
4371 | |
4372 | delete_thread (tp->ptid); | |
4373 | keep_going (ecs); | |
4374 | return; | |
4375 | } | |
4376 | ||
a7212384 UW |
4377 | /* Otherwise, we no longer expect a trap in the current thread. |
4378 | Clear the trap_expected flag before switching back -- this is | |
4379 | what keep_going would do as well, if we called it. */ | |
16c381f0 | 4380 | ecs->event_thread->control.trap_expected = 0; |
a7212384 UW |
4381 | |
4382 | if (debug_infrun) | |
4383 | fprintf_unfiltered (gdb_stdlog, | |
4384 | "infrun: switching back to stepped thread\n"); | |
4385 | ||
4386 | ecs->event_thread = tp; | |
4387 | ecs->ptid = tp->ptid; | |
4388 | context_switch (ecs->ptid); | |
4389 | keep_going (ecs); | |
4390 | return; | |
4391 | } | |
4392 | } | |
4393 | ||
9d1ff73f MS |
4394 | /* Are we stepping to get the inferior out of the dynamic linker's |
4395 | hook (and possibly the dld itself) after catching a shlib | |
4396 | event? */ | |
4e1c45ea | 4397 | if (ecs->event_thread->stepping_through_solib_after_catch) |
488f131b JB |
4398 | { |
4399 | #if defined(SOLIB_ADD) | |
1777feb0 | 4400 | /* Have we reached our destination? If not, keep going. */ |
488f131b JB |
4401 | if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc)) |
4402 | { | |
527159b7 | 4403 | if (debug_infrun) |
3e43a32a MS |
4404 | fprintf_unfiltered (gdb_stdlog, |
4405 | "infrun: stepping in dynamic linker\n"); | |
4e1c45ea | 4406 | ecs->event_thread->stepping_over_breakpoint = 1; |
488f131b | 4407 | keep_going (ecs); |
104c1213 | 4408 | return; |
488f131b JB |
4409 | } |
4410 | #endif | |
527159b7 | 4411 | if (debug_infrun) |
8a9de0e4 | 4412 | fprintf_unfiltered (gdb_stdlog, "infrun: step past dynamic linker\n"); |
488f131b | 4413 | /* Else, stop and report the catchpoint(s) whose triggering |
1777feb0 | 4414 | caused us to begin stepping. */ |
4e1c45ea | 4415 | ecs->event_thread->stepping_through_solib_after_catch = 0; |
16c381f0 JK |
4416 | bpstat_clear (&ecs->event_thread->control.stop_bpstat); |
4417 | ecs->event_thread->control.stop_bpstat | |
347bddb7 | 4418 | = bpstat_copy (ecs->event_thread->stepping_through_solib_catchpoints); |
4e1c45ea | 4419 | bpstat_clear (&ecs->event_thread->stepping_through_solib_catchpoints); |
488f131b JB |
4420 | stop_print_frame = 1; |
4421 | stop_stepping (ecs); | |
4422 | return; | |
4423 | } | |
c906108c | 4424 | |
8358c15c | 4425 | if (ecs->event_thread->control.step_resume_breakpoint) |
488f131b | 4426 | { |
527159b7 | 4427 | if (debug_infrun) |
d3169d93 DJ |
4428 | fprintf_unfiltered (gdb_stdlog, |
4429 | "infrun: step-resume breakpoint is inserted\n"); | |
527159b7 | 4430 | |
488f131b JB |
4431 | /* Having a step-resume breakpoint overrides anything |
4432 | else having to do with stepping commands until | |
4433 | that breakpoint is reached. */ | |
488f131b JB |
4434 | keep_going (ecs); |
4435 | return; | |
4436 | } | |
c5aa993b | 4437 | |
16c381f0 | 4438 | if (ecs->event_thread->control.step_range_end == 0) |
488f131b | 4439 | { |
527159b7 | 4440 | if (debug_infrun) |
8a9de0e4 | 4441 | fprintf_unfiltered (gdb_stdlog, "infrun: no stepping, continue\n"); |
488f131b | 4442 | /* Likewise if we aren't even stepping. */ |
488f131b JB |
4443 | keep_going (ecs); |
4444 | return; | |
4445 | } | |
c5aa993b | 4446 | |
4b7703ad JB |
4447 | /* Re-fetch current thread's frame in case the code above caused |
4448 | the frame cache to be re-initialized, making our FRAME variable | |
4449 | a dangling pointer. */ | |
4450 | frame = get_current_frame (); | |
628fe4e4 | 4451 | gdbarch = get_frame_arch (frame); |
4b7703ad | 4452 | |
488f131b | 4453 | /* If stepping through a line, keep going if still within it. |
c906108c | 4454 | |
488f131b JB |
4455 | Note that step_range_end is the address of the first instruction |
4456 | beyond the step range, and NOT the address of the last instruction | |
31410e84 MS |
4457 | within it! |
4458 | ||
4459 | Note also that during reverse execution, we may be stepping | |
4460 | through a function epilogue and therefore must detect when | |
4461 | the current-frame changes in the middle of a line. */ | |
4462 | ||
16c381f0 JK |
4463 | if (stop_pc >= ecs->event_thread->control.step_range_start |
4464 | && stop_pc < ecs->event_thread->control.step_range_end | |
31410e84 | 4465 | && (execution_direction != EXEC_REVERSE |
388a8562 | 4466 | || frame_id_eq (get_frame_id (frame), |
16c381f0 | 4467 | ecs->event_thread->control.step_frame_id))) |
488f131b | 4468 | { |
527159b7 | 4469 | if (debug_infrun) |
5af949e3 UW |
4470 | fprintf_unfiltered |
4471 | (gdb_stdlog, "infrun: stepping inside range [%s-%s]\n", | |
16c381f0 JK |
4472 | paddress (gdbarch, ecs->event_thread->control.step_range_start), |
4473 | paddress (gdbarch, ecs->event_thread->control.step_range_end)); | |
b2175913 MS |
4474 | |
4475 | /* When stepping backward, stop at beginning of line range | |
4476 | (unless it's the function entry point, in which case | |
4477 | keep going back to the call point). */ | |
16c381f0 | 4478 | if (stop_pc == ecs->event_thread->control.step_range_start |
b2175913 MS |
4479 | && stop_pc != ecs->stop_func_start |
4480 | && execution_direction == EXEC_REVERSE) | |
4481 | { | |
16c381f0 | 4482 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4483 | print_end_stepping_range_reason (); |
b2175913 MS |
4484 | stop_stepping (ecs); |
4485 | } | |
4486 | else | |
4487 | keep_going (ecs); | |
4488 | ||
488f131b JB |
4489 | return; |
4490 | } | |
c5aa993b | 4491 | |
488f131b | 4492 | /* We stepped out of the stepping range. */ |
c906108c | 4493 | |
488f131b | 4494 | /* If we are stepping at the source level and entered the runtime |
388a8562 MS |
4495 | loader dynamic symbol resolution code... |
4496 | ||
4497 | EXEC_FORWARD: we keep on single stepping until we exit the run | |
4498 | time loader code and reach the callee's address. | |
4499 | ||
4500 | EXEC_REVERSE: we've already executed the callee (backward), and | |
4501 | the runtime loader code is handled just like any other | |
4502 | undebuggable function call. Now we need only keep stepping | |
4503 | backward through the trampoline code, and that's handled further | |
4504 | down, so there is nothing for us to do here. */ | |
4505 | ||
4506 | if (execution_direction != EXEC_REVERSE | |
16c381f0 | 4507 | && ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
cfd8ab24 | 4508 | && in_solib_dynsym_resolve_code (stop_pc)) |
488f131b | 4509 | { |
4c8c40e6 | 4510 | CORE_ADDR pc_after_resolver = |
568d6575 | 4511 | gdbarch_skip_solib_resolver (gdbarch, stop_pc); |
c906108c | 4512 | |
527159b7 | 4513 | if (debug_infrun) |
3e43a32a MS |
4514 | fprintf_unfiltered (gdb_stdlog, |
4515 | "infrun: stepped into dynsym resolve code\n"); | |
527159b7 | 4516 | |
488f131b JB |
4517 | if (pc_after_resolver) |
4518 | { | |
4519 | /* Set up a step-resume breakpoint at the address | |
4520 | indicated by SKIP_SOLIB_RESOLVER. */ | |
4521 | struct symtab_and_line sr_sal; | |
abbb1732 | 4522 | |
fe39c653 | 4523 | init_sal (&sr_sal); |
488f131b | 4524 | sr_sal.pc = pc_after_resolver; |
6c95b8df | 4525 | sr_sal.pspace = get_frame_program_space (frame); |
488f131b | 4526 | |
a6d9a66e UW |
4527 | insert_step_resume_breakpoint_at_sal (gdbarch, |
4528 | sr_sal, null_frame_id); | |
c5aa993b | 4529 | } |
c906108c | 4530 | |
488f131b JB |
4531 | keep_going (ecs); |
4532 | return; | |
4533 | } | |
c906108c | 4534 | |
16c381f0 JK |
4535 | if (ecs->event_thread->control.step_range_end != 1 |
4536 | && (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE | |
4537 | || ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) | |
568d6575 | 4538 | && get_frame_type (frame) == SIGTRAMP_FRAME) |
488f131b | 4539 | { |
527159b7 | 4540 | if (debug_infrun) |
3e43a32a MS |
4541 | fprintf_unfiltered (gdb_stdlog, |
4542 | "infrun: stepped into signal trampoline\n"); | |
42edda50 | 4543 | /* The inferior, while doing a "step" or "next", has ended up in |
8fb3e588 AC |
4544 | a signal trampoline (either by a signal being delivered or by |
4545 | the signal handler returning). Just single-step until the | |
4546 | inferior leaves the trampoline (either by calling the handler | |
4547 | or returning). */ | |
488f131b JB |
4548 | keep_going (ecs); |
4549 | return; | |
4550 | } | |
c906108c | 4551 | |
c17eaafe DJ |
4552 | /* Check for subroutine calls. The check for the current frame |
4553 | equalling the step ID is not necessary - the check of the | |
4554 | previous frame's ID is sufficient - but it is a common case and | |
4555 | cheaper than checking the previous frame's ID. | |
14e60db5 DJ |
4556 | |
4557 | NOTE: frame_id_eq will never report two invalid frame IDs as | |
4558 | being equal, so to get into this block, both the current and | |
4559 | previous frame must have valid frame IDs. */ | |
005ca36a JB |
4560 | /* The outer_frame_id check is a heuristic to detect stepping |
4561 | through startup code. If we step over an instruction which | |
4562 | sets the stack pointer from an invalid value to a valid value, | |
4563 | we may detect that as a subroutine call from the mythical | |
4564 | "outermost" function. This could be fixed by marking | |
4565 | outermost frames as !stack_p,code_p,special_p. Then the | |
4566 | initial outermost frame, before sp was valid, would | |
ce6cca6d | 4567 | have code_addr == &_start. See the comment in frame_id_eq |
005ca36a | 4568 | for more. */ |
edb3359d | 4569 | if (!frame_id_eq (get_stack_frame_id (frame), |
16c381f0 | 4570 | ecs->event_thread->control.step_stack_frame_id) |
005ca36a | 4571 | && (frame_id_eq (frame_unwind_caller_id (get_current_frame ()), |
16c381f0 JK |
4572 | ecs->event_thread->control.step_stack_frame_id) |
4573 | && (!frame_id_eq (ecs->event_thread->control.step_stack_frame_id, | |
005ca36a JB |
4574 | outer_frame_id) |
4575 | || step_start_function != find_pc_function (stop_pc)))) | |
488f131b | 4576 | { |
95918acb | 4577 | CORE_ADDR real_stop_pc; |
8fb3e588 | 4578 | |
527159b7 | 4579 | if (debug_infrun) |
8a9de0e4 | 4580 | fprintf_unfiltered (gdb_stdlog, "infrun: stepped into subroutine\n"); |
527159b7 | 4581 | |
16c381f0 JK |
4582 | if ((ecs->event_thread->control.step_over_calls == STEP_OVER_NONE) |
4583 | || ((ecs->event_thread->control.step_range_end == 1) | |
d80b854b | 4584 | && in_prologue (gdbarch, ecs->event_thread->prev_pc, |
4e1c45ea | 4585 | ecs->stop_func_start))) |
95918acb AC |
4586 | { |
4587 | /* I presume that step_over_calls is only 0 when we're | |
4588 | supposed to be stepping at the assembly language level | |
4589 | ("stepi"). Just stop. */ | |
4590 | /* Also, maybe we just did a "nexti" inside a prolog, so we | |
4591 | thought it was a subroutine call but it was not. Stop as | |
4592 | well. FENN */ | |
388a8562 | 4593 | /* And this works the same backward as frontward. MVS */ |
16c381f0 | 4594 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4595 | print_end_stepping_range_reason (); |
95918acb AC |
4596 | stop_stepping (ecs); |
4597 | return; | |
4598 | } | |
8fb3e588 | 4599 | |
388a8562 MS |
4600 | /* Reverse stepping through solib trampolines. */ |
4601 | ||
4602 | if (execution_direction == EXEC_REVERSE | |
16c381f0 | 4603 | && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE |
388a8562 MS |
4604 | && (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) |
4605 | || (ecs->stop_func_start == 0 | |
4606 | && in_solib_dynsym_resolve_code (stop_pc)))) | |
4607 | { | |
4608 | /* Any solib trampoline code can be handled in reverse | |
4609 | by simply continuing to single-step. We have already | |
4610 | executed the solib function (backwards), and a few | |
4611 | steps will take us back through the trampoline to the | |
4612 | caller. */ | |
4613 | keep_going (ecs); | |
4614 | return; | |
4615 | } | |
4616 | ||
16c381f0 | 4617 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) |
8567c30f | 4618 | { |
b2175913 MS |
4619 | /* We're doing a "next". |
4620 | ||
4621 | Normal (forward) execution: set a breakpoint at the | |
4622 | callee's return address (the address at which the caller | |
4623 | will resume). | |
4624 | ||
4625 | Reverse (backward) execution. set the step-resume | |
4626 | breakpoint at the start of the function that we just | |
4627 | stepped into (backwards), and continue to there. When we | |
6130d0b7 | 4628 | get there, we'll need to single-step back to the caller. */ |
b2175913 MS |
4629 | |
4630 | if (execution_direction == EXEC_REVERSE) | |
4631 | { | |
4632 | struct symtab_and_line sr_sal; | |
3067f6e5 | 4633 | |
388a8562 MS |
4634 | /* Normal function call return (static or dynamic). */ |
4635 | init_sal (&sr_sal); | |
4636 | sr_sal.pc = ecs->stop_func_start; | |
6c95b8df PA |
4637 | sr_sal.pspace = get_frame_program_space (frame); |
4638 | insert_step_resume_breakpoint_at_sal (gdbarch, | |
4639 | sr_sal, null_frame_id); | |
b2175913 MS |
4640 | } |
4641 | else | |
568d6575 | 4642 | insert_step_resume_breakpoint_at_caller (frame); |
b2175913 | 4643 | |
8567c30f AC |
4644 | keep_going (ecs); |
4645 | return; | |
4646 | } | |
a53c66de | 4647 | |
95918acb | 4648 | /* If we are in a function call trampoline (a stub between the |
8fb3e588 AC |
4649 | calling routine and the real function), locate the real |
4650 | function. That's what tells us (a) whether we want to step | |
4651 | into it at all, and (b) what prologue we want to run to the | |
4652 | end of, if we do step into it. */ | |
568d6575 | 4653 | real_stop_pc = skip_language_trampoline (frame, stop_pc); |
95918acb | 4654 | if (real_stop_pc == 0) |
568d6575 | 4655 | real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); |
95918acb AC |
4656 | if (real_stop_pc != 0) |
4657 | ecs->stop_func_start = real_stop_pc; | |
8fb3e588 | 4658 | |
db5f024e | 4659 | if (real_stop_pc != 0 && in_solib_dynsym_resolve_code (real_stop_pc)) |
1b2bfbb9 RC |
4660 | { |
4661 | struct symtab_and_line sr_sal; | |
abbb1732 | 4662 | |
1b2bfbb9 RC |
4663 | init_sal (&sr_sal); |
4664 | sr_sal.pc = ecs->stop_func_start; | |
6c95b8df | 4665 | sr_sal.pspace = get_frame_program_space (frame); |
1b2bfbb9 | 4666 | |
a6d9a66e UW |
4667 | insert_step_resume_breakpoint_at_sal (gdbarch, |
4668 | sr_sal, null_frame_id); | |
8fb3e588 AC |
4669 | keep_going (ecs); |
4670 | return; | |
1b2bfbb9 RC |
4671 | } |
4672 | ||
95918acb | 4673 | /* If we have line number information for the function we are |
8fb3e588 | 4674 | thinking of stepping into, step into it. |
95918acb | 4675 | |
8fb3e588 AC |
4676 | If there are several symtabs at that PC (e.g. with include |
4677 | files), just want to know whether *any* of them have line | |
4678 | numbers. find_pc_line handles this. */ | |
95918acb AC |
4679 | { |
4680 | struct symtab_and_line tmp_sal; | |
8fb3e588 | 4681 | |
95918acb AC |
4682 | tmp_sal = find_pc_line (ecs->stop_func_start, 0); |
4683 | if (tmp_sal.line != 0) | |
4684 | { | |
b2175913 | 4685 | if (execution_direction == EXEC_REVERSE) |
568d6575 | 4686 | handle_step_into_function_backward (gdbarch, ecs); |
b2175913 | 4687 | else |
568d6575 | 4688 | handle_step_into_function (gdbarch, ecs); |
95918acb AC |
4689 | return; |
4690 | } | |
4691 | } | |
4692 | ||
4693 | /* If we have no line number and the step-stop-if-no-debug is | |
8fb3e588 AC |
4694 | set, we stop the step so that the user has a chance to switch |
4695 | in assembly mode. */ | |
16c381f0 | 4696 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
078130d0 | 4697 | && step_stop_if_no_debug) |
95918acb | 4698 | { |
16c381f0 | 4699 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4700 | print_end_stepping_range_reason (); |
95918acb AC |
4701 | stop_stepping (ecs); |
4702 | return; | |
4703 | } | |
4704 | ||
b2175913 MS |
4705 | if (execution_direction == EXEC_REVERSE) |
4706 | { | |
4707 | /* Set a breakpoint at callee's start address. | |
4708 | From there we can step once and be back in the caller. */ | |
4709 | struct symtab_and_line sr_sal; | |
abbb1732 | 4710 | |
b2175913 MS |
4711 | init_sal (&sr_sal); |
4712 | sr_sal.pc = ecs->stop_func_start; | |
6c95b8df | 4713 | sr_sal.pspace = get_frame_program_space (frame); |
a6d9a66e UW |
4714 | insert_step_resume_breakpoint_at_sal (gdbarch, |
4715 | sr_sal, null_frame_id); | |
b2175913 MS |
4716 | } |
4717 | else | |
4718 | /* Set a breakpoint at callee's return address (the address | |
4719 | at which the caller will resume). */ | |
568d6575 | 4720 | insert_step_resume_breakpoint_at_caller (frame); |
b2175913 | 4721 | |
95918acb | 4722 | keep_going (ecs); |
488f131b | 4723 | return; |
488f131b | 4724 | } |
c906108c | 4725 | |
fdd654f3 MS |
4726 | /* Reverse stepping through solib trampolines. */ |
4727 | ||
4728 | if (execution_direction == EXEC_REVERSE | |
16c381f0 | 4729 | && ecs->event_thread->control.step_over_calls != STEP_OVER_NONE) |
fdd654f3 MS |
4730 | { |
4731 | if (gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc) | |
4732 | || (ecs->stop_func_start == 0 | |
4733 | && in_solib_dynsym_resolve_code (stop_pc))) | |
4734 | { | |
4735 | /* Any solib trampoline code can be handled in reverse | |
4736 | by simply continuing to single-step. We have already | |
4737 | executed the solib function (backwards), and a few | |
4738 | steps will take us back through the trampoline to the | |
4739 | caller. */ | |
4740 | keep_going (ecs); | |
4741 | return; | |
4742 | } | |
4743 | else if (in_solib_dynsym_resolve_code (stop_pc)) | |
4744 | { | |
4745 | /* Stepped backward into the solib dynsym resolver. | |
4746 | Set a breakpoint at its start and continue, then | |
4747 | one more step will take us out. */ | |
4748 | struct symtab_and_line sr_sal; | |
abbb1732 | 4749 | |
fdd654f3 MS |
4750 | init_sal (&sr_sal); |
4751 | sr_sal.pc = ecs->stop_func_start; | |
9d1807c3 | 4752 | sr_sal.pspace = get_frame_program_space (frame); |
fdd654f3 MS |
4753 | insert_step_resume_breakpoint_at_sal (gdbarch, |
4754 | sr_sal, null_frame_id); | |
4755 | keep_going (ecs); | |
4756 | return; | |
4757 | } | |
4758 | } | |
4759 | ||
488f131b JB |
4760 | /* If we're in the return path from a shared library trampoline, |
4761 | we want to proceed through the trampoline when stepping. */ | |
568d6575 | 4762 | if (gdbarch_in_solib_return_trampoline (gdbarch, |
e76f05fa | 4763 | stop_pc, ecs->stop_func_name)) |
488f131b | 4764 | { |
488f131b | 4765 | /* Determine where this trampoline returns. */ |
52f729a7 | 4766 | CORE_ADDR real_stop_pc; |
abbb1732 | 4767 | |
568d6575 | 4768 | real_stop_pc = gdbarch_skip_trampoline_code (gdbarch, frame, stop_pc); |
c906108c | 4769 | |
527159b7 | 4770 | if (debug_infrun) |
3e43a32a MS |
4771 | fprintf_unfiltered (gdb_stdlog, |
4772 | "infrun: stepped into solib return tramp\n"); | |
527159b7 | 4773 | |
488f131b | 4774 | /* Only proceed through if we know where it's going. */ |
d764a824 | 4775 | if (real_stop_pc) |
488f131b | 4776 | { |
1777feb0 | 4777 | /* And put the step-breakpoint there and go until there. */ |
488f131b JB |
4778 | struct symtab_and_line sr_sal; |
4779 | ||
fe39c653 | 4780 | init_sal (&sr_sal); /* initialize to zeroes */ |
d764a824 | 4781 | sr_sal.pc = real_stop_pc; |
488f131b | 4782 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
6c95b8df | 4783 | sr_sal.pspace = get_frame_program_space (frame); |
44cbf7b5 AC |
4784 | |
4785 | /* Do not specify what the fp should be when we stop since | |
4786 | on some machines the prologue is where the new fp value | |
4787 | is established. */ | |
a6d9a66e UW |
4788 | insert_step_resume_breakpoint_at_sal (gdbarch, |
4789 | sr_sal, null_frame_id); | |
c906108c | 4790 | |
488f131b JB |
4791 | /* Restart without fiddling with the step ranges or |
4792 | other state. */ | |
4793 | keep_going (ecs); | |
4794 | return; | |
4795 | } | |
4796 | } | |
c906108c | 4797 | |
2afb61aa | 4798 | stop_pc_sal = find_pc_line (stop_pc, 0); |
7ed0fe66 | 4799 | |
1b2bfbb9 RC |
4800 | /* NOTE: tausq/2004-05-24: This if block used to be done before all |
4801 | the trampoline processing logic, however, there are some trampolines | |
4802 | that have no names, so we should do trampoline handling first. */ | |
16c381f0 | 4803 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_UNDEBUGGABLE |
7ed0fe66 | 4804 | && ecs->stop_func_name == NULL |
2afb61aa | 4805 | && stop_pc_sal.line == 0) |
1b2bfbb9 | 4806 | { |
527159b7 | 4807 | if (debug_infrun) |
3e43a32a MS |
4808 | fprintf_unfiltered (gdb_stdlog, |
4809 | "infrun: stepped into undebuggable function\n"); | |
527159b7 | 4810 | |
1b2bfbb9 | 4811 | /* The inferior just stepped into, or returned to, an |
7ed0fe66 DJ |
4812 | undebuggable function (where there is no debugging information |
4813 | and no line number corresponding to the address where the | |
1b2bfbb9 RC |
4814 | inferior stopped). Since we want to skip this kind of code, |
4815 | we keep going until the inferior returns from this | |
14e60db5 DJ |
4816 | function - unless the user has asked us not to (via |
4817 | set step-mode) or we no longer know how to get back | |
4818 | to the call site. */ | |
4819 | if (step_stop_if_no_debug | |
c7ce8faa | 4820 | || !frame_id_p (frame_unwind_caller_id (frame))) |
1b2bfbb9 RC |
4821 | { |
4822 | /* If we have no line number and the step-stop-if-no-debug | |
4823 | is set, we stop the step so that the user has a chance to | |
4824 | switch in assembly mode. */ | |
16c381f0 | 4825 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4826 | print_end_stepping_range_reason (); |
1b2bfbb9 RC |
4827 | stop_stepping (ecs); |
4828 | return; | |
4829 | } | |
4830 | else | |
4831 | { | |
4832 | /* Set a breakpoint at callee's return address (the address | |
4833 | at which the caller will resume). */ | |
568d6575 | 4834 | insert_step_resume_breakpoint_at_caller (frame); |
1b2bfbb9 RC |
4835 | keep_going (ecs); |
4836 | return; | |
4837 | } | |
4838 | } | |
4839 | ||
16c381f0 | 4840 | if (ecs->event_thread->control.step_range_end == 1) |
1b2bfbb9 RC |
4841 | { |
4842 | /* It is stepi or nexti. We always want to stop stepping after | |
4843 | one instruction. */ | |
527159b7 | 4844 | if (debug_infrun) |
8a9de0e4 | 4845 | fprintf_unfiltered (gdb_stdlog, "infrun: stepi/nexti\n"); |
16c381f0 | 4846 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4847 | print_end_stepping_range_reason (); |
1b2bfbb9 RC |
4848 | stop_stepping (ecs); |
4849 | return; | |
4850 | } | |
4851 | ||
2afb61aa | 4852 | if (stop_pc_sal.line == 0) |
488f131b JB |
4853 | { |
4854 | /* We have no line number information. That means to stop | |
4855 | stepping (does this always happen right after one instruction, | |
4856 | when we do "s" in a function with no line numbers, | |
4857 | or can this happen as a result of a return or longjmp?). */ | |
527159b7 | 4858 | if (debug_infrun) |
8a9de0e4 | 4859 | fprintf_unfiltered (gdb_stdlog, "infrun: no line number info\n"); |
16c381f0 | 4860 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4861 | print_end_stepping_range_reason (); |
488f131b JB |
4862 | stop_stepping (ecs); |
4863 | return; | |
4864 | } | |
c906108c | 4865 | |
edb3359d DJ |
4866 | /* Look for "calls" to inlined functions, part one. If the inline |
4867 | frame machinery detected some skipped call sites, we have entered | |
4868 | a new inline function. */ | |
4869 | ||
4870 | if (frame_id_eq (get_frame_id (get_current_frame ()), | |
16c381f0 | 4871 | ecs->event_thread->control.step_frame_id) |
edb3359d DJ |
4872 | && inline_skipped_frames (ecs->ptid)) |
4873 | { | |
4874 | struct symtab_and_line call_sal; | |
4875 | ||
4876 | if (debug_infrun) | |
4877 | fprintf_unfiltered (gdb_stdlog, | |
4878 | "infrun: stepped into inlined function\n"); | |
4879 | ||
4880 | find_frame_sal (get_current_frame (), &call_sal); | |
4881 | ||
16c381f0 | 4882 | if (ecs->event_thread->control.step_over_calls != STEP_OVER_ALL) |
edb3359d DJ |
4883 | { |
4884 | /* For "step", we're going to stop. But if the call site | |
4885 | for this inlined function is on the same source line as | |
4886 | we were previously stepping, go down into the function | |
4887 | first. Otherwise stop at the call site. */ | |
4888 | ||
4889 | if (call_sal.line == ecs->event_thread->current_line | |
4890 | && call_sal.symtab == ecs->event_thread->current_symtab) | |
4891 | step_into_inline_frame (ecs->ptid); | |
4892 | ||
16c381f0 | 4893 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4894 | print_end_stepping_range_reason (); |
edb3359d DJ |
4895 | stop_stepping (ecs); |
4896 | return; | |
4897 | } | |
4898 | else | |
4899 | { | |
4900 | /* For "next", we should stop at the call site if it is on a | |
4901 | different source line. Otherwise continue through the | |
4902 | inlined function. */ | |
4903 | if (call_sal.line == ecs->event_thread->current_line | |
4904 | && call_sal.symtab == ecs->event_thread->current_symtab) | |
4905 | keep_going (ecs); | |
4906 | else | |
4907 | { | |
16c381f0 | 4908 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4909 | print_end_stepping_range_reason (); |
edb3359d DJ |
4910 | stop_stepping (ecs); |
4911 | } | |
4912 | return; | |
4913 | } | |
4914 | } | |
4915 | ||
4916 | /* Look for "calls" to inlined functions, part two. If we are still | |
4917 | in the same real function we were stepping through, but we have | |
4918 | to go further up to find the exact frame ID, we are stepping | |
4919 | through a more inlined call beyond its call site. */ | |
4920 | ||
4921 | if (get_frame_type (get_current_frame ()) == INLINE_FRAME | |
4922 | && !frame_id_eq (get_frame_id (get_current_frame ()), | |
16c381f0 | 4923 | ecs->event_thread->control.step_frame_id) |
edb3359d | 4924 | && stepped_in_from (get_current_frame (), |
16c381f0 | 4925 | ecs->event_thread->control.step_frame_id)) |
edb3359d DJ |
4926 | { |
4927 | if (debug_infrun) | |
4928 | fprintf_unfiltered (gdb_stdlog, | |
4929 | "infrun: stepping through inlined function\n"); | |
4930 | ||
16c381f0 | 4931 | if (ecs->event_thread->control.step_over_calls == STEP_OVER_ALL) |
edb3359d DJ |
4932 | keep_going (ecs); |
4933 | else | |
4934 | { | |
16c381f0 | 4935 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4936 | print_end_stepping_range_reason (); |
edb3359d DJ |
4937 | stop_stepping (ecs); |
4938 | } | |
4939 | return; | |
4940 | } | |
4941 | ||
2afb61aa | 4942 | if ((stop_pc == stop_pc_sal.pc) |
4e1c45ea PA |
4943 | && (ecs->event_thread->current_line != stop_pc_sal.line |
4944 | || ecs->event_thread->current_symtab != stop_pc_sal.symtab)) | |
488f131b JB |
4945 | { |
4946 | /* We are at the start of a different line. So stop. Note that | |
4947 | we don't stop if we step into the middle of a different line. | |
4948 | That is said to make things like for (;;) statements work | |
4949 | better. */ | |
527159b7 | 4950 | if (debug_infrun) |
3e43a32a MS |
4951 | fprintf_unfiltered (gdb_stdlog, |
4952 | "infrun: stepped to a different line\n"); | |
16c381f0 | 4953 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 4954 | print_end_stepping_range_reason (); |
488f131b JB |
4955 | stop_stepping (ecs); |
4956 | return; | |
4957 | } | |
c906108c | 4958 | |
488f131b | 4959 | /* We aren't done stepping. |
c906108c | 4960 | |
488f131b JB |
4961 | Optimize by setting the stepping range to the line. |
4962 | (We might not be in the original line, but if we entered a | |
4963 | new line in mid-statement, we continue stepping. This makes | |
4964 | things like for(;;) statements work better.) */ | |
c906108c | 4965 | |
16c381f0 JK |
4966 | ecs->event_thread->control.step_range_start = stop_pc_sal.pc; |
4967 | ecs->event_thread->control.step_range_end = stop_pc_sal.end; | |
edb3359d | 4968 | set_step_info (frame, stop_pc_sal); |
488f131b | 4969 | |
527159b7 | 4970 | if (debug_infrun) |
8a9de0e4 | 4971 | fprintf_unfiltered (gdb_stdlog, "infrun: keep going\n"); |
488f131b | 4972 | keep_going (ecs); |
104c1213 JM |
4973 | } |
4974 | ||
b3444185 | 4975 | /* Is thread TP in the middle of single-stepping? */ |
104c1213 | 4976 | |
a289b8f6 | 4977 | static int |
b3444185 | 4978 | currently_stepping (struct thread_info *tp) |
a7212384 | 4979 | { |
8358c15c JK |
4980 | return ((tp->control.step_range_end |
4981 | && tp->control.step_resume_breakpoint == NULL) | |
4982 | || tp->control.trap_expected | |
4983 | || tp->stepping_through_solib_after_catch | |
4984 | || bpstat_should_step ()); | |
a7212384 UW |
4985 | } |
4986 | ||
b3444185 PA |
4987 | /* Returns true if any thread *but* the one passed in "data" is in the |
4988 | middle of stepping or of handling a "next". */ | |
a7212384 | 4989 | |
104c1213 | 4990 | static int |
b3444185 | 4991 | currently_stepping_or_nexting_callback (struct thread_info *tp, void *data) |
104c1213 | 4992 | { |
b3444185 PA |
4993 | if (tp == data) |
4994 | return 0; | |
4995 | ||
16c381f0 JK |
4996 | return (tp->control.step_range_end |
4997 | || tp->control.trap_expected | |
b3444185 | 4998 | || tp->stepping_through_solib_after_catch); |
104c1213 | 4999 | } |
c906108c | 5000 | |
b2175913 MS |
5001 | /* Inferior has stepped into a subroutine call with source code that |
5002 | we should not step over. Do step to the first line of code in | |
5003 | it. */ | |
c2c6d25f JM |
5004 | |
5005 | static void | |
568d6575 UW |
5006 | handle_step_into_function (struct gdbarch *gdbarch, |
5007 | struct execution_control_state *ecs) | |
c2c6d25f JM |
5008 | { |
5009 | struct symtab *s; | |
2afb61aa | 5010 | struct symtab_and_line stop_func_sal, sr_sal; |
c2c6d25f JM |
5011 | |
5012 | s = find_pc_symtab (stop_pc); | |
5013 | if (s && s->language != language_asm) | |
568d6575 | 5014 | ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, |
b2175913 | 5015 | ecs->stop_func_start); |
c2c6d25f | 5016 | |
2afb61aa | 5017 | stop_func_sal = find_pc_line (ecs->stop_func_start, 0); |
c2c6d25f JM |
5018 | /* Use the step_resume_break to step until the end of the prologue, |
5019 | even if that involves jumps (as it seems to on the vax under | |
5020 | 4.2). */ | |
5021 | /* If the prologue ends in the middle of a source line, continue to | |
5022 | the end of that source line (if it is still within the function). | |
5023 | Otherwise, just go to end of prologue. */ | |
2afb61aa PA |
5024 | if (stop_func_sal.end |
5025 | && stop_func_sal.pc != ecs->stop_func_start | |
5026 | && stop_func_sal.end < ecs->stop_func_end) | |
5027 | ecs->stop_func_start = stop_func_sal.end; | |
c2c6d25f | 5028 | |
2dbd5e30 KB |
5029 | /* Architectures which require breakpoint adjustment might not be able |
5030 | to place a breakpoint at the computed address. If so, the test | |
5031 | ``ecs->stop_func_start == stop_pc'' will never succeed. Adjust | |
5032 | ecs->stop_func_start to an address at which a breakpoint may be | |
5033 | legitimately placed. | |
8fb3e588 | 5034 | |
2dbd5e30 KB |
5035 | Note: kevinb/2004-01-19: On FR-V, if this adjustment is not |
5036 | made, GDB will enter an infinite loop when stepping through | |
5037 | optimized code consisting of VLIW instructions which contain | |
5038 | subinstructions corresponding to different source lines. On | |
5039 | FR-V, it's not permitted to place a breakpoint on any but the | |
5040 | first subinstruction of a VLIW instruction. When a breakpoint is | |
5041 | set, GDB will adjust the breakpoint address to the beginning of | |
5042 | the VLIW instruction. Thus, we need to make the corresponding | |
5043 | adjustment here when computing the stop address. */ | |
8fb3e588 | 5044 | |
568d6575 | 5045 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) |
2dbd5e30 KB |
5046 | { |
5047 | ecs->stop_func_start | |
568d6575 | 5048 | = gdbarch_adjust_breakpoint_address (gdbarch, |
8fb3e588 | 5049 | ecs->stop_func_start); |
2dbd5e30 KB |
5050 | } |
5051 | ||
c2c6d25f JM |
5052 | if (ecs->stop_func_start == stop_pc) |
5053 | { | |
5054 | /* We are already there: stop now. */ | |
16c381f0 | 5055 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 5056 | print_end_stepping_range_reason (); |
c2c6d25f JM |
5057 | stop_stepping (ecs); |
5058 | return; | |
5059 | } | |
5060 | else | |
5061 | { | |
5062 | /* Put the step-breakpoint there and go until there. */ | |
fe39c653 | 5063 | init_sal (&sr_sal); /* initialize to zeroes */ |
c2c6d25f JM |
5064 | sr_sal.pc = ecs->stop_func_start; |
5065 | sr_sal.section = find_pc_overlay (ecs->stop_func_start); | |
6c95b8df | 5066 | sr_sal.pspace = get_frame_program_space (get_current_frame ()); |
44cbf7b5 | 5067 | |
c2c6d25f | 5068 | /* Do not specify what the fp should be when we stop since on |
488f131b JB |
5069 | some machines the prologue is where the new fp value is |
5070 | established. */ | |
a6d9a66e | 5071 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, null_frame_id); |
c2c6d25f JM |
5072 | |
5073 | /* And make sure stepping stops right away then. */ | |
16c381f0 JK |
5074 | ecs->event_thread->control.step_range_end |
5075 | = ecs->event_thread->control.step_range_start; | |
c2c6d25f JM |
5076 | } |
5077 | keep_going (ecs); | |
5078 | } | |
d4f3574e | 5079 | |
b2175913 MS |
5080 | /* Inferior has stepped backward into a subroutine call with source |
5081 | code that we should not step over. Do step to the beginning of the | |
5082 | last line of code in it. */ | |
5083 | ||
5084 | static void | |
568d6575 UW |
5085 | handle_step_into_function_backward (struct gdbarch *gdbarch, |
5086 | struct execution_control_state *ecs) | |
b2175913 MS |
5087 | { |
5088 | struct symtab *s; | |
167e4384 | 5089 | struct symtab_and_line stop_func_sal; |
b2175913 MS |
5090 | |
5091 | s = find_pc_symtab (stop_pc); | |
5092 | if (s && s->language != language_asm) | |
568d6575 | 5093 | ecs->stop_func_start = gdbarch_skip_prologue (gdbarch, |
b2175913 MS |
5094 | ecs->stop_func_start); |
5095 | ||
5096 | stop_func_sal = find_pc_line (stop_pc, 0); | |
5097 | ||
5098 | /* OK, we're just going to keep stepping here. */ | |
5099 | if (stop_func_sal.pc == stop_pc) | |
5100 | { | |
5101 | /* We're there already. Just stop stepping now. */ | |
16c381f0 | 5102 | ecs->event_thread->control.stop_step = 1; |
33d62d64 | 5103 | print_end_stepping_range_reason (); |
b2175913 MS |
5104 | stop_stepping (ecs); |
5105 | } | |
5106 | else | |
5107 | { | |
5108 | /* Else just reset the step range and keep going. | |
5109 | No step-resume breakpoint, they don't work for | |
5110 | epilogues, which can have multiple entry paths. */ | |
16c381f0 JK |
5111 | ecs->event_thread->control.step_range_start = stop_func_sal.pc; |
5112 | ecs->event_thread->control.step_range_end = stop_func_sal.end; | |
b2175913 MS |
5113 | keep_going (ecs); |
5114 | } | |
5115 | return; | |
5116 | } | |
5117 | ||
d3169d93 | 5118 | /* Insert a "step-resume breakpoint" at SR_SAL with frame ID SR_ID. |
44cbf7b5 AC |
5119 | This is used to both functions and to skip over code. */ |
5120 | ||
5121 | static void | |
a6d9a66e UW |
5122 | insert_step_resume_breakpoint_at_sal (struct gdbarch *gdbarch, |
5123 | struct symtab_and_line sr_sal, | |
44cbf7b5 AC |
5124 | struct frame_id sr_id) |
5125 | { | |
611c83ae PA |
5126 | /* There should never be more than one step-resume or longjmp-resume |
5127 | breakpoint per thread, so we should never be setting a new | |
44cbf7b5 | 5128 | step_resume_breakpoint when one is already active. */ |
8358c15c | 5129 | gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL); |
d3169d93 DJ |
5130 | |
5131 | if (debug_infrun) | |
5132 | fprintf_unfiltered (gdb_stdlog, | |
5af949e3 UW |
5133 | "infrun: inserting step-resume breakpoint at %s\n", |
5134 | paddress (gdbarch, sr_sal.pc)); | |
d3169d93 | 5135 | |
8358c15c | 5136 | inferior_thread ()->control.step_resume_breakpoint |
a6d9a66e | 5137 | = set_momentary_breakpoint (gdbarch, sr_sal, sr_id, bp_step_resume); |
44cbf7b5 | 5138 | } |
7ce450bd | 5139 | |
d3169d93 | 5140 | /* Insert a "step-resume breakpoint" at RETURN_FRAME.pc. This is used |
14e60db5 | 5141 | to skip a potential signal handler. |
7ce450bd | 5142 | |
14e60db5 DJ |
5143 | This is called with the interrupted function's frame. The signal |
5144 | handler, when it returns, will resume the interrupted function at | |
5145 | RETURN_FRAME.pc. */ | |
d303a6c7 AC |
5146 | |
5147 | static void | |
44cbf7b5 | 5148 | insert_step_resume_breakpoint_at_frame (struct frame_info *return_frame) |
d303a6c7 AC |
5149 | { |
5150 | struct symtab_and_line sr_sal; | |
a6d9a66e | 5151 | struct gdbarch *gdbarch; |
d303a6c7 | 5152 | |
f4c1edd8 | 5153 | gdb_assert (return_frame != NULL); |
d303a6c7 AC |
5154 | init_sal (&sr_sal); /* initialize to zeros */ |
5155 | ||
a6d9a66e | 5156 | gdbarch = get_frame_arch (return_frame); |
568d6575 | 5157 | sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, get_frame_pc (return_frame)); |
d303a6c7 | 5158 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
6c95b8df | 5159 | sr_sal.pspace = get_frame_program_space (return_frame); |
d303a6c7 | 5160 | |
a6d9a66e UW |
5161 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, |
5162 | get_stack_frame_id (return_frame)); | |
d303a6c7 AC |
5163 | } |
5164 | ||
14e60db5 DJ |
5165 | /* Similar to insert_step_resume_breakpoint_at_frame, except |
5166 | but a breakpoint at the previous frame's PC. This is used to | |
5167 | skip a function after stepping into it (for "next" or if the called | |
5168 | function has no debugging information). | |
5169 | ||
5170 | The current function has almost always been reached by single | |
5171 | stepping a call or return instruction. NEXT_FRAME belongs to the | |
5172 | current function, and the breakpoint will be set at the caller's | |
5173 | resume address. | |
5174 | ||
5175 | This is a separate function rather than reusing | |
5176 | insert_step_resume_breakpoint_at_frame in order to avoid | |
5177 | get_prev_frame, which may stop prematurely (see the implementation | |
c7ce8faa | 5178 | of frame_unwind_caller_id for an example). */ |
14e60db5 DJ |
5179 | |
5180 | static void | |
5181 | insert_step_resume_breakpoint_at_caller (struct frame_info *next_frame) | |
5182 | { | |
5183 | struct symtab_and_line sr_sal; | |
a6d9a66e | 5184 | struct gdbarch *gdbarch; |
14e60db5 DJ |
5185 | |
5186 | /* We shouldn't have gotten here if we don't know where the call site | |
5187 | is. */ | |
c7ce8faa | 5188 | gdb_assert (frame_id_p (frame_unwind_caller_id (next_frame))); |
14e60db5 DJ |
5189 | |
5190 | init_sal (&sr_sal); /* initialize to zeros */ | |
5191 | ||
a6d9a66e | 5192 | gdbarch = frame_unwind_caller_arch (next_frame); |
c7ce8faa DJ |
5193 | sr_sal.pc = gdbarch_addr_bits_remove (gdbarch, |
5194 | frame_unwind_caller_pc (next_frame)); | |
14e60db5 | 5195 | sr_sal.section = find_pc_overlay (sr_sal.pc); |
6c95b8df | 5196 | sr_sal.pspace = frame_unwind_program_space (next_frame); |
14e60db5 | 5197 | |
a6d9a66e | 5198 | insert_step_resume_breakpoint_at_sal (gdbarch, sr_sal, |
c7ce8faa | 5199 | frame_unwind_caller_id (next_frame)); |
14e60db5 DJ |
5200 | } |
5201 | ||
611c83ae PA |
5202 | /* Insert a "longjmp-resume" breakpoint at PC. This is used to set a |
5203 | new breakpoint at the target of a jmp_buf. The handling of | |
5204 | longjmp-resume uses the same mechanisms used for handling | |
5205 | "step-resume" breakpoints. */ | |
5206 | ||
5207 | static void | |
a6d9a66e | 5208 | insert_longjmp_resume_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
611c83ae PA |
5209 | { |
5210 | /* There should never be more than one step-resume or longjmp-resume | |
5211 | breakpoint per thread, so we should never be setting a new | |
5212 | longjmp_resume_breakpoint when one is already active. */ | |
8358c15c | 5213 | gdb_assert (inferior_thread ()->control.step_resume_breakpoint == NULL); |
611c83ae PA |
5214 | |
5215 | if (debug_infrun) | |
5216 | fprintf_unfiltered (gdb_stdlog, | |
5af949e3 UW |
5217 | "infrun: inserting longjmp-resume breakpoint at %s\n", |
5218 | paddress (gdbarch, pc)); | |
611c83ae | 5219 | |
8358c15c | 5220 | inferior_thread ()->control.step_resume_breakpoint = |
a6d9a66e | 5221 | set_momentary_breakpoint_at_pc (gdbarch, pc, bp_longjmp_resume); |
611c83ae PA |
5222 | } |
5223 | ||
186c406b TT |
5224 | /* Insert an exception resume breakpoint. TP is the thread throwing |
5225 | the exception. The block B is the block of the unwinder debug hook | |
5226 | function. FRAME is the frame corresponding to the call to this | |
5227 | function. SYM is the symbol of the function argument holding the | |
5228 | target PC of the exception. */ | |
5229 | ||
5230 | static void | |
5231 | insert_exception_resume_breakpoint (struct thread_info *tp, | |
5232 | struct block *b, | |
5233 | struct frame_info *frame, | |
5234 | struct symbol *sym) | |
5235 | { | |
5236 | struct gdb_exception e; | |
5237 | ||
5238 | /* We want to ignore errors here. */ | |
5239 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
5240 | { | |
5241 | struct symbol *vsym; | |
5242 | struct value *value; | |
5243 | CORE_ADDR handler; | |
5244 | struct breakpoint *bp; | |
5245 | ||
5246 | vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL); | |
5247 | value = read_var_value (vsym, frame); | |
5248 | /* If the value was optimized out, revert to the old behavior. */ | |
5249 | if (! value_optimized_out (value)) | |
5250 | { | |
5251 | handler = value_as_address (value); | |
5252 | ||
5253 | if (debug_infrun) | |
5254 | fprintf_unfiltered (gdb_stdlog, | |
5255 | "infrun: exception resume at %lx\n", | |
5256 | (unsigned long) handler); | |
5257 | ||
5258 | bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame), | |
5259 | handler, bp_exception_resume); | |
5260 | bp->thread = tp->num; | |
5261 | inferior_thread ()->control.exception_resume_breakpoint = bp; | |
5262 | } | |
5263 | } | |
5264 | } | |
5265 | ||
5266 | /* This is called when an exception has been intercepted. Check to | |
5267 | see whether the exception's destination is of interest, and if so, | |
5268 | set an exception resume breakpoint there. */ | |
5269 | ||
5270 | static void | |
5271 | check_exception_resume (struct execution_control_state *ecs, | |
5272 | struct frame_info *frame, struct symbol *func) | |
5273 | { | |
5274 | struct gdb_exception e; | |
5275 | ||
5276 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
5277 | { | |
5278 | struct block *b; | |
5279 | struct dict_iterator iter; | |
5280 | struct symbol *sym; | |
5281 | int argno = 0; | |
5282 | ||
5283 | /* The exception breakpoint is a thread-specific breakpoint on | |
5284 | the unwinder's debug hook, declared as: | |
5285 | ||
5286 | void _Unwind_DebugHook (void *cfa, void *handler); | |
5287 | ||
5288 | The CFA argument indicates the frame to which control is | |
5289 | about to be transferred. HANDLER is the destination PC. | |
5290 | ||
5291 | We ignore the CFA and set a temporary breakpoint at HANDLER. | |
5292 | This is not extremely efficient but it avoids issues in gdb | |
5293 | with computing the DWARF CFA, and it also works even in weird | |
5294 | cases such as throwing an exception from inside a signal | |
5295 | handler. */ | |
5296 | ||
5297 | b = SYMBOL_BLOCK_VALUE (func); | |
5298 | ALL_BLOCK_SYMBOLS (b, iter, sym) | |
5299 | { | |
5300 | if (!SYMBOL_IS_ARGUMENT (sym)) | |
5301 | continue; | |
5302 | ||
5303 | if (argno == 0) | |
5304 | ++argno; | |
5305 | else | |
5306 | { | |
5307 | insert_exception_resume_breakpoint (ecs->event_thread, | |
5308 | b, frame, sym); | |
5309 | break; | |
5310 | } | |
5311 | } | |
5312 | } | |
5313 | } | |
5314 | ||
104c1213 JM |
5315 | static void |
5316 | stop_stepping (struct execution_control_state *ecs) | |
5317 | { | |
527159b7 | 5318 | if (debug_infrun) |
8a9de0e4 | 5319 | fprintf_unfiltered (gdb_stdlog, "infrun: stop_stepping\n"); |
527159b7 | 5320 | |
cd0fc7c3 SS |
5321 | /* Let callers know we don't want to wait for the inferior anymore. */ |
5322 | ecs->wait_some_more = 0; | |
5323 | } | |
5324 | ||
d4f3574e SS |
5325 | /* This function handles various cases where we need to continue |
5326 | waiting for the inferior. */ | |
1777feb0 | 5327 | /* (Used to be the keep_going: label in the old wait_for_inferior). */ |
d4f3574e SS |
5328 | |
5329 | static void | |
5330 | keep_going (struct execution_control_state *ecs) | |
5331 | { | |
c4dbc9af PA |
5332 | /* Make sure normal_stop is called if we get a QUIT handled before |
5333 | reaching resume. */ | |
5334 | struct cleanup *old_cleanups = make_cleanup (resume_cleanups, 0); | |
5335 | ||
d4f3574e | 5336 | /* Save the pc before execution, to compare with pc after stop. */ |
fb14de7b UW |
5337 | ecs->event_thread->prev_pc |
5338 | = regcache_read_pc (get_thread_regcache (ecs->ptid)); | |
d4f3574e | 5339 | |
d4f3574e SS |
5340 | /* If we did not do break;, it means we should keep running the |
5341 | inferior and not return to debugger. */ | |
5342 | ||
16c381f0 JK |
5343 | if (ecs->event_thread->control.trap_expected |
5344 | && ecs->event_thread->suspend.stop_signal != TARGET_SIGNAL_TRAP) | |
d4f3574e SS |
5345 | { |
5346 | /* We took a signal (which we are supposed to pass through to | |
4e1c45ea PA |
5347 | the inferior, else we'd not get here) and we haven't yet |
5348 | gotten our trap. Simply continue. */ | |
c4dbc9af PA |
5349 | |
5350 | discard_cleanups (old_cleanups); | |
2020b7ab | 5351 | resume (currently_stepping (ecs->event_thread), |
16c381f0 | 5352 | ecs->event_thread->suspend.stop_signal); |
d4f3574e SS |
5353 | } |
5354 | else | |
5355 | { | |
5356 | /* Either the trap was not expected, but we are continuing | |
488f131b JB |
5357 | anyway (the user asked that this signal be passed to the |
5358 | child) | |
5359 | -- or -- | |
5360 | The signal was SIGTRAP, e.g. it was our signal, but we | |
5361 | decided we should resume from it. | |
d4f3574e | 5362 | |
c36b740a | 5363 | We're going to run this baby now! |
d4f3574e | 5364 | |
c36b740a VP |
5365 | Note that insert_breakpoints won't try to re-insert |
5366 | already inserted breakpoints. Therefore, we don't | |
5367 | care if breakpoints were already inserted, or not. */ | |
5368 | ||
4e1c45ea | 5369 | if (ecs->event_thread->stepping_over_breakpoint) |
45e8c884 | 5370 | { |
9f5a595d | 5371 | struct regcache *thread_regcache = get_thread_regcache (ecs->ptid); |
abbb1732 | 5372 | |
9f5a595d | 5373 | if (!use_displaced_stepping (get_regcache_arch (thread_regcache))) |
237fc4c9 PA |
5374 | /* Since we can't do a displaced step, we have to remove |
5375 | the breakpoint while we step it. To keep things | |
5376 | simple, we remove them all. */ | |
5377 | remove_breakpoints (); | |
45e8c884 VP |
5378 | } |
5379 | else | |
d4f3574e | 5380 | { |
e236ba44 | 5381 | struct gdb_exception e; |
abbb1732 | 5382 | |
569631c6 UW |
5383 | /* Stop stepping when inserting breakpoints |
5384 | has failed. */ | |
e236ba44 VP |
5385 | TRY_CATCH (e, RETURN_MASK_ERROR) |
5386 | { | |
5387 | insert_breakpoints (); | |
5388 | } | |
5389 | if (e.reason < 0) | |
d4f3574e | 5390 | { |
97bd5475 | 5391 | exception_print (gdb_stderr, e); |
d4f3574e SS |
5392 | stop_stepping (ecs); |
5393 | return; | |
5394 | } | |
d4f3574e SS |
5395 | } |
5396 | ||
16c381f0 JK |
5397 | ecs->event_thread->control.trap_expected |
5398 | = ecs->event_thread->stepping_over_breakpoint; | |
d4f3574e SS |
5399 | |
5400 | /* Do not deliver SIGNAL_TRAP (except when the user explicitly | |
488f131b JB |
5401 | specifies that such a signal should be delivered to the |
5402 | target program). | |
5403 | ||
5404 | Typically, this would occure when a user is debugging a | |
5405 | target monitor on a simulator: the target monitor sets a | |
5406 | breakpoint; the simulator encounters this break-point and | |
5407 | halts the simulation handing control to GDB; GDB, noteing | |
5408 | that the break-point isn't valid, returns control back to the | |
5409 | simulator; the simulator then delivers the hardware | |
1777feb0 | 5410 | equivalent of a SIGNAL_TRAP to the program being debugged. */ |
488f131b | 5411 | |
16c381f0 JK |
5412 | if (ecs->event_thread->suspend.stop_signal == TARGET_SIGNAL_TRAP |
5413 | && !signal_program[ecs->event_thread->suspend.stop_signal]) | |
5414 | ecs->event_thread->suspend.stop_signal = TARGET_SIGNAL_0; | |
d4f3574e | 5415 | |
c4dbc9af | 5416 | discard_cleanups (old_cleanups); |
2020b7ab | 5417 | resume (currently_stepping (ecs->event_thread), |
16c381f0 | 5418 | ecs->event_thread->suspend.stop_signal); |
d4f3574e SS |
5419 | } |
5420 | ||
488f131b | 5421 | prepare_to_wait (ecs); |
d4f3574e SS |
5422 | } |
5423 | ||
104c1213 JM |
5424 | /* This function normally comes after a resume, before |
5425 | handle_inferior_event exits. It takes care of any last bits of | |
5426 | housekeeping, and sets the all-important wait_some_more flag. */ | |
cd0fc7c3 | 5427 | |
104c1213 JM |
5428 | static void |
5429 | prepare_to_wait (struct execution_control_state *ecs) | |
cd0fc7c3 | 5430 | { |
527159b7 | 5431 | if (debug_infrun) |
8a9de0e4 | 5432 | fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n"); |
104c1213 | 5433 | |
104c1213 JM |
5434 | /* This is the old end of the while loop. Let everybody know we |
5435 | want to wait for the inferior some more and get called again | |
5436 | soon. */ | |
5437 | ecs->wait_some_more = 1; | |
c906108c | 5438 | } |
11cf8741 | 5439 | |
33d62d64 JK |
5440 | /* Several print_*_reason functions to print why the inferior has stopped. |
5441 | We always print something when the inferior exits, or receives a signal. | |
5442 | The rest of the cases are dealt with later on in normal_stop and | |
5443 | print_it_typical. Ideally there should be a call to one of these | |
5444 | print_*_reason functions functions from handle_inferior_event each time | |
5445 | stop_stepping is called. */ | |
5446 | ||
5447 | /* Print why the inferior has stopped. | |
5448 | We are done with a step/next/si/ni command, print why the inferior has | |
5449 | stopped. For now print nothing. Print a message only if not in the middle | |
5450 | of doing a "step n" operation for n > 1. */ | |
5451 | ||
5452 | static void | |
5453 | print_end_stepping_range_reason (void) | |
5454 | { | |
16c381f0 JK |
5455 | if ((!inferior_thread ()->step_multi |
5456 | || !inferior_thread ()->control.stop_step) | |
33d62d64 JK |
5457 | && ui_out_is_mi_like_p (uiout)) |
5458 | ui_out_field_string (uiout, "reason", | |
5459 | async_reason_lookup (EXEC_ASYNC_END_STEPPING_RANGE)); | |
5460 | } | |
5461 | ||
5462 | /* The inferior was terminated by a signal, print why it stopped. */ | |
5463 | ||
11cf8741 | 5464 | static void |
33d62d64 | 5465 | print_signal_exited_reason (enum target_signal siggnal) |
11cf8741 | 5466 | { |
33d62d64 JK |
5467 | annotate_signalled (); |
5468 | if (ui_out_is_mi_like_p (uiout)) | |
5469 | ui_out_field_string | |
5470 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_SIGNALLED)); | |
5471 | ui_out_text (uiout, "\nProgram terminated with signal "); | |
5472 | annotate_signal_name (); | |
5473 | ui_out_field_string (uiout, "signal-name", | |
5474 | target_signal_to_name (siggnal)); | |
5475 | annotate_signal_name_end (); | |
5476 | ui_out_text (uiout, ", "); | |
5477 | annotate_signal_string (); | |
5478 | ui_out_field_string (uiout, "signal-meaning", | |
5479 | target_signal_to_string (siggnal)); | |
5480 | annotate_signal_string_end (); | |
5481 | ui_out_text (uiout, ".\n"); | |
5482 | ui_out_text (uiout, "The program no longer exists.\n"); | |
5483 | } | |
5484 | ||
5485 | /* The inferior program is finished, print why it stopped. */ | |
5486 | ||
5487 | static void | |
5488 | print_exited_reason (int exitstatus) | |
5489 | { | |
fda326dd TT |
5490 | struct inferior *inf = current_inferior (); |
5491 | const char *pidstr = target_pid_to_str (pid_to_ptid (inf->pid)); | |
5492 | ||
33d62d64 JK |
5493 | annotate_exited (exitstatus); |
5494 | if (exitstatus) | |
5495 | { | |
5496 | if (ui_out_is_mi_like_p (uiout)) | |
5497 | ui_out_field_string (uiout, "reason", | |
5498 | async_reason_lookup (EXEC_ASYNC_EXITED)); | |
fda326dd TT |
5499 | ui_out_text (uiout, "[Inferior "); |
5500 | ui_out_text (uiout, plongest (inf->num)); | |
5501 | ui_out_text (uiout, " ("); | |
5502 | ui_out_text (uiout, pidstr); | |
5503 | ui_out_text (uiout, ") exited with code "); | |
33d62d64 | 5504 | ui_out_field_fmt (uiout, "exit-code", "0%o", (unsigned int) exitstatus); |
fda326dd | 5505 | ui_out_text (uiout, "]\n"); |
33d62d64 JK |
5506 | } |
5507 | else | |
11cf8741 | 5508 | { |
9dc5e2a9 | 5509 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f | 5510 | ui_out_field_string |
33d62d64 | 5511 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY)); |
fda326dd TT |
5512 | ui_out_text (uiout, "[Inferior "); |
5513 | ui_out_text (uiout, plongest (inf->num)); | |
5514 | ui_out_text (uiout, " ("); | |
5515 | ui_out_text (uiout, pidstr); | |
5516 | ui_out_text (uiout, ") exited normally]\n"); | |
33d62d64 JK |
5517 | } |
5518 | /* Support the --return-child-result option. */ | |
5519 | return_child_result_value = exitstatus; | |
5520 | } | |
5521 | ||
5522 | /* Signal received, print why the inferior has stopped. The signal table | |
1777feb0 | 5523 | tells us to print about it. */ |
33d62d64 JK |
5524 | |
5525 | static void | |
5526 | print_signal_received_reason (enum target_signal siggnal) | |
5527 | { | |
5528 | annotate_signal (); | |
5529 | ||
5530 | if (siggnal == TARGET_SIGNAL_0 && !ui_out_is_mi_like_p (uiout)) | |
5531 | { | |
5532 | struct thread_info *t = inferior_thread (); | |
5533 | ||
5534 | ui_out_text (uiout, "\n["); | |
5535 | ui_out_field_string (uiout, "thread-name", | |
5536 | target_pid_to_str (t->ptid)); | |
5537 | ui_out_field_fmt (uiout, "thread-id", "] #%d", t->num); | |
5538 | ui_out_text (uiout, " stopped"); | |
5539 | } | |
5540 | else | |
5541 | { | |
5542 | ui_out_text (uiout, "\nProgram received signal "); | |
8b93c638 | 5543 | annotate_signal_name (); |
33d62d64 JK |
5544 | if (ui_out_is_mi_like_p (uiout)) |
5545 | ui_out_field_string | |
5546 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_SIGNAL_RECEIVED)); | |
488f131b | 5547 | ui_out_field_string (uiout, "signal-name", |
33d62d64 | 5548 | target_signal_to_name (siggnal)); |
8b93c638 JM |
5549 | annotate_signal_name_end (); |
5550 | ui_out_text (uiout, ", "); | |
5551 | annotate_signal_string (); | |
488f131b | 5552 | ui_out_field_string (uiout, "signal-meaning", |
33d62d64 | 5553 | target_signal_to_string (siggnal)); |
8b93c638 | 5554 | annotate_signal_string_end (); |
33d62d64 JK |
5555 | } |
5556 | ui_out_text (uiout, ".\n"); | |
5557 | } | |
252fbfc8 | 5558 | |
33d62d64 JK |
5559 | /* Reverse execution: target ran out of history info, print why the inferior |
5560 | has stopped. */ | |
252fbfc8 | 5561 | |
33d62d64 JK |
5562 | static void |
5563 | print_no_history_reason (void) | |
5564 | { | |
5565 | ui_out_text (uiout, "\nNo more reverse-execution history.\n"); | |
11cf8741 | 5566 | } |
43ff13b4 | 5567 | |
c906108c SS |
5568 | /* Here to return control to GDB when the inferior stops for real. |
5569 | Print appropriate messages, remove breakpoints, give terminal our modes. | |
5570 | ||
5571 | STOP_PRINT_FRAME nonzero means print the executing frame | |
5572 | (pc, function, args, file, line number and line text). | |
5573 | BREAKPOINTS_FAILED nonzero means stop was due to error | |
5574 | attempting to insert breakpoints. */ | |
5575 | ||
5576 | void | |
96baa820 | 5577 | normal_stop (void) |
c906108c | 5578 | { |
73b65bb0 DJ |
5579 | struct target_waitstatus last; |
5580 | ptid_t last_ptid; | |
29f49a6a | 5581 | struct cleanup *old_chain = make_cleanup (null_cleanup, NULL); |
73b65bb0 DJ |
5582 | |
5583 | get_last_target_status (&last_ptid, &last); | |
5584 | ||
29f49a6a PA |
5585 | /* If an exception is thrown from this point on, make sure to |
5586 | propagate GDB's knowledge of the executing state to the | |
5587 | frontend/user running state. A QUIT is an easy exception to see | |
5588 | here, so do this before any filtered output. */ | |
c35b1492 PA |
5589 | if (!non_stop) |
5590 | make_cleanup (finish_thread_state_cleanup, &minus_one_ptid); | |
5591 | else if (last.kind != TARGET_WAITKIND_SIGNALLED | |
5592 | && last.kind != TARGET_WAITKIND_EXITED) | |
5593 | make_cleanup (finish_thread_state_cleanup, &inferior_ptid); | |
29f49a6a | 5594 | |
4f8d22e3 PA |
5595 | /* In non-stop mode, we don't want GDB to switch threads behind the |
5596 | user's back, to avoid races where the user is typing a command to | |
5597 | apply to thread x, but GDB switches to thread y before the user | |
5598 | finishes entering the command. */ | |
5599 | ||
c906108c SS |
5600 | /* As with the notification of thread events, we want to delay |
5601 | notifying the user that we've switched thread context until | |
5602 | the inferior actually stops. | |
5603 | ||
73b65bb0 DJ |
5604 | There's no point in saying anything if the inferior has exited. |
5605 | Note that SIGNALLED here means "exited with a signal", not | |
5606 | "received a signal". */ | |
4f8d22e3 PA |
5607 | if (!non_stop |
5608 | && !ptid_equal (previous_inferior_ptid, inferior_ptid) | |
73b65bb0 DJ |
5609 | && target_has_execution |
5610 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
5611 | && last.kind != TARGET_WAITKIND_EXITED) | |
c906108c SS |
5612 | { |
5613 | target_terminal_ours_for_output (); | |
a3f17187 | 5614 | printf_filtered (_("[Switching to %s]\n"), |
c95310c6 | 5615 | target_pid_to_str (inferior_ptid)); |
b8fa951a | 5616 | annotate_thread_changed (); |
39f77062 | 5617 | previous_inferior_ptid = inferior_ptid; |
c906108c | 5618 | } |
c906108c | 5619 | |
74960c60 | 5620 | if (!breakpoints_always_inserted_mode () && target_has_execution) |
c906108c SS |
5621 | { |
5622 | if (remove_breakpoints ()) | |
5623 | { | |
5624 | target_terminal_ours_for_output (); | |
3e43a32a MS |
5625 | printf_filtered (_("Cannot remove breakpoints because " |
5626 | "program is no longer writable.\nFurther " | |
5627 | "execution is probably impossible.\n")); | |
c906108c SS |
5628 | } |
5629 | } | |
c906108c | 5630 | |
c906108c SS |
5631 | /* If an auto-display called a function and that got a signal, |
5632 | delete that auto-display to avoid an infinite recursion. */ | |
5633 | ||
5634 | if (stopped_by_random_signal) | |
5635 | disable_current_display (); | |
5636 | ||
5637 | /* Don't print a message if in the middle of doing a "step n" | |
5638 | operation for n > 1 */ | |
af679fd0 PA |
5639 | if (target_has_execution |
5640 | && last.kind != TARGET_WAITKIND_SIGNALLED | |
5641 | && last.kind != TARGET_WAITKIND_EXITED | |
5642 | && inferior_thread ()->step_multi | |
16c381f0 | 5643 | && inferior_thread ()->control.stop_step) |
c906108c SS |
5644 | goto done; |
5645 | ||
5646 | target_terminal_ours (); | |
5647 | ||
7abfe014 DJ |
5648 | /* Set the current source location. This will also happen if we |
5649 | display the frame below, but the current SAL will be incorrect | |
5650 | during a user hook-stop function. */ | |
d729566a | 5651 | if (has_stack_frames () && !stop_stack_dummy) |
7abfe014 DJ |
5652 | set_current_sal_from_frame (get_current_frame (), 1); |
5653 | ||
dd7e2d2b PA |
5654 | /* Let the user/frontend see the threads as stopped. */ |
5655 | do_cleanups (old_chain); | |
5656 | ||
5657 | /* Look up the hook_stop and run it (CLI internally handles problem | |
5658 | of stop_command's pre-hook not existing). */ | |
5659 | if (stop_command) | |
5660 | catch_errors (hook_stop_stub, stop_command, | |
5661 | "Error while running hook_stop:\n", RETURN_MASK_ALL); | |
5662 | ||
d729566a | 5663 | if (!has_stack_frames ()) |
d51fd4c8 | 5664 | goto done; |
c906108c | 5665 | |
32400beb PA |
5666 | if (last.kind == TARGET_WAITKIND_SIGNALLED |
5667 | || last.kind == TARGET_WAITKIND_EXITED) | |
5668 | goto done; | |
5669 | ||
c906108c SS |
5670 | /* Select innermost stack frame - i.e., current frame is frame 0, |
5671 | and current location is based on that. | |
5672 | Don't do this on return from a stack dummy routine, | |
1777feb0 | 5673 | or if the program has exited. */ |
c906108c SS |
5674 | |
5675 | if (!stop_stack_dummy) | |
5676 | { | |
0f7d239c | 5677 | select_frame (get_current_frame ()); |
c906108c SS |
5678 | |
5679 | /* Print current location without a level number, if | |
c5aa993b JM |
5680 | we have changed functions or hit a breakpoint. |
5681 | Print source line if we have one. | |
5682 | bpstat_print() contains the logic deciding in detail | |
1777feb0 | 5683 | what to print, based on the event(s) that just occurred. */ |
c906108c | 5684 | |
d01a8610 AS |
5685 | /* If --batch-silent is enabled then there's no need to print the current |
5686 | source location, and to try risks causing an error message about | |
5687 | missing source files. */ | |
5688 | if (stop_print_frame && !batch_silent) | |
c906108c SS |
5689 | { |
5690 | int bpstat_ret; | |
5691 | int source_flag; | |
917317f4 | 5692 | int do_frame_printing = 1; |
347bddb7 | 5693 | struct thread_info *tp = inferior_thread (); |
c906108c | 5694 | |
16c381f0 | 5695 | bpstat_ret = bpstat_print (tp->control.stop_bpstat); |
917317f4 JM |
5696 | switch (bpstat_ret) |
5697 | { | |
5698 | case PRINT_UNKNOWN: | |
b0f4b84b DJ |
5699 | /* If we had hit a shared library event breakpoint, |
5700 | bpstat_print would print out this message. If we hit | |
5701 | an OS-level shared library event, do the same | |
5702 | thing. */ | |
5703 | if (last.kind == TARGET_WAITKIND_LOADED) | |
5704 | { | |
5705 | printf_filtered (_("Stopped due to shared library event\n")); | |
5706 | source_flag = SRC_LINE; /* something bogus */ | |
5707 | do_frame_printing = 0; | |
5708 | break; | |
5709 | } | |
5710 | ||
aa0cd9c1 | 5711 | /* FIXME: cagney/2002-12-01: Given that a frame ID does |
8fb3e588 AC |
5712 | (or should) carry around the function and does (or |
5713 | should) use that when doing a frame comparison. */ | |
16c381f0 JK |
5714 | if (tp->control.stop_step |
5715 | && frame_id_eq (tp->control.step_frame_id, | |
aa0cd9c1 | 5716 | get_frame_id (get_current_frame ())) |
917317f4 | 5717 | && step_start_function == find_pc_function (stop_pc)) |
1777feb0 MS |
5718 | source_flag = SRC_LINE; /* Finished step, just |
5719 | print source line. */ | |
917317f4 | 5720 | else |
1777feb0 MS |
5721 | source_flag = SRC_AND_LOC; /* Print location and |
5722 | source line. */ | |
917317f4 JM |
5723 | break; |
5724 | case PRINT_SRC_AND_LOC: | |
1777feb0 MS |
5725 | source_flag = SRC_AND_LOC; /* Print location and |
5726 | source line. */ | |
917317f4 JM |
5727 | break; |
5728 | case PRINT_SRC_ONLY: | |
c5394b80 | 5729 | source_flag = SRC_LINE; |
917317f4 JM |
5730 | break; |
5731 | case PRINT_NOTHING: | |
488f131b | 5732 | source_flag = SRC_LINE; /* something bogus */ |
917317f4 JM |
5733 | do_frame_printing = 0; |
5734 | break; | |
5735 | default: | |
e2e0b3e5 | 5736 | internal_error (__FILE__, __LINE__, _("Unknown value.")); |
917317f4 | 5737 | } |
c906108c SS |
5738 | |
5739 | /* The behavior of this routine with respect to the source | |
5740 | flag is: | |
c5394b80 JM |
5741 | SRC_LINE: Print only source line |
5742 | LOCATION: Print only location | |
1777feb0 | 5743 | SRC_AND_LOC: Print location and source line. */ |
917317f4 | 5744 | if (do_frame_printing) |
b04f3ab4 | 5745 | print_stack_frame (get_selected_frame (NULL), 0, source_flag); |
c906108c SS |
5746 | |
5747 | /* Display the auto-display expressions. */ | |
5748 | do_displays (); | |
5749 | } | |
5750 | } | |
5751 | ||
5752 | /* Save the function value return registers, if we care. | |
5753 | We might be about to restore their previous contents. */ | |
16c381f0 | 5754 | if (inferior_thread ()->control.proceed_to_finish) |
d5c31457 UW |
5755 | { |
5756 | /* This should not be necessary. */ | |
5757 | if (stop_registers) | |
5758 | regcache_xfree (stop_registers); | |
5759 | ||
5760 | /* NB: The copy goes through to the target picking up the value of | |
5761 | all the registers. */ | |
5762 | stop_registers = regcache_dup (get_current_regcache ()); | |
5763 | } | |
c906108c | 5764 | |
aa7d318d | 5765 | if (stop_stack_dummy == STOP_STACK_DUMMY) |
c906108c | 5766 | { |
b89667eb DE |
5767 | /* Pop the empty frame that contains the stack dummy. |
5768 | This also restores inferior state prior to the call | |
16c381f0 | 5769 | (struct infcall_suspend_state). */ |
b89667eb | 5770 | struct frame_info *frame = get_current_frame (); |
abbb1732 | 5771 | |
b89667eb DE |
5772 | gdb_assert (get_frame_type (frame) == DUMMY_FRAME); |
5773 | frame_pop (frame); | |
3e43a32a MS |
5774 | /* frame_pop() calls reinit_frame_cache as the last thing it |
5775 | does which means there's currently no selected frame. We | |
5776 | don't need to re-establish a selected frame if the dummy call | |
5777 | returns normally, that will be done by | |
5778 | restore_infcall_control_state. However, we do have to handle | |
5779 | the case where the dummy call is returning after being | |
5780 | stopped (e.g. the dummy call previously hit a breakpoint). | |
5781 | We can't know which case we have so just always re-establish | |
5782 | a selected frame here. */ | |
0f7d239c | 5783 | select_frame (get_current_frame ()); |
c906108c SS |
5784 | } |
5785 | ||
c906108c SS |
5786 | done: |
5787 | annotate_stopped (); | |
41d2bdb4 PA |
5788 | |
5789 | /* Suppress the stop observer if we're in the middle of: | |
5790 | ||
5791 | - a step n (n > 1), as there still more steps to be done. | |
5792 | ||
5793 | - a "finish" command, as the observer will be called in | |
5794 | finish_command_continuation, so it can include the inferior | |
5795 | function's return value. | |
5796 | ||
5797 | - calling an inferior function, as we pretend we inferior didn't | |
5798 | run at all. The return value of the call is handled by the | |
5799 | expression evaluator, through call_function_by_hand. */ | |
5800 | ||
5801 | if (!target_has_execution | |
5802 | || last.kind == TARGET_WAITKIND_SIGNALLED | |
5803 | || last.kind == TARGET_WAITKIND_EXITED | |
5804 | || (!inferior_thread ()->step_multi | |
16c381f0 JK |
5805 | && !(inferior_thread ()->control.stop_bpstat |
5806 | && inferior_thread ()->control.proceed_to_finish) | |
5807 | && !inferior_thread ()->control.in_infcall)) | |
347bddb7 PA |
5808 | { |
5809 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
16c381f0 | 5810 | observer_notify_normal_stop (inferior_thread ()->control.stop_bpstat, |
1d33d6ba | 5811 | stop_print_frame); |
347bddb7 | 5812 | else |
1d33d6ba | 5813 | observer_notify_normal_stop (NULL, stop_print_frame); |
347bddb7 | 5814 | } |
347bddb7 | 5815 | |
48844aa6 PA |
5816 | if (target_has_execution) |
5817 | { | |
5818 | if (last.kind != TARGET_WAITKIND_SIGNALLED | |
5819 | && last.kind != TARGET_WAITKIND_EXITED) | |
5820 | /* Delete the breakpoint we stopped at, if it wants to be deleted. | |
5821 | Delete any breakpoint that is to be deleted at the next stop. */ | |
16c381f0 | 5822 | breakpoint_auto_delete (inferior_thread ()->control.stop_bpstat); |
94cc34af | 5823 | } |
6c95b8df PA |
5824 | |
5825 | /* Try to get rid of automatically added inferiors that are no | |
5826 | longer needed. Keeping those around slows down things linearly. | |
5827 | Note that this never removes the current inferior. */ | |
5828 | prune_inferiors (); | |
c906108c SS |
5829 | } |
5830 | ||
5831 | static int | |
96baa820 | 5832 | hook_stop_stub (void *cmd) |
c906108c | 5833 | { |
5913bcb0 | 5834 | execute_cmd_pre_hook ((struct cmd_list_element *) cmd); |
c906108c SS |
5835 | return (0); |
5836 | } | |
5837 | \f | |
c5aa993b | 5838 | int |
96baa820 | 5839 | signal_stop_state (int signo) |
c906108c | 5840 | { |
d6b48e9c | 5841 | return signal_stop[signo]; |
c906108c SS |
5842 | } |
5843 | ||
c5aa993b | 5844 | int |
96baa820 | 5845 | signal_print_state (int signo) |
c906108c SS |
5846 | { |
5847 | return signal_print[signo]; | |
5848 | } | |
5849 | ||
c5aa993b | 5850 | int |
96baa820 | 5851 | signal_pass_state (int signo) |
c906108c SS |
5852 | { |
5853 | return signal_program[signo]; | |
5854 | } | |
5855 | ||
488f131b | 5856 | int |
7bda5e4a | 5857 | signal_stop_update (int signo, int state) |
d4f3574e SS |
5858 | { |
5859 | int ret = signal_stop[signo]; | |
abbb1732 | 5860 | |
d4f3574e SS |
5861 | signal_stop[signo] = state; |
5862 | return ret; | |
5863 | } | |
5864 | ||
488f131b | 5865 | int |
7bda5e4a | 5866 | signal_print_update (int signo, int state) |
d4f3574e SS |
5867 | { |
5868 | int ret = signal_print[signo]; | |
abbb1732 | 5869 | |
d4f3574e SS |
5870 | signal_print[signo] = state; |
5871 | return ret; | |
5872 | } | |
5873 | ||
488f131b | 5874 | int |
7bda5e4a | 5875 | signal_pass_update (int signo, int state) |
d4f3574e SS |
5876 | { |
5877 | int ret = signal_program[signo]; | |
abbb1732 | 5878 | |
d4f3574e SS |
5879 | signal_program[signo] = state; |
5880 | return ret; | |
5881 | } | |
5882 | ||
c906108c | 5883 | static void |
96baa820 | 5884 | sig_print_header (void) |
c906108c | 5885 | { |
3e43a32a MS |
5886 | printf_filtered (_("Signal Stop\tPrint\tPass " |
5887 | "to program\tDescription\n")); | |
c906108c SS |
5888 | } |
5889 | ||
5890 | static void | |
96baa820 | 5891 | sig_print_info (enum target_signal oursig) |
c906108c | 5892 | { |
54363045 | 5893 | const char *name = target_signal_to_name (oursig); |
c906108c | 5894 | int name_padding = 13 - strlen (name); |
96baa820 | 5895 | |
c906108c SS |
5896 | if (name_padding <= 0) |
5897 | name_padding = 0; | |
5898 | ||
5899 | printf_filtered ("%s", name); | |
488f131b | 5900 | printf_filtered ("%*.*s ", name_padding, name_padding, " "); |
c906108c SS |
5901 | printf_filtered ("%s\t", signal_stop[oursig] ? "Yes" : "No"); |
5902 | printf_filtered ("%s\t", signal_print[oursig] ? "Yes" : "No"); | |
5903 | printf_filtered ("%s\t\t", signal_program[oursig] ? "Yes" : "No"); | |
5904 | printf_filtered ("%s\n", target_signal_to_string (oursig)); | |
5905 | } | |
5906 | ||
5907 | /* Specify how various signals in the inferior should be handled. */ | |
5908 | ||
5909 | static void | |
96baa820 | 5910 | handle_command (char *args, int from_tty) |
c906108c SS |
5911 | { |
5912 | char **argv; | |
5913 | int digits, wordlen; | |
5914 | int sigfirst, signum, siglast; | |
5915 | enum target_signal oursig; | |
5916 | int allsigs; | |
5917 | int nsigs; | |
5918 | unsigned char *sigs; | |
5919 | struct cleanup *old_chain; | |
5920 | ||
5921 | if (args == NULL) | |
5922 | { | |
e2e0b3e5 | 5923 | error_no_arg (_("signal to handle")); |
c906108c SS |
5924 | } |
5925 | ||
1777feb0 | 5926 | /* Allocate and zero an array of flags for which signals to handle. */ |
c906108c SS |
5927 | |
5928 | nsigs = (int) TARGET_SIGNAL_LAST; | |
5929 | sigs = (unsigned char *) alloca (nsigs); | |
5930 | memset (sigs, 0, nsigs); | |
5931 | ||
1777feb0 | 5932 | /* Break the command line up into args. */ |
c906108c | 5933 | |
d1a41061 | 5934 | argv = gdb_buildargv (args); |
7a292a7a | 5935 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
5936 | |
5937 | /* Walk through the args, looking for signal oursigs, signal names, and | |
5938 | actions. Signal numbers and signal names may be interspersed with | |
5939 | actions, with the actions being performed for all signals cumulatively | |
1777feb0 | 5940 | specified. Signal ranges can be specified as <LOW>-<HIGH>. */ |
c906108c SS |
5941 | |
5942 | while (*argv != NULL) | |
5943 | { | |
5944 | wordlen = strlen (*argv); | |
5945 | for (digits = 0; isdigit ((*argv)[digits]); digits++) | |
5946 | {; | |
5947 | } | |
5948 | allsigs = 0; | |
5949 | sigfirst = siglast = -1; | |
5950 | ||
5951 | if (wordlen >= 1 && !strncmp (*argv, "all", wordlen)) | |
5952 | { | |
5953 | /* Apply action to all signals except those used by the | |
1777feb0 | 5954 | debugger. Silently skip those. */ |
c906108c SS |
5955 | allsigs = 1; |
5956 | sigfirst = 0; | |
5957 | siglast = nsigs - 1; | |
5958 | } | |
5959 | else if (wordlen >= 1 && !strncmp (*argv, "stop", wordlen)) | |
5960 | { | |
5961 | SET_SIGS (nsigs, sigs, signal_stop); | |
5962 | SET_SIGS (nsigs, sigs, signal_print); | |
5963 | } | |
5964 | else if (wordlen >= 1 && !strncmp (*argv, "ignore", wordlen)) | |
5965 | { | |
5966 | UNSET_SIGS (nsigs, sigs, signal_program); | |
5967 | } | |
5968 | else if (wordlen >= 2 && !strncmp (*argv, "print", wordlen)) | |
5969 | { | |
5970 | SET_SIGS (nsigs, sigs, signal_print); | |
5971 | } | |
5972 | else if (wordlen >= 2 && !strncmp (*argv, "pass", wordlen)) | |
5973 | { | |
5974 | SET_SIGS (nsigs, sigs, signal_program); | |
5975 | } | |
5976 | else if (wordlen >= 3 && !strncmp (*argv, "nostop", wordlen)) | |
5977 | { | |
5978 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
5979 | } | |
5980 | else if (wordlen >= 3 && !strncmp (*argv, "noignore", wordlen)) | |
5981 | { | |
5982 | SET_SIGS (nsigs, sigs, signal_program); | |
5983 | } | |
5984 | else if (wordlen >= 4 && !strncmp (*argv, "noprint", wordlen)) | |
5985 | { | |
5986 | UNSET_SIGS (nsigs, sigs, signal_print); | |
5987 | UNSET_SIGS (nsigs, sigs, signal_stop); | |
5988 | } | |
5989 | else if (wordlen >= 4 && !strncmp (*argv, "nopass", wordlen)) | |
5990 | { | |
5991 | UNSET_SIGS (nsigs, sigs, signal_program); | |
5992 | } | |
5993 | else if (digits > 0) | |
5994 | { | |
5995 | /* It is numeric. The numeric signal refers to our own | |
5996 | internal signal numbering from target.h, not to host/target | |
5997 | signal number. This is a feature; users really should be | |
5998 | using symbolic names anyway, and the common ones like | |
5999 | SIGHUP, SIGINT, SIGALRM, etc. will work right anyway. */ | |
6000 | ||
6001 | sigfirst = siglast = (int) | |
6002 | target_signal_from_command (atoi (*argv)); | |
6003 | if ((*argv)[digits] == '-') | |
6004 | { | |
6005 | siglast = (int) | |
6006 | target_signal_from_command (atoi ((*argv) + digits + 1)); | |
6007 | } | |
6008 | if (sigfirst > siglast) | |
6009 | { | |
1777feb0 | 6010 | /* Bet he didn't figure we'd think of this case... */ |
c906108c SS |
6011 | signum = sigfirst; |
6012 | sigfirst = siglast; | |
6013 | siglast = signum; | |
6014 | } | |
6015 | } | |
6016 | else | |
6017 | { | |
6018 | oursig = target_signal_from_name (*argv); | |
6019 | if (oursig != TARGET_SIGNAL_UNKNOWN) | |
6020 | { | |
6021 | sigfirst = siglast = (int) oursig; | |
6022 | } | |
6023 | else | |
6024 | { | |
6025 | /* Not a number and not a recognized flag word => complain. */ | |
8a3fe4f8 | 6026 | error (_("Unrecognized or ambiguous flag word: \"%s\"."), *argv); |
c906108c SS |
6027 | } |
6028 | } | |
6029 | ||
6030 | /* If any signal numbers or symbol names were found, set flags for | |
1777feb0 | 6031 | which signals to apply actions to. */ |
c906108c SS |
6032 | |
6033 | for (signum = sigfirst; signum >= 0 && signum <= siglast; signum++) | |
6034 | { | |
6035 | switch ((enum target_signal) signum) | |
6036 | { | |
6037 | case TARGET_SIGNAL_TRAP: | |
6038 | case TARGET_SIGNAL_INT: | |
6039 | if (!allsigs && !sigs[signum]) | |
6040 | { | |
9e2f0ad4 | 6041 | if (query (_("%s is used by the debugger.\n\ |
3e43a32a MS |
6042 | Are you sure you want to change it? "), |
6043 | target_signal_to_name ((enum target_signal) signum))) | |
c906108c SS |
6044 | { |
6045 | sigs[signum] = 1; | |
6046 | } | |
6047 | else | |
6048 | { | |
a3f17187 | 6049 | printf_unfiltered (_("Not confirmed, unchanged.\n")); |
c906108c SS |
6050 | gdb_flush (gdb_stdout); |
6051 | } | |
6052 | } | |
6053 | break; | |
6054 | case TARGET_SIGNAL_0: | |
6055 | case TARGET_SIGNAL_DEFAULT: | |
6056 | case TARGET_SIGNAL_UNKNOWN: | |
6057 | /* Make sure that "all" doesn't print these. */ | |
6058 | break; | |
6059 | default: | |
6060 | sigs[signum] = 1; | |
6061 | break; | |
6062 | } | |
6063 | } | |
6064 | ||
6065 | argv++; | |
6066 | } | |
6067 | ||
3a031f65 PA |
6068 | for (signum = 0; signum < nsigs; signum++) |
6069 | if (sigs[signum]) | |
6070 | { | |
6071 | target_notice_signals (inferior_ptid); | |
c906108c | 6072 | |
3a031f65 PA |
6073 | if (from_tty) |
6074 | { | |
6075 | /* Show the results. */ | |
6076 | sig_print_header (); | |
6077 | for (; signum < nsigs; signum++) | |
6078 | if (sigs[signum]) | |
6079 | sig_print_info (signum); | |
6080 | } | |
6081 | ||
6082 | break; | |
6083 | } | |
c906108c SS |
6084 | |
6085 | do_cleanups (old_chain); | |
6086 | } | |
6087 | ||
6088 | static void | |
96baa820 | 6089 | xdb_handle_command (char *args, int from_tty) |
c906108c SS |
6090 | { |
6091 | char **argv; | |
6092 | struct cleanup *old_chain; | |
6093 | ||
d1a41061 PP |
6094 | if (args == NULL) |
6095 | error_no_arg (_("xdb command")); | |
6096 | ||
1777feb0 | 6097 | /* Break the command line up into args. */ |
c906108c | 6098 | |
d1a41061 | 6099 | argv = gdb_buildargv (args); |
7a292a7a | 6100 | old_chain = make_cleanup_freeargv (argv); |
c906108c SS |
6101 | if (argv[1] != (char *) NULL) |
6102 | { | |
6103 | char *argBuf; | |
6104 | int bufLen; | |
6105 | ||
6106 | bufLen = strlen (argv[0]) + 20; | |
6107 | argBuf = (char *) xmalloc (bufLen); | |
6108 | if (argBuf) | |
6109 | { | |
6110 | int validFlag = 1; | |
6111 | enum target_signal oursig; | |
6112 | ||
6113 | oursig = target_signal_from_name (argv[0]); | |
6114 | memset (argBuf, 0, bufLen); | |
6115 | if (strcmp (argv[1], "Q") == 0) | |
6116 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
6117 | else | |
6118 | { | |
6119 | if (strcmp (argv[1], "s") == 0) | |
6120 | { | |
6121 | if (!signal_stop[oursig]) | |
6122 | sprintf (argBuf, "%s %s", argv[0], "stop"); | |
6123 | else | |
6124 | sprintf (argBuf, "%s %s", argv[0], "nostop"); | |
6125 | } | |
6126 | else if (strcmp (argv[1], "i") == 0) | |
6127 | { | |
6128 | if (!signal_program[oursig]) | |
6129 | sprintf (argBuf, "%s %s", argv[0], "pass"); | |
6130 | else | |
6131 | sprintf (argBuf, "%s %s", argv[0], "nopass"); | |
6132 | } | |
6133 | else if (strcmp (argv[1], "r") == 0) | |
6134 | { | |
6135 | if (!signal_print[oursig]) | |
6136 | sprintf (argBuf, "%s %s", argv[0], "print"); | |
6137 | else | |
6138 | sprintf (argBuf, "%s %s", argv[0], "noprint"); | |
6139 | } | |
6140 | else | |
6141 | validFlag = 0; | |
6142 | } | |
6143 | if (validFlag) | |
6144 | handle_command (argBuf, from_tty); | |
6145 | else | |
a3f17187 | 6146 | printf_filtered (_("Invalid signal handling flag.\n")); |
c906108c | 6147 | if (argBuf) |
b8c9b27d | 6148 | xfree (argBuf); |
c906108c SS |
6149 | } |
6150 | } | |
6151 | do_cleanups (old_chain); | |
6152 | } | |
6153 | ||
6154 | /* Print current contents of the tables set by the handle command. | |
6155 | It is possible we should just be printing signals actually used | |
6156 | by the current target (but for things to work right when switching | |
6157 | targets, all signals should be in the signal tables). */ | |
6158 | ||
6159 | static void | |
96baa820 | 6160 | signals_info (char *signum_exp, int from_tty) |
c906108c SS |
6161 | { |
6162 | enum target_signal oursig; | |
abbb1732 | 6163 | |
c906108c SS |
6164 | sig_print_header (); |
6165 | ||
6166 | if (signum_exp) | |
6167 | { | |
6168 | /* First see if this is a symbol name. */ | |
6169 | oursig = target_signal_from_name (signum_exp); | |
6170 | if (oursig == TARGET_SIGNAL_UNKNOWN) | |
6171 | { | |
6172 | /* No, try numeric. */ | |
6173 | oursig = | |
bb518678 | 6174 | target_signal_from_command (parse_and_eval_long (signum_exp)); |
c906108c SS |
6175 | } |
6176 | sig_print_info (oursig); | |
6177 | return; | |
6178 | } | |
6179 | ||
6180 | printf_filtered ("\n"); | |
6181 | /* These ugly casts brought to you by the native VAX compiler. */ | |
6182 | for (oursig = TARGET_SIGNAL_FIRST; | |
6183 | (int) oursig < (int) TARGET_SIGNAL_LAST; | |
6184 | oursig = (enum target_signal) ((int) oursig + 1)) | |
6185 | { | |
6186 | QUIT; | |
6187 | ||
6188 | if (oursig != TARGET_SIGNAL_UNKNOWN | |
488f131b | 6189 | && oursig != TARGET_SIGNAL_DEFAULT && oursig != TARGET_SIGNAL_0) |
c906108c SS |
6190 | sig_print_info (oursig); |
6191 | } | |
6192 | ||
3e43a32a MS |
6193 | printf_filtered (_("\nUse the \"handle\" command " |
6194 | "to change these tables.\n")); | |
c906108c | 6195 | } |
4aa995e1 PA |
6196 | |
6197 | /* The $_siginfo convenience variable is a bit special. We don't know | |
6198 | for sure the type of the value until we actually have a chance to | |
6199 | fetch the data. The type can change depending on gdbarch, so it it | |
6200 | also dependent on which thread you have selected. | |
6201 | ||
6202 | 1. making $_siginfo be an internalvar that creates a new value on | |
6203 | access. | |
6204 | ||
6205 | 2. making the value of $_siginfo be an lval_computed value. */ | |
6206 | ||
6207 | /* This function implements the lval_computed support for reading a | |
6208 | $_siginfo value. */ | |
6209 | ||
6210 | static void | |
6211 | siginfo_value_read (struct value *v) | |
6212 | { | |
6213 | LONGEST transferred; | |
6214 | ||
6215 | transferred = | |
6216 | target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, | |
6217 | NULL, | |
6218 | value_contents_all_raw (v), | |
6219 | value_offset (v), | |
6220 | TYPE_LENGTH (value_type (v))); | |
6221 | ||
6222 | if (transferred != TYPE_LENGTH (value_type (v))) | |
6223 | error (_("Unable to read siginfo")); | |
6224 | } | |
6225 | ||
6226 | /* This function implements the lval_computed support for writing a | |
6227 | $_siginfo value. */ | |
6228 | ||
6229 | static void | |
6230 | siginfo_value_write (struct value *v, struct value *fromval) | |
6231 | { | |
6232 | LONGEST transferred; | |
6233 | ||
6234 | transferred = target_write (¤t_target, | |
6235 | TARGET_OBJECT_SIGNAL_INFO, | |
6236 | NULL, | |
6237 | value_contents_all_raw (fromval), | |
6238 | value_offset (v), | |
6239 | TYPE_LENGTH (value_type (fromval))); | |
6240 | ||
6241 | if (transferred != TYPE_LENGTH (value_type (fromval))) | |
6242 | error (_("Unable to write siginfo")); | |
6243 | } | |
6244 | ||
6245 | static struct lval_funcs siginfo_value_funcs = | |
6246 | { | |
6247 | siginfo_value_read, | |
6248 | siginfo_value_write | |
6249 | }; | |
6250 | ||
6251 | /* Return a new value with the correct type for the siginfo object of | |
78267919 UW |
6252 | the current thread using architecture GDBARCH. Return a void value |
6253 | if there's no object available. */ | |
4aa995e1 | 6254 | |
2c0b251b | 6255 | static struct value * |
78267919 | 6256 | siginfo_make_value (struct gdbarch *gdbarch, struct internalvar *var) |
4aa995e1 | 6257 | { |
4aa995e1 | 6258 | if (target_has_stack |
78267919 UW |
6259 | && !ptid_equal (inferior_ptid, null_ptid) |
6260 | && gdbarch_get_siginfo_type_p (gdbarch)) | |
4aa995e1 | 6261 | { |
78267919 | 6262 | struct type *type = gdbarch_get_siginfo_type (gdbarch); |
abbb1732 | 6263 | |
78267919 | 6264 | return allocate_computed_value (type, &siginfo_value_funcs, NULL); |
4aa995e1 PA |
6265 | } |
6266 | ||
78267919 | 6267 | return allocate_value (builtin_type (gdbarch)->builtin_void); |
4aa995e1 PA |
6268 | } |
6269 | ||
c906108c | 6270 | \f |
16c381f0 JK |
6271 | /* infcall_suspend_state contains state about the program itself like its |
6272 | registers and any signal it received when it last stopped. | |
6273 | This state must be restored regardless of how the inferior function call | |
6274 | ends (either successfully, or after it hits a breakpoint or signal) | |
6275 | if the program is to properly continue where it left off. */ | |
6276 | ||
6277 | struct infcall_suspend_state | |
7a292a7a | 6278 | { |
16c381f0 JK |
6279 | struct thread_suspend_state thread_suspend; |
6280 | struct inferior_suspend_state inferior_suspend; | |
6281 | ||
6282 | /* Other fields: */ | |
7a292a7a | 6283 | CORE_ADDR stop_pc; |
b89667eb | 6284 | struct regcache *registers; |
1736ad11 | 6285 | |
35515841 | 6286 | /* Format of SIGINFO_DATA or NULL if it is not present. */ |
1736ad11 JK |
6287 | struct gdbarch *siginfo_gdbarch; |
6288 | ||
6289 | /* The inferior format depends on SIGINFO_GDBARCH and it has a length of | |
6290 | TYPE_LENGTH (gdbarch_get_siginfo_type ()). For different gdbarch the | |
6291 | content would be invalid. */ | |
6292 | gdb_byte *siginfo_data; | |
b89667eb DE |
6293 | }; |
6294 | ||
16c381f0 JK |
6295 | struct infcall_suspend_state * |
6296 | save_infcall_suspend_state (void) | |
b89667eb | 6297 | { |
16c381f0 | 6298 | struct infcall_suspend_state *inf_state; |
b89667eb | 6299 | struct thread_info *tp = inferior_thread (); |
16c381f0 | 6300 | struct inferior *inf = current_inferior (); |
1736ad11 JK |
6301 | struct regcache *regcache = get_current_regcache (); |
6302 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
6303 | gdb_byte *siginfo_data = NULL; | |
6304 | ||
6305 | if (gdbarch_get_siginfo_type_p (gdbarch)) | |
6306 | { | |
6307 | struct type *type = gdbarch_get_siginfo_type (gdbarch); | |
6308 | size_t len = TYPE_LENGTH (type); | |
6309 | struct cleanup *back_to; | |
6310 | ||
6311 | siginfo_data = xmalloc (len); | |
6312 | back_to = make_cleanup (xfree, siginfo_data); | |
6313 | ||
6314 | if (target_read (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, | |
6315 | siginfo_data, 0, len) == len) | |
6316 | discard_cleanups (back_to); | |
6317 | else | |
6318 | { | |
6319 | /* Errors ignored. */ | |
6320 | do_cleanups (back_to); | |
6321 | siginfo_data = NULL; | |
6322 | } | |
6323 | } | |
6324 | ||
16c381f0 | 6325 | inf_state = XZALLOC (struct infcall_suspend_state); |
1736ad11 JK |
6326 | |
6327 | if (siginfo_data) | |
6328 | { | |
6329 | inf_state->siginfo_gdbarch = gdbarch; | |
6330 | inf_state->siginfo_data = siginfo_data; | |
6331 | } | |
b89667eb | 6332 | |
16c381f0 JK |
6333 | inf_state->thread_suspend = tp->suspend; |
6334 | inf_state->inferior_suspend = inf->suspend; | |
6335 | ||
35515841 JK |
6336 | /* run_inferior_call will not use the signal due to its `proceed' call with |
6337 | TARGET_SIGNAL_0 anyway. */ | |
16c381f0 | 6338 | tp->suspend.stop_signal = TARGET_SIGNAL_0; |
35515841 | 6339 | |
b89667eb DE |
6340 | inf_state->stop_pc = stop_pc; |
6341 | ||
1736ad11 | 6342 | inf_state->registers = regcache_dup (regcache); |
b89667eb DE |
6343 | |
6344 | return inf_state; | |
6345 | } | |
6346 | ||
6347 | /* Restore inferior session state to INF_STATE. */ | |
6348 | ||
6349 | void | |
16c381f0 | 6350 | restore_infcall_suspend_state (struct infcall_suspend_state *inf_state) |
b89667eb DE |
6351 | { |
6352 | struct thread_info *tp = inferior_thread (); | |
16c381f0 | 6353 | struct inferior *inf = current_inferior (); |
1736ad11 JK |
6354 | struct regcache *regcache = get_current_regcache (); |
6355 | struct gdbarch *gdbarch = get_regcache_arch (regcache); | |
b89667eb | 6356 | |
16c381f0 JK |
6357 | tp->suspend = inf_state->thread_suspend; |
6358 | inf->suspend = inf_state->inferior_suspend; | |
6359 | ||
b89667eb DE |
6360 | stop_pc = inf_state->stop_pc; |
6361 | ||
1736ad11 JK |
6362 | if (inf_state->siginfo_gdbarch == gdbarch) |
6363 | { | |
6364 | struct type *type = gdbarch_get_siginfo_type (gdbarch); | |
6365 | size_t len = TYPE_LENGTH (type); | |
6366 | ||
6367 | /* Errors ignored. */ | |
6368 | target_write (¤t_target, TARGET_OBJECT_SIGNAL_INFO, NULL, | |
6369 | inf_state->siginfo_data, 0, len); | |
6370 | } | |
6371 | ||
b89667eb DE |
6372 | /* The inferior can be gone if the user types "print exit(0)" |
6373 | (and perhaps other times). */ | |
6374 | if (target_has_execution) | |
6375 | /* NB: The register write goes through to the target. */ | |
1736ad11 | 6376 | regcache_cpy (regcache, inf_state->registers); |
803b5f95 | 6377 | |
16c381f0 | 6378 | discard_infcall_suspend_state (inf_state); |
b89667eb DE |
6379 | } |
6380 | ||
6381 | static void | |
16c381f0 | 6382 | do_restore_infcall_suspend_state_cleanup (void *state) |
b89667eb | 6383 | { |
16c381f0 | 6384 | restore_infcall_suspend_state (state); |
b89667eb DE |
6385 | } |
6386 | ||
6387 | struct cleanup * | |
16c381f0 JK |
6388 | make_cleanup_restore_infcall_suspend_state |
6389 | (struct infcall_suspend_state *inf_state) | |
b89667eb | 6390 | { |
16c381f0 | 6391 | return make_cleanup (do_restore_infcall_suspend_state_cleanup, inf_state); |
b89667eb DE |
6392 | } |
6393 | ||
6394 | void | |
16c381f0 | 6395 | discard_infcall_suspend_state (struct infcall_suspend_state *inf_state) |
b89667eb DE |
6396 | { |
6397 | regcache_xfree (inf_state->registers); | |
803b5f95 | 6398 | xfree (inf_state->siginfo_data); |
b89667eb DE |
6399 | xfree (inf_state); |
6400 | } | |
6401 | ||
6402 | struct regcache * | |
16c381f0 | 6403 | get_infcall_suspend_state_regcache (struct infcall_suspend_state *inf_state) |
b89667eb DE |
6404 | { |
6405 | return inf_state->registers; | |
6406 | } | |
6407 | ||
16c381f0 JK |
6408 | /* infcall_control_state contains state regarding gdb's control of the |
6409 | inferior itself like stepping control. It also contains session state like | |
6410 | the user's currently selected frame. */ | |
b89667eb | 6411 | |
16c381f0 | 6412 | struct infcall_control_state |
b89667eb | 6413 | { |
16c381f0 JK |
6414 | struct thread_control_state thread_control; |
6415 | struct inferior_control_state inferior_control; | |
d82142e2 JK |
6416 | |
6417 | /* Other fields: */ | |
6418 | enum stop_stack_kind stop_stack_dummy; | |
6419 | int stopped_by_random_signal; | |
7a292a7a | 6420 | int stop_after_trap; |
7a292a7a | 6421 | |
b89667eb | 6422 | /* ID if the selected frame when the inferior function call was made. */ |
101dcfbe | 6423 | struct frame_id selected_frame_id; |
7a292a7a SS |
6424 | }; |
6425 | ||
c906108c | 6426 | /* Save all of the information associated with the inferior<==>gdb |
b89667eb | 6427 | connection. */ |
c906108c | 6428 | |
16c381f0 JK |
6429 | struct infcall_control_state * |
6430 | save_infcall_control_state (void) | |
c906108c | 6431 | { |
16c381f0 | 6432 | struct infcall_control_state *inf_status = xmalloc (sizeof (*inf_status)); |
4e1c45ea | 6433 | struct thread_info *tp = inferior_thread (); |
d6b48e9c | 6434 | struct inferior *inf = current_inferior (); |
7a292a7a | 6435 | |
16c381f0 JK |
6436 | inf_status->thread_control = tp->control; |
6437 | inf_status->inferior_control = inf->control; | |
d82142e2 | 6438 | |
8358c15c | 6439 | tp->control.step_resume_breakpoint = NULL; |
5b79abe7 | 6440 | tp->control.exception_resume_breakpoint = NULL; |
8358c15c | 6441 | |
16c381f0 JK |
6442 | /* Save original bpstat chain to INF_STATUS; replace it in TP with copy of |
6443 | chain. If caller's caller is walking the chain, they'll be happier if we | |
6444 | hand them back the original chain when restore_infcall_control_state is | |
6445 | called. */ | |
6446 | tp->control.stop_bpstat = bpstat_copy (tp->control.stop_bpstat); | |
d82142e2 JK |
6447 | |
6448 | /* Other fields: */ | |
6449 | inf_status->stop_stack_dummy = stop_stack_dummy; | |
6450 | inf_status->stopped_by_random_signal = stopped_by_random_signal; | |
6451 | inf_status->stop_after_trap = stop_after_trap; | |
c5aa993b | 6452 | |
206415a3 | 6453 | inf_status->selected_frame_id = get_frame_id (get_selected_frame (NULL)); |
b89667eb | 6454 | |
7a292a7a | 6455 | return inf_status; |
c906108c SS |
6456 | } |
6457 | ||
c906108c | 6458 | static int |
96baa820 | 6459 | restore_selected_frame (void *args) |
c906108c | 6460 | { |
488f131b | 6461 | struct frame_id *fid = (struct frame_id *) args; |
c906108c | 6462 | struct frame_info *frame; |
c906108c | 6463 | |
101dcfbe | 6464 | frame = frame_find_by_id (*fid); |
c906108c | 6465 | |
aa0cd9c1 AC |
6466 | /* If inf_status->selected_frame_id is NULL, there was no previously |
6467 | selected frame. */ | |
101dcfbe | 6468 | if (frame == NULL) |
c906108c | 6469 | { |
8a3fe4f8 | 6470 | warning (_("Unable to restore previously selected frame.")); |
c906108c SS |
6471 | return 0; |
6472 | } | |
6473 | ||
0f7d239c | 6474 | select_frame (frame); |
c906108c SS |
6475 | |
6476 | return (1); | |
6477 | } | |
6478 | ||
b89667eb DE |
6479 | /* Restore inferior session state to INF_STATUS. */ |
6480 | ||
c906108c | 6481 | void |
16c381f0 | 6482 | restore_infcall_control_state (struct infcall_control_state *inf_status) |
c906108c | 6483 | { |
4e1c45ea | 6484 | struct thread_info *tp = inferior_thread (); |
d6b48e9c | 6485 | struct inferior *inf = current_inferior (); |
4e1c45ea | 6486 | |
8358c15c JK |
6487 | if (tp->control.step_resume_breakpoint) |
6488 | tp->control.step_resume_breakpoint->disposition = disp_del_at_next_stop; | |
6489 | ||
5b79abe7 TT |
6490 | if (tp->control.exception_resume_breakpoint) |
6491 | tp->control.exception_resume_breakpoint->disposition | |
6492 | = disp_del_at_next_stop; | |
6493 | ||
d82142e2 | 6494 | /* Handle the bpstat_copy of the chain. */ |
16c381f0 | 6495 | bpstat_clear (&tp->control.stop_bpstat); |
d82142e2 | 6496 | |
16c381f0 JK |
6497 | tp->control = inf_status->thread_control; |
6498 | inf->control = inf_status->inferior_control; | |
d82142e2 JK |
6499 | |
6500 | /* Other fields: */ | |
6501 | stop_stack_dummy = inf_status->stop_stack_dummy; | |
6502 | stopped_by_random_signal = inf_status->stopped_by_random_signal; | |
6503 | stop_after_trap = inf_status->stop_after_trap; | |
c906108c | 6504 | |
b89667eb | 6505 | if (target_has_stack) |
c906108c | 6506 | { |
c906108c | 6507 | /* The point of catch_errors is that if the stack is clobbered, |
101dcfbe AC |
6508 | walking the stack might encounter a garbage pointer and |
6509 | error() trying to dereference it. */ | |
488f131b JB |
6510 | if (catch_errors |
6511 | (restore_selected_frame, &inf_status->selected_frame_id, | |
6512 | "Unable to restore previously selected frame:\n", | |
6513 | RETURN_MASK_ERROR) == 0) | |
c906108c SS |
6514 | /* Error in restoring the selected frame. Select the innermost |
6515 | frame. */ | |
0f7d239c | 6516 | select_frame (get_current_frame ()); |
c906108c | 6517 | } |
c906108c | 6518 | |
72cec141 | 6519 | xfree (inf_status); |
7a292a7a | 6520 | } |
c906108c | 6521 | |
74b7792f | 6522 | static void |
16c381f0 | 6523 | do_restore_infcall_control_state_cleanup (void *sts) |
74b7792f | 6524 | { |
16c381f0 | 6525 | restore_infcall_control_state (sts); |
74b7792f AC |
6526 | } |
6527 | ||
6528 | struct cleanup * | |
16c381f0 JK |
6529 | make_cleanup_restore_infcall_control_state |
6530 | (struct infcall_control_state *inf_status) | |
74b7792f | 6531 | { |
16c381f0 | 6532 | return make_cleanup (do_restore_infcall_control_state_cleanup, inf_status); |
74b7792f AC |
6533 | } |
6534 | ||
c906108c | 6535 | void |
16c381f0 | 6536 | discard_infcall_control_state (struct infcall_control_state *inf_status) |
7a292a7a | 6537 | { |
8358c15c JK |
6538 | if (inf_status->thread_control.step_resume_breakpoint) |
6539 | inf_status->thread_control.step_resume_breakpoint->disposition | |
6540 | = disp_del_at_next_stop; | |
6541 | ||
5b79abe7 TT |
6542 | if (inf_status->thread_control.exception_resume_breakpoint) |
6543 | inf_status->thread_control.exception_resume_breakpoint->disposition | |
6544 | = disp_del_at_next_stop; | |
6545 | ||
1777feb0 | 6546 | /* See save_infcall_control_state for info on stop_bpstat. */ |
16c381f0 | 6547 | bpstat_clear (&inf_status->thread_control.stop_bpstat); |
8358c15c | 6548 | |
72cec141 | 6549 | xfree (inf_status); |
7a292a7a | 6550 | } |
b89667eb | 6551 | \f |
47932f85 | 6552 | int |
3a3e9ee3 | 6553 | inferior_has_forked (ptid_t pid, ptid_t *child_pid) |
47932f85 DJ |
6554 | { |
6555 | struct target_waitstatus last; | |
6556 | ptid_t last_ptid; | |
6557 | ||
6558 | get_last_target_status (&last_ptid, &last); | |
6559 | ||
6560 | if (last.kind != TARGET_WAITKIND_FORKED) | |
6561 | return 0; | |
6562 | ||
3a3e9ee3 | 6563 | if (!ptid_equal (last_ptid, pid)) |
47932f85 DJ |
6564 | return 0; |
6565 | ||
6566 | *child_pid = last.value.related_pid; | |
6567 | return 1; | |
6568 | } | |
6569 | ||
6570 | int | |
3a3e9ee3 | 6571 | inferior_has_vforked (ptid_t pid, ptid_t *child_pid) |
47932f85 DJ |
6572 | { |
6573 | struct target_waitstatus last; | |
6574 | ptid_t last_ptid; | |
6575 | ||
6576 | get_last_target_status (&last_ptid, &last); | |
6577 | ||
6578 | if (last.kind != TARGET_WAITKIND_VFORKED) | |
6579 | return 0; | |
6580 | ||
3a3e9ee3 | 6581 | if (!ptid_equal (last_ptid, pid)) |
47932f85 DJ |
6582 | return 0; |
6583 | ||
6584 | *child_pid = last.value.related_pid; | |
6585 | return 1; | |
6586 | } | |
6587 | ||
6588 | int | |
3a3e9ee3 | 6589 | inferior_has_execd (ptid_t pid, char **execd_pathname) |
47932f85 DJ |
6590 | { |
6591 | struct target_waitstatus last; | |
6592 | ptid_t last_ptid; | |
6593 | ||
6594 | get_last_target_status (&last_ptid, &last); | |
6595 | ||
6596 | if (last.kind != TARGET_WAITKIND_EXECD) | |
6597 | return 0; | |
6598 | ||
3a3e9ee3 | 6599 | if (!ptid_equal (last_ptid, pid)) |
47932f85 DJ |
6600 | return 0; |
6601 | ||
6602 | *execd_pathname = xstrdup (last.value.execd_pathname); | |
6603 | return 1; | |
6604 | } | |
6605 | ||
a96d9b2e SDJ |
6606 | int |
6607 | inferior_has_called_syscall (ptid_t pid, int *syscall_number) | |
6608 | { | |
6609 | struct target_waitstatus last; | |
6610 | ptid_t last_ptid; | |
6611 | ||
6612 | get_last_target_status (&last_ptid, &last); | |
6613 | ||
6614 | if (last.kind != TARGET_WAITKIND_SYSCALL_ENTRY && | |
6615 | last.kind != TARGET_WAITKIND_SYSCALL_RETURN) | |
6616 | return 0; | |
6617 | ||
6618 | if (!ptid_equal (last_ptid, pid)) | |
6619 | return 0; | |
6620 | ||
6621 | *syscall_number = last.value.syscall_number; | |
6622 | return 1; | |
6623 | } | |
6624 | ||
ca6724c1 KB |
6625 | /* Oft used ptids */ |
6626 | ptid_t null_ptid; | |
6627 | ptid_t minus_one_ptid; | |
6628 | ||
6629 | /* Create a ptid given the necessary PID, LWP, and TID components. */ | |
488f131b | 6630 | |
ca6724c1 KB |
6631 | ptid_t |
6632 | ptid_build (int pid, long lwp, long tid) | |
6633 | { | |
6634 | ptid_t ptid; | |
6635 | ||
6636 | ptid.pid = pid; | |
6637 | ptid.lwp = lwp; | |
6638 | ptid.tid = tid; | |
6639 | return ptid; | |
6640 | } | |
6641 | ||
6642 | /* Create a ptid from just a pid. */ | |
6643 | ||
6644 | ptid_t | |
6645 | pid_to_ptid (int pid) | |
6646 | { | |
6647 | return ptid_build (pid, 0, 0); | |
6648 | } | |
6649 | ||
6650 | /* Fetch the pid (process id) component from a ptid. */ | |
6651 | ||
6652 | int | |
6653 | ptid_get_pid (ptid_t ptid) | |
6654 | { | |
6655 | return ptid.pid; | |
6656 | } | |
6657 | ||
6658 | /* Fetch the lwp (lightweight process) component from a ptid. */ | |
6659 | ||
6660 | long | |
6661 | ptid_get_lwp (ptid_t ptid) | |
6662 | { | |
6663 | return ptid.lwp; | |
6664 | } | |
6665 | ||
6666 | /* Fetch the tid (thread id) component from a ptid. */ | |
6667 | ||
6668 | long | |
6669 | ptid_get_tid (ptid_t ptid) | |
6670 | { | |
6671 | return ptid.tid; | |
6672 | } | |
6673 | ||
6674 | /* ptid_equal() is used to test equality of two ptids. */ | |
6675 | ||
6676 | int | |
6677 | ptid_equal (ptid_t ptid1, ptid_t ptid2) | |
6678 | { | |
6679 | return (ptid1.pid == ptid2.pid && ptid1.lwp == ptid2.lwp | |
488f131b | 6680 | && ptid1.tid == ptid2.tid); |
ca6724c1 KB |
6681 | } |
6682 | ||
252fbfc8 PA |
6683 | /* Returns true if PTID represents a process. */ |
6684 | ||
6685 | int | |
6686 | ptid_is_pid (ptid_t ptid) | |
6687 | { | |
6688 | if (ptid_equal (minus_one_ptid, ptid)) | |
6689 | return 0; | |
6690 | if (ptid_equal (null_ptid, ptid)) | |
6691 | return 0; | |
6692 | ||
6693 | return (ptid_get_lwp (ptid) == 0 && ptid_get_tid (ptid) == 0); | |
6694 | } | |
6695 | ||
0723dbf5 PA |
6696 | int |
6697 | ptid_match (ptid_t ptid, ptid_t filter) | |
6698 | { | |
6699 | /* Since both parameters have the same type, prevent easy mistakes | |
6700 | from happening. */ | |
6701 | gdb_assert (!ptid_equal (ptid, minus_one_ptid) | |
5f25d77d | 6702 | && !ptid_equal (ptid, null_ptid)); |
0723dbf5 PA |
6703 | |
6704 | if (ptid_equal (filter, minus_one_ptid)) | |
6705 | return 1; | |
6706 | if (ptid_is_pid (filter) | |
6707 | && ptid_get_pid (ptid) == ptid_get_pid (filter)) | |
6708 | return 1; | |
6709 | else if (ptid_equal (ptid, filter)) | |
6710 | return 1; | |
6711 | ||
6712 | return 0; | |
6713 | } | |
6714 | ||
ca6724c1 KB |
6715 | /* restore_inferior_ptid() will be used by the cleanup machinery |
6716 | to restore the inferior_ptid value saved in a call to | |
6717 | save_inferior_ptid(). */ | |
ce696e05 KB |
6718 | |
6719 | static void | |
6720 | restore_inferior_ptid (void *arg) | |
6721 | { | |
6722 | ptid_t *saved_ptid_ptr = arg; | |
abbb1732 | 6723 | |
ce696e05 KB |
6724 | inferior_ptid = *saved_ptid_ptr; |
6725 | xfree (arg); | |
6726 | } | |
6727 | ||
6728 | /* Save the value of inferior_ptid so that it may be restored by a | |
6729 | later call to do_cleanups(). Returns the struct cleanup pointer | |
6730 | needed for later doing the cleanup. */ | |
6731 | ||
6732 | struct cleanup * | |
6733 | save_inferior_ptid (void) | |
6734 | { | |
6735 | ptid_t *saved_ptid_ptr; | |
6736 | ||
6737 | saved_ptid_ptr = xmalloc (sizeof (ptid_t)); | |
6738 | *saved_ptid_ptr = inferior_ptid; | |
6739 | return make_cleanup (restore_inferior_ptid, saved_ptid_ptr); | |
6740 | } | |
c5aa993b | 6741 | \f |
488f131b | 6742 | |
b2175913 MS |
6743 | /* User interface for reverse debugging: |
6744 | Set exec-direction / show exec-direction commands | |
6745 | (returns error unless target implements to_set_exec_direction method). */ | |
6746 | ||
6747 | enum exec_direction_kind execution_direction = EXEC_FORWARD; | |
6748 | static const char exec_forward[] = "forward"; | |
6749 | static const char exec_reverse[] = "reverse"; | |
6750 | static const char *exec_direction = exec_forward; | |
6751 | static const char *exec_direction_names[] = { | |
6752 | exec_forward, | |
6753 | exec_reverse, | |
6754 | NULL | |
6755 | }; | |
6756 | ||
6757 | static void | |
6758 | set_exec_direction_func (char *args, int from_tty, | |
6759 | struct cmd_list_element *cmd) | |
6760 | { | |
6761 | if (target_can_execute_reverse) | |
6762 | { | |
6763 | if (!strcmp (exec_direction, exec_forward)) | |
6764 | execution_direction = EXEC_FORWARD; | |
6765 | else if (!strcmp (exec_direction, exec_reverse)) | |
6766 | execution_direction = EXEC_REVERSE; | |
6767 | } | |
8bbed405 MS |
6768 | else |
6769 | { | |
6770 | exec_direction = exec_forward; | |
6771 | error (_("Target does not support this operation.")); | |
6772 | } | |
b2175913 MS |
6773 | } |
6774 | ||
6775 | static void | |
6776 | show_exec_direction_func (struct ui_file *out, int from_tty, | |
6777 | struct cmd_list_element *cmd, const char *value) | |
6778 | { | |
6779 | switch (execution_direction) { | |
6780 | case EXEC_FORWARD: | |
6781 | fprintf_filtered (out, _("Forward.\n")); | |
6782 | break; | |
6783 | case EXEC_REVERSE: | |
6784 | fprintf_filtered (out, _("Reverse.\n")); | |
6785 | break; | |
6786 | case EXEC_ERROR: | |
6787 | default: | |
3e43a32a MS |
6788 | fprintf_filtered (out, _("Forward (target `%s' does not " |
6789 | "support exec-direction).\n"), | |
b2175913 MS |
6790 | target_shortname); |
6791 | break; | |
6792 | } | |
6793 | } | |
6794 | ||
6795 | /* User interface for non-stop mode. */ | |
6796 | ||
ad52ddc6 | 6797 | int non_stop = 0; |
ad52ddc6 PA |
6798 | |
6799 | static void | |
6800 | set_non_stop (char *args, int from_tty, | |
6801 | struct cmd_list_element *c) | |
6802 | { | |
6803 | if (target_has_execution) | |
6804 | { | |
6805 | non_stop_1 = non_stop; | |
6806 | error (_("Cannot change this setting while the inferior is running.")); | |
6807 | } | |
6808 | ||
6809 | non_stop = non_stop_1; | |
6810 | } | |
6811 | ||
6812 | static void | |
6813 | show_non_stop (struct ui_file *file, int from_tty, | |
6814 | struct cmd_list_element *c, const char *value) | |
6815 | { | |
6816 | fprintf_filtered (file, | |
6817 | _("Controlling the inferior in non-stop mode is %s.\n"), | |
6818 | value); | |
6819 | } | |
6820 | ||
d4db2f36 PA |
6821 | static void |
6822 | show_schedule_multiple (struct ui_file *file, int from_tty, | |
6823 | struct cmd_list_element *c, const char *value) | |
6824 | { | |
3e43a32a MS |
6825 | fprintf_filtered (file, _("Resuming the execution of threads " |
6826 | "of all processes is %s.\n"), value); | |
d4db2f36 | 6827 | } |
ad52ddc6 | 6828 | |
c906108c | 6829 | void |
96baa820 | 6830 | _initialize_infrun (void) |
c906108c | 6831 | { |
52f0bd74 AC |
6832 | int i; |
6833 | int numsigs; | |
c906108c | 6834 | |
1bedd215 AC |
6835 | add_info ("signals", signals_info, _("\ |
6836 | What debugger does when program gets various signals.\n\ | |
6837 | Specify a signal as argument to print info on that signal only.")); | |
c906108c SS |
6838 | add_info_alias ("handle", "signals", 0); |
6839 | ||
1bedd215 AC |
6840 | add_com ("handle", class_run, handle_command, _("\ |
6841 | Specify how to handle a signal.\n\ | |
c906108c SS |
6842 | Args are signals and actions to apply to those signals.\n\ |
6843 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
6844 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
6845 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
6846 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 AC |
6847 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
6848 | Recognized actions include \"stop\", \"nostop\", \"print\", \"noprint\",\n\ | |
c906108c SS |
6849 | \"pass\", \"nopass\", \"ignore\", or \"noignore\".\n\ |
6850 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
6851 | Print means print a message if this signal happens.\n\ | |
6852 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
6853 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 6854 | Pass and Stop may be combined.")); |
c906108c SS |
6855 | if (xdb_commands) |
6856 | { | |
1bedd215 AC |
6857 | add_com ("lz", class_info, signals_info, _("\ |
6858 | What debugger does when program gets various signals.\n\ | |
6859 | Specify a signal as argument to print info on that signal only.")); | |
6860 | add_com ("z", class_run, xdb_handle_command, _("\ | |
6861 | Specify how to handle a signal.\n\ | |
c906108c SS |
6862 | Args are signals and actions to apply to those signals.\n\ |
6863 | Symbolic signals (e.g. SIGSEGV) are recommended but numeric signals\n\ | |
6864 | from 1-15 are allowed for compatibility with old versions of GDB.\n\ | |
6865 | Numeric ranges may be specified with the form LOW-HIGH (e.g. 1-5).\n\ | |
6866 | The special arg \"all\" is recognized to mean all signals except those\n\ | |
1bedd215 | 6867 | used by the debugger, typically SIGTRAP and SIGINT.\n\ |
cce7e648 | 6868 | Recognized actions include \"s\" (toggles between stop and nostop),\n\ |
c906108c SS |
6869 | \"r\" (toggles between print and noprint), \"i\" (toggles between pass and \ |
6870 | nopass), \"Q\" (noprint)\n\ | |
6871 | Stop means reenter debugger if this signal happens (implies print).\n\ | |
6872 | Print means print a message if this signal happens.\n\ | |
6873 | Pass means let program see this signal; otherwise program doesn't know.\n\ | |
6874 | Ignore is a synonym for nopass and noignore is a synonym for pass.\n\ | |
1bedd215 | 6875 | Pass and Stop may be combined.")); |
c906108c SS |
6876 | } |
6877 | ||
6878 | if (!dbx_commands) | |
1a966eab AC |
6879 | stop_command = add_cmd ("stop", class_obscure, |
6880 | not_just_help_class_command, _("\ | |
6881 | There is no `stop' command, but you can set a hook on `stop'.\n\ | |
c906108c | 6882 | This allows you to set a list of commands to be run each time execution\n\ |
1a966eab | 6883 | of the program stops."), &cmdlist); |
c906108c | 6884 | |
85c07804 AC |
6885 | add_setshow_zinteger_cmd ("infrun", class_maintenance, &debug_infrun, _("\ |
6886 | Set inferior debugging."), _("\ | |
6887 | Show inferior debugging."), _("\ | |
6888 | When non-zero, inferior specific debugging is enabled."), | |
6889 | NULL, | |
920d2a44 | 6890 | show_debug_infrun, |
85c07804 | 6891 | &setdebuglist, &showdebuglist); |
527159b7 | 6892 | |
3e43a32a MS |
6893 | add_setshow_boolean_cmd ("displaced", class_maintenance, |
6894 | &debug_displaced, _("\ | |
237fc4c9 PA |
6895 | Set displaced stepping debugging."), _("\ |
6896 | Show displaced stepping debugging."), _("\ | |
6897 | When non-zero, displaced stepping specific debugging is enabled."), | |
6898 | NULL, | |
6899 | show_debug_displaced, | |
6900 | &setdebuglist, &showdebuglist); | |
6901 | ||
ad52ddc6 PA |
6902 | add_setshow_boolean_cmd ("non-stop", no_class, |
6903 | &non_stop_1, _("\ | |
6904 | Set whether gdb controls the inferior in non-stop mode."), _("\ | |
6905 | Show whether gdb controls the inferior in non-stop mode."), _("\ | |
6906 | When debugging a multi-threaded program and this setting is\n\ | |
6907 | off (the default, also called all-stop mode), when one thread stops\n\ | |
6908 | (for a breakpoint, watchpoint, exception, or similar events), GDB stops\n\ | |
6909 | all other threads in the program while you interact with the thread of\n\ | |
6910 | interest. When you continue or step a thread, you can allow the other\n\ | |
6911 | threads to run, or have them remain stopped, but while you inspect any\n\ | |
6912 | thread's state, all threads stop.\n\ | |
6913 | \n\ | |
6914 | In non-stop mode, when one thread stops, other threads can continue\n\ | |
6915 | to run freely. You'll be able to step each thread independently,\n\ | |
6916 | leave it stopped or free to run as needed."), | |
6917 | set_non_stop, | |
6918 | show_non_stop, | |
6919 | &setlist, | |
6920 | &showlist); | |
6921 | ||
c906108c | 6922 | numsigs = (int) TARGET_SIGNAL_LAST; |
488f131b | 6923 | signal_stop = (unsigned char *) xmalloc (sizeof (signal_stop[0]) * numsigs); |
c906108c SS |
6924 | signal_print = (unsigned char *) |
6925 | xmalloc (sizeof (signal_print[0]) * numsigs); | |
6926 | signal_program = (unsigned char *) | |
6927 | xmalloc (sizeof (signal_program[0]) * numsigs); | |
6928 | for (i = 0; i < numsigs; i++) | |
6929 | { | |
6930 | signal_stop[i] = 1; | |
6931 | signal_print[i] = 1; | |
6932 | signal_program[i] = 1; | |
6933 | } | |
6934 | ||
6935 | /* Signals caused by debugger's own actions | |
6936 | should not be given to the program afterwards. */ | |
6937 | signal_program[TARGET_SIGNAL_TRAP] = 0; | |
6938 | signal_program[TARGET_SIGNAL_INT] = 0; | |
6939 | ||
6940 | /* Signals that are not errors should not normally enter the debugger. */ | |
6941 | signal_stop[TARGET_SIGNAL_ALRM] = 0; | |
6942 | signal_print[TARGET_SIGNAL_ALRM] = 0; | |
6943 | signal_stop[TARGET_SIGNAL_VTALRM] = 0; | |
6944 | signal_print[TARGET_SIGNAL_VTALRM] = 0; | |
6945 | signal_stop[TARGET_SIGNAL_PROF] = 0; | |
6946 | signal_print[TARGET_SIGNAL_PROF] = 0; | |
6947 | signal_stop[TARGET_SIGNAL_CHLD] = 0; | |
6948 | signal_print[TARGET_SIGNAL_CHLD] = 0; | |
6949 | signal_stop[TARGET_SIGNAL_IO] = 0; | |
6950 | signal_print[TARGET_SIGNAL_IO] = 0; | |
6951 | signal_stop[TARGET_SIGNAL_POLL] = 0; | |
6952 | signal_print[TARGET_SIGNAL_POLL] = 0; | |
6953 | signal_stop[TARGET_SIGNAL_URG] = 0; | |
6954 | signal_print[TARGET_SIGNAL_URG] = 0; | |
6955 | signal_stop[TARGET_SIGNAL_WINCH] = 0; | |
6956 | signal_print[TARGET_SIGNAL_WINCH] = 0; | |
16dfc9ce JB |
6957 | signal_stop[TARGET_SIGNAL_PRIO] = 0; |
6958 | signal_print[TARGET_SIGNAL_PRIO] = 0; | |
c906108c | 6959 | |
cd0fc7c3 SS |
6960 | /* These signals are used internally by user-level thread |
6961 | implementations. (See signal(5) on Solaris.) Like the above | |
6962 | signals, a healthy program receives and handles them as part of | |
6963 | its normal operation. */ | |
6964 | signal_stop[TARGET_SIGNAL_LWP] = 0; | |
6965 | signal_print[TARGET_SIGNAL_LWP] = 0; | |
6966 | signal_stop[TARGET_SIGNAL_WAITING] = 0; | |
6967 | signal_print[TARGET_SIGNAL_WAITING] = 0; | |
6968 | signal_stop[TARGET_SIGNAL_CANCEL] = 0; | |
6969 | signal_print[TARGET_SIGNAL_CANCEL] = 0; | |
6970 | ||
85c07804 AC |
6971 | add_setshow_zinteger_cmd ("stop-on-solib-events", class_support, |
6972 | &stop_on_solib_events, _("\ | |
6973 | Set stopping for shared library events."), _("\ | |
6974 | Show stopping for shared library events."), _("\ | |
c906108c SS |
6975 | If nonzero, gdb will give control to the user when the dynamic linker\n\ |
6976 | notifies gdb of shared library events. The most common event of interest\n\ | |
85c07804 AC |
6977 | to the user would be loading/unloading of a new library."), |
6978 | NULL, | |
920d2a44 | 6979 | show_stop_on_solib_events, |
85c07804 | 6980 | &setlist, &showlist); |
c906108c | 6981 | |
7ab04401 AC |
6982 | add_setshow_enum_cmd ("follow-fork-mode", class_run, |
6983 | follow_fork_mode_kind_names, | |
6984 | &follow_fork_mode_string, _("\ | |
6985 | Set debugger response to a program call of fork or vfork."), _("\ | |
6986 | Show debugger response to a program call of fork or vfork."), _("\ | |
c906108c SS |
6987 | A fork or vfork creates a new process. follow-fork-mode can be:\n\ |
6988 | parent - the original process is debugged after a fork\n\ | |
6989 | child - the new process is debugged after a fork\n\ | |
ea1dd7bc | 6990 | The unfollowed process will continue to run.\n\ |
7ab04401 AC |
6991 | By default, the debugger will follow the parent process."), |
6992 | NULL, | |
920d2a44 | 6993 | show_follow_fork_mode_string, |
7ab04401 AC |
6994 | &setlist, &showlist); |
6995 | ||
6c95b8df PA |
6996 | add_setshow_enum_cmd ("follow-exec-mode", class_run, |
6997 | follow_exec_mode_names, | |
6998 | &follow_exec_mode_string, _("\ | |
6999 | Set debugger response to a program call of exec."), _("\ | |
7000 | Show debugger response to a program call of exec."), _("\ | |
7001 | An exec call replaces the program image of a process.\n\ | |
7002 | \n\ | |
7003 | follow-exec-mode can be:\n\ | |
7004 | \n\ | |
cce7e648 | 7005 | new - the debugger creates a new inferior and rebinds the process\n\ |
6c95b8df PA |
7006 | to this new inferior. The program the process was running before\n\ |
7007 | the exec call can be restarted afterwards by restarting the original\n\ | |
7008 | inferior.\n\ | |
7009 | \n\ | |
7010 | same - the debugger keeps the process bound to the same inferior.\n\ | |
7011 | The new executable image replaces the previous executable loaded in\n\ | |
7012 | the inferior. Restarting the inferior after the exec call restarts\n\ | |
7013 | the executable the process was running after the exec call.\n\ | |
7014 | \n\ | |
7015 | By default, the debugger will use the same inferior."), | |
7016 | NULL, | |
7017 | show_follow_exec_mode_string, | |
7018 | &setlist, &showlist); | |
7019 | ||
7ab04401 AC |
7020 | add_setshow_enum_cmd ("scheduler-locking", class_run, |
7021 | scheduler_enums, &scheduler_mode, _("\ | |
7022 | Set mode for locking scheduler during execution."), _("\ | |
7023 | Show mode for locking scheduler during execution."), _("\ | |
c906108c SS |
7024 | off == no locking (threads may preempt at any time)\n\ |
7025 | on == full locking (no thread except the current thread may run)\n\ | |
7026 | step == scheduler locked during every single-step operation.\n\ | |
7027 | In this mode, no other thread may run during a step command.\n\ | |
7ab04401 AC |
7028 | Other threads may run while stepping over a function call ('next')."), |
7029 | set_schedlock_func, /* traps on target vector */ | |
920d2a44 | 7030 | show_scheduler_mode, |
7ab04401 | 7031 | &setlist, &showlist); |
5fbbeb29 | 7032 | |
d4db2f36 PA |
7033 | add_setshow_boolean_cmd ("schedule-multiple", class_run, &sched_multi, _("\ |
7034 | Set mode for resuming threads of all processes."), _("\ | |
7035 | Show mode for resuming threads of all processes."), _("\ | |
7036 | When on, execution commands (such as 'continue' or 'next') resume all\n\ | |
7037 | threads of all processes. When off (which is the default), execution\n\ | |
7038 | commands only resume the threads of the current process. The set of\n\ | |
7039 | threads that are resumed is further refined by the scheduler-locking\n\ | |
7040 | mode (see help set scheduler-locking)."), | |
7041 | NULL, | |
7042 | show_schedule_multiple, | |
7043 | &setlist, &showlist); | |
7044 | ||
5bf193a2 AC |
7045 | add_setshow_boolean_cmd ("step-mode", class_run, &step_stop_if_no_debug, _("\ |
7046 | Set mode of the step operation."), _("\ | |
7047 | Show mode of the step operation."), _("\ | |
7048 | When set, doing a step over a function without debug line information\n\ | |
7049 | will stop at the first instruction of that function. Otherwise, the\n\ | |
7050 | function is skipped and the step command stops at a different source line."), | |
7051 | NULL, | |
920d2a44 | 7052 | show_step_stop_if_no_debug, |
5bf193a2 | 7053 | &setlist, &showlist); |
ca6724c1 | 7054 | |
fff08868 HZ |
7055 | add_setshow_enum_cmd ("displaced-stepping", class_run, |
7056 | can_use_displaced_stepping_enum, | |
7057 | &can_use_displaced_stepping, _("\ | |
237fc4c9 PA |
7058 | Set debugger's willingness to use displaced stepping."), _("\ |
7059 | Show debugger's willingness to use displaced stepping."), _("\ | |
fff08868 HZ |
7060 | If on, gdb will use displaced stepping to step over breakpoints if it is\n\ |
7061 | supported by the target architecture. If off, gdb will not use displaced\n\ | |
7062 | stepping to step over breakpoints, even if such is supported by the target\n\ | |
7063 | architecture. If auto (which is the default), gdb will use displaced stepping\n\ | |
7064 | if the target architecture supports it and non-stop mode is active, but will not\n\ | |
7065 | use it in all-stop mode (see help set non-stop)."), | |
7066 | NULL, | |
7067 | show_can_use_displaced_stepping, | |
7068 | &setlist, &showlist); | |
237fc4c9 | 7069 | |
b2175913 MS |
7070 | add_setshow_enum_cmd ("exec-direction", class_run, exec_direction_names, |
7071 | &exec_direction, _("Set direction of execution.\n\ | |
7072 | Options are 'forward' or 'reverse'."), | |
7073 | _("Show direction of execution (forward/reverse)."), | |
7074 | _("Tells gdb whether to execute forward or backward."), | |
7075 | set_exec_direction_func, show_exec_direction_func, | |
7076 | &setlist, &showlist); | |
7077 | ||
6c95b8df PA |
7078 | /* Set/show detach-on-fork: user-settable mode. */ |
7079 | ||
7080 | add_setshow_boolean_cmd ("detach-on-fork", class_run, &detach_fork, _("\ | |
7081 | Set whether gdb will detach the child of a fork."), _("\ | |
7082 | Show whether gdb will detach the child of a fork."), _("\ | |
7083 | Tells gdb whether to detach the child of a fork."), | |
7084 | NULL, NULL, &setlist, &showlist); | |
7085 | ||
ca6724c1 KB |
7086 | /* ptid initializations */ |
7087 | null_ptid = ptid_build (0, 0, 0); | |
7088 | minus_one_ptid = ptid_build (-1, 0, 0); | |
7089 | inferior_ptid = null_ptid; | |
7090 | target_last_wait_ptid = minus_one_ptid; | |
5231c1fd PA |
7091 | |
7092 | observer_attach_thread_ptid_changed (infrun_thread_ptid_changed); | |
252fbfc8 | 7093 | observer_attach_thread_stop_requested (infrun_thread_stop_requested); |
a07daef3 | 7094 | observer_attach_thread_exit (infrun_thread_thread_exit); |
fc1cf338 | 7095 | observer_attach_inferior_exit (infrun_inferior_exit); |
4aa995e1 PA |
7096 | |
7097 | /* Explicitly create without lookup, since that tries to create a | |
7098 | value with a void typed value, and when we get here, gdbarch | |
7099 | isn't initialized yet. At this point, we're quite sure there | |
7100 | isn't another convenience variable of the same name. */ | |
7101 | create_internalvar_type_lazy ("_siginfo", siginfo_make_value); | |
d914c394 SS |
7102 | |
7103 | add_setshow_boolean_cmd ("observer", no_class, | |
7104 | &observer_mode_1, _("\ | |
7105 | Set whether gdb controls the inferior in observer mode."), _("\ | |
7106 | Show whether gdb controls the inferior in observer mode."), _("\ | |
7107 | In observer mode, GDB can get data from the inferior, but not\n\ | |
7108 | affect its execution. Registers and memory may not be changed,\n\ | |
7109 | breakpoints may not be set, and the program cannot be interrupted\n\ | |
7110 | or signalled."), | |
7111 | set_observer_mode, | |
7112 | show_observer_mode, | |
7113 | &setlist, | |
7114 | &showlist); | |
c906108c | 7115 | } |