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