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