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