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