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