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