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