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