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