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