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