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