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