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